/* =============================================================================
 * CarveAI end-user webapp — unified design system.
 *
 * Tokens mirror the manager dashboard so both surfaces feel like one product.
 * Principles encoded here come from the project ui-design skill:
 *  - tinted neutrals, never pure black / pure gray
 *  - strict 4px spacing grid, strict type scale
 *  - custom cubic-bezier easings (CSS defaults are too weak)
 *  - buttons scale(0.97) on :active; popovers animate from their origin
 *  - hover effects gated behind @media (hover: hover)
 *  - visible :focus-visible rings, never stripped without a replacement
 * ============================================================================= */

/* ---------- Self-hosted fonts ---------- */
/* Inter + JetBrains Mono served from /static/fonts so a corporate firewall
 * blocking fonts.googleapis.com / fonts.gstatic.com (or a privacy-strict
 * browser like Firefox with Enhanced Tracking) can't strip the page back
 * to a system-font fallback that resizes every button. Variable woff2
 * with all wght values; Google Fonts is kept as a CDN fallback in
 * `src` for the small chance our local file 404s in some environment. */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/static/fonts/inter-latin.woff2') format('woff2'),
       url('https://fonts.gstatic.com/s/inter/v20/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa1ZL7W0Q5nw.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url('/static/fonts/jetbrains-mono-latin.woff2') format('woff2'),
       url('https://fonts.gstatic.com/s/jetbrainsmono/v24/tDbv2o-flEEny0FZhsfKu5WU4zr3E_BX0PnT8RD8yKwBNntkaToggR7BYRbKPxDcwgknk-4.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- Tokens — LIGHT (default) ---------- */

:root {
  /* Surfaces — warm-tinted off-white rather than #FFF, feels less clinical */
  --bg:            #FAFAF9;
  --surface:       #FFFFFF;
  --surface-subtle:#F3F3F1;
  --surface-raised:#FFFFFF;
  --border:        #E7E5E4;
  --border-strong: #D6D3D1;

  /* Text */
  --text:          #18181B;
  --text-muted:    #52525B;
  --text-mute:     #71717A;

  /* Accent — indigo (primary) + violet (secondary, used in brand gradients) */
  --accent:        #4F46E5;
  --accent-hover:  #4338CA;
  --accent-soft:   #EEF2FF;
  --accent-2:      #8B5CF6;

  /* Semantic */
  --success:       #059669;
  --success-soft:  rgba(5, 150, 105, 0.10);
  --warning:       #D97706;
  --warning-soft:  rgba(217, 119, 6, 0.10);
  --danger:        #DC2626;
  --danger-soft:   rgba(220, 38, 38, 0.10);

  /* Shadows — blur = 2× distance (Hobday rule #19). Soft alpha on light. */
  --shadow-sm: 0 1px 2px rgba(24, 24, 27, 0.04);
  --shadow-md: 0 4px 8px rgba(24, 24, 27, 0.08);
  --shadow-lg: 0 16px 32px rgba(24, 24, 27, 0.14);

  /* Type scale */
  --text-xs:    12px;
  --text-sm:    13px;
  --text-base:  14px;
  --text-md:    16px;  /* Hobday #7: body/reading text ≥ 16px */
  --text-lg:    18px;
  --text-xl:    20px;
  --text-2xl:   24px;
  --text-3xl:   32px;
  --text-4xl:   40px;

  /* Spacing — 4px grid */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-7:  28px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Radii */
  --radius-xs:   4px;
  --radius-sm:   6px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --radius-xl:   16px;
  --radius-2xl:  20px;
  --radius-full: 999px;

  /* Motion — Emil Kowalski's strong curves */
  --ease-out:    cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  --dur-fast:    120ms;
  --dur-base:    180ms;
  --dur-slow:    260ms;
  --dur-modal:   320ms;

  /* Layout */
  --topnav-height: 56px;
  --sidebar-width: 260px;
  --chat-max:      780px;
  --page-max:      880px;
  --settings-max:  720px;
}

/* ---------- Tokens — DARK ---------- */

html.dark {
  --bg:            #0A0A0C;
  --surface:       #141418;
  --surface-subtle:#1B1B21;
  --surface-raised:#1F1F26;
  --border:        #2A2A33;
  --border-strong: #3A3A46;

  --text:          #F4F4F5;
  --text-muted:    #A1A1AA;
  --text-mute:     #71717A;

  --accent:        #818CF8;
  --accent-hover:  #A5B4FC;
  --accent-soft:   rgba(129, 140, 248, 0.14);
  --accent-2:      #A78BFA;

  --success:       #34D399;
  --success-soft:  rgba(52, 211, 153, 0.14);
  --warning:       #FBBF24;
  --warning-soft:  rgba(251, 191, 36, 0.14);
  --danger:        #F87171;
  --danger-soft:   rgba(248, 113, 113, 0.14);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 32px rgba(0, 0, 0, 0.55);
}

/* ---------- Reset + base ---------- */

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: var(--text-base);
  font-feature-settings: "cv02", "cv03", "cv04", "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

code, pre {
  font-family: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
  font-size: 0.92em;
}

/* Numeric content — digits stop jittering between rows */
.tnum {
  font-variant-numeric: tabular-nums;
}

/* Interactive chrome: never selectable. Prevents accidental text selection
   on double-click or drag, and signals "this is a control" (Rauno). */
button, [role="button"], .navtab, .session-item, .session-group-label,
.chip, .pill, .prompt-tile, .palette-item, .theme-btn, .wizard-dot, .avatar {
  user-select: none;
}

/* :focus-visible — never stripped without a replacement */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Strip focus rings from buttons/inputs only for non-keyboard focus */
button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
textarea:focus:not(:focus-visible),
select:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
  outline: none;
}

/* ---------- Scrollbar — subtle, minimal ---------- */

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-mute);
}

