:root {
  /* ── GravityUI dark palette ── */
  --bg-deep:         #0d0d0f;
  --bg-surface:      rgba(20, 20, 23, 0.75);
  --bg-surface-solid:#141417;
  --bg-raised:       rgba(28, 28, 34, 0.65);
  --glass-border:    rgba(255, 255, 255, 0.07);

  --text-primary:    #ededed;
  --text-secondary:  #9494a8;
  --text-muted:      #52526a;

  /* ── Semantic mode accents (preserved) ── */
  --accent-morning:     #FFB020;
  --accent-morning-dim: rgba(255, 176, 32, 0.13);
  --accent-morning-glow:rgba(255, 176, 32, 0.35);

  --accent-evening:     #818CF8;
  --accent-evening-dim: rgba(129, 140, 248, 0.13);
  --accent-evening-glow:rgba(129, 140, 248, 0.35);

  --accent-coach:       #F472B6;
  --accent-coach-dim:   rgba(244, 114, 182, 0.13);
  --accent-coach-glow:  rgba(244, 114, 182, 0.35);

  --accent-blueprint:      #34D399;
  --accent-blueprint-dim:  rgba(52, 211, 153, 0.13);
  --accent-blueprint-glow: rgba(52, 211, 153, 0.35);

  --accent-weekly:      #38BDF8;
  --accent-weekly-dim:  rgba(56, 189, 248, 0.13);
  --accent-weekly-glow: rgba(56, 189, 248, 0.35);

  --accent-monthly:      #A78BFA;
  --accent-monthly-dim:  rgba(167, 139, 250, 0.13);
  --accent-monthly-glow: rgba(167, 139, 250, 0.35);

  --accent-quarterly:      #FB923C;
  --accent-quarterly-dim:  rgba(251, 146, 60, 0.13);
  --accent-quarterly-glow: rgba(251, 146, 60, 0.35);

  --accent-annual:      #FBBF24;
  --accent-annual-dim:  rgba(251, 191, 36, 0.13);
  --accent-annual-glow: rgba(251, 191, 36, 0.35);

  --accent-active:      var(--accent-morning);
  --accent-active-dim:  var(--accent-morning-dim);
  --accent-active-glow: var(--accent-morning-glow);

  /* ── GravityUI base accent (indigo) ── */
  --accent-base:     #6366f1;
  --accent-base-dim: rgba(99, 102, 241, 0.12);

  --success:         #22c55e;
  --success-dim:     rgba(34, 197, 94, 0.12);

  --voice-active:    #34D399;
  --voice-active-dim: rgba(52, 211, 153, 0.13);
  --voice-active-glow:rgba(52, 211, 153, 0.35);

  /* ── GravityUI radius scale ── */
  --r-xs: 3px;
  --r-sm: 5px;
  --r-md: 8px;
  --r-lg: 10px;
  --r-xl: 14px;
  --r-2xl:18px;

  --app-height: 100dvh;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-deep);
  color: var(--text-primary);
  height: var(--app-height);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Base Layout */
.app-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  background: radial-gradient(circle at top left, rgba(20, 20, 30, 0.4) 0%, transparent 40%),
              radial-gradient(circle at bottom right, rgba(20, 20, 30, 0.3) 0%, transparent 50%);
}

/* ──────────────────────────────────────────────────────────
 * App Header
 * ────────────────────────────────────────────────────────── */
