/* AI Studio — Intelligent Workspace design system (ADR-054, docs/DESIGN_SYSTEM.md).
 * Three areas: navigation sidebar, conversation, contextual panel. White surfaces, thin
 * borders, 4/8 px spacing. Blue is for navigation and ordinary actions, violet is reserved
 * for agents and orchestration, green only for success, red for errors and destruction.
 * CSS stays free of gradient functions; the Agent Core symbol is drawn in SVG.
 */

@font-face {
  font-family: "Inter";
  src: url("../fonts/InterVariable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

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

@font-face {
  font-family: "JetBrains Mono";
  src: url("../fonts/JetBrainsMono-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

/* ==========================================================================
   1. Tokens
   ========================================================================== */
:root {
  color-scheme: dark;
  --bg-canvas: #0f1220;
  --bg-sidebar: #121524;
  --bg-surface: #171b2b;
  --bg-surface-subtle: #202538;
  --bg-elevated: #1c2134;
  --text-primary: #eceef8;
  --text-secondary: #c2c7da;
  --text-muted: #9aa1b9;
  --text-faint: #6d7591;
  --accent-primary: #4766f0;
  --accent-primary-hover: #3a57dc;
  --accent-on: #ffffff;
  --accent-text: #a5b8ff;
  --accent-soft: #212c55;
  --agent-primary: #7c57ec;
  --agent-primary-hover: #6b45dd;
  --agent-secondary: #9775fa;
  --agent-text: #c3b1ff;
  --agent-soft: #2b2250;
  --border-default: #2a3047;
  --border-strong: #454d6b;
  --status-success: #5fd3a0;
  --status-success-solid: #169b62;
  --status-success-soft: #12302a;
  --status-warning: #f0b45c;
  --status-warning-soft: #33270f;
  --status-danger: #ff8f98;
  --status-danger-soft: #3b1d27;
  --focus-ring: #a5b8ff;
  --code-keyword: #c3b1ff;
  --code-string: #7fd6a8;
  --code-number: #f0b45c;
  --code-name: #8fb8ff;
  --code-comment: #9aa1b9;
  --hover-veil: rgba(236, 238, 248, 0.06);
  --active-veil: rgba(236, 238, 248, 0.1);
  --scrim: rgba(5, 7, 14, 0.66);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-popover: 0 12px 32px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.35);
  --shadow-modal: 0 28px 80px rgba(0, 0, 0, 0.62), 0 4px 14px rgba(0, 0, 0, 0.4);

  --font-sans: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "SF Pro Text", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", ui-monospace, SFMono-Regular, Consolas, monospace;
  /* Typography (docs/DESIGN_SYSTEM.md, section 3) */
  --text-xs: 13px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-reading: 15px;
  --text-section: 16px;
  --text-technical: 13px;
  --text-page: 24px;
  --text-hero: 32px;
  --line-reading: 1.65;
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;

  --topbar-height: 52px;
  --sidebar-width: 252px;
  --sidebar-rail: 68px;
  --chat-column: 900px;
  /* The prompt field is narrower than the thread: 760 px plus the side padding. */
  --composer-width: 900px;
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --motion: 0.2s;
  --z-sidebar: 40;
  --z-header: 30;
  --z-popover: 60;
  --z-toast: 90;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg-canvas: #f8f9fc;
  --bg-sidebar: #f6f7fb;
  --bg-surface: #ffffff;
  --bg-surface-subtle: #f1f3f9;
  --bg-elevated: #ffffff;
  --text-primary: #171b2e;
  --text-secondary: #475069;
  --text-muted: #5f677d;
  --text-faint: #98a2b3;
  --accent-primary: #3459ed;
  --accent-primary-hover: #2548d8;
  --accent-on: #ffffff;
  --accent-text: #2548d8;
  --accent-soft: #edf2ff;
  --agent-primary: #7047eb;
  --agent-primary-hover: #5d35d6;
  --agent-secondary: #9775fa;
  --agent-text: #5b34d6;
  --agent-soft: #f3efff;
  --border-default: #e4e7ef;
  --border-strong: #c6ccda;
  --status-success: #0e7448;
  --status-success-solid: #169b62;
  --status-success-soft: #e6f6ee;
  --status-warning: #9a5304;
  --status-warning-soft: #fdf2e0;
  --status-danger: #bd2334;
  --status-danger-soft: #fdecee;
  --focus-ring: #3459ed;
  --code-keyword: #6d28d9;
  --code-string: #0b6b41;
  --code-number: #9a4a04;
  --code-name: #1d4ed8;
  --code-comment: #5f677d;
  --hover-veil: rgba(23, 27, 46, 0.045);
  --active-veil: rgba(23, 27, 46, 0.08);
  --scrim: rgba(23, 27, 46, 0.34);
  --shadow-card: 0 1px 2px rgba(23, 27, 46, 0.04);
  --shadow-popover: 0 12px 32px rgba(23, 27, 46, 0.12), 0 2px 6px rgba(23, 27, 46, 0.06);
  --shadow-modal: 0 28px 80px rgba(23, 27, 46, 0.2), 0 4px 14px rgba(23, 27, 46, 0.1);
}

@media (prefers-color-scheme: light) {
  :root[data-theme="system"] {
    color-scheme: light;
    --bg-canvas: #f8f9fc;
    --bg-sidebar: #f6f7fb;
    --bg-surface: #ffffff;
    --bg-surface-subtle: #f1f3f9;
    --bg-elevated: #ffffff;
    --text-primary: #171b2e;
    --text-secondary: #475069;
    --text-muted: #5f677d;
    --text-faint: #98a2b3;
    --accent-primary: #3459ed;
    --accent-primary-hover: #2548d8;
    --accent-on: #ffffff;
    --accent-text: #2548d8;
    --accent-soft: #edf2ff;
    --agent-primary: #7047eb;
    --agent-primary-hover: #5d35d6;
    --agent-secondary: #9775fa;
    --agent-text: #5b34d6;
    --agent-soft: #f3efff;
    --border-default: #e4e7ef;
    --border-strong: #c6ccda;
    --status-success: #0e7448;
    --status-success-solid: #169b62;
    --status-success-soft: #e6f6ee;
    --status-warning: #9a5304;
    --status-warning-soft: #fdf2e0;
    --status-danger: #bd2334;
    --status-danger-soft: #fdecee;
    --focus-ring: #3459ed;
    --code-keyword: #6d28d9;
    --code-string: #0b6b41;
    --code-number: #9a4a04;
    --code-name: #1d4ed8;
    --code-comment: #5f677d;
    --hover-veil: rgba(23, 27, 46, 0.045);
    --active-veil: rgba(23, 27, 46, 0.08);
    --scrim: rgba(23, 27, 46, 0.34);
    --shadow-card: 0 1px 2px rgba(23, 27, 46, 0.04);
    --shadow-popover: 0 12px 32px rgba(23, 27, 46, 0.12), 0 2px 6px rgba(23, 27, 46, 0.06);
    --shadow-modal: 0 28px 80px rgba(23, 27, 46, 0.2), 0 4px 14px rgba(23, 27, 46, 0.1);
  }
}


/* ==========================================================================
   2. Base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
[x-cloak] { display: none !important; }
[hidden] { display: none !important; }

html, body { max-width: 100%; overflow-x: clip; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-synthesis-weight: none;
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-canvas);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
body.scroll-locked { overflow: hidden; }

::selection { background: rgba(112, 71, 235, 0.24); }

h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.25; font-weight: var(--weight-semibold); letter-spacing: -0.01em; text-wrap: balance; }
h1 { font-size: var(--text-page); }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
h4 { font-size: 14px; }
p { margin: 0 0 10px; }
p:last-child { margin-bottom: 0; }

a { color: var(--accent-text); text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 3px; transition: text-decoration-color 0.15s ease, color 0.15s ease; }
a:hover { text-decoration-color: currentColor; }

:is(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}
:focus:not(:focus-visible) { outline: none; }

code, pre, kbd, samp, .font-mono { font-family: var(--font-mono); font-variant-ligatures: none; }
.tabular-nums { font-variant-numeric: tabular-nums; }

hr { border: 0; border-top: 1px solid var(--border-default); margin: 16px 0; }
img { max-width: 100%; height: auto; }

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background-color: var(--border-strong); }
*::-webkit-scrollbar-track { background: transparent; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: fixed; left: -9999px; top: 8px; z-index: 100;
  padding: 10px 14px; background: var(--bg-surface); color: var(--text-primary);
  border: 2px solid var(--focus-ring); border-radius: var(--radius-sm); text-decoration: none;
}
.skip-link:focus { left: 8px; }

/* ==========================================================================
   3. Floating surfaces (menus, dialogs)
   ========================================================================== */
.glass-panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-popover);
}
.app-modal::backdrop { background: var(--scrim); }
@supports (backdrop-filter: blur(4px)) {
  .app-modal::backdrop { -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
}

/* ==========================================================================
   4. App shell: navigation sidebar, mobile bar, main column
   ========================================================================== */
.app-frame { display: flex; flex-direction: column; height: 100vh; height: 100dvh; min-height: 0; }
.app-shell { position: relative; display: flex; flex: 1 1 auto; width: 100%; max-width: 100%; min-height: 0; }
.app-shell.is-guest { height: 100%; }
.app-main-column { flex: 1; min-width: 0; min-height: 0; height: 100%; display: flex; flex-direction: column; background: var(--bg-canvas); }

.mobile-bar {
  display: none; position: relative; z-index: var(--z-header); flex-shrink: 0; align-items: center; justify-content: space-between; gap: var(--space-2);
  height: var(--topbar-height); padding: 0 var(--space-2); background: var(--bg-sidebar); border-bottom: 1px solid var(--border-default);
}
.mobile-bar form { margin: 0; }

.logo { display: block; flex-shrink: 0; width: 32px; height: 32px; }
.logo-avatar { width: 32px; height: 32px; }
.logo-md { width: 72px; height: 72px; }
.logo-lg { width: clamp(120px, 18vh, 168px); height: clamp(120px, 18vh, 168px); margin: 0 auto; }
.brand { display: inline-flex; align-items: center; gap: 10px; min-width: 0; color: var(--text-primary); text-decoration: none; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.brand-tagline { overflow: hidden; text-overflow: ellipsis; font-size: 11px; color: var(--text-muted); }

/* Sidebar */
.app-sidebar {
  position: relative; z-index: 12; width: var(--sidebar-width); flex-shrink: 0; display: flex; flex-direction: column; gap: var(--space-2);
  padding: var(--space-3) var(--space-2) var(--space-2); background: var(--bg-sidebar); border-right: 1px solid var(--border-default);
  min-height: 0; transition: width var(--motion) var(--ease), transform var(--motion) var(--ease);
}
.app-sidebar-backdrop { display: none; }
.sidebar-brand { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); min-height: 40px; padding: 0 var(--space-1) 0 var(--space-2); }
.sidebar-top { display: flex; flex-direction: column; gap: 6px; padding: 0 var(--space-1); }
.sidebar-top form { margin: 0; }
.chat-new-btn { width: 100%; justify-content: flex-start; min-height: 40px; }
.sidebar-search {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 36px; padding: 0 8px 0 10px; border: 1px solid var(--border-default);
  border-radius: var(--radius-sm); background: var(--bg-surface); color: var(--text-muted); font: inherit; font-size: 13px; text-align: left; cursor: pointer;
}
.sidebar-search:hover { border-color: var(--border-strong); color: var(--text-primary); }
.sidebar-search .kbd { margin-left: auto; }

.sidebar-scroll { flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto; padding: 0 var(--space-1) var(--space-2); display: flex; flex-direction: column; gap: var(--space-1); }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-projects { display: flex; flex-direction: column; gap: 1px; margin-top: var(--space-2); padding-top: var(--space-2); border-top: 1px solid var(--border-default); }

.sidebar-project > summary {
  display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 6px 10px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; color: var(--text-secondary); cursor: pointer; list-style: none;
}
.sidebar-project > summary::-webkit-details-marker { display: none; }
.sidebar-project > summary:hover { background: var(--hover-veil); color: var(--text-primary); }
.sidebar-project[open] > summary { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.sidebar-project > summary .sidebar-project-chevron { margin-left: auto; transition: transform var(--motion) var(--ease); }
.sidebar-project[open] > summary .sidebar-project-chevron { transform: rotate(180deg); }
.sidebar-project-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-project-links { display: flex; flex-direction: column; gap: 1px; padding: 2px 0 4px var(--space-4); }

.sidebar-link {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 36px; padding: 6px 10px;
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-secondary);
  font: inherit; font-size: 14px; font-weight: 500; text-align: left; text-decoration: none; cursor: pointer;
  transition: background-color var(--motion) ease, color var(--motion) ease;
}
.sidebar-link:hover { background: var(--hover-veil); color: var(--text-primary); text-decoration: none; }
.sidebar-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.sidebar-link.is-agent[aria-current="page"] { background: var(--agent-soft); color: var(--agent-text); }

.sidebar-history { display: flex; flex-direction: column; gap: 1px; margin-top: var(--space-2); padding-top: var(--space-2); border-top: 1px solid var(--border-default); }
.sidebar-group-label { margin: var(--space-3) 10px 3px; font-size: 13px; font-weight: 600; color: var(--text-muted); letter-spacing: 0; }
.sidebar-section-label { margin: var(--space-1) 10px 3px; font-size: 13px; font-weight: 600; color: var(--text-muted); letter-spacing: 0; }
.sidebar-empty { padding: 10px; color: var(--text-muted); font-size: 13px; }
.sidebar-filter-note { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; font-size: 13px; color: var(--text-muted); }
.sidebar-archive { margin-bottom: var(--space-1); }
.conv-row { display: flex; align-items: stretch; min-width: 0; border-radius: var(--radius-sm); }
.conv-row:hover, .conv-row:focus-within { background: var(--hover-veil); }
.conv-row:has(.conv-item.is-active, .conv-row-popover:popover-open) { background: var(--accent-soft); }
.conv-item {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--space-2); min-height: 34px; padding: 6px 10px;
  border-radius: var(--radius-sm); color: var(--text-secondary); font-size: 14px; line-height: 1.35; text-decoration: none;
}
.conv-item:hover { color: var(--text-primary); text-decoration: none; }
.conv-item.is-active { color: var(--accent-text); font-weight: 600; text-decoration: none; }
.conv-item-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item-flag { flex-shrink: 0; font-size: 11px; color: var(--text-muted); }
.conv-row-action.icon-btn { flex: 0 0 auto; align-self: center; width: 30px; height: 30px; opacity: 0; }
.conv-row:hover .conv-row-action, .conv-row:focus-within .conv-row-action, .conv-row:has(.conv-item.is-active) .conv-row-action { opacity: 1; }
@media (hover: none) { .conv-row-action.icon-btn { opacity: 1; } }
.conv-row-popover {
  position: fixed; width: min(240px, calc(100vw - 24px)); max-height: min(320px, calc(100dvh - 24px)); overflow: auto;
  padding: 6px; border-radius: var(--radius-md); color: var(--text-primary);
}
@supports (position-area: bottom span-left) {
  .conv-row-popover { inset: auto; margin: 4px 0; position-area: bottom span-left; position-try-fallbacks: flip-block; }
}
.conv-row-popover form { margin: 0; }

/* Sidebar footer: balance, notifications, theme and account */
.sidebar-footer { display: flex; flex-direction: column; gap: 6px; padding: var(--space-2) var(--space-1) 0; border-top: 1px solid var(--border-default); }
.sidebar-footer-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
/* Balance, theme and notifications share one row; a long balance pushes the tools down. */
.sidebar-footer-tools { flex-wrap: wrap; }
.sidebar-tools { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.sidebar-bell { position: relative; }
.sidebar-bell-dot { position: absolute; top: 6px; right: 7px; width: 9px; height: 9px; border: 2px solid var(--bg-sidebar); border-radius: 50%; background: var(--accent-primary); }
.theme-switch { display: inline-flex; padding: 2px; gap: 2px; border: 1px solid var(--border-default); border-radius: 999px; background: var(--bg-surface); }
.theme-switch button { display: grid; place-items: center; width: 28px; height: 28px; padding: 0; border: 1px solid transparent; border-radius: 999px; background: transparent; color: var(--text-muted); cursor: pointer; }
.theme-switch button[aria-pressed="true"] { border-color: var(--accent-primary); background: var(--accent-soft); color: var(--accent-text); }

/* Avatar and account menu (sidebar footer) */
.account-menu { position: relative; flex: 1 1 auto; min-width: 0; }
.account-trigger { display: flex; align-items: center; gap: 10px; width: 100%; min-width: 0; padding: 5px 6px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-primary); font: inherit; text-align: left; cursor: pointer; }
.account-trigger:hover { background: var(--hover-veil); }
.account-trigger .account-menu-id strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 600; }
.avatar {
  display: inline-grid; place-items: center; flex-shrink: 0; width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-primary); color: var(--accent-on); font-size: 13px; font-weight: 700;
}
.account-menu-panel {
  position: absolute; left: 0; bottom: calc(100% + 8px); z-index: var(--z-popover); width: min(288px, calc(100vw - 24px));
  padding: 6px; border-radius: var(--radius-lg); max-height: min(70vh, 600px); overflow-y: auto;
  animation: pop-in 0.16s var(--ease); transform-origin: bottom left;
}
.account-menu-head { display: flex; align-items: center; gap: 10px; padding: 8px 8px 10px; }
.account-menu-id { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.account-menu-id strong { font-size: 14px; }
.account-menu-id .caption { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-menu-section { margin: 0; padding: 4px 0; border-top: 1px solid var(--border-default); }
.account-menu-label { display: block; padding: 6px 10px 4px; font-size: 13px; color: var(--text-muted); }

/* Collapsed navigation rail (desktop) */
@media (min-width: 1024px) {
  .app-sidebar.is-collapsed { width: var(--sidebar-rail); }
  .app-sidebar.is-collapsed :is(.brand, .sidebar-label, .sidebar-search .kbd, .sidebar-projects, .sidebar-history, .theme-switch, .balance-pill, .account-menu-id, .sidebar-settings) { display: none; }
  .app-sidebar.is-collapsed .sidebar-brand { justify-content: center; padding: 0; }
  .app-sidebar.is-collapsed :is(.sidebar-link, .sidebar-search, .chat-new-btn, .account-trigger) { justify-content: center; padding-inline: 0; }
  .app-sidebar.is-collapsed .sidebar-footer-row, .app-sidebar.is-collapsed .sidebar-tools { flex-direction: column; }
  .app-sidebar.is-collapsed .sidebar-tools { margin-left: 0; }
  .app-sidebar.is-collapsed .sidebar-collapse .nav-icon { transform: rotate(180deg); }
}

/* Menus / dropdowns */
.menu-wrap { position: relative; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: var(--z-popover); min-width: 240px; padding: 6px;
  border-radius: var(--radius-lg); animation: pop-in 0.16s var(--ease); transform-origin: top right;
}
.dropdown form, .account-menu-section form { margin: 0; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 36px; padding: 7px 10px; border: 0;
  border-radius: var(--radius-xs); background: transparent; color: var(--text-primary); font: inherit; font-size: 14px;
  text-align: left; text-decoration: none; cursor: pointer;
}
.menu-item:hover { background: var(--hover-veil); text-decoration: none; }
.menu-item .nav-icon { color: var(--text-muted); }
.menu-item-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-item-meta { font-size: 13px; color: var(--text-muted); }
.menu-item.is-selected { background: var(--accent-soft); }
.menu-item-danger, .menu-item-danger .nav-icon { color: var(--status-danger); }
.menu-item-danger:hover { background: var(--status-danger-soft); }
.menu-sep { height: 1px; margin: 5px 4px; background: var(--border-default); }
@keyframes pop-in { from { opacity: 0; transform: scale(0.98) translateY(-4px); } to { opacity: 1; transform: none; } }

/* Header (guests only) */
.app-header {
  position: sticky; top: 0; z-index: var(--z-header); flex-shrink: 0; height: 56px; padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--bg-surface); border-bottom: 1px solid var(--border-default);
}
.app-header-group { display: flex; align-items: center; gap: 8px; min-width: 0; }
.app-header-group:first-child { flex: 1 1 0; }
.app-header-group:last-child { flex: 0 0 auto; }
.app-header-title { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.app-content {
  position: relative; flex: 1 1 auto; min-height: 0; width: 100%; max-width: none; margin: 0 auto;
  padding: 24px 24px 64px; overflow-y: auto; -webkit-overflow-scrolling: touch; scroll-behavior: smooth;
}
.app-content > * { max-width: 1180px; margin-left: auto; margin-right: auto; }
.app-content > * + * { margin-top: 16px; }
.app-content-narrow > * { max-width: 680px; }
.app-content-fill { max-width: none; padding: 0; display: flex; flex-direction: column; overflow: hidden; }
.app-content-fill > * { max-width: none; margin: 0; }
body.scroll-locked .app-content { overflow: hidden; }
.app-content:focus { outline: none; }

/* Sub-navigation of a product area */
.section-tabs { display: flex; gap: 4px; width: fit-content; max-width: 100%; overflow-x: auto; padding: 4px; border: 1px solid var(--border-default); border-radius: var(--radius-lg); background: var(--bg-surface); box-shadow: var(--shadow-card); scrollbar-width: none; }
.section-tabs::-webkit-scrollbar { display: none; }
.app-content > .section-tabs { margin-left: auto; margin-right: auto; width: 100%; max-width: 1180px; }
.section-tab { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 14px; flex-shrink: 0; border-radius: var(--radius-sm); color: var(--text-secondary); font-weight: var(--weight-medium); text-decoration: none; white-space: nowrap; transition: background-color var(--motion) ease, color var(--motion) ease; }
.section-tab:hover { background: var(--hover-veil); color: var(--text-primary); text-decoration: none; }
.section-tab[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: var(--weight-semibold); }
/* On a phone the short agent tab set wraps, so no tab is scrolled out of sight. */
@media (max-width: 767px) {
  .section-tabs-wrap { flex-wrap: wrap; }
  .section-tabs-wrap .section-tab { flex: 1 1 auto; justify-content: center; padding: 0 10px; }
}

.hide-xs { display: none; }
@media (min-width: 640px) { .hide-xs { display: inline-flex; } }
.hide-sm { display: none; }
@media (min-width: 900px) { .hide-sm { display: inline-flex; } }

/* Tablets and phones: the sidebar becomes a drawer opened from the mobile bar. */
@media (max-width: 1023px) {
  .mobile-bar { display: flex; }
  .app-sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: var(--z-sidebar); width: min(304px, calc(100vw - 48px));
    transform: translateX(-105%); visibility: hidden; transition: transform var(--motion) var(--ease), visibility var(--motion);
  }
  .app-sidebar.is-open { transform: translateX(0); visibility: visible; box-shadow: var(--shadow-modal); }
  .app-sidebar-backdrop.is-open { display: block; position: fixed; inset: 0; z-index: calc(var(--z-sidebar) - 1); background: var(--scrim); animation: fade-in var(--motion) ease; }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ==========================================================================
   5. Icons, icon buttons, kbd, balance
   ========================================================================== */
.nav-icon { flex: 0 0 auto; width: 20px; height: 20px; color: currentColor; }
.nav-icon-sm { width: 16px; height: 16px; }

.icon-btn {
  display: inline-grid; place-items: center; flex-shrink: 0; width: 36px; height: 36px; padding: 0; border: 0;
  border-radius: var(--radius-sm); background: transparent; color: var(--text-secondary); cursor: pointer;
  text-decoration: none; transition: background-color 0.15s ease, color 0.15s ease;
}
.icon-btn:hover { background: var(--hover-veil); color: var(--text-primary); text-decoration: none; }
.icon-btn-sm { width: 30px; height: 30px; border-radius: var(--radius-xs); }
.icon-btn[data-copy-state="copied"] { color: var(--status-success); }

.kbd {
  display: inline-flex; align-items: center; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--border-default);
  background: var(--bg-surface-subtle); font-family: var(--font-sans); font-size: 11px; font-weight: 500; color: var(--text-muted); white-space: nowrap;
}

.balance-pill {
  display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-default); background: var(--bg-surface); color: var(--text-primary);
  font-size: 13px; font-weight: 600; white-space: nowrap; text-decoration: none;
}
.balance-pill:hover { border-color: var(--border-strong); text-decoration: none; }
.balance-pill .nav-icon { color: var(--text-muted); }

