/* ── Noto Sans (self-describing @font-face, served by Fontsource/jsDelivr) ──
   Declared here because every page loads this file, so no page needs its own
   font <link>. One modern sans for everything: display, prose, and chrome.
   Noto Sans Mono carries code. */
@font-face {
  font-family: "Noto Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("https://cdn.jsdelivr.net/fontsource/fonts/noto-sans@latest/latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Noto Sans";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("https://cdn.jsdelivr.net/fontsource/fonts/noto-sans@latest/latin-400-italic.woff2") format("woff2");
}
@font-face {
  font-family: "Noto Sans";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("https://cdn.jsdelivr.net/fontsource/fonts/noto-sans@latest/latin-500-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Noto Sans";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("https://cdn.jsdelivr.net/fontsource/fonts/noto-sans@latest/latin-600-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Noto Sans";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("https://cdn.jsdelivr.net/fontsource/fonts/noto-sans@latest/latin-700-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Noto Sans Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("https://cdn.jsdelivr.net/fontsource/fonts/noto-sans-mono@latest/latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Noto Sans Mono";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("https://cdn.jsdelivr.net/fontsource/fonts/noto-sans-mono@latest/latin-600-normal.woff2") format("woff2");
}

/* ── Jomoq Design Tokens ──────────────────────────────────────────────────
   The brand system lives here; DESIGN.md explains the intent, brand.html
   shows every component. Every color in the app resolves to a token below.
   Themes: dark (default) and light. Legacy token names are kept as a
   compatibility layer — new work should prefer the scale tokens. */
:root,
[data-theme="dark"] {
  color-scheme: dark;

  /* foundational scales (theme-independent) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-pill: 999px;
  --z-nav: 30;
  --z-dropdown: 900;
  --z-overlay: 1200;
  --z-modal: 6000;
  --z-modal-top: 7000; /* dialogs launched from within another modal (e.g. from Project settings) */
  --z-toast: 9999;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-fast: 120ms;
  --dur-base: 180ms;
  --dur-slow: 260ms;

  /* base surfaces — one neutral graphite ramp */
  --bg-app: #0A0A0C;
  --bg-950: #101013;
  --bg-900: #141418;
  --bg-850: #232329;
  --surface: #131316;
  --surface-strong: #060608;
  --surface-soft: #26262C;
  --surface-2: #18181D;
  /* elevated panels (menus, popovers, cards, code blocks) — same temperature */
  --panel: rgba(20, 20, 24, 0.97);
  --panel-translucent: rgba(20, 20, 24, 0.9);
  --panel-soft: rgba(20, 20, 24, 0.6);
  --panel-deep: #0C0C0F;
  /* backdrops */
  --scrim: rgba(0, 0, 0, 0.64);
  --scrim-soft: rgba(0, 0, 0, 0.5);
  /* lines + ink overlays: --on-rgb is the "ink" drawn over surfaces */
  --line: #26262C;
  --line-strong: #3A3A42;
  --line-accent: rgba(255, 255, 255, 0.35);
  --on-rgb: 255, 255, 255;
  /* text */
  --text: #EDEEF2;
  --message-text: #E4E5EA;
  --message-user-bg: #232329;
  --text-muted: #9A9AA6;
  --text-soft: #C2C3CC;
  --text-faint: #8A8A97;
  /* Sentiment colors, theme-aware so they stay readable in both modes. */
  --sent-pos: #3ECF8E;
  --sent-neg: #F27983;
  --sent-warn: #E8B15C;
  --text-accent: #FFFFFF;
  --text-accent-soft: #D6D6DC;
  --on-accent: #0A0A0C;
  --link: #EDEEF2;
  /* accent — monochrome: ink on the opposite pole of the surface */
  --accent: #FFFFFF;
  --accent-rgb: 255, 255, 255;
  --accent-deep: #D9D9DE;
  --accent-strong-text: #FFFFFF;
  --focus-rgb: 255, 255, 255;
  /* status — semantically honest: green success, amber warn, red danger */
  --accent-strong: #33C481;
  --green-rgb: 51, 196, 129;
  --success-text: #4ADE93;
  --teal-text: #7EE8D2;
  --info-rgb: 154, 154, 166;
  --info-text: #C2C3CC;
  --accent-warm: #F0A32E;
  --warn-text: #FFC46B;
  --warn-strong-text: #FF9D8F;
  --danger: #F87168;
  --error-text: #F4574E;
  --error-soft-text: #FF8E87;
  --danger-panel: rgba(42, 16, 16, 0.98);
  --danger-text: #FFD9D6;
  --stop: #D93B32;
  /* diffs */
  --diff-add: #7BD8A0;
  --diff-del: #F5928B;
  --diff-hunk: #C2C3CC;
  /* token meter */
  --meter-track: rgba(255, 255, 255, 0.12);
  --grad-warn: #F0A32E;
  --grad-danger: #F4574E;
  /* misc */
  --scrollbar-thumb: #3A3A42;
  /* Flat design: elevation is drawn with borders + surface steps, never blur.
     The shadow tokens stay defined (as "none") so legacy references melt away. */
  --shadow-1: none;
  --shadow-2: none;
  --shadow-3: none;
  --shadow: none;
  --focus-ring: 0 0 0 2px var(--bg-app), 0 0 0 4px rgb(var(--focus-rgb));
  --grid-dot: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28'%3E%3Ccircle cx='1' cy='1' r='1' fill='%23ffffff' fill-opacity='0.03'/%3E%3C/svg%3E");
  /* One face, every job: Noto Sans carries display, prose, and chrome; the
     tokens stay distinct so surfaces can diverge again later without a hunt.
     Math keeps KaTeX's own faces — that's rendering correctness, not branding. */
  --font-display: "Noto Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-prose: "Noto Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-ui: "Noto Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-main: var(--font-ui);
  --font-math: KaTeX_Math, "Times New Roman", serif;
  --font-mono: "Noto Sans Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  /* A grotesque headline wants weight and tight tracking. */
  --font-display-weight: 700;
  --font-display-tracking: -0.02em;
  /* shared UI aliases (chat, menus, modals) */
  --bg: var(--bg-app);
  --border: var(--line);
  --border-strong: var(--line-strong);
  --surface-1: var(--surface-2);
  --panel-elevated: var(--surface-2);
  --accent-on: var(--on-accent);
  --danger-rgb: 244, 87, 78;
  --font-body: var(--font-main);
  --border-subtle: rgba(var(--on-rgb), 0.08);
  --border-mild: rgba(var(--on-rgb), 0.12);
  --border-faint: rgba(var(--on-rgb), 0.06);
  --hover-fill: rgba(var(--on-rgb), 0.06);
  --hover-fill-strong: rgba(var(--on-rgb), 0.1);
  --text-secondary: var(--text-muted);
  --surface-elevated: var(--surface-2);
  --code-block-bg: var(--bg-950);
  --shadow-soft: rgba(0, 0, 0, 0);
  --scrim-heavy: var(--scrim);
  --accent-fill-subtle: rgba(var(--accent-rgb), 0.14);
  --accent-fill-active: rgba(var(--accent-rgb), 0.22);
  --success-pill-bg: rgba(var(--green-rgb), 0.14);
  --success-pill-text: var(--success-text);
  --warn-pill-bg: rgba(240, 163, 46, 0.16);
  --warn-pill-text: var(--warn-text);
  --danger-hover-bg: rgba(244, 87, 78, 0.14);
  --danger-hover-text: var(--error-soft-text);
  /* buttons — primary (tactile) + secondary (outlined); edit to restyle app-wide */
  --btn-font-family: var(--font-main);
  --btn-font-size: 14px;
  --btn-font-size-sm: 12px;
  --btn-font-weight: 600;
  --btn-letter-spacing: 0.01em;
  --btn-radius: var(--radius-pill);
  --btn-radius-pill: var(--radius-pill);
  --btn-gap: 6px;
  --btn-padding-x: 14px;
  --btn-padding-x-sm: 12px;
  --btn-height: 36px;
  --btn-height-sm-secondary: 30px;
  --btn-height-sm-primary: 28px;
  --btn-primary-lip: 2px;
  --btn-primary-press-y: 1px;
  --btn-transition: var(--dur-fast);
  --btn-disabled-opacity: 0.5;
  --accent-gradient: linear-gradient(to bottom, #FFFFFF, #F0F0F3);
  --btn-primary-color: #0A0A0C;
  --btn-primary-bg: var(--accent-gradient);
  --btn-primary-bg-hover: linear-gradient(to bottom, #ECECEF, #DDDDE2);
  --btn-primary-shadow: none;
  --btn-primary-shadow-active: none;
  --btn-secondary-bg: #1D1D22;
  --btn-secondary-bg-hover: #232329;
  --btn-secondary-bg-active: #18181D;
  --btn-secondary-border: #33333B;
  --btn-secondary-border-hover: #4A4A54;
  --btn-secondary-border-width: 1px;
  --btn-secondary-color: var(--text-soft);
  --btn-secondary-color-hover: var(--text);
  --btn-danger-bg: rgba(244, 87, 78, 0.12);
  --btn-danger-bg-hover: rgba(244, 87, 78, 0.2);
  --btn-danger-border: rgba(244, 87, 78, 0.42);
  --btn-danger-border-hover: rgba(244, 87, 78, 0.56);
  --btn-danger-color: var(--error-soft-text);
  /* custom select */
  --select-bg: #1D1D22;
  --select-bg-hover: #232329;
  --select-border: #33333B;
  --select-border-focus: rgba(var(--accent-rgb), 0.55);
  --select-panel-bg: var(--surface-2);
  --select-panel-shadow: none;
  --select-option-hover: rgba(var(--on-rgb), 0.08);
  --select-option-selected: rgba(var(--on-rgb), 0.14);
  --select-focus-ring: rgba(var(--accent-rgb), 0.35);
  --input-bg: var(--select-bg);
  --input-border: var(--select-border);
  --input-border-focus: var(--select-border-focus);
  /* custom checkbox */
  --checkbox-size: 20px;
  --checkbox-radius: 6px;
  --checkbox-bg: var(--select-bg);
  --checkbox-border: var(--select-border);
  --checkbox-bg-checked: var(--accent-gradient);
  --checkbox-border-checked: var(--accent-deep);
  --checkbox-mark: var(--on-accent); /* mark rides the accent fill in both themes */
  --checkbox-focus-ring: var(--select-focus-ring);
  --checkbox-chip-bg-checked: rgba(var(--on-rgb), 0.12);
  --checkbox-chip-border-checked: rgba(var(--on-rgb), 0.4);
}

[data-theme="light"] {
  color-scheme: light;
  /* base surfaces — paper ramp */
  --bg-app: #F7F7F8;
  --bg-950: #FFFFFF;
  --bg-900: #F2F2F4;
  --bg-850: #E7E7EA;
  --surface: #FFFFFF;
  --surface-strong: #EFEFF2;
  --surface-soft: #E3E3E8;
  --surface-2: #F2F2F5;
  /* elevated panels */
  --panel: rgba(255, 255, 255, 0.98);
  --panel-translucent: rgba(255, 255, 255, 0.94);
  --panel-soft: rgba(255, 255, 255, 0.75);
  --panel-deep: #EFEFF2;
  /* backdrops */
  --scrim: rgba(16, 17, 20, 0.44);
  --scrim-soft: rgba(16, 17, 20, 0.3);
  /* lines + ink overlays */
  --line: #E3E4E9;
  --line-strong: #C9CAD2;
  --line-accent: rgba(23, 24, 28, 0.4);
  --on-rgb: 23, 24, 28;
  /* text */
  --text: #17181C;
  --message-text: #1D1E23;
  --message-user-bg: #ECECEF;
  --text-muted: #5D5E6B;
  --text-soft: #43444F;
  --text-faint: #6B6C78;
  --sent-pos: #0E7A52;
  --sent-neg: #B22A32;
  --sent-warn: #8A5A0B;
  --text-accent: #111114;
  --text-accent-soft: #43444F;
  --on-accent: #fff;
  --link: #17181C;
  /* accent — monochrome ink */
  --accent: #111114;
  --accent-rgb: 17, 17, 20;
  --accent-deep: #2A2A30;
  --accent-strong-text: #111114;
  --focus-rgb: 17, 17, 20;
  /* status */
  --accent-strong: #148A50;
  --green-rgb: 20, 138, 80;
  --success-text: #117A46;
  --teal-text: #0D7A68;
  --info-rgb: 93, 94, 107;
  --info-text: #43444F;
  --accent-warm: #9A6B1F;
  --warn-text: #8A5A12;
  --warn-strong-text: #B3261E;
  --danger: #C5221F;
  --error-text: #C5221F;
  --error-soft-text: #B3261E;
  --danger-panel: #FDE7E9;
  --danger-text: #8C1D18;
  --stop: #B3261E;
  /* diffs */
  --diff-add: #137333;
  --diff-del: #C5221F;
  --diff-hunk: #5D5E6B;
  /* token meter */
  --meter-track: rgba(23, 24, 28, 0.12);
  --grad-warn: #D98324;
  --grad-danger: #D23F31;
  /* misc */
  --scrollbar-thumb: #C4C5CC;
  --shadow-1: none;
  --shadow-2: none;
  --shadow-3: none;
  --shadow: none;
  --focus-ring: 0 0 0 2px var(--bg-app), 0 0 0 4px rgb(var(--focus-rgb));
  --grid-dot: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28'%3E%3Ccircle cx='1' cy='1' r='1' fill='%23000000' fill-opacity='0.05'/%3E%3C/svg%3E");
  /* shared UI aliases */
  --bg: var(--bg-app);
  --border: var(--line);
  --border-strong: var(--line-strong);
  --surface-1: var(--surface-2);
  --panel-elevated: var(--surface-2);
  --accent-on: var(--on-accent);
  --danger-rgb: 197, 34, 31;
  --font-body: var(--font-main);
  --border-subtle: rgba(var(--on-rgb), 0.1);
  --border-mild: rgba(var(--on-rgb), 0.14);
  --border-faint: rgba(var(--on-rgb), 0.08);
  /* Light mode: a few % of black over near-white reads much fainter than the
     same alpha of white over near-black, so bump these above the dark values
     to keep hover/press feedback equally tactile. */
  --hover-fill: rgba(var(--on-rgb), 0.08);
  --hover-fill-strong: rgba(var(--on-rgb), 0.13);
  --text-secondary: var(--text-muted);
  --surface-elevated: var(--surface-2);
  --code-block-bg: var(--bg-900);
  --shadow-soft: rgba(16, 17, 20, 0);
  --scrim-heavy: var(--scrim);
  --accent-fill-subtle: rgba(var(--accent-rgb), 0.1);
  --accent-fill-active: rgba(var(--accent-rgb), 0.16);
  --success-pill-bg: rgba(var(--green-rgb), 0.12);
  --success-pill-text: var(--success-text);
  --warn-pill-bg: rgba(154, 107, 31, 0.14);
  --warn-pill-text: var(--warn-text);
  --danger-hover-bg: rgba(197, 34, 31, 0.1);
  --danger-hover-text: var(--error-text);
  /* buttons */
  --accent-gradient: linear-gradient(to bottom, #1D1D22, #111114);
  --btn-primary-bg: var(--accent-gradient);
  --btn-primary-bg-hover: linear-gradient(to bottom, #33333B, #24242B);
  --btn-primary-color: #fff;
  --btn-primary-shadow: none;
  --btn-primary-shadow-active: none;
  --btn-secondary-bg: #FFFFFF;
  --btn-secondary-bg-hover: #F4F4F6;
  --btn-secondary-bg-active: #ECECEF;
  --btn-secondary-border: #D8D9DF;
  --btn-secondary-border-hover: #B9BAC4;
  --btn-danger-bg: rgba(197, 34, 31, 0.08);
  --btn-danger-bg-hover: rgba(197, 34, 31, 0.14);
  --btn-danger-border: rgba(197, 34, 31, 0.35);
  --btn-danger-border-hover: rgba(197, 34, 31, 0.5);
  --btn-danger-color: var(--error-text);
  /* custom select */
  --select-bg: #FFFFFF;
  --select-bg-hover: #F6F6F8;
  --select-border: #D8D9DF;
  --select-border-focus: rgba(var(--accent-rgb), 0.5);
  --select-panel-bg: #FFFFFF;
  --select-panel-shadow: none;
  --select-option-hover: rgba(var(--on-rgb), 0.09);
  --select-option-selected: rgba(var(--on-rgb), 0.16);
  --select-focus-ring: rgba(var(--accent-rgb), 0.3);
  --input-bg: var(--select-bg);
  --input-border: var(--select-border);
  --input-border-focus: var(--select-border-focus);
  /* custom checkbox */
  --checkbox-bg-checked: var(--accent-gradient);
  --checkbox-border-checked: var(--accent-deep);
  --checkbox-chip-bg-checked: rgba(var(--on-rgb), 0.08);
  --checkbox-chip-border-checked: rgba(var(--on-rgb), 0.35);
}

* {
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

/* Form controls do NOT inherit fonts by default — without this, any button,
   input, select, or textarea missing an explicit font-family silently falls
   back to the UA's Arial/Helvetica and breaks the one-face system. */
button,
input,
select,
textarea,
optgroup {
  font-family: inherit;
  letter-spacing: inherit;
}

/* Safari fallback (no scrollbar-color support) — same quiet thumb. */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: var(--radius-pill);
  border: 3px solid transparent;
  background-clip: padding-box;
}

/* Keycaps — flat chip with a 2px base, same recipe as brand.html's specimen. */
kbd {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  color: var(--text-soft);
}

/* ── Motion layer ─────────────────────────────────────────────────────────
   Flat monochrome surfaces lean on motion for feedback: quiet, fast, and
   consistent. Two entrance curves (menus pop, modals rise), a press scale on
   every button, and nothing at all for reduced-motion users. */
@keyframes ui-pop {
  from {
    opacity: 0;
    transform: translateY(4px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes ui-rise {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes ui-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Dropdowns + popovers pop in place. */
.chat-model-menu:not([hidden]),
.chat-composer-dropup:not([hidden]),
.custom-select-panel:not([hidden]),
.chat-slash-menu:not([hidden]) {
  animation: ui-pop var(--dur-base) var(--ease-out);
}

/* Modal cards rise; their backdrops fade. */
.settings-modal-card,
.jf-modal-card,
.study-review-modal,
.study-cal-modal,
.quiz-modal {
  animation: ui-rise var(--dur-slow) var(--ease-out);
}

.settings-modal-backdrop,
.jf-modal-overlay,
.study-review-overlay,
.study-cal-overlay,
.quiz-overlay {
  animation: ui-fade var(--dur-base) ease;
}

/* Buttons acknowledge the press. */
.btn:active:not(:disabled),
.settings-action-button:active:not(:disabled),
.jf-toolbar-btn:active,
.chat-composer-add-btn:active,
.memory-item-btn:active,
.study-cal-navbtn:active {
  transform: scale(0.97);
}

/* Message rows ease in as they land. */
.message-row {
  animation: ui-pop var(--dur-base) var(--ease-out);
}

@media (prefers-reduced-motion: reduce) {
  .chat-model-menu:not([hidden]),
  .chat-composer-dropup:not([hidden]),
  .custom-select-panel:not([hidden]),
  .chat-slash-menu:not([hidden]),
  .settings-modal-card,
  .jf-modal-card,
  .study-review-modal,
  .study-cal-modal,
  .quiz-modal,
  .settings-modal-backdrop,
  .jf-modal-overlay,
  .study-review-overlay,
  .study-cal-overlay,
  .quiz-overlay,
  .message-row {
    animation: none;
  }
  .btn:active:not(:disabled),
  .settings-action-button:active:not(:disabled),
  .jf-toolbar-btn:active,
  .chat-composer-add-btn:active,
  .memory-item-btn:active,
  .study-cal-navbtn:active {
    transform: none;
  }
}

html,
body {
  height: 100%;
  width: 100%;
  margin: 0;
  color: var(--text);
  font-family: var(--font-main);
  background: var(--bg-app);
  overflow: hidden;
  -moz-osx-font-smoothing: grayscale;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 {
  text-wrap: balance;
}

/* Iconic monochrome selection: full ink inversion, like print. */
::selection {
  background: var(--text);
  color: var(--bg-app);
}

/* Numbers that update in place (counters, meters, timers) must not wiggle. */
.chat-usage-pill,
.token-meter,
.upg-usage-line,
.study-cal-daynum,
.study-review-progress,
.chat-activity-title,
.jf-brief-date,
.message-more-stat,
.composer-stats,
.key-call-count {
  font-variant-numeric: tabular-nums;
}

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

#container {
  position: relative;
  z-index: 1;
  height: 100%;
}

.app-shell {
  display: flex;
  height: 100%;
  gap: 16px;
  padding: 16px;
}

.activity-strip {
  width: 88px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px 10px;
  backdrop-filter: blur(10px);
}

.brand-chip {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: var(--accent);
  border: none;
  color: var(--on-accent);
  font-family: var(--font-display);
  letter-spacing: 0.04em;
  font-weight: var(--font-display-weight);
  display: grid;
  place-items: center;
}

/* Brand wordmark (inline SVG, inherits currentColor) */
.brand-logo {
  height: 22px;
  width: auto;
  display: block;
  color: var(--text);
  flex: none;
}

.brand-logo-accent {
  color: var(--accent);
}

/* Accessibility utilities */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10000;
  padding: 10px 16px;
  border-radius: var(--btn-radius);
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-64px);
  opacity: 0;
  pointer-events: none;
}

.skip-link:focus-visible {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* Signature technical eyebrow label */
.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.rail-button {
  width: 100%;
  border: 1px solid transparent;
  border-radius: var(--btn-radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 6px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-main);
  transition:
    color var(--dur-base) var(--ease-out),
    border-color var(--dur-base) var(--ease-out),
    background-color var(--dur-base) var(--ease-out);
}

.rail-button .material-symbols-rounded {
  font-size: 20px;
}

.rail-button:hover {
  color: var(--text);
  border-color: rgba(var(--accent-rgb), 0.35);
  background: rgba(var(--accent-rgb), 0.08);
}

.rail-button.active {
  color: var(--on-accent);
  border-color: rgba(var(--accent-rgb), 0.5);
  background: var(--accent-deep);
}

.rail-divider {
  width: 70%;
  border-top: 1px solid var(--line);
  margin: 4px 0;
}

.rail-hint {
  font-size: 11px;
  line-height: 1.35;
  color: var(--text-muted);
  text-align: center;
  max-width: 64px;
}

.workspace {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.top-vv,
.navbar,
.bottom-vv {
  border-radius: var(--btn-radius-pill);
  background: transparent;
  backdrop-filter: blur(10px);
}

.top-vv {
  padding: 14px 0px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.title-block {
  min-width: 0;
}

.eyebrow {
  margin: 0;
}

#program-title {
  margin: 4px 0 0;
  font-family: var(--font-ui);
  font-size: clamp(1.1rem, 1.55vw, 1.45rem);
  line-height: 1.2;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 56vw;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.keyboard-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 5px 10px;
}

hr {
  height: 1px;
  border: none;
  background: var(--line);
  margin: 16px 0;
}

/* ── Buttons: primary (tactile) + secondary (outlined) ───────────────────
   Use .btn.btn-primary or .btn.btn-secondary. Legacy classes (.settings-action-button,
   .plan-modal-approve-btn, .chat-nav-chip, etc.) map to the same tokens. */
.btn,
button.btn,
a.btn,
.settings-action-button,
.storage-modal-button,
.chip-button,
.plan-modal-secondary-btn,
.plan-modal-approve-btn,
.chat-nav-chip,
.chat-starter-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--btn-gap);
  padding: 0 var(--btn-padding-x);
  height: var(--btn-height);
  min-height: var(--btn-height);
  border-radius: var(--btn-radius);
  border: none;
  font-family: var(--btn-font-family);
  font-size: var(--btn-font-size);
  font-weight: var(--btn-font-weight);
  letter-spacing: var(--btn-letter-spacing);
  line-height: 1;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  text-decoration: none;
  box-sizing: border-box;
  appearance: none;
  -webkit-appearance: none;
  transition:
    transform var(--btn-transition) var(--ease-out),
    box-shadow var(--btn-transition) var(--ease-out),
    background var(--btn-transition) var(--ease-out),
    border-color var(--btn-transition) var(--ease-out),
    color var(--btn-transition) var(--ease-out);
}

.btn:focus-visible,
.settings-action-button:focus-visible,
.storage-modal-button:focus-visible,
.chip-button:focus-visible,
.plan-modal-secondary-btn:focus-visible,
.plan-modal-approve-btn:focus-visible,
.chat-nav-chip:focus-visible,
.chat-starter-chip:focus-visible {
  outline: 2px solid rgba(var(--focus-rgb), 0.85);
  outline-offset: 2px;
}

.btn:disabled,
.btn[aria-disabled="true"],
.settings-action-button:disabled,
.storage-modal-button:disabled,
.plan-modal-approve-btn:disabled,
.plan-modal-secondary-btn:disabled {
  opacity: var(--btn-disabled-opacity);
  cursor: not-allowed;
  pointer-events: none;
}

.btn-sm,
.chat-nav-chip {
  --btn-height: var(--btn-height-sm-secondary);
  --btn-font-size: var(--btn-font-size-sm);
  --btn-padding-x: var(--btn-padding-x-sm);
}

.btn-pill,
.chat-nav-chip,
.chat-starter-chip,
.plan-modal-secondary-btn,
.plan-modal-approve-btn {
  border-radius: var(--btn-radius-pill);
}

.btn-primary,
.btn.btn-primary,
.settings-action-button.primary,
.storage-modal-button.primary,
.plan-modal-approve-btn,
.chat-nav-chip.btn-primary,
.chat-nav-chip.primary {
  height: calc(var(--btn-height) - var(--btn-primary-lip));
  min-height: calc(var(--btn-height) - var(--btn-primary-lip));
  color: var(--btn-primary-color);
  background: var(--btn-primary-bg);
  transform: translateY(0);
}

.btn-sm.btn-primary,
.chat-nav-chip.btn-primary,
.chat-nav-chip.primary {
  height: var(--btn-height-sm-primary);
  min-height: var(--btn-height-sm-primary);
}

.btn-primary:hover:not(:disabled),
.settings-action-button.primary:hover,
.storage-modal-button.primary:hover,
.plan-modal-approve-btn:hover:not(:disabled),
.chat-nav-chip.btn-primary:hover,
.chat-nav-chip.primary:hover {
  background: var(--btn-primary-bg-hover);
  color: var(--btn-primary-color);
}

.btn-primary:active:not(:disabled),
.settings-action-button.primary:active,
.storage-modal-button.primary:active,
.plan-modal-approve-btn:active:not(:disabled),
.chat-nav-chip.btn-primary:active,
.chat-nav-chip.primary:active {
  transform: translateY(var(--btn-primary-press-y));
}

.btn-secondary,
.btn-subtle,
.btn-ghost,
.btn.btn-secondary,
.btn.btn-subtle,
.btn.btn-ghost,
.settings-action-button:not(.primary):not(.danger),
.storage-modal-button:not(.primary),
.chip-button,
.plan-modal-secondary-btn,
.chat-nav-chip.btn-secondary,
.chat-nav-chip:not(.btn-primary):not(.primary),
.chat-starter-chip {
  height: var(--btn-height);
  min-height: var(--btn-height);
  border: var(--btn-secondary-border-width) solid var(--btn-secondary-border);
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-color);
  box-shadow: none;
  transform: none;
}

.btn-secondary:hover:not(:disabled),
.btn-subtle:hover:not(:disabled),
.btn-ghost:hover:not(:disabled),
.settings-action-button:not(.primary):not(.danger):hover,
.storage-modal-button:not(.primary):hover,
.chip-button:hover,
.plan-modal-secondary-btn:hover,
.chat-nav-chip.btn-secondary:hover,
.chat-nav-chip:not(.btn-primary):not(.primary):hover,
.chat-starter-chip:hover {
  background: var(--btn-secondary-bg-hover);
  border-color: var(--btn-secondary-border-hover);
  color: var(--btn-secondary-color-hover);
}

.btn-secondary:active:not(:disabled),
.btn-subtle:active:not(:disabled),
.btn-ghost:active:not(:disabled),
.settings-action-button:not(.primary):not(.danger):active,
.storage-modal-button:not(.primary):active,
.chip-button:active,
.plan-modal-secondary-btn:active,
.chat-nav-chip.btn-secondary:active,
.chat-nav-chip:not(.btn-primary):not(.primary):active,
.chat-starter-chip:active {
  background: var(--btn-secondary-bg-active);
}

.btn-danger,
.settings-action-button.danger {
  border: var(--btn-secondary-border-width) solid var(--btn-danger-border);
  background: var(--btn-danger-bg);
  color: var(--btn-danger-color);
  box-shadow: none;
  transform: none;
}

.btn-danger:hover:not(:disabled),
.settings-action-button.danger:hover {
  background: var(--btn-danger-bg-hover);
  border-color: var(--btn-danger-border-hover);
  color: var(--btn-danger-color);
}

.storage-modal-button,
.plan-modal-secondary-btn,
.plan-modal-approve-btn {
  --btn-height: var(--btn-height-sm-secondary);
  --btn-font-size: var(--btn-font-size-sm);
  --btn-padding-x: var(--btn-padding-x-sm);
}

.chat-starter-chip {
  --btn-height: 34px;
  --btn-font-size: 13px;
  --btn-padding-x: 14px;
  text-align: left;
  max-width: 100%;
}

/* ── Custom select (animated, accessible) ─────────────────────────────── */
.custom-select {
  position: relative;
  width: 100%;
}

.custom-select__native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  pointer-events: none;
}

.custom-select__trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 38px;
  padding: 8px 11px;
  border-radius: 10px;
  border: 1.5px solid var(--select-border);
  background: var(--select-bg);
  color: var(--text);
  font: inherit;
  font-size: inherit;
  text-align: left;
  cursor: pointer;
  transition:
    border-color var(--dur-fast) var(--ease-out),
    background var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-base) var(--ease-out);
}

.custom-select__trigger:hover {
  background: var(--select-bg-hover);
}

.custom-select.is-open .custom-select__trigger,
.custom-select__trigger:focus-visible {
  border-color: var(--select-border-focus);
  box-shadow: 0 0 0 3px var(--select-focus-ring);
  outline: none;
}

.custom-select__value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-select__chevron {
  flex-shrink: 0;
  font-size: 20px;
  color: var(--text-muted);
  transition: transform var(--dur-base) cubic-bezier(0.4, 0, 0.2, 1);
}

.custom-select.is-open .custom-select__chevron {
  transform: rotate(180deg);
  color: var(--text-accent-soft);
}

.custom-select__list {
  position: absolute;
  z-index: 12000;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 5px;
  list-style: none;
  border-radius: 12px;
  border: 1.5px solid var(--select-border);
  background: var(--select-panel-bg);
  max-height: 240px;
  overflow-y: auto;
  opacity: 0;
  transform: translateY(-8px) scale(0.98);
  transform-origin: top center;
  pointer-events: none;
  transition:
    opacity var(--dur-base) var(--ease-out),
    transform var(--dur-base) cubic-bezier(0.4, 0, 0.2, 1);
}

.custom-select.is-open .custom-select__list {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.custom-select__option {
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-soft);
  font-size: inherit;
  line-height: 1.35;
  transition:
    background var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}

.custom-select__option:hover,
.custom-select__option.is-focused {
  background: var(--select-option-hover);
  color: var(--text);
}

.custom-select__option.is-selected {
  background: var(--select-option-selected);
  color: var(--text-accent);
  font-weight: 600;
}

/* ── Custom checkbox (animated checkmark) ─────────────────────────────── */
.custom-check input[type="checkbox"],
.chat-customize-check input[type="checkbox"],
.project-skill-chip input[type="checkbox"],
.settings-checkbox input[type="checkbox"],
.key-entry-toggle input[type="checkbox"],
.settings-page input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  flex-shrink: 0;
  width: var(--checkbox-size);
  height: var(--checkbox-size);
  margin: 0;
  border: 1.5px solid var(--checkbox-border);
  border-radius: var(--checkbox-radius);
  background: var(--checkbox-bg);
  cursor: pointer;
  display: grid;
  place-content: center;
  transition:
    background var(--dur-base) var(--ease-out),
    border-color var(--dur-base) var(--ease-out),
    box-shadow var(--dur-base) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}

.custom-check input[type="checkbox"]::after,
.chat-customize-check input[type="checkbox"]::after,
.project-skill-chip input[type="checkbox"]::after,
.settings-checkbox input[type="checkbox"]::after,
.key-entry-toggle input[type="checkbox"]::after,
.settings-page input[type="checkbox"]::after {
  content: "";
  width: 5px;
  height: 9px;
  border: solid var(--checkbox-mark);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0.4);
  opacity: 0;
  margin-top: -2px;
  transition:
    transform var(--dur-base) cubic-bezier(0.34, 1.4, 0.64, 1),
    opacity var(--dur-fast) var(--ease-out);
}

.custom-check input[type="checkbox"]:checked,
.chat-customize-check input[type="checkbox"]:checked,
.project-skill-chip input[type="checkbox"]:checked,
.settings-checkbox input[type="checkbox"]:checked,
.key-entry-toggle input[type="checkbox"]:checked,
.settings-page input[type="checkbox"]:checked {
  background: var(--checkbox-bg-checked);
  border-color: var(--checkbox-border-checked);
}

.custom-check input[type="checkbox"]:checked::after,
.chat-customize-check input[type="checkbox"]:checked::after,
.project-skill-chip input[type="checkbox"]:checked::after,
.settings-checkbox input[type="checkbox"]:checked::after,
.key-entry-toggle input[type="checkbox"]:checked::after,
.settings-page input[type="checkbox"]:checked::after {
  opacity: 1;
  transform: rotate(45deg) scale(1);
}

.custom-check input[type="checkbox"]:active,
.chat-customize-check input[type="checkbox"]:active,
.project-skill-chip input[type="checkbox"]:active,
.settings-checkbox input[type="checkbox"]:active,
.key-entry-toggle input[type="checkbox"]:active,
.settings-page input[type="checkbox"]:active {
  transform: scale(0.94);
}

.custom-check input[type="checkbox"]:focus-visible,
.chat-customize-check input[type="checkbox"]:focus-visible,
.project-skill-chip input[type="checkbox"]:focus-visible,
.settings-checkbox input[type="checkbox"]:focus-visible,
.key-entry-toggle input[type="checkbox"]:focus-visible,
.settings-page input[type="checkbox"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--checkbox-focus-ring);
}

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

.sync-pill {
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(36vw, 260px);
  flex-shrink: 1;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--text-soft);
  transition:
    color var(--dur-base) var(--ease-out),
    border-color var(--dur-base) var(--ease-out),
    background-color var(--dur-base) var(--ease-out);
}

.sync-pill:empty {
  display: none;
}

.sync-pill[data-tone="ready"] {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
  background: color-mix(in srgb, var(--accent) 12%, var(--surface-strong));
}

.sync-pill[data-tone="running"] {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  background: color-mix(in srgb, var(--accent) 18%, var(--surface-strong));
}

.sync-pill[data-tone="warning"] {
  color: var(--warn-strong-text);
  border-color: color-mix(in srgb, var(--error-text) 45%, var(--line));
  background: color-mix(in srgb, var(--error-text) 12%, var(--surface-strong));
}

.builder-navbar .navbar-leading {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-shrink: 0;
}

.builder-navbar .navbar-brand {
  font-family: var(--font-main);
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.builder-navbar .navbar-back-link {
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-soft);
  text-decoration: none;
  white-space: nowrap;
  opacity: 0.85;
  transition:
    color var(--dur-base) var(--ease-out),
    opacity var(--dur-base) var(--ease-out);
}

.builder-navbar .navbar-back-link:hover {
  color: var(--text);
  opacity: 1;
  text-decoration: none;
}

button.navbar-back-link {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font: inherit;
}

.builder-navbar .nav-links {
  margin-left: auto;
}

.builder-navbar .nav-drawer-divider {
  display: none;
}

/* Embedded in chat drawer — hide back link to chat.html; use embed close instead */
html[data-embed="1"] #builder-chat-link {
  display: none !important;
}

