/* Support Ops Copilot - styled after Open WebUI: its neutral gray scale (gray-50 #f9f9f9 ... gray-950 #0d0d0d),
   black/white primary actions, Inter body text with Archivo headings, pill buttons and rounded-3xl composer.
   Theme follows the OS unless the user picks Light or Dark (stored as html[data-theme]). */
/*
 * Purpose: the only stylesheet of the web UI (index.html + app.js), no preprocessor or build step. Colours are CSS
 * custom properties on :root, redefined for dark mode, so components never hard-code a theme. Fonts are served
 * locally from /static/vendor/fonts. Route colours (.r-<route> sets --c) are shared by the route dots, the
 * trajectory graph and the turn list; plugin routes get their --c from a <style> rule app.js adds.
 * Sections: tokens, base, buttons, brand, sign-in, shell (sidebar, menu, top bar), chat (messages, Markdown,
 * citations, SQL results, composer), data sources, toast, trajectory panel, responsive breakpoints.
 *
 * Created By: Saif Rahman
 * Created On: 2026-10-05
 * Updated By: Saif Rahman
 * Updated On: 2026-10-30
 */
@font-face { font-family: "Inter"; font-style: normal; font-weight: 100 900; font-display: swap;
             src: url("/static/vendor/fonts/inter-latin-wght.woff2") format("woff2"); }
@font-face { font-family: "Archivo"; font-style: normal; font-weight: 100 900; font-display: swap;
             src: url("/static/vendor/fonts/archivo-latin-wght.woff2") format("woff2"); }

/* ---------- design tokens (light theme defaults) ---------- */
:root {
  /* Open WebUI gray scale */
  --gray-50: #f9f9f9; --gray-100: #ececec; --gray-200: #e3e3e3; --gray-300: #cdcdcd; --gray-400: #b4b4b4;
  --gray-500: #9b9b9b; --gray-600: #676767; --gray-700: #4e4e4e; --gray-800: #333333; --gray-850: #262626;
  --gray-900: #171717; --gray-950: #0d0d0d;

  --bg: #ffffff;
  --sidebar: var(--gray-50);
  --sidebar-hover: var(--gray-100);
  --surface: #ffffff;
  --surface-2: var(--gray-50);
  --elevated: #ffffff;
  --hover: #f4f4f4;
  --line: var(--gray-100);
  --line-strong: var(--gray-200);
  --ink: var(--gray-900);
  --ink-2: var(--gray-700);
  --muted: var(--gray-600);
  --faint: var(--gray-500);
  --bubble: #f4f4f4;
  --primary: #000000;
  --primary-ink: #ffffff;
  --primary-off: var(--gray-200);
  --link: #2563eb;
  --ok: #059669;
  --warn-bg: rgba(234, 179, 8, .12);
  --warn-line: rgba(202, 138, 4, .35);
  --warn-ink: #a16207;
  --bad-bg: rgba(239, 68, 68, .1);
  --bad-line: rgba(220, 38, 38, .3);
  --bad-ink: #b91c1c;
  --code-bg: var(--gray-50);
  --hl-keyword: #7c3aed; --hl-string: #059669; --hl-number: #c2410c;
  --scroll: rgba(215, 215, 215, .8);
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 6px 24px rgba(0, 0, 0, .06);
  --shadow-lg: 0 10px 38px -10px rgba(0, 0, 0, .25), 0 10px 20px -15px rgba(0, 0, 0, .2);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-primary: "Archivo", var(--font);
  --mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}
