/* =============================================================================
 * 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. The Google Fonts CDN `src` fallback was removed
 * (V6c) so the enforcing CSP needs no external font origin — the
 * self-hosted files are the only source. */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/static/fonts/inter-latin.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');
  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;
}
/* Fraunces — the marketing-site display serif, brought into the product so
 * the webapp and the website read as one brand. Used ONLY for large display
 * headings (see --font-display); body / UI / chat stay Inter. Self-hosted
 * variable woff2 (opsz 9–144, wght 100–900). Self-hosted only — the Google
 * CDN src-list fallback was removed so the enforcing CSP can keep
 * font-src to 'self' data: (no external font origin). */
@font-face {
  font-family: 'Fraunces';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/static/fonts/fraunces-latin.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 {
  /* Paint native controls (date/time/datetime-local pickers, spin buttons,
     scrollbars) in the light scheme so their segments + calendar/clock
     indicators stay legible and clickable. Flipped to `dark` in html.dark —
     without this, native time inputs render dark-on-dark and look uneditable. */
  color-scheme: light;
  /* Surfaces — the warm golden canvas of the app shell (static/mvp.css,
     which re-points these same tokens at its --mvp-* palette inside .mvp).
     Set here too so everything outside the shell (sign-in, modals, toasts,
     the onboarding wizard) wears the same palette. */
  --bg:            #FEFCF8;
  --surface:       #FFFDF8;
  --surface-subtle:#F9F3E8;
  --surface-raised:#FFFDF8;
  --border:        rgba(160, 118, 40, 0.18);
  --border-strong: rgba(160, 118, 40, 0.34);

  /* Text */
  --text:          #2E2414;
  --text-muted:    #6B5C45;
  --text-mute:     #756852;

  /* Accent — gold. --accent is the deep gold used for text and links (clears
   * AA on the canvas); --accent-fill is the bright gold behind DARK text
   * (--on-accent), as on the shell's primary buttons. --accent-2 pairs with
   * --accent in the two-stop gradients; --accent-brand is the decorative
   * full tone for hairlines and glyphs. */
  --accent:        #8B6312;
  --accent-hover:  #7F5A0F;
  --accent-soft:   rgba(214, 167, 64, 0.15);
  --accent-2:      #D19D33;
  --accent-brand:  #D19D33;
  --accent-fill:       #D19D33;
  --accent-fill-hover: #C08C26;

  /* 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);
  /* Danger FILL (white text) — same fill-vs-foreground split as the accent:
   * --danger stays the bright semantic red for text/borders/soft tints;
   * --danger-fill is the AA-safe shade behind white on the destructive button. */
  --danger-fill:       #DC2626;
  --danger-fill-hover: #B91C1C;

  /* 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;
  /* Slower celebratory settle — the onboarding success-check entrance. */
  --dur-celebrate: 400ms;
  /* Reveal curve — the marketing site's signature ease; a hair springier
   * than --ease-out, for mount/scroll entrances where a little settle reads
   * as "crafted". Theme-independent, declared once. */
  --ease-reveal: cubic-bezier(0.16, 1, 0.3, 1);

  /* Chat UI — unified bubble/card geometry, leading, micro-type, focus, press.
   * Single source of truth referenced by all chat blocks (see chat changeset). */
  --chat-bubble-max:820px;
  --chat-card-max:620px;
  --chat-col-gap:6px;
  --chat-card-gap:var(--space-3);
  --space-3-5:14px;
  --text-2xs:10px;
  --leading-body:1.6;
  --leading-snug:1.5;
  --radius-bubble:var(--radius-2xl);
  --radius-card:var(--radius-md);
  --dur-enter:var(--dur-slow);
  --focus-ring-width:2px;
  --focus-ring-offset:2px;
  --focus-ring-color:var(--accent);
  --press-scale:0.97;
  --on-accent:#2A1D05;
  --on-accent-muted:rgba(42,29,5,0.72);
  --on-accent-surface:rgba(42,29,5,0.08);
  --text-dim:#756852;
  --mono:ui-monospace, SFMono-Regular, Menlo, monospace;
  --warning-text:#92500A;
  /* Aliases for tokens referenced but never defined (zero markup churn). */
  --surface-border: var(--border);
  --font-mono: var(--mono);

  /* Lists/tables — single source of truth for row density/hover/selected/
   * separator/radius (mirrors the chat block above). Migrated incrementally. */
  --row-pad-y: var(--space-3);
  --row-pad-x: var(--space-3);
  --row-pad-y-compact: var(--space-2);
  --row-radius: var(--radius-md);
  --row-hover-bg: var(--surface-subtle);
  --row-active-bg: var(--accent-soft);
  --row-active-fg: var(--accent);
  --row-separator: 1px solid var(--border);
  --row-separator-soft: 1px dashed color-mix(in srgb, var(--border) 60%, transparent);

  /* Shared min-height for in-page tab strips (.library-tab, .settings-tab,
   * project tabbar) so all in-page tabs match. Rail keeps its own 36px. */
  --tab-height: 32px;

  /* Overlay scrim/blur + z-index ladder — single source of truth for every
   * backdrop. Theme-aware scrim (drawers' on-brand recipe); the z scale fixes
   * the ad-hoc ladder so toasts/tooltips render above blocking overlays. */
  --overlay-scrim: color-mix(in srgb, var(--text) 45%, transparent);
  --overlay-blur: 6px;
  --z-drawer: 60;
  --z-modal: 70;
  --z-drawer-over: 80;
  --z-toast: 90;
  --z-tooltip: 100;
  --z-metrics: 200; /* metrics drill-down + CB body-mounted sheet layer above the standard ladder by design */
  --z-cb-sheet: 9990;

  /* Display font — Fraunces serif, large headings only (never body/UI). */
  --font-display: 'Fraunces', 'Iowan Old Style', Georgia, 'Times New Roman', serif;

  /* Brand gradient + glow (values overridden in html.dark). The gradient is
   * the site's indigo→blue shimmer; the glow is the accent halo on the
   * primary button, focus, and the conic glow-border card. */
  --grad-accent: linear-gradient(110deg, #E2AE45, #C08C26 45%, #9C6F14);
  --glow-accent: 0 1px 2px rgba(168, 122, 28, 0.2), 0 10px 26px -10px rgba(201, 149, 43, 0.5);
  --shadow-glow: 0 1px 2px rgba(96, 68, 18, 0.05), 0 18px 44px -18px rgba(120, 84, 20, 0.26);

  /* Layout */
  --sidebar-width: 260px;
  /* --chat-max evolution:
   *   780  (original — too narrow on modern displays)
   *   960  (2026-04-30 — first bump)
   *  1080  (2026-04-30 second pass — user feedback "column too narrow")
   * Bubbles cap at min(820px, 100%); chat-max is the outer wrapper. The
   * 1080 value gives ~40px of breathing room on each side of a 1000-wide
   * bubble, plus slack for the day-separator chips and follow-up chips. */
  --chat-max:      1080px;
  --page-max:      1080px;
  /* --settings-max governs both the Settings page AND the Files page
   * (both use .settings-container). Bumped 720 → 880 so the chunk-
   * density slider stays on the same row as its label/description
   * instead of wrapping to a second line. The descriptive copy already
   * caps at max-width: 360px, so widening the container only gives
   * extra room to the right-hand control column. */
  --settings-max:  880px;

  /* ===================================================================
   * carve_UI (2026-06-29) — the standardized system extension.
   * ADDITIVE only: extends the existing tokens to close the gap to
   * best-in-class AI apps (Linear / Vercel / Raycast / shadcn — see
   * docs/active/ui-research-top-chats-2026-06-29.md). Nothing here
   * overrides an existing value, so every page that already used the
   * old tokens is unchanged. Canonical usage lives in the carve_UI skill.
   * ================================================================ */

  /* Inter sub-Medium weights (Linear's 510/590) — emphasis without the
   * heavy 700 that reads as shouting in a dense UI. Cap at --weight-strong. */
  --weight-normal:   400;
  --weight-emphasis: 510;   /* labels, card titles, active tabs */
  --weight-strong:   590;   /* page-hero h2, section headers — the ceiling */

  /* Frequency-gated motion budget (sub-300ms; "when in doubt, go faster").
   * Per-element durations so motion is consistent across every page. These
   * alias the existing --dur-* so the curve/timing vocabulary stays single. */
  --dur-button:   140ms;   /* press/hover feedback — high frequency */
  --dur-tooltip:  160ms;
  --dur-dropdown: 200ms;
  --dur-tab:      var(--dur-base);   /* 180ms tab/panel switch */
  --dur-modal-in: var(--dur-modal);  /* 320ms overlays — rare, can delight */
  --dur-page:     var(--dur-slow);   /* 260ms route entrance */
  /* The one entrance curve every page-level reveal uses (springy settle). */
  --ease-page: var(--ease-reveal);

  /* Hairline-brighten focus (Raycast pattern): the surface-ladder feel comes
   * from borders that BRIGHTEN on focus, not a glowy colored ring. Pages opt
   * into this for inputs/cards; the accent ring stays for buttons/links. */
  --focus-hairline: var(--border-strong);

  /* Standard page gutters — referenced by the carve_UI page recipe so every
   * page frame is identical (top breathing room, generous bottom). */
  --page-pad: var(--space-8) var(--space-6) var(--space-16) var(--space-6);
}

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

html.dark {
  /* Native pickers/spinners/scrollbars render in dark chrome (see :root note). */
  color-scheme: dark;
  /* The shell's warm dark canvas (html.dark .mvp in mvp.css). */
  --bg:            #2B251C;
  --surface:       #383024;
  --surface-subtle:#332B20;
  --surface-raised:#3A3226;
  --border:        rgba(226, 176, 74, 0.16);
  --border-strong: rgba(226, 176, 74, 0.3);

  --text:          #F4EBD9;
  --text-muted:    #C3B292;
  --text-mute:     #AA9D84;

  /* Gold reads on the dark canvas as-is; fills keep dark text on them. */
  --accent:        #EDC36B;
  --accent-hover:  #F6D38A;
  --accent-soft:   rgba(226, 176, 74, 0.13);
  --accent-2:      #E2B04A;
  --accent-brand:  #E2B04A;
  --accent-fill:       #E2B04A;
  --accent-fill-hover: #EDBE5C;
  --on-accent:         #1E1505;
  --on-accent-muted:   rgba(30, 21, 5, 0.72);
  --on-accent-surface: rgba(30, 21, 5, 0.1);

  --success:       #34D399;
  --success-soft:  rgba(52, 211, 153, 0.14);
  --warning:       #FBBF24;
  --warning-soft:  rgba(251, 191, 36, 0.14);
  /* Chat UI — theme-sensitive overrides (accent/space/radius tokens are
   * theme-independent and inherit from :root). */
  --text-dim:#AA9D84;
  --warning-text:#FBBF24;
  --danger:        #F87171;
  --danger-soft:   rgba(248, 113, 113, 0.14);
  /* Deeper red so white text clears AA on the destructive button (the bright
   * #F87171 is foreground-only on dark). */
  --danger-fill:       #DC2626;
  --danger-fill-hover: #B91C1C;
  /* Re-resolve the alias against the dark --border. */
  --surface-border: var(--border);
  /* A dark scrim on dark: one tinted from the light --text washes the page out. */
  --overlay-scrim: rgba(12, 9, 4, 0.6);

  --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);

  /* Dark gradient + glow. On dark, shadows do little work (Hobday #5), so the
   * "lift" is carried by the accent halo + a hairline highlight, matching the
   * website's backlit-glass treatment. Gradient = the site's exact shimmer. */
  --grad-accent: linear-gradient(110deg, #F6D38A, #E2B04A 45%, #C99A3A);
  --glow-accent: 0 0 0 1px rgba(226, 176, 74, 0.3), 0 8px 40px rgba(226, 176, 74, 0.14);
  --shadow-glow: 0 0 0 1px var(--border), inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 14px 44px -12px rgba(0, 0, 0, 0.6);
}

/* ---------- Display & accessibility preference variants ----------
 * Applied via data-* attributes on <html> by the inline boot script in
 * index.html (FOUC-avoidance) and by setDisplayPref() in app.js once
 * Alpine boots. Each variant only overrides the variables it needs; the
 * rest fall through to the defaults declared on :root above.
 *
 * The default tier for every dimension is "md", which is the existing
 * design — so a user with no prefs persisted sees zero change.
 */

/* Text scale — multiplies the entire type ramp. Designed so
 * adjacent tiers feel like one step (S → MD → LG → XL is 12 → 14 → 16
 * → 18 at base, with the upper end of the ramp scaling proportionally
 * so display headings stay larger than body). */
html[data-text-scale="s"] {
  --text-2xs:  9px;
  --text-xs:   11px;
  --text-sm:   12px;
  --text-base: 13px;
  --text-md:   15px;
  --text-lg:   17px;
  --text-xl:   19px;
  --text-2xl:  22px;
  --text-3xl:  28px;
  --text-4xl:  34px;
}
html[data-text-scale="lg"] {
  --text-2xs:  11px;
  --text-xs:   13px;
  --text-sm:   14px;
  --text-base: 16px;
  --text-md:   18px;
  --text-lg:   20px;
  --text-xl:   22px;
  --text-2xl:  26px;
  --text-3xl:  36px;
  --text-4xl:  44px;
}
html[data-text-scale="xl"] {
  --text-2xs:  12px;
  --text-xs:   14px;
  --text-sm:   16px;
  --text-base: 18px;
  --text-md:   20px;
  --text-lg:   23px;
  --text-xl:   25px;
  --text-2xl:  30px;
  --text-3xl:  40px;
  --text-4xl:  50px;
}

/* Chat column width — controls the outer wrapper. Message bubbles cap
 * themselves at min(820px, 100%), so the wider tiers give extra
 * breathing room to the surrounding chrome (day separators, follow-up
 * chips, attachments) rather than stretching the bubbles edge-to-edge. */
html[data-chat-width="s"]  { --chat-max:  820px; }
html[data-chat-width="lg"] { --chat-max: 1280px; }
html[data-chat-width="xl"] { --chat-max: 1500px; }

/* Sidebar width — the inner sessions-list rail (not the outer app rail). */
html[data-sidebar-width="s"]  { --sidebar-width: 220px; }
html[data-sidebar-width="lg"] { --sidebar-width: 320px; }

/* High contrast — bumps the text/border channels so the WCAG AA ratio
 * exceeds 7:1 (AAA) for body copy. Designed to layer on top of either
 * theme; light + HC and dark + HC both produce a usable result. */
html[data-high-contrast="true"] {
  --text:        #000000;
  --text-muted:  #1F1F23;
  --text-mute:   #2A2A33;
  --border:      #6B6B73;
  --border-strong: #45454D;
}
html.dark[data-high-contrast="true"] {
  --text:        #FFFFFF;
  --text-muted:  #EAEAF0;
  --text-mute:   #BFBFC8;
  --border:      #5A5A66;
  --border-strong: #8A8A96;
}

/* Reduce motion — global animation/transition kill switch. Honored in
 * addition to the OS-level prefers-reduced-motion media query, so a
 * user who opts in here gets the same behavior regardless of OS setting.
 * Uses 0.01ms instead of 0ms so onAnimationEnd-style handlers still fire. */
html[data-reduce-motion="true"] *,
html[data-reduce-motion="true"] *::before,
html[data-reduce-motion="true"] *::after {
  animation-duration: 0.01ms !important;
  animation-delay: 0.01ms !important;
  transition-duration: 0.01ms !important;
  transition-delay: 0.01ms !important;
  scroll-behavior: auto !important;
}

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

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  /* Soft canvas grain (whisper) — a faint tiling noise over --bg to take the
     flat glare off the page. Same feTurbulence recipe + soft-light blend as the
     hero plate; desaturated so a full-page fill reads as paper, not colour
     speckle, at a low 0.06 opacity. Static. */
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='cg'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23cg)' opacity='0.06'/%3E%3C/svg%3E") repeat,
    var(--bg);
  background-size: 140px 140px, auto;
  background-blend-mode: soft-light, normal;
  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;
  height: 100dvh;  /* the visible viewport on phones (URL bar), where supported */
  display: flex;
  flex-direction: column;
}

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