html[data-embed="1"] #builder-embed-close {
  display: inline-flex !important;
}

.nav-link {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-soft);
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  border-radius: var(--radius-pill);
  min-height: 36px;
  padding: 8px 12px;
  margin: 0;
  cursor: pointer;
  transition:
    border-color var(--dur-base) var(--ease-out),
    background-color var(--dur-base) var(--ease-out),
    color var(--dur-base) var(--ease-out);
}

a.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
}

.nav-link:hover {
  color: var(--text);
  border-color: rgba(var(--on-rgb), 0.08);
  background: rgba(var(--on-rgb), 0.05);
  text-decoration: none;
}

.nav-link.active {
  color: var(--on-accent);
  border-color: rgba(var(--accent-rgb), 0.45);
  background: var(--accent-deep);
}

[data-theme="dark"] .nav-link.active {
  border-color: rgba(var(--accent-rgb), 0.55);
}

[data-theme="light"] .nav-link.active {
  border-color: rgba(var(--accent-rgb), 0.55);
}

/* Nav links container — inline on desktop, right drawer on mobile. */
.nav-links {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Chat is always shown in the left panel on desktop, so its tab is mobile-only. */
.nav-link-chat {
  display: none;
}

/* Hamburger — hidden on desktop, shown on mobile. */
.nav-menu-btn {
  display: none;
  margin-left: auto;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--text);
  border-radius: var(--btn-radius);
  padding: 8px;
  cursor: pointer;
}

