@font-face {
  font-family: "JetBrains Mono";
  src: url("/fonts/jetbrains-mono-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/fonts/jetbrains-mono-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root,
:root[data-theme="light"] {
  color-scheme: light;
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;

  /* Fluent 2 semantic tokens */
  --color-neutral-background-1: #ffffff;
  --color-neutral-background-2: #fafafa;
  --color-neutral-background-3: #f5f5f5;
  --color-neutral-background-4: #ebebeb;
  --color-neutral-foreground-1: #242424;
  --color-neutral-foreground-2: #424242;
  --color-neutral-foreground-3: #616161;
  --color-neutral-stroke-1: #d1d1d1;
  --color-neutral-stroke-2: #e0e0e0;
  --color-brand-background: #0f6cbd;
  --color-brand-background-hover: #115ea3;
  --color-brand-background-pressed: #0c3b5e;
  --color-brand-foreground: #115ea3;
  --color-brand-subtle: #ebf3fc;
  --color-status-success: #0e700e;
  --color-status-warning: #8a3707;
  --color-status-danger: #b10e1c;
  --color-status-info: #004e8c;

  /* Compatibility aliases used by page components. */
  --font-ui: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  --bg: var(--color-neutral-background-2);
  --panel: var(--color-neutral-background-1);
  --panel-2: var(--color-neutral-background-3);
  --sidebar: #fafafa;
  --header: rgb(255 255 255 / 82%);
  --line: var(--color-neutral-stroke-2);
  --line-strong: var(--color-neutral-stroke-1);
  --muted: var(--color-neutral-foreground-3);
  --faint: #707070;
  --text: var(--color-neutral-foreground-1);
  --text-soft: var(--color-neutral-foreground-2);
  --accent: var(--color-brand-background);
  --accent-hover: var(--color-brand-background-hover);
  --accent-pressed: var(--color-brand-background-pressed);
  --accent-contrast: #ffffff;
  --accent-soft: var(--color-brand-subtle);
  --accent-border: #96c6fa;
  --signal: var(--color-status-success);
  --signal-soft: #f1faf1;
  --signal-border: #9fd89f;
  --info: var(--color-status-info);
  --info-soft: #ebf3fc;
  --info-border: #b4d6fa;
  --danger: var(--color-status-danger);
  --danger-hover: #9c0c19;
  --danger-pressed: #7c0a14;
  --danger-soft: #fdf3f4;
  --danger-border: #eeacb2;
  --warning: var(--color-status-warning);
  --warning-soft: #fff9f5;
  --warning-border: #f2bb8d;
  --success-soft: #f1faf1;
  --overlay: #ffffff;
  --code-bg: #f5f5f5;
  --user-bubble: #ebf3fc;
  --shadow-2: 0 1px 2px rgb(0 0 0 / 14%), 0 0 2px rgb(0 0 0 / 12%);
  --shadow-8: 0 4px 8px rgb(0 0 0 / 14%), 0 0 2px rgb(0 0 0 / 12%);
  --shadow-16: 0 8px 16px rgb(0 0 0 / 14%), 0 0 2px rgb(0 0 0 / 12%);
  --shadow: var(--shadow-16);
  --shadow-sm: var(--shadow-2);
  --shadow-lift: var(--shadow-8);
  --radius: 8px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --color-neutral-background-1: #292929;
  --color-neutral-background-2: #1f1f1f;
  --color-neutral-background-3: #333333;
  --color-neutral-background-4: #3d3d3d;
  --color-neutral-foreground-1: #ffffff;
  --color-neutral-foreground-2: #d6d6d6;
  --color-neutral-foreground-3: #adadad;
  --color-neutral-stroke-1: #666666;
  --color-neutral-stroke-2: #424242;
  --color-brand-background: #479ef5;
  --color-brand-background-hover: #62abf5;
  --color-brand-background-pressed: #2886de;
  --color-brand-foreground: #62abf5;
  --color-brand-subtle: #0f2d46;
  --color-status-success: #54b054;
  --color-status-warning: #fce100;
  --color-status-danger: #dc626d;
  --color-status-info: #62abf5;
  --bg: var(--color-neutral-background-2);
  --panel: var(--color-neutral-background-1);
  --panel-2: var(--color-neutral-background-3);
  --sidebar: #242424;
  --header: rgb(41 41 41 / 82%);
  --line: var(--color-neutral-stroke-2);
  --line-strong: var(--color-neutral-stroke-1);
  --muted: var(--color-neutral-foreground-3);
  --faint: #929292;
  --text: var(--color-neutral-foreground-1);
  --text-soft: var(--color-neutral-foreground-2);
  --accent: var(--color-brand-background);
  --accent-hover: var(--color-brand-background-hover);
  --accent-pressed: var(--color-brand-background-pressed);
  --accent-contrast: #0f0f0f;
  --accent-soft: var(--color-brand-subtle);
  --accent-border: #0f6cbd;
  --signal: var(--color-status-success);
  --signal-soft: #183b18;
  --signal-border: #107c10;
  --info: var(--color-status-info);
  --info-soft: #0f2d46;
  --info-border: #0f6cbd;
  --danger: var(--color-status-danger);
  --danger-hover: #e17a83;
  --danger-pressed: #b74954;
  --danger-soft: #3b1219;
  --danger-border: #8f1d2c;
  --warning: var(--color-status-warning);
  --warning-soft: #3a2d00;
  --warning-border: #986f00;
  --success-soft: #183b18;
  --overlay: #333333;
  --code-bg: #1f1f1f;
  --user-bubble: #0f2d46;
  --shadow-2: 0 1px 2px rgb(0 0 0 / 28%), 0 0 2px rgb(0 0 0 / 24%);
  --shadow-8: 0 4px 8px rgb(0 0 0 / 28%), 0 0 2px rgb(0 0 0 / 24%);
  --shadow-16: 0 8px 16px rgb(0 0 0 / 28%), 0 0 2px rgb(0 0 0 / 24%);
}

/* Curated Fluent brand ramps. Each accent has tuned light and dark values. */
:root[data-accent="purple"] { --color-brand-background: #5c2e91; --color-brand-background-hover: #4f2682; --color-brand-background-pressed: #32145f; --color-brand-foreground: #5c2e91; --color-brand-subtle: #f5eef8; --accent-border: #c6b1de; }
:root[data-accent="teal"] { --color-brand-background: #006c4c; --color-brand-background-hover: #005a3f; --color-brand-background-pressed: #003d2b; --color-brand-foreground: #006c4c; --color-brand-subtle: #e6f7f2; --accent-border: #83c7b8; }
:root[data-accent="green"] { --color-brand-background: #107c10; --color-brand-background-hover: #0e6b0e; --color-brand-background-pressed: #0b5a0b; --color-brand-foreground: #107c10; --color-brand-subtle: #edf7ed; --accent-border: #9fd89f; }
:root[data-accent="orange"] { --color-brand-background: #ca5010; --color-brand-background-hover: #a83f0b; --color-brand-background-pressed: #7a2e08; --color-brand-foreground: #a83f0b; --color-brand-subtle: #fff3e8; --accent-border: #f2bb8d; }
:root[data-accent="magenta"] { --color-brand-background: #9b0062; --color-brand-background-hover: #850053; --color-brand-background-pressed: #65003f; --color-brand-foreground: #9b0062; --color-brand-subtle: #fceef5; --accent-border: #d8a0bd; }
:root[data-theme="dark"][data-accent="purple"] { --color-brand-background: #b4a0ff; --color-brand-background-hover: #c6b7ff; --color-brand-background-pressed: #9f85f2; --color-brand-foreground: #c6b7ff; --color-brand-subtle: #2b173d; --accent-border: #744da9; --accent-contrast: #1f1f1f; }
:root[data-theme="dark"][data-accent="teal"] { --color-brand-background: #4cc2a0; --color-brand-background-hover: #65d4b4; --color-brand-background-pressed: #2ea987; --color-brand-foreground: #65d4b4; --color-brand-subtle: #0d3328; --accent-border: #008567; --accent-contrast: #0f0f0f; }
:root[data-theme="dark"][data-accent="green"] { --color-brand-background: #54b054; --color-brand-background-hover: #6bc46b; --color-brand-background-pressed: #3f963f; --color-brand-foreground: #6bc46b; --color-brand-subtle: #183b18; --accent-border: #107c10; --accent-contrast: #0f0f0f; }
:root[data-theme="dark"][data-accent="orange"] { --color-brand-background: #f4a261; --color-brand-background-hover: #ffb57a; --color-brand-background-pressed: #db8747; --color-brand-foreground: #ffb57a; --color-brand-subtle: #402313; --accent-border: #c45d1d; --accent-contrast: #1f1f1f; }
:root[data-theme="dark"][data-accent="magenta"] { --color-brand-background: #e36fbe; --color-brand-background-hover: #ef88cc; --color-brand-background-pressed: #c951a3; --color-brand-foreground: #ef88cc; --color-brand-subtle: #3d1830; --accent-border: #a4267a; --accent-contrast: #1f1f1f; }

/* Fluent materials. Mica: ambient brand-tinted backdrop. Acrylic: translucent blurred surfaces. */
:root {
  --topbar-h: 68px;
  --mica:
    radial-gradient(1200px 560px at 76% -140px, color-mix(in srgb, var(--accent) 7%, transparent), transparent 64%),
    radial-gradient(900px 480px at -8% 108%, color-mix(in srgb, var(--accent) 4%, transparent), transparent 60%),
    var(--bg);
  --surface-acrylic: color-mix(in srgb, var(--overlay) 80%, transparent);
  --acrylic-blur: blur(20px) saturate(1.5);
}

* { box-sizing: border-box; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { border: 3px solid transparent; border-radius: 10px; background: var(--line-strong); background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background-color: var(--muted); }
::selection { color: var(--text); background: var(--accent-soft); }
html, body, #app { width: 100%; min-width: 320px; height: 100%; }
body { margin: 0; color: var(--text); background: var(--mica); font-size: 14px; }
h1, h2, h3, h4 { font-family: "Segoe UI Variable Display", var(--font-ui); font-weight: 600; }
strong, b { font-weight: 600; }
button, input, textarea, select { font: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:disabled { cursor: not-allowed; opacity: .45; }

/* Pairing */
.pairing-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.pairing-card { width: min(100%, 440px); padding: 32px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); box-shadow: var(--shadow-16); }
.pairing-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 32px; }
.pairing-brand strong { font-size: 16px; }
.pairing-icon { width: 48px; height: 48px; display: grid; place-items: center; margin-bottom: 20px; border-radius: 8px; color: var(--accent); background: var(--accent-soft); }
.pairing-card h1 { margin: 0 0 8px; font-size: 28px; line-height: 36px; }
.pairing-card > p { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 20px; }
.pairing-command { display: block; margin-bottom: 24px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 4px; color: var(--text); background: var(--code-bg); font: 13px/20px var(--font-mono); }
.pairing-card form { display: grid; gap: 10px; }
.pairing-card label { color: var(--text-soft); font-size: 13px; font-weight: 600; }
.pairing-card input { width: 100%; height: 48px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--text); background: var(--panel); font: 600 24px/1 var(--font-mono); letter-spacing: .22em; text-align: center; }
.pairing-card input:hover { border-color: var(--muted); }
.pairing-card input:focus { border-color: var(--accent); border-bottom-width: 2px; outline: none; }
.pairing-card form .primary { margin-top: 4px; }
.pairing-card > small { display: block; margin-top: 18px; color: var(--muted); font-size: 12px; line-height: 18px; }
.pairing-error, .turn-error { padding: 9px 11px; border: 1px solid var(--danger-border); border-radius: 6px; color: var(--danger); background: var(--danger-soft); font-size: 12px; }
.auth-loading { color: var(--muted); font-size: 14px; }

/* Application shell */
.shell { height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); overflow: hidden; }
.sidebar { z-index: 30; display: flex; flex-direction: column; min-width: 0; padding: 8px 12px 12px; border-right: 1px solid var(--line); background: color-mix(in srgb, var(--sidebar) 72%, transparent); backdrop-filter: var(--acrylic-blur); -webkit-backdrop-filter: var(--acrylic-blur); }
.brand { display: flex; align-items: center; gap: 11px; min-height: 60px; padding: 6px 8px; }
.brand-mark, .empty-logo { display: grid; place-items: center; color: var(--accent-contrast); background: linear-gradient(145deg, var(--accent), var(--accent-pressed)); }
.brand-mark { width: 36px; height: 36px; border-radius: 8px; box-shadow: var(--shadow-2); }
.brand strong { display: block; font-size: 15px; line-height: 20px; }
.brand small { display: block; margin-top: 1px; color: var(--muted); font-size: 11px; line-height: 16px; }
.nav-label { padding: 16px 12px 6px; color: var(--muted); font-size: 11px; font-weight: 600; }
.sidebar nav { display: grid; gap: 2px; }
.sidebar nav button, .settings-nav button { position: relative; min-height: 40px; padding: 0 10px; border: 0; border-radius: 6px; color: var(--text-soft); background: transparent; text-align: left; cursor: pointer; font-size: 14px; font-weight: 500; transition: background-color .1s ease, color .1s ease; }
.sidebar nav button { display: flex; align-items: center; gap: 9px; }
.sidebar nav button::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 2px; background: var(--accent); transform: scaleY(0); transition: transform .12s ease; }
.sidebar nav button:hover, .settings-nav button:hover { background: var(--panel-2); color: var(--text); }
.sidebar nav button.active, .settings-nav button[data-state="active"] { color: var(--text); background: var(--accent-soft); }
.sidebar nav button.active::before { transform: scaleY(1); }
.nav-icon { width: 28px; height: 28px; display: grid; place-items: center; color: var(--muted); }
.nav-icon svg { width: 18px; height: 18px; }
.sidebar nav button.active .nav-icon { color: var(--accent); }
.gateway-status { display: flex; align-items: center; gap: 10px; min-height: 54px; margin-top: auto; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); box-shadow: var(--shadow-2); }
.gateway-status i { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; color: var(--warning); background: currentColor; }
.gateway-status i.online { color: var(--signal); }
.gateway-status b, .gateway-status small { display: block; }
.gateway-status b { font-size: 12px; line-height: 16px; }
.gateway-status small { margin-top: 1px; color: var(--muted); font-size: 10px; line-height: 14px; }
.app-main { position: relative; min-width: 0; min-height: 0; height: 100vh; display: flex; flex-direction: column; }
.topbar { position: absolute; inset: 0 0 auto 0; z-index: 10; min-height: var(--topbar-h); display: flex; align-items: center; gap: 12px; padding: 0 24px; border-bottom: 1px solid var(--line); background: var(--header); backdrop-filter: var(--acrylic-blur); -webkit-backdrop-filter: var(--acrylic-blur); }
.page-heading { min-width: 180px; }
.topbar h1 { margin: 0; font-size: 20px; line-height: 26px; }
.topbar p { margin: 1px 0 0; color: var(--muted); font-size: 12px; line-height: 16px; }
.topbar .menu { display: none; }
.theme-toggle { min-width: 74px; height: 32px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--text-soft); background: var(--panel); cursor: pointer; font-size: 12px; font-weight: 600; }
.theme-toggle:hover { color: var(--text); background: var(--panel-2); }
.nav-scrim { display: none; }

/* Fluent controls. 13px/20px control text is a deliberate dense ramp choice below Fluent Body1 14/20. */
.primary, .secondary, .danger-solid { min-height: 32px; padding: 5px 12px; border-radius: 4px; font-size: 13px; line-height: 20px; font-weight: 600; cursor: pointer; transition: background-color .1s ease, border-color .1s ease; }
.primary, .secondary, .danger-solid { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.primary { border: 1px solid var(--accent); color: var(--accent-contrast); background: var(--accent); }
.primary:hover { border-color: var(--accent-hover); background: var(--accent-hover); }
.primary:active { border-color: var(--accent-pressed); background: var(--accent-pressed); }
.secondary { border: 1px solid var(--line-strong); color: var(--text); background: var(--panel); }
.secondary:hover { background: var(--panel-2); }
.secondary:active { background: var(--color-neutral-background-4); }
.danger-solid { border: 1px solid var(--danger); color: var(--accent-contrast); background: var(--danger); }
.danger-solid:hover:not(:disabled) { border-color: var(--danger-hover); background: var(--danger-hover); }
.danger-solid:active:not(:disabled) { border-color: var(--danger-pressed); background: var(--danger-pressed); }
.full { width: 100%; min-height: 36px; }
.icon-button { width: 32px; height: 32px; display: inline-grid; place-items: center; padding: 0; border: 0; border-radius: 4px; color: var(--text-soft); background: transparent; cursor: pointer; }
.icon-button:hover { color: var(--text); background: var(--panel-2); }
.search { height: 34px; display: flex; align-items: center; padding: 0 9px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--muted); background: var(--panel); }
.search:hover { border-color: var(--muted); }
.search:focus-within { border-color: var(--accent); border-bottom-width: 2px; }
.search input { width: 100%; padding: 0 7px; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 13px; }
.filters select { height: 34px; padding: 0 28px 0 10px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--text); background: var(--panel); }
.grow { flex: 1; max-width: 520px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 5px 11px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--muted); background: var(--panel); font-size: 12px; font-weight: 600; cursor: pointer; transition: background-color .1s ease, border-color .1s ease, color .1s ease; }
.chip:hover { border-color: var(--muted); color: var(--text); }
.chip.active { color: var(--accent); border-color: var(--accent-border); background: var(--accent-soft); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.tabs { display: flex; gap: 16px; min-height: 36px; border-bottom: 1px solid var(--line); }
.tabs button { position: relative; padding: 0 2px 9px; border: 0; color: var(--muted); background: none; cursor: pointer; font-size: 13px; font-weight: 600; }
.tabs button::after { content: ""; position: absolute; right: 0; bottom: -1px; left: 0; height: 2px; border-radius: 2px; background: var(--accent); transform: scaleX(0); }
.tabs button:hover { color: var(--text); }
.tabs button[data-state="active"] { color: var(--text); }
.tabs button[data-state="active"]::after { transform: scaleX(1); }
.tooltip { z-index: 50; padding: 6px 9px; border: 1px solid var(--line); border-radius: 4px; color: var(--text); background: var(--surface-acrylic); backdrop-filter: var(--acrylic-blur); -webkit-backdrop-filter: var(--acrylic-blur); box-shadow: var(--shadow-8); font-size: 12px; }
.tooltip-arrow { fill: var(--overlay); }

/* Chat */
.page { min-height: 0; flex: 1; animation: page-in .16s ease both; }
.chat-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); padding-top: var(--topbar-h); }
.chat-layout.todo-open { grid-template-columns: 280px minmax(0, 1fr) 320px; }
.sessions-panel { overflow: auto; margin-top: calc(-1 * var(--topbar-h)); padding: 16px 12px; padding-top: calc(var(--topbar-h) + 16px); scroll-padding-top: calc(var(--topbar-h) + 16px); border-right: 1px solid var(--line); background: var(--panel); }
.sessions-panel > .search { margin-top: 12px; }
.session-list-head { display: flex; align-items: center; justify-content: space-between; margin: 18px 8px 7px; }
.session-count { color: var(--muted); font: 11px var(--font-mono); font-variant-numeric: tabular-nums; }
.session-list { display: grid; gap: 2px; }
.session-item { position: relative; width: 100%; padding: 10px 10px 10px 12px; border: 0; border-radius: 6px; color: var(--text); background: transparent; text-align: left; cursor: pointer; }
.session-item::before { content: ""; position: absolute; left: 0; top: 11px; bottom: 11px; width: 3px; border-radius: 2px; background: var(--accent); transform: scaleY(0); }
.session-item:hover { background: var(--panel-2); }
.session-item.active { background: var(--accent-soft); }
.session-item.active::before { transform: scaleY(1); }
.session-item strong { display: block; overflow: hidden; font-size: 13px; white-space: nowrap; text-overflow: ellipsis; }
.session-item small { display: flex; justify-content: space-between; margin-top: 4px; color: var(--muted); font-size: 11px; }
.plan-unread { display: inline-block; width: 6px; height: 6px; margin-left: 6px; border-radius: 50%; background: var(--accent); }
.chat-panel { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.chat-heading { min-height: 52px; flex: 0 0 52px; display: flex; align-items: center; justify-content: space-between; padding: 0 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
.chat-heading strong, .chat-heading small { display: block; }
.chat-heading strong { font-size: 13px; }
.chat-heading small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.chat-heading-actions { display: flex; align-items: center; gap: 6px; }
.todo-toggle { min-height: 28px; padding: 3px 9px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--text-soft); background: var(--panel); font-size: 11px; font-weight: 600; cursor: pointer; }
.todo-toggle { display: inline-flex; align-items: center; gap: 5px; }
.todo-toggle:hover { background: var(--panel-2); }
.todo-toggle.active { border-color: var(--accent-border); color: var(--accent); background: var(--accent-soft); }
.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 24px max(24px, calc((100% - 880px) / 2)) 18px; }
.empty { padding-top: 12vh; color: var(--muted); text-align: center; }
.empty-logo { width: 52px; height: 52px; margin: auto; border-radius: 10px; font-size: 22px; box-shadow: var(--shadow-8); }
.empty h2 { margin: 18px 0 6px; color: var(--text); font-size: 24px; line-height: 32px; }
.empty p { margin: 0; font-size: 13px; }
.message { display: flex; align-items: flex-start; gap: 10px; margin: 14px 0; animation: message-in .18s ease both; }
.message.user { flex-direction: row-reverse; }
.avatar { width: 28px; height: 28px; flex: 0 0 28px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; color: var(--text-soft); background: var(--panel); font-size: 11px; font-weight: 600; }
.message.assistant .avatar { border-color: var(--accent); color: var(--accent-contrast); background: var(--accent); }
.message-content { min-width: 0; max-width: min(84%, 760px); display: grid; gap: 7px; }
.message.user .message-content { justify-items: end; }
.bubble { max-width: 100%; padding: 10px 13px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); background: var(--panel); box-shadow: var(--shadow-2); font-size: 14px; line-height: 1.65; overflow-wrap: anywhere; }
.message.user .bubble { border-color: var(--accent-border); border-top-right-radius: 2px; background: var(--user-bubble); }
.message.assistant .bubble { border-top-left-radius: 2px; }
.typing .bubble { color: var(--muted); }
.active-turn .message-content { width: min(84%, 760px); }
.streaming { border-color: var(--accent-border); }
.message-attachments { width: min(100%, 520px); display: grid; gap: 7px; }
.attachment-card { display: grid; grid-template-columns: 38px minmax(0, 1fr) 30px; align-items: center; gap: 9px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); box-shadow: var(--shadow-2); }
.attachment-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 6px; color: var(--accent); background: var(--accent-soft); }
.attachment-card strong, .attachment-card small, .attachment-meta strong, .attachment-meta small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.attachment-card strong, .attachment-meta strong { font-size: 12px; }
.attachment-card small, .attachment-meta small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.attachment-card a, .attachment-meta > a { width: 28px; height: 28px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 4px; color: var(--accent); text-decoration: none; }
.continuation-tag { justify-self: start; font-size: 10px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; background: var(--code-bg); }
.agent-event-cards { display: grid; gap: 7px; margin: 14px 0; }
.agent-event-card { display: flex; gap: 9px; align-items: flex-start; padding: 8px 11px; border: 1px solid var(--line); border-left-width: 3px; border-left-color: var(--info); border-radius: 8px; background: var(--panel); box-shadow: var(--shadow-2); }
.agent-event-card.warning { border-left-color: var(--accent); }
.agent-event-card.critical { border-left-color: var(--danger); }
.agent-event-icon { width: 24px; height: 24px; flex: 0 0 24px; display: grid; place-items: center; border-radius: 5px; color: var(--info); background: var(--code-bg); border: 1px solid var(--line); }
.agent-event-card.warning .agent-event-icon { color: var(--accent); }
.agent-event-card.critical .agent-event-icon { color: var(--danger); }
.agent-event-body { min-width: 0; }
.agent-event-title { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; color: var(--text); }
.agent-event-delivery { font-family: var(--font-mono); font-size: 10px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
.agent-event-body p { margin: 2px 0 0; font-size: 12px; color: var(--text-soft); overflow-wrap: anywhere; }
.agent-event-status { font-family: var(--font-mono); }
.image-attachment { width: min(100%, 680px); overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); box-shadow: var(--shadow-2); }
.image-preview-link { max-height: 520px; display: grid; overflow: hidden; place-items: center; background: var(--panel-2); }
.image-preview { display: block; max-width: 100%; max-height: 520px; object-fit: contain; }
.attachment-meta { display: grid; grid-template-columns: minmax(0, 1fr) 30px; align-items: center; gap: 9px; padding: 8px 10px; }
.reasoning-block, .live-tool { width: min(100%, 680px); overflow: hidden; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.reasoning-block summary, .live-tool summary { padding: 8px 11px; color: var(--muted); font-size: 12px; cursor: pointer; user-select: none; }
.reasoning-block summary::marker, .live-tool summary::marker { color: var(--accent); }
.reasoning-content { padding: 10px 12px; border-top: 1px solid var(--line); color: var(--text-soft); font-size: 13px; line-height: 1.6; }
.reasoning-block.historical { border-style: dashed; }
.live-tool summary { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 8px; }
.live-tool summary strong { color: var(--text); font: 600 12px/18px var(--font-mono); }
.live-tool summary small { color: var(--muted); }
.live-tool-details { display: grid; gap: 8px; padding: 10px 11px; border-top: 1px solid var(--line); }
.live-tool-details pre { max-height: 260px; margin: 0; padding: 10px; overflow: auto; border-radius: 4px; color: var(--text-soft); background: var(--code-bg); font: 12px/1.55 var(--font-mono); white-space: pre-wrap; }
.turn-status, .completion-status { color: var(--muted); font-size: 11px; }
.turn-status.failed, .turn-error { color: var(--danger); }
.pulse { display: inline-block; width: 6px; height: 6px; margin-right: 7px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }

/* Markdown and tool cards */
.markdown-body { min-width: 0; }
.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }
.markdown-body p, .markdown-body ul, .markdown-body ol, .markdown-body blockquote, .markdown-body pre, .markdown-body table { margin: .62em 0; }
.markdown-body ul, .markdown-body ol { padding-left: 1.4em; }
.markdown-body li + li { margin-top: .2em; }
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 { margin: 1em 0 .42em; line-height: 1.3; }
.markdown-body h1 { font-size: 1.42em; }
.markdown-body h2 { font-size: 1.22em; }
.markdown-body h3 { font-size: 1.08em; }
.markdown-body a { color: var(--accent); text-underline-offset: 2px; }
.markdown-body blockquote { padding-left: 12px; border-left: 3px solid var(--accent); color: var(--muted); }
.markdown-body code { padding: .12em .32em; border-radius: 4px; color: var(--text); background: var(--code-bg); font: .88em/1.5 var(--font-mono); }
.markdown-body pre { max-width: 100%; padding: 12px; overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--code-bg); }
.markdown-body pre code { padding: 0; border: 0; background: transparent; }
.markdown-body table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.markdown-body th, .markdown-body td { padding: 7px 10px; border: 1px solid var(--line); text-align: left; }
.markdown-body th { background: var(--panel-2); }
.markdown-body hr { border: 0; border-top: 1px solid var(--line); }
.markdown-body img { max-width: 100%; border-radius: 6px; }
.tool-calls { width: min(100%, 680px); display: grid; gap: 6px; }
.tool-call { overflow: hidden; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.tool-call.open { border-color: var(--accent-border); }
.tool-call-summary { width: 100%; min-height: 46px; display: grid; grid-template-columns: 28px 1fr auto 18px; align-items: center; gap: 9px; padding: 7px 10px; border: 0; color: var(--text); background: transparent; text-align: left; cursor: pointer; }
.tool-call-summary:hover { background: var(--panel-2); }
.tool-call-icon { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 4px; color: var(--accent); background: var(--accent-soft); font-size: 13px; }
.tool-call-title small, .tool-call-title strong { display: block; }
.tool-call-title small { color: var(--muted); font-size: 10px; }
.tool-call-title strong { font: 600 12px/18px var(--font-mono); }
.tool-call-status { color: var(--muted); font-size: 11px; }
.tool-call-chevron { color: var(--muted); transition: transform .12s; }
.tool-call.open .tool-call-chevron { transform: rotate(180deg); }
.tool-call-details { display: grid; gap: 12px; padding: 12px; border-top: 1px solid var(--line); background: var(--panel-2); }
.tool-call-details > div > span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 11px; font-weight: 600; }
.tool-call-details pre, .tool-result { max-height: 300px; margin: 0; padding: 10px 11px; overflow: auto; border: 1px solid var(--line); border-radius: 4px; color: var(--text-soft); background: var(--code-bg); font: 12px/1.6 var(--font-mono); white-space: pre-wrap; overflow-wrap: anywhere; }