/* ---------- Typography helpers ---------- */

.text-display {
  font-weight: 600;
  font-size: var(--text-4xl);
  letter-spacing: -0.025em;
  line-height: 1.05;
}
.text-page-title {
  font-weight: 600;
  font-size: var(--text-2xl);
  letter-spacing: -0.015em;
  line-height: 1.2;
}
.text-section {
  font-weight: 500;
  font-size: var(--text-lg);
  letter-spacing: -0.005em;
  line-height: 1.3;
}
.text-muted {
  color: var(--text-muted);
}
.text-micro {
  font-size: var(--text-xs);
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 500;
}

/* ---------- Surfaces ---------- */

.surface {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.surface-subtle {
  background: var(--surface-subtle);
  border-radius: var(--radius-lg);
}

.divider {
  height: 1px;
  background: var(--border);
  width: 100%;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: var(--text-base);
  padding: 8px 16px;
  min-height: 36px;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  font-family: inherit;
  background: transparent;
  color: var(--text);
  transition: background-color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}

/* Tactile press feedback — signals "the UI is listening" */
.btn:active:not(:disabled) { transform: scale(0.97); }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: var(--shadow-md);
  }
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

@media (hover: hover) and (pointer: fine) {
  .btn-secondary:hover:not(:disabled) {
    background: var(--surface-subtle);
    border-color: var(--border-strong);
  }
}

.btn-ghost {
  background: transparent;
  color: var(--text);
}

@media (hover: hover) and (pointer: fine) {
  .btn-ghost:hover:not(:disabled) {
    background: var(--surface-subtle);
  }
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

@media (hover: hover) and (pointer: fine) {
  .btn-danger:hover:not(:disabled) {
    filter: brightness(0.92);
  }
}

.btn-sm {
  font-size: var(--text-sm);
  padding: 6px 12px;
  min-height: 30px;
}
.btn-lg {
  font-size: var(--text-md);
  padding: 10px 20px;
  min-height: 42px;
}

/* ---------- Inputs ---------- */

.input, .textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: var(--text-base);
  color: var(--text);
  font-family: inherit;
  min-height: 40px;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.input::placeholder, .textarea::placeholder {
  color: var(--text-mute);
}
.input:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.textarea {
  resize: none;
  line-height: 1.55;
}

/* ---------- Top nav ---------- */

.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px var(--space-5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--topnav-height);
  flex-shrink: 0;
}
.topnav-left {
  display: flex;
  align-items: center;
  gap: var(--space-7);
}
.brand {
  font-weight: 600;
  font-size: var(--text-md);
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text);
}
.brand-mark {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: var(--text-sm);
  letter-spacing: -0.02em;
  flex-shrink: 0;
}
.navtabs {
  display: flex;
  gap: 2px;
}
.navtab {
  padding: 7px var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  color: var(--text-muted);
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: transparent;
  font-family: inherit;
  min-height: 32px;
  transition: background-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .navtab:hover {
    background: var(--surface-subtle);
    color: var(--text);
  }
}

.navtab.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- Chat layout ---------- */

.chat-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  flex: 1;
  overflow: hidden;
}

.sessions-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.session-item {
  padding: 10px var(--space-4);
  border-radius: var(--radius-md);
  cursor: pointer;
  margin: 2px var(--space-2);
  font-size: var(--text-sm);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
  line-height: 1.45;
  min-height: 38px;
  color: var(--text);
  transition: background-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .session-item:hover {
    background: var(--surface-subtle);
  }
}

.session-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}

/* Pending / new-reply states. has-inbox: a reply landed while user was in
 * a different session — small accent dot. is-pending: a turn is in flight
 * for this session — pulsing dot. Visual hierarchy: pending > inbox. */
.session-item.has-inbox:not(.active) .session-item-title {
  font-weight: 500;
  color: var(--text);
}
.session-item.is-pending .session-item-title {
  color: var(--text-muted);
  font-style: italic;
}

.session-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-item-status {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  margin-left: 4px;
  margin-top: 4px;
}

/* Hover-reveal action row inside a session-item — rename + delete.
 * Only visible on hover (desktop) or on the active session (always
 * useful). Mirrors ChatGPT's per-conversation action menu without the
 * extra dropdown layer; keyboards see the buttons via tab order. */