.nav-menu-btn .material-symbols-rounded {
  font-size: 24px;
}

/* Dark overlay behind the mobile drawer. */
.nav-overlay {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: var(--z-dropdown);
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-out);
}

.nav-overlay:not(.open) {
  pointer-events: none;
}

.nav-overlay.open {
  opacity: 1;
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Nav / icon links styled as buttons — no underline on hover */
a:is(
  .chat-nav-icon-btn,
  .chat-sidebar-link-btn,
  .nav-link,
  .navbar-back-link,
  .navbar-brand,
  .message-open-project-btn,
  .settings-sidebar-back,
  .settings-sidebar-link,
  .settings-mobile-close
):hover,
a:is(
  .chat-nav-icon-btn,
  .chat-sidebar-link-btn,
  .nav-link,
  .navbar-back-link,
  .navbar-brand,
  .message-open-project-btn,
  .settings-sidebar-back,
  .settings-sidebar-link,
  .settings-mobile-close
):focus-visible {
  text-decoration: none;
}

.status-pill {
  margin-left: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 6px 11px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-soft);
  white-space: nowrap;
}

.status-pill[data-tone="ready"] {
  color: var(--accent);
  border-color: rgba(var(--on-rgb), 0.27);
}

.status-pill[data-tone="running"] {
  color: var(--accent-warm);
  border-color: rgba(var(--accent-rgb), 0.35);
}