/* Interactive chrome: never selectable. Prevents accidental text selection
   on double-click or drag, and signals "this is a control" (Rauno). */
button, [role="button"], .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: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
}

/* 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-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 {
  /* Same faint top-down sheen as the memory cards, so every panel in the app
   * reads as one material instead of a flat fill. */
  background: linear-gradient(180deg,
              color-mix(in srgb, var(--text) 2.5%, var(--surface)),
              var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

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

/* .card — used across the Projects views (invite/member/shared-memory/settings
 * panels) and the project-memory review list, but it was never actually defined
 * in the webapp, so those boxes rendered with no surface at all. Define it as a
 * first-class sheened panel (padding stays inline per-usage). */
.card {
  background: linear-gradient(180deg,
              color-mix(in srgb, var(--text) 2.5%, var(--surface)),
              var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

/* ---------- 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(var(--press-scale)); }

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

.btn-primary {
  background: var(--accent-fill);
  color: var(--on-accent);
}

@media (hover: hover) and (pointer: fine) {
  /* Lift + brand glow on hover — the website's primary-CTA treatment, applied
   * only on interaction so buttons aren't perpetually glowing. The :active
   * scale(0.97) above takes over on press (translateY is dropped then). */
  .btn-primary:hover:not(:disabled) {
    background: var(--accent-fill-hover);
    box-shadow: var(--glow-accent);
    transform: translateY(-1px);
  }
}

.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-fill);
  color: #fff;
}

@media (hover: hover) and (pointer: fine) {
  .btn-danger:hover:not(:disabled) {
    background: var(--danger-fill-hover);
  }
}

.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;
}

.btn-full { width: 100%; }

.error-message { color: var(--danger); font-size: var(--text-sm); margin-bottom: var(--space-3); }

/* ---------- 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;
}
.input:disabled, .textarea:disabled, select.input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: var(--surface-subtle);
}
.input[aria-invalid="true"], .textarea[aria-invalid="true"] {
  border-color: var(--danger);
}
.input[aria-invalid="true"]:focus, .textarea[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent);
}
select.input {
  appearance: none;
  -webkit-appearance: none;
  height: 40px;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%2371717A' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

/* ---------- Brand mark (rail + sign-in lockups) ---------- */

.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);
}

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

.chat-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  flex: 1;
  overflow: hidden;
  position: relative;
  transition: grid-template-columns var(--dur-base) var(--ease-out);
}

.slash-menu {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: 240px;
  overflow-y: auto;
  z-index: 30;
  animation: ctxMenuIn var(--dur-fast) var(--ease-out);
}

/* 2026-05-13 — cross-page "chat working" banner. Renders on every
 * non-chat route when a turn is pending or a reply is waiting for
 * pickup. Sticky top so it's visible regardless of scroll position
 * on the underlying page. Subtle accent surface so it reads as
 * informational, not as an error. */
.away-banner {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--accent-soft);
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
  font-size: var(--text-sm);
  color: var(--text);
  animation: routeFadeIn var(--dur-base) var(--ease-out);
}

/* 2026-05-12 — copy-button morph (#10). When .copied is added by
 * copyMessage(), the existing label-text swap gets a satisfying
 * scale + color flash. The checkmark itself is swapped via
 * Alpine in the bubble-actions block.  */
.bubble-action-btn.copied {
  color: var(--success);
  transform: scale(1.02);
}
.bubble-action-btn .check-icon {
  display: none;
}
.bubble-action-btn.copied .copy-icon { display: none; }
.bubble-action-btn.copied .check-icon { display: inline-flex; }

/* ---------- 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);
}

/* ---------- Project Library — `.library-row` cards ----------
 * Visual parity with the personal Library's row card pattern but
 * with a leading icon column + a dedicated actions row that wraps
 * cleanly when a doc has many buttons. */

.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-enter) var(--ease-out);
}
.bubble-row.user {
  flex-direction: row-reverse;
}
/* Per-message column wrapper (tool-badge → thinking → bubble → actions →
 * follow-ups). One gap token across all four wrappers (was 2px persisted /
 * 6px live — visibly settled 4px at finalize). */
.bubble-col {
  display: flex;
  flex-direction: column;
  gap: var(--chat-col-gap);
  min-width: 0;
}

/*
 * 2026-05-15 — fix: long (multi-line) user messages were rendering
 * left-shifted inside their row instead of flush with the avatar on
 * the right.
 *
 * The inner column wrapper next to the avatar (the unnamed
 * `<div style="display:flex; flex-direction:column; min-width: 0">`
 * in index.html) is a flex item with `flex: 0 1 auto`, so its width
 * is its content's intrinsic max-content. For a long single-paragraph
 * message the bubble's max-content (unwrapped natural width) can
 * exceed its rendered `max-width: min(820px, 100%)` cap — so the
 * column becomes wider than 820px while the bubble inside is pinned
 * to 820px. Default `align-items: stretch` on the column can't
 * stretch a max-width-constrained child, falling back to
 * `flex-start` (left), which left-shifts the bubble away from the
 * avatar.
 *
 * Forcing `align-items: flex-end` on the column for user rows pins
 * the bubble, attachments, and edit-action row to the right edge no
 * matter how wide the column resolves to. The `> div` selector
 * targets the unnamed inline-styled wrapper without needing to
 * change the markup.
 */
.bubble-row.user > .bubble-col {
  align-items: flex-end;
}