/* ==========================================================================
   6. Buttons, chips, badges, tags
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 36px; padding: 7px 14px;
  border-radius: var(--radius-sm); border: 1px solid transparent; font-family: inherit; font-size: 14px; font-weight: 600;
  line-height: 1.2; text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn:hover { text-decoration: none; }
.btn-sm { min-height: 32px; padding: 5px 12px; font-size: 13px; }
.btn-xs { min-height: 26px; padding: 3px 9px; font-size: 13px; }
.btn-lg { min-height: 44px; padding: 10px 22px; font-size: 15px; }
.btn-primary { background: var(--accent-primary); color: var(--accent-on); }
.btn-primary:hover:not(:disabled) { background: var(--accent-primary-hover); color: var(--accent-on); }
.btn-agent { background: var(--agent-primary); color: var(--accent-on); }
.btn-agent:hover:not(:disabled) { background: var(--agent-primary-hover); color: var(--accent-on); }
.btn-secondary { background: var(--bg-surface); color: var(--text-primary); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-surface-subtle); color: var(--text-primary); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--hover-veil); color: var(--text-primary); }
.btn-danger { background: var(--bg-surface); color: var(--status-danger); border-color: var(--status-danger); }
.btn-danger:hover:not(:disabled) { background: var(--status-danger-soft); }
.btn-danger-solid { background: var(--status-danger); color: var(--bg-surface); }
.btn-danger-solid:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 4px 12px; border-radius: 999px;
  border: 1px solid var(--border-default); background: var(--bg-surface); color: var(--text-secondary); font: inherit;
  font-size: 13px; cursor: pointer; white-space: nowrap;
}
.chip:hover { border-color: var(--border-strong); color: var(--text-primary); }
.chip.is-active { background: var(--accent-soft); border-color: var(--accent-primary); color: var(--accent-text); font-weight: 600; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 13px; font-weight: 600;
  line-height: 1.5; background: var(--accent-soft); color: var(--accent-text); white-space: nowrap;
}
.badge-neutral { background: var(--bg-surface-subtle); color: var(--text-secondary); }
.badge-success { background: var(--status-success-soft); color: var(--status-success); }
.badge-warning { background: var(--status-warning-soft); color: var(--status-warning); }
.badge-danger { background: var(--status-danger-soft); color: var(--status-danger); }

.tag {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: var(--radius-xs);
  background: var(--bg-surface-subtle); font-size: 13px; color: var(--text-secondary); white-space: nowrap;
}
.tag-warning { color: var(--status-warning); background: var(--status-warning-soft); }
.tag-price { font-family: var(--font-mono); font-size: 12px; white-space: normal; }

/* ==========================================================================
   7. Typography helpers & layout utilities
   ========================================================================== */
.page-title { margin: 0 0 6px; font-size: var(--text-page); line-height: 1.25; font-weight: var(--weight-semibold); letter-spacing: -0.01em; }
.section-title { margin: 0 0 10px; font-size: 16px; line-height: 1.35; font-weight: 700; }
.card-title { margin: 0 0 6px; font-size: 15px; line-height: 1.4; font-weight: 600; }
.muted { color: var(--text-secondary); font-size: 14px; margin: 0; }
.caption { color: var(--text-muted); font-size: 13px; }
.error-code { font-size: 64px; font-weight: 700; line-height: 1; letter-spacing: -0.01em; color: var(--text-muted); margin: 0 0 12px; }
.bullet-list, .ordered-list { margin: 8px 0 0; padding-left: 20px; color: var(--text-secondary); font-size: 14px; }
.bullet-list li, .ordered-list li { margin-bottom: 6px; }
.bullet-list li::marker, .ordered-list li::marker { color: var(--accent-text); font-weight: 600; }

.stack-xs { display: flex; flex-direction: column; gap: 4px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.stack-md { display: flex; flex-direction: column; gap: 14px; }
.stack-lg { display: flex; flex-direction: column; gap: 20px; }
.row-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.inline-form { display: inline; margin: 0; }
.is-hidden { display: none !important; }

.grid-2, .grid-3 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
@media (min-width: 768px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1280px) { .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 768px) and (max-width: 1279px) {
  .grid-3 > :last-child:nth-child(odd) { grid-column: 1 / -1; }
}

/* ==========================================================================
   8. Cards & surfaces
   ========================================================================== */
.ui-card, .card {
  background: var(--bg-surface); border: 1px solid var(--border-default); border-radius: var(--radius-lg);
  padding: 18px 20px; box-shadow: var(--shadow-card); overflow-wrap: anywhere; min-width: 0;
}
.card + .card, .ui-card + .ui-card { margin-top: 0; }
.ui-card .ui-card, .card .ui-card, .card .card { box-shadow: none; }
.card > h1, .card > h2 { margin-bottom: 6px; }
.card > h1 + .muted, .card > h2 + .muted { margin-bottom: 16px; }
.ui-card-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding-bottom: 12px; margin-bottom: 14px; border-bottom: 1px solid var(--border-default);
}
.ui-card-footer { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; padding-top: 12px; margin-top: 14px; border-top: 1px solid var(--border-default); }

.section-hero { background: transparent; border: 0; padding: 0; box-shadow: none; }
.section-hero .ui-card-header { border-bottom: 0; margin-bottom: 0; padding-bottom: 4px; }
.section-hero .muted { max-width: 76ch; }

.stat-card {
  display: flex; flex-direction: column; gap: 4px; padding: 16px 18px; min-height: 108px; justify-content: center;
  border: 1px solid var(--border-default); border-radius: var(--radius-lg); background: var(--bg-surface); box-shadow: var(--shadow-card);
}
.stat-card-primary { border-color: var(--accent-primary); }
.stat-value { margin: 0; font-size: 26px; line-height: 1.15; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; color: var(--text-primary); }
.stat-card-primary .stat-value { font-size: clamp(28px, 2.8vw, 36px); }
.stat-hint { font-size: 13px; color: var(--text-muted); }
.wallet-summary { gap: 12px; }

.list-item { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; padding: 12px 0; border-bottom: 1px solid var(--border-default); }
.list-item:last-child { border-bottom: 0; }
.list-item form { margin: 0; }

/* ==========================================================================
   9. Forms
   ========================================================================== */
.field { margin-bottom: 14px; }
.field label, .ui-label, .field-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-primary); margin-bottom: 5px; }
.field-group { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-group .field-label { margin-bottom: 0; }

.ui-input, .ui-select, .ui-textarea, .field-input,
.field input[type="email"], .field input[type="password"], .field input[type="text"],
.field input[type="search"], .field input[type="number"], .field input[type="url"],
.field select, .field textarea,
.card input[type="text"], .card input[type="email"], .card input[type="password"],
.card input[type="number"], .card input[type="search"], .card input[type="url"],
.card select, .card textarea {
  width: 100%; min-height: 38px; padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--bg-surface); color: var(--text-primary); font-family: inherit; font-size: 14px; line-height: 1.45;
}
.ui-textarea, .field textarea, .card textarea, textarea.field-input { min-height: 88px; resize: vertical; }
:is(.ui-input, .ui-select, .ui-textarea, .field-input, .field input, .field select, .field textarea, .card input, .card select, .card textarea):hover { border-color: var(--text-muted); }
:is(.ui-input, .ui-select, .ui-textarea, .field-input, .field input, .field select, .field textarea, .card input, .card select, .card textarea):focus {
  outline: 2px solid var(--focus-ring); outline-offset: 0; border-color: var(--focus-ring);
}
::placeholder { color: var(--text-muted); opacity: 1; }
.ui-input[aria-invalid="true"], .ui-select[aria-invalid="true"] { border-color: var(--status-danger); }
.ui-input:disabled, .ui-select:disabled, .ui-textarea:disabled { opacity: 0.55; cursor: not-allowed; }
select.ui-select, .field select, .card select { appearance: auto; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent-primary); width: 16px; height: 16px; flex-shrink: 0; margin-top: 2px; }
input[type="file"] { font: inherit; font-size: 13px; color: var(--text-secondary); max-width: 100%; }
input[type="file"]::file-selector-button { margin-right: 10px; padding: 7px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--bg-surface); color: var(--text-primary); font: inherit; cursor: pointer; }