.session-item-actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 6px;
  margin-top: 2px;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-out);
  flex-shrink: 0;
}
@media (hover: hover) and (pointer: fine) {
  .session-item:hover .session-item-actions {
    opacity: 1;
  }
}
.session-item.active .session-item-actions {
  opacity: 1;
}
.session-act-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .session-act-btn:hover {
    background: color-mix(in srgb, var(--text) 8%, transparent);
    color: var(--text);
  }
  .session-act-btn.session-act-danger:hover {
    background: var(--danger-soft);
    color: var(--danger);
  }
}
.session-act-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
@media (hover: none) {
  .session-item-actions { opacity: 0.6; }
}
.session-pulse,
.session-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.session-pulse {
  background: var(--accent);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 50%, transparent);
  animation: session-pulse 1.4s var(--ease-in-out) infinite;
}
@keyframes session-pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 50%, transparent);
  }
  50% {
    transform: scale(1.15);
    box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 0%, transparent);
  }
}
@media (prefers-reduced-motion: reduce) {
  .session-pulse { animation: none; }
}

.session-group-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: var(--text-mute);
  padding: var(--space-4) var(--space-5) 6px var(--space-5);
}

/* ---------- Chat main ---------- */

.chat-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-7) 0 var(--space-4) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.chat-container {
  max-width: var(--chat-max);
  margin: 0 auto;
  width: 100%;
  padding: 0 var(--space-6);
  display: flex;
  flex-direction: column;
  /* Tightened from --space-5 (20px) to --space-4 (16px) — denser
   * conversation flow, less feel-of-blocks-stacked. */
  gap: var(--space-4);
}

.bubble-row {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  animation: bubble-in var(--dur-slow) var(--ease-out);
}
.bubble-row.user {
  flex-direction: row-reverse;
}

/* Smaller, lighter avatar reads as identity affordance, not a UI element
 * fighting for attention with the bubble itself. 28px is the iMessage-ish
 * size that doesn't dominate. */
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
  color: #fff;
  user-select: none;
}
.avatar-assistant {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  box-shadow: var(--shadow-sm);
}
.avatar-user {
  background: var(--surface-subtle);
  color: var(--text);
  border: 1px solid var(--border);
}

/*
 * Bubble redesign (2026-04-28): the previous tail-cut on one corner read
 * as "blocky" — at radius-xs (4px) the tail looked clipped rather than
 * speech-bubble-like. Modern chat surfaces (Claude.ai, ChatGPT, Linear)
 * use uniform rounded corners. We follow that:
 *   - radius: --radius-2xl (20px) on every corner
 *   - subtle shadow on assistant bubble for lift
 *   - removed white-space: pre-wrap; markdown renderer handles paragraph
 *     breaks; pre-wrap was injecting extra blank lines from raw newlines
 *     in the streaming output
 *   - vertical padding bumped to 14px for breathing room
 */
.bubble {
  max-width: min(680px, 88%);
  padding: 14px var(--space-5);
  border-radius: var(--radius-2xl);
  font-size: var(--text-md);
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  position: relative;
}
.bubble.assistant {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.bubble.user {
  background: var(--accent);
  color: #fff;
  border: 1px solid color-mix(in srgb, var(--accent) 80%, transparent);
}
.bubble.clarifying {
  border: 1px dashed var(--border-strong);
  background: var(--surface-subtle);
  color: var(--text-muted);
  font-style: italic;
}
.bubble.system {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  font-size: var(--text-sm);
  max-width: 100%;
  text-align: center;
  font-style: italic;
}
.bubble p { margin: 0 0 var(--space-3) 0; }
.bubble p:last-child { margin: 0; }
.bubble ul, .bubble ol {
  margin: 0 0 var(--space-3) 0;
  padding-left: 1.4em;
}
.bubble li { margin: 0 0 4px 0; }
.bubble li:last-child { margin: 0; }
.bubble h1, .bubble h2, .bubble h3 {
  margin: var(--space-3) 0 var(--space-2) 0;
  font-weight: 600;
  line-height: 1.3;
}
.bubble h1 { font-size: 1.15em; }
.bubble h2 { font-size: 1.08em; }
.bubble h3 { font-size: 1.02em; }
.bubble h1:first-child, .bubble h2:first-child, .bubble h3:first-child { margin-top: 0; }
/* Code blocks inside bubbles — theme-aware via surface-subtle, not raw black.
 * The renderer wraps fenced code in a .code-block container with a header
 * strip showing language + copy button (Claude.ai / ChatGPT pattern). */
.bubble .code-block {
  margin: var(--space-3) 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
}
.bubble.user .code-block {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.10);
}
.bubble .code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: color-mix(in srgb, var(--text) 4%, var(--surface-subtle));
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
  user-select: none;
}
.bubble.user .code-block-header {
  background: rgba(0, 0, 0, 0.10);
  border-bottom-color: rgba(255, 255, 255, 0.12);
}
.bubble .code-lang {
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: lowercase;
  font-family: var(--font-mono, ui-monospace, "SF Mono", Menlo, monospace);
}
.bubble.user .code-lang {
  color: rgba(255, 255, 255, 0.7);
}
.bubble .code-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .bubble .code-copy-btn:hover {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
  }
}
.bubble.user .code-copy-btn {
  color: rgba(255, 255, 255, 0.75);
}
@media (hover: hover) and (pointer: fine) {
  .bubble.user .code-copy-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.25);
  }
}
.bubble .code-copy-btn.copied {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 30%, var(--border));
}
.bubble.user .code-copy-btn.copied {
  color: #fff;
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.3);
}