/* 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;
  /* 2026-05-15 — center the avatar's single-character glyph in the
   * 28px circle. Earlier attempts (line-height:1, padding-bottom)
   * behaved differently between the header avatar (fontSize:11px
   * inline) and the chat avatar (12px) because the line-box height
   * scaled with font-size, so any padding-based shift hit them
   * unevenly.
   *
   * line-height equal to the container height fixes the line-box at
   * 28px regardless of font-size. Half-leading lands the em-box
   * dead-center vertically; Inter's per-glyph baseline (~80% of
   * em-box from top) then renders the cap of a single capital
   * within ~1px of optical center for both 11px and 12px font
   * sizes. align-items:center is now redundant (the line-box and
   * container match) but kept for defensive consistency. */
  box-sizing: border-box;
  line-height: 28px;
  text-align: center;
  flex-shrink: 0;
  color: #fff;
  user-select: none;
}
.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 {
  /* Was `min(680px, 88%)`. The 88% was relative to the column-flex
   * parent which auto-sizes to bubble content — a circular constraint
   * that browsers resolve inconsistently and made consecutive user
   * messages of different lengths look subtly misaligned. Switched to a
   * flat 820px cap so every bubble shares the same right edge in user
   * rows and the same left edge in assistant rows. The 100% fallback
   * keeps short viewport widths sensible without re-introducing the
   * percent-of-auto-parent edge case. */
  max-width: min(var(--chat-bubble-max), 100%);
  padding: var(--space-3-5) var(--space-5);
  border-radius: var(--radius-bubble);
  font-size: var(--text-md);
  line-height: var(--leading-body);
  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-fill);
  color: var(--on-accent);
  border: 1px solid color-mix(in srgb, var(--accent-fill) 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: var(--text-xs);
  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);
}
/* Markdown tables (marked's GFM tables). display:block + max-content lets a
 * table too wide for the bubble scroll sideways inside it instead of
 * stretching the column. Cells wrap only at spaces: the bubble's
 * overflow-wrap:anywhere would otherwise squeeze every column to a sliver
 * before the table ever scrolls. */
.bubble table {
  display: block;
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
  margin: var(--space-3) 0;
  border-collapse: collapse;
  font-size: 0.92em;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}
.bubble table:first-child { margin-top: 0; }
.bubble table:last-child { margin-bottom: 0; }
.bubble th, .bubble td {
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  vertical-align: top;
  overflow-wrap: normal;
}
.bubble th {
  background: var(--surface-subtle);
  font-weight: 600;
}
.bubble th:not([align]) { text-align: left; }

.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),
              transform var(--dur-fast) var(--ease-out);
}

.bubble-action-btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}
.bubble-action-btn:active:not(:disabled) {
  transform: scale(var(--press-scale));
}

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

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

/* 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); }
}

/* 2026-05-12 — token cursor on a still-streaming assistant bubble.
 * Mimics a terminal caret. Pinned to the end of the rendered content
 * via the `.streaming` class added in app.js when chatPending is
 * true AND this is the last assistant message. Honors prefers-
 * reduced-motion (no blink, just a static caret). */
.bubble.streaming::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--text);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 1s steps(2, end) infinite;
  border-radius: 1px;
}
@keyframes blink {
  50% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .bubble.streaming::after { animation: none; opacity: 0.7; }
}

/* 2026-05-12 — stagger bubble-in mount animation by index. The base
 * animation lives on .bubble-row above; this delays each row's
 * fire by (i × 30ms) capped at 360ms so a long session doesn't take
 * 12 seconds to "settle in". `--i` is set inline from the x-for
 * index, defaulting to 0 if absent. animation-fill-mode: backwards
 * keeps the initial opacity:0 state during the delay so rows don't
 * flash visible before their turn. */
.bubble-row {
  animation-delay: calc(min(var(--i, 0), 12) * 30ms);
  animation-fill-mode: backwards;
}

/* 2026-05-14 — in-webapp PDF viewer drawer. Slides in from the right
 * at 65vw (capped 1100px). Uses native browser PDF rendering via an
 * iframe — no PDF.js dependency. Backdrop scrim dims the rest of the
 * app and traps clicks to close. */
.pdf-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay-scrim);
  backdrop-filter: blur(var(--overlay-blur));
  -webkit-backdrop-filter: blur(var(--overlay-blur));
  z-index: var(--z-drawer-over);
  display: flex;
  justify-content: flex-end;
  animation: routeFadeIn var(--dur-fast) var(--ease-out);
}
.pdf-drawer {
  width: min(65vw, 1100px);
  height: 100vh;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 24px color-mix(in srgb, var(--text) 14%, transparent);
  animation: pdfDrawerSlideIn var(--dur-base) var(--ease-drawer, var(--ease-out));
}
@keyframes pdfDrawerSlideIn {
  from { transform: translateX(40px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
.pdf-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.pdf-drawer-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}
.pdf-drawer-body {
  flex: 1;
  min-height: 0;
  background: color-mix(in srgb, var(--text) 4%, var(--surface));
  display: flex;
  align-items: stretch;
  justify-content: center;
}
.pdf-drawer-iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}
.pdf-drawer-loading {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4, 16px);
  padding: 40px;
}
.pdf-drawer-status {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
}
.pdf-drawer-error {
  padding: 40px;
  color: var(--danger);
  font-size: 14px;
  text-align: center;
}
@media (max-width: 900px) {
  .pdf-drawer { width: 100vw; }
}
@media (prefers-reduced-motion: reduce) {
  .pdf-drawer { animation: none; }
  .pdf-drawer-backdrop { animation: none; }
}

/* 2026-06-23 — inline file preview card (generic; PDFs today). Rendered by
 * enhanceFileLinks() in place of any previewable link in chat. The header
 * filename links to the source; the body shows a LIVE preview of the top of
 * page 1 (clipped), and clicking the preview / the ⤢ button opens the full
 * in-app .pdf-drawer reader. Box files stream via the authed proxy (Office
 * docs converted to PDF); other .pdf URLs embed directly.
 *
 * Size is the user's `previewSize` display pref (Settings → General → File
 * previews), applied via data-preview-size on <html>. "medium" is the default
 * (no attribute); large/small uniformly scale the SAME card up/down via
 * --fp-scale, so width AND height change together and all three tiers keep
 * identical proportions. Generic so future preview kinds reuse the system. */
.file-preview {
  --fp-scale: 0.5; /* medium (default); large = 1, small ≈ 0.1667 */
  display: flex;
  flex-direction: column;
  width: calc(min(100%, 760px) * var(--fp-scale));
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
  overflow: hidden;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.file-preview:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.file-preview__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
}
.file-preview__icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 30px;
  padding: 0 6px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.file-preview__title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-preview__title:hover { text-decoration: underline; }
.file-preview__expand {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out);
}
.file-preview__expand:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
/* Preview viewport — height scales with --fp-scale alongside the width, so
 * the preview keeps identical proportions at every size. The page iframe is
 * taller than the box, so only the TOP of page 1 shows (clipped). */
.file-preview__viewport {
  position: relative;
  height: calc(42vh * var(--fp-scale));
  background: #fff;
  border-top: 1px solid var(--border);
  overflow: hidden;
  cursor: pointer;
}
.file-preview__frame {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 1100px; /* >> viewport so the bottom is clipped, top shown */
  border: 0;
  background: #fff;
  pointer-events: none; /* clicks fall through to the overlay */
}
.file-preview__skeleton {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 12px;
}
.file-preview__overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  /* fade the clipped bottom edge + seat the call-to-action cue */
  background: linear-gradient(
    to bottom,
    transparent 62%,
    color-mix(in srgb, var(--text) 9%, transparent) 100%
  );
  transition: background var(--dur-fast) var(--ease-out);
}
.file-preview__viewport:hover .file-preview__overlay {
  background: linear-gradient(
    to bottom,
    color-mix(in srgb, var(--accent) 6%, transparent) 0%,
    color-mix(in srgb, var(--accent) 16%, transparent) 100%
  );
}
.file-preview__cue {
  margin-bottom: 12px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 12px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* Size tiers — uniform scales of the same card. Large is the full size,
 * Medium (default) ~1/2 and Small ~1/6 of Large, all keeping the same
 * proportions (only --fp-scale changes; the width:height ratio is constant). */
html[data-preview-size="large"]  .file-preview { --fp-scale: 1; }
html[data-preview-size="small"]  .file-preview { --fp-scale: 0.16667; }
/* Small is too narrow for the format badge + call-to-action pill — drop
 * them so it reads as a clean thumbnail. */
html[data-preview-size="small"] .file-preview__icon,
html[data-preview-size="small"] .file-preview__cue { display: none; }

/* 2026-05-14 — HITL approval card. Structured field rows instead of a
 * single text blob so values like the email body don't collide with
 * labels. Long-form values (Body, Message, Procedure) use a soft
 * monospace block to stay readable; short ones use a single inline row. */
.approval-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: var(--text-sm);
  color: var(--text);
}
.approval-card-headline {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}
.approval-card-field {
  display: grid;
  grid-template-columns: minmax(80px, max-content) 1fr;
  column-gap: 12px;
  align-items: baseline;
}
.approval-card-label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  line-height: 1.6;
}
.approval-card-value {
  font-size: var(--text-sm);
  color: var(--text);
  word-break: break-word;
  line-height: var(--leading-body);
}
.approval-card-field-code {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.approval-card-field-code .approval-card-value {
  background: color-mix(in srgb, var(--text) 5%, var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: var(--text-xs);
  white-space: pre-wrap;
  max-height: 260px;
  overflow-y: auto;
}

/* Browser 'connect your login' card (Phase 3 authenticated actions, dark).
 * A cookie-entry form inside the approval bubble; the user pastes their
 * session cookie(s) and the agent injects them model-blind. */
.connect-login-reason {
  color: var(--text-muted);
  font-style: italic;
}
.connect-login-help {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: var(--leading-body);
}
.connect-login-error {
  font-size: var(--text-sm);
  color: var(--danger);
}

/* Coding-edit diff cards (coding-ux overhaul, 2026-06-17).
 * Rendered inside the sub-agent approval bubble for `file_edit` /
 * `file_binary` write-proposal bundles — a per-file collapsible unified
 * diff with +/- counts, an edit-kind chip, and a partial-approve
 * checkbox. Colors ride the theme vars so light/dark both work. */
.approval-card-diff {
  gap: 6px;
}
.diff-prop-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  cursor: pointer;
}
/* Custom approval-card subset checkbox. Native accent-color checkboxes
 * looked plain against the polished card; this draws an explicit box that
 * fills with the accent + animates a checkmark in on :checked. Token-driven
 * (matches the carve_range slider pattern); motion is frequency-gated per
 * carve_UI (sub-150ms, transform/opacity + a checkmark draw, --ease-out). */
.diff-check {
  flex: none;
  position: relative;
  width: 18px;
  height: 18px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm, 6px);
  background: var(--surface-subtle);
  cursor: pointer;
  display: inline-grid;
  place-content: center;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    transform var(--dur-button) var(--ease-out);
}
/* The checkmark — a rotated border tick. Hidden state is scaled-down +
 * transparent so it "draws in" on check rather than popping. */
.diff-check::after {
  content: "";
  width: 5px;
  height: 9px;
  margin-top: -1px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0.6);
  opacity: 0;
  transition:
    opacity var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}
