/* ============================================================
   AVA — Android-native design system
   ============================================================ */
:root {
  /* Surfaces */
  --bg:            #f5f5f5;
  --surface:       #ffffff;
  --surface-variant:#f0f0f0;
  --surface-raised: #ffffff;
  /* Content */
  --on-bg:         #1a1a1a;
  --on-surface:    #1a1a1a;
  --on-surface-2:  #5c5c5c;
  --on-surface-3:  #8a8a8a;
  /* Brand */
  --primary:       #2563eb;
  --primary-hover: #1d4ed8;
  --primary-container: #dbeafe;
  --on-primary-container: #1e40af;
  /* Semantic */
  --error:         #dc2626;
  --error-container:#fee2e2;
  --warning:       #b45309;
  --warning-container:#fef3c7;
  --success:       #16a34a;
  --success-container:#dcfce7;
  --info-container:#dbeafe;
  /* Shape */
  --radius-xs:     8px;
  --radius-sm:     12px;
  --radius-md:     16px;
  --radius-lg:     20px;
  --radius-xl:     28px;
  --radius-full:   999px;
  /* Elevation */
  --elevation-1:   0 1px 3px rgba(0,0,0,.08);
  --elevation-2:   0 4px 12px rgba(0,0,0,.1);
  --elevation-3:   0 8px 24px rgba(0,0,0,.14);
  /* Typography */
  --font:          Roboto, "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:     "Roboto Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  /* Motion */
  --transition:    200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast:150ms cubic-bezier(0.4, 0, 0.2, 1);
  /* Safe areas */
  --safe-top:      env(safe-area-inset-top, 0px);
  --safe-bottom:   env(safe-area-inset-bottom, 0px);
  --safe-left:     env(safe-area-inset-left, 0px);
  --safe-right:    env(safe-area-inset-right, 0px);
}

[data-theme="dark"] {
  --bg:            #121212;
  --surface:       #1e1e1e;
  --surface-variant:#2c2c2c;
  --surface-raised: #252525;
  --on-bg:         #e8e8e8;
  --on-surface:    #e8e8e8;
  --on-surface-2:  #a0a0a0;
  --on-surface-3:  #6e6e6e;
  --primary:       #4b8bff;
  --primary-hover: #3b7aee;
  --primary-container: #1a3a6e;
  --on-primary-container: #b0d0ff;
  --error:         #f87171;
  --error-container:#4a1a1a;
  --warning:       #fbbf24;
  --warning-container:#4a3510;
  --success:       #4ade80;
  --success-container:#1a3a20;
  --info-container:#1a3050;
  --elevation-1:   0 1px 3px rgba(0,0,0,.4);
  --elevation-2:   0 4px 12px rgba(0,0,0,.5);
  --elevation-3:   0 8px 24px rgba(0,0,0,.6);
}

/* ============================================================
   Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--on-bg);
  -webkit-font-smoothing: antialiased;
}

input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

.hidden { display: none !important; }

/* ============================================================
   App shell — full height, column layout
   ============================================================ */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* ============================================================
   App bar — Android top app bar
   ============================================================ */
.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 8px 12px;
  padding-top: calc(8px + var(--safe-top));
  background: var(--surface);
  border-bottom: 1px solid transparent;
  flex-shrink: 0;
  z-index: 10;
  min-height: 56px;
}
.app-bar-start, .app-bar-end {
  display: flex;
  align-items: center;
  gap: 6px;
}
.app-bar-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--on-surface);
  letter-spacing: -.3px;
}
.app-bar-btn {
  width: 40px; height: 40px;
  border: none; border-radius: var(--radius-full);
  background: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--on-surface-2);
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition-fast);
  flex-shrink: 0;
}
.app-bar-btn:hover { background: var(--surface-variant); }
.app-bar-btn:active { background: var(--primary-container); }

.chip {
  font-size: 10px; font-weight: 600;
  padding: 4px 10px; border-radius: var(--radius-full);
  background: var(--primary-container);
  color: var(--on-primary-container);
  text-transform: uppercase; letter-spacing: .5px;
  white-space: nowrap;
}

/* Status dot in app bar */
.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--on-surface-3);
  transition: background var(--transition), box-shadow var(--transition);
}
.status-dot.standby   { background: var(--on-surface-3); }
.status-dot.listening { background: var(--error); box-shadow: 0 0 8px var(--error); animation: dotPulse 1.1s infinite; }
.status-dot.thinking  { background: var(--warning); animation: dotPulse 0.8s infinite; }
.status-dot.speaking  { background: var(--primary); box-shadow: 0 0 8px var(--primary); }
.status-dot.error     { background: var(--error); }