/* Pre/code body: no border, since the wrapper has the border now. */
.bubble .code-block pre {
  margin: 0;
  padding: 12px 14px;
  background: transparent;
  border-radius: 0;
  overflow-x: auto;
  font-size: 0.92em;
  line-height: 1.55;
}
/* Legacy fallback — bubbles that don't go through the new renderer. */
.bubble pre:not(.code-block pre) {
  background: var(--surface-subtle);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: var(--space-2) 0;
  font-size: 0.92em;
  line-height: 1.5;
}
.bubble.user pre:not(.code-block pre) {
  background: rgba(255, 255, 255, 0.14);
}
.bubble code:not(pre code) {
  background: var(--surface-subtle);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.9em;
}
.bubble.user code:not(pre code) {
  background: rgba(255, 255, 255, 0.20);
}

.bubble-meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
  padding: 0 var(--space-1);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-out);
}

/*
 * Tool badge — always-visible chip above an assistant bubble showing
 * which specialist (if any) produced the reply. Pattern borrowed from
 * ChatGPT's "Searched 5 websites" / "Used DALL-E" affordance and
 * Perplexity's source-card row. The "handled by your X agent" hover-
 * meta footnote was easy to miss; this is a primary affordance.
 */
.tool-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  align-self: flex-start;
  padding: 3px 9px;
  margin-bottom: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.01em;
  user-select: none;
  white-space: nowrap;
}
.tool-badge-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tool-badge-text strong {
  font-weight: 600;
  text-transform: capitalize;
}

/*
 * Bubble actions row (Copy + specialist meta) — hover-reveal on desktop,
 * always-visible on touch (no hover state). Sits below the bubble in the
 * same column so it doesn't push the bubble width around. Mirrors
 * Claude.ai / ChatGPT pattern.
 */
.bubble-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-1);
  padding: 0 4px;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-out);
}

.bubble-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-family: inherit;
  cursor: pointer;
  user-select: none;
  transition: background-color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .bubble-action-btn:hover {
    background: var(--surface-subtle);
    border-color: var(--border);
    color: var(--text);
  }
}

.bubble-action-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.bubble-action-btn.copied {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 30%, var(--border));
  background: var(--success-soft);
}

.bubble-action-meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-style: italic;
}

/* Touch: always show — no hover to discover the affordance */
@media (hover: none) {
  .bubble-actions { opacity: 1; }
}

/*
 * Follow-up suggestion chips — appear only under the LAST assistant
 * reply. Click sends as the next user message. Perplexity/Claude.ai
 * pattern: surface the question users probably want to ask next so
 * they don't have to type "tell me more" themselves.
 */
.follow-up-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  padding: 0 4px;
  animation: bubble-in var(--dur-base) var(--ease-out);
}
.follow-up-chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-xs);
  font-family: inherit;
  cursor: pointer;
  user-select: none;
  transition: background-color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .follow-up-chip:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
  }
}
.follow-up-chip:active { transform: scale(0.97); }
.follow-up-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {
  .bubble-row:hover .bubble-meta { opacity: 1; }
  .bubble-row:hover .bubble-actions { opacity: 1; }
}

/* Start from scale(0.98) + 6px offset — nothing ever appears from scale(0) */
@keyframes bubble-in {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/*
 * Inbox banner — surfaces "reply ready in another session" notifications
 * at the top of chat-main when a response landed for a session the user
 * has navigated away from. Mirrors the Slack/Discord pattern of "your
 * other channel has activity" without being modal/blocking. Click Open
 * to jump; click × to dismiss without jumping.
 */
.inbox-banner {
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--accent) 6%, var(--surface));
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.inbox-banner-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px var(--space-6);
  font-size: var(--text-sm);
  animation: inbox-in var(--dur-base) var(--ease-out);
}
@keyframes inbox-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.inbox-banner-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  flex-shrink: 0;
}
.inbox-banner-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.inbox-banner-title {
  color: var(--text);
  font-size: var(--text-sm);
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.inbox-banner-title strong {
  font-weight: 600;
}
.inbox-banner-pill {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-style: italic;
}
.inbox-banner-snippet {
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.inbox-banner-action {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 5px 12px;
  font-size: var(--text-xs);
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color var(--dur-fast) var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .inbox-banner-action:hover { background: var(--accent-hover); }
}
.inbox-banner-dismiss {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  transition: background-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .inbox-banner-dismiss:hover {
    background: color-mix(in srgb, var(--text) 8%, transparent);
    color: var(--text);
  }
}

/* Day separators — slim text divider when consecutive messages span days.
 * Slack/Linear pattern. Centered, all-caps-vibe via letter-spacing, low
 * contrast so it reads as wayfinding chrome, not a message. */
.day-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: var(--space-3) 0 var(--space-2) 0;
  user-select: none;
}
.day-separator::before,
.day-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
  max-width: 100px;
}