.diff-check:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.diff-check:active {
  transform: scale(var(--press-scale, 0.97));
}
.diff-check:checked {
  background: var(--accent-fill, var(--accent));
  border-color: var(--accent-fill, var(--accent));
}
.diff-check:checked::after {
  opacity: 1;
  transform: rotate(45deg) scale(1);
}
.diff-check:focus-visible {
  outline: var(--focus-ring-width, 2px) solid var(--focus-ring-color, var(--accent));
  outline-offset: var(--focus-ring-offset, 2px);
}
@media (prefers-reduced-motion: reduce) {
  .diff-check,
  .diff-check::after {
    transition: none;
  }
}
.diff-head {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}
.diff-kind {
  flex: none;
  font-size: var(--text-2xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 1px 7px;
  border-radius: var(--radius-full, 999px);
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--mono, ui-monospace, monospace);
}
.diff-kind-create { background: var(--success-soft); color: var(--success); }
.diff-kind-delete { background: var(--danger-soft); color: var(--danger); }
.diff-path {
  font-family: var(--mono, ui-monospace, monospace);
  font-size: var(--text-xs);
  color: var(--text);
  word-break: break-all;
  min-width: 0;
}
.diff-counts {
  flex: none;
  display: inline-flex;
  gap: 6px;
  font-family: var(--mono, ui-monospace, monospace);
  font-size: var(--text-xs);
  font-weight: 600;
}
.diff-add-count { color: var(--success); }
.diff-del-count { color: var(--danger); }
.diff-details {
  margin-top: 2px;
}
.diff-summary {
  font-size: var(--text-xs);
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  list-style: revert;
}
.diff-block {
  margin: 6px 0 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--text) 4%, var(--surface));
  font-family: var(--mono, ui-monospace, monospace);
  font-size: var(--text-xs);
  line-height: var(--leading-snug);
  max-height: 320px;
  overflow: auto;
  white-space: pre;
}
.diff-line {
  display: block;
  white-space: pre-wrap;
  word-break: break-word;
}
.diff-add { background: var(--success-soft); color: var(--success); }
.diff-del { background: var(--danger-soft); color: var(--danger); }
.diff-hunk { color: var(--accent); font-weight: 600; }
.diff-file { color: var(--text-muted); }
.diff-rationale {
  font-size: var(--text-sm);
  color: var(--text);
  line-height: var(--leading-snug);
}
.diff-conflict-banner {
  font-size: var(--text-xs);
  line-height: 1.5;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--warning);
  background: var(--warning-soft);
  color: var(--text);
}

/* 2026-05-14 — HITL approval caveat callout. Renders above the action
 * description when the agent provided pre-action reasoning. Amber stripe
 * to read as "warning / requires attention" without using error red. */
.approval-caveat {
  font-size: var(--text-sm);
  color: var(--text);
  background: color-mix(in srgb, var(--warning) 14%, var(--surface));
  border-left: 3px solid var(--warning);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  line-height: var(--leading-snug);
}
.approval-caveat strong {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--warning);
  margin-bottom: 3px;
}

/* 2026-05-14 — Scheduled-wakeup separator + auto-fired assistant stripe.
 * Wakeups used to render as a normal `.bubble.user` filled with multi-line
 * agent-facing imperative text, right-aligned, which made the chat look
 * off-center and confused users. Now they render as a thin centered chip
 * (matching the .day-separator visual language) that expands on click to
 * show the raw synthetic message for transparency. The assistant reply
 * that follows gets a 2px accent stripe + small "Auto-fired" caption so
 * users can tell the agent kicked itself awake, not them.
 */
.wakeup-separator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) 0 var(--space-2) 0;
}

/* Auto-fired assistant — the reply that came from a scheduled wakeup.
 * 2px accent stripe on the left side of the bubble + a tiny "Auto-fired"
 * caption above the avatar. The caption is purely visual (no
 * interaction), so we use ::before on the bubble-row. */
.bubble-row.assistant.auto-fired .bubble {
  border-left: 2px solid var(--accent);
  padding-left: calc(var(--space-4) - 2px);
}
.bubble-row.assistant.auto-fired::before {
  content: 'Auto-fired';
  position: absolute;
  top: -14px;
  left: 48px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--surface);
  padding: 0 6px;
}
.bubble-row.assistant.auto-fired {
  position: relative;
  margin-top: var(--space-5);
}

/* 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); }
}

/*
 * 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.
 */
.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);
  }
}

/* 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; }
}

/* ---------- 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 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;
}

/* ---------- 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 h3 {
  /* The chat greeting is the centerpiece of an empty conversation — size it
   * up to a real display heading (font-family/weight set by the display-serif
   * rule below). */
  font-size: var(--text-3xl);
  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);
}

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

.memory-page {
  overflow-y: auto;
  flex: 1;
}

.mcard {
  position: relative;
  isolation: isolate;
  /* Faint top-down sheen for depth, plus a top-rim light band along the top edge
     (matches the hero's feature [9]: #fff 26%, 1.5px, fading before the corners).
     Painted as the topmost background layer so it clips to the rounded corners.
     Dials: the #fff 26% alpha (brightness) and the 1.5px thickness. (2026-07-15) */
  background:
    linear-gradient(90deg,
      transparent 8%,
      color-mix(in srgb, #fff 13%, transparent) 50%,
      transparent 92%) top / 100% 1.5px no-repeat,
    linear-gradient(180deg,
      color-mix(in srgb, var(--text) 2.5%, var(--surface)),
      var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-2);
  transition: border-color var(--dur-base) var(--ease-out),
              box-shadow var(--dur-base) var(--ease-out),
              transform var(--dur-base) var(--ease-out);
}
/* Cursor spotlight — a soft brand glow that tracks the pointer (app.js sets
 * --mx/--my). The marketing site's signature card affordance. Drawn as a
 * z-index:-1 ::before (paints above the card fill, below the content) and
 * clipped to the rounded rect via border-radius:inherit — no overflow:hidden,
 * so the header's focus ring is never clipped. Defaults to centred (50% 50%)
 * for reduced-motion users, where app.js skips the pointer tracking. */
.mcard::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(260px circle at var(--mx, 50%) var(--my, 50%),
              color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%);
  opacity: 0;
  transition: opacity var(--dur-slow) var(--ease-out);
}
/* Light-catching gradient edge on hover — masked so only the 1px border
 * lights up. Plain cards only; pinned/insight carry their own accent stripe. */
.mcard:not(.pinned):not(.insight)::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  pointer-events: none;
  background: linear-gradient(135deg,
              color-mix(in srgb, var(--accent) 55%, transparent), transparent 45%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .mcard:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-glow);
    transform: translateY(-2px);
  }
  .mcard:hover::before { opacity: 1; }
  .mcard:not(.pinned):not(.insight):hover::after { opacity: 1; }
}

.mcard.pinned {
  /* Pinned reads as a distinct, "lit" tier: an accent-tinted wash, a glowing
   * left edge (stripe + inner hairline), and a warmer border. */
  border-color: color-mix(in srgb, var(--accent) 32%, var(--border));
  background: linear-gradient(180deg,
              color-mix(in srgb, var(--accent) 12%, var(--surface)),
              color-mix(in srgb, var(--accent) 4%, var(--surface)));
  border-left: 3px solid var(--accent);
  box-shadow: inset 1px 0 0 color-mix(in srgb, var(--accent) 45%, transparent);
}
@media (hover: hover) and (pointer: fine) {
  .mcard.pinned:hover {
    box-shadow: var(--shadow-glow),
                inset 1px 0 0 color-mix(in srgb, var(--accent) 45%, transparent);
  }
}

/* ---------- Collapsible memory cards ----------
 * Each .mcard collapses to its header by default. Click the header
 * (anywhere except the action buttons) to expand. Header shows a
 * rotating chevron, the block label, and a dim "preview" snippet of
 * the content so the page is scannable when everything's collapsed.
 */
.mcard.collapsed {
  padding-bottom: 0;
}

/* ---------- Share-modal styles (cross-user memory) ---------- */
.signin-field .hint {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* iOS-style toggle switch — used by the Advanced settings cards. */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.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;
  /* Pills are single-line badges — never let their text wrap to a stack of
     lines when squeezed inside a narrow flex row (e.g. a Kanban card). The
     containing row wraps the whole pill instead (see .wb-card-meta). */
  white-space: nowrap;
}
.pill.accent {
  background: var(--accent-soft);
  color: var(--accent);
}
.pill.danger {
  background: var(--danger-soft);
  color: var(--danger);
}
.pill.success {
  background: var(--success-soft);
  color: var(--success);
}
.pill.warning {
  background: var(--warning-soft);
  color: var(--warning);
}
/* Standalone integration-status pill classes (mirror .pill.success/.danger
   for the inline-styled Connected/Disconnected chips migrated in C20). */
.pill-success {
  background: var(--success-soft);
  color: var(--success);
}

.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;
}

/* ---------- 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;
}

.signin-logo-wrapper { text-align: center; margin-bottom: var(--space-6); }
.signin-confirmation { text-align: center; padding: var(--space-3) 0; }
.signin-confirmation-icon { font-size: var(--text-4xl); margin-bottom: var(--space-3); }
.signin-confirmation-heading { font-size: var(--text-lg); margin: 0 0 var(--space-1); }
.signin-confirmation-text { font-size: var(--text-base); color: var(--text-muted); line-height: 1.55; }
.signin-actions { text-align: center; margin-top: var(--space-3); }

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay-scrim);
  backdrop-filter: blur(var(--overlay-blur));
  -webkit-backdrop-filter: blur(var(--overlay-blur));
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  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%;
  max-height: calc(100vh - var(--space-6) * 2);
  overflow-y: auto;
  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(var(--press-scale)); }

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

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

.toast-host {
  position: fixed;
  top: calc(var(--topstrip-height) + var(--space-3));
  right: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: var(--z-toast);
  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 > span { flex: 1; min-width: 0; }
.toast-action {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background-color var(--dur-fast) var(--ease-out);
}
.toast-action:hover {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}
.toast.warning { border-left-color: var(--warning); }
.toast.danger  { border-left-color: var(--danger); }
.toast.error   { border-left-color: var(--danger); }
.toast.info    { border-left-color: var(--accent); }

@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);
}

/* ---------- Inline alerts — form/load feedback (reuses the banner recipe) ---------- */

.alert {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  border-left-width: 3px;
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
  animation: fade-in var(--dur-base) var(--ease-out);
}

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

.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:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow-lg), 0 0 0 3px var(--accent-soft);
}
.palette input::placeholder {
  color: var(--text-mute);
}

/* ---------- 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; }
}
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: var(--radius-full);
  animation: spin var(--dur-slow) linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

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

[x-cloak] { display: none !important; }

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

.settings-page {
  overflow-y: auto;
  flex: 1;
}

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

/* Inline "run in background?" proposal control under a reply. */
.async-proposal {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle, var(--surface));
  font-size: 13px;
  line-height: 1.4;
}