/* dark tokens: once for "follow the OS", once for an explicit Dark choice */
/* (the two blocks must stay identical; html[data-theme="light"] opts out of the OS-driven one) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--gray-900); --sidebar: var(--gray-950); --sidebar-hover: var(--gray-900);
    --surface: var(--gray-900); --surface-2: var(--gray-850); --elevated: var(--gray-850); --hover: var(--gray-850);
    --line: var(--gray-850); --line-strong: var(--gray-800);
    --ink: var(--gray-100); --ink-2: var(--gray-300); --muted: var(--gray-500); --faint: var(--gray-600);
    --bubble: var(--gray-850); --primary: #ffffff; --primary-ink: #000000; --primary-off: var(--gray-700);
    --link: #60a5fa; --ok: #34d399;
    --warn-bg: rgba(234, 179, 8, .12); --warn-line: rgba(234, 179, 8, .3); --warn-ink: #fde68a;
    --bad-bg: rgba(239, 68, 68, .12); --bad-line: rgba(239, 68, 68, .3); --bad-ink: #fecaca;
    --code-bg: var(--gray-950); --hl-keyword: #c4a7ff; --hl-string: #6ee7b7; --hl-number: #fdba74;
    --scroll: rgba(67, 67, 67, .8);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 24px rgba(0, 0, 0, .3);
    --shadow-lg: 0 10px 38px -10px rgba(0, 0, 0, .6), 0 10px 20px -15px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: var(--gray-900); --sidebar: var(--gray-950); --sidebar-hover: var(--gray-900);
  --surface: var(--gray-900); --surface-2: var(--gray-850); --elevated: var(--gray-850); --hover: var(--gray-850);
  --line: var(--gray-850); --line-strong: var(--gray-800);
  --ink: var(--gray-100); --ink-2: var(--gray-300); --muted: var(--gray-500); --faint: var(--gray-600);
  --bubble: var(--gray-850); --primary: #ffffff; --primary-ink: #000000; --primary-off: var(--gray-700);
  --link: #60a5fa; --ok: #34d399;
  --warn-bg: rgba(234, 179, 8, .12); --warn-line: rgba(234, 179, 8, .3); --warn-ink: #fde68a;
  --bad-bg: rgba(239, 68, 68, .12); --bad-line: rgba(239, 68, 68, .3); --bad-ink: #fecaca;
  --code-bg: var(--gray-950); --hl-keyword: #c4a7ff; --hl-string: #6ee7b7; --hl-number: #fdba74;
  --scroll: rgba(67, 67, 67, .8);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 24px rgba(0, 0, 0, .3);
  --shadow-lg: 0 10px 38px -10px rgba(0, 0, 0, .6), 0 10px 20px -15px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

/* ---------- base ---------- */
/* [hidden] needs !important: app.js toggles the hidden attribute on elements whose class sets display */
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.6 var(--font); -webkit-font-smoothing: antialiased;
       font-feature-settings: "cv11", "ss01"; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
input, textarea { font: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--faint); outline-offset: 2px; border-radius: 8px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
::selection { background: rgba(155, 155, 155, .3); }

/* thin, rounded scrollbars as in Open WebUI */
* { scrollbar-width: thin; scrollbar-color: var(--scroll) transparent; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--scroll); border-radius: 999px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 16px;
       border-radius: 999px; border: 0; background: var(--surface-2); color: var(--ink); cursor: pointer;
       font-size: 14px; font-weight: 500; transition: background .15s; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn svg { width: 16px; height: 16px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary); opacity: .88; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--hover); }
.btn-block { width: 100%; height: 42px; }
.icon-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 10px;
            background: transparent; color: var(--muted); cursor: pointer; transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn svg { width: 17px; height: 17px; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--ink); text-decoration: none;
         font-weight: 600; font-size: 15px; letter-spacing: -.01em; white-space: nowrap; }
.brand span:last-child { overflow: hidden; text-overflow: ellipsis; }
.brand-mark { position: relative; display: inline-block; width: 26px; height: 26px; border-radius: 50%; flex: none;
              background: var(--primary); }
.brand-mark::after { content: ""; position: absolute; inset: 0; background: var(--primary-ink);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M10 16.5l4 4 8-9' stroke='black' stroke-width='3' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 100% no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M10 16.5l4 4 8-9' stroke='black' stroke-width='3' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 100% no-repeat; }

/* ---------- sign-in ---------- */
.login { position: relative; min-height: 100%; display: grid; place-items: center; padding: 64px 16px 24px; background: var(--bg); }
.login-corner { position: absolute; top: 24px; left: 24px; }
.login-corner .brand-mark { width: 30px; height: 30px; }
.login-card { width: min(400px, 100%); display: grid; gap: 18px; }
.login-head { text-align: center; margin-bottom: 8px; }
.login-title { margin: 0; font: 500 24px/1.3 var(--font-primary); letter-spacing: -.01em; }
.login-sub { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.field { display: grid; gap: 6px; font-size: 13.5px; font-weight: 500; color: var(--ink-2); }
.field input { height: 42px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2);
               color: var(--ink); font-size: 14.5px; transition: border-color .15s; }
.field input::placeholder { color: var(--faint); }
.field input:focus { outline: none; border-color: var(--gray-400); }
.form-error { margin: 0; padding: 9px 14px; border-radius: 12px; background: var(--bad-bg); color: var(--bad-ink);
              border: 1px solid var(--bad-line); font-size: 13.5px; }
.login-card .btn-block { margin-top: 6px; }
.login-fields { display: grid; gap: 18px; }
.btn-sso { background: var(--surface); border: 1px solid var(--line-strong); color: var(--ink); text-decoration: none; gap: 10px; }
.btn-sso:hover { background: var(--hover); }
.btn-sso svg { width: 18px; height: 18px; }