.status-pill[data-tone="warning"] {
  color: var(--accent-warm);
  border-color: rgba(var(--accent-rgb), 0.4);
}

.editor-iframe {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 8px;
  overflow: hidden;
}

.panel {
  min-width: 280px;
  min-height: 0;
  flex: 0 0 32%;
  display: flex;
}

#right-stage {
  flex: 1 1 68%;
  min-width: 320px;
  min-height: 0;
  display: flex;
  position: relative;
}

#right-stage>.stage-view {
  width: 100%;
  flex: 1;
}

#iframebox {
  display: flex;
  flex-direction: column;
}

.panel-surface {
  width: 100%;
  border: none;
  border-radius: 0px;
  background: var(--surface-strong);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: panelIn var(--dur-slow) var(--ease-out);
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.panel-head {
  min-height: 48px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-translucent);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.01em;
  color: var(--text-soft);
}

.panel-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.panel-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-hint-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface-soft);
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 11px;
  font-weight: 600;
  padding: 5px 11px;
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}

.panel-hint-btn .material-symbols-rounded {
  font-size: 15px;
  vertical-align: middle;
  margin: -2px 2px 0 0;
}

.panel-hint-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

.panel-hint-btn.active {
  color: var(--on-accent);
  background: var(--accent-deep);
  border-color: var(--accent-deep);
}

/* ── Dev mode: code editor + live preview side by side, no chat/navbar ── */
.dev-mode .navbar {
  display: none !important;
}

.dev-mode #left-panel {
  display: none !important;
}

.dev-mode #resizer {
  display: none !important;
}

.dev-mode #right-stage {
  flex: 1 1 100% !important;
  gap: 8px;
}

/* Show BOTH the preview and code panels at once, each taking half */
.dev-mode #right-stage>#iframebox,
.dev-mode #right-stage>#code-content {
  display: flex !important;
  flex: 1 1 50%;
  width: 50%;
  min-width: 0;
}

/* Switch sides: reverse the order of the two panels */
.dev-mode #right-stage.dev-swapped {
  flex-direction: row-reverse;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
}

.dot-green {
  background: var(--accent-strong);
}

.dot-amber {
  background: var(--accent-warm);
}

#code-content,
#chat-content,
#storage-content {
  width: 100%;
}

#code-content {
  display: none;
  flex-direction: column;
  min-height: 0;
}

.code-workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.file-tree {
  width: 168px;
  min-width: 128px;
  max-width: 220px;
  flex-shrink: 0;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--panel-elevated, var(--panel));
  padding: 6px 0;
  font-family: var(--font-mono);
  font-size: 12px;
}

.file-tree-item,
.file-tree-folder {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  text-align: left;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition:
    background-color var(--dur-base) var(--ease-out),
    color var(--dur-base) var(--ease-out);
}

.file-tree-item:hover,
.file-tree-folder:hover {
  background: rgba(var(--accent-rgb), 0.08);
  color: var(--text);
}

.file-tree-item:focus-visible,
.file-tree-folder:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.file-tree-item.active {
  background: rgba(var(--accent-rgb), 0.16);
  color: var(--accent);
  font-weight: 600;
}

.file-tree-folder-icon {
  font-size: 16px !important;
  opacity: 0.85;
}

.vscode-context-menu {
  position: fixed;
  z-index: 12000;
  min-width: 180px;
  padding: 4px 0;
  border-radius: 6px;
  border: 1px solid var(--border-mild);
  background: var(--surface-elevated);
}

.vscode-context-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition:
    background-color var(--dur-base) var(--ease-out),
    color var(--dur-base) var(--ease-out);
}

.vscode-context-menu-item:hover:not(:disabled) {
  background: var(--accent-fill-active);
}

.vscode-context-menu-item:disabled {
  opacity: 0.45;
  cursor: default;
}

.vscode-context-menu-item.danger:hover:not(:disabled) {
  background: var(--danger-hover-bg);
  color: var(--danger-hover-text);
}

.vscode-context-menu-sep {
  height: 1px;
  margin: 4px 0;
  background: var(--border-faint);
}

.workspace-dialog-card {
  max-width: 420px;
}

.workspace-dialog-message {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.workspace-dialog-hint {
  margin-top: 8px;
}

.workspace-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.cloud-sync-banner {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  border: 1px solid var(--border-mild);
}

.cloud-sync-banner.ok {
  background: var(--success-pill-bg);
  color: var(--success-pill-text);
}

.cloud-sync-banner.warn {
  background: var(--warn-pill-bg);
  color: var(--warn-pill-text);
}

.code-editor-pane,
#editor {
  flex: 1;
  min-width: 0;
  min-height: 320px;
  font-family: var(--font-mono);
}

.editor-agent-overlay {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(var(--accent-rgb), 0.12);
  border-bottom: 1px solid rgba(var(--accent-rgb), 0.3);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  font-family: var(--font-main);
  letter-spacing: 0.01em;
}