/* Scroll-to-bottom pill — appears when the user has scrolled up and
 * a new message arrives. Click to follow. Sits centered above the
 * composer; chat-main has overflow:hidden + position:relative for the
 * fixed-relative pin to work. */
.scroll-to-bottom {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  color: var(--text);
  font-size: var(--text-xs);
  cursor: pointer;
  user-select: none;
  z-index: 4;
  animation: scroll-pill-in var(--dur-base) var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .scroll-to-bottom:hover {
    border-color: var(--accent);
    color: var(--accent);
  }
}
@keyframes scroll-pill-in {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- Typing indicator ---------- */

/*
 * Thinking indicator (2026-04-28 redesign)
 * ----------------------------------------
 * Replaced the legacy 3-pulsing-dots-in-a-bubble pattern with a Claude.ai-
 * style ambient indicator: the C avatar gently breathes (scale + halo),
 * and a "Thinking..." text label fades its trailing dots. Reads as "I'm
 * working on it" rather than retro-IM "I'm typing." Bubble border is
 * dropped on the thinking-row so the indicator feels ambient, not a
 * placeholder card.
 */
.thinking-row {
  align-items: center;
}
.avatar.pulse {
  animation: avatar-breathe 1.6s var(--ease-in-out) infinite;
}
@keyframes avatar-breathe {
  0%, 100% {
    transform: scale(1);
    box-shadow:
      0 0 0 0 color-mix(in srgb, var(--accent) 30%, transparent),
      var(--shadow-sm);
  }
  50% {
    transform: scale(1.05);
    box-shadow:
      0 0 0 6px color-mix(in srgb, var(--accent) 8%, transparent),
      var(--shadow-sm);
  }
}

.thinking-text {
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-style: italic;
  display: inline-flex;
  align-items: center;
  gap: 1px;
  padding: 6px 0;
  letter-spacing: 0.01em;
}
.thinking-dots {
  display: inline-flex;
  width: 1.2em;
  margin-left: 2px;
  letter-spacing: 0.05em;
}
.thinking-dots span {
  opacity: 0;
  animation: thinking-dot 1.4s var(--ease-in-out) infinite;
}
.thinking-dots span:nth-child(1) { animation-delay: 0s; }
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes thinking-dot {
  0%, 60%, 100% { opacity: 0; }
  30%           { opacity: 1; }
}

/* Reduced-motion: kill the breathe and dot stagger but keep the text
 * label so screen readers + low-motion users still see "Thinking…". */
@media (prefers-reduced-motion: reduce) {
  .avatar.pulse { animation: none; }
  .thinking-dots span { animation: none; opacity: 0.7; }
}

/* ---------- Composer ---------- */

.composer {
  padding: var(--space-4) var(--space-6) var(--space-6) var(--space-6);
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.composer-inner {
  max-width: var(--chat-max);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.composer-box {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 10px 12px;
  transition: border-color var(--dur-base) var(--ease-out),
              box-shadow var(--dur-base) var(--ease-out);
}
.composer-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}
.composer textarea {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  resize: none;
  font-size: var(--text-md);
  color: var(--text);
  line-height: 1.55;
  padding: 6px var(--space-1);
  font-family: inherit;
  max-height: 220px;
}
.composer-send {
  /* Nested radius = outer (16) − gap (~10px inner padding) = 6px — Hobday #14 */
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 0;
  background: var(--accent);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}
.composer-send:disabled {
  background: var(--border-strong);
  cursor: not-allowed;
}
.composer-send:active:not(:disabled) { transform: scale(0.94); }

@media (hover: hover) and (pointer: fine) {
  .composer-send:hover:not(:disabled) {
    background: var(--accent-hover);
  }
}

/* Stop variant — replaces Send while a turn is in flight. ChatGPT pattern:
 * same footprint, swapped icon, contrast color so it reads as cancel. */
.composer-send.composer-stop {
  background: var(--text);
  color: var(--surface);
}
@media (hover: hover) and (pointer: fine) {
  .composer-send.composer-stop:hover {
    background: var(--text-muted);
  }
}

.composer-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
  padding: 0 6px;
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.btn-linklike {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-size: var(--text-xs);
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  transition: opacity var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .btn-linklike:hover:not(:disabled) { opacity: 0.75; }
}

.btn-linklike:disabled {
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.55;
}

/* ---------- Empty states ---------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-16) var(--space-6);
  color: var(--text-muted);
  animation: empty-in var(--dur-slow) var(--ease-out);
}

@keyframes empty-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.empty-state .emoji {
  font-size: 36px;
  margin-bottom: var(--space-4);
  opacity: 0.9;
}
.empty-state h3 {
  font-size: var(--text-xl);
  color: var(--text);
  margin: 0 0 var(--space-2) 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.empty-state p {
  max-width: 420px;
  line-height: 1.6;
  margin: 0 0 var(--space-6) 0;
  font-size: var(--text-base);
}
.suggested-prompts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 560px;
  width: 100%;
}
.prompt-tile {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  cursor: pointer;
  font-size: var(--text-base);
  color: var(--text);
  line-height: 1.5;
  font-family: inherit;
  transition: background-color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .prompt-tile:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: var(--shadow-sm);
  }
}

.prompt-tile:active { transform: scale(0.98); }

/* ---------- Memory page ---------- */

.memory-page {
  overflow-y: auto;
  flex: 1;
}
.memory-container {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) var(--space-16) var(--space-6);
}

.memory-hero {
  background:
    radial-gradient(
      120% 120% at 0% 0%,
      var(--accent-soft) 0%,
      transparent 55%
    ),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-6) var(--space-7);
  margin-bottom: var(--space-6);
}
.memory-hero h2 {
  margin: 0 0 6px 0;
  font-size: var(--text-2xl);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.2;
  color: var(--text);
}
.memory-hero p {
  margin: 0 0 var(--space-4) 0;
  color: var(--text-muted);
  max-width: 600px;
  line-height: 1.6;
  font-size: var(--text-base);
}
.memory-stats {
  display: flex;
  gap: var(--space-6);
  flex-wrap: wrap;
  font-size: var(--text-sm);
  color: var(--text-muted);
}
.memory-stat {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-1);
  font-variant-numeric: tabular-nums;
}
.memory-stat strong {
  color: var(--text);
  font-weight: 600;
  font-size: var(--text-md);
}