.app-header {
  height: 72px;
  background: var(--bg-surface-solid);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  z-index: 10;
  box-shadow: 0 4px 24px rgba(0,0,0,0.1);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-mark {
  width: 36px;
  height: 36px;
  border-radius: var(--r-lg);
  background: linear-gradient(135deg, var(--accent-morning), var(--accent-evening));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  color: #fff;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.logo h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.logo h1 span {
  color: var(--text-secondary);
  font-weight: 400;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-pill {
  font-size: 11.5px;
  font-family: 'JetBrains Mono', monospace;
  padding: 6px 12px;
  border-radius: var(--r-md);
  background: var(--bg-raised);
  color: var(--text-secondary);
  border: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-save {
  background: var(--success-dim);
  color: var(--success);
  border-color: rgba(16, 185, 129, 0.3);
  box-shadow: 0 0 15px rgba(16, 185, 129, 0.1);
  animation: fadeIn 0.4s ease;
}

/* ──────────────────────────────────────────────────────────
 * Voice Toggle Button (header)
 * ────────────────────────────────────────────────────────── */
.voice-toggle {
  width: 34px;
  height: 34px;
  border-radius: var(--r-md);
  border: 1px solid var(--glass-border);
  background: var(--bg-raised);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.voice-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
}

.voice-toggle.active {
  background: var(--voice-active-dim);
  color: var(--voice-active);
  border-color: rgba(52, 211, 153, 0.3);
  box-shadow: 0 0 12px var(--voice-active-glow);
}

.voice-toggle .voice-icon-off { display: block; }
.voice-toggle .voice-icon-on { display: none; }
.voice-toggle.active .voice-icon-off { display: none; }
.voice-toggle.active .voice-icon-on { display: block; }

/* Clear session button */
.clear-session-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--r-md);
  border: 1px solid var(--glass-border);
  background: var(--bg-raised);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.clear-session-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
}

/* Voice settings link */
.voice-settings-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--r-md);
  border: 1px solid var(--glass-border);
  background: var(--bg-raised);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: all 0.2s ease;
}

.voice-settings-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
}

/* ──────────────────────────────────────────────────────────
 * Main Chat Area
 * ────────────────────────────────────────────────────────── */
.chat-container {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: transparent;
}

.chat-scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 40px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  scroll-behavior: smooth;
}

/* Custom Scrollbar */
.chat-scroll-area::-webkit-scrollbar { width: 6px; }
.chat-scroll-area::-webkit-scrollbar-track { background: transparent; }
.chat-scroll-area::-webkit-scrollbar-thumb { 
  background: rgba(255,255,255,0.1); 
  border-radius: 3px; 
}

.welcome-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
  animation: fadeIn 0.6s ease;
  padding-bottom: 60px; /* offset for chips */
}

.welcome-icon {
  font-size: 48px;
  color: var(--text-muted);
  opacity: 0.3;
}

.welcome-screen h2 {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-secondary);
}

.welcome-screen p {
  color: var(--text-muted);
  max-width: 300px;
  line-height: 1.5;
}

/* Messages */
.message {
  max-width: 760px;
  padding: 16px 20px;
  line-height: 1.6;
  font-size: 15px;
  animation: slideUpFade 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  opacity: 0;
  margin: 0 auto;
  width: 100%;
}

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

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.message.user {
  margin-left: auto;
  margin-right: max(calc(50% - 380px), 20px);
  background: var(--bg-raised);
  border: 1px solid var(--glass-border);
  border-radius: 16px 16px 4px 16px;
  color: var(--text-primary);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.message.assistant {
  margin-right: auto;
  margin-left: max(calc(50% - 380px), 20px);
  background: linear-gradient(145deg, var(--accent-active-dim), rgba(255,255,255,0.02));
  border: 1px solid rgba(255,255,255,0.04);
  border-radius: 16px 16px 16px 4px;
  color: var(--text-primary);
  box-shadow: 0 4px 24px rgba(0,0,0,0.15);
  position: relative;
}

.message.assistant::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  border-radius: inherit;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
  pointer-events: none;
}

.message.assistant p { margin-bottom: 12px; }
.message.assistant p:last-child { margin-bottom: 0; }
.message.assistant strong { font-weight: 600; color: #fff; }
.message.assistant em { font-style: italic; color: #d4d4db; }
.message.assistant ul, .message.assistant ol { margin-left: 20px; margin-bottom: 12px; }

/* Old History Modifier */
.message.old-history {
  color: var(--text-muted);
  font-style: italic;
}
.message.user.old-history {
  background: rgba(26, 26, 35, 0.3);
  border-color: rgba(255, 255, 255, 0.02);
}
.message.assistant.old-history {
  background: rgba(255, 255, 255, 0.01);
  border-color: rgba(255, 255, 255, 0.02);
}
.message.assistant.old-history strong { color: var(--text-secondary); }
.message.assistant.old-history em { color: var(--text-muted); }

.message.system {
  margin: 10px auto;
  background: var(--bg-raised);
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 100px;
  text-align: center;
  max-width: fit-content;
}

.message.system.success {
  background: var(--success-dim);
  color: var(--success);
  border-color: rgba(16, 185, 129, 0.2);
}

/* Typing Indicator */
.typing-indicator {
  margin-right: auto;
  margin-left: max(calc(50% - 380px), 20px);
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 16px 20px;
  background: var(--accent-active-dim);
  border-radius: 20px 20px 20px 4px;
  animation: fadeIn 0.3s;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--active-accent);
  opacity: 0.6;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); opacity: 1; box-shadow: 0 0 8px var(--active-accent-glow); }
}