.ui-field-hint { margin: 2px 0 0; font-size: 13px; color: var(--text-muted); }
.ui-field-error { margin: 4px 0 0; font-size: 13px; color: var(--status-danger); }
.field .alert { margin: 6px 0 0; padding: 6px 10px; font-size: 13px; }

.checkbox-row {
  display: flex; align-items: flex-start; gap: 10px; padding: 11px 13px; margin-bottom: 8px; border: 1px solid var(--border-default);
  border-radius: var(--radius-sm); background: var(--bg-surface); font-size: 14px; cursor: pointer;
}
.checkbox-row:hover { border-color: var(--border-strong); }
.field label:has(input[type="checkbox"]) { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }

.input-with-icon { position: relative; flex: 1; min-width: 180px; }
.input-with-icon .nav-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.input-with-icon .ui-input, .input-with-icon input[type="search"], .input-with-icon input[type="text"] { padding-left: 38px; }

.advanced-settings { padding: 12px 0 0; border-top: 1px solid var(--border-default); }
.advanced-settings > summary { cursor: pointer; color: var(--text-secondary); font-size: 14px; list-style-position: inside; }
.advanced-settings[open] > summary { margin-bottom: 12px; color: var(--text-primary); }

/* ==========================================================================
   10. Alerts, states
   ========================================================================== */
.alert { padding: 11px 14px; margin-bottom: 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-default); background: var(--bg-surface-subtle); font-size: 14px; }
.alert-error, .alert-danger { border-color: var(--status-danger); background: var(--status-danger-soft); color: var(--status-danger); }
.alert-success { border-color: var(--status-success); background: var(--status-success-soft); color: var(--status-success); }
.alert-warning { border-color: var(--status-warning); background: var(--status-warning-soft); color: var(--status-warning); }
.alert p { margin: 0; }
.flash-data { display: none; }
.noscript-messages { position: fixed; top: 12px; right: 12px; z-index: var(--z-toast); max-width: 360px; }

.ui-state-box, .empty-state { padding: 24px 18px; text-align: center; border-radius: var(--radius-md); border: 1px dashed var(--border-strong); background: transparent; color: var(--text-secondary); }
.ui-state-box.is-error { border-style: solid; border-color: var(--status-danger); background: var(--status-danger-soft); }

.ui-spinner { display: inline-block; width: 16px; height: 16px; border-radius: 999px; border: 2px solid var(--border-strong); border-top-color: var(--accent-primary); animation: ui-spin 0.8s linear infinite; }
@keyframes ui-spin { to { transform: rotate(360deg); } }
.ui-skeleton, .skeleton-line { display: block; height: 14px; margin-bottom: 10px; border-radius: 6px; background: var(--bg-surface-subtle); animation: ui-pulse 1.4s ease-in-out infinite; }
.ui-skeleton-lg { height: 22px; width: 45%; }
.ui-skeleton-md { width: 80%; }
.ui-skeleton-sm { width: 60%; }
@keyframes ui-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-flex; align-items: center; gap: 8px; }

/* ==========================================================================
   11. Tables
   ========================================================================== */
.ui-table-wrap, .table-wrap, .table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-surface); }
.ui-table, .card table, .app-modal-body table { width: 100%; border-collapse: collapse; font-size: 14px; text-align: left; }
.card table { display: block; overflow-x: auto; }
.card table :is(th, td) { overflow-wrap: normal; word-break: normal; }
.card table td:first-child { min-width: 132px; }
.ui-table th, .ui-table td, .card table th, .card table td, .app-modal-body table th, .app-modal-body table td { padding: 10px 14px; border-bottom: 1px solid var(--border-default); vertical-align: top; }
.ui-table th, .card table th, .app-modal-body table th { font-size: 13px; font-weight: 600; color: var(--text-muted); white-space: nowrap; background: var(--bg-surface-subtle); }
.ui-table td { white-space: nowrap; }
.ui-table tbody tr:last-child td, .card table tbody tr:last-child td { border-bottom: 0; }
.ui-table tbody tr:hover td { background: var(--hover-veil); }
.ui-table td form, .card table td form { margin: 0; }

/* ==========================================================================
   12. Tabs, popovers, tooltips, combobox (component library)
   ========================================================================== */
.ui-tablist { display: flex; gap: 4px; max-width: 100%; overflow-x: auto; border-bottom: 1px solid var(--border-default); }
.ui-tab { padding: 9px 12px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--text-secondary); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.ui-tab:hover { color: var(--text-primary); }
.ui-tab[aria-selected="true"] { border-bottom-color: var(--accent-primary); color: var(--accent-text); }
.ui-tabpanel { padding-top: 14px; }

.ui-popover-wrap { position: relative; display: inline-block; }
.ui-popover-panel { position: absolute; top: calc(100% + 8px); left: 0; z-index: var(--z-popover); min-width: 240px; max-width: min(340px, calc(100vw - 32px)); padding: 14px; background: var(--bg-elevated); border: 1px solid var(--border-default); border-radius: var(--radius-md); box-shadow: var(--shadow-popover); animation: pop-in 0.16s var(--ease); }
.ui-popover-panel-right { left: auto; right: 0; }
.ui-tooltip-wrap { position: relative; display: inline-flex; align-items: center; }
.ui-tooltip { position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); z-index: var(--z-popover); padding: 5px 9px; border-radius: 6px; background: var(--text-primary); color: var(--bg-surface); font-size: 13px; white-space: nowrap; pointer-events: none; }
.ui-combobox { position: relative; }
.ui-listbox { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: var(--z-popover); max-height: 260px; overflow-y: auto; margin: 0; padding: 4px; list-style: none; background: var(--bg-elevated); border: 1px solid var(--border-default); border-radius: var(--radius-sm); box-shadow: var(--shadow-popover); }
.ui-option { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 6px; font-size: 14px; cursor: pointer; }
.ui-option:hover, .ui-option.is-active { background: var(--hover-veil); }
.ui-option[aria-selected="true"] { background: var(--accent-soft); font-weight: 600; }

.ui-modal-backdrop { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--scrim); }
.ui-modal-dialog { width: 100%; max-width: 480px; padding: 22px; border-radius: var(--radius-xl); background: var(--bg-elevated); border: 1px solid var(--border-default); box-shadow: var(--shadow-modal); }

.swatch { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border-default); border-radius: var(--radius-sm); }
.swatch-chip { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border-strong); flex-shrink: 0; }
.swatch-canvas { background: var(--bg-canvas); }
.swatch-surface { background: var(--bg-surface); }
.swatch-text { background: var(--text-primary); }
.swatch-accent { background: var(--accent-primary); }
.swatch-border { background: var(--border-default); }

/* ==========================================================================
   13. Modal dialogs (native <dialog>)
   ========================================================================== */
.app-modal { width: min(var(--modal-w, 760px), calc(100vw - 32px)); max-width: none; max-height: min(88vh, 920px); margin: auto; padding: 0; border: 0; background: transparent; color: var(--text-primary); overflow: visible; }
.app-modal[data-size="sm"] { --modal-w: 440px; }
.app-modal[data-size="md"] { --modal-w: 620px; }
.app-modal[data-size="lg"] { --modal-w: 860px; }
.app-modal[data-size="xl"] { --modal-w: 1120px; }
.app-modal[open] { animation: modal-in 0.2s var(--ease); }
.app-modal[open]::backdrop { animation: fade-in 0.2s ease; }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(0.99); } to { opacity: 1; transform: none; } }
.app-modal-frame { display: flex; flex-direction: column; max-height: min(88vh, 920px); margin: 0; border-radius: var(--radius-xl); box-shadow: var(--shadow-modal); overflow: hidden; }
.app-modal-head { display: flex; align-items: center; gap: 8px; flex-shrink: 0; padding: 12px 12px 10px 20px; border-bottom: 1px solid var(--border-default); }
.app-modal-back { margin-left: -10px; }
.app-modal-title { flex: 1; min-width: 0; margin: 0; font-size: 16px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-modal-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 20px; overscroll-behavior: contain; }
.app-modal-foot { display: flex; justify-content: flex-end; gap: 10px; flex-shrink: 0; padding: 12px 20px; border-top: 1px solid var(--border-default); }
.modal-loading { padding: 6px 0; }
.app-modal-body .section-hero .page-title,
.app-modal-body > .modal-page > h1:first-child,
.app-modal-body .section-tabs { display: none; }
.app-modal-body .card, .app-modal-body .ui-card { box-shadow: none; }
.app-modal-body .section-hero .ui-card-header { padding-top: 0; }
.app-modal-body .modal-page > * + * { margin-top: 16px; }
.app-modal-body .modal-page > .card:first-of-type > h1:first-child { display: none; }
.app-modal-confirm .app-modal-frame { padding: 20px; gap: 16px; }
.confirm-body .app-modal-title { white-space: normal; margin-bottom: 8px; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; }

.app-modal-search { margin-top: 12vh; }
.search-dialog-form { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--border-default); }
.search-dialog-form > .nav-icon { color: var(--text-muted); }
.search-dialog-input { flex: 1; min-width: 0; height: 40px; border: 0; background: transparent; color: var(--text-primary); font: inherit; font-size: 15px; }
.search-dialog-input:focus { outline: none; }
.search-dialog-input::-webkit-search-cancel-button { display: none; }
.search-dialog-results { max-height: min(52vh, 460px); overflow-y: auto; padding: 6px; }
.search-dialog-results form { margin: 0; }
.search-result { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 40px; padding: 8px 12px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-primary); font: inherit; font-size: 14px; text-align: left; text-decoration: none; cursor: pointer; }
.search-result:hover, .search-result.is-active { background: var(--accent-soft); text-decoration: none; }
.search-result .nav-icon { color: var(--text-muted); }
.search-result-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result-meta { font-size: 13px; color: var(--text-muted); white-space: nowrap; }
.search-dialog-hint { padding: 10px 12px; margin: 0; }
.search-dialog-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; padding: 10px 16px; border-top: 1px solid var(--border-default); }
.search-dialog-foot a { margin-left: auto; color: var(--text-secondary); }
.search-dialog-foot a + a { margin-left: 0; }

/* ==========================================================================
   14. Toasts
   ========================================================================== */
.ui-toast-region { position: fixed; top: 72px; right: max(16px, env(safe-area-inset-right, 0px)); z-index: var(--z-toast); display: flex; flex-direction: column; gap: 8px; width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.ui-toast { pointer-events: auto; display: grid; grid-template-columns: 24px minmax(0, 1fr) 28px; align-items: start; gap: 10px; min-height: 52px; padding: 12px 10px 12px 14px; border-radius: var(--radius-md); color: var(--text-primary); background: var(--bg-elevated); border: 1px solid var(--border-default); box-shadow: var(--shadow-popover); font-size: 14px; line-height: 1.4; animation: toast-in 0.22s var(--ease); }
.ui-toast-icon { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; color: var(--accent-on); background: var(--accent-primary); font-size: 13px; font-weight: 700; }
.ui-toast-content { min-width: 0; overflow-wrap: anywhere; padding-top: 2px; }
.ui-toast-close { display: grid; place-items: center; width: 28px; height: 28px; margin-top: -3px; padding: 0; color: var(--text-muted); background: transparent; border: 0; border-radius: 6px; cursor: pointer; }
.ui-toast-close:hover { color: var(--text-primary); background: var(--hover-veil); }
.ui-toast-success .ui-toast-icon { background: var(--status-success); color: var(--bg-surface); }
.ui-toast-warning .ui-toast-icon { background: var(--status-warning); color: var(--bg-surface); }
.ui-toast-error .ui-toast-icon { background: var(--status-danger); color: var(--bg-surface); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px) scale(0.98); } to { opacity: 1; transform: none; } }
@media (max-width: 639px) { .ui-toast-region { right: 10px; width: calc(100vw - 20px); } }

/* ==========================================================================
   15. Chat: conversation column and resizable side panel
   ========================================================================== */