.memory-section {
  margin-bottom: var(--space-10);
}
.memory-section h3 {
  margin: 0 0 var(--space-1) 0;
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--text);
}
.memory-section-sub {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin: 0 0 var(--space-4) 0;
  line-height: 1.55;
}

.mcard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  margin-bottom: 10px;
  transition: border-color var(--dur-base) var(--ease-out),
              box-shadow var(--dur-base) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .mcard:hover {
    border-color: var(--border-strong);
  }
}

.mcard.pinned {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  background: color-mix(in srgb, var(--accent-soft) 60%, var(--surface));
}
.mcard.insight {
  border-left: 3px solid var(--accent);
  padding-left: calc(var(--space-5) - 2px);
  background: color-mix(in srgb, var(--accent-soft) 35%, var(--surface));
}
.mcard.tombstoned .mcontent {
  text-decoration: line-through;
  color: var(--text-muted);
}

.mhead {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-2);
  gap: var(--space-2);
}
.mhead-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.mhead-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .mcard:hover .mhead-actions { opacity: 1; }
}

/* On touch, always show actions — hover-reveal fails on touch */
@media (hover: none) {
  .mhead-actions { opacity: 1; }
}

.icon-btn {
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  border: 0;
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover {
    background: var(--surface-subtle);
    color: var(--text);
  }
}

.icon-btn:active { transform: scale(0.9); }

.icon-btn.active {
  color: var(--accent);
}

@media (hover: hover) and (pointer: fine) {
  .icon-btn.danger:hover {
    background: var(--danger-soft);
    color: var(--danger);
  }
}

.mcontent {
  font-size: var(--text-md);
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.mfoot {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 10px;
  font-variant-numeric: tabular-nums;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  background: var(--surface-subtle);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  min-height: 20px;
  letter-spacing: 0.01em;
}
.pill.accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.timeline {
  position: relative;
  padding-left: var(--space-6);
}
.timeline::before {
  content: '';
  position: absolute;
  left: 7px; top: 4px; bottom: 4px;
  width: 2px;
  background: var(--border);
  border-radius: 1px;
}
.timeline-item {
  position: relative;
  padding-bottom: var(--space-4);
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: calc(-1 * var(--space-6) + 2px); top: 18px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 3px var(--bg);
}

/* ---------- Sign-in ---------- */

.signin-backdrop {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  background:
    radial-gradient(
      circle at 30% 25%,
      color-mix(in srgb, var(--accent) 18%, transparent) 0%,
      transparent 55%
    ),
    radial-gradient(
      circle at 75% 85%,
      color-mix(in srgb, var(--accent-2) 12%, transparent) 0%,
      transparent 55%
    ),
    var(--bg);
}
.signin-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  padding: var(--space-8) var(--space-8) var(--space-7) var(--space-8);
  box-shadow: var(--shadow-lg);
  animation: signin-in var(--dur-modal) var(--ease-out);
}