/* ---------- shell ---------- */
.app { display: flex; height: 100%; }
.app.sidebar-collapsed .sidebar { display: none; }
.sidebar { width: 260px; flex: none; background: var(--sidebar); display: flex; flex-direction: column; min-height: 0; color: var(--ink); }
.sidebar-top { padding: 10px 10px 4px; display: grid; gap: 2px; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 2px 8px 8px; }
.sidebar .icon-btn:hover { background: var(--sidebar-hover); }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border: 0; border-radius: 12px;
            background: transparent; color: var(--ink); cursor: pointer; font-size: 14px; font-weight: 500; text-align: left;
            transition: background .15s; }
.nav-item svg { width: 18px; height: 18px; color: var(--ink-2); }
.nav-item:hover, .nav-item.active { background: var(--sidebar-hover); }
.search { display: flex; align-items: center; gap: 10px; padding: 0 10px; height: 36px; border-radius: 12px; color: var(--muted);
          cursor: text; transition: background .15s; }
.search:hover, .search:focus-within { background: var(--sidebar-hover); }
.search svg { width: 18px; height: 18px; }
.search input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; color: var(--ink); font-size: 14px; }
.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button { filter: grayscale(1); }

/* conversation list; row actions (rename, delete) appear on hover, focus or for the active row */
.conv-list { flex: 1; overflow-y: auto; padding: 4px 10px 12px; }
.conv-group { margin: 16px 10px 4px; font-size: 12px; font-weight: 500; color: var(--muted); }
.conv-group:first-child { margin-top: 8px; }
.conv-item { position: relative; display: flex; align-items: center; border-radius: 12px; transition: background .15s; }
.conv-item a { flex: 1; min-width: 0; padding: 7px 10px; color: var(--ink); text-decoration: none; font-size: 14px;
               white-space: nowrap; overflow: hidden; border-radius: 12px;
               -webkit-mask-image: linear-gradient(to right, #000 85%, transparent); mask-image: linear-gradient(to right, #000 85%, transparent); }
.conv-item:hover, .conv-item.active { background: var(--sidebar-hover); }
.conv-actions { display: none; position: absolute; right: 4px; top: 50%; transform: translateY(-50%); border-radius: 10px;
                background: var(--sidebar-hover); }
.conv-item:hover .conv-actions, .conv-item.active .conv-actions, .conv-item:focus-within .conv-actions { display: flex; }
.conv-item:hover a, .conv-item.active a, .conv-item:focus-within a { padding-right: 64px; }
.conv-actions .icon-btn { width: 28px; height: 28px; }
.conv-actions .icon-btn svg { width: 15px; height: 15px; }
.conv-actions .icon-btn:hover { color: var(--ink); background: transparent; }
.conv-rename { flex: 1; margin: 3px 4px; height: 30px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--line-strong);
               background: var(--bg); color: var(--ink); font-size: 14px; outline: none; }
.conv-empty { padding: 10px 12px; color: var(--muted); font-size: 13.5px; }

/* user row at the bottom of the sidebar (opens the user menu) */
.sidebar-bottom { position: relative; padding: 8px 10px 10px; }
.user-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 8px; border: 0; border-radius: 12px;
            background: transparent; cursor: pointer; text-align: left; transition: background .15s; }
.user-row:hover, .user-row[aria-expanded="true"] { background: var(--sidebar-hover); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, #6b7280, #374151); color: #fff;
          display: grid; place-items: center; font-weight: 600; font-size: 13px; flex: none; }
.user-name { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.user-email { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-roles { font-size: 12px; color: var(--muted); }
.user-roles:empty { display: none; }

/* popover menu (user menu) */
.menu { position: absolute; left: 10px; right: 10px; bottom: calc(100% - 2px); z-index: 45; padding: 6px; border-radius: 18px;
        background: var(--elevated); border: 1px solid var(--line); box-shadow: var(--shadow-lg); display: grid; gap: 2px;
        animation: pop .12s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(.98); } }
.menu-head { display: grid; padding: 6px 10px 4px; line-height: 1.35; }
.menu-sep { height: 1px; margin: 4px 6px; background: var(--line-strong); }
.menu-label { padding: 2px 10px; font-size: 12px; font-weight: 500; color: var(--muted); }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 12px;
             background: transparent; cursor: pointer; font-size: 14px; text-align: left; }
.menu-item:hover { background: var(--hover); }
.menu-item svg { width: 17px; height: 17px; color: var(--ink-2); }
.theme-switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; margin: 2px 6px 4px; padding: 3px;
                border-radius: 12px; background: var(--surface-2); }
.theme-switch button { border: 0; border-radius: 9px; padding: 4px 0; background: transparent; cursor: pointer; font-size: 13px; color: var(--muted); }
.theme-switch button:hover { color: var(--ink); }
.theme-switch button[aria-pressed="true"] { background: var(--bg); color: var(--ink); font-weight: 500; box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }

/* main column and top bar; the sidebar toggles show only when the sidebar is collapsed (or on narrow screens) */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.topbar { display: flex; align-items: center; gap: 6px; height: 52px; padding: 0 12px; flex: none; }
.topbar-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; padding-left: 6px; }
.model-name { font-size: 17px; font-weight: 500; letter-spacing: -.01em; white-space: nowrap; color: var(--ink); }
.page-title { min-width: 0; margin: 0; font-size: 14px; font-weight: 400; color: var(--muted); white-space: nowrap;
              overflow: hidden; text-overflow: ellipsis; }
.model-name:not([hidden]) + .page-title::before { content: "·"; margin-right: 10px; color: var(--faint); }
.sidebar-toggle { display: none; }
.app.sidebar-collapsed .sidebar-toggle { display: inline-grid; }
.scrim { display: none; }

/* ---------- chat ---------- */
.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.scroller { flex: 1; overflow-y: auto; padding: 8px 16px 32px; }
.messages { list-style: none; margin: 0 auto; padding: 0; max-width: 780px; display: grid; gap: 28px; }
.messages:empty { display: none; }

/* new chat: greeting, composer and suggestions sit together in the middle of the page */
.chat-view.is-empty { justify-content: center; padding-bottom: 8vh; }
.chat-view.is-empty .scroller { flex: none; overflow: visible; padding-bottom: 20px; }
.empty { max-width: 780px; margin: 0 auto; text-align: center; animation: fade .3s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }
.greeting-row { display: flex; align-items: center; justify-content: center; gap: 14px; }
.greeting-row .brand-mark { width: 40px; height: 40px; }
.greeting { margin: 0; font: 500 30px/1.25 var(--font-primary); letter-spacing: -.01em; }
.empty-sub { margin: 8px 0 0; color: var(--muted); font-size: 15px; }

.suggestions-wrap { max-width: 780px; margin: 18px auto 0; animation: fade .3s ease-out; }
.suggestions-label { display: flex; align-items: center; gap: 6px; padding: 0 4px 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
.suggestions-label svg { width: 14px; height: 14px; }
.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 8px; }
.suggestion { display: grid; gap: 1px; padding: 8px 12px; border: 0; border-radius: 14px; background: transparent;
              cursor: pointer; text-align: left; transition: background .15s; }