.chat-app { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; width: 100%; }
.chat-app[data-layout] { flex-direction: row; }
.chat-column { container: chat / inline-size; position: relative; flex: 1 1 0; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--bg-surface); }
@container chat (max-width: 560px) { .chat-topbar .context-chip, .chat-topbar .tag:not(.tag-warning) { display: none; } .header-model span { max-width: 96px; } }
.chat-topbar { position: relative; z-index: 5; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; padding: 8px 12px 8px 20px; border-bottom: 1px solid var(--border-default); }
.chat-heading-block { display: flex; flex: 1 1 auto; flex-direction: column; gap: 3px; min-width: 0; }
.chat-title-row { display: flex; align-items: center; gap: 4px; min-width: 0; }
.chat-chips { display: flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; }
.mode-chip { display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font-size: var(--text-xs); font-weight: 600; white-space: nowrap; }
.mode-chip.is-agent { background: var(--agent-soft); color: var(--agent-text); }
.header-model { display: inline-flex; align-items: center; gap: 8px; height: 38px; max-width: 260px; padding: 0 10px 0 12px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-surface); color: var(--text-primary); font: inherit; font-size: var(--text-sm); font-weight: 600; cursor: pointer; }
.header-model:hover { border-color: var(--border-strong); }
.header-model span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-model > .nav-icon:first-child { color: var(--agent-primary); }
.chat-topbar-group { display: flex; flex-shrink: 0; align-items: center; gap: 6px; min-width: 0; }
.chat-thread-title { margin: 0; min-width: 0; font-size: var(--text-section); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-toggle { position: relative; }
.panel-toggle[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent-text); }
.panel-count { position: absolute; top: 1px; right: 0; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px; background: var(--accent-primary); color: var(--accent-on); font-size: 10px; font-weight: 700; line-height: 16px; text-align: center; }
.pane-tabs { display: flex; flex: 1; align-items: stretch; gap: 2px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.pane-tabs::-webkit-scrollbar { display: none; }
.pane-tab { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 52px; padding: 0 10px; flex-shrink: 0; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--text-secondary); font: inherit; font-size: var(--text-sm); font-weight: 600; cursor: pointer; white-space: nowrap; }
.pane-tab:hover { color: var(--text-primary); }
.pane-tab[aria-selected="true"] { border-bottom-color: var(--accent-primary); color: var(--accent-text); }
.pane-tab.is-agent[aria-selected="true"] { border-bottom-color: var(--agent-primary); color: var(--agent-text); }
.pane-subtabs { display: flex; flex-shrink: 0; gap: 4px; overflow-x: auto; padding: 8px 12px; border-bottom: 1px solid var(--border-default); background: var(--bg-surface); scrollbar-width: none; }
.pane-subtab { display: inline-flex; align-items: center; gap: 5px; min-height: 30px; padding: 0 10px; flex-shrink: 0; border: 0; border-radius: 999px; background: transparent; color: var(--text-secondary); font: inherit; font-size: var(--text-xs); font-weight: 600; cursor: pointer; }
.pane-subtab:hover { background: var(--hover-veil); }
.pane-subtab[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-text); }
.pane-tab-count { font-size: 12px; font-weight: 600; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.context-chip { align-items: center; height: 24px; padding: 0 9px; border-radius: 999px; font-size: 12px; color: var(--text-muted); border: 1px solid var(--border-default); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chat-thread-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; scroll-behavior: smooth; }
.chat-thread { width: 100%; max-width: var(--chat-column); margin: 0 auto; padding: 20px 24px 24px; display: flex; flex-direction: column; gap: 20px; }

.branch-strip { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 8px 10px; border-radius: var(--radius-md); border: 1px solid var(--border-default); background: var(--bg-canvas); }
.branch-strip form { margin: 0; }
.branch-strip-label { display: inline-flex; align-items: center; gap: 6px; margin-right: 4px; font-size: 13px; color: var(--text-secondary); }

.chat-msg { min-width: 0; display: flex; gap: 10px; }
.chat-msg-avatar { display: grid; place-items: center; flex-shrink: 0; width: 32px; height: 32px; }
.chat-msg-user { justify-content: flex-end; }
.chat-msg-user .chat-msg-main { flex: 0 1 auto; max-width: 85%; align-items: flex-end; }
.chat-msg-user .chat-msg-bubble { padding: 10px 16px; border-radius: var(--radius-lg) var(--radius-lg) var(--radius-xs) var(--radius-lg); background: var(--accent-soft); }
.chat-msg-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.chat-msg-meta { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; min-height: 20px; font-size: 13px; color: var(--text-muted); }
.chat-msg-model { font-size: 14px; font-weight: 700; color: var(--text-primary); }
.chat-msg-time { font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.chat-msg-bubble { font-size: var(--text-reading); line-height: var(--line-reading); overflow-wrap: anywhere; }
.chat-msg-body { font-size: var(--text-reading); line-height: var(--line-reading); color: var(--text-primary); overflow-wrap: anywhere; }
.chat-msg-body > * + *, .chat-msg-bubble > * + * { margin-top: 12px; }
/* Long answers read as a document: clear sections, comfortable lines, quiet lists. */
.chat-msg-body > h2.chat-heading, .chat-msg-body > h3.chat-heading, .chat-msg-body > h4.chat-heading { margin-top: 26px; margin-bottom: 0; line-height: 1.35; letter-spacing: -0.01em; }
.chat-msg-body > .chat-heading + * { margin-top: 8px; }
.chat-msg-body p.chat-paragraph + p.chat-paragraph { margin-top: 12px; }
.chat-msg-body > h2.chat-heading:first-child, .chat-msg-body > h3.chat-heading:first-child { margin-top: 0; }
.chat-msg-body > h2.chat-heading { padding-bottom: 6px; border-bottom: 1px solid var(--border-default); }
.chat-msg-body p.chat-paragraph { max-width: 78ch; }
.chat-msg-body li { max-width: 76ch; }
.chat-msg-body li + li { margin-top: 6px; }
.chat-msg-body li::marker { color: var(--accent-primary); font-weight: 700; }
.chat-msg-body .chat-quote { padding: 8px 14px; border-left: 3px solid var(--accent-primary); border-radius: 0 10px 10px 0; background: var(--bg-surface-subtle); }
.chat-msg-body .chat-table th { background: var(--bg-surface-subtle); font-weight: 700; text-align: left; }
.chat-msg-body .chat-table th, .chat-msg-body .chat-table td { padding: 8px 12px; vertical-align: top; }
.chat-msg-body .chat-table tbody tr:nth-child(even) { background: var(--hover-veil); }
.chat-msg-body .chat-rule { margin: 18px 0; border: 0; border-top: 1px solid var(--border-default); }
.chat-analysis { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: var(--text-sm); color: var(--text-muted); }
.chat-analysis:empty { display: none; }
.chat-analysis li { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.chat-analysis li::before { content: "✓"; width: 14px; color: var(--status-success); font-weight: 700; }
.chat-analysis li.is-active::before { content: "●"; color: var(--accent-primary); animation: chat-analysis-pulse 1.2s ease-in-out infinite; }
.chat-analysis-label { font-weight: 600; color: var(--text-secondary); }
.chat-analysis-time { font-variant-numeric: tabular-nums; }
.chat-stream-tail { white-space: pre-wrap; }
.chat-msg-body.chat-stream-text[data-live-answer] { white-space: normal; }
@keyframes chat-analysis-pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .chat-analysis li.is-active::before { animation: none; } }
.chat-msg-attachments { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-paragraph { margin: 0; word-break: break-word; }
.chat-heading { margin: 18px 0 0; }
.chat-msg-body h2.chat-heading { font-size: 21px; }
.chat-msg-body h3.chat-heading { font-size: 18px; }
.chat-msg-body h4.chat-heading { font-size: 16px; }
.chat-msg-body .bullet-list, .chat-msg-body .ordered-list { color: var(--text-primary); font-size: inherit; padding-left: 22px; }
.chat-msg-body ul.bullet-list, .panel-preview .chat-msg-body ul { list-style: disc; }
.chat-msg-body ol.ordered-list { list-style: decimal; }
.chat-msg-body strong { font-weight: 700; }
.chat-msg-body a { text-decoration-color: currentColor; }
.chat-quote { margin-inline: 0; margin-block-end: 0; padding: 4px 0 4px 14px; border-left: 3px solid var(--agent-secondary); color: var(--text-secondary); }
.chat-quote p { margin: 0; }
.chat-rule { margin-inline: 0; margin-block-end: 0; width: 100%; }
.chat-table-wrap { max-width: 100%; overflow-x: auto; border: 1px solid var(--border-default); border-radius: var(--radius-md); }
.chat-table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 1.5; }
.chat-table th, .chat-table td { min-width: 96px; padding: 8px 12px; border-bottom: 1px solid var(--border-default); text-align: left; vertical-align: top; overflow-wrap: normal; }
.chat-table th { background: var(--bg-surface-subtle); font-weight: 600; }
.chat-table tr:last-child td { border-bottom: 0; }
.chat-table .align-center { text-align: center; }
.chat-table .align-right { text-align: right; font-variant-numeric: tabular-nums; }
.chat-inline-code { padding: 1px 6px; border-radius: 5px; background: var(--bg-surface-subtle); font-size: 0.88em; }
.chat-code-block { padding: 0 !important; margin: 4px 0; border-radius: var(--radius-md) !important; background: var(--bg-canvas) !important; border: 1px solid var(--border-default) !important; box-shadow: none !important; overflow: hidden; gap: 0 !important; }
.chat-code-header { padding: 5px 6px 5px 14px; border-bottom: 1px solid var(--border-default); }
.chat-code-header .badge { background: transparent; padding: 0; color: var(--text-muted); font-weight: 500; }
.chat-code-header .btn { min-height: 26px; padding: 2px 10px; font-size: 13px; background: transparent; border-color: transparent; color: var(--text-secondary); }
.chat-code-header .btn:hover { background: var(--hover-veil); color: var(--text-primary); }
.chat-code-pre { margin: 0; padding: 12px 14px; overflow-x: auto; font-size: var(--text-technical); font-weight: var(--weight-regular); line-height: 1.6; tab-size: 4; }
.chat-code-pre :is(.tok-k, .tok-kc, .tok-kd, .tok-kn, .tok-kp, .tok-kr, .tok-kt, .tok-ow, .tok-nt) { color: var(--code-keyword); font-weight: var(--weight-medium); }
.chat-code-pre :is(.tok-s, .tok-sa, .tok-sb, .tok-sc, .tok-dl, .tok-sd, .tok-s2, .tok-se, .tok-sh, .tok-si, .tok-sx, .tok-sr, .tok-s1, .tok-ss) { color: var(--code-string); }
.chat-code-pre :is(.tok-m, .tok-mb, .tok-mf, .tok-mh, .tok-mi, .tok-mo, .tok-il) { color: var(--code-number); }
.chat-code-pre :is(.tok-nf, .tok-fm, .tok-nc, .tok-nd, .tok-nb, .tok-bp, .tok-na) { color: var(--code-name); }
.chat-code-pre :is(.tok-c, .tok-ch, .tok-cm, .tok-c1, .tok-cs, .tok-cp, .tok-cpf) { color: var(--code-comment); font-style: italic; }
.chat-math math { font-size: 1.08em; }
.chat-math-block { display: block; max-width: 100%; overflow-x: auto; padding: 4px 0; text-align: center; }
.chat-image { display: block; max-width: min(100%, 560px); max-height: 520px; border: 1px solid var(--border-default); border-radius: var(--radius-md); }
.chat-image-link { display: inline-flex; padding: 4px 10px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); }

/* The Word file of an answer: what it is and how to get it. */
.chat-doc-result { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 10px 0 6px; padding: 12px 14px; border: 1px solid var(--border-default); border-radius: 12px; background: var(--bg-surface-subtle); }
.chat-doc-icon { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 10px; background: var(--bg-surface); color: var(--accent-primary); flex: none; }
.chat-doc-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 220px; }
.chat-doc-text strong { font-size: 14px; overflow-wrap: anywhere; }
.chat-doc-text span { font-size: 13px; color: var(--text-secondary); }
.chat-doc-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.chat-msg-actions { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; margin-left: -6px; min-height: 30px; }
.chat-msg-actions form { margin: 0; }
.chat-msg-actions-user { opacity: 0; transition: opacity 0.15s ease; }
.chat-msg-user:hover .chat-msg-actions-user, .chat-msg-user:focus-within .chat-msg-actions-user { opacity: 1; }
@media (hover: none) { .chat-msg-actions-user { opacity: 1; } }
.chat-msg-actions .icon-btn { color: var(--text-muted); }
.chat-msg-actions .icon-btn:hover { color: var(--text-primary); }
.chat-msg-cost { display: inline-flex; align-items: center; height: 22px; padding: 0 9px; margin-left: 6px; border-radius: 999px; background: var(--bg-surface-subtle); color: var(--text-secondary); font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.attempt-switch { display: inline-flex; align-items: center; gap: 2px; margin-left: 6px; padding: 2px; border-radius: 999px; border: 1px solid var(--border-default); }
.attempt-switch form { margin: 0; }
.attempt-btn { min-width: 24px; height: 22px; padding: 0 7px; border: 0; border-radius: 999px; background: transparent; color: var(--text-muted); font: inherit; font-size: 13px; cursor: pointer; }
.attempt-btn:hover { color: var(--text-primary); }
.attempt-btn.is-active { background: var(--accent-soft); color: var(--accent-text); font-weight: 700; }
.chat-msg-error { margin: 4px 0 0; }
.citation { display: inline-block; min-width: 17px; margin: 0 1px; padding: 0 4px; border-radius: 5px; background: var(--accent-soft); color: var(--accent-text); font-size: 11px; font-weight: 700; line-height: 17px; text-align: center; vertical-align: 2px; text-decoration: none; }
.citation:hover { background: var(--accent-primary); color: var(--accent-on); text-decoration: none; }
.grounding { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin: 4px 0 0; padding: 6px 10px; border: 1px solid var(--border-default); border-radius: var(--radius-sm); font-size: 13px; }
.grounding .nav-icon { color: var(--text-muted); }
.grounding-label { font-weight: 600; }
.grounding-detail { flex-basis: 100%; color: var(--text-muted); font-size: 13px; }
.grounding-success { border-color: var(--status-success); background: var(--status-success-soft); }
.grounding-success .nav-icon, .grounding-success .grounding-label { color: var(--status-success); }
.grounding-warning { border-color: var(--status-warning); background: var(--status-warning-soft); }
.grounding-warning .nav-icon, .grounding-warning .grounding-label { color: var(--status-warning); }
.grounding-danger { border-color: var(--status-danger); background: var(--status-danger-soft); }
.grounding-danger .nav-icon, .grounding-danger .grounding-label { color: var(--status-danger); }
.grounding-success .grounding-detail, .grounding-warning .grounding-detail, .grounding-danger .grounding-detail { color: var(--text-secondary); }
.grounding .btn-xs { min-height: 22px; }
.tag-button { border: 0; font: inherit; font-size: 13px; cursor: pointer; }
.tag-button:hover { background: var(--accent-soft); color: var(--accent-text); }
.image-button { display: block; width: 100%; padding: 0; border: 0; background: transparent; cursor: pointer; }
.chat-stream { gap: 5px; }
.chat-stream-status { color: var(--agent-text); font-size: 13px; font-weight: 600; }
.chat-stream-text { white-space: pre-wrap; min-height: 24px; }
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; animation: dot 1.2s ease-in-out infinite; }
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