/* ---------- Inline agent charts (agent-produced PNG attachments) ---------- */
.bubble-charts {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: 8px;
}
.bubble-chart {
  margin: 0;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 8px);
  overflow: hidden;
  background: var(--surface-subtle, #fff);
}
.bubble-chart__img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 720px;
}
.bubble-chart__cap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-muted, #667);
  border-top: 1px solid var(--border);
}
.bubble-chart__dl {
  flex: none;
  font-size: 11.5px;
  text-decoration: none;
  color: var(--accent, #2563eb);
}
.bubble-chart__dl:hover { text-decoration: underline; }

/* ---------- 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);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

@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;
}

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .skeleton { animation: none; background: var(--surface-subtle); }
}

/* =============================================================================
 * Appshell (2026-05-12) — collapsible left rail replacing the top tab bar.
 *
 * Two-state pattern borrowed from shadcn/ui Sidebar + the Claude desktop
 * redesign: expanded (240px, icon + label) ↔ collapsed (60px, icons only
 * with hover tooltips). Slides the label out (opacity + translateX) rather
 * than fading so the collapse feels physical.
 *
 * Below 900px the rail auto-collapses; below 640px it stacks (top strip
 * stays, rail items hide behind the hamburger). Mobile is graceful
 * fallback, not the primary target (demo runs on a laptop).
 * ============================================================================= */

:root {
  --rail-width-expanded: 232px;
  --rail-width-collapsed: 60px;
  --rail-width: var(--rail-width-expanded);
  --topstrip-height: 52px;
}

.appshell {
  display: grid;
  grid-template-columns: var(--rail-width) 1fr;
  grid-template-rows: var(--topstrip-height) 1fr;
  grid-template-areas:
    "rail topstrip"
    "rail main";
  flex: 1;
  min-height: 0;
  overflow: hidden;
  transition: grid-template-columns var(--dur-base) var(--ease-out);
}

/* Grouped-sidebar preview (UI overhaul, 2026-07-08). When the active group
   has a secondary sidebar, insert a third column for it between the rail and
   the main area. The subrail spans both grid rows (it's a full-height
   column), so the topstrip starts to the right of it. */
:root {
  --subrail-width: 176px;
}

.appshell-main {
  grid-area: main;
  overflow: hidden;
  min-width: 0;
  position: relative;
  /* The chat layout inside `.appshell-main` uses `flex: 1`, so we
   * provide a flex column container for it to fill. Page-level
   * routes (memory, library, settings) override with their own
   * scroll containers; this default is harmless for them. */
  display: flex;
  flex-direction: column;
}
.appshell-main > * {
  flex: 1;
  min-height: 0;
}
/* The cross-page "working on your reply" banner is a thin status
 * strip — it must NOT inherit flex:1 from the rule above, which
 * would stretch it to fill the entire main slot. Pin to content
 * height instead. */
.appshell-main > .away-banner {
  flex: 0 0 auto;
  order: -1;   /* sits just BELOW the section tab bar (order -2); was above it */
}

/* Settings-style pages already render inside .settings-page which
 * has its own padding + max-width; they should scroll inside the
 * main slot, not push the topstrip off-screen. */
.appshell-main > .settings-page {
  overflow-y: auto;
}

/* Mobile / narrow auto-collapse. The rail collapses to icons-only
 * below 900px and disappears entirely below 640px (the topstrip's
 * hamburger button is the affordance there — see HTML). */
@media (max-width: 900px) {
  .appshell:not(.rail-overlay) {
    --rail-width: var(--rail-width-collapsed);
  }
}

@media (max-width: 640px) {
  .appshell {
    grid-template-columns: 0 1fr;
  }
}

/* =============================================================================
 * Display serif (Fraunces)
 *
 * Reserved for the largest "you've arrived somewhere" headings: the chat
 * greeting, page titles, page heroes, and the sign-in headline. Everything
 * smaller — section labels, modal/card titles, the small empty-state-card
 * placeholders, body, UI, chat — stays Inter, exactly how the marketing site
 * uses the serif only at display scale (small serif reads muddy on screen).
 *
 * Weight 500 + gentle negative tracking is the site's display cut; Fraunces'
 * optical-size axis auto-selects the right drawing for each heading's size.
 * Placed after the hero/empty-state component rules so it wins source-order
 * for the font properties without a specificity bump. */
.text-display,
.text-page-title,
.page-hero h1,
.page-hero h2,
.carve-hero h2,
.carve-hero .carve-title,
.wb-title,
.empty-state h3,
.signin-card h1,
.signin-card h2 {
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: -0.02em;
  font-optical-sizing: auto;
}

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

/* =============================================================================
 * carve_UI — the canonical page recipe (2026-06-29)
 * The single page frame every route should adopt so all 10 pages are uniform.
 * It's a thin, additive layer over the proven .memory-page/.page-hero patterns:
 *   <div class="carve-page route-fade">         scroll container, fills slot
 *     <div class="carve-container [wide|narrow]"> centered column + gutters
 *       <header class="carve-hero"> h2 + p + .carve-hero-stats </header>
 *       <section class="carve-section"> ...cards... </section>
 * Existing pages keep working; new/migrated pages use these classes. Canonical
 * usage + component rules live in the carve_UI skill (.claude/skills/carve_ui).
 * ============================================================================= */

/* Hero — one header treatment for every page. h2 in the strong sub-Medium
 * weight (not 700), a muted lead, and an optional stat row. The accent wash
 * ::before is the same diagonal glow .page-hero uses, so the two are
 * interchangeable and a migrated page reads identically to Memory/Library. */
.carve-hero {
  position: relative;
  padding: 28px 0 22px 0;
  margin-bottom: var(--space-5);
  border-bottom: 1px solid var(--border);
}
.carve-hero::before {
  content: "";
  position: absolute;
  inset: -8px -16px 0 -16px;
  z-index: 0;
  pointer-events: none;
  border-radius: var(--radius-xl);
  /* Same per-sub-tab glow geometry as .page-hero::before (idea #10). */
  background: linear-gradient(var(--hero-glow-angle, 135deg),
              color-mix(in srgb, var(--accent) 22%, transparent) 0%,
              color-mix(in srgb, var(--accent-2) 18%, transparent) 100%);
}
html.dark .carve-hero::before {
  background: linear-gradient(var(--hero-glow-angle, 135deg),
              color-mix(in srgb, var(--accent) 18%, transparent) 0%,
              color-mix(in srgb, var(--accent-2) 14%, transparent) 100%);
}
.carve-hero > * { position: relative; z-index: 1; }
/* Pixel-identical to .page-hero h2 (Memory/Library): 28px, and Fraunces @ 500
 * via the shared display-font rule below (which lists .carve-hero h2). The
 * font-weight here is overridden to 500 by that later same-specificity rule —
 * size + line-height + margin are what this rule contributes. Keep in lockstep
 * with .page-hero h2 so migrated pages never diverge from the reference pages. */
.carve-hero h2,
.carve-hero .carve-title {
  font-size: 28px;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin: 0 0 8px 0;
  color: var(--text);
}
.carve-hero p,
.carve-hero .carve-lead {
  margin: 0;
  font-size: var(--text-base);   /* matches .page-hero p */
  color: var(--text-muted);
  line-height: 1.55;
  max-width: 64ch;
}

/* =============================================================================
 * Hero visual refresh (2026-07-15) — sequential craft pass on the shared
 * .page-hero / .carve-hero masthead. Purely additive: placed after both hero
 * definitions so equal-specificity rules win by source order, and applied one
 * feature at a time. New features stack above the insertion sentinel below.
 * ============================================================================= */

/* [2] Bigger, tighter title — lift the hero title from 28px to a responsive
 * 30–34px with firmer negative tracking, widening the title→body ratio so the
 * masthead reads as deliberate. Overrides the shared hero-title size and the
 * display-font rule's -0.02em tracking (both earlier in source order). */
.page-hero h1,
.page-hero h2,
.carve-hero h2,
.carve-hero .carve-title {
  font-size: clamp(30px, 2.4vw, 34px);
  letter-spacing: -0.028em;
  line-height: 1.08;
}

/* [3] Optical wrapping — balance the title so a multi-line heading splits
 * evenly instead of stranding one word on the last line, and let the lead
 * paragraph avoid orphans. Progressive enhancement: browsers without text-wrap
 * support simply ignore these, so there's no downside. */
.page-hero h1,
.page-hero h2,
.carve-hero h2,
.carve-hero .carve-title {
  text-wrap: balance;
}
.page-hero p,
.carve-hero p,
.carve-hero .carve-lead {
  text-wrap: pretty;
}

/* [5] Contained masthead plate — lift the hero off the page as a defined
 * rounded surface instead of a glow that bleeds into the gutters. Horizontal
 * padding pulls the text in from the plate edge.
 * No overflow:hidden and no real border: overflow:hidden's rounded clip shaves
 * a 1px edge line off at the corners (the ring survived on the straight sides
 * but broke around the curve). Instead the glow (::before) clips to its OWN
 * border-radius, and the hairline is a dedicated ::after ring that is never
 * clipped — so it wraps all four corners cleanly. */
.page-hero,
.carve-hero {
  padding: 22px 24px 20px 24px;
  border: none;
  border-radius: var(--radius-xl);
  background: color-mix(in srgb, var(--surface) 60%, transparent);
}
/* Glow fills the plate; its own border-radius clips the wash to the rounded
 * corners (was inset -8px -16px 0 -16px, bleeding out). */
.page-hero::before,
.carve-hero::before {
  inset: 0;
  border-radius: inherit;
}
/* Hairline edge — a full-wrap rounded ring, painted above the glow and never
 * clipped, so all four corners meet cleanly. */
.page-hero::after,
.carve-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  /* Hairline nudged a touch darker than --border so the plate edge reads a
     little more defined (Thomas 2026-07-15). */
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--border), #000 4%);
  pointer-events: none;
  z-index: 0;
}

/* [7] Grain — a whisper of tiling SVG noise, soft-light blended over the glow
 * to kill gradient banding and give the plate a matte, premium texture. The
 * diagonal glow is re-stated (feature 6's radial was removed) with the noise
 * layered above it; the base ::before rule's border-radius/inset are untouched.
 * Static — nothing animates. */
.page-hero::before,
.carve-hero::before {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.07'/%3E%3C/svg%3E"),
    linear-gradient(var(--hero-glow-angle, 135deg),
      color-mix(in srgb, var(--accent) 22%, transparent) 0%,
      color-mix(in srgb, var(--accent-2) 18%, transparent) 100%);
  background-size: 140px 140px, auto;
  background-blend-mode: soft-light, normal;
}
html.dark .page-hero::before,
html.dark .carve-hero::before {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E"),
    linear-gradient(var(--hero-glow-angle, 135deg),
      color-mix(in srgb, var(--accent) 18%, transparent) 0%,
      color-mix(in srgb, var(--accent-2) 14%, transparent) 100%);
  background-size: 140px 140px, auto;
  background-blend-mode: soft-light, normal;
}

/* [8] Quiet the glow — pull the whole wash back so the plate whispers colour and
 * the title leads, instead of the accent competing with it. Done as an opacity
 * on the glow pseudo (fades glow + grain together; leaves the ::after hairline
 * ring and the text untouched) so it's a single, cleanly-removable dial. */
.page-hero::before,
.carve-hero::before {
  opacity: 0.62;
}

/* [9] Gradient top highlight — a faint band of light along the plate's top edge
 * that fades toward the corners, so the plate looks lit from above rather than
 * flatly outlined. Painted as a 1.5px gradient on the ::after ring layer (above
 * the glow, below content), clipped to the rounded top by the ::after radius so
 * it curves off at the corners. */