.suggestion:hover { background: var(--hover); }
.suggestion .q { font-size: 14px; font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggestion .kind { font-size: 12.5px; color: var(--muted); }

/* messages: user bubbles on the right, assistant turns with avatar, name, time and route tag */
.msg { display: flex; gap: 14px; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { max-width: 85%; background: var(--bubble); padding: 8px 20px; border-radius: 24px;
                    white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant .avatar-bot { width: 32px; height: 32px; margin-top: 1px; }
.msg-col { flex: 1; min-width: 0; }
.msg-body { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.msg-head { display: flex; align-items: baseline; gap: 8px; line-height: 32px; margin-bottom: 2px; }
.msg-name { font-weight: 600; font-size: 15px; }
.msg-time { font-size: 12px; font-weight: 500; color: var(--faint); opacity: 0; transition: opacity .15s; }
.msg:hover .msg-time { opacity: 1; }
.route-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--muted); }
.route-tag svg { width: 15px; height: 15px; }
.route-tag.incident { color: #d97706; }

/* rendered Markdown (model answers), code blocks with a Copy header, and inline [n] citation buttons */
.markdown { overflow-wrap: anywhere; line-height: 1.7; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p, .markdown ul, .markdown ol { margin: 0 0 12px; }
.markdown ul, .markdown ol { padding-left: 22px; }
.markdown li { margin: 4px 0; }
.markdown li::marker { color: var(--muted); }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { margin: 22px 0 8px; line-height: 1.3; letter-spacing: -.01em; font-weight: 600; }
.markdown h1 { font-size: 21px; } .markdown h2 { font-size: 18px; } .markdown h3, .markdown h4 { font-size: 16px; }
.markdown strong { font-weight: 600; }
.markdown blockquote { margin: 0 0 12px; padding-left: 14px; border-left: 3px solid var(--line-strong); color: var(--ink-2); }
.markdown code { font-family: var(--mono); font-size: 13px; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }
.markdown pre { margin: 0; padding: 12px 16px; overflow-x: auto; }
.markdown pre code { background: none; padding: 0; font-size: 13px; line-height: 1.6; }
.code-block { margin: 0 0 12px; border-radius: 14px; background: var(--code-bg); border: 1px solid var(--line); overflow: hidden; }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 0 16px; font-size: 12px;
             font-weight: 500; color: var(--muted); }
.code-head .copy-code { display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 8px; border: 0; border-radius: 8px;
                        background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; }
.code-head .copy-code:hover { background: var(--hover); color: var(--ink); }
.code-head svg { width: 14px; height: 14px; }
.markdown table { border-collapse: separate; border-spacing: 0; margin: 0 0 12px; font-size: 14px; display: block; overflow-x: auto;
                  border: 1px solid var(--line); border-radius: 12px; max-width: 100%; width: max-content; }
.markdown th, .markdown td { border-bottom: 1px solid var(--line); padding: 7px 12px; text-align: left; vertical-align: top; }
.markdown tr:last-child td { border-bottom: 0; }
.markdown th { background: var(--surface-2); font-weight: 600; font-size: 13px; }
.markdown hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.markdown a { color: var(--link); text-decoration: none; }
.markdown a:hover { text-decoration: underline; }
.cite { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin: 0 1px;
        border-radius: 6px; border: 0; background: var(--surface-2); color: var(--ink-2); font-size: 11px; font-weight: 600;
        vertical-align: 2px; cursor: pointer; line-height: 1; transition: background .15s; }
.cite:hover { background: var(--line-strong); color: var(--ink); }

/* source chips under a knowledge answer and the detail pane they open */
.sources { display: flex; flex-wrap: wrap; gap: 6px; }
.source-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 4px 10px 4px 5px;
               border: 0; border-radius: 12px; background: var(--surface-2); cursor: pointer; font-size: 12.5px; color: var(--ink-2);
               transition: background .15s; }
.source-chip:hover, .source-chip[aria-expanded="true"] { background: var(--line-strong); color: var(--ink); }
.source-chip .n { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 6px;
                  background: var(--bg); color: var(--ink-2); font-weight: 600; font-size: 11px; }
.source-chip .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 420px; }
.source-detail { border: 1px solid var(--line); border-radius: 16px; background: var(--surface-2); padding: 12px 16px; font-size: 13.5px; }
.source-detail .head { font-weight: 600; margin-bottom: 2px; }
.source-detail .excerpt { margin-top: 8px; color: var(--ink-2); white-space: pre-wrap; max-height: 220px; overflow-y: auto; }

/* action row: always shown on the latest answer, on hover for older ones (as in Open WebUI) */
.msg-actions { display: flex; align-items: center; gap: 2px; margin-left: -6px; color: var(--muted); font-size: 12px;
               opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions, .msg-actions:focus-within, .msg.assistant:last-child .msg-actions { opacity: 1; }
.msg-actions .icon-btn { width: 30px; height: 30px; border-radius: 8px; }
.msg-actions .icon-btn svg { width: 16px; height: 16px; }
.msg-actions .meta { margin-left: 6px; color: var(--faint); }

/* "working" indicators while an answer is on its way: typing dots and shimmering status text */
.typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--ink); opacity: .4; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .15s; } .typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; transform: scale(.85); } 40% { opacity: .8; transform: none; } }
.working { font-size: 14.5px; display: flex; align-items: center; gap: 8px; }
.shimmer { color: transparent; background: linear-gradient(90deg, var(--faint) 0%, var(--faint) 40%, var(--ink) 50%, var(--faint) 60%, var(--faint) 100%);
           background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; animation: shimmer 2s linear infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* SQL result card */
.result-card { border: 1px solid var(--line); border-radius: 18px; background: var(--surface); overflow: hidden; }
.result-head { display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 16px; border-bottom: 1px solid var(--line); }
.result-title { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.result-title svg { width: 16px; height: 16px; color: var(--muted); }
.result-meta { color: var(--muted); font-size: 12.5px; flex: 1; }
.result-tools { display: flex; gap: 2px; }
.result-tools .btn { height: 30px; padding: 0 10px; font-size: 13px; background: transparent; color: var(--ink-2); }
.result-tools .btn:hover { background: var(--hover); color: var(--ink); }
.result-tools svg { width: 15px; height: 15px; }
.result-table-wrap { max-height: 380px; overflow: auto; }
.result-table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13.5px; }
.result-table th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-weight: 500; font-size: 12px;
                   text-transform: uppercase; letter-spacing: .02em; color: var(--muted); padding: 8px 14px; white-space: nowrap; }
.result-table td { padding: 8px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; max-width: 360px;
                   overflow: hidden; text-overflow: ellipsis; }