.editor-agent-overlay.active {
  display: flex;
}

#editor,
#diff-editor {
  position: relative;
  overflow: hidden;
}

.monaco-editor,
.monaco-editor .margin,
.monaco-editor-background,
.monaco-editor .monaco-editor-background {
  background-color: var(--panel) !important;
}

#diff-editor {
  flex: 1;
  min-height: 360px;
  height: 60vh;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.resizer {
  width: 10px;
  margin: 0 -3px;
  border-radius: var(--radius-pill);
  background: var(--bg-app);
  border: 1px solid rgba(var(--on-rgb), 0.0);
  cursor: ew-resize;
  position: relative;
  flex-shrink: 0;
  touch-action: none;
  transition:
    border-color var(--dur-fast) var(--ease-out),
    background var(--dur-fast) var(--ease-out);
}

/* Wider invisible hit area for the drag handle */
.resizer::after {
  content: "";
  position: absolute;
  inset: 0 -6px;
}

.resizer::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 1px;
  height: 30px;
  border-radius: var(--radius-pill);
  background: rgba(var(--on-rgb), 0.4);
  transition: background-color var(--dur-base) var(--ease-out);
}

.resizer:hover {
  border: 1px solid rgba(var(--on-rgb), 0.2);
}

.resizer:active {

  border: 1px solid rgba(var(--on-rgb), 0.3);
}

.resizer:hover::before {
  background: rgba(var(--on-rgb), 0.7);
}

.resizer:active::before {

  background: rgba(var(--on-rgb), 0.9);
}

.preview-surface {
  background: var(--surface-strong);
}

#iframe {
  flex: 1;
  width: 100%;
  border: none;
  /* User content renders on white regardless of app theme. */
  background: #fefefe;
}

#chat-content {
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

.nav-icon {
  font-size: 16px !important;
  vertical-align: -3px;
  margin-right: 6px;
}

.settings-modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  animation: settingsModalIn var(--dur-base) var(--ease-out);
}

.settings-modal[hidden] {
  display: none;
}

.settings-modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  backdrop-filter: blur(6px);
}

#storage-content.settings-modal-card,
.settings-modal-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 920px;
  height: 100%;
  max-height: calc(100vh - 64px);
  display: flex !important;
  flex-direction: column;
  border: none;
  border-radius: 18px;
  background: var(--surface-strong);
  overflow: hidden;
}

.settings-modal-head {
  flex: 0 0 auto;
}

.settings-modal-head .panel-title-wrap {
  font-family: var(--font-main);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
}

.settings-modal-card .panel-head {
  border-bottom: none;
}

.settings-modal-head-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.settings-modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border: none;
  border-radius: var(--btn-radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}

.settings-modal-close:hover {
  background: var(--hover-fill);
  color: var(--text);
}

.settings-modal-close:active {
  background: var(--hover-fill-strong);
}

.settings-modal-close:focus-visible {
  outline: 2px solid rgba(var(--focus-rgb), 0.85);
  outline-offset: 2px;
}

.settings-modal-close .material-symbols-rounded {
  font-size: 18px !important;
}

.settings-modal-card .settings-panel {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
}

@keyframes settingsModalIn {
  from {
    opacity: 0;
    transform: scale(0.98);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (max-width: 720px) {
  .settings-modal {
    padding: 0;
  }

  .settings-modal-card {
    max-width: 100%;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }
}

.provider-tag {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 10px;
  font-family: var(--font-mono);
  border-radius: var(--radius-pill);
  background: rgba(var(--accent-rgb), 0.16);
  color: var(--text-accent);
  border: 1px solid rgba(var(--accent-rgb), 0.32);
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#storage-content {
  display: none;
  flex-direction: column;
  min-height: 0;
}

.chat-panel-head {
  padding: 8px 10px;
}

.chat-navbar {
  display: flex;
  gap: 6px;
}

.chat-nav-link {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--btn-radius);
  padding: 7px 10px;
  cursor: pointer;
  font-family: var(--font-main);
  transition:
    border-color var(--dur-base) var(--ease-out),
    color var(--dur-base) var(--ease-out),
    background-color var(--dur-base) var(--ease-out);
}

.chat-nav-link:hover {
  color: var(--text);
  border-color: rgba(var(--accent-rgb), 0.28);
  background: rgba(var(--accent-rgb), 0.1);
}

.chat-nav-link.active {
  color: var(--on-accent);
  border-color: rgba(var(--accent-rgb), 0.45);
  background: var(--accent);
}

#chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--panel-soft);
}

.empty-state {
  border: none;
  border-radius: 12px;
  padding: 16px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  background: transparent;
}

.message-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
  animation: messageIn var(--dur-base) var(--ease-out);
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-row.user {
  align-items: flex-end;
}

.message-row.assistant {
  align-items: flex-start;
}

.message-row.assistant .chat-activity-panel {
  width: 100%;
  max-width: 100%;
}

.message-row.assistant .chat-tool-step-row.live-step {
  width: 100%;
  flex-wrap: wrap;
}

.message {
  max-width: 100%;
  width: 100%;
  /* Reading surface — the serif lives here, not in the chrome around it. */
  font-family: var(--font-prose);
  border-radius: 14px;
  padding: 12px 14px;
  line-height: 1.48;
  margin-top: 32px;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--message-text);
  font-size: 13px;
}

.message.user {
  color: var(--message-text);
  padding: 8px 14px;
  background: var(--message-user-bg);
  border-radius: 10px;
  white-space: pre-wrap;
  border-color: rgba(var(--on-rgb), 0.2);
}

.message.assistant {
  background: transparent;
  border: none;
  color: var(--message-text);
  line-height: 1.65;
}

.message-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 2px;
  min-height: 22px;
}

.message-row.user .message-footer {
  justify-content: flex-end;
}

.message-copy-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--btn-radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition:
    color var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out);
}

.message-copy-button .material-symbols-rounded {
  font-size: 16px;
}

.message-copy-button:hover {
  color: var(--text);
  background: var(--surface);
  border-color: var(--line);
}

.message-copy-button.copied {
  color: var(--teal-text);
  border-color: rgba(var(--green-rgb), 0.35);
  background: rgba(var(--green-rgb), 0.1);
}

.message-redo-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--btn-radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition:
    color var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out);
}

.message-redo-button .material-symbols-rounded {
  font-size: 16px;
}

.message-redo-button:hover {
  color: var(--text);
  background: var(--surface);
  border-color: var(--line);
}

.message-redo-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.message-meta {
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 2px;
  white-space: nowrap;
  transition: opacity var(--dur-fast) var(--ease-out);
}

@media (hover: hover) {
  #chat-messages .message-row .message-meta,
  #chat-messages .message-row .token-meter {
    opacity: 0;
    pointer-events: none;
  }

  #chat-messages .message-row:hover .message-meta,
  #chat-messages .message-row:hover .token-meter,
  #chat-messages .message-row:focus-within .message-meta,
  #chat-messages .message-row:focus-within .token-meter {
    opacity: 1;
    pointer-events: auto;
  }
}

.message-edit-row {
  width: min(760px, 92%);
  padding: 0 2px;
}

.message-edit-button {

  border: 1px solid rgba(var(--green-rgb), 0.42);
  border-radius: var(--btn-radius);
  background: rgba(var(--green-rgb), 0.12);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  text-align: left;
  padding: 7px 10px;
  cursor: pointer;
  transition:
    border-color var(--dur-base) var(--ease-out),
    background-color var(--dur-base) var(--ease-out);
}

.message-edit-button:hover {
  border-color: rgba(var(--green-rgb), 0.58);
  background: rgba(var(--green-rgb), 0.18);
}

.message-revert-row {
  width: 100%;
  padding: 0 2px;
}

.message-revert-button {

  border: 1px solid var(--surface-strong);
  border-radius: var(--btn-radius);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-main);
  font-size: 11px;
  text-align: left;
  padding: 7px 10px;
  cursor: pointer;
  transition:
    border-color var(--dur-base) var(--ease-out),
    background-color var(--dur-base) var(--ease-out),
    opacity var(--dur-base) var(--ease-out);
  opacity: 0.8;
  width: 100%;
}

.message-revert-button:hover {
  opacity: 1.0;
}

.token-meter {
  max-width: 220px;
  border: none;
  border-radius: 10px;
  background: transparent;
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.token-meter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--text-soft);
  font-family: var(--font-mono);
}

.token-meter-percent {
  color: var(--text-muted);
}

.token-meter-bar {
  width: 100%;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--meter-track);
  overflow: hidden;
}

.token-meter-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width var(--dur-base) var(--ease-out);
}

.token-meter.warning .token-meter-fill {
  background: var(--grad-warn);
}

.token-meter.danger .token-meter-fill {
  background: var(--grad-danger);
}

.token-meter-notes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.token-meter-tag {
  border: 1px solid rgba(var(--accent-rgb), 0.46);
  border-radius: var(--radius-pill);
  padding: 2px 7px;
  color: var(--text-accent);
  background: rgba(var(--accent-rgb), 0.11);
  font-size: 10px;
  font-family: var(--font-main);
  letter-spacing: 0.01em;
}

.message pre {
  margin: 10px 0;
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--panel);
  position: relative;
  overflow: auto;
  border: 1px solid var(--line);
}

.message code {
  background: var(--panel);
  font-family: var(--font-mono);
  font-size: 12px;
}

/* Inline code (outside <pre>) gets the same quiet chip as .live-narration. */
.message :not(pre) > code {
  background: rgba(var(--on-rgb), 0.06);
  border: 1px solid var(--border-faint);
  border-radius: 4px;
  padding: 1px 5px;
}

.message .katex,
.live-agent-bubble .katex {
  font-size: 1.05em;
  color: var(--message-text);
}