.page-hero::after,
.carve-hero::after {
  background: linear-gradient(90deg,
      transparent 8%,
      color-mix(in srgb, #fff 26%, transparent) 50%,
      transparent 92%) top / 100% 1.5px no-repeat;
}

/* [14] Glyph watermark — the CarveAI isometric AI monogram (filled silhouette,
 * see carve-mono.svg) cropped into the plate's top-right corner: a faint brand
 * flourish, identical on every hero, parked where the glow is weakest so it
 * stays legible without competing. Grey + theme-neutral; geometry angle-
 * corrected to a perfect isometric grid (every edge exactly -30/+30/vertical).
 * Painted on the ::after layer (above the glow, clipped to the rounded
 * corner); this rule restates feature 9's top-highlight alongside it, so
 * removing this block hands the highlight back to feature 9's rule above. */
.page-hero::after,
.carve-hero::after {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-6 -6 327 376'%3E%3Cpath d='M198.2,198.9L198.2,105.5L157.8,82.2L109.7,109.9L193.7,158.5L193.7,340.4L155.5,362.4L120.7,342.3L120.7,301.8L70.0,272.5L35.5,292.5L0.8,272.5L0.8,91.7L160.3,-0.5L314.5,88.5L314.5,129.2L279.2,149.6L269.0,143.7L269.0,202.0L314.4,228.3L314.4,271.4L280.4,291.0L193.4,240.8ZM38.0,208.8L123.8,258.3L123.8,199.4L38.0,149.8Z' fill='%238b90a3' fill-opacity='0.13'/%3E%3C/svg%3E") calc(100% + 2px) calc(50% - 22px) / auto 134px no-repeat,
    linear-gradient(90deg,
      transparent 8%,
      color-mix(in srgb, #fff 26%, transparent) 50%,
      transparent 92%) top / 100% 1.5px no-repeat;
}
html.dark .page-hero::after,
html.dark .carve-hero::after {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-6 -6 327 376'%3E%3Cpath d='M198.2,198.9L198.2,105.5L157.8,82.2L109.7,109.9L193.7,158.5L193.7,340.4L155.5,362.4L120.7,342.3L120.7,301.8L70.0,272.5L35.5,292.5L0.8,272.5L0.8,91.7L160.3,-0.5L314.5,88.5L314.5,129.2L279.2,149.6L269.0,143.7L269.0,202.0L314.4,228.3L314.4,271.4L280.4,291.0L193.4,240.8ZM38.0,208.8L123.8,258.3L123.8,199.4L38.0,149.8Z' fill='%238b90a3' fill-opacity='0.16'/%3E%3C/svg%3E") calc(100% + 2px) calc(50% - 22px) / auto 134px no-repeat,
    linear-gradient(90deg,
      transparent 8%,
      color-mix(in srgb, #fff 26%, transparent) 50%,
      transparent 92%) top / 100% 1.5px no-repeat;
}

/* ·· hero-refresh insertion point — features stack above this ·· */

/* =============================================================================
 * Library page — segmented control + dense row layout
 * ============================================================================= */

.library-tabs {
  display: inline-flex;
  background: var(--surface-subtle);
  padding: 3px;
  border-radius: var(--radius-md);
  gap: 2px;
}
.library-tab {
  display: inline-flex;
  align-items: center;
  min-height: var(--tab-height);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}
.library-tab.active {
  /* Selected pill: indigo scheme (--accent text on --accent-soft) matching the
     sidebar + top-bar tabs. Because --accent-soft sits close to the grey track,
     the fill alone doesn't read as selected — so lift + outline it (the standard
     "selected segment" treatment): a soft elevation shadow to raise it off the
     track + a crisp 1px --accent ring to define it. Neither base colour changes.
     Applies to every .library-tab pill selector (Memory/Library sub-tabs, Agenda
     Reminders/To-Do + Events pills, Settings tabs, admin sub-nav). (2026-07-15) */
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: var(--shadow-sm),
              inset 0 0 0 1px color-mix(in srgb, var(--accent) 50%, transparent);
}
.library-tab .count {
  margin-left: 6px;
  font-size: 11px;
  color: var(--text-muted);
}
.library-tab:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Memory page — pinned-card accent moved into the existing
 * `.mcard.pinned` rule (above) which is what the HTML actually
 * uses. The `.memory-card-pinned` class never appeared in markup. */

/* =============================================================================
 * Keyboard hint chip + cheatsheet overlay
 * ============================================================================= */

.cheatsheet {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px 28px;
}
.cheatsheet h2 {
  margin: 0 0 16px 0;
  font-size: var(--text-xl);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

/* =============================================================================
 * Sign-in polish — remember-me checkbox, demo button, form refinements
 * ============================================================================= */

.signin-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-muted);
  user-select: none;
  cursor: pointer;
}
.signin-remember input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: background-color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}
.signin-remember input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.signin-remember input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.signin-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: var(--space-3) 0 var(--space-2) 0;
  font-size: 11px;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.signin-divider::before,
.signin-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* =============================================================================
 * Onboarding wizard rebuild (2026-05-12)
 * ============================================================================= */

.onboard-checks {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
  padding: 16px 18px;
  background: var(--surface-subtle);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}
.onboard-check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--text-sm);
  color: var(--text);
  opacity: 0;
  transform: translateY(2px);
  animation: onboardCheckIn var(--dur-celebrate) var(--ease-out) forwards;
}
.onboard-check.check-1 { animation-delay: 100ms; }
.onboard-check.check-2 { animation-delay: 350ms; }
.onboard-check.check-3 { animation-delay: 600ms; }

.onboard-check-icon {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  background: var(--success);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

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

.onboard-tz-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface-subtle);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
.onboard-tz-name {
  font-family: 'JetBrains Mono', monospace;
  font-size: var(--text-sm);
  color: var(--text);
}
.onboard-tz-clock {
  font-variant-numeric: tabular-nums;
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--accent);
}

.onboard-avatar-swatches {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}
.onboard-swatch {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: transform var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.onboard-swatch:active { transform: scale(var(--press-scale)); }
.onboard-swatch:hover { transform: scale(1.06); }
.onboard-swatch.selected {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--bg) inset;
}
.onboard-swatch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.onboard-example-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.onboard-example-chips .chip {
  font-size: 12px;
  padding: 4px 10px;
}

/* =============================================================================
 * Right-click context menu (Linear pattern)
 * ============================================================================= */