@keyframes dotPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .4; transform: scale(1.5); }
}

/* ============================================================
   Banner
   ============================================================ */
.banner {
  background: var(--warning-container);
  color: var(--warning);
  text-align: center;
  padding: 8px;
  font-size: 13px;
  font-weight: 500;
  flex-shrink: 0;
}

/* ============================================================
   Main content: chat fills all available space
   ============================================================ */
.main-content {
  flex: 1 1 0%;
  min-height: 0; /* required for flex child to scroll */
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 12px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Chat list — grows with content, or fills for empty state */
.chat-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 100%;
  padding-bottom: 4px;
}

/* Empty state — centers in the available vertical space */
.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 20px;
  gap: 8px;
}
.chat-empty-icon { font-size: 48px; opacity: .35; }
.chat-empty-title { font-size: 18px; font-weight: 600; color: var(--on-surface); }
.chat-empty-sub { font-size: 13px; color: var(--on-surface-2); line-height: 1.5; }

/* Chat bubbles */
.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  animation: msgIn 250ms cubic-bezier(0.4, 0, 0.2, 1);
}
.chat-msg.user      { align-self: flex-end; align-items: flex-end; }
.chat-msg.assistant  { align-self: flex-start; align-items: flex-start; }
.chat-msg.system     { align-self: center; max-width: 92%; }

.chat-msg-label {
  font-size: 11px; font-weight: 600;
  padding: 0 6px 2px;
  color: var(--on-surface-3);
  letter-spacing: .4px;
}

.chat-msg-bubble {
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.chat-msg.user .chat-msg-bubble {
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-md) 4px var(--radius-md) var(--radius-md);
}
.chat-msg.assistant .chat-msg-bubble {
  background: var(--surface);
  color: var(--on-surface);
  border-radius: 4px var(--radius-md) var(--radius-md) var(--radius-md);
  box-shadow: var(--elevation-1);
}
.chat-msg.system .chat-msg-bubble {
  background: var(--surface-variant);
  color: var(--on-surface-2);
  font-size: 12px;
  font-style: italic;
  border-radius: var(--radius-sm);
  text-align: center;
  padding: 6px 14px;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Bottom bar
   ============================================================ */
.bottom-bar {
  flex-shrink: 0;
  padding: 0 12px 12px;
  padding-bottom: calc(12px + var(--safe-bottom));
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 10;
}

/* Audio level */
.audio-level {
  height: 3px;
  background: var(--surface-variant);
  border-radius: 2px;
  overflow: hidden;
  opacity: 0;
  transition: opacity 250ms;
}
.audio-level.active { opacity: 1; }
.audio-level-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--success), var(--primary));
  border-radius: 2px;
  transition: width 100ms linear;
}

/* Status label */
.status-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--on-surface-3);
  text-align: center;
  min-height: 18px;
  transition: color var(--transition-fast);
}
.status-label.listening { color: var(--error); }
.status-label.thinking  { color: var(--warning); }
.status-label.speaking  { color: var(--primary); }
.status-label.error     { color: var(--error); }

/* Input row: text field + FAB */
.input-row-bottom {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Text field — Android pill style */
.text-field {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: var(--radius-xl);
  padding: 0 4px;
  min-height: 52px;
  box-shadow: var(--elevation-1);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.text-field:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.text-field input {
  flex: 1;
  border: none;
  background: none;
  padding: 12px 8px;
  font-size: 15px;
  font-family: var(--font);
  color: var(--on-surface);
  outline: none;
  min-width: 0;
}
.text-field input::placeholder { color: var(--on-surface-3); }
.text-field-btn {
  width: 40px; height: 40px;
  border: none; border-radius: var(--radius-full);
  background: none;
  font-size: 14px;
  cursor: pointer;
  color: var(--on-surface-3);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition-fast);
}
.text-field-btn:hover { background: var(--surface-variant); }
.text-field-btn.send { color: var(--primary); }

/* FAB — floating action button */
.fab {
  width: 56px; height: 56px;
  border: none; border-radius: var(--radius-full);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--elevation-2);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), background var(--transition);
  flex-shrink: 0;
  position: relative;
}
.fab:active { transform: scale(.92); }
.fab-icon { font-size: 24px; line-height: 1; }
.fab.active {
  background: var(--error);
  box-shadow: 0 4px 20px rgba(220, 38, 38, .5);
  animation: fabPulse 2s infinite;
}
@keyframes fabPulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(220, 38, 38, .5); }
  50%      { box-shadow: 0 4px 32px rgba(220, 38, 38, .75); }
}