.result-table tr:last-child td { border-bottom: 0; }
.result-table tbody tr:hover td { background: var(--surface-2); }
.result-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.result-table .null { color: var(--faint); }
.result-empty { padding: 14px 16px; color: var(--muted); font-size: 14px; }
.sql-details { border-top: 1px solid var(--line); }
.msg-body > .sql-details { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.sql-details summary { list-style: none; cursor: pointer; padding: 8px 16px; font-size: 13px; font-weight: 500; color: var(--muted);
                       display: flex; align-items: center; gap: 6px; user-select: none; }
.sql-details summary:hover { color: var(--ink); }
.sql-details summary::-webkit-details-marker { display: none; }
.sql-details summary svg { width: 14px; height: 14px; transition: transform .15s; }
.sql-details[open] summary svg { transform: rotate(90deg); }
.sql-details pre { margin: 0; padding: 12px 16px; background: var(--code-bg); border-top: 1px solid var(--line); overflow-x: auto; font-size: 13px; }
.sql-details .how-text { padding: 0 16px 12px; font-size: 14px; color: var(--ink-2); }
.sql-details .copy-sql { height: 28px; margin: 8px 12px 10px; padding: 0 10px; font-size: 12.5px; }
.sql-details .copy-sql svg { width: 14px; height: 14px; }
.result-table th.masked svg { width: 12px; height: 12px; margin-right: 4px; vertical-align: -1px; }
.masked-note { display: inline-flex; align-items: center; gap: 4px; margin-left: 8px; padding: 0 7px; border-radius: 6px;
               background: var(--surface-2); color: var(--ink-2); font-size: 11.5px; font-weight: 500; white-space: nowrap; }
.data-table .masked-note { margin-left: 0; }
.masked-note svg { width: 11px; height: 11px; }
.sql-details code { font-family: var(--mono); }
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: 14px; font-size: 14px; border: 1px solid; }
.notice svg { margin-top: 2px; }
.notice.blocked { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-ink); }
.notice.error { background: var(--bad-bg); border-color: var(--bad-line); color: var(--bad-ink); }
.notice .btn { height: 28px; margin-left: auto; font-size: 13px; padding: 0 12px; color: inherit; }
/* what the guardrails did with the turn (personal data masked, a passage left out), under the answer */
.guard-note { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); }

/* highlight.js - quiet theme from the palette */
.hljs-keyword, .hljs-built_in, .hljs-literal { color: var(--hl-keyword); }
.hljs-string { color: var(--hl-string); } .hljs-number { color: var(--hl-number); }
.hljs-comment { color: var(--faint); font-style: italic; }
.hljs-title, .hljs-type { color: var(--link); }

/* composer */
.composer { flex: none; padding: 0 16px 10px; }
.composer-box { max-width: 780px; margin: 0 auto; display: grid; padding: 4px 6px 6px 8px;
                border: 1px solid var(--line); border-radius: 26px; background: var(--surface); box-shadow: var(--shadow);
                transition: border-color .15s; }
:root[data-theme="dark"] .composer-box { background: rgba(155, 155, 155, .05); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .composer-box { background: rgba(155, 155, 155, .05); } }
.composer-box:focus-within { border-color: var(--line-strong); }
.composer textarea { resize: none; border: 0; outline: none; background: transparent; color: var(--ink); font-size: 15px;
                     max-height: 200px; padding: 10px 10px 4px; line-height: 1.5; }
.composer textarea::placeholder { color: var(--faint); }
.composer-row { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.send-btn { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--primary); color: var(--primary-ink);
            display: grid; place-items: center; cursor: pointer; flex: none; transition: background .15s, opacity .15s; }
.send-btn svg { stroke-width: 2.2; }
.send-btn:hover { opacity: .85; }
.send-btn:disabled { background: var(--primary-off); color: var(--bg); cursor: default; opacity: 1; }
.send-btn.stop svg { fill: currentColor; }
.composer-hint { max-width: 780px; margin: 8px auto 0; text-align: center; color: var(--faint); font-size: 12px; }
.chat-view.is-empty .composer-hint { display: none; }