/* Composer and active plan */
.composer { position: relative; margin: 0 max(18px, calc((100% - 880px) / 2)) 18px; display: grid; grid-template-columns: 36px 1fr 36px; padding: 9px 10px 5px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--panel); box-shadow: var(--shadow-16); }
.composer:focus-within { border-color: var(--accent); border-bottom-width: 2px; }
.composer textarea { max-height: 180px; resize: none; padding: 6px 8px; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 14px; line-height: 1.6; }
.file-input { display: none; }
.attach, .send { width: 32px; height: 32px; align-self: end; display: grid; place-items: center; border-radius: 4px; cursor: pointer; }
.attach { border: 0; color: var(--text-soft); background: transparent; }
.attach:hover { background: var(--panel-2); }
.send { border: 1px solid var(--accent); color: var(--accent-contrast); background: var(--accent); }
.send:hover:not(:disabled) { border-color: var(--accent-hover); background: var(--accent-hover); }
.send:active:not(:disabled) { border-color: var(--accent-pressed); background: var(--accent-pressed); }
.composer small { grid-column: 1 / -1; display: flex; justify-content: space-between; padding: 3px 7px 0; color: var(--muted); font-size: 10px; }
.composer small .online { color: var(--signal); }
.pending-uploads { grid-column: 1 / -1; display: flex; gap: 7px; padding: 2px 3px 8px; overflow-x: auto; }
.pending-upload { min-width: 170px; max-width: 260px; display: grid; grid-template-columns: 24px minmax(0, 1fr) 22px; align-items: center; gap: 6px; padding: 7px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); }
.pending-upload.error { border-color: var(--danger); }
.pending-upload strong, .pending-upload small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.pending-upload strong { font-size: 11px; }
.pending-upload small { color: var(--muted); font-size: 10px; }
.pending-upload button { border: 0; color: var(--muted); background: none; cursor: pointer; }
.command-menu { position: absolute; z-index: 40; right: 0; bottom: calc(100% + 8px); left: 0; max-height: min(360px, 48vh); overflow-y: auto; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-acrylic); backdrop-filter: var(--acrylic-blur); -webkit-backdrop-filter: var(--acrylic-blur); box-shadow: var(--shadow-16); }
.command-menu-heading { position: sticky; z-index: 1; top: -6px; display: flex; justify-content: space-between; gap: 16px; padding: 8px 9px; color: var(--muted); background: var(--surface-acrylic); font-size: 11px; }
.command-menu-heading kbd { color: var(--muted); font: inherit; }
.command-menu button { width: 100%; display: grid; grid-template-columns: minmax(100px, auto) 1fr; gap: 14px; padding: 8px 9px; border: 0; border-radius: 4px; color: var(--text); background: transparent; text-align: left; cursor: pointer; }
.command-menu button:hover, .command-menu button.selected { background: var(--accent-soft); }
.command-menu code { color: var(--accent); font: 600 12px/1.4 var(--font-mono); }
.command-menu button span { color: var(--text-soft); font-size: 12px; }
.todo-panel { display: none; min-width: 0; overflow: hidden; border-left: 1px solid var(--line); background: var(--panel); }
.todo-open .todo-panel { display: flex; flex-direction: column; }
.todo-heading { min-height: 74px; display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 14px 14px 11px 16px; border-bottom: 1px solid var(--line); }
.todo-heading small, .todo-heading strong { display: block; }
.todo-heading small { margin-bottom: 4px; color: var(--muted); font-size: 11px; }
.todo-heading strong { font-size: 13px; line-height: 18px; }
.todo-progress { height: 3px; background: var(--panel-2); }
.todo-progress span { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.todo-summary { display: flex; justify-content: space-between; padding: 10px 16px; color: var(--muted); font-size: 11px; }
.todo-items { min-height: 0; overflow-y: auto; padding: 3px 10px 18px; }
.todo-item { display: grid; grid-template-columns: 22px 1fr; gap: 8px; padding: 9px 7px; border-radius: 6px; color: var(--text-soft); }
.todo-item + .todo-item { margin-top: 2px; }
.todo-item.running { color: var(--text); background: var(--accent-soft); }
.todo-item.blocked { background: var(--danger-soft); }
.todo-item.done { color: var(--muted); }
.todo-icon { width: 20px; height: 20px; display: grid; place-items: center; border: 1px solid var(--line-strong); border-radius: 50%; font-size: 11px; }
.todo-item.running .todo-icon { border-color: var(--accent); color: var(--accent); }
.todo-item.blocked .todo-icon { border-color: var(--danger); color: var(--danger); }
.todo-item.done .todo-icon { color: var(--signal); }
.todo-item strong, .todo-item small { display: block; }
.todo-item strong { font-size: 12px; line-height: 18px; }
.todo-item small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.todo-item p { margin: 5px 0 0; color: var(--text-soft); font-size: 11px; line-height: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Management pages */
.content-page { overflow: auto; padding: calc(var(--topbar-h) + 24px) 28px 40px; scroll-padding-top: calc(var(--topbar-h) + 16px); }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.filters { align-items: center; }
.cards { display: grid; gap: 10px; }
.card, .panel, .metric { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow-2); }
.card { padding: 15px 17px; transition: border-color .15s ease, box-shadow .15s ease; }
.card:hover { border-color: var(--line-strong); box-shadow: var(--shadow-8); }
.card-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.card h3 { margin: 0 0 6px; font-size: 14px; }
.card p { margin: 5px 0; color: var(--text-soft); font-size: 13px; line-height: 20px; white-space: pre-wrap; }
.meta { display: flex; flex-wrap: wrap; gap: 12px; color: var(--muted); font-size: 11px; }
.badge { display: inline-flex; align-items: center; min-height: 22px; padding: 2px 8px; border-radius: 4px; color: var(--text-soft); background: var(--panel-2); font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge.ok { color: var(--signal); background: var(--signal-soft); }
.badge.fail { color: var(--danger); background: var(--danger-soft); }
.badge.run { color: var(--warning); background: var(--warning-soft); }
.details { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.run-row + .run-row { margin-top: 7px; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.metric { padding: 15px 16px; }
.metric b { display: block; font: 600 28px/36px "Segoe UI Variable Display", var(--font-ui); font-variant-numeric: tabular-nums; }
.metric small { color: var(--muted); }
.memory-content { font-size: 14px !important; }
.memory-key { color: var(--accent); font-family: var(--font-mono); }
.log-view { min-height: calc(100vh - 190px); margin: 0; padding: 14px 16px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; color: var(--text-soft); background: var(--code-bg); font: 12px/1.7 var(--font-mono); white-space: pre-wrap; }
.log-meta { margin: -8px 0 8px; color: var(--muted); font-size: 12px; }
.switch-label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; cursor: pointer; }
.switch { width: 40px; height: 20px; padding: 2px; border: 0; border-radius: 10px; background: var(--line-strong); cursor: pointer; }
.switch[data-state="checked"] { background: var(--accent); }
.switch-thumb { display: block; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-2); transition: transform .12s; }
.switch-thumb[data-state="checked"] { transform: translateX(20px); }
.settings-grid { display: grid; grid-template-columns: 168px minmax(0, 1fr); gap: 18px; }
.settings-nav { display: flex; flex-direction: column; gap: 2px; }
.editor-card { overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); box-shadow: var(--shadow-2); }
.editor-head { min-height: 62px; display: flex; align-items: center; justify-content: space-between; padding: 0 15px; border-bottom: 1px solid var(--line); }
.editor-head strong, .editor-head small { display: block; }
.editor-head small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.editor-card textarea { width: 100%; height: calc(100vh - 275px); min-height: 420px; display: block; resize: vertical; padding: 18px; border: 0; outline: 0; color: var(--text); background: var(--code-bg); font: 13px/1.65 var(--font-mono); tab-size: 2; }
.notice { padding: 10px 15px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.cap { display: inline-flex; align-items: center; gap: 5px; padding: 3px 7px; border-radius: 4px; font-size: 10px; font-weight: 600; }
.cap.signal { border: 1px solid var(--signal-border); color: var(--signal); background: var(--signal-soft); }
.cap.accent { border: 1px solid var(--accent-border); color: var(--accent); background: var(--accent-soft); }
.cap.danger { border: 1px solid var(--danger-border); color: var(--danger); background: var(--danger-soft); }
.cap.info { border: 1px solid var(--info-border); color: var(--info); background: var(--info-soft); }
.label-caps { color: var(--muted); font-size: 11px; font-weight: 600; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
code { color: var(--accent); }
.loading, .empty-card { padding: 50px; color: var(--muted); text-align: center; }
.empty-card.compact { padding: 24px 8px; }
.error-text { color: var(--danger) !important; }
#toast { position: fixed; z-index: 100; right: 20px; bottom: 20px; max-width: min(420px, calc(100vw - 40px)); padding: 11px 14px; border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 6px; color: var(--text); background: var(--overlay); box-shadow: var(--shadow-16); font-size: 13px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .16s, transform .16s; }
#toast.show { opacity: 1; transform: none; }
#toast.error { border-left-color: var(--danger); color: var(--danger); }

@keyframes pulse { 50% { opacity: .3; } }
@keyframes message-in { from { opacity: 0; transform: translateY(4px); } }
@keyframes page-in { from { opacity: 0; } }
@keyframes spine-pulse { 50% { opacity: .35; } }
.pulse-dot { width: 7px; height: 7px; display: inline-block; border-radius: 50%; }
.pulse-dot.active { background: var(--accent); animation: spine-pulse 1.5s ease-in-out infinite; }
.pulse-dot.idle { background: var(--signal); }

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

@media (max-width: 960px) {
  .theme-toggle { min-width: 32px; width: 32px; padding: 0; }
  .theme-toggle span { display: none; }
  .page-heading { min-width: 150px; }
}

@media (max-width: 800px) {
  :root { --topbar-h: 62px; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 248px; transform: translateX(-100%); transition: transform .16s ease; box-shadow: var(--shadow-16); }
  .sidebar.open { transform: none; }
  .nav-scrim { position: fixed; z-index: 25; inset: 0; display: block; border: 0; background: rgb(0 0 0 / 42%); }
  .topbar { padding: 0 14px; }
  .topbar .menu { display: inline-grid; }
  .page-heading p { display: none; }
  .chat-layout, .chat-layout.todo-open { grid-template-columns: 1fr; }
  .sessions-panel { display: none; }
  .todo-open .todo-panel { position: fixed; z-index: 20; top: var(--topbar-h); right: 0; bottom: 0; width: min(340px, 92vw); background: var(--surface-acrylic); backdrop-filter: var(--acrylic-blur); -webkit-backdrop-filter: var(--acrylic-blur); box-shadow: var(--shadow-16); }
  .content-page { padding: calc(var(--topbar-h) + 18px) 16px 32px; }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-nav { flex-direction: row; overflow-x: auto; }
  .metrics { grid-template-columns: 1fr; }
  .filters { align-items: stretch; flex-wrap: wrap; }
  .grow { max-width: none; width: 100%; flex-basis: 100%; }
  .message-content { max-width: 90%; }
  .messages { padding-right: 16px; padding-left: 16px; }
  .composer { margin-right: 12px; margin-left: 12px; }
}

@media (max-width: 520px) {
  .topbar h1 { font-size: 18px; }
  .page-heading { min-width: 0; }
  .messages { padding-top: 16px; }
  .message-content { max-width: calc(100% - 38px); }
  .toolbar { align-items: stretch; flex-wrap: wrap; }
  .toolbar .tabs { width: 100%; overflow-x: auto; }
  .card-row { gap: 10px; }
}

@media (prefers-reduced-transparency: reduce) {
  .sidebar { background: var(--sidebar); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .topbar { background: var(--panel); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .command-menu, .command-menu-heading, .tooltip { background: var(--overlay); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .todo-open .todo-panel { background: var(--panel); backdrop-filter: none; -webkit-backdrop-filter: none; }
}