/* ──────────────────────────────────────────────────────────
 * Input Area & Mode Chips
 * ────────────────────────────────────────────────────────── */
.input-container {
  padding: 0 40px 40px;
  background: linear-gradient(to top, var(--bg-deep) 60%, transparent);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.mode-chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
  justify-content: center;
}

.mode-chip {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-xl);
  padding: 8px 16px;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.mode-chip:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  transform: translateY(-2px);
}

.mode-chip.active {
  color: var(--text-primary);
  border-color: rgba(255,255,255,0.1);
}

.mode-chip.planday.active   { background: var(--accent-morning-dim);   box-shadow: 0 0 12px var(--accent-morning-glow);   border-color: var(--accent-morning); }
.mode-chip.closeday.active  { background: var(--accent-evening-dim);   box-shadow: 0 0 12px var(--accent-evening-glow);   border-color: var(--accent-evening); }
.mode-chip.coaching.active  { background: var(--accent-coach-dim);     box-shadow: 0 0 12px var(--accent-coach-glow);     border-color: var(--accent-coach); }
.mode-chip.blueprint.active { background: var(--accent-blueprint-dim); box-shadow: 0 0 12px var(--accent-blueprint-glow); border-color: var(--accent-blueprint); }
.mode-chip.weekly.active    { background: var(--accent-weekly-dim);    box-shadow: 0 0 12px var(--accent-weekly-glow);    border-color: var(--accent-weekly); }
.mode-chip.monthly.active   { background: var(--accent-monthly-dim);   box-shadow: 0 0 12px var(--accent-monthly-glow);   border-color: var(--accent-monthly); }
.mode-chip.quarterly.active { background: var(--accent-quarterly-dim); box-shadow: 0 0 12px var(--accent-quarterly-glow); border-color: var(--accent-quarterly); }
.mode-chip.annual.active    { background: var(--accent-annual-dim);    box-shadow: 0 0 12px var(--accent-annual-glow);    border-color: var(--accent-annual); }

.mode-chip .icon { font-size: 15px; filter: grayscale(1) opacity(0.7); }
.mode-chip.active .icon { filter: grayscale(0) opacity(1); }

.input-wrapper {
  width: 100%;
  max-width: 800px;
  position: relative;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-2xl);
  padding: 4px;
  display: flex;
  align-items: flex-end;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  transition: border-color 0.3s, box-shadow 0.3s;
}

.input-wrapper:focus-within {
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.05);
}

textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 16px;
  line-height: 1.5;
  padding: 16px 20px;
  resize: none;
  min-height: 56px;
  max-height: 200px;
  outline: none;
}

textarea::placeholder { color: var(--text-muted); }

.input-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
}

.action-btn {
  border: none;
  border-radius: var(--r-lg);
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.send-btn {
  width: 40px;
  height: 40px;
  background: var(--active-accent);
  color: #000;
  box-shadow: 0 4px 12px var(--active-accent-glow);
}

.send-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px var(--active-accent-glow);
}

.send-btn:disabled {
  background: var(--bg-raised);
  color: var(--text-muted);
  box-shadow: none;
  cursor: not-allowed;
}

.save-btn {
  padding: 0 16px;
  height: 40px;
  background: var(--success-dim);
  color: var(--success);
  font-size: 14px;
}

.save-btn:hover {
  background: rgba(16, 185, 129, 0.25);
  transform: translateY(-2px);
}

/* ──────────────────────────────────────────────────────────
 * Mic Button
 * ────────────────────────────────────────────────────────── */