.message .katex-display,
.live-agent-bubble .katex-display {
  margin: 0.55em 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.message .math-fallback,
.live-agent-bubble .math-fallback {
  font-family: var(--font-mono);
  font-size: 0.92em;
  color: var(--text-muted);
}

.message .math-fallback.math-display,
.live-agent-bubble .math-fallback.math-display {
  display: block;
  margin: 0.55em 0;
  padding: 0.35em 0.5em;
  border-radius: 8px;
  background: var(--surface);
  overflow-x: auto;
}

.message .table-wrap,
.live-agent-bubble .table-wrap {
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 0.75em 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.message .table-wrap table,
.live-agent-bubble .table-wrap table {
  width: 100%;
  table-layout: auto;
}

.message table,
.live-agent-bubble table {
  border-collapse: collapse;
  font-size: 13px;
  line-height: 1.5;
}

.message th,
.message td,
.live-agent-bubble th,
.live-agent-bubble td {
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
  white-space: normal;
  overflow-wrap: break-word;
  word-break: break-word;
}

.message th,
.live-agent-bubble th {
  background: var(--surface);
  font-weight: 600;
  color: var(--message-text);
}

.message tr:last-child td,
.live-agent-bubble tr:last-child td {
  border-bottom: none;
}

.message tbody tr:nth-child(even) td,
.live-agent-bubble tbody tr:nth-child(even) td {
  background: rgba(var(--on-rgb), 0.025);
}

.message td code,
.live-agent-bubble td code {
  font-size: 11px;
}

/* Safety: any <pre> that hosts a copy button must be its positioning parent */
pre:has(.copy-button) {
  position: relative;
}

.copy-button {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 1px solid var(--line);
  border-radius: var(--btn-radius);
  background: var(--panel);
  color: var(--text);
  font-size: 11px;
  font-family: var(--font-main);
  font-weight: 600;
  padding: 4px 8px;
  cursor: pointer;
  transition:
    opacity var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
  opacity: 0.8;
}
.copy-button .material-symbols-rounded {
  font-size: 14px !important;
}

.copy-button:hover {
  opacity: 1;
  border-color: var(--line-strong);
  color: var(--teal-text);
}

/* Language label, top-left of a fenced code block (ChatGPT/Claude-style). */
.code-lang-label {
  position: absolute;
  top: 8px;
  left: 12px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  opacity: 0.7;
  user-select: none;
  pointer-events: none;
}
.message pre:has(.code-lang-label) {
  padding-top: 30px;
}

/* Rides inside #chat-messages, pinned below the streaming reply. */
.typing-indicator {
  display: none;
  align-items: center;
  gap: 10px;
  width: fit-content;
  margin: 6px 14px 12px;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  font-size: 12px;
  color: var(--text-muted);
  background: var(--panel-translucent);
}

.typing-indicator:not([hidden]):not(:empty) {
  display: flex;
}

.typing-indicator button {
  border: 1px solid rgba(var(--accent-rgb), 0.4);
  background: rgba(var(--accent-rgb), 0.12);
  color: var(--text-accent);
  border-radius: var(--btn-radius);
  font-size: 11px;
  padding: 4px 8px;
  cursor: pointer;
  font-family: var(--font-main);
  font-weight: 600;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}

.typing-indicator button:hover {
  background: rgba(var(--accent-rgb), 0.2);
}

.typing-indicator button:active {
  transform: translateY(1px);
}

.streaming-preview {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--panel-soft);
  border-left: 2px solid var(--accent);
  margin: 0 8px;
  border-radius: 0 6px 6px 0;
  opacity: 0.85;
}

.streaming-preview::after {
  content: "▍";
  display: inline;
  animation: blink-cursor 0.7s step-end infinite;
  color: var(--accent);
  margin-left: 1px;
}

@keyframes blink-cursor {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0;
  }
}

/* ── Live agent bubble ─────────────────────────────────────── */
.live-agent-bubble {
  margin: 6px 10px;
  padding: 10px 12px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 12px;
  color: var(--message-text);
  display: flex;
  flex-direction: column;
  gap: 6px;

  width: 100%;
}

.cancelled-tag {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.7;
  padding-top: 4px;
  border-top: 1px solid var(--line);
  margin-top: 4px;
}

.live-agent-header {
  color: var(--text-muted);
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.live-agent-spinner {
  display: inline-block;
  animation: spin 1s linear infinite;
  font-style: normal;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.live-agent-steps {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.live-step {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 2px 0;
  color: var(--text-muted);
  line-height: 1.4;
}

.live-step-icon {
  flex-shrink: 0;
  font-size: 11px;
}

.live-step-name {
  font-weight: 600;
  color: var(--accent);
}

.live-step-info {
  font-family: var(--font-mono);
  font-size: 11px;
  opacity: 0.65;
  word-break: break-all;
  font-weight: 400;
}

.live-step.done .live-step-name {
  color: var(--text-muted);
  font-weight: 400;
}

.live-step.error .live-step-name {
  color: var(--error-soft-text);
}

/* Inline diff attached to edit live-steps */
.live-step {
  flex-wrap: wrap;
  min-width: 0;
  overflow: hidden;
  position: relative;
  width: 100%;
}

.live-step-diff-badge {
  font-family: var(--font-mono);
  font-size: 12px;
  margin-left: 4px;
  opacity: 0.8;
  width: 100%;
}

.diff-add-count {
  color: var(--success-text);
}

.diff-del-count {
  color: var(--error-text);
}

.live-step-diff-details {
  width: 100%;
  min-width: 0;
  margin-top: 4px;
  overflow: hidden;
}


.live-step-diff-summary {
  font-size: 12px;
  color: var(--text-accent-soft);
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  opacity: 0.8;
  width: 100%;
  transition:
    color var(--dur-fast) var(--ease-out),
    opacity var(--dur-fast) var(--ease-out);
}
.live-step-diff-summary:hover {
  color: var(--text-accent);
  opacity: 1;
}
.live-step-diff-summary::-webkit-details-marker {
  display: none;
}

.live-step-diff-summary::before {
  content: "▶";
  font-size: 9px;
  transition: transform var(--dur-fast) var(--ease-out);
}

.live-step-diff-details[open] .live-step-diff-summary::before {
  transform: rotate(90deg);
}

.live-step-diff-pre {
  margin: 4px 0 0;
  padding: 6px 8px;
  background: var(--surface-2);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  overflow-x: auto;
  max-width: 100%;
  white-space: pre;
}

.diff-line-add {
  color: var(--diff-add);
  display: block;
}

.diff-line-del {
  color: var(--diff-del);
  display: block;
}

.diff-line-hunk {
  color: var(--diff-hunk);
  display: block;
  opacity: 0.7;
}

.diff-line-ctx {
  color: var(--text-muted);
  display: block;
  opacity: 0.6;
}

/* Inline streamed narration inside the live bubble (the model "thinking") */
.live-narration {
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
  padding: 2px 0;
  min-width: 0;
  overflow: hidden;
}

.live-narration p {
  margin: 4px 0;
}

.live-narration strong {
  font-weight: 600;
  color: var(--text);
}

.live-narration em {
  opacity: 0.85;
}

.live-narration pre {
  margin: 8px 0;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 12px;
  background: var(--panel-deep);
  position: relative;
  overflow-x: auto;
  max-width: 100%;
  white-space: pre;
  word-break: normal;
}

.live-narration code {
  font-family: var(--font-mono);
  font-size: 13px;
}

.live-narration p code {
  background: rgba(var(--on-rgb), 0.06);
  border-radius: 4px;
  padding: 1px 5px;
}

.live-narration ul,
.live-narration ol {
  margin: 4px 0;
  padding-left: 20px;
}

.live-narration li {
  margin: 2px 0;
}

/* Persisted thinking trace inside an assistant message */
.thinking-trace {
  margin: 0 0 6px 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-size: 13px;
  overflow: hidden;
  width: 100%;
}

.thinking-trace>summary {
  cursor: pointer;
  padding: 6px 10px;
  color: var(--text);
  user-select: none;
  list-style: none;
}

.thinking-trace>summary::-webkit-details-marker {
  display: none;
}

.thinking-trace>summary::before {
  content: "▸ ";
  color: var(--accent);
}

.thinking-trace[open]>summary::before {
  content: "▾ ";
}

.thinking-trace>summary:hover {
  color: var(--text);
}

.thinking-trace-body {
  padding: 4px 12px 10px;
  color: var(--text);

  line-height: 1.6;
  white-space: normal;
  word-break: break-word;
}

.thinking-trace-body pre {
  margin: 8px 0;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 12px;
  background: var(--panel-deep);
  position: relative;
  overflow-x: auto;
  max-width: 100%;
  white-space: pre;
  word-break: normal;
}

.thinking-trace-body code {
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  background: rgba(var(--on-rgb), 0.06);
  padding: 1px 5px;
  border-radius: 4px;
}

.debug-panel {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.debug-panel summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  padding: 8px 12px;
  user-select: none;
  font-family: var(--font-main);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.debug-panel[open] summary {
  color: var(--text);
}

#debug-output {
  margin: 0;
  padding: 0 12px 12px;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-muted);
  font-family: var(--font-mono);
  border-top: 1px dashed var(--line);
  background: var(--surface);
}

.settings-panel {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 14px 12px;
  background: var(--surface);
  display: grid;
  gap: 10px;
}

.settings-panel h3 {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.settings-panel p {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

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

/* `display: flex` above beats the UA `[hidden] { display: none }`, so honor the
   hidden attribute explicitly — otherwise the legacy usage actions (which stay
   hidden while the account dashboard renders its own reset button) show a
   duplicate "Reset usage stats" button. */
.settings-actions[hidden] {
  display: none;
}

.settings-divider {
  border-top: 1px dashed var(--line);
  margin: 4px 0;
}

.settings-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.settings-field {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.settings-field input[type="number"],
.settings-field input[type="text"],
.settings-field input[type="password"],
.settings-field select {
  width: 100%;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 8px 9px;
}

.settings-field input[type="number"]:focus-visible,
.settings-field input[type="text"]:focus-visible,
.settings-field input[type="password"]:focus-visible,
.settings-field select:focus-visible {
  border-color: var(--input-border-focus);
  box-shadow: 0 0 0 3px var(--select-focus-ring);
  outline: none;
}

.key-list {
  display: grid;
  gap: 8px;
  padding-right: 2px;
}

/* ── Data APIs (external_data integrations) ────────────────────────────── */
/* ── Usage dashboard (Settings → Usage) ─────────────────────────────────
   Chart tokens: blue/violet series are grayscale in the monochrome design;
   semantic greens/ambers/reds stay colored. Dark values are the default (app
   root is dark); light overrides below. Series colors are read at render time
   by usage-dashboard.js. */
.usage-dash {
  --uv-s1: #E8E8EC;
  --uv-s2: #199e70;
  --uv-s3: #c98500;
  --uv-s4: #008300;
  --uv-s5: #B9B9C4;
  --uv-s6: #e66767;
  --uv-other: var(--text-faint);
  --uv-grid: var(--line);
  --uv-axis: var(--line-strong);
  --uv-muted: var(--text-faint);
  --uv-ink: var(--text);
  --uv-surface: var(--surface);
  --uv-accent: var(--accent);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
[data-theme="light"] .usage-dash {
  --uv-s1: #5D5E6B;
  --uv-s2: #1baf7a;
  --uv-s3: #eda100;
  --uv-s4: #008300;
  --uv-s5: #3A3A42;
  --uv-s6: #e34948;
  --uv-grid: var(--line);
  --uv-axis: var(--line-strong);
  --uv-surface: var(--surface);
  --uv-accent: var(--accent);
}
.uv-plan {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  background: var(--surface-strong, var(--panel));
}
.uv-plan-name {
  font-weight: 600;
  font-size: 15px;
}
.uv-plan-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.uv-meter {
  margin-top: 10px;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--meter-track);
  overflow: hidden;
}
.uv-meter-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--uv-accent);
  transition: width var(--dur-base) var(--ease-out);
}
.uv-meter-fill.uv-meter-full {
  background: var(--error-text);
}
.uv-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.uv-filter-btn {
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-soft, inherit);
  cursor: pointer;
  font-family: var(--font-main);
  font-size: 12px;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}
.uv-filter-btn:hover:not(.is-active) {
  background: var(--hover-fill);
  border-color: var(--line-strong);
  color: var(--text);
}
.uv-filter-btn.is-active {
  border-color: var(--uv-accent);
  color: var(--text);
  background: rgba(var(--accent-rgb), 0.1);
}
.uv-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}
.uv-tile {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--surface-strong, var(--panel));
}
.uv-tile-label {
  font-size: 11px;
  color: var(--text-muted);
}
.uv-tile-value {
  font-size: 22px;
  font-weight: 600;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.uv-tile-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.uv-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px 14px;
  background: var(--surface-strong, var(--panel));
}
.uv-card-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.uv-chart {
  position: relative;
  width: 100%;
}
.uv-chart svg {
  display: block;
}
.uv-hit {
  cursor: default;
  outline: none;
}
.uv-hit:hover,
.uv-hit:focus-visible {
  fill: var(--hover-fill);
}
.uv-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 120px;
  max-width: 220px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-strong, var(--panel));
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.uv-tip-title {
  font-weight: 600;
  margin-bottom: 4px;
}
.uv-tip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 1px 0;
}
.uv-tip-key {
  width: 10px;
  height: 3px;
  border-radius: 2px;
  flex-shrink: 0;
}
.uv-tip-name {
  color: var(--text-muted);
}
.uv-tip-total {
  margin-top: 4px;
  color: var(--text-muted);
}
.uv-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}
.uv-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-soft, inherit);
}
.uv-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}
.uv-table-wrap {
  overflow-x: auto;
}
.uv-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.uv-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.uv-note {
  font-size: 12px;
  color: var(--text-muted);
}
.uv-empty {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  text-align: center;
}