@keyframes signin-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.signin-card h1 {
  font-size: var(--text-2xl);
  margin: 0 0 var(--space-1) 0;
  letter-spacing: -0.02em;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
  color: var(--text);
}
.signin-card .subtitle {
  font-size: var(--text-base);
  color: var(--text-muted);
  margin: 0 0 var(--space-6) 0;
  text-align: center;
  line-height: 1.5;
}
.signin-field {
  margin-bottom: var(--space-3);
}
.signin-field label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  margin-bottom: var(--space-1);
  color: var(--text);
}
.signin-disclaimer {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-4);
  text-align: center;
  line-height: 1.55;
}

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.50);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: var(--space-6);
  animation: fade-in var(--dur-base) var(--ease-out);
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  max-width: 560px;
  width: 100%;
  padding: var(--space-7);
  box-shadow: var(--shadow-lg);
  animation: modal-in var(--dur-modal) var(--ease-out);
  /* transform-origin: center — modals enter from viewport center, not a trigger */
  transform-origin: center;
}
.modal.modal-wide { max-width: 720px; }
.modal h2 {
  margin: 0 0 var(--space-1) 0;
  font-size: var(--text-xl);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.25;
  color: var(--text);
}
.modal p.modal-sub {
  color: var(--text-muted);
  margin: 0 0 var(--space-5) 0;
  font-size: var(--text-base);
  line-height: 1.6;
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: var(--space-6);
  flex-wrap: wrap;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  /* Never scale(0) — start from scale(0.96) with opacity 0 */
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- Wizard ---------- */

.wizard-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: var(--space-7);
}
.wizard-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background-color var(--dur-base) var(--ease-out),
              width var(--dur-base) var(--ease-out),
              border-radius var(--dur-base) var(--ease-out);
}
.wizard-dot.active {
  background: var(--accent);
  width: 24px;
  border-radius: var(--radius-sm);
}
.wizard-dot.done {
  background: var(--accent);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: var(--space-3) 0;
}
.chip {
  padding: 6px 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 500;
  font-family: inherit;
  color: var(--text);
  user-select: none;
  min-height: 30px;
  transition: background-color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .chip:hover {
    border-color: var(--border-strong);
  }
}

.chip:active { transform: scale(0.97); }

.chip.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* ---------- Toasts — pinned top-right, slide + scale in ---------- */

.toast-host {
  position: fixed;
  top: calc(var(--topnav-height) + var(--space-3));
  right: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 60;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  min-width: 260px;
  max-width: 360px;
  font-size: var(--text-sm);
  color: var(--text);
  box-shadow: var(--shadow-md);
  animation: toast-in var(--dur-slow) var(--ease-out);
  display: flex;
  gap: 10px;
  align-items: center;
  /* transform-origin: origin-aware — scaling from the top-right, not center */
  transform-origin: top right;
}
.toast.success { border-left-color: var(--success); }
.toast.warning { border-left-color: var(--warning); }
.toast.danger  { border-left-color: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(16px) scale(0.98); }
  to   { opacity: 1; transform: translateX(0)  scale(1); }
}

/* ---------- Banners ---------- */

.banner {
  padding: 10px var(--space-5);
  font-size: var(--text-sm);
  line-height: 1.5;
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-2);
  animation: fade-in var(--dur-slow) var(--ease-out);
}
.banner-warning {
  background: var(--warning-soft);
  color: var(--warning);
  border-bottom: 1px solid color-mix(in srgb, var(--warning) 25%, transparent);
}
.banner-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-bottom: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
}
.banner-info {
  background: var(--accent-soft);
  color: var(--accent);
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}

/* ---------- Command palette — scale from trigger; here, from top center ---------- */

.palette-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.40);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 70;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 120px;
  animation: fade-in var(--dur-base) var(--ease-out);
}
.palette {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 560px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  /* Palette scales from top (where the trigger lives in the topbar) */
  transform-origin: top center;
  animation: palette-in var(--dur-slow) var(--ease-out);
}

@keyframes palette-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.palette input {
  width: 100%;
  padding: var(--space-4) var(--space-5);
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: var(--text-md);
  font-family: inherit;
  border-bottom: 1px solid var(--border);
}
.palette input::placeholder {
  color: var(--text-mute);
}
.palette-list {
  max-height: 360px;
  overflow-y: auto;
  padding: 6px;
}
.palette-item {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--text-base);
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  transition: background-color var(--dur-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .palette-item:hover { background: var(--accent-soft); }
}

.palette-item.focused { background: var(--accent-soft); }

.palette-item .sub {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

/* ---------- Chip filters (memory page) ---------- */

/* (.chip is defined above, reused here) */

/* ---------- Skeleton ---------- */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface-subtle) 0%,
    var(--border) 50%,
    var(--surface-subtle) 100%
  );
  background-size: 200% 100%;
  animation: skeleton 1.3s var(--ease-in-out) infinite;
  border-radius: var(--radius-md);
}
@keyframes skeleton {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* ---------- Misc helpers ---------- */

.cursor-pointer { cursor: pointer; }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
[x-cloak] { display: none !important; }

/* ---------- Settings ---------- */

.settings-page {
  overflow-y: auto;
  flex: 1;
}
.settings-container {
  max-width: var(--settings-max);
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) var(--space-16) var(--space-6);
}
.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border);
  gap: var(--space-6);
  flex-wrap: wrap;
}
.settings-row:last-child { border-bottom: 0; }
.settings-row label {
  font-weight: 500;
  font-size: var(--text-md);
  color: var(--text);
}
.settings-row .desc {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: 2px;
  max-width: 360px;
  line-height: 1.55;
}
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 4px var(--space-5);
  margin-bottom: var(--space-5);
  transition: border-color var(--dur-base) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .settings-card:hover { border-color: var(--border-strong); }
}