.mic-btn {
  width: 40px;
  height: 40px;
  background: var(--bg-raised);
  color: var(--text-secondary);
  border: 1px solid var(--glass-border);
  border-radius: 50%;
  position: relative;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

.mic-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.mic-btn .mic-icon-active { display: none; }
.mic-btn .mic-icon-default { display: block; }

/* Recording state */
.mic-btn.recording {
  background: rgba(239, 68, 68, 0.2);
  color: #EF4444;
  border-color: rgba(239, 68, 68, 0.4);
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
  animation: micPulse 1.5s ease-in-out infinite;
}

.mic-btn.recording .mic-icon-active { display: block; }
.mic-btn.recording .mic-icon-default { display: none; }

@keyframes micPulse {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* Stop audio button */
.stop-audio-btn {
  width: 40px;
  height: 40px;
  background: rgba(239, 68, 68, 0.15);
  color: #EF4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 50%;
}

.stop-audio-btn:hover {
  background: rgba(239, 68, 68, 0.25);
}

/* ──────────────────────────────────────────────────────────
 * Voice Status Indicator
 * ────────────────────────────────────────────────────────── */
.voice-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 6px 14px;
  border-radius: 100px;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-secondary);
  background: var(--bg-raised);
  border: 1px solid var(--glass-border);
  max-width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.voice-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-muted);
}

.voice-status.listening .voice-status-dot {
  background: #EF4444;
  animation: statusPulse 1s ease-in-out infinite;
}

.voice-status.processing .voice-status-dot {
  background: var(--active-accent);
  animation: statusPulse 0.6s ease-in-out infinite;
}

.voice-status.speaking .voice-status-dot {
  background: var(--voice-active);
  animation: statusPulse 1.2s ease-in-out infinite;
}

.voice-status.error .voice-status-dot {
  background: #EF4444;
}

@keyframes statusPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.7); }
}

/* Discrete Token Counter */
.discrete-token-counter {
  margin-top: 12px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  opacity: 0.5;
  text-align: center;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.5px;
  transition: opacity 0.3s ease;
}

.discrete-token-counter:hover {
  opacity: 1;
}

/* ──────────────────────────────────────────────────────────
 * Responsive — Mobile First
 * ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-header {
    padding: 0 16px;
    height: 60px;
  }
  .logo h1 span { display: none; }
  .logo-mark { width: 34px; height: 34px; font-size: 18px; border-radius: 10px; }
  .logo h1 { font-size: 17px; }

  .status-pill.status-date {
    font-size: 12px;
    padding: 7px 12px;
  }

  /* Bigger header touch targets */
  .clear-session-btn,
  .voice-settings-btn,
  .voice-toggle {
    width: 44px;
    height: 44px;
    border-radius: var(--r-lg);
  }

  .chat-scroll-area { padding: 16px; gap: 16px; }
  .input-container { padding: 0 12px 20px; }

  /* Mode chips — full-width rows, tall enough to tap easily */
  .mode-chips-container {
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 800px;
  }
  .mode-chip {
    justify-content: center;
    padding: 13px 20px;
    font-size: 14.5px;
    border-radius: var(--r-xl);
  }
  .mode-chip .icon { font-size: 18px; }

  .message { padding: 14px 16px; font-size: 15px; }
  .message.user, .message.assistant { margin-left: 0; margin-right: 0; }
  .typing-indicator { margin-left: 0; }

  .input-wrapper { border-radius: var(--r-2xl); }
  textarea { padding: 16px; font-size: 16px; min-height: 56px; }

  /* Send & stop buttons */
  .send-btn,
  .stop-audio-btn {
    width: 48px;
    height: 48px;
  }

  /* Mic button — large and prominent on mobile */
  .mic-btn {
    width: 56px;
    height: 56px;
    background: var(--voice-active-dim);
    color: var(--voice-active);
    border-color: rgba(52, 211, 153, 0.35);
    box-shadow: 0 0 16px var(--voice-active-glow);
    border-radius: 50%;
  }
  .mic-btn:active,
  .mic-btn.recording {
    background: rgba(239, 68, 68, 0.2);
    color: #EF4444;
    border-color: rgba(239, 68, 68, 0.5);
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.4);
  }
  .mic-btn svg {
    width: 24px;
    height: 24px;
  }
}

/* Extra small phones */
@media (max-width: 380px) {
  .app-header { padding: 0 12px; }
  .chat-scroll-area { padding: 12px; }
  .input-container { padding: 0 8px 16px; }
  .mode-chip { padding: 12px 16px; font-size: 14px; }
}

/* PWA safe area insets for notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
  .app-header {
    padding-top: env(safe-area-inset-top);
    height: calc(56px + env(safe-area-inset-top));
  }
}