/* Quick row */
.quick-row {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}
.chip-btn {
  font-size: 12px; font-weight: 500;
  padding: 6px 14px;
  border: none; border-radius: var(--radius-full);
  background: var(--surface-variant);
  color: var(--on-surface-2);
  cursor: pointer;
  font-family: var(--font);
  transition: background var(--transition-fast);
  white-space: nowrap;
}
.chip-btn:hover { background: var(--primary-container); color: var(--on-primary-container); }
.chip-btn:active { transform: scale(.96); }

/* Shortcuts dropdown */
.shortcuts-drop { position: relative; }
.shortcuts-drop summary { list-style: none; }
.shortcuts-drop summary::-webkit-details-marker { display: none; }
.shortcuts-popup {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 8px;
  background: var(--surface-raised);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--elevation-3);
  min-width: 260px;
  z-index: 20;
}
.shortcuts-popup .shortcuts-section {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px;
  color: var(--on-surface-3);
  margin: 8px 0 4px;
}
.shortcuts-popup .shortcuts-section:first-child { margin-top: 0; }
.shortcuts-popup ul {
  list-style: none; padding: 0; margin: 0;
  font-size: 12px;
}
.shortcuts-popup li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 3px 0; gap: 12px;
  color: var(--on-surface-2);
}
kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--surface-variant);
  color: var(--on-surface);
  white-space: nowrap;
}

/* ============================================================
   Settings sheet — slides up from bottom
   ============================================================ */
.settings-sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  animation: slideUp 300ms cubic-bezier(0.4, 0, 0.2, 1);
}
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + var(--safe-top));
  background: var(--surface);
  flex-shrink: 0;
}
.settings-header h2 { font-size: 20px; font-weight: 600; color: var(--on-surface); }
.settings-body {
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  -webkit-overflow-scrolling: touch;
}

@keyframes slideUp {
  from { transform: translateY(20%); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* Form elements */
.form-group {
  display: flex; flex-direction: column; gap: 6px;
}
.form-group label {
  font-size: 13px; font-weight: 600;
  color: var(--on-surface-2);
  display: flex; justify-content: space-between; align-items: center;
}
.form-group select,
.form-group input {
  padding: 12px 14px;
  border: 1px solid var(--surface-variant);
  border-radius: var(--radius-sm);
  font-size: 14px; font-family: var(--font);
  background: var(--surface);
  color: var(--on-surface);
  outline: none;
  transition: border-color var(--transition-fast);
  min-height: 48px;
}
.form-group select:focus,
.form-group input:focus {
  border-color: var(--primary);
}
.form-group input[type="range"] {
  padding: 0;
  min-height: auto;
  accent-color: var(--primary);
}
.input-row {
  display: flex; gap: 8px; align-items: center;
}
.input-row input { flex: 1; }
.form-row {
  display: flex; gap: 16px;
}

.link {
  font-size: 13px; color: var(--primary);
  text-decoration: none; font-weight: 500;
  background: none; border: none; cursor: pointer;
  padding: 0;
}
.link:hover { text-decoration: underline; }

.form-actions {
  display: flex; gap: 8px;
}

/* Buttons */
.btn-primary-full {
  width: 100%; padding: 14px;
  background: var(--primary); color: #fff;
  border: none; border-radius: var(--radius-xl);
  font-size: 15px; font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  min-height: 48px;
  transition: background var(--transition-fast);
}
.btn-primary-full:hover { background: var(--primary-hover); }
.btn-primary-full:active { transform: scale(.98); }

.btn-outline {
  flex: 1; padding: 10px;
  background: none; color: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--radius-full);
  font-size: 13px; font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  min-height: 40px;
  transition: background var(--transition-fast);
}
.btn-outline:hover { background: var(--primary-container); }

/* ============================================================
   Scrollbar
   ============================================================ */
.main-content::-webkit-scrollbar,
.settings-body::-webkit-scrollbar { width: 3px; }
.main-content::-webkit-scrollbar-thumb,
.settings-body::-webkit-scrollbar-thumb {
  background: var(--on-surface-3);
  border-radius: 2px;
}
.main-content::-webkit-scrollbar-track,
.settings-body::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   Desktop: slightly wider, keep mobile proportions
   ============================================================ */
@media (min-width: 481px) {
  .app-shell {
    border-left: 1px solid var(--surface-variant);
    border-right: 1px solid var(--surface-variant);
  }
  .chat-msg { max-width: 78%; }
}