.usage-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.usage-cat-head {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-top: 12px;
}
.usage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.usage-table th,
.usage-table td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}
.usage-table th {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}
.usage-table td:nth-child(2),
.usage-table td:nth-child(4),
.usage-table th:nth-child(2),
.usage-table th:nth-child(4) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.usage-total {
  margin-top: 12px;
  font-size: 13px;
  font-weight: 600;
}
.usage-empty {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  text-align: center;
}

.data-api-list {
  display: grid;
  gap: 8px;
}

.data-api-row {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-strong);
  padding: 10px 12px;
  transition: opacity var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}

.data-api-row.is-off {
  opacity: 0.55;
}

.data-api-toggle {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
  cursor: pointer;
}

.data-api-toggle input[type="checkbox"] {
  margin-top: 1px;
}

.data-api-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.data-api-name {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.data-api-badge {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  background: rgba(var(--on-rgb), 0.05);
  border: 1px solid var(--line);
}

.data-api-badge.is-required {
  color: var(--accent);
  border-color: rgba(var(--accent-rgb), 0.45);
  background: rgba(var(--accent-rgb), 0.12);
}

.data-api-desc {
  font-size: 12px;
  color: var(--text-muted);
}

.data-api-key-field {
  flex: 0 0 264px;
  max-width: 264px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.data-api-key-input {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12px;
  padding: 7px 9px;
  border: 1px solid var(--select-border);
  border-radius: 8px;
  background: var(--select-bg);
  color: var(--text);
}

.data-api-key-input:focus {
  outline: none;
  border-color: var(--checkbox-border-checked);
  box-shadow: 0 0 0 3px var(--select-focus-ring);
}

.data-api-icon-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--select-border);
  border-radius: var(--btn-radius);
  background: var(--select-bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}

.data-api-icon-btn:hover {
  color: var(--text);
  border-color: var(--checkbox-border-checked);
}

.data-api-icon-btn:focus-visible {
  outline: none;
  border-color: var(--checkbox-border-checked);
  box-shadow: 0 0 0 3px var(--select-focus-ring);
}

.data-api-copy-btn.is-copied {
  color: var(--accent);
  border-color: rgba(var(--accent-rgb), 0.45);
}

.data-api-icon-btn .material-symbols-rounded {
  font-size: 18px;
  line-height: 1;
}

@media (max-width: 640px) {
  .data-api-row {
    flex-wrap: wrap;
  }
  .data-api-key-field {
    flex-basis: 100%;
    max-width: none;
  }
}

.key-list-empty {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 10px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
  background: var(--surface);
}

.key-entry {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-strong);
  padding: 9px 10px;
  display: grid;
  gap: 7px;
}

.key-entry-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--text);
}

.key-call-count {
  font-size: 10px;
  color: var(--text-muted);
  background: rgba(var(--on-rgb), 0.05);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 1px 7px;
  margin-left: auto;
  white-space: nowrap;
  flex-shrink: 0;
}

.key-entry-meta {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.key-entry-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.key-entry-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  user-select: none;
}

.key-entry-toggle:has(input:checked) {
  color: var(--text);
}

.key-remove-button {
  border: 1px solid rgba(var(--accent-rgb), 0.4);
  background: rgba(var(--accent-rgb), 0.12);
  color: var(--text-accent);
  border-radius: var(--btn-radius);
  padding: 4px 8px;
  cursor: pointer;
  font-size: 11px;
  font-family: var(--font-main);
  font-weight: 600;
  transition:
    background-color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out);
}

.key-remove-button:hover {
  background: rgba(var(--accent-rgb), 0.2);
  border-color: rgba(var(--accent-rgb), 0.55);
}

.settings-checkbox-row {
  display: grid;
  gap: 8px;
}

.settings-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-soft);
  cursor: pointer;
  user-select: none;
}

.settings-checkbox:has(input:checked) {
  color: var(--text);
}

.settings-inline-status {
  font-size: 12px;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
}

.settings-inline-status.success {
  color: var(--success-text);
}

.settings-inline-status.warning {
  color: var(--warn-text);
}

.settings-inline-status.error {
  color: var(--error-text);
}

.version-history-list {
  display: grid;
  gap: 8px;
  padding-right: 2px;
}

.version-history-empty {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 10px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface);
}

.version-entry {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  padding: 9px 10px;
  cursor: pointer;
  display: grid;
  gap: 4px;
  transition:
    border-color var(--dur-base) var(--ease-out),
    background-color var(--dur-base) var(--ease-out);
  opacity: 0.9;
}

.version-entry:hover {
  border-color: var(--accent);
  opacity: 1.0;
}

.version-entry-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.version-entry-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.version-entry-stats {
  white-space: nowrap;
  color: var(--text-accent);
}

.version-entry-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.storage-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 14px;
  background: var(--scrim);
  z-index: var(--z-overlay);
  backdrop-filter: blur(5px);
}

/* Import/Export (#storage-modal) and the confirm dialog (#workspace-dialog, which
   reuses .settings-modal) can be opened from inside the Project settings modal
   (z-index --z-modal). They must stack above it, or they render hidden behind it.
   Both are already direct <body> children, so a higher z-index is sufficient. */
#storage-modal,
#workspace-dialog {
  z-index: var(--z-modal-top);
}

.storage-modal[hidden] {
  display: none;
}

.storage-modal-card {
  width: min(760px, 100%);
  border: none;
  border-radius: 14px;
  background: var(--panel);
  display: grid;
  gap: 10px;
  padding: 14px;
}

.storage-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.storage-modal-head h3 {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.storage-modal-description {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

#storage-modal-textarea {
  width: 100%;
  min-height: 220px;
  max-height: 50vh;
  resize: vertical;
  border: 1px solid var(--input-border);
  border-radius: 10px;
  padding: 10px;
  background: var(--panel);
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre;
  overflow: auto;
}

#storage-modal-textarea:focus-visible {
  border-color: var(--input-border-focus);
  box-shadow: 0 0 0 3px var(--select-focus-ring);
  outline: none;
}

#diff-modal-output {
  width: 100%;
  min-height: 300px;
  max-height: 58vh;
  margin: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.45;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.storage-modal-feedback {
  margin: 0;
  min-height: 16px;
  color: var(--accent-warm);
  font-size: 12px;
}

.storage-modal-feedback.success {
  color: var(--text-accent);
}

.storage-modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

#chat-input-area {
  border-top: 1px solid var(--line);
  padding: 6px 8px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
}

.composer-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.composer-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.mode-toggle-wrap {
  position: relative;
}

.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px 5px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
  transition:
    background var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out);
}

.mode-pill:hover {
  background: var(--surface-soft);
  border-color: var(--btn-secondary-border-hover);
}

.mode-pill .mode-pill-icon,
.mode-pill .mode-pill-caret {
  font-size: 14px !important;
}

.mode-pill .mode-pill-caret {
  opacity: 0.7;
  margin-left: -2px;
}

.mode-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  min-width: 160px;
  padding: 6px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: var(--z-nav);
  /* Long model lists must scroll inside the menu: without a cap the drop-up
     grows past the top of the viewport and the first entries are unreachable. */
  max-height: min(60vh, 480px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.mode-menu[hidden] {
  display: none;
}

.mode-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font-main);
  font-size: 13px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: background-color var(--dur-base) var(--ease-out);
}

.mode-menu-item:hover {
  background: rgba(var(--accent-rgb), 0.12);
}

.mode-menu-item.active {
  background: rgba(var(--accent-rgb), 0.18);
  color: var(--text);
}

.mode-menu-item .material-symbols-rounded {
  font-size: 16px !important;
}

.model-provider-icon {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  object-fit: contain;
  flex-shrink: 0;
}

.mode-pill-subtle {
  background: transparent;
  border-color: var(--line);
  color: var(--text-muted);
  min-width: 0;
  max-width: 100%;
}

#agent-model-toggle {
  max-width: 132px;
}

#agent-model-label {
  display: block;
  min-width: 0;
  max-width: 16ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mode-pill-subtle:hover {
  color: var(--text);
}

#model-toggle-wrap[data-disabled="true"] {
  opacity: 0.4;
  pointer-events: none;
}

#reasoning-toggle[data-state="on"] {
  border-color: rgba(var(--focus-rgb), 0.55);
  background: rgba(var(--focus-rgb), 0.12);
  color: var(--text-accent-soft);
}

#reasoning-toggle[data-state="off"] {
  opacity: 0.55;
}

#reasoning-toggle[data-state="on"] .mode-pill-icon {
  color: var(--text-accent-soft);
}

#pick-element-btn {
  margin-left: auto;
}

/* Active (engaged) state for the Pick / Text tools — as prominent as the
   Preview/Code/Settings nav tabs' .active state so it's obvious the mode is on. */
#pick-element-btn[aria-pressed="true"],
#text-edit-btn[aria-pressed="true"] {
  color: var(--on-accent);
  border-color: rgba(var(--accent-rgb), 0.45);
  background: var(--accent-deep);
}

#pick-element-btn[aria-pressed="true"]:hover,
#text-edit-btn[aria-pressed="true"]:hover {
  color: var(--on-accent);
  background: var(--accent-deep);
}

.picked-context {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.picked-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 4px 6px 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(var(--accent-rgb), 0.5);
  background: rgba(var(--accent-rgb), 0.12);
  color: var(--text-accent);
  font-family: var(--font-mono);
  font-size: 11px;
}

.picked-chip .picked-chip-sel {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 240px;
}

.picked-chip-remove {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: transparent;
  padding: 0;
  color: inherit;
  cursor: pointer;
  text-align: center;
  transition: background-color var(--dur-base) var(--ease-out);
}