.settings-card-title {
  font-size: var(--text-md);
  font-weight: 600;
  padding: var(--space-4) 0 var(--space-2) 0;
  letter-spacing: -0.005em;
  color: var(--text);
}

/* ---------- Theme toggle ---------- */

.theme-row {
  display: flex;
  gap: var(--space-2);
}
.theme-btn {
  padding: 8px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text);
  font-family: inherit;
  min-height: 34px;
  transition: background-color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .theme-btn:hover:not(.active) {
    border-color: var(--border-strong);
  }
}

.theme-btn:active { transform: scale(0.97); }

.theme-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}

/* ---------- In-chat attachment chips (Week 5) ---------- */

/*
 * The chip strip sits between message history and the composer-box. Files
 * uploaded mid-conversation appear here with status, then move into the
 * sent user bubble after send() and the strip clears.
 */
.composer-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: 0 6px;
}

.composer-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-size: var(--text-xs);
  color: var(--text);
  user-select: none;
  /* Long file names should ellipsize, not blow up the strip */
  max-width: 280px;
}

.composer-chip.success {
  border-color: color-mix(in srgb, var(--success) 35%, var(--border));
  background: var(--success-soft);
}

.composer-chip.error {
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
  background: var(--danger-soft);
  color: var(--danger);
}

.composer-chip.pending {
  background: var(--surface-subtle);
  color: var(--text-muted);
}

.chip-icon {
  flex-shrink: 0;
  font-size: 12px;
  line-height: 1;
}

.chip-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.chip-meta {
  color: var(--text-muted);
  white-space: nowrap;
}

.chip-remove {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  user-select: none;
  margin-left: 2px;
}

@media (hover: hover) and (pointer: fine) {
  .chip-remove:hover {
    background: color-mix(in srgb, var(--text) 8%, transparent);
    color: var(--text);
  }
}

.chip-remove:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Composer drop-target highlight — uses the same accent-soft pattern as the
 * Files tab drop zone for visual consistency. */
.composer-box.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.composer-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Paperclip button. 36×36 to match composer-send so the action row stays
 * visually balanced. Ghost background so the send button remains the
 * primary affordance. */
.composer-attach {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}

.composer-attach:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.composer-attach:active:not(:disabled) { transform: scale(0.94); }

@media (hover: hover) and (pointer: fine) {
  .composer-attach:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
  }
}

.composer-attach:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.bubble-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-top: 4px;
}

/* ---------- File upload (Week 5) ---------- */

/*
 * Drop zone follows the same token system as the rest of the app:
 *   - dashed border on var(--border) so it reads as an affordance, not a hard frame
 *   - background flips with theme via var(--surface-subtle)
 *   - drag-over uses var(--accent-soft) (color-mix-derived in dark mode) so the
 *     active state is theme-aware without hardcoded rgba()
 *   - hover gated to fine pointers per Rauno; no transform on hover so reduced-motion
 *     users still see the state change without a jolt
 */
.upload-drop {
  display: block;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
  cursor: pointer;
  text-align: center;
  transition: border-color var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out);
  user-select: none;
}

.upload-drop.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}

@media (hover: hover) and (pointer: fine) {
  .upload-drop:hover {
    border-color: var(--border-strong);
  }
}

/* Keyboard users tab to the inner "Choose files" button; if they tab onto the
 * label itself we still want a visible ring so the focus state isn't invisible. */
.upload-drop:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Nested radius = outer (var(--radius-md) = 8) − gap (~2) → var(--radius-sm) = 6
 * per Hobday #14. Keeps the rounded corners visually concentric. */
.upload-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.upload-name {
  font-size: var(--text-sm);
  color: var(--text);
  font-weight: 500;
  /* break-all is aggressive but file names without spaces (foo_bar_baz.docx)
   * need it to avoid blowing the row width on long names */
  word-break: break-all;
}

.upload-status {
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
}

/* Use the canonical semantic tokens. Both --success and --danger flip in dark
 * mode (defined in :root.dark) so no hardcoded color leaks. */
.upload-status.success {
  color: var(--success);
}

.upload-status.error {
  color: var(--danger);
}

.upload-status.pending {
  color: var(--text-muted);
}

/* ---------- Reduced motion — fewer and gentler, not zero ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  /* Keep the dot pulse off — it's decorative and can trigger motion sickness */
  .status-dot .dot.loading { animation: none; }
  .skeleton { animation: none; background: var(--surface-subtle); }
}