/* Composer */
.chat-composer { container: composer / inline-size; flex-shrink: 0; width: 100%; max-width: min(var(--composer-width), var(--chat-column)); margin: 0 auto; padding: 4px 24px calc(12px + env(safe-area-inset-bottom, 0px)); }
.composer-notes { display: flex; flex-direction: column; gap: 6px; }
.composer-notes > :not(.is-hidden) { margin-bottom: 8px; }
.composer-notes .badge { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px 6px 12px; border-radius: var(--radius-sm); font-weight: 500; }
.composer-notes .badge span { display: inline-flex; align-items: center; gap: 6px; }
.composer-shell { width: 100%; margin: 0 auto; padding: 14px 10px 10px 16px; border-radius: var(--radius-xl); background: var(--bg-surface); border: 1px solid var(--border-strong); box-shadow: var(--shadow-popover); transition: border-color var(--motion) ease, box-shadow var(--motion) ease; }
.composer-shell:focus-within { border-color: var(--accent-primary); box-shadow: 0 0 0 3px var(--accent-soft); }
.is-drop-target .composer-shell { border-color: var(--accent-primary); box-shadow: 0 0 0 3px var(--accent-soft); }
.chat-column.is-drop-target::after { content: "Отпустите файл, чтобы прикрепить"; position: absolute; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center; background: rgba(12, 14, 24, 0.42); -webkit-backdrop-filter: blur(5px); backdrop-filter: blur(5px); border: 2px dashed var(--accent-primary); border-radius: var(--radius-lg); color: var(--text-primary); font-size: var(--text-section); font-weight: 600; pointer-events: none; }
.composer-input { display: block; width: 100%; min-height: 24px; max-height: 240px; padding: 0 6px 0 0; border: 0; background: transparent; color: var(--text-primary); font-family: inherit; font-size: var(--text-reading); line-height: var(--line-reading); resize: none; overflow-y: auto; }
.composer-input:focus, .composer-input:focus-visible { outline: none; }
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 10px; }
.composer-bar-group { display: flex; align-items: center; gap: 6px; min-width: 0; }
.composer-bar-group:first-child { margin-left: -6px; }
.composer-bar-group:last-child { flex: 0 1 auto; justify-content: flex-end; }
.composer-attach { cursor: pointer; border: 1px solid var(--border-default); border-radius: 999px; }
.composer-pill { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border: 1px solid var(--border-default); border-radius: 999px; background: var(--bg-surface); color: var(--text-secondary); font: inherit; font-size: var(--text-sm); font-weight: 600; white-space: nowrap; cursor: pointer; transition: background-color var(--motion) ease, border-color var(--motion) ease; }
.composer-pill:hover:not(:disabled) { border-color: var(--border-strong); color: var(--text-primary); }
.composer-pill:disabled { opacity: 0.5; cursor: default; }
.composer-pill.is-selected { border-color: transparent; background: var(--accent-soft); color: var(--accent-text); }
.composer-pill.is-agent { border-color: transparent; background: var(--agent-soft); color: var(--agent-text); }
.composer-mode-prefix { font-weight: 500; }
.composer-check[aria-pressed="true"] { border-color: transparent; background: var(--accent-soft); color: var(--accent-text); }
.composer-check[aria-pressed="false"] { color: var(--text-muted); text-decoration: line-through; }
.composer-menu { position: absolute; left: 0; bottom: calc(100% + 8px); z-index: var(--z-popover); display: flex; flex-direction: column; gap: 2px; width: min(320px, calc(100vw - 32px)); max-height: min(60vh, 420px); overflow-y: auto; padding: 6px; border-radius: var(--radius-lg); animation: pop-in 0.16s var(--ease); transform-origin: bottom left; }
.composer-tool { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 6px 10px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-primary); font: inherit; text-align: left; cursor: pointer; }
.composer-tool .nav-icon { width: 20px; height: 20px; color: var(--accent-text); }
.composer-tool.is-agent .nav-icon { color: var(--agent-text); }
.composer-tool:hover:not(:disabled) { background: var(--hover-veil); }
.composer-tool[aria-pressed="true"] { background: var(--accent-soft); }
.composer-tool.is-agent[aria-pressed="true"] { background: var(--agent-soft); }
.composer-tool:disabled { opacity: 0.5; cursor: default; }
.composer-tool-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.composer-tool-text strong { font-size: var(--text-sm); font-weight: 600; }
.composer-tool-text small { color: var(--text-muted); font-size: var(--text-xs); }
.model-trigger { display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 220px; height: 36px; padding: 0 8px 0 12px; border: 0; border-radius: 999px; background: var(--bg-surface-subtle); color: var(--text-primary); font: inherit; font-size: var(--text-sm); font-weight: 600; cursor: pointer; }
.model-trigger:hover { background: var(--accent-soft); color: var(--accent-text); }
.model-trigger-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-trigger-provider { display: none; }
.chat-app:not([data-layout]) .model-trigger { max-width: 320px; }
.chat-app:not([data-layout]) .model-trigger-provider { display: inline; font-weight: 400; color: var(--text-muted); }
.model-trigger .nav-icon { color: var(--text-muted); }
.composer-agent-choice { margin-top: 8px; }
.image-model-wrap { min-width: 0; }
.image-model-wrap .model-trigger { max-width: 260px; }
.composer-menu.image-model-menu { left: auto; right: 0; width: min(340px, 86vw); }
.image-model-heading { margin: 0; padding: 4px 10px 6px; font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.image-model-menu .composer-tool[aria-pressed="true"] { background: var(--accent-soft); }
.composer-file { font-size: 13px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.composer-attachment-preview { display: flex; align-items: center; gap: 6px; width: fit-content; max-width: 100%; margin-bottom: 10px; padding: 4px 4px 4px 10px; border: 1px solid var(--border-default); border-radius: var(--radius-sm); background: var(--bg-surface-subtle); }
.composer-attachment-preview .icon-btn { flex-shrink: 0; }
.composer-hint { max-width: none; margin: 8px auto 0; text-align: center; font-size: 12px; line-height: 1.4; color: var(--text-muted); }
.send-btn { display: inline-grid; place-items: center; flex-shrink: 0; width: 40px; height: 40px; padding: 0; border: 0; border-radius: var(--radius-md); background: var(--accent-primary); color: var(--accent-on); cursor: pointer; transition: background-color var(--motion) ease; }
.send-btn:hover:not(:disabled) { background: var(--accent-primary-hover); }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.send-btn.is-stop { background: var(--text-primary); color: var(--bg-surface); }
@container composer (max-width: 560px) {
  .composer-mode-prefix, .composer-check span { display: none; }
  .composer-shell .model-trigger { max-width: 130px; }
}
@container composer (max-width: 400px) {
  .composer-shell .composer-bar { flex-wrap: wrap; }
  .composer-shell .composer-bar-group:last-child { flex-basis: 100%; }
}

/* Agent picker and tool cards */
.chat-tool-card { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; width: 100%; padding: 16px; border: 1px solid var(--border-default); border-radius: var(--radius-lg); background: var(--bg-surface); }
.chat-tool-title { display: flex; align-items: center; gap: 8px; }
.chat-tool-title .nav-icon { color: var(--accent-text); }
.chat-tool-card.is-agent { border-color: var(--border-default); background: var(--bg-canvas); }
.chat-tool-card.is-agent .chat-tool-title .nav-icon { color: var(--agent-text); }
.chat-generated-file {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 12px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
}
.chat-generated-file-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-generated-file-title .nav-icon { flex: none; }
.chat-generated-file-title strong { overflow-wrap: anywhere; }
.chat-tool-sources { display: grid; gap: 10px; margin: 0; padding-left: 20px; }
.chat-tool-sources a { overflow-wrap: anywhere; }
.chat-tool-sources .caption { display: block; }
.chat-tool-sources p { margin: 2px 0 0; }
/* AI search answer and its sources inside a chat tool card. */
.chat-tool-period { margin: -4px 0 0; }
.chat-tool-answer { display: grid; gap: 8px; }
.chat-tool-answer-body { font-size: 15px; line-height: 1.6; }
.chat-tool-answer-body > * + * { margin-top: 8px; }
.chat-tool-answer-body ol, .chat-tool-answer-body ul { margin: 0; padding-left: 20px; }
.chat-tool-answer-body li + li { margin-top: 4px; }
.chat-tool-sources-block { display: grid; gap: 8px; }
.chat-tool-sources { font-size: 14px; line-height: 1.45; }
.chat-tool-sources li::marker { color: var(--text-muted); }
.chat-tool-snippet {
  margin: 4px 0 0; font-size: 13px; color: var(--text-secondary);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.chat-tool-image { margin: 0; max-width: 440px; }
.chat-tool-image img { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; border-radius: var(--radius-md); }
.chat-tool-image figcaption { margin-top: 6px; }

/* Side panel */
.side-panel { container: panel / inline-size; position: relative; flex: 0 0 auto; display: flex; flex-direction: column; width: var(--panel-width, 360px); max-width: calc(100% - 360px); min-width: 0; min-height: 0; border-left: 1px solid var(--border-default); background: var(--bg-canvas); transition: background-color var(--motion) ease; }
.chat-app[data-panel="closed"] .side-panel { display: none; }
.chat-app[data-panel="full"] .side-panel { width: 100%; max-width: 100%; border-left: 0; }
.chat-app[data-panel="full"] .chat-column, .chat-app[data-panel="full"] .panel-resizer { display: none; }
.panel-resizer { position: absolute; z-index: 3; top: 0; bottom: 0; left: -5px; width: 10px; cursor: col-resize; touch-action: none; }
.panel-resizer::after { content: ""; position: absolute; top: 0; bottom: 0; left: 4px; width: 2px; background: transparent; transition: background-color 0.12s ease; }
.panel-resizer:hover::after, .panel-resizer:focus-visible::after, body.is-resizing .panel-resizer::after { background: var(--accent-primary); }
.panel-resizer:focus-visible { outline: none; }
body.is-resizing { cursor: col-resize; user-select: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; flex-shrink: 0; min-height: 64px; padding: 6px 8px 0 12px; border-bottom: 1px solid var(--border-default); background: var(--bg-surface); }
.panel-head-actions { display: flex; flex-shrink: 0; gap: 2px; }
@container panel (max-width: 350px) {
  .panel-head { gap: 2px; padding-inline: 6px; }
  .panel-head .pane-tabs { gap: 0; }
  .panel-head .pane-tab { gap: 3px; padding: 0 6px; }
}
.panel-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px; }
.panel-list { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.panel-row { display: flex; align-items: center; gap: 10px; width: 100%; min-width: 0; padding: 9px 10px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-surface); color: var(--text-primary); font: inherit; text-align: left; text-decoration: none; }
a.panel-row:hover, button.panel-row:hover { border-color: var(--accent-primary); text-decoration: none; cursor: pointer; }
.panel-row-icon { display: grid; place-items: center; flex-shrink: 0; width: 32px; height: 32px; border-radius: var(--radius-sm); background: var(--bg-surface-subtle); color: var(--accent-text); }
.panel-row-number { display: grid; place-items: center; flex-shrink: 0; min-width: 22px; height: 22px; padding: 0 4px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-text); font-size: 12px; font-weight: 700; }
.panel-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.panel-row-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 14px; }
.panel-row-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--text-muted); }
.panel-file { display: flex; align-items: center; gap: 4px; }
.panel-file > .panel-row { flex: 1; }
.panel-empty { padding: 28px 16px; margin: 0; text-align: center; color: var(--text-muted); font-size: 13px; }
div.panel-empty { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.panel-note { margin-top: 12px; }
.source-group { margin-bottom: 18px; border-radius: var(--radius-md); }
.source-group-title { margin: 0 0 6px; font-size: 14px; }
.source-group-title a { color: var(--text-primary); }
.source-group > .grounding { margin: 0 0 8px; }
.version-group { margin-bottom: 8px; padding: 0 10px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-surface); }
.version-group > summary { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 42px; font-size: 14px; font-weight: 600; cursor: pointer; }
.version-group > summary > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.version-group > .diff-grid { padding: 0 0 10px; }
.version-group > a { display: inline-block; padding-bottom: 10px; }
.is-highlighted { outline: 2px solid var(--accent-primary); outline-offset: 3px; }
.panel-preview { padding: 12px 14px 20px; border: 1px solid var(--border-default); border-radius: var(--radius-lg); background: var(--bg-surface); overflow-wrap: anywhere; }
.panel-preview-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: -4px -6px 10px; }
.panel-preview-actions { display: flex; align-items: center; gap: 4px; }
.panel-preview-title { margin: 0 0 6px; font-size: 20px; line-height: 1.25; }
.panel-preview-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 14px; color: var(--text-muted); font-size: 13px; }
.panel-preview .chat-msg-body > h2.chat-heading:first-child { display: none; }
.chat-app[data-panel="full"] .panel-body > * { max-width: 900px; margin-left: auto; margin-right: auto; }
.panel-images { display: flex; flex-direction: column; gap: 12px; }
.panel-images figure { margin: 0; }
.panel-images img { display: block; width: 100%; border: 1px solid var(--border-default); border-radius: var(--radius-md); }
.file-page + .file-page { margin-top: 12px; }
.file-text { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--font-sans); font-size: 13px; line-height: 1.6; }
.wb-refresh { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; flex-shrink: 0; padding: 8px 14px; background: var(--accent-soft); font-size: 13px; }
.wb-refresh:empty { display: none; }

.version-list { margin: 0; padding: 0; list-style: none; }
.version-item { position: relative; display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; align-items: start; gap: 10px; padding: 6px 6px; }
.version-item::before { content: ""; position: absolute; left: 14px; top: 24px; bottom: -4px; width: 2px; background: var(--border-default); }
.version-item:last-child::before { display: none; }
.version-dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border-strong); background: var(--bg-surface); }
.version-item.is-current .version-dot { border: 5px solid var(--accent-primary); }
.version-item form { margin: 0; }
.diff-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; padding: 0 6px; }
.diff-column { display: flex; flex-direction: column; gap: 6px; padding: 8px; border-radius: var(--radius-sm); font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
.diff-column strong { font-size: 13px; }
.diff-column.is-removed { background: var(--status-danger-soft); }
.diff-column.is-added { background: var(--status-success-soft); }
.diff-column del { text-decoration-color: var(--status-danger); }
.diff-column ins { text-decoration: none; }

/* Narrow screens: the panel covers the chat */
@media (max-width: 899px) {
  .chat-app[data-panel="open"] .side-panel, .chat-app[data-panel="full"] .side-panel { position: absolute; inset: 0; z-index: 8; width: 100%; max-width: 100%; border-left: 0; }
  .panel-resizer, .panel-fullscreen { display: none; }
  .context-chip { display: none; }
}

/* Welcome: the start of a new conversation */
.chat-home { display: flex; background: var(--bg-surface); }
.chat-hero { width: 100%; margin: auto; padding: 28px 20px 44px; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.chat-hero > * { max-width: var(--chat-column); width: 100%; }
.chat-hero > .chat-start-form, .chat-hero > .suggestions { max-width: calc(var(--composer-width) - 48px); }
.chat-greeting { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; margin: auto; text-align: center; }
.chat-hero > .agent-core, .chat-greeting > .agent-core { width: clamp(150px, 22vh, 220px); height: clamp(150px, 22vh, 220px); }
.chat-hero-title { margin: 0; font-size: var(--text-hero); line-height: 1.25; font-weight: var(--weight-semibold); letter-spacing: -0.01em; }
.chat-start-form { margin: 12px 0 0; text-align: left; }
.composer-shell-hero .composer-input { min-height: 52px; }
.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.suggestion { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--border-default); background: var(--bg-surface); color: var(--text-secondary); font: inherit; font-size: var(--text-sm); font-weight: 500; cursor: pointer; transition: background-color var(--motion) ease, border-color var(--motion) ease; }
.suggestion .nav-icon { color: var(--accent-text); }
.suggestion.is-agent .nav-icon { color: var(--agent-text); }
.suggestion:hover { border-color: var(--accent-primary); color: var(--text-primary); }
.suggestion.is-agent:hover { border-color: var(--agent-primary); }
.welcome-suggestions { width: 100%; max-width: var(--composer-width); margin: 0 auto; padding: 4px 24px 20px; }

/* An empty dialogue centres the symbol, the question and the composer as one block.
   After the first message the column returns to the usual thread-over-composer layout. */
.chat-column[data-welcome="true"]:not(.is-started) { overflow-y: auto; }
.chat-column[data-welcome="true"]:not(.is-started) .chat-thread-scroll { flex: 0 0 auto; margin-top: auto; overflow: visible; }
.chat-column[data-welcome="true"]:not(.is-started) .chat-thread { padding-bottom: 12px; }
.chat-column[data-welcome="true"]:not(.is-started) .welcome-suggestions { margin-bottom: auto; }
.chat-column[data-welcome="true"].is-started .welcome-suggestions { display: none; }
.chat-column.is-started .chat-greeting { display: none; }
.chat-column.is-started .chat-composer { animation: composer-settle 0.25s var(--ease); }
@keyframes composer-settle { from { opacity: 0.4; transform: translateY(-12px); } to { opacity: 1; transform: none; } }

/* Model picker dialog */
.picker-filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 12px 20px; border-bottom: 1px solid var(--border-default); }
.picker-filters .ui-select { width: auto; min-width: 180px; }
.picker-list { padding: 10px; }
.picker-options { display: flex; flex-direction: column; gap: 4px; }
.picker-option { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border-radius: var(--radius-md); border: 1px solid transparent; }
.picker-option:hover { background: var(--hover-veil); }
.picker-option.is-selected { background: var(--accent-soft); border-color: var(--accent-primary); }
.picker-option.is-disabled { opacity: 0.62; }
.picker-option-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.picker-option-title { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.picker-option-title strong { font-size: 15px; font-weight: 600; }
.picker-option-desc { margin: 0; }
.picker-option-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.picker-option-warning { margin: 0; color: var(--status-warning); }

/* ==========================================================================
   16. Section pages (catalog, media, compare, landing, auth, errors)
   ========================================================================== */
.catalog-filters { padding: 16px; border-radius: var(--radius-lg); border: 1px solid var(--border-default); background: var(--bg-surface); box-shadow: var(--shadow-card); }
.catalog-filters .checkbox-row { margin-bottom: 0; padding: 8px 12px; }
.catalog-category { min-width: 0; padding: 4px 0 12px; }
.catalog-model-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); gap: 12px; }
.model-card { display: flex; flex-direction: column; padding: 18px; }
.model-card:hover { border-color: var(--accent-primary); }
.model-card .ui-card-header { border-bottom: 0; padding-bottom: 0; margin-bottom: 4px; }
.model-card .card-title { font-size: 16px; letter-spacing: -0.01em; }
.model-card .ui-state-box { border-style: solid; text-align: left; padding: 10px 12px; }
.model-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border-default); }
.compare-answer { margin: 10px 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }

.welcome-page { max-width: 980px; margin: 6vh auto 0; padding: 24px 0; text-align: center; }
.welcome-page h1 { max-width: 18ch; margin: 24px auto 16px; font-size: clamp(36px, 5.2vw, 62px); line-height: 1.06; letter-spacing: -0.01em; font-weight: 700; }
.welcome-description { max-width: 54ch; margin: 0 auto; color: var(--text-secondary); font-size: 17px; line-height: 1.65; }
.welcome-actions { justify-content: center; margin: 28px 0 56px; }
.welcome-features { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; text-align: left; }
.welcome-features > div { padding: 20px; border-radius: var(--radius-lg); background: var(--bg-surface); border: 1px solid var(--border-default); box-shadow: var(--shadow-card); }
.welcome-features .nav-icon { color: var(--accent-text); }
.welcome-features h2 { font-size: 15px; font-weight: 600; margin: 12px 0 6px; }
.welcome-features p { margin: 0; font-size: 14px; line-height: 1.6; color: var(--text-secondary); }
@media (max-width: 719px) { .welcome-features { grid-template-columns: 1fr; } .welcome-page { margin-top: 2vh; } }

.auth-page { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: calc(100% - 40px); padding: 24px 0; }
.app-content > .auth-page { max-width: 440px; }
.auth-card { width: 100%; padding: 28px 26px; border-radius: var(--radius-xl); }
.auth-card .auth-head { text-align: center; margin-bottom: 20px; }
.auth-card .auth-head .logo { margin: 0 auto 12px; }
.auth-card h1 { font-size: 23px; letter-spacing: -0.01em; margin-bottom: 6px; }
.auth-card .btn-block { width: 100%; margin-top: 6px; }
.auth-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px 16px; margin-top: 18px; font-size: 14px; color: var(--text-secondary); }

.error-page { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 10vh 0 0; }
.error-page .muted { max-width: 46ch; }
.error-page .row-wrap { justify-content: center; margin-top: 18px; }

.settings-section + .settings-section { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border-default); }
.settings-section h2 { font-size: 15px; margin-bottom: 12px; }
.btn-block { width: 100%; }

/* Account settings: 8px rhythm, 640px form column, focus-visible on every control */
.settings-page { max-width: 680px; }
.settings-page .settings-head { margin-bottom: 16px; }
.settings-page .settings-head h1 { margin-bottom: 4px; }
.settings-nav {
  display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 16px; margin-bottom: 8px;
  border-bottom: 1px solid var(--border-default);
}
.settings-nav a {
  display: inline-flex; align-items: center; min-height: 32px; padding: 4px 14px; border-radius: 999px;
  border: 1px solid var(--border-default); color: var(--text-secondary); font-size: 13px; text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.settings-nav a:hover { color: var(--text-primary); background: var(--hover-veil); text-decoration: none; }
.settings-page :is(a, button, input, label):focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

.settings-block { padding-top: 32px; scroll-margin-top: 24px; }
.settings-block + .settings-block { margin-top: 8px; border-top: 1px solid var(--border-default); }
.settings-block-title { margin: 0 0 4px; font-size: 16px; line-height: 1.35; font-weight: 600; }
.settings-block-desc { margin: 0 0 24px; font-size: 14px; color: var(--text-secondary); }
.settings-subtitle { margin: 24px 0 8px; font-size: 14px; font-weight: 600; color: var(--text-primary); }
.settings-page .field { margin-bottom: 24px; }
.settings-page .field:last-child { margin-bottom: 0; }
.settings-page .ui-field-hint { font-size: 13px; color: var(--text-secondary); margin-top: 8px; }
.settings-page .ui-field-error { font-size: 13px; color: var(--status-danger); margin: 8px 0 0; }
.settings-fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.settings-fieldset legend { display: block; padding: 0; margin-bottom: 8px; font-size: 14px; font-weight: 500; color: var(--text-primary); }

.segmented {
  display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; max-width: 100%;
  border: 1px solid var(--border-default); border-radius: var(--radius-sm); background: var(--bg-canvas);
}
.segmented-option { position: relative; margin: 0; cursor: pointer; }
.segmented-option input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.segmented-option span {
  display: block; min-height: 32px; padding: 6px 16px; border-radius: 6px;
  font-size: 14px; line-height: 20px; color: var(--text-secondary);
  transition: background-color 0.15s ease, color 0.15s ease;
}
.segmented-option:hover span { color: var(--text-primary); background: var(--hover-veil); }
.segmented-option:has(input:checked) span { background: var(--accent-primary); color: var(--accent-on); font-weight: 500; }
.segmented-option:has(input:focus-visible) span { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px; margin: 0 0 8px;
  border: 1px solid var(--border-default); border-radius: var(--radius-sm); background: var(--hover-veil);
  cursor: pointer; transition: border-color 0.15s ease;
}
.switch-row:hover { border-color: var(--border-strong); }
.switch-row:has(input:focus-visible) { border-color: var(--focus-ring); }
.switch-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; font-size: 14px; color: var(--text-primary); }
.switch-text strong { font-weight: 500; }
.switch-text .caption { font-size: 13px; color: var(--text-secondary); }
.settings-page input.switch,
.settings-page input[type="checkbox"][role="switch"] {
  appearance: none; -webkit-appearance: none; flex-shrink: 0; position: relative;
  width: 40px; height: 22px; margin: 0; border-radius: 999px; cursor: pointer;
  background: var(--border-strong); transition: background-color 0.15s ease;
}
.settings-page input[type="checkbox"][role="switch"]::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--bg-canvas); transition: transform 0.15s ease;
}
.settings-page input[type="checkbox"][role="switch"]:checked { background: var(--accent-primary); }
.settings-page input[type="checkbox"][role="switch"]:checked::after { transform: translateX(18px); background: var(--accent-on); }
.settings-page input[type="checkbox"][role="switch"]:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

.settings-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 16px; margin-top: 24px; }
.settings-status { font-size: 13px; color: var(--status-success); }

.settings-links { display: grid; gap: 8px; }
.settings-link {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px; border: 1px solid var(--border-default); border-radius: var(--radius-sm);
  background: var(--hover-veil); color: var(--text-primary); text-decoration: none;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.settings-link:hover { border-color: var(--border-strong); background: var(--active-veil); text-decoration: none; }
.settings-link:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.settings-link strong { display: block; font-size: 14px; font-weight: 500; }
.settings-link .caption { display: block; margin-top: 2px; font-size: 13px; color: var(--text-secondary); }
.settings-link-arrow { color: var(--text-muted); font-size: 16px; }

.settings-empty { padding: 16px; border: 1px dashed var(--border-default); border-radius: var(--radius-sm); }
.settings-empty p { margin: 0; }
.settings-empty .caption { margin-top: 4px; font-size: 13px; color: var(--text-secondary); }

/* Support page */
.support-page { display: grid; gap: 12px; }
.support-page .card + .card { margin-top: 0; }

/* Help center */
.help-page { display: grid; gap: 16px; }
.help-head h1 { margin: 0 0 4px; }
.help-quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.help-tile {
  display: grid; gap: 4px; padding: 16px; border-radius: var(--radius-lg);
  border: 1px solid var(--border-default); background: var(--hover-veil); color: var(--text-primary);
  text-decoration: none; transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.1s ease;
}
.help-tile:hover { border-color: var(--border-strong); background: var(--active-veil); text-decoration: none; }
.help-tile:active { transform: scale(0.99); }
.help-tile:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.help-tile strong { font-size: 14px; font-weight: 600; }
.help-tile .caption { font-size: 13px; color: var(--text-secondary); }
.help-tile-primary { background: var(--accent-primary); color: var(--accent-on); border-color: transparent; }
.help-tile-primary .caption { color: var(--accent-on); opacity: 0.75; }
.help-tile-primary:hover { background: var(--accent-primary-hover); border-color: transparent; }

.help-section h2 { margin: 0 0 12px; font-size: 16px; font-weight: 600; }
.help-faq { border-top: 1px solid var(--border-default); }
.help-faq:first-of-type { border-top: 0; }
.help-faq summary {
  display: grid; gap: 4px; padding: 14px 28px 14px 0; cursor: pointer; list-style: none;
  position: relative; color: var(--text-primary);
}
.help-faq summary::-webkit-details-marker { display: none; }
.help-faq summary::after {
  content: ""; position: absolute; right: 4px; top: 50%; width: 8px; height: 8px;
  border-right: 1.5px solid var(--text-secondary); border-bottom: 1.5px solid var(--text-secondary);
  transform: translateY(-70%) rotate(45deg); transition: transform 0.15s ease;
}
.help-faq[open] summary::after { transform: translateY(-30%) rotate(-135deg); }
.help-faq summary:hover .help-faq-question { color: var(--focus-ring); }
.help-faq summary:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: 6px; }
.help-faq-section {
  justify-self: start; padding: 2px 8px; border-radius: 6px; font-size: 13px; font-weight: 500;
  background: var(--accent-soft); color: var(--text-secondary);
}
.help-faq-question { font-size: 15px; font-weight: 600; line-height: 1.4; }
.help-faq-answer { margin: 0 0 16px; font-size: 15px; line-height: 1.65; color: var(--text-secondary); max-width: 72ch; }

.help-table-wrap { overflow-x: auto; }
.help-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.help-table th {
  text-align: left; padding: 8px 12px; font-size: 13px; font-weight: 600; color: var(--text-secondary);
  border-bottom: 1px solid var(--border-default);
}
.help-table td { padding: 12px; vertical-align: top; border-bottom: 1px solid var(--border-default); }
.help-table tbody tr:last-child td { border-bottom: 0; }
.help-table td p { margin: 4px 0 0; }
.help-table code { font-size: 13px; }
@media (max-width: 640px) {
  .help-table thead { display: none; }
  .help-table, .help-table tbody, .help-table tr, .help-table td { display: block; width: 100%; }
  .help-table tr { padding: 12px 0; border-bottom: 1px solid var(--border-default); }
  .help-table td { border: 0; padding: 4px 0; }
}

/* ==========================================================================
   17. Density, motion, responsive
   ========================================================================== */
:root[data-density="compact"] .chat-thread { gap: 10px; }
:root[data-density="compact"] .ui-card, :root[data-density="compact"] .card { padding: 14px; }
:root[data-density="compact"] .conv-item, :root[data-density="compact"] .sidebar-link { min-height: 30px; padding-top: 4px; padding-bottom: 4px; }
:root[data-density="compact"] .app-content:not(.app-content-fill) { padding-top: 16px; }

@media (max-width: 767px) {
  .app-content:not(.app-content-fill) { padding: 16px 12px 56px; }
  .chat-thread { padding: 10px 12px 16px; }
  .chat-composer { padding: 4px 8px calc(8px + env(safe-area-inset-bottom, 0px)); }
  .app-modal { width: 100vw; max-height: 94dvh; margin: auto 0 0; }
  .app-modal-frame { max-height: 94dvh; border-radius: var(--radius-xl) var(--radius-xl) 0 0; }
  .app-modal-search { margin-top: auto; }
  .app-modal-body { padding: 16px 14px; }
  .composer-hint:not([role="status"]) { display: none; }
  .chat-app:not([data-layout]) .model-trigger-provider { display: none; }
  .btn, .icon-btn, .sidebar-link, .sidebar-search, .conv-item, .menu-item, .pane-tab, .section-tab { min-height: 44px; }
  .grounding .btn-xs, .version-chip { min-height: 36px; }
  .conv-row-action.icon-btn { min-width: 44px; }
  .icon-btn { width: 44px; height: 44px; }
  .icon-btn-sm { width: 36px; height: 36px; min-height: 36px; }
  .btn-sm { min-height: 38px; }
  .btn { max-width: 100%; white-space: normal; text-align: center; }
  .composer-pill, .suggestion, .pane-subtab, .header-model { min-height: 44px; height: auto; }
  .chat-topbar { min-height: 56px; padding: 6px 8px 6px 12px; }
  .chat-chips .tag, .chat-chips .context-chip, .chat-chips .mode-chip + .mode-chip { display: none; }
  .header-model span { display: none; }
  .composer-bar { flex-wrap: wrap; }
  .composer-bar-group:last-child { margin-left: auto; }
  .model-trigger { height: 44px; max-width: 150px; }
  .send-btn { width: 44px; height: 44px; }
  .welcome-suggestions { padding-inline: 10px; }
  .chat-hero > .agent-core, .chat-greeting > .agent-core { width: 128px; height: 128px; }
  .ui-input, .ui-select, .composer-input, .search-dialog-input { font-size: 16px; }
}
@media (max-width: 400px) {
  .balance-pill .nav-icon { display: none; }
  .balance-pill { padding: 0 8px; }
}