.picked-chip-remove:hover {
  background: rgba(var(--on-rgb), 0.12);
}

.picked-chip-remove .material-symbols-rounded {
  font-size: 14px;
}

.model-hint {
  font-style: normal;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 10px;
  border-radius: var(--radius-pill);
  background: rgba(var(--info-rgb), 0.14);
  color: var(--info-text);
  border: 1px solid rgba(var(--info-rgb), 0.28);
  font-family: var(--font-mono);
}

.mode-menu-empty {
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.settings-hint-text {
  font-size: 11px;
  color: var(--text-muted);
  margin: 4px 0 8px;
  line-height: 1.45;
}

.composer-input-stack {
  position: relative;
  min-height: 40px;
  border-radius: 11px;
}

.composer-input-stack:focus-within {
  box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.55);
}

#chat-input-overlay {
  position: absolute;
  inset: 0;
  border-radius: 11px;
  border: none;
  background: transparent;
  color: transparent;
  font-family: var(--font-main);
  font-size: 14px;
  line-height: 1.4;
  padding: 8px 10px;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  overflow-y: auto;
  pointer-events: none;
}

#chat-input-overlay::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.composer-overflow {
  color: var(--text-faint);
}

#chat-input {
  position: relative;
  z-index: 1;
  width: 100%;
  resize: none;
  min-height: 40px;
  max-height: 190px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--text);
  caret-color: var(--text);
  font-family: var(--font-main);
  font-size: 14px;
  line-height: 1.4;
  padding: 8px 10px;
  overflow-y: auto;
}

#chat-input:focus {
  outline: none;
  box-shadow: none;
}

#chat-input:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

#chat-input::placeholder {
  color: var(--text-muted);
}

.composer-stats {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  padding: 0 2px;
}

.composer-stats.warning {
  color: var(--warn-text);
}

.composer-stats.danger {
  color: var(--warn-strong-text);
}

#send-button {
  border: 1px solid rgba(var(--on-rgb), 0.24);
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--on-accent);
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 0;
  padding: 0;
  height: 30px;
  width: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 0;
  cursor: pointer;
  transition: transform var(--dur-base) var(--ease-out);
}

#send-button .material-symbols-rounded {
  font-size: 15px;
  width: 15px;
  height: 15px;
  line-height: 1;
  display: block;
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 20;
}


#send-button:hover:not(:disabled):not(.stop-mode) {
  background: var(--accent-deep);
}

#send-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

/* Stop state while the agent is generating — click to cancel. */
#send-button.stop-mode {
  background: var(--stop);
  border-color: rgba(var(--on-rgb), 0.28);
}

.bottom-vv {
  min-height: 44px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media screen and (max-width: 1180px) {
  .top-vv {
    flex-wrap: wrap;
  }

  #program-title {
    max-width: 100%;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }
}

@media screen and (max-width: 640px) {
  .app-shell {
    padding: 10px;
    gap: 10px;
  }

  .top-vv {
    padding: 12px;
  }

  .navbar {
    flex-wrap: wrap;
  }

  .status-pill {
    margin-left: 0;
  }

  .bottom-vv {
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    padding: 8px 12px;
    line-height: 1.5;
  }

  .btn,
  .btn-subtle,
  .btn-secondary,
  .settings-action-button,
  .storage-modal-button {
    --btn-padding-x: 12px;
  }

  #chat-messages {
    padding: 10px;
  }

  #chat-input-area {
    padding: 10px;
  }
}

/* ── Mobile: single-view tabs + hamburger right drawer ───────────────── */
@media screen and (max-width: 1000px) {

  html,
  body {
    overflow: hidden;
  }

  .app-shell {
    flex-direction: column;
    height: 100%;
    min-height: 0;
    padding: 10px;
    gap: 10px;
  }

  /* Navbar: brand + menu (+ tool icons on builder). backdrop-filter removed so
     the fixed drawer is not clipped. */
  .navbar {
    flex-wrap: nowrap;
    backdrop-filter: none;
    gap: 6px;
    padding: 8px 10px;
    min-height: 48px;
  }

  .builder-navbar {
    justify-content: space-between;
  }

  .builder-navbar .navbar-leading {
    flex: 1;
    min-width: 0;
  }

  .builder-navbar .navbar-back-link {
    display: none;
  }

  .builder-navbar .nav-links {
    margin-left: 0;
  }

  .builder-navbar .nav-drawer-divider {
    display: block;
    height: 1px;
    background: var(--line);
    margin: 6px 4px;
    flex-shrink: 0;
  }

  .navbar img {
    margin-right: 0 !important;
  }

  .nav-menu-btn {
    display: inline-flex;
    flex-shrink: 0;
    margin-left: 0;
  }

  #sync-pill {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top, 0px));
    bottom: auto;
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-overlay);
    max-width: calc(100vw - 24px);
    box-shadow: none;
  }

  #sync-pill:empty {
    display: none !important;
  }

  /* Nav links become a right side drawer. */
  .nav-links {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: min(80vw, 300px);
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 64px 14px 18px;
    background: var(--surface-strong);
    border-left: 1px solid var(--line);
    transform: translateX(100%);
    transition: transform var(--dur-slow) var(--ease-out);
    z-index: 1000;
    overflow-y: auto;
  }

  .nav-links.open {
    transform: translateX(0);
  }

  .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    font-size: 15px;
    padding: 12px 14px;
    border-radius: var(--btn-radius);
  }

  .nav-link-chat {
    display: flex;
  }

  /* Builder agent chat first, then preview, in the mobile drawer. */
  .builder-navbar .nav-links [data-view="chat"] {
    order: -20;
  }

  .builder-navbar .nav-links [data-view="preview"] {
    order: -19;
  }

  .builder-navbar .nav-links [data-view="code"] {
    order: -18;
  }

  .builder-navbar .nav-links [data-view="storage"] {
    order: -17;
  }

  /* Embedded builder: keep agent chat reachable when switching views on mobile. */
  html[data-embed="1"] .builder-navbar .nav-link-chat,
  html[data-embed="1"] .builder-navbar [data-view="chat"] {
    display: flex !important;
  }

  /* Single view at a time, driven by #main-stage[data-view]. */
  .editor-iframe {
    flex-direction: column;
    min-height: 0;
    flex: 1;
    gap: 0;
  }

  #editor {
    min-height: 280px;
  }

  #iframe {
    min-height: 320px;
  }

  .resizer {
    display: none;
  }

  #left-panel,
  #right-stage {
    flex: 1 1 auto !important;
    min-width: 0;
    width: 100%;
  }

  #main-stage[data-view="chat"] #right-stage {
    display: none;
  }

  #main-stage[data-view="chat"] #left-panel {
    display: flex !important;
    flex: 1 1 auto;
    min-height: 0;
  }

  #main-stage[data-view="chat"] #chat-content {
    flex: 1;
    min-height: 0;
  }

  #chat-input-area {
    flex-shrink: 0;
  }

  #main-stage[data-view="preview"] #left-panel,
  #main-stage[data-view="code"] #left-panel {
    display: none;
  }

  /* Hide Code tab mode: preview is always visible — no Preview nav tab needed. */
  #main-stage[data-hide-code-tab="1"][data-view="chat"] #right-stage {
    display: flex !important;
    flex: 1 1 auto;
    min-height: 0;
  }

  #main-stage[data-hide-code-tab="1"][data-view="chat"] #left-panel {
    display: flex !important;
    flex: 1 1 auto;
    min-height: 0;
  }

  #main-stage[data-hide-code-tab="1"] .builder-navbar .nav-links [data-view="preview"] {
    display: none !important;
  }

  /* No dev mode on mobile. */
  #dev-mode-btn,
  #switch-sides-btn {
    display: none !important;
  }
}

.no-select {
  -webkit-user-select: none;
  /* Safari, Chrome, Opera */
  -moz-user-select: none;
  /* Firefox */
  -ms-user-select: none;
  /* Internet Explorer */
  user-select: none;
  /* Standard property */
}

span.material-symbols-rounded {
  -webkit-user-select: none;
  /* Safari, Chrome, Opera */
  -moz-user-select: none;
  /* Firefox */
  -ms-user-select: none;
  /* Internet Explorer */
  user-select: none;
  /* Standard property */
}

/* ── Agent thinking block styled details ────────────────────────────── */
.agent-thinking-block {
  border: 1px solid rgba(var(--accent-rgb), 0.25);
  background: rgba(var(--accent-rgb), 0.06);
  border-radius: 10px;
  padding: 10px 14px;
  margin: 10px 0;
  font-family: var(--font-main);
  backdrop-filter: blur(4px);
}

.agent-thinking-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.agent-thinking-content {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.55;
  white-space: pre-wrap;
  font-style: italic;
}
/* ── Builder navbar: secondary tools are icon-only on desktop ─────────── */
@media (min-width: 1001px) {
  .nav-tool-btn:not(.nav-tool-labeled) .nav-label {
    display: none;
  }
  .nav-tool-btn:not(.nav-tool-labeled) {
    padding-left: 10px;
    padding-right: 10px;
  }
  .nav-tool-btn:not(.nav-tool-labeled) .nav-icon {
    margin-right: 0;
  }
}

/* Long filenames ellipsize inside the tree row (span added by js/index.js). */
.file-tree-label {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Tooltip layer (js/ui-tooltip.js) ───────────────────────────────────
   One fixed-position bubble on <body>, above every surface — immune to
   overflow clipping and stacking contexts, which killed the old ::after
   tooltips inside scroll containers. */
.ui-tooltip {
  position: fixed;
  z-index: calc(var(--z-toast) + 100);
  max-width: min(320px, calc(100vw - 16px));
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  background: var(--text);
  color: var(--bg-app);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}

.ui-tooltip.is-below {
  transform: translateY(-2px);
}

.ui-tooltip.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .ui-tooltip {
    transition: none;
  }
}

/* ── Memory (settings popup + study calendar buttons) ─────────────────────────────────────────── */
.memory-list {
  display: grid;
  gap: 8px;
  margin-top: 4px;
}

.memory-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.memory-item-body {
  min-width: 0;
}

.memory-item-text {
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
  overflow-wrap: anywhere;
}

.memory-item-meta {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-muted);
}

.memory-item-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

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

.memory-item-btn:hover {
  background: var(--hover-fill-strong);
  color: var(--text);
}

.memory-item-btn:active {
  transform: scale(0.98);
}

.memory-item-btn:focus-visible {
  outline: 2px solid rgb(var(--focus-rgb));
  outline-offset: 2px;
}

.memory-item-btn .material-symbols-rounded {
  font-size: 17px;
}

/* index.css paints .key-list-empty with --scrim-soft, which is a dark overlay
   in the light theme (muted text becomes unreadable on it). Scope a theme-safe
   ghost-item fill to this page and match the card radius used here. */
html.settings-page .key-list-empty {
  background: var(--surface);
  border-radius: var(--radius-md);
  line-height: 1.5;
}

/* Ghost-item look so an empty list reads as intentional, in both themes */
.memory-empty {
  margin: 0;
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
  background: var(--surface);
}