/* ---------- data sources ---------- */
.sources-view { flex: 1; overflow-y: auto; padding: 12px 16px 40px; }
.sources-inner { max-width: 980px; margin: 0 auto; display: grid; gap: 20px; }
.panel { border: 1px solid var(--line); border-radius: 22px; background: var(--surface); padding: 18px 20px; display: grid; gap: 14px; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.panel h2 { margin: 0 0 2px; font-size: 17px; font-weight: 500; display: flex; align-items: baseline; gap: 8px; }
.panel .count { font-size: 15px; color: var(--faint); font-weight: 500; }
.panel p { margin: 0; font-size: 14px; }
.dropzone { position: relative; display: grid; justify-items: center; gap: 4px; padding: 24px; border: 1.5px dashed var(--line-strong);
            border-radius: 18px; cursor: pointer; text-align: center; color: var(--ink-2); font-size: 14px; transition: background .15s, border-color .15s; }
.dropzone:hover, .dropzone.drag { border-color: var(--gray-400); background: var(--surface-2); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone svg { width: 22px; height: 22px; color: var(--muted); }
.status { margin: 0; font-size: 13.5px; color: var(--ink-2); }
.status.ok { color: var(--ok); } .status.bad { color: var(--bad-ink); }
.table-wrap { overflow-x: auto; border-radius: 14px; border: 1px solid var(--line); }
.table-wrap:has(table:empty) { display: none; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th { text-align: left; font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; color: var(--muted);
                 padding: 9px 14px; background: var(--surface-2); }
.data-table td { padding: 9px 14px; border-top: 1px solid var(--line); vertical-align: top; }
.data-table tbody tr:hover td { background: var(--surface-2); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }
.doc-type { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }

/* ---------- toast ---------- */
.toast { position: fixed; top: 16px; right: 16px; max-width: min(360px, calc(100vw - 32px)); background: var(--elevated); color: var(--ink);
         border: 1px solid var(--line); padding: 12px 16px; border-radius: 14px; font-size: 13.5px; box-shadow: var(--shadow-lg); z-index: 50;
         animation: pop .15s ease-out; }

/* ---------- trajectory (right panel) ---------- */
/* route colours: --c drives dots, graph nodes, badges and turn numbers (plugins add their own .r-<route> rule) */
.r-knowledge { --c: #3b82f6; } .r-schema { --c: #8b5cf6; } .r-sql { --c: #10b981; } .r-chitchat { --c: #9b9b9b; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--gray-400)); flex: none; }
#toggle-trajectory[aria-pressed="true"] { background: var(--hover); color: var(--ink); }
.trajectory { display: none; flex: none; width: 340px; flex-direction: column; min-height: 0; background: var(--bg);
              border-left: 1px solid var(--line); }
.app.traj-open .trajectory { display: flex; }
.traj-scrim { display: none; }
.app.view-sources .trajectory, .app.view-sources #toggle-trajectory, .app.view-sources .traj-scrim { display: none !important; }
.traj-head { display: flex; align-items: center; justify-content: space-between; height: 52px; padding: 0 10px 0 18px; flex: none; }
.traj-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
/* the graph card stays put; the summary and the (possibly long) list of turns scroll beneath it */
.traj-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 14px; padding: 0 12px; }
.traj-card { flex: none; border: 1px solid var(--line); border-radius: 18px; padding: 12px 12px 14px; display: grid; gap: 10px; }
.traj-scroll { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -12px; padding: 4px 12px 24px; display: grid; gap: 16px; align-content: start;
               -webkit-mask-image: linear-gradient(to bottom, transparent, #000 14px); mask-image: linear-gradient(to bottom, transparent, #000 14px); }
@media (max-height: 620px) {
  .traj-body { overflow-y: auto; display: block; }
  .traj-card { margin-bottom: 14px; }
  .traj-scroll { overflow: visible; }
}
.traj-caption { margin: 0; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: 12.5px; color: var(--muted); }
.link-btn { border: 0; padding: 0; background: none; color: var(--link); font-size: 12.5px; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

/* graph: dashed edges by default; on = path taken, live = in progress (animated), err = failed sub agent */
.traj-graph svg { display: block; width: 100%; height: auto; fill: none; stroke: none; }
.g-edge { fill: none; stroke: var(--line-strong); stroke-width: 1.5; stroke-dasharray: 3 4; }
.g-edge.on { stroke: var(--ink); stroke-width: 2; stroke-dasharray: none; }
.g-edge.live { stroke: var(--ink); stroke-width: 2; stroke-dasharray: 5 5; animation: flow .7s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -10; } }
.g-node rect { fill: var(--bg); stroke: var(--line-strong); stroke-width: 1.2; transition: fill .2s, stroke .2s; }
.g-node text { fill: var(--muted); stroke: none; font: 600 11px var(--font); text-anchor: middle; }
.g-spec text { font-size: 10.5px; }
.g-node .g-sub { font-size: 9px; font-weight: 500; fill: var(--faint); }
.g-term text { font-size: 9.5px; letter-spacing: .06em; }
.g-node.on rect, .g-node.live rect { stroke: var(--ink); stroke-width: 2; fill: var(--surface-2); }
.g-node.on text, .g-node.live text { fill: var(--ink); }
.g-spec.on rect, .g-spec.live rect { stroke: var(--c); fill: color-mix(in srgb, var(--c) 14%, var(--bg)); }
.g-node.live rect { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { stroke-opacity: .3; } }
.g-node.err rect { stroke: var(--bad-ink); stroke-width: 2; fill: var(--bad-bg); }
.g-node.err text { fill: var(--bad-ink); }
.g-badge { display: none; }
.g-badge.show { display: inline; }
.g-badge circle { fill: var(--c); stroke: var(--bg); stroke-width: 2; }
.g-badge text { fill: #fff; font: 700 9.5px var(--font); }

/* step chips of a turn (kinds from turnSteps() in app.js: code, ok, warn, lock, bad, live) */
.traj-steps { display: grid; gap: 6px; }
.traj-steps:empty { display: none; }
.steps-head { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 600; }
.step-row, .turn-steps { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.step-row .sep, .turn-steps .sep { color: var(--faint); font-size: 12px; }
.step { font-size: 12px; padding: 1px 8px; border-radius: 8px; background: var(--surface-2); color: var(--ink-2); overflow-wrap: anywhere; }
.step.code { font-family: var(--mono); font-size: 11px; }
.step.ok { color: var(--ok); }
.step.warn { background: var(--warn-bg); color: var(--warn-ink); }
.step.lock { box-shadow: inset 0 0 0 1px var(--line-strong); }
.step.bad { background: var(--bad-bg); color: var(--bad-ink); }
.step.live { animation: blink 1.4s infinite; }
.turn-steps { margin-top: 4px; }
.turn-steps .step { font-size: 11px; padding: 0 6px; border-radius: 6px; }

/* conversation summary: turn / switch counts and the route-mix bar */
.traj-summary { display: grid; gap: 8px; padding: 0 4px; }
.traj-stats { font-size: 12.5px; color: var(--muted); }
.traj-stats strong { color: var(--ink); font-weight: 600; }
.mix-bar { display: flex; gap: 2px; height: 6px; border-radius: 999px; overflow: hidden; }
.mix-bar span { flex: 1 1 0; background: var(--c); }
.mix-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); }
.mix-item { display: inline-flex; align-items: center; gap: 6px; }

/* turn timeline, with a divider where the route switched; clicking a route tag in the chat flashes its message */
.traj-label { padding: 0 4px 6px; font-size: 12px; font-weight: 500; color: var(--muted); }
.traj-turns { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.turn-btn { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 10px; width: 100%; padding: 8px; border: 0;
            border-radius: 14px; background: transparent; text-align: left; cursor: pointer; transition: background .15s; }
.turn-btn:hover { background: var(--hover); }
.turn.selected .turn-btn { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line-strong); }
.turn-n { width: 22px; height: 22px; margin-top: 1px; border-radius: 50%; display: grid; place-items: center; font-size: 11px;
          font-weight: 600; color: #fff; background: var(--c, var(--gray-400)); }
.turn.routing .turn-n, .turn.running .turn-n { animation: blink 1.4s infinite; }
.turn-main { min-width: 0; display: grid; }
.turn-q { font-size: 13.5px; font-weight: 500; color: var(--ink); line-height: 1.4; overflow: hidden;
          display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.turn-route { display: flex; align-items: center; gap: 6px; margin-top: 3px; font-size: 12px; color: var(--ink-2); }
.pill { padding: 0 6px; border-radius: 6px; font-size: 10.5px; font-weight: 600; background: var(--warn-bg); color: var(--warn-ink); }
.turn-rewrite { margin-top: 3px; font-size: 12px; line-height: 1.4; color: var(--muted); overflow-wrap: anywhere; }
.turn-rewrite::before { content: "Rewritten: "; color: var(--faint); }
.turn-time { margin-top: 2px; font-size: 11.5px; color: var(--faint); white-space: nowrap; }
.turn-switch { display: flex; align-items: center; gap: 6px; padding: 4px 8px 4px 40px; font-size: 11.5px; font-weight: 500; color: var(--muted); }
.turn-switch svg { width: 12px; height: 12px; }
.turn-switch::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.route-tag { cursor: pointer; }
.route-tag:hover { color: var(--ink); }
.msg.flash { animation: flash 1.6s ease-out; border-radius: 16px; }
@keyframes flash { from { background: var(--hover); box-shadow: 0 0 0 8px var(--hover); } }

/* below 1200px (app.js's "wide" breakpoint) the trajectory panel overlays the page instead of taking a column */
@media (max-width: 1199px) {
  .trajectory { position: fixed; top: 0; right: 0; bottom: 0; width: min(360px, 100vw); z-index: 42; border-left: 0;
                box-shadow: var(--shadow-lg); }
  .app.traj-open .traj-scrim { display: block; position: fixed; inset: 0; z-index: 41; background: rgba(0, 0, 0, .3); }
}

/* ---------- narrow screens ---------- */
/* 860px matches app.js's "narrow" query: the sidebar becomes a slide-over with a scrim, collapsed state ignored */
@media (max-width: 860px) {
  .sidebar, .app.sidebar-collapsed .sidebar { display: flex; position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 40;
                                              transform: translateX(-100%); transition: transform .2s; }
  .app.sidebar-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .app.sidebar-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 30; }
  .sidebar-toggle { display: inline-grid; }
  .msg.user .bubble { max-width: 90%; }
  .msg.assistant .avatar-bot { display: none; }
  .suggestions { grid-template-columns: minmax(0, 1fr); }
  .greeting { font-size: 25px; }
  .model-name { font-size: 16px; }
}
@media (max-width: 520px) {
  .page-title { display: none; }
  .greeting-row .brand-mark { display: none; }
}
/* honour the OS "reduce motion" setting: no animations or transitions anywhere */
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