@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; }
}
@media (prefers-reduced-transparency: reduce) {
  .app-modal::backdrop { -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media print {
  .mobile-bar, .app-sidebar, .side-panel, .chat-composer, .ui-toast-region { display: none !important; }
  .app-frame, .app-shell, .app-content, .chat-thread-scroll { height: auto; overflow: visible; }
}

/* ==========================================================================
   18. Composer extras, artifact editor, share and builder sections (ADR-055)
   ========================================================================== */
.composer-extras { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 8px; }
.composer-extras-inline { display: inline-flex; flex-wrap: nowrap; align-items: center; gap: 6px; min-width: 0; }
.composer-extras-inline .composer-select select { max-width: 150px; }
.composer-attach-menu { min-width: 260px; display: flex; flex-direction: column; gap: 8px; padding: 8px; }
.composer-attach-base { width: 100%; justify-content: space-between; border-radius: var(--radius-sm); min-height: 40px; padding: 0 10px; }
.composer-attach-base select { flex: 1 1 auto; max-width: none; min-width: 0; }
.kb-picker { display: flex; flex-direction: column; gap: 6px; padding: 8px 4px 4px; border-top: 1px solid var(--border-default); margin-top: 4px; }
.kb-picker.is-disabled { opacity: 0.55; }
.kb-picker-title { margin: 0 6px; font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); }
.kb-list { display: flex; flex-direction: column; gap: 2px; max-height: 240px; overflow-y: auto; }
.kb-option { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; min-height: 36px; padding: 6px 10px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-primary); font: inherit; font-size: var(--text-sm); text-align: left; cursor: pointer; }
.kb-option:hover:not(:disabled) { background: var(--bg-surface-subtle); }
.kb-option:disabled { cursor: not-allowed; color: var(--text-muted); }
.kb-option.is-selected { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.kb-option.is-selected::after { content: "✓"; font-weight: 700; }
.composer-select { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 34px; padding: 0 6px 0 10px; border: 1px solid var(--border-default); border-radius: 999px; background: var(--bg-surface); color: var(--text-secondary); font-size: var(--text-xs); font-weight: 600; }
.composer-select:focus-within { border-color: var(--accent-primary); }
.composer-select select, .composer-select input { max-width: 190px; min-height: 28px; border: 0; background: transparent; color: var(--text-primary); font: inherit; }
.composer-select input { width: 110px; }
.composer-select select[name="presentation_image_model"] { max-width: 320px; }
.composer-select select option { background: var(--bg-elevated); }
.composer-select:has(select:disabled) { opacity: 0.5; }
.artifact-editor { margin-top: 12px; }
.artifact-editor > summary { display: inline-flex; list-style: none; }
.artifact-editor > summary::-webkit-details-marker { display: none; }
.artifact-editor[open] > summary { margin-bottom: 8px; }
.artifact-original { margin-top: 12px; padding-top: 8px; border-top: 1px solid var(--border-default); }
.artifact-original > summary { cursor: pointer; color: var(--text-secondary); font-size: var(--text-sm); }
.share-days { width: auto; }
/* Skill library: six categories, each skill expandable to its full instructions. */
.skill-library { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 12px; }
.skill-category { display: flex; flex-direction: column; gap: 8px; }
.skill-category-title { display: flex; align-items: center; gap: 8px; margin: 0; font-size: var(--text-section); font-weight: var(--weight-semibold); }
.skill-category-title .nav-icon { color: var(--agent-text); }
.skill-list { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
.skill-item { display: flex; align-items: flex-start; gap: 8px; padding: 8px 0; border-top: 1px solid var(--border-default); }
.skill-item > details { flex: 1; min-width: 0; }
.skill-item summary { display: flex; flex-direction: column; cursor: pointer; list-style: none; }
.skill-item summary::-webkit-details-marker { display: none; }
.skill-item-name { font-weight: var(--weight-medium); }
.skill-item summary:hover .skill-item-name, .skill-item details[open] .skill-item-name { color: var(--accent-text); }
.skill-instructions { margin-top: 8px; max-height: 260px; overflow-y: auto; white-space: pre-wrap; color: var(--text-secondary); font-size: var(--text-sm); }
.export-links { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.share-result { padding: 12px; border: 1px solid var(--accent-primary); border-radius: var(--radius-lg); background: var(--accent-soft); }
/* Public page of a shared dialogue: the conversation, and its materials beside it on wide screens. */
.shared-layout { display: grid; grid-template-columns: minmax(0, 1fr); width: 100%; max-width: var(--chat-column); margin: 0 auto; }
.shared-layout.has-aside { max-width: calc(var(--chat-column) + 360px); }
.shared-page .chat-thread { padding-bottom: 48px; }
.shared-page [data-copy-code] { display: none; }
.shared-aside { display: flex; flex-direction: column; gap: 12px; min-width: 0; padding: 20px 20px 48px; }
.shared-aside .panel-card + .panel-card { margin-top: 0; }
@media (min-width: 1100px) {
  .shared-layout.has-aside { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
  .shared-layout.has-aside .shared-aside { position: sticky; top: 56px; max-height: calc(100dvh - 56px); overflow-y: auto; }
}
.shared-block { padding: 8px 12px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-surface); }
.shared-block > summary { display: flex; align-items: center; gap: 8px; min-height: 28px; font-weight: var(--weight-semibold); cursor: pointer; }
.shared-block > :not(summary) { margin-top: 8px; }
.shared-block > summary::after { content: "+"; margin-left: auto; color: var(--text-muted); }
.shared-block[open] > summary::after { content: "−"; }
.builder-section { display: flex; flex-direction: column; gap: 8px; min-width: 0; margin: 0; padding: 12px; border: 1px solid var(--border-default); border-radius: var(--radius-md); }
.builder-section legend { padding: 0 6px; font-size: var(--text-sm); font-weight: 700; }
@media (max-width: 767px) { .composer-select { min-height: 44px; } .composer-select select, .composer-select input { font-size: 16px; } }
@container chat (max-width: 880px) { .chat-chips .context-chip { display: none; } }
.chat-topbar .share-button { display: none; }
@media (min-width: 900px) { .chat-topbar .share-button { display: inline-flex; } }

/* ==========================================================================
   19. Numbers and technical text
   ========================================================================== */
/* Measured values and money: JetBrains Mono, tabular figures. */
.execution-meta, .timeline-time, .chat-msg-cost, .fact-list dd, .tag-price, .file-text {
  font-family: var(--font-mono); font-size: var(--text-technical); font-variant-numeric: tabular-nums;
}
.balance-pill, .context-chip, .stat-value, .chat-msg-time, .pane-tab-count, .ui-table td, .chat-table td { font-variant-numeric: tabular-nums; }
@media (max-width: 767px) { :root { --text-hero: 26px; } }
@container chat (max-width: 820px) {
  .chat-topbar .share-button { gap: 0; width: 36px; padding: 0; font-size: 0; }
  .chat-topbar .header-model span { max-width: 104px; }
}

/* ---------- Image gallery (ADR-066) ---------- */
.gallery-page { display: flex; flex-direction: column; gap: var(--space-6); width: 100%; max-width: 1280px; margin: 0 auto; }
.gallery-head { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-end; justify-content: space-between; }
.gallery-head .muted { max-width: 62ch; margin: 0; }
.gallery-composer { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-4); }
.gallery-prompt { width: 100%; min-height: 84px; resize: vertical; border: 0; background: transparent; color: var(--text-primary); font: inherit; font-size: 16px; line-height: 1.55; padding: 4px 2px; }
.gallery-prompt:focus { outline: none; }
.gallery-composer:focus-within { border-color: var(--accent-primary); }
.gallery-controls { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-end; border-top: 1px solid var(--border-default); padding-top: var(--space-3); }
.gallery-control { display: flex; flex-direction: column; gap: 4px; min-width: 140px; flex: 1 1 150px; }
.gallery-control > span { font-size: var(--text-xs); font-weight: 600; color: var(--text-muted); }
.gallery-control-wide { flex: 2 1 260px; }
.gallery-control-narrow { flex: 0 0 96px; min-width: 96px; }
.gallery-submit { margin-left: auto; }
.gallery-grid { list-style: none; margin: 0; padding: 0; columns: 4 260px; column-gap: var(--space-4); }
.gallery-card { break-inside: avoid; margin: 0 0 var(--space-4); border: 1px solid var(--border-default); border-radius: 16px; overflow: hidden; background: var(--bg-surface); box-shadow: var(--shadow-card); transition: transform 0.18s ease, box-shadow 0.18s ease; }
.gallery-card:hover, .gallery-card:focus-within { transform: translateY(-2px); box-shadow: var(--shadow-popover); }
.gallery-image { display: block; width: 100%; padding: 0; border: 0; background: var(--bg-surface-subtle); cursor: zoom-in; }
.gallery-image img { display: block; width: 100%; height: auto; }
.gallery-missing { display: none; flex-direction: column; gap: var(--space-2); align-items: center; justify-content: center; aspect-ratio: 4 / 3; padding: var(--space-4); color: var(--text-muted); font-size: var(--text-sm); text-align: center; }
.gallery-card.is-missing .gallery-image { cursor: default; }
.gallery-card.is-missing img { display: none; }
.gallery-card.is-missing .gallery-missing { display: flex; }
.gallery-caption { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-3); }
.gallery-prompt-text { margin: 0; font-size: var(--text-base); font-weight: 600; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.gallery-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; font-size: var(--text-xs); color: var(--text-muted); }
.gallery-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.gallery-empty { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); padding: 48px var(--space-4); color: var(--text-muted); }
.gallery-history > summary { cursor: pointer; }
.lightbox-body { display: flex; flex-direction: column; gap: var(--space-3); align-items: center; }
.lightbox-body img { max-width: 100%; max-height: 64vh; border-radius: 12px; object-fit: contain; }
.lightbox-prompt { margin: 0; max-width: 80ch; text-align: center; }
@media (max-width: 640px) {
  .gallery-grid { columns: 1; }
  .gallery-submit { margin-left: 0; width: 100%; justify-content: center; }
  .gallery-control, .gallery-control-wide { flex-basis: 100%; }
}