@keyframes ctxMenuIn {
  from { opacity: 0; transform: translateY(-2px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Display & accessibility popover ----------
 * Anchored under the trigger button (in the global topstrip, next to
 * ⌘K). Floats above content; uses the same surface/shadow tokens as
 * the existing avatar menu. */

/* Segmented control — single-select chip row. Used inline in both the
 * popover and the Settings card. */
.segmented {
  display: inline-flex;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}
.segmented-option {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 36px;
  height: 26px;
  padding: 0 10px;
  background: transparent;
  border: none;
  border-radius: calc(var(--radius-sm) - 2px);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}
.segmented-option:hover {
  color: var(--text);
}
.segmented-option[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* Settings section tabs (2026-06-18) — top-of-page underline tab bar that
 * groups the Settings cards into User info / General / Tooling / Memory. */
/* Settings tabs use the canonical .library-tab(s) component (re-classed
 * 2026-06-19); the old .settings-tab(s) rules were removed as dead. */

.toggle-switch {
  position: relative;
  width: 36px;
  height: 20px;
  background: var(--border);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background var(--dur-fast) var(--ease-out);
}
.toggle-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #FFFFFF;
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-fast) var(--ease-out);
}
.toggle-switch[aria-pressed="true"] {
  background: var(--accent);
}
.toggle-switch[aria-pressed="true"]::after {
  transform: translateX(16px);
}
.toggle-switch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* =============================================================================
 * Premium motion layer
 *
 * The marketing site's "feels alive" polish, brought into the product at a
 * restrained, daily-tool intensity: a crossfade when you switch tabs, a small
 * staggered entrance on the chat suggestions, and the conic glow-border on the
 * approval card — the one place a looping animation earns its keep, because it
 * means "a decision is waiting on you". Everything here degrades to nothing
 * under reduced-motion (OS query below + the in-app data-reduce-motion kill
 * switch near the top of this file).
 * ============================================================================= */

/* ---- Tab crossfade. Each route view mounts fresh as a direct child of
 *      .appshell-main (Alpine x-if), so a mount animation fires on switch.
 *      Opacity-only by design: never transforms a scroll / sticky ancestor. */
@keyframes route-crossfade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
/* :not(.route-fade) — six route roots (memory/library/documents/tasks/workbench/
 * manage) already carry the pre-existing .route-fade class, whose routeFadeIn
 * keyframe adds a 2px translateY settle. Leave those to it and only crossfade
 * the roots that had no entrance before (chat, projects, settings), so every
 * tab gets exactly one transition with no double-animation. */
.appshell-main > div:not(.route-fade) {
  animation: route-crossfade var(--dur-slow) var(--ease-out);
}

/* ---- Conic glow-border (the site's signature). The ring is a masked
 *      ::before sitting exactly on the border; pointer-events:none keeps the
 *      content clickable. --glow-border-color defaults to the brand accent;
 *      the approval card overrides it to --warning to match its amber theme,
 *      so the motion reads as "this needs your attention" rather than decor. */
@property --gb-angle {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}
.approval-card--nested{background:color-mix(in srgb,var(--text) 4%,var(--surface));border:1px solid color-mix(in srgb,var(--accent) 18%,var(--border));border-radius:var(--radius-card);}

/* ---- Reduced motion (OS query): kill the loop and skip entrances so the UI
 *      arrives settled, never jumpy. Opacity/color transitions elsewhere are
 *      intentionally left alone (reduced means gentler, not zero). */
@media (prefers-reduced-motion: reduce) {
  .appshell-main > div,
  .suggested-prompts .prompt-tile { animation: none; }
  /* Keep the memory-card glow (opacity), drop the positional lift. */
  .mcard:hover { transform: none; }
  .bubble-row, .follow-up-row, .empty-state, .empty-state-card, .scroll-to-bottom { animation: none; }
}

/* =============================================================================
 * Material sheen — repo-wide box consistency
 *
 * Extends the memory-card depth (a faint top-down sheen) to the remaining
 * content cards/panels so every box in the app reads as one material, not a
 * flat fill: the sign-in card, Manage dashboard panels, Workbench cards,
 * Library file rows, task rows, and the shortcuts cheatsheet. One override
 * placed last so it wins source-order without editing each rule's background.
 *
 * Deliberately NOT included (they should stay flat): inputs/textarea (recessed
 * fields), chips, the slash/context menus, command palette, toasts, and
 * buttons — sheen on those would read as wrong-material.
 * ============================================================================= */
.signin-card,
.manage-card,
.wb-card,
.library-row,
.upload-row,
.grant-row,
.task-row,
.modal,
.cheatsheet {
  /* Top-down material sheen + a top-rim light band (matches the hero's feature
     [9]: #fff 26%, 1.5px, fading before the corners) as the topmost background
     layer, so every plate that shares this material also catches the top rim.
     Dials: the #fff 26% alpha (brightness) and the 1.5px thickness. (2026-07-15) */
  background:
    linear-gradient(90deg,
      transparent 8%,
      color-mix(in srgb, #fff 13%, transparent) 50%,
      transparent 92%) top / 100% 1.5px no-repeat,
    linear-gradient(180deg,
      color-mix(in srgb, var(--text) 2.5%, var(--surface)),
      var(--surface));
}

/* ------------------------------------------------------------------ */
/* Email triage buckets (2026-06-24) — Tasks ▸ Email sub-tab.          */

/* Metric drill-down (reusable expand-to-detail, 2026-06-24) -------------- */

/* FLIP-driven master->detail: 0.5s, others fade, the clicked box translates
   to the top carrying its graph. The detail overlays (absolute) during the
   move so the fading boxes don't push it down, then settles into flow. */
.manage-detail-host { position: relative; }

/* Stack the normal view and the detail in ONE css-grid cell so the detail's
   resting position is fixed (no absolute->static snap, no padding offset).
   The fading normal view sits behind; the detail (z-index 2) is on top. */
.manage-detail-host { display: grid; align-items: start; }
.manage-detail-host > * { grid-area: 1 / 1; min-width: 0; }

/* ---------------------------------------------------------------------------
   To-Do (2026-06-30) — manual checklist shell on the Tasks page. Tokens mirror
   the triage/tasks panes so it sits consistently next to them.
--------------------------------------------------------------------------- */

.live-browser-frame {
  display: block;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 8px);
  background: #000;
}
.live-browser-url {
  margin-top: var(--space-2, 8px);
  font-family: var(--mono, ui-monospace, monospace);
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ------------------------------------------------------------------ */
/* Product tour (2026-07-01, item 3) — opt-in spotlight walkthrough.    */
/* Sits above modals (z 70) but below toasts (z 90) so a success toast  */
/* can still surface over it.                                           */

/* --- Tier cards: the three routing tiers as interactive cards ----------- */
.mdl-tiers {
  display: grid;
  /* Container-adaptive: 3 columns whenever the admin content PANE is ~660px+
     (the common case), dropping to 2 then 1 as the pane narrows — keyed off the
     grid's own width, not the viewport. The old fixed repeat(3) crammed three
     ~150px cards (clipping model names like "DeepSeek v3.2") when the pane was
     narrow but the window wide, because the viewport media query never fired.
     auto-fit gives each card real width instead. */
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
  /* Align with the rest of the Models tab: every panel below (usage, catalog,
     Advanced, benchmark) is a details.adm-collapse capped at max-width:900px
     (index.html inline styles), but this strip had NO cap — so the tier row ran
     the full pane width and the rightmost (hard) card overhung the column all
     the other panels align to, reading as "the hard card spills over". One
     shared column instead. */
  max-width: 900px;
}
/* The "Keep Claude inside AWS" toggle sits between the tiers and the panels —
   same 900px column so the whole tab lines up. */
#admin-view .mdl-switch-row { max-width: 900px; }
.mdl-tier-card {
  background: var(--surface, #fff);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  min-width: 0;   /* allow shrink below the select's intrinsic width */
  /* Hard containment: a native <select> value (e.g. a long unlisted id like
     "claude-haiku-4-5-20251001 (unlisted)") does NOT honor text-overflow in
     every browser (Safari/Firefox render the full value). Clip at the card's
     own box so a long model name can never spill into the neighbouring tier
     column, regardless of engine. */
  overflow: hidden;
  transition: border-color .15s ease, box-shadow .15s ease;
}
/* Keep the borderless title-select from painting past the clipped card edge. */
#admin-view .mdl-model-select { max-width: 100%; }
.mdl-tier-card:hover { border-color: var(--border-strong); box-shadow: 0 2px 10px rgba(0,0,0,.04); }
/* Tier accent: a slim top bar keyed by tier. */
.mdl-tier-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  border-radius: 10px 10px 0 0;
}
.mdl-tier-card[data-tier="easy"]::before   { background: #059669; }
.mdl-tier-card[data-tier="medium"]::before { background: var(--accent); }
.mdl-tier-card[data-tier="hard"]::before   { background: #9333EA; }
.mdl-tier-head { display: flex; align-items: center; justify-content: space-between; }
.mdl-tier-name { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); }
.mdl-tier-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mdl-tier-foot { display: flex; align-items: center; justify-content: space-between; margin-top: auto; }
.mdl-tier-desc { font-size: 11px; color: var(--text-mute); }
/* Compact inline chip in the tier meta row — NOT a full-width banner (that
   made non-Claude cards a whole row taller than Claude ones, so the tier
   columns looked broken/oversized). The full warning lives in the title tip. */
.mdl-tier-caution {
  font-size: 10.5px; font-weight: 600; line-height: 1; white-space: nowrap;
  color: var(--warning); background: var(--warning-soft);
  border: 1px solid var(--warning); border-radius: 100px; padding: 3px 8px;
}
.mdl-reset {
  border: none; background: none; color: var(--accent); font-size: 12px;
  cursor: pointer; padding: 2px 6px; border-radius: 6px;
}
.mdl-reset:hover { background: var(--accent-soft); }

/* The model name IS the picker: a borderless select styled as a title. */
.mdl-model-select {
  appearance: none; -webkit-appearance: none;
  border: none; background: transparent; width: 100%;
  font-size: 13.5px; font-weight: 650; color: var(--text);
  padding: 0 16px 0 0; cursor: pointer;
  /* Clip a long model name to the card with an ellipsis instead of letting the
     select's intrinsic width overflow the tier column. */
  min-width: 0; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2352525B' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 2px center;
}
.mdl-model-select:hover { color: var(--accent); }
.mdl-model-select:focus { outline: none; }

/* --- Chips --------------------------------------------------------------- */
.mdl-chip {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 10.5px; font-weight: 600; line-height: 1;
  padding: 3px 7px; border-radius: 999px; white-space: nowrap;
}
.mdl-chip-custom  { background: var(--accent-soft); color: var(--accent); }
.mdl-chip-default { background: var(--surface-2, #F4F4F5); color: var(--text-mute); }
.mdl-chip-aws     { background: rgba(255,153,0,.12); color: #B45309; }
.mdl-chip-api     { background: var(--surface-2, #F4F4F5); color: var(--text-muted); }
.mdl-chip-gated   { background: var(--warning-soft); color: var(--warning); margin-left: 6px; }
.mdl-chip-tool    { background: var(--accent-soft); color: var(--accent); margin-left: 6px; }
.mdl-price { font-size: 11.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.mdl-ctx   { font-size: 11.5px; color: var(--text-mute); font-variant-numeric: tabular-nums; }

/* --- AWS switch row ------------------------------------------------------ */
.mdl-switch-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-muted);
  margin: 2px 2px 14px; cursor: pointer; user-select: none;
}
.mdl-switch-input { display: none; }
.mdl-switch {
  width: 30px; height: 17px; border-radius: 999px; flex: none;
  background: var(--border-strong); position: relative; transition: background .15s ease;
}
.mdl-switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 13px; height: 13px; border-radius: 50%;
  background: #fff; transition: transform .15s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.mdl-switch-input:checked + .mdl-switch { background: var(--accent); }
.mdl-switch-input:checked + .mdl-switch::after { transform: translateX(13px); }

/* --- Catalog toolbar + dense list ---------------------------------------- */
.mdl-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 8px;
}
.mdl-search { max-width: 220px; font-size: 13px; padding: 6px 10px; }
.mdl-fam-filter { max-width: 150px; font-size: 12px; padding: 6px 8px; }
.mdl-check { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-muted); }

.mdl-list {
  border: 1px solid var(--border); border-radius: 12px;
  max-height: 420px; overflow-y: auto; overflow-x: hidden;
  margin-bottom: 14px; background: var(--surface, #fff);
}
.mdl-row {
  display: grid;
  grid-template-columns: 44px 10px minmax(140px, 1.4fr) minmax(70px, .8fr) 92px 46px 84px 78px;
  align-items: center; gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
.mdl-row:last-child { border-bottom: none; }
.mdl-row:hover { background: var(--accent-soft); }
.mdl-row-gated { opacity: .55; }
.mdl-name { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mdl-fam { color: var(--text-mute); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mdl-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.mdl-meter {
  height: 5px; border-radius: 999px; background: var(--surface-2, #F4F4F5);
  overflow: hidden; position: relative;
}
.mdl-meter-fill {
  display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, #059669, var(--accent) 55%, #9333EA);
}
.mdl-tools { font-size: 11px; white-space: nowrap; }
.mdl-tools-excellent { color: var(--success); }
.mdl-tools-good      { color: var(--accent); }
.mdl-tools-basic     { color: var(--text-mute); }
.mdl-tools-none      { color: var(--warning); }

/* One-click tier assignment: hidden until row hover. */
.mdl-assign { display: flex; gap: 4px; justify-content: flex-end; opacity: 0; transition: opacity .12s ease; }
.mdl-row:hover .mdl-assign { opacity: 1; }
.mdl-assign-btn {
  width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--border-strong);
  background: var(--surface, #fff); color: var(--text-muted);
  font-size: 10.5px; font-weight: 700; cursor: pointer; line-height: 1;
}
.mdl-assign-btn:hover:not([disabled]) { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.mdl-assign-btn[disabled] { opacity: .4; cursor: not-allowed; }
.mdl-assign-btn[data-tier="easy"]:hover:not([disabled])   { border-color: #059669; color: #059669; background: var(--success-soft); }
.mdl-assign-btn[data-tier="hard"]:hover:not([disabled])   { border-color: #9333EA; color: #9333EA; background: rgba(147,51,234,.08); }

/* --- Model usage & cost: per-model calls + spend table ------------------- */
.mdl-usage-tbl { border-collapse: collapse; font-size: 12.5px; }
.mdl-usage-tbl th {
  text-align: left; font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-mute);
  padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.mdl-usage-tbl td { padding: 6px 12px; border-bottom: 1px solid var(--border); color: var(--text); }
.mdl-usage-tbl tbody tr:hover { background: var(--accent-soft); }
.mdl-usage-tbl .mdl-usage-total td {
  border-top: 1.5px solid var(--border-strong); border-bottom: none; color: var(--text);
}
.mdl-usage-total:hover { background: transparent; }
/* Flush the first/last columns to the panel edges so table content lines up
   with the section labels + notes above them (kills the ragged 12px indent). */
.mdl-usage-tbl th:first-child, .mdl-usage-tbl td:first-child { padding-left: 0; }
.mdl-usage-tbl th:last-child, .mdl-usage-tbl td:last-child { padding-right: 0; }
/* Section label above each sub-report — a quiet uppercase caption, matching
   the table-header treatment, instead of an ad-hoc bold line. */
.mdl-usage-sec { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; flex-wrap: wrap; }
.mdl-usage-sec-title { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted); }
/* Separate the stacked sub-reports (estimate / AWS-live / AWS-bill) with a
   hairline + breathing room so they read as distinct blocks, not one wall. */
.mdl-usage-block { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--border); }
.mdl-usage-note { margin: 8px 0 0; font-size: 11.5px; color: var(--text-mute); line-height: 1.5; }
.mdl-usage-subhead { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted); }

/* --- Advanced: per-call-site matrix -------------------------------------- */
.mdl-sites { margin-top: 8px; }
.mdl-site-group {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-mute); padding: 10px 2px 4px;
  border-bottom: 1px solid var(--border); margin-bottom: 2px;
}
.mdl-site-row {
  display: grid; grid-template-columns: 14px minmax(160px, 1fr) minmax(220px, 1.2fr);
  align-items: center; gap: 8px; padding: 4px 2px; font-size: 12.5px;
}
.mdl-site-row:hover { background: var(--accent-soft); border-radius: 8px; }
.mdl-site-label { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mdl-site-dot {
  width: 7px; height: 7px; border-radius: 50%;
  border: 1.5px solid var(--border-strong); background: transparent;
}
.mdl-site-dot.on { background: var(--accent); border-color: var(--accent); }
.mdl-site-select {
  font-size: 12px; padding: 4px 8px;
  /* Pin to the grid track and clip a long option label ("DeepSeek v3.2 —
     $0.62/$1.85 /M") instead of letting the select's intrinsic width push past
     its column. */
  width: 100%; max-width: 100%; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Dark mode: rely on tokens; fix the few hard-coded lights. */
html.dark .mdl-tier-card,
html.dark .mdl-list,
html.dark .mdl-assign-btn { background: var(--surface, #16161A); }
html.dark .mdl-chip-default,
html.dark .mdl-chip-api,
html.dark .mdl-meter { background: rgba(255,255,255,.08); }
html.dark .mdl-chip-aws { color: #F59E0B; }

/* Admin console two-level nav: the sub-tab row under the group pills. */
.adm-subnav { margin-top: -6px; margin-bottom: 4px; }
.adm-subnav .library-tab { font-size: 12px; padding: 4px 12px; }
.adm-subnav.hidden { display: none; }
.mdl-site-dead { opacity: .55; }
.mdl-site-dead .mdl-site-label { color: var(--text-mute); }

/* Keys "In use right now" rows: first column sized for a tier pill (the
   14px mdl-site-row dot column made pills overlap the model name). */
.mdl-key-row {
  display: grid; grid-template-columns: 84px minmax(160px, 1fr) auto;
  align-items: center; gap: 10px; padding: 5px 12px; font-size: 12.5px;
}
.mdl-key-row:hover { background: var(--accent-soft); }
.mdl-key-tier { display: flex; justify-content: flex-start; }
.mdl-key-tier .pill { min-width: 62px; text-align: center; }

/* The admin view's inline `#admin-view select` rule (ID specificity) beats
   the class — re-assert the borderless title-style tier picker under the ID. */
#admin-view .mdl-model-select {
  appearance: none; -webkit-appearance: none;
  border: none; background-color: transparent; width: 100%;
  font-size: 13.5px; font-weight: 650; color: var(--text);
  padding: 0 16px 0 0; cursor: pointer; box-shadow: none; border-radius: 0;
  min-width: 0; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#admin-view .mdl-model-select:hover { color: var(--accent); }

/* Org Admin header: breathing room between the title, tenant name and role
   pill (they rendered flush together). */
#admin-view .carve-hero { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
#admin-view .carve-hero h2 { margin-right: 2px; }

/* Admin tables: action buttons read as row affordances, not page CTAs.
   Compact size; destructive stays red but as a quiet outline until hover
   (a filled red "Remove" on every member row out-shouted the actual data). */
#admin-view table .btn {
  padding: 4px 12px; font-size: 12px; border-radius: 8px; line-height: 1.3;
}
#admin-view table .btn-danger {
  background: transparent; color: #DC2626; border: 1px solid rgba(220, 38, 38, .45);
}
#admin-view table .btn-danger:hover { background: #DC2626; color: #fff; border-color: #DC2626; }
#admin-view table .btn-primary {
  background: transparent; color: var(--accent); border: 1px solid var(--accent-soft);
}
#admin-view table .btn-primary:hover { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
html.dark #admin-view table .btn-danger { color: #F87171; border-color: rgba(248, 113, 113, .4); }

/* MCP "Test connection" — a live reachability + tool-list probe rendered into
   the server's detail row. Green when reachable, red on failure; tokenized. */
#admin-view .mcp-test-row > td { border-top: none; }
.mcp-test-result {
  margin: 0 0 8px; padding: 10px 12px; border-radius: var(--radius-md);
  border: 1px solid var(--border); background: var(--surface-subtle);
  font-size: 12.5px; line-height: 1.45;
}
.mcp-test-result.ok { border-color: var(--success); background: var(--success-soft); }
.mcp-test-result.err { border-color: var(--danger); background: var(--danger-soft); }
.mcp-test-head { font-weight: var(--weight-emphasis); }
.mcp-test-result.ok .mcp-test-head { color: var(--success); }
.mcp-test-result.err .mcp-test-head { color: var(--danger); }
.mcp-test-tools { margin: 8px 0 0; padding-left: 18px; display: grid; gap: 3px; }
.mcp-test-tools li { list-style: disc; }

/* MCP OAuth setup panel + inline credential editor: in-page forms instead of
   prompt()/confirm(), which the browser cancels when the admin switches tabs. */
#admin-view .mcp-setup {
  margin: 12px 0; padding: 14px 18px; border: 1px solid var(--border);
  border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-sm);
}
#admin-view .mcp-setup h4 { margin: 0 0 6px; }
#admin-view .mcp-setup p { margin: 6px 0; }
#admin-view .mcp-setup ol { margin: 8px 0; padding-left: 20px; }
#admin-view .mcp-setup li { margin: 8px 0; list-style: decimal; }
#admin-view .mcp-setup li .row { margin: 6px 0 0; }
#admin-view .mcp-setup-hint { font-size: 12.5px; }
/* Connector apps (provider OAuth apps): one card per provider. */
#admin-view .papp { margin: 0 0 12px; }
#admin-view .papp-section { margin: 18px 0 6px; }
#admin-view .papp-head { display: flex; align-items: center; gap: 10px; }
#admin-view .papp-head h4 { margin: 0; }
#admin-view .papp-logo[src$="/salesforce.svg"] { padding: 2px; }
#admin-view .papp-logo {
  flex: none;
  width: 28px;
  height: 28px;
  padding: 4px;
  box-sizing: border-box;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--border);
}
#admin-view .papp-facts { margin: 6px 0; display: flex; flex-direction: column; gap: 2px; }
#admin-view .papp-facts code { font-family: var(--mono); font-size: 12.5px; }
#admin-view .papp-field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; }
#admin-view .papp .mcp-setup-status.ok { color: var(--success, var(--text)); margin: 6px 0; }
#admin-view .pill.warn { color: var(--warning, var(--text-muted)); }
#admin-view .mcp-setup-status:empty { display: none; }
#admin-view .mcp-setup-status.err { color: var(--danger); margin: 6px 0; }
/* Admin → Cloud (admin.js renderCloud): AWS accounts and their capability cards. */
#admin-view .cloud .pill.success { color: var(--success); background: var(--success-soft); border-color: transparent; }
#admin-view .cloud .pill.warning { color: var(--warning); background: var(--warning-soft); border-color: transparent; }
#admin-view .cloud .pill.danger { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
#admin-view .cloud-open-row > td { background: var(--surface-subtle); }
#admin-view .cloud-detail { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 4px 16px 8px; scroll-margin-top: 16px; }
#admin-view .cloud-detail > h3 { margin: 12px 0 4px; }
#admin-view .cloud-panel { padding: 6px 0 10px; display: flex; flex-direction: column; gap: 12px; }
#admin-view .cloud-panel a.btn-primary { color: var(--on-accent); text-decoration: none; }
#admin-view .cloud-panel h4 { margin: 4px 0; font-size: var(--text-base); }
#admin-view .cloud-facts { display: flex; flex-direction: column; gap: 6px; }
#admin-view .cloud-facts code, #admin-view .cloud-panel td code { font-family: var(--mono); font-size: 12.5px; word-break: break-all; }
#admin-view .cloud-failure {
  margin: 0; padding: 10px 12px; border-radius: var(--radius-md);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); background: var(--danger-soft); color: var(--text);
}
#admin-view .cloud-setup { display: flex; flex-direction: column; gap: 8px; }
#admin-view .cloud-setup p, #admin-view .cloud-card p { margin: 0; }
#admin-view details.cloud-fold { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 8px 12px; background: var(--surface); }
#admin-view details.cloud-fold > summary { cursor: pointer; font-weight: var(--weight-emphasis, 510); }
#admin-view details.cloud-fold[open] > summary { margin-bottom: 8px; }
#admin-view details.cloud-fold > :not(summary) + * { margin-top: 8px; }
#admin-view .cloud-block { display: flex; gap: 8px; align-items: flex-start; }
#admin-view .cloud-block pre {
  flex: 1; min-width: 0; margin: 0; max-height: 300px; overflow: auto;
  white-space: pre-wrap; word-break: break-all; font-family: var(--mono); font-size: 12px; line-height: 1.5;
  background: var(--surface-subtle); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 8px 10px;
}
#admin-view .cloud-card table { margin: 8px 0 0; }
#admin-view .cloud-excess { margin-top: 10px; padding: 10px 12px; border-radius: var(--radius-md); background: var(--warning-soft); }
#admin-view .cloud-excess ul { margin: 4px 0 4px 18px; }
@media (max-width: 640px) {
  #admin-view .cloud .cloud-wide { display: none; }
  #admin-view .cloud-detail { padding: 2px 10px 6px; }
  #admin-view .cloud-block { flex-direction: column; }
  #admin-view .cloud-block pre { width: 100%; }
}
#admin-view .mcp-setup-notice {
  margin: 0 0 12px; padding: 10px 12px; border-radius: var(--radius-md);
  border: 1px solid var(--success); background: var(--success-soft); color: var(--text);
}
#admin-view .mcp-cred-edit { margin: 0 0 8px; padding: 8px 10px; }
.mcp-test-tools code {
  font-family: var(--mono); font-size: 11.5px; color: var(--text);
  background: var(--surface-raised); padding: 1px 5px; border-radius: var(--radius-sm);
}

/* Per-server tool allowlist editor (Connectors) — a checkbox per discovered
   tool; unchecked ⇒ hidden from the agent (stored in disabled_tools). */
.mcp-tools-edit { border-color: var(--border); background: var(--surface-subtle); }
.mcp-tools-grid { margin: 8px 0 0; display: grid; gap: 4px; }
.mcp-tool-row {
  display: flex; align-items: baseline; gap: 8px; font-size: 12.5px;
  padding: 3px 4px; border-radius: var(--radius-sm); cursor: pointer;
}
.mcp-tool-row:hover { background: var(--surface-raised); }
.mcp-tool-row input { margin: 0; flex-shrink: 0; align-self: center; }
.mcp-tool-row code {
  font-family: var(--mono); font-size: 11.5px; color: var(--text);
  background: var(--surface-raised); padding: 1px 5px; border-radius: var(--radius-sm);
}

/* Models tab: catalog + advanced are collapsed <details> so the tab lands on
   the 3 tier cards. Give those top-level collapsibles a card-like surface. */
#admin-view .mdl-tiers + .mdl-switch-row + details.adm-collapse,
#admin-view details.adm-collapse.mdl-topwrap { margin-top: 6px; }
/* Nested per-call-site group headers: compact, with an active accent. */
.mdl-sites details.adm-collapse-nested { margin: 2px 0; }
.mdl-sites details.adm-collapse-nested > summary { font-size: 12.5px; padding: 7px 10px; }
.mdl-sites details.mdl-group-active > summary { color: var(--accent); font-weight: 600; }
.mdl-sites .mdl-site-row { padding-left: 14px; }