/* Pictures in chat: thumbnails in messages and in the composer, one viewer for all of them. */
.chat-attachment-thumb { display: inline-block; padding: 0; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-surface-subtle); cursor: zoom-in; overflow: hidden; }
.chat-attachment-thumb img { display: block; max-width: 220px; max-height: 160px; object-fit: cover; }
.composer-attachment-thumb { flex: 0 0 auto; width: 40px; height: 40px; padding: 0; border: 0; border-radius: var(--radius-sm); overflow: hidden; cursor: zoom-in; }
.composer-attachment-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.composer-attachment-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 6px; flex: 1 1 auto; min-width: 0; }
.composer-attachment-list:empty { display: none; }
.composer-attachment-count { font-size: 0.8125rem; color: var(--text-secondary); white-space: nowrap; margin-top: 10px; }
.composer-attachment-chip { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 4px; border: 1px solid var(--border-default); border-radius: var(--radius-sm); background: var(--bg-surface); }
.composer-attachment-media { flex: 0 0 40px; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-surface-subtle); }
.composer-attachment-media .composer-attachment-thumb { width: 100%; height: 100%; }
.composer-attachment-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.composer-attachment-ext { font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.02em; color: var(--accent-blue, #3459ED); text-transform: uppercase; }
.composer-attachment-chip .composer-file { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.8125rem; }
.composer-attachment-chip .icon-btn { flex-shrink: 0; }
.file-image { margin: 0 0 12px; }
.file-image-button { display: block; padding: 0; border: 1px solid var(--border-default); border-radius: var(--radius-md); overflow: hidden; background: var(--bg-surface-subtle); cursor: zoom-in; max-width: 100%; }
.file-image-button img { display: block; width: 100%; height: auto; }
.image-lightbox { width: min(96vw, 1100px); max-height: 92vh; padding: 12px 16px; border: 1px solid var(--border-default); border-radius: var(--radius-lg); background: var(--bg-surface); color: var(--text-primary); }
.image-lightbox::backdrop { background: rgba(0, 0, 0, 0.72); }
.image-lightbox-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.image-lightbox-bar .caption { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.image-lightbox-bar form { margin: 0; }
.image-lightbox-stage { max-height: 72vh; overflow: auto; text-align: center; cursor: zoom-in; }
.image-lightbox-stage img { display: inline-block; max-width: 100%; height: auto; border-radius: var(--radius-sm); }
.image-lightbox-stage.is-zoomed { cursor: zoom-out; }
.image-lightbox-stage.is-zoomed img { max-width: none; width: auto; }

/* Notification settings: one row per category, label | channels | save, aligned in columns. */
.notify-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 8px 16px; padding: 8px 0; border-bottom: 1px solid var(--border-default); }
.notify-row:last-of-type { border-bottom: 0; }
.notify-label { min-width: 0; overflow-wrap: anywhere; }
.notify-channels { display: flex; gap: 14px; align-items: center; }
.notify-check { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-sm); white-space: nowrap; cursor: pointer; }
.notify-save { min-width: 116px; justify-self: end; }
@media (max-width: 560px) { .notify-row { grid-template-columns: 1fr; } .notify-save { justify-self: start; } }

/* Projects list: header, summary strip, card grid with the create form beside it. */
.projects-page { max-width: 1200px; }
.projects-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px 20px; }
.projects-head-text { min-width: 0; flex: 1 1 360px; }
.projects-head-text .page-title { margin-bottom: 4px; }
.projects-head-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.projects-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.projects-stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 14px 16px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-surface); }
.projects-stat strong { font-size: 1rem; line-height: 1.35; overflow-wrap: anywhere; }
.projects-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 340px); gap: 20px; align-items: start; }
.projects-main, .projects-side { min-width: 0; }
.projects-side { position: sticky; top: 16px; }
.projects-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin: 0; padding: 0; list-style: none; }
.projects-card { display: flex; flex-direction: column; gap: 8px; height: 100%; padding: 16px; color: inherit; text-decoration: none; transition: border-color 0.15s ease; }
.projects-card:hover, .projects-card:focus-visible { border-color: var(--accent-blue, #3459ED); }
.projects-card-title { font-weight: 600; overflow-wrap: anywhere; }
.projects-card-desc { font-size: 0.875rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.projects-card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: auto; }
.projects-card-counts { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.projects-empty { display: flex; flex-direction: column; gap: 4px; padding: 20px; }
.projects-details { padding: 12px 16px; }
.projects-details summary { cursor: pointer; font-weight: 600; }
.projects-details .table-wrap { margin-top: 10px; }
.projects-select { width: 100%; min-width: 0; text-overflow: ellipsis; }
@media (max-width: 960px) {
  .projects-layout { grid-template-columns: minmax(0, 1fr); }
  .projects-side { position: static; }
}
@media (max-width: 600px) {
  .projects-grid { grid-template-columns: minmax(0, 1fr); }
}

/* The attachment strip spans the composer width; the clip sits left of the file tiles. */
.composer-attachment-preview { width: 100%; align-items: flex-start; }

/* Sidebar groups: headings, the collapsible recent chats, nested items and the archive link. */
.sidebar-nav .sidebar-section-label { margin-top: var(--space-3); }
.sidebar-nav .sidebar-section-label:first-child { margin-top: var(--space-1); }
.sidebar-link.is-sub { padding-left: 30px; }
.sidebar-recent { display: flex; flex-direction: column; gap: 1px; }
.sidebar-recent-summary { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: var(--radius-sm); font-size: 14px; color: var(--text-secondary); cursor: pointer; list-style: none; }
.sidebar-recent-summary::-webkit-details-marker { display: none; }
.sidebar-recent-summary:hover { background: var(--hover-veil); color: var(--text-primary); }
.sidebar-recent-summary .sidebar-label { flex: 1 1 auto; }
.sidebar-recent[open] > .sidebar-recent-summary .sidebar-project-chevron { transform: rotate(180deg); }
.sidebar-recent .sidebar-history { margin-top: 0; padding-top: 0; border-top: 0; }
.sidebar-bottom { margin-top: var(--space-3); padding-top: var(--space-2); border-top: 1px solid var(--border-default); }
.app-sidebar.is-collapsed :is(.sidebar-section-label, .sidebar-recent, .sidebar-bottom .sidebar-label, .sidebar-projects) { display: none; }

/* Chat project page: title with edit buttons, instructions, chats list and the files panel. */
.project-title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }
.project-title-row .page-title { margin: 0; overflow-wrap: anywhere; }
.project-instructions { margin: 0; white-space: pre-line; font-size: 0.875rem; overflow-wrap: anywhere; }
.project-chat-list { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.project-chat-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; color: inherit; text-decoration: none; }
.project-chat-item:hover, .project-chat-item:focus-visible { border-color: var(--accent-blue, #3459ED); }
.project-chat-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.project-files-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.project-file-list { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.project-file-row { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 6px 8px; border: 1px solid var(--border-default); border-radius: var(--radius-sm); }
.project-file-row form { display: flex; flex-shrink: 0; margin: 0; }
.project-file-ext { flex-shrink: 0; min-width: 40px; text-align: center; font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.02em; color: var(--accent-blue, #3459ED); text-transform: uppercase; }
.project-file-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.875rem; }
.project-chat-list > li { display: block; width: 100%; }
.project-chat-item { width: 100%; box-sizing: border-box; }
.sidebar-bottom-recent { display: flex; flex-direction: column; margin-top: var(--space-2); padding-top: var(--space-2); border-top: 1px solid var(--border-default); }

/* Sidebar projects: each project folds open to its own «new chat», chats and settings pencil. */
.sidebar-project-summary { display: flex; align-items: center; gap: 4px; min-width: 0; padding: 6px 10px; border-radius: var(--radius-sm); font-size: 14px; color: var(--text-secondary); cursor: pointer; list-style: none; }
.sidebar-project-summary::-webkit-details-marker { display: none; }
.sidebar-project-summary:hover { background: var(--hover-veil); color: var(--text-primary); }
.sidebar-project-summary .sidebar-project-name { flex: 1 1 auto; }
.sidebar-project-edit { flex-shrink: 0; opacity: 0.7; }
.sidebar-project-edit:hover, .sidebar-project-edit:focus-visible { opacity: 1; }
.sidebar-project-new { display: flex; margin: 0; }
.sidebar-project-new-btn { width: 100%; border: 0; background: none; cursor: pointer; text-align: left; font: inherit; }
.sidebar-project-chat .sidebar-project-name { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-project .sidebar-project-links { padding-left: var(--space-3); }

/* Sidebar project rows: header with fold toggle, «+» and pencil; chats fold under it. */
.sidebar-project { display: flex; flex-direction: column; gap: 1px; }
.sidebar-project-head { display: flex; align-items: center; gap: 2px; min-width: 0; }
.sidebar-project-toggle { flex: 1 1 auto; display: flex; align-items: center; gap: 6px; min-width: 0; padding: 6px 8px; border: 0; border-radius: var(--radius-sm); background: none; color: var(--text-secondary); font: inherit; font-size: 14px; text-align: left; cursor: pointer; }
.sidebar-project-toggle:hover { background: var(--hover-veil); color: var(--text-primary); }
.sidebar-project-toggle .sidebar-project-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-project-toggle .sidebar-project-chevron { flex-shrink: 0; transition: transform var(--motion) var(--ease); }
.sidebar-project-toggle[aria-expanded="true"] .sidebar-project-chevron { transform: rotate(180deg); }
.sidebar-project-new, .sidebar-project-edit { flex-shrink: 0; margin: 0; }
.sidebar-project-links { display: flex; flex-direction: column; gap: 1px; padding-left: 0; }
.sidebar-project-links[hidden] { display: none; }
.sidebar-project-links .conv-row-action.icon-btn { opacity: 1; }

/* Chat project page: hero card, instructions, chat cards, drop zone for files. */
.project-page { gap: var(--space-4, 16px); }
.project-back { align-self: flex-start; text-decoration: none; }
.project-hero { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px; border: 1px solid var(--border-default); border-radius: var(--radius-lg); background: var(--bg-surface); }
.project-hero-main { display: flex; gap: 16px; min-width: 0; flex: 1 1 360px; }
.project-hero-icon { flex-shrink: 0; display: grid; place-items: center; width: 52px; height: 52px; border-radius: var(--radius-md); background: var(--accent-soft); color: var(--accent-blue, #3459ED); }
.project-hero-text { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.project-hero-text .page-title { margin: 0; font-size: 1.5rem; overflow-wrap: anywhere; }
.project-hero-desc { margin: 0; color: var(--text-secondary); overflow-wrap: anywhere; }
.project-hero-add { align-self: flex-start; padding: 0; border: 0; background: none; color: var(--accent-blue, #3459ED); font: inherit; font-size: 0.875rem; cursor: pointer; }
.project-hero-add:hover { text-decoration: underline; }
.project-stats { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 4px; font-size: 0.875rem; color: var(--text-secondary); }
.project-stat strong { color: var(--text-primary); }
.project-hero-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.project-hero-actions form { margin: 0; }
.project-instructions-card { display: flex; flex-direction: column; gap: 6px; padding: 14px 16px; border-left: 3px solid var(--accent-blue, #3459ED); border-radius: var(--radius-md); background: var(--bg-surface-subtle); }
.project-instructions-label { font-size: 0.75rem; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase; color: var(--text-muted); }
.project-instructions-card .project-instructions { margin: 0; font-size: 0.9375rem; line-height: 1.5; }
.project-instructions-card .project-hero-add { margin-top: 2px; }
.project-instructions-empty { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 16px; border: 1px dashed var(--border-default); border-radius: var(--radius-md); background: none; color: var(--text-secondary); font: inherit; text-align: left; cursor: pointer; }
.project-instructions-empty:hover { border-color: var(--accent-blue, #3459ED); color: var(--text-primary); }
.project-instructions-empty small { display: block; color: var(--text-muted); }
.project-section-head { display: flex; align-items: baseline; justify-content: space-between; }
.project-chat-list { gap: 8px; }
.project-chat-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-surface); color: inherit; text-decoration: none; transition: border-color 0.15s ease, background 0.15s ease; }
.project-chat-item:hover, .project-chat-item:focus-visible { border-color: var(--accent-blue, #3459ED); background: var(--bg-surface-subtle); }
.project-chat-icon { flex-shrink: 0; display: grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent-blue, #3459ED); }
.project-chat-body { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; gap: 2px; }
.project-chat-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.project-chat-arrow { color: var(--text-muted); transition: transform 0.15s ease; }
.project-chat-item:hover .project-chat-arrow { transform: translateX(3px); color: var(--accent-blue, #3459ED); }
.project-empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 32px 20px; border: 1px dashed var(--border-default); border-radius: var(--radius-lg); text-align: center; color: var(--text-secondary); }
.project-empty-icon { display: grid; place-items: center; width: 56px; height: 56px; margin-bottom: 4px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-blue, #3459ED); }
.project-empty form { margin-top: 6px; }
.project-files-card { display: flex; flex-direction: column; gap: 12px; padding: 16px; border: 1px solid var(--border-default); border-radius: var(--radius-lg); background: var(--bg-surface); }
.project-files-card .project-files-head { align-items: baseline; }
.project-meter { width: 100%; height: 6px; border: 0; border-radius: 999px; overflow: hidden; appearance: none; -webkit-appearance: none; background: var(--bg-surface-subtle); }
.project-meter::-webkit-progress-bar { background: var(--bg-surface-subtle); }
.project-meter::-webkit-progress-value { background: var(--accent-blue, #3459ED); border-radius: 999px; }
.project-meter::-moz-progress-bar { background: var(--accent-blue, #3459ED); }
.project-files-card .project-file-list { gap: 6px; }
.project-dropzone { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 20px 16px; border: 1.5px dashed var(--border-default); border-radius: var(--radius-md); background: var(--bg-surface-subtle); text-align: center; transition: border-color 0.15s ease, background 0.15s ease; }
.project-dropzone:hover, .project-dropzone:focus-within { border-color: var(--accent-blue, #3459ED); }
.project-dropzone-input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.project-dropzone-icon { display: grid; place-items: center; width: 40px; height: 40px; margin-bottom: 4px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-blue, #3459ED); }
.project-dropzone-submit { margin-top: 8px; position: relative; z-index: 1; }
.project-files-note { margin: 0; }

/* Chat: the composer floats over the feed once a conversation has started; the feed scrolls
   beneath it, behind a soft blur (no gradients, per DESIGN_SYSTEM). */
.chat-column.is-started > .chat-composer {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 6;
  padding-top: 12px;
  background: color-mix(in srgb, var(--bg-surface) 82%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.chat-column.is-started > .chat-thread-scroll { padding-bottom: 150px; }

/* Files and knowledge bases: upload dropzone, document cards and knowledge base cards. */
.files-page, .kb-page { gap: 16px; }
.files-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px 20px; }
.files-head-text { min-width: 0; flex: 1 1 360px; }
.files-head-text .page-title { margin: 0 0 4px; }
.files-head-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.files-upload { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 16px; border: 1px solid var(--border-default); border-radius: var(--radius-lg); background: var(--bg-surface); }
.files-dropzone { position: relative; display: flex; align-items: center; gap: 14px; padding: 18px 20px; border: 1.5px dashed var(--border-default); border-radius: var(--radius-md); background: var(--bg-surface-subtle); cursor: pointer; transition: border-color 0.15s ease; }
.files-dropzone:hover, .files-dropzone:focus-within { border-color: var(--accent-blue, #3459ED); }
.files-dropzone-input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.files-dropzone-icon { flex-shrink: 0; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-blue, #3459ED); }
.files-dropzone-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.files-upload-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)) auto; align-items: end; gap: 12px; }
.files-upload-options .field-group { min-width: 0; }
.files-projects { display: flex; flex-direction: column; gap: 8px; }
.files-project-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.files-project-chip { padding: 5px 12px; border: 1px solid var(--border-default); border-radius: 999px; background: var(--bg-surface); color: var(--text-secondary); font-size: 0.875rem; text-decoration: none; }
.files-project-chip:hover { border-color: var(--accent-blue, #3459ED); color: var(--text-primary); }
.files-list-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.files-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin: 0; padding: 0; list-style: none; }
.file-card { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 14px 16px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-surface); }
.file-card-ext { display: grid; place-items: center; width: 48px; height: 48px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent-blue, #3459ED); font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; }
.file-card-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.file-card-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-card-meta { overflow-wrap: anywhere; }
.file-card-badges { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.file-card-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 6px; }
.file-card-actions form { margin: 0; }
.files-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 32px 20px; border: 1px dashed var(--border-default); border-radius: var(--radius-lg); text-align: center; color: var(--text-secondary); }
.files-empty-icon { display: grid; place-items: center; width: 56px; height: 56px; margin-bottom: 4px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-blue, #3459ED); }
.kb-create { display: flex; flex-direction: column; gap: 14px; padding: 18px; border: 1px solid var(--border-default); border-radius: var(--radius-lg); background: var(--bg-surface); }
.kb-create-head { display: flex; align-items: center; gap: 12px; }
.kb-create-head > div { display: flex; flex-direction: column; gap: 2px; }
.kb-create-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.kb-create-fields .field-group { min-width: 0; }
.kb-create-actions { display: flex; justify-content: flex-end; }
.kb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin: 0; padding: 0; list-style: none; }
.kb-card { display: flex; flex-direction: column; gap: 14px; padding: 16px; border: 1px solid var(--border-default); border-radius: var(--radius-lg); background: var(--bg-surface); }
.kb-card-head { display: flex; align-items: flex-start; gap: 12px; min-width: 0; }
.kb-card-icon { flex-shrink: 0; display: grid; place-items: center; width: 40px; height: 40px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent-blue, #3459ED); }
.kb-card-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kb-card-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-card-facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; }
.kb-card-facts > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 8px; border-radius: var(--radius-sm); background: var(--bg-surface-subtle); }
.kb-card-facts dt { font-size: 0.75rem; color: var(--text-muted); }
.kb-card-facts dd { margin: 0; font-size: 0.8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-card-open { align-self: flex-start; margin-top: auto; }
@media (min-width: 900px) {
  .files-grid { gap: 10px; }
}
@media (max-width: 720px) {
  .file-card { grid-template-columns: auto minmax(0, 1fr); }
  .file-card-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .files-upload-options { grid-template-columns: minmax(0, 1fr); }
}

/* Sidebar project row: folder icon, name toggles the chats; «+» and pencil show on hover. */
.sidebar-project-icon { flex-shrink: 0; display: inline-flex; color: var(--text-muted); }
.sidebar-project-head .icon-btn { opacity: 0; transition: opacity var(--motion) ease; }
.sidebar-project-head:hover .icon-btn, .sidebar-project-head:focus-within .icon-btn { opacity: 1; }
.sidebar-project-toggle[aria-expanded="false"] .sidebar-project-icon { color: var(--text-secondary); }

/* The whole project row is grey on hover, not only the name. */
.sidebar-project-head { border-radius: var(--radius-sm); }
.sidebar-project-head:hover, .sidebar-project-head:focus-within { background: var(--hover-veil); }
.sidebar-project-head:hover .sidebar-project-toggle, .sidebar-project-toggle:hover { background: transparent; color: var(--text-primary); }

/* Knowledge base form: embedding models as a radio list of cards. */
.kb-model-picker { margin: 0; padding: 0; border: 0; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.kb-model-picker legend { padding: 0; margin-bottom: 6px; }
.kb-model-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.kb-model-option { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 10px 12px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-surface); cursor: pointer; transition: border-color 0.15s ease, background 0.15s ease; }
.kb-model-option:hover { border-color: var(--accent-blue, #3459ED); }
.kb-model-option:has(input:checked) { border-color: var(--accent-blue, #3459ED); background: var(--accent-soft); }
.kb-model-option input { flex-shrink: 0; margin: 0; accent-color: var(--accent-blue, #3459ED); }
.kb-model-option-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 auto; }
.kb-model-option-body strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-model-option-slug { flex-shrink: 0; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Sidebar «Проекты» header: title link, fold chevron, sort and new-project buttons on one row. */
.sidebar-projects-head { display: flex; align-items: center; gap: 2px; margin-top: var(--space-2); padding: 0 4px 0 0; min-width: 0; }
.sidebar-projects-title { flex: 1 1 auto; display: flex; align-items: center; min-width: 0; padding: 6px 10px; border-radius: var(--radius-sm); color: var(--text-secondary); font-size: 14px; font-weight: 600; text-decoration: none; }
.sidebar-projects-title:hover { background: var(--hover-veil); color: var(--text-primary); }
.sidebar-projects-title[aria-current="page"] { color: var(--accent-text); }
.sidebar-projects-head .icon-btn { flex-shrink: 0; }
.sidebar-projects-fold { transition: transform var(--motion) var(--ease); }
.sidebar-projects-fold[aria-expanded="false"] { transform: rotate(-90deg); }
#projects-sort-menu { min-width: 220px; }
#projects-sort-menu .menu-item.is-active { color: var(--accent-text); font-weight: 600; }
.app-sidebar.is-collapsed .sidebar-projects-head { display: none; }

/* Projects page: sort chips. */
.projects-sort { display: flex; flex-wrap: wrap; gap: 6px; }
.projects-sort-chip { padding: 5px 12px; border: 1px solid var(--border-default); border-radius: 999px; background: var(--bg-surface); color: var(--text-secondary); font-size: 0.8125rem; text-decoration: none; }
.projects-sort-chip:hover { border-color: var(--accent-blue, #3459ED); color: var(--text-primary); }
.projects-sort-chip.is-active { border-color: var(--accent-blue, #3459ED); background: var(--accent-soft); color: var(--accent-text); }

/* Sidebar «Проекты»: the whole row is one grey target; clicking the title folds the list; no divider. */
.sidebar-projects-head { border-radius: var(--radius-sm); }
.sidebar-projects-head:hover, .sidebar-projects-head:focus-within { background: var(--hover-veil); }
.sidebar-projects-title { flex: 1 1 auto; display: flex; align-items: center; min-width: 0; padding: 6px 10px; border: 0; background: none; color: var(--text-secondary); font: inherit; font-size: 14px; font-weight: 600; text-align: left; cursor: pointer; }
.sidebar-projects-head:hover .sidebar-projects-title { color: var(--text-primary); }
.sidebar-projects { border-top: 0; margin-top: 0; padding-top: 0; }

/* Dialog actions get the same inset as the header and body, so buttons do not touch the edge. */
.app-modal-frame > .confirm-actions { padding: 12px 20px 18px; }

/* One grey only: the row's hover background. The title button adds no second shade. */
.sidebar-projects-title:hover, .sidebar-projects-title:focus-visible { background: transparent; }

/* Chevron beside «Проекты»: down when the list is open, right when folded. */
.sidebar-projects-title .sidebar-projects-chevron { display: inline-flex; margin-left: 4px; color: var(--text-muted); transition: transform var(--motion) var(--ease); }
.sidebar-projects-title[aria-expanded="false"] .sidebar-projects-chevron { transform: rotate(-90deg); }

/* Confirmation dialog: danger icon beside the title, roomier text and actions. */
.app-modal-confirm .app-modal-frame { padding: 24px 24px 20px; gap: 20px; }
.confirm-head { display: flex; align-items: flex-start; gap: 14px; }
.confirm-icon { flex-shrink: 0; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--bg-danger); color: var(--text-danger); }
.confirm-body { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.confirm-body .app-modal-title { margin: 0; font-size: 18px; }
.confirm-text { margin: 0; font-size: 15px; line-height: 1.55; color: var(--text-secondary); overflow-wrap: anywhere; }
.app-modal-confirm .confirm-actions { gap: 12px; padding-top: 4px; }

/* Confirmation dialog in the platform style: title with close on the right, grey cancel, soft red action. */
.app-modal-confirm .app-modal-frame { padding: 20px 20px 16px 22px; gap: 14px; border-radius: 16px; }
.app-modal-confirm .confirm-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0; border: 0; }
.confirm-title { margin: 0; font-size: 18px; font-weight: 600; color: var(--text-primary); }
.app-modal-confirm .confirm-text { margin: 0; font-size: 15px; line-height: 1.55; color: var(--text-secondary); overflow-wrap: anywhere; }
.app-modal-confirm .confirm-actions { gap: 10px; padding-top: 6px; }
.btn-danger-soft { background: var(--bg-danger); color: var(--text-danger); border: 0.5px solid var(--border-danger); }
.btn-danger-soft:hover { filter: brightness(0.97); }

/* Sidebar sort menu: opens under the «Проекты» row, in place. */
.sidebar-projects-head { position: relative; }
.projects-sort-menu { position: absolute; right: 4px; top: 100%; z-index: 20; width: 230px; margin-top: 4px; padding: 6px; display: flex; flex-direction: column; gap: 2px; border: 1px solid var(--border-default); border-radius: var(--radius-md); background: var(--bg-surface); box-shadow: var(--shadow-popover); }
.projects-sort-menu[hidden] { display: none; }
.projects-sort-menu form { margin: 0; }
.projects-sort-option { width: 100%; border: 0; background: none; text-align: left; cursor: pointer; }
.projects-sort-option.is-active { color: var(--accent-text); font-weight: 600; }
