  /* Tokens mirror the marketing site (assets/css/theme.css): Inter, a slate
     neutral scale, navy #1e2877 as brand/primary, olive #719430 as accent. */
  :root {
    --navy-50: #f4f6fd; --navy-100: #e8ecfb; --navy-200: #d2d8f7; --navy-300: #adb8ee;
    --navy-400: #8090e2; --navy-500: #5566d0; --navy-600: #3b4cb8; --navy-700: #2b3a99;
    --navy-800: #1e2877; --navy-900: #141a4f; --navy-950: #0d1130;
    --olive-300: #a8c96a; --olive-400: #8bb03f; --olive-500: #719430; --olive-600: #5d7c28; --olive-700: #46601c;
    --ember-500: #ea580c; --ember-600: #c2410c;

    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --surface-3: #e2e8f0;
    --border: #e6eaf0;
    --border-strong: #cbd5e1;
    --ink: #1e293b;
    --ink-strong: #0f172a;
    --ink-2: #47536b;
    --ink-3: #64748b;
    --ink-4: #94a3b8;

    --accent: var(--navy-800);
    --accent-hover: var(--navy-900);
    --accent-weak: var(--navy-100);
    --accent-weaker: var(--navy-50);
    --accent-text: var(--navy-700);
    --accent-ink: #ffffff;

    --olive: var(--olive-600);
    --olive-weak: #eef4e0;
    --ember: var(--ember-600);
    --ember-weak: #fbe9df;
    --warn: #b45309;
    --warn-weak: #f9edd8;
    --ok: var(--olive-600);
    --ok-weak: #eef4e0;
    --danger: #dc2626;
    --danger-weak: #fbeaea;

    --logo-chip: #f4f6fd;

    --shadow-xs: 0 1px 2px rgba(15,23,42,.04);
    --shadow-sm: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.05);
    --shadow-md: 0 2px 4px rgba(15,23,42,.04), 0 8px 20px rgba(15,23,42,.08);
    --shadow-lg: 0 4px 8px rgba(15,23,42,.05), 0 20px 48px rgba(15,23,42,.14);

    --radius: 8px;
    --radius-sm: 6px;
    --radius-lg: 12px;

    --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, "SF Mono", "SFMono-Regular", Menlo, Consolas, monospace;

    --topbar-h: 60px;
    --tabbar-h: 62px;
    --imp-banner-h: 0px;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: #0b0f1a;
      --surface: #121828;
      --surface-2: #182035;
      --surface-3: #212b45;
      --border: #232e49;
      --border-strong: #33415c;
      --ink: #e6eaf5;
      --ink-strong: #f4f6fd;
      --ink-2: #a7b0c6;
      --ink-3: #7c879f;
      --ink-4: #5c667d;
      --accent: var(--navy-500);
      --accent-hover: var(--navy-400);
      --accent-weak: #1b2444;
      --accent-weaker: #161d38;
      --accent-text: var(--navy-300);
      --accent-ink: #ffffff;
      --olive: var(--olive-400);
      --olive-weak: #1c2a12;
      --ember: #f97316;
      --ember-weak: #34190d;
      --warn: #f0a742;
      --warn-weak: #2a1f0d;
      --ok: var(--olive-400);
      --ok-weak: #1c2a12;
      --danger: #f87171;
      --danger-weak: #2a1414;
      --logo-chip: #eef1fb;
      --shadow-xs: 0 1px 2px rgba(0,0,0,.35);
      --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
      --shadow-md: 0 6px 20px rgba(0,0,0,.45), 0 1px 3px rgba(0,0,0,.4);
      --shadow-lg: 0 20px 48px rgba(0,0,0,.55);
    }
  }
  :root[data-theme="dark"] {
    --bg: #0b0f1a;
    --surface: #121828;
    --surface-2: #182035;
    --surface-3: #212b45;
    --border: #232e49;
    --border-strong: #33415c;
    --ink: #e6eaf5;
    --ink-strong: #f4f6fd;
    --ink-2: #a7b0c6;
    --ink-3: #7c879f;
    --ink-4: #5c667d;
    --accent: var(--navy-500);
    --accent-hover: var(--navy-400);
    --accent-weak: #1b2444;
    --accent-weaker: #161d38;
    --accent-text: var(--navy-300);
    --accent-ink: #ffffff;
    --olive: var(--olive-400);
    --olive-weak: #1c2a12;
    --ember: #f97316;
    --ember-weak: #34190d;
    --warn: #f0a742;
    --warn-weak: #2a1f0d;
    --ok: var(--olive-400);
    --ok-weak: #1c2a12;
    --danger: #f87171;
    --danger-weak: #2a1414;
    --logo-chip: #eef1fb;
    --shadow-xs: 0 1px 2px rgba(0,0,0,.35);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow-md: 0 6px 20px rgba(0,0,0,.45), 0 1px 3px rgba(0,0,0,.4);
    --shadow-lg: 0 20px 48px rgba(0,0,0,.55);
  }

  * { box-sizing: border-box; }
  body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 14.5px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
  }
  h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -.021em; color: var(--ink-strong); text-wrap: balance; }
  button { font-family: inherit; }
  a { color: var(--accent-text); text-decoration: none; }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
  [hidden] { display: none !important; }
  .mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
  .eyebrow {
    font-size: 11px; font-weight: 600; letter-spacing: .08em;
    text-transform: uppercase; color: var(--ink-3);
  }

  /* ---- brand mark ---- */
  .brand-mark {
    background: var(--logo-chip);
    border-radius: 7px; padding: 5px;
    display: block; flex: none; object-fit: contain;
    box-shadow: inset 0 0 0 1px rgba(30,40,119,.08);
  }
  .brand-lockup { display: flex; align-items: center; gap: 10px; }
  .brand-lockup .name { line-height: 1.05; }
  .brand-lockup .name b { display: block; font-weight: 700; letter-spacing: -.01em; color: inherit; }
  .brand-lockup .name small {
    display: block; font-size: 10px; font-weight: 500; letter-spacing: .12em;
    text-transform: uppercase; color: var(--ink-3); margin-top: 3px;
  }
  .brand-lockup .name small.tracked { letter-spacing: .14em; }

  /* ---- page layout ---- */

  /* ---- badges / pills ---- */
  .badge {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 11.5px; font-weight: 500; letter-spacing: .01em;
    padding: 2px 9px; border-radius: 999px;
    border: 1px solid var(--border-strong);
    background: var(--surface-2); color: var(--ink-2);
    white-space: nowrap;
  }
  .badge.type-document { color: var(--accent-text); background: var(--accent-weak); border-color: transparent; }
  .badge.type-rule { color: var(--ember); background: var(--ember-weak); border-color: transparent; }
  .badge.type-glossary { color: var(--olive); background: var(--olive-weak); border-color: transparent; }
  .badge.type-media, .badge.type-text { color: var(--ink-2); }
  .badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
  .aud { text-transform: capitalize; }
  .state-on { color: var(--ok); }
  .state-off { color: var(--ink-4); }

  /* ---- buttons ---- */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    border: 1px solid var(--border-strong);
    background: var(--surface); color: var(--ink);
    padding: 8px 14px; border-radius: var(--radius-sm);
    font-size: 13.5px; font-weight: 500; cursor: pointer;
    transition: background .12s, border-color .12s, box-shadow .12s, transform .04s;
  }
  .btn:hover { background: var(--surface-2); }
  .btn:active { transform: translateY(1px); }
  .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-xs); }
  .btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
  .btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
  .btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
  .btn.sm { padding: 5px 10px; font-size: 12.5px; }
  /* A submitted form is visually busy and can't be re-sent until it navigates. */
  form.is-submitting button[type="submit"],
  form.is-submitting input[type="submit"] { opacity: .6; pointer-events: none; }
  /* Invalid-field cue, only after the user has interacted; the native bubble
     carries the message, so this is a colour cue on the border alone. */
  .field input:user-invalid,
  .inp:user-invalid,
  .select:user-invalid { border-color: var(--danger); }
  .field input:user-invalid:focus,
  .inp:user-invalid:focus,
  .select:user-invalid:focus { box-shadow: 0 0 0 3px var(--danger-weak); }
  .icon-btn {
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink-2);
    cursor: pointer; display: grid; place-items: center;
    transition: background .12s, color .12s;
  }
  .icon-btn:hover { background: var(--surface-2); color: var(--ink); }
  .icon-btn svg { width: 16px; height: 16px; }

  /* ================= SIGN IN ================= */
  .signin { display: grid; min-height: 100vh; grid-template-columns: 1.05fr .95fr; align-items: stretch; }
  .signin-brandcol {
    background: linear-gradient(165deg, var(--navy-800), var(--navy-950) 78%);
    color: #eef1fb; padding: 56px 60px;
    display: flex; flex-direction: column; justify-content: space-between;
    position: relative; overflow: hidden;
  }
  .signin-brandcol::after {
    content: ""; position: absolute; right: -12%; top: -18%;
    width: 60%; aspect-ratio: 1; border-radius: 50%;
    background: radial-gradient(circle, rgba(139,176,63,.22), transparent 62%);
    pointer-events: none;
  }
  .signin-brandcol .brand-lockup { position: relative; z-index: 1; color: #fff; }
  .signin-brandcol .brand-lockup .name small { color: #9fb0d8; }
  .signin-pitch { position: relative; z-index: 1; max-width: 32ch; }
  .signin-pitch .eyebrow { color: var(--olive-300); }
  .signin-pitch h2 { color: #fff; font-size: 30px; line-height: 1.14; margin-top: 14px; }
  .signin-pitch p { color: #b9c3dd; font-size: 14px; margin-top: 14px; }
  .signin-meta { position: relative; z-index: 1; display: flex; gap: 26px; font-size: 12px; letter-spacing: .02em; color: #8b97b8; }

  .signin-formcol { background: var(--bg); display: grid; place-items: center; padding: 40px; }
  .signin-inner { width: 100%; max-width: 380px; }
  .signin-mobilebrand { display: none; justify-content: center; margin-bottom: 26px; }
  .signin-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
    padding: 30px 28px;
  }
  .signin-card h1 { font-size: 21px; }
  .signin-card > p { color: var(--ink-2); font-size: 13.5px; margin: 6px 0 24px; }
  .field { margin-bottom: 15px; }
  .field label { display: block; font-size: 12.5px; font-weight: 500; color: var(--ink-2); margin-bottom: 6px; }
  .field input {
    width: 100%; padding: 10px 12px; font-family: inherit; font-size: 14px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--ink);
  }
  .field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
  .role-note { font-size: 12px; color: var(--ink-3); margin: 20px 0 10px; text-align: center; }
  .role-split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .signin-submit { width: 100%; margin-top: 4px; }
  .signin-fine { margin-top: 20px; text-align: center; font-size: 12px; color: var(--ink-4); }

  /* Inline form error (sign-in, password change). Theme-aware via the danger tokens. */
  .form-alert { display: flex; align-items: flex-start; gap: 8px; margin: 0 0 16px; padding: 10px 12px; border-radius: 10px; font-size: 13px; line-height: 1.45; background: var(--danger-weak); color: var(--danger); }
  .form-alert svg { flex: none; margin-top: 1px; }

  /* A button that reads as an inline link (KB version rollback). */
  .linkbtn { background: none; border: 0; padding: 0; margin: 0; font: inherit; color: var(--accent-text); cursor: pointer; }
  .linkbtn:hover { text-decoration: underline; }

  /* Post-action flash banner, shown under the top bar in the app shell. */
  .flash { display: flex; align-items: center; gap: 8px; margin: 16px 24px -4px; padding: 11px 14px; border-radius: 10px; font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-sm); }
  .flash svg { flex: none; }
  .flash-ok { background: var(--accent-weak); color: var(--accent-text); }
  .flash-warn { background: var(--warn-weak); color: var(--warn); }
  .flash-error { background: var(--danger-weak); color: var(--danger); }
  @media (max-width: 860px) { .flash { margin: 14px 16px -2px; } }

  /* Transient client toast (portal.js portalToast), for feedback raised without a
     reload, e.g. an oversize file pick. Distinct from the server .flash banner. */
  .toast-host {
    position: fixed; z-index: 1200; bottom: 20px; right: 20px;
    display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
    max-width: min(360px, calc(100vw - 32px)); pointer-events: none;
  }
  .toast {
    pointer-events: auto; cursor: pointer;
    padding: 11px 14px; border-radius: 10px; font-size: 13px; line-height: 1.45; font-weight: 500;
    box-shadow: var(--shadow-md); border: 1px solid var(--border-strong);
    background: var(--surface); color: var(--ink);
    opacity: 0; transform: translateY(8px); transition: opacity .16s, transform .16s;
  }
  .toast.in { opacity: 1; transform: none; }
  .toast-error { background: var(--danger-weak); color: var(--danger); border-color: var(--danger); }
  .toast-ok { background: var(--accent-weak); color: var(--accent-text); border-color: transparent; }
  @media (max-width: 860px) {
    .toast-host { left: 16px; right: 16px; bottom: 16px; max-width: none; align-items: stretch; }
  }
  @media (prefers-reduced-motion: reduce) {
    .toast { transition: none; opacity: 1; transform: none; }
  }

  /* Impersonation banner: shown under the top bar while a super admin views the
     portal as another user. Amber (warn) so it reads as an active, temporary mode.
     It has a fixed height (--imp-banner-h, set on .app.is-impersonating) so the
     viewport-height layout below it can subtract it and keep the chat composer and
     scroll region in place. */
  .app.is-impersonating { --imp-banner-h: 52px; }
  .imp-banner {
    display: flex; align-items: center; gap: 10px;
    height: var(--imp-banner-h); padding: 0 24px; font-size: 13px; font-weight: 500;
    background: var(--warn-weak); color: var(--warn);
    border-bottom: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  }
  .imp-banner .imp-ico { flex: none; display: inline-flex; }
  .imp-banner .imp-text { min-width: 0; line-height: 1.3; }
  .imp-banner .imp-line, .imp-banner .imp-sub { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .imp-banner .imp-line b { font-weight: 700; }
  .imp-banner .imp-sub { font-size: 11.5px; font-weight: 400; opacity: .8; }
  .imp-banner .imp-return { margin-left: auto; flex: none; }
  .imp-return-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 11px; border-radius: var(--radius-sm);
    border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
    background: transparent; color: var(--warn);
    font-size: 12.5px; font-weight: 600; cursor: pointer;
    transition: background .12s;
  }
  .imp-return-btn:hover { background: color-mix(in srgb, var(--warn) 14%, transparent); }
  .imp-return-btn svg { flex: none; }
  @media (max-width: 860px) { .imp-banner { padding: 9px 16px; } }

  /* ================= APP SHELL ================= */
  .app { display: grid; min-height: 100vh; grid-template-columns: 244px 1fr; }
  .sidebar {
    background: var(--surface); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 2px;
    padding: 16px 12px; position: sticky; top: 0; height: 100vh;
  }
  .side-brand { padding: 4px 8px 14px; margin-bottom: 6px; border-bottom: 1px solid var(--border); }
  .side-brand .brand-mark { width: 27px; height: 34px; }
  .side-brand .name b { font-size: 15px; }
  .nav-label { font-size: 10.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-4); padding: 14px 10px 6px; }
  .nav-item {
    display: flex; align-items: center; gap: 11px; width: 100%;
    padding: 9px 10px; border-radius: var(--radius-sm);
    border: none; background: transparent; color: var(--ink-2);
    font-size: 14px; font-weight: 500; text-align: left; cursor: pointer;
    transition: background .12s, color .12s;
  }
  .nav-item:hover { background: var(--surface-2); color: var(--ink); }
  .nav-item.active { background: var(--accent-weak); color: var(--accent-text); font-weight: 600; }
  .nav-item svg { width: 18px; height: 18px; flex: none; }
  .nav-spacer { flex: 1; }
  /* Desktop account card: the sidebar-footer trigger for the account menu. */
  .sidebar .account-wrap { display: block; margin-top: 6px; }
  .account-card {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 12px 8px 4px; border: none; border-top: 1px solid var(--border);
    background: transparent; color: var(--ink); cursor: pointer; text-align: left;
  }
  .account-card:hover,
  .account-card:focus-visible,
  .account-card[aria-expanded="true"] {
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    border-top-color: transparent;
  }
  .account-card .who { min-width: 0; flex: 1; }
  .account-card .who b { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .account-card .who span { font-size: 11.5px; color: var(--ink-3); }
  .account-card > svg { width: 15px; height: 15px; color: var(--ink-4); flex: none; }
  .avatar {
    width: 34px; height: 34px; border-radius: 8px; flex: none;
    background: var(--accent); color: var(--accent-ink);
    display: grid; place-items: center; font-weight: 600; font-size: 12.5px; letter-spacing: .02em;
  }

  .main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
  .topbar {
    display: flex; align-items: center; gap: 12px;
    height: var(--topbar-h); padding: 0 26px; border-bottom: 1px solid var(--border);
    background: var(--surface); position: sticky; top: 0; z-index: 20;
  }
  .topbar .top-brand { display: none; align-items: center; gap: 9px; }
  .topbar .top-brand .brand-mark { width: 24px; height: 30px; }
  .topbar .crumb { font-size: 12px; font-weight: 600; color: var(--ink-3); letter-spacing: .04em; text-transform: uppercase; }
  .topbar h1 { font-size: 16px; }
  .topbar .spacer { flex: 1; }

  /* mobile account menu (top-right) */
  .account-wrap { position: relative; display: none; }
  .account-btn { padding: 0; border: none; background: transparent; cursor: pointer; }
  .account-btn .avatar { width: 34px; height: 34px; }
  .account-menu {
    position: absolute; right: 0; top: calc(100% + 8px); width: 230px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); padding: 8px; z-index: 60;
  }
  .account-menu .am-head { display: flex; align-items: center; gap: 10px; padding: 8px 8px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
  .account-menu .am-head .who b { display: block; font-size: 13.5px; font-weight: 600; }
  .account-menu .am-head .who span { font-size: 11.5px; color: var(--ink-3); }
  .am-item {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 9px 8px; border: none; background: transparent; border-radius: var(--radius-sm);
    color: var(--ink-2); font-size: 13.5px; font-weight: 500; text-align: left; cursor: pointer;
  }
  .am-item:hover { background: var(--surface-2); color: var(--ink); }
  .am-item svg { width: 16px; height: 16px; flex: none; color: var(--ink-3); }
  /* Sidebar (full) variant opens upward and spans the card width. */
  .account-wrap-full .account-menu { right: auto; left: 0; top: auto; bottom: calc(100% + 8px); width: 100%; }
  /* Identity switcher inside the account menu. */
  .am-sep { height: 1px; margin: 6px 4px; background: var(--border); }
  .am-label { font-size: 10px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-4); padding: 4px 8px 2px; }
  .am-identity { justify-content: space-between; gap: 8px; }
  .am-idtext { display: flex; flex-direction: column; min-width: 0; }
  .am-idmain { font-size: 13px; font-weight: 600; color: var(--ink); }
  .am-idsub { font-size: 11px; font-weight: 400; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .am-identity.current { background: var(--accent-weak); }
  .am-identity.current .am-idmain { color: var(--accent-text); }
  .am-idcheck { flex: none; display: inline-flex; }
  .am-idcheck svg { width: 15px; height: 15px; color: var(--accent-text); }

  .content { padding: 26px; padding-bottom: 40px; }
  .content-narrow { max-width: 1080px; margin: 0 auto; }

  /* ---- cards / panels ---- */
  .panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs); }
  .panel-h { display: flex; align-items: center; gap: 10px; padding: 15px 18px; border-bottom: 1px solid var(--border); }
  .panel-h h3 { font-size: 14.5px; font-weight: 600; }
  .panel-h .spacer { flex: 1; }
  .panel-b { padding: 16px 18px; }

  /* ---- dashboard ---- */
  .dash-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; align-items: start; }
  .greet { margin-bottom: 22px; }
  .greet h2 { font-size: 22px; }
  .greet p { color: var(--ink-2); margin-top: 5px; }
  .ask-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: 20px; box-shadow: var(--shadow-sm); margin-bottom: 20px;
  }
  .ask-card h3 { font-size: 16px; font-weight: 600; }
  .ask-card p { color: var(--ink-2); font-size: 13.5px; margin: 5px 0 15px; }
  .ask-row { display: flex; gap: 10px; }
  .ask-row input {
    flex: 1; padding: 11px 13px; font-family: inherit; font-size: 14px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--surface-2); color: var(--ink);
  }
  .ask-row input:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-weak); }
  .suggest { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
  .chip {
    font-size: 12.5px; padding: 6px 12px; border-radius: 999px;
    border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink-2);
    cursor: pointer; transition: border-color .12s, color .12s;
  }
  .chip:hover { border-color: var(--accent); color: var(--accent-text); }

  .task { display: flex; align-items: flex-start; gap: 12px; padding: 13px 0; border-top: 1px solid var(--border); }
  .task:first-child { border-top: none; }
  .task .tick { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; }
  .task .tick.warn { background: var(--warn); }
  .task .tick.crit { background: var(--ember); }
  .task .tick.ok { background: var(--ok); }
  .task .body { flex: 1; min-width: 0; }
  .task .body b { font-size: 13.5px; font-weight: 600; }
  .task .body p { color: var(--ink-3); font-size: 12.5px; margin: 2px 0 0; }
  .task .when { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }
  .stub-note {
    display: flex; gap: 8px; align-items: center;
    font-size: 12px; color: var(--ink-3);
    background: var(--surface-2); border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm); padding: 9px 12px; margin-top: 14px;
  }
  .stub-note svg { flex: none; }
  .recent-chat { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); cursor: pointer; }
  .recent-chat:first-child { border-top: none; }
  .recent-chat:hover .rc-title { color: var(--accent-text); }
  .rc-icon { width: 32px; height: 32px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; color: var(--ink-3); flex: none; }
  .rc-title { font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .rc-meta { font-size: 11.5px; color: var(--ink-3); margin-top: 1px; }

  /* ================= CHAT ================= */
  .chat-wrap { display: grid; grid-template-columns: 250px 1fr; height: calc(100vh - var(--topbar-h) - var(--imp-banner-h)); }
  .chat-list {
    border-right: 1px solid var(--border); background: var(--surface);
    padding: 14px 10px; overflow-y: auto; display: flex; flex-direction: column;
  }
  .chat-list-h { display: none; align-items: center; justify-content: space-between; padding: 2px 4px 12px; }
  .chat-list-h b { font-size: 14px; font-weight: 600; }
  .newchat { width: 100%; margin-bottom: 12px; }
  .ci { display: flex; align-items: center; border-radius: var(--radius-sm); margin-bottom: 2px; }
  .ci:hover { background: var(--surface-2); }
  .ci.active { background: var(--accent-weak); }
  .ci-link { flex: 1; min-width: 0; padding: 10px 11px; cursor: pointer; }
  .ci b { display: block; font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
  .ci.active b { color: var(--accent-text); }
  .ci span { font-size: 11px; color: var(--ink-3); }
  .ci-actions { flex: 0 0 auto; padding-right: 4px; }
  .ci .kb-kebab { width: 28px; height: 28px; }
  /* On pointer devices the kebab stays out of the way until the row is hovered
     or its menu focused; touch devices (no hover) keep it always visible. */
  @media (hover: hover) {
    .ci .kb-kebab { opacity: 0; transition: opacity .12s ease; }
    .ci:hover .kb-kebab, .ci:focus-within .kb-kebab { opacity: 1; }
  }

  .chat-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
  .chat-mobilebar { display: none; }
  .chat-scroll { flex: 1; overflow-y: auto; padding: 26px 0; }
  .thread { max-width: 720px; margin: 0 auto; padding: 0 24px; display: flex; flex-direction: column; gap: 22px; }
  .msg { display: flex; gap: 13px; }
  .msg .who-av { width: 32px; height: 32px; border-radius: 8px; flex: none; display: grid; place-items: center; font-size: 11.5px; font-weight: 600; }
  .msg.user .who-av { background: var(--surface-3); color: var(--ink-2); border: 1px solid var(--border); }
  .msg.agent .who-av { background: var(--logo-chip); overflow: hidden; box-shadow: inset 0 0 0 1px rgba(30,40,119,.08); }
  .msg.agent .who-av img { width: 22px; height: 28px; display: block; object-fit: contain; }
  .msg .bubble { min-width: 0; flex: 1; }
  .msg .name { font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
  .msg .name .mono { color: var(--ink-3); font-weight: 400; margin-left: 6px; font-size: 11.5px; }
  .msg .text { font-size: 14.5px; color: var(--ink); }
  .msg .text p { margin: 0 0 10px; }
  .msg .text p:last-child { margin-bottom: 0; }
  .msg .text ul { margin: 4px 0 10px; padding-left: 20px; }
  .msg .text li { margin: 4px 0; }

  .toolsteps { display: flex; flex-direction: column; gap: 5px; margin: 2px 0 12px; align-items: flex-start; }
  .toolstep {
    display: flex; align-items: center; gap: 8px; max-width: 100%; min-width: 0;
    font-size: 12px; color: var(--ink-3);
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 999px; padding: 5px 12px; box-shadow: var(--shadow-xs);
    white-space: nowrap;
  }
  .toolstep svg { width: 13px; height: 13px; color: var(--accent-text); flex: none; }
  .toolstep b { color: var(--ink-2); font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .toolstep .mono { color: var(--ink-3); flex: none; }
  .toolstep.pending { animation: toolstep-pulse 1.1s ease-in-out infinite; }
  @keyframes toolstep-pulse { 0%, 100% { opacity: .45; } 50% { opacity: .85; } }

  /* Pending indicator shown from send until the first tool step or answer token. */
  .thinking { display: inline-flex; align-items: center; gap: 5px; margin: 4px 0 12px; padding: 2px 0; }
  .thinking span {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--accent-text, var(--ink-3));
    animation: thinking-bounce 1.2s ease-in-out infinite;
  }
  .thinking span:nth-child(2) { animation-delay: .18s; }
  .thinking span:nth-child(3) { animation-delay: .36s; }
  @keyframes thinking-bounce { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: .9; transform: translateY(-3px); } }
  @media (prefers-reduced-motion: reduce) {
    .thinking span { animation: thinking-fade 1.2s ease-in-out infinite; }
    .thinking span:nth-child(2) { animation-delay: .18s; }
    .thinking span:nth-child(3) { animation-delay: .36s; }
    @keyframes thinking-fade { 0%, 80%, 100% { opacity: .3; } 40% { opacity: .9; } }
  }

  /* Collapsible tool steps ("Explore") */
  .explore { margin: 2px 0 12px; }
  .explore-toggle {
    display: inline-flex; align-items: center; gap: 6px;
    border: none; background: transparent; padding: 2px 0; cursor: pointer;
    font: inherit; font-size: 12px; color: var(--ink-3);
  }
  .explore-toggle:hover { color: var(--ink-2); }
  .explore-toggle svg { width: 13px; height: 13px; flex: none; color: var(--ink-3); transition: transform .15s; }
  .explore-toggle[aria-expanded="true"] svg { transform: rotate(90deg); }
  .explore .toolsteps { margin: 8px 0 0; }

  .rulecallout {
    border-left: 3px solid var(--ember); background: var(--ember-weak);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding: 11px 14px; margin: 4px 0 12px; font-size: 13.5px;
  }
  .rulecallout .lab { font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ember); display: block; margin-bottom: 3px; }

  .cites { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
  .cite {
    display: inline-flex; align-items: center; gap: 7px; max-width: 100%;
    font-size: 12px; padding: 6px 11px; border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink-2);
    cursor: pointer; transition: border-color .12s, color .12s;
  }
  .cite:hover { border-color: var(--accent); color: var(--accent-text); }
  .cite svg { flex: none; }
  .cite .v { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-3); }
  .cite:hover .v { color: var(--accent-text); }
  .cite { font-family: inherit; }
  .cite .cite-t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .cite .cite-dl { display: inline-flex; color: var(--ink-3); }
  .cite:hover .cite-dl { color: var(--accent-text); }

  /* Source viewer slide-over (opened from a citation) */
  .source-scrim {
    position: fixed; inset: 0; background: rgba(15,23,42,.44);
    opacity: 0; pointer-events: none; transition: opacity .18s; z-index: 70;
  }
  .source-scrim.show { opacity: 1; pointer-events: auto; }
  .source-panel {
    position: fixed; top: 0; right: 0; height: 100%; width: min(440px, 92vw);
    background: var(--surface); border-left: 1px solid var(--border);
    box-shadow: var(--shadow-lg); z-index: 71; display: flex; flex-direction: column;
    transform: translateX(100%); transition: transform .2s ease; overflow: hidden;
  }
  .source-panel.open { transform: translateX(0); }
  .source-h { display: flex; align-items: flex-start; gap: 12px; padding: 16px 16px 12px; border-bottom: 1px solid var(--border); }
  .source-h-meta { flex: 1; min-width: 0; }
  .source-h-meta b { display: block; font-size: 15px; margin-top: 3px; }
  .source-ver { font-size: 11px; color: var(--ink-3); }
  .source-dl { padding: 12px 16px; border-bottom: 1px solid var(--border); }
  .source-dl .btn { width: 100%; }
  .source-dl .btn svg { flex: none; }
  .source-note { display: flex; align-items: center; gap: 8px; padding: 10px 16px; font-size: 11.5px; color: var(--ink-3); background: var(--surface-2); border-bottom: 1px solid var(--border); }
  .source-note svg { flex: none; }
  .source-body { padding: 16px; overflow-y: auto; font-size: 13.5px; line-height: 1.6; color: var(--ink); }
  .source-body h3 { font-size: 15px; margin: 0 0 8px; }
  .source-body ul { padding-left: 18px; margin: 8px 0; }
  .source-body li { margin: 4px 0; }
  .source-body p { margin: 8px 0; }

  .composer { border-top: 1px solid var(--border); background: var(--surface); padding: 14px 24px 16px; }
  .composer-inner { max-width: 720px; margin: 0 auto; }
  .composer-box { display: flex; align-items: flex-end; gap: 10px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface-2); padding: 8px 8px 8px 14px; }
  .composer-box:focus-within { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-weak); }
  .composer-box textarea {
    flex: 1; border: none; background: transparent; resize: none; color: var(--ink);
    font-family: inherit; font-size: 14.5px; line-height: 1.45; padding: 5px 0; max-height: 120px;
  }
  .composer-box textarea:focus { outline: none; }
  .send-btn { width: 34px; height: 34px; border-radius: var(--radius-sm); border: none; background: var(--accent); color: var(--accent-ink); cursor: pointer; display: grid; place-items: center; flex: none; }
  .send-btn:hover { background: var(--accent-hover); }
  .send-btn.is-stop { background: var(--ink); color: var(--surface); }
  .send-btn.is-stop:hover { background: var(--ink-2); }
  .composer-fine { font-size: 11px; color: var(--ink-3); text-align: center; margin-top: 9px; }
  .context-banner {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    font-size: 12.5px; line-height: 1.4; color: var(--warn);
    background: var(--warn-weak); border: 1px solid var(--warn);
    border-radius: var(--radius-sm); padding: 8px 12px; margin-bottom: 10px;
  }
  .context-banner.is-full { color: var(--danger); background: var(--danger-weak); border-color: var(--danger); }
  .context-banner .context-newchat {
    margin-left: auto; font-weight: 600; color: inherit; white-space: nowrap;
    border: 1px solid currentColor; border-radius: var(--radius-sm); padding: 3px 10px;
  }
  .context-banner .context-newchat:hover { text-decoration: underline; }
  .send-btn:disabled { opacity: .5; cursor: not-allowed; }
  .send-btn:disabled:hover { background: var(--accent); }
  .composer-box textarea:disabled { cursor: not-allowed; color: var(--ink-3); }

  /* ================= KB MANAGER ================= */
  .kb-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
  .search-box { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 8px 12px; min-width: 260px; flex: 1; }
  .search-box svg { width: 15px; height: 15px; color: var(--ink-3); flex: none; }
  .search-box input { border: none; background: transparent; color: var(--ink); font-family: inherit; font-size: 13.5px; flex: 1; min-width: 0; }
  .search-box input:focus { outline: none; }
  .select {
    padding: 8px 11px; font-family: inherit; font-size: 13px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--ink-2); cursor: pointer;
  }

  .table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs); }
  .kb-table { width: 100%; border-collapse: collapse; background: var(--surface); }
  .kb-table th {
    text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
    color: var(--ink-3); padding: 11px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2);
  }
  .kb-table td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: middle; }
  .kb-table tr:last-child td { border-bottom: none; }
  .kb-table tbody tr:hover { background: var(--surface-2); }
  .kb-title { font-weight: 600; color: var(--ink-strong); }
  .kb-title small { display: block; font-weight: 400; font-size: 12px; color: var(--ink-3); margin-top: 2px; }
  .kb-title small.user-title { color: var(--ink-2); font-weight: 500; }
  .col-ver { font-family: var(--font-mono); color: var(--ink-3); font-size: 12px; }
  .col-updated { font-size: 12.5px; color: var(--ink-3); }
  .st { font-size: 12.5px; display: inline-flex; align-items: center; gap: 5px; }
  .kb-table tr[hidden] { display: none !important; }
  .kb-table tbody tr.is-off .kb-title,
  .kb-table tbody tr.is-off .col-updated { opacity: .55; }

  /* row actions + kebab menu */
  .kb-table th.col-actions, .kb-table td.cell-actions { width: 48px; text-align: right; }
  .kb-actions { position: relative; display: inline-flex; }
  .kb-kebab {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; padding: 0; border-radius: var(--radius-sm);
    border: 1px solid transparent; background: transparent; color: var(--ink-3); cursor: pointer;
  }
  .kb-kebab:hover, .kb-kebab[aria-expanded="true"] { background: var(--surface-2); color: var(--ink); border-color: var(--border); }
  .kb-menu {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; min-width: 190px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); padding: 6px;
  }
  .kb-menu-item {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 8px 9px; border: none; background: transparent; border-radius: var(--radius-sm);
    color: var(--ink-2); font-family: inherit; font-size: 13px; font-weight: 500; text-align: left; cursor: pointer;
  }
  .kb-menu-item:hover { background: var(--surface-2); color: var(--ink); }
  .kb-menu-item svg { width: 16px; height: 16px; flex: none; color: var(--ink-3); }
  .kb-menu-item.danger { color: var(--danger); }
  .kb-menu-item.danger svg { color: currentColor; }
  .kb-menu-item.danger:hover { background: var(--danger-weak); color: var(--danger); }
  .kb-menu-sep { height: 1px; margin: 5px 4px; background: var(--border); }
  .kb-empty td { text-align: center; color: var(--ink-3); font-size: 13px; padding: 26px 16px; }

  /* ---- KB editor ---- */
  .editor-grid { display: grid; grid-template-columns: 1fr 300px; gap: 22px; align-items: start; }
  /* Let the 1fr track shrink to the viewport instead of its content's min width,
     otherwise the monospace body and file card push the page wider on mobile. */
  .editor-grid > * { min-width: 0; }
  .form-field { margin-bottom: 16px; }
  .form-field > label:not(.dropzone) { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
  .form-field .hint { font-size: 12px; color: var(--ink-3); margin: 5px 0 0; font-weight: 400; }
  /* A below-field note flagging a validation error or an extraction problem. */
  .form-field .hint.is-invalid { color: var(--danger); font-weight: 500; }
  .req { color: var(--danger); font-weight: 700; }
  .req-note { font-size: 12px; color: var(--ink-3); margin: 0 0 16px; }
  .inp {
    width: 100%; padding: 10px 12px; font-family: inherit; font-size: 14px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--ink);
  }
  .inp:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
  .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .md-editor { border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
  .md-bar { display: flex; gap: 2px; padding: 6px 8px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
  .md-bar button { border: none; background: transparent; color: var(--ink-3); width: 28px; height: 26px; border-radius: 5px; cursor: pointer; font-size: 13px; }
  .md-bar button:hover { background: var(--surface-3); color: var(--ink); }
  .md-editor textarea {
    width: 100%; min-height: 260px; border: none; resize: vertical;
    padding: 13px 15px; font-family: var(--font-mono); font-size: 13px; line-height: 1.6;
    background: var(--surface); color: var(--ink);
  }
  .md-editor textarea:focus { outline: none; }

  /* Rendered markdown preview; .prose is reused wherever KB markdown is shown. */
  .md-preview {
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    padding: 14px 16px; background: var(--surface); color: var(--ink);
    min-height: 260px; font-size: 14px; line-height: 1.65;
  }
  .md-preview-empty { color: var(--ink-3); font-style: italic; }

  /* Document URL-import stand-ins for the editable body (see kb-edit.php). */
  .doc-url-note {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 12px 14px; background: var(--surface-2); color: var(--ink-2);
    font-size: 13px; line-height: 1.55;
  }
  .doc-url-note b { color: var(--ink); font-weight: 600; }
  .doc-current-text {
    margin-top: 8px; max-height: 280px; overflow: auto;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 12px 14px; background: var(--surface); color: var(--ink-2);
    font-size: 13px; line-height: 1.6; white-space: pre-wrap;
  }
  .doc-current-text.is-empty { color: var(--ink-3); font-style: italic; white-space: normal; }
  .prose > :first-child { margin-top: 0; }
  .prose > :last-child { margin-bottom: 0; }
  .prose h1, .prose h2, .prose h3, .prose h4 { font-weight: 650; line-height: 1.3; margin: 1.1em 0 .5em; }
  .prose h1 { font-size: 1.4em; }
  .prose h2 { font-size: 1.2em; }
  .prose h3 { font-size: 1.05em; }
  .prose p { margin: .6em 0; }
  .prose ul, .prose ol { margin: .6em 0; padding-left: 1.4em; }
  .prose li { margin: .25em 0; }
  .prose a { color: var(--accent-text); }
  .prose code { font-family: var(--font-mono); font-size: .88em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
  .prose pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; overflow-x: auto; }
  .prose pre code { background: none; padding: 0; }
  .prose blockquote { margin: .6em 0; padding-left: 12px; border-left: 3px solid var(--border-strong); color: var(--ink-2); }
  .prose table { border-collapse: collapse; width: 100%; margin: .6em 0; font-size: .95em; }
  .prose th, .prose td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
  .prose th { background: var(--surface-2); }

  .toggle-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
  .switch { width: 38px; height: 22px; border-radius: 999px; background: var(--ok); position: relative; flex: none; cursor: pointer; border: none; }
  .switch::after { content: ""; position: absolute; top: 2px; left: 18px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .14s; }
  .switch.off { background: var(--border-strong); }
  .switch.off::after { left: 2px; }
  .switch:disabled, .switch.is-locked { cursor: not-allowed; opacity: .55; }

  /* user manager: user cell, capability badges, locked capability rows */
  .user-cell { display: flex; align-items: center; gap: 10px; }
  .user-cell .avatar { width: 30px; height: 30px; font-size: 11.5px; }
  .cap-badge {
    display: inline-flex; align-items: center; font-size: 11.5px; font-weight: 500;
    padding: 2px 8px; border-radius: 999px; margin: 1px 2px 1px 0;
    color: var(--accent-text); background: var(--accent-weak);
  }
  .cap-badge.cap-super { color: var(--accent-ink); background: var(--accent); }
  .cap-none { color: var(--ink-4); }
  .kb-menu-note { display: flex; align-items: center; gap: 8px; padding: 8px 12px; font-size: 12px; color: var(--ink-3); }
  .kb-menu-note svg { width: 14px; height: 14px; flex: none; color: var(--ink-4); }
  .cap-row { align-items: flex-start; }
  .cap-lock-note { margin-top: 4px; font-size: 11.5px; color: var(--ink-4); font-style: italic; }

  /* Audit log viewer (PRD 3.3). Reuses .kb-table for the desktop/mobile shells. */
  .audit-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); white-space: nowrap; cursor: pointer; }
  .audit-check input { accent-color: var(--accent); }
  .date-input { min-width: 148px; }
  .audit-table td.cell-title { padding-top: 12px; padding-bottom: 12px; }
  .audit-event { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
  .audit-entity { font-size: 13px; color: var(--ink); }
  .audit-meta { margin-top: 4px; font-size: 12px; color: var(--ink-3); }
  .audit-badge {
    display: inline-flex; align-items: center; font-size: 11.5px; font-weight: 600;
    padding: 2px 9px; border-radius: 999px; white-space: nowrap;
    color: var(--accent-text); background: var(--accent-weak);
  }
  .audit-badge.k-create, .audit-badge.k-on { color: var(--ok); background: var(--ok-weak); }
  .audit-badge.k-edit { color: var(--accent-text); background: var(--accent-weak); }
  .audit-badge.k-delete { color: var(--danger); background: var(--danger-weak); }
  .audit-badge.k-off { color: var(--ember); background: var(--ember-weak); }
  .audit-badge.k-view { color: var(--ink-2); background: var(--surface-3); }
  .audit-actor { display: flex; flex-direction: column; gap: 3px; }
  .audit-actor-name { font-size: 13.5px; color: var(--ink); }
  .audit-via {
    display: inline-flex; align-items: center; gap: 4px; align-self: flex-start;
    font-size: 11.5px; font-weight: 500; padding: 1px 8px; border-radius: 999px;
    color: var(--ember); background: var(--ember-weak);
  }
  .audit-via svg { width: 13px; height: 13px; flex: none; }
  .col-ip { font-size: 12.5px; color: var(--ink-3); }
  .pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
  .pager-count { font-size: 13px; color: var(--ink-3); }
  .pager-nav { display: flex; align-items: center; gap: 8px; }
  .pager-page { font-size: 12.5px; color: var(--ink-3); }
  .pager .btn.is-disabled { opacity: .45; pointer-events: none; }

  .version-item { display: flex; gap: 11px; padding: 11px 0; border-top: 1px solid var(--border); }
  .version-item:first-child { border-top: none; }
  .vbadge { font-family: var(--font-mono); font-size: 11px; font-weight: 600; color: var(--accent-text); background: var(--accent-weak); padding: 2px 7px; border-radius: 5px; height: fit-content; flex: none; }
  .version-item.old .vbadge { color: var(--ink-3); background: var(--surface-2); }
  .vmeta { min-width: 0; flex: 1; }
  .vmeta b { font-size: 12.5px; font-weight: 500; }
  .vmeta span { display: block; font-size: 11px; color: var(--ink-3); margin-top: 1px; }
  .vmeta a { font-size: 11.5px; }

  /* Source-document upload / attached file */
  .dropzone {
    display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px;
    padding: 26px 20px; border: 1.5px dashed var(--border-strong); border-radius: var(--radius-sm);
    background: var(--surface-2); color: var(--ink-3); cursor: pointer;
    transition: border-color .14s, background .14s;
  }
  .dropzone:hover { border-color: var(--accent); background: var(--accent-weaker); }
  .dropzone.dragover { border-color: var(--accent); background: var(--accent-weaker); border-style: solid; }
  .dropzone svg { color: var(--accent-text); }
  .dropzone b { font-size: 13.5px; color: var(--ink); }
  .dropzone span { font-size: 12px; max-width: 380px; line-height: 1.5; }
  .filecard { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); }
  .filecard-ic { width: 38px; height: 38px; border-radius: 8px; background: var(--accent-weaker); color: var(--accent-text); display: grid; place-items: center; flex: none; }
  .filecard-meta { flex: 1; min-width: 0; }
  .filecard-meta b { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .filecard-meta span { font-size: 11.5px; color: var(--ink-3); }
  .filecard-actions { display: flex; gap: 6px; flex: none; align-items: center; }
  .filecard-actions .btn { display: inline-flex; align-items: center; gap: 5px; }
  /* Staged upload (a freshly picked file, mid/after extraction). */
  .filecard.staged.working { border-color: var(--accent); }
  .filecard.staged.error { border-color: var(--danger); background: var(--danger-weak); }
  .filecard.staged [data-kb-staged-status] { display: block; }
  .filecard.staged.working [data-kb-staged-status] { color: var(--accent-text); animation: toolstep-pulse 1.4s ease-in-out infinite; }
  .filecard.staged.done [data-kb-staged-status] { color: var(--ink-2); }
  .filecard.staged.error [data-kb-staged-status] { color: var(--danger); }
  .fileflag { display: inline-flex; vertical-align: middle; color: var(--ink-4); margin-left: 6px; }

  /* KB editor: media source segmented toggle (Link URL / Upload file) */
  .seg { display: inline-flex; gap: 4px; padding: 3px; margin-bottom: 10px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); }
  .seg-btn {
    display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
    border: none; border-radius: calc(var(--radius-sm) - 3px); background: transparent;
    font-size: 12.5px; font-weight: 500; color: var(--ink-2); cursor: pointer;
    transition: background .12s, color .12s;
  }
  .seg-btn svg { width: 14px; height: 14px; color: var(--ink-4); flex: none; }
  .seg-btn:hover { color: var(--ink); }
  .seg-btn.on { background: var(--surface); color: var(--accent-text); box-shadow: var(--shadow-xs); }
  .seg-btn.on svg { color: currentColor; }

  /* KB filing: folder + site chips (organizational layer, PRD 4.3) */
  .filingcell { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; }
  .tagcell { display: flex; flex-wrap: wrap; gap: 4px; }
  .folderchip, .sitechip {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 999px;
    border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--ink-2);
    white-space: nowrap;
  }
  .folderchip svg, .sitechip svg { width: 12px; height: 12px; color: var(--ink-4); flex: none; }
  .folderchip { color: var(--accent-text); background: var(--accent-weak); border-color: transparent; }
  .folderchip svg { color: currentColor; }
  .folderchip.none, .sitechip.all { color: var(--ink-4); background: transparent; border-style: dashed; font-style: italic; }
  .folderchip.none svg, .sitechip.all svg { color: var(--ink-4); }
  /* While browsing, the folder is already in the breadcrumb, so the folder chip
     is redundant; it shows only in the flat search view. Site chips always show. */
  .kb-table:not(.kb-search) .filingcell .folderchip { display: none; }
  .kb-table:not(.kb-search) .filingcell { gap: 0; }

  /* KB editor: site tag picker (checkbox pills) */
  .tagpick { display: flex; flex-wrap: wrap; gap: 8px; }
  .tagpick label {
    display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px;
    border: 1px solid var(--border-strong); border-radius: 999px;
    font-size: 12.5px; cursor: pointer; user-select: none;
    background: var(--surface); color: var(--ink-2);
    transition: border-color .12s, background .12s, color .12s;
  }
  .tagpick label:hover { border-color: var(--accent); }
  .tagpick label svg { width: 12px; height: 12px; color: var(--ink-4); flex: none; }
  .tagpick input { accent-color: var(--accent); margin: 0; }
  .tagpick label.on { border-color: transparent; background: var(--accent-weak); color: var(--accent-text); }
  .tagpick label.on svg { color: currentColor; }

  /* KB manager: Site -> Folder -> Item browse (PRD 4.4) */
  .kb-crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; font-size: 13px; }
  .kb-crumbs a { color: var(--ink-2); text-decoration: none; }
  .kb-crumbs a:hover { color: var(--accent-text); }
  .kb-crumbs .sep { color: var(--ink-4); }
  .kb-crumbs .cur { color: var(--ink-strong); font-weight: 600; }
  .kb-crumbs:empty { display: none; }
  tr.browse-row { cursor: pointer; }
  tr.browse-row:hover td { background: var(--surface-2); }
  .browse-name { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--ink-strong); }
  .browse-name svg { width: 17px; height: 17px; flex: none; color: var(--accent-text); }
  .browse-name.is-unfiled svg { color: var(--ink-4); }
  .browse-count { color: var(--ink-3); font-size: 12.5px; white-space: nowrap; }
  .browse-chev { display: inline-flex; color: var(--ink-4); }
  .browse-chev svg { width: 18px; height: 18px; }
  td.cell-actions .browse-chev { justify-content: flex-end; width: 100%; }

  /* ---- KB editor header ---- */
  .editor-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
  .editor-back { flex: none; align-self: flex-start; }
  .editor-head-title { flex: 1; min-width: 0; }
  .editor-head-title .eyebrow { display: block; }
  .editor-head-title h2 { font-size: 20px; margin: 3px 0 0; }
  .editor-actions { display: flex; gap: 8px; flex: none; }
  .kindchip {
    display: inline-flex; align-items: center; gap: 6px; margin-top: 8px;
    font-size: 12px; font-weight: 600; color: var(--accent-text);
    background: var(--accent-weak); border-radius: 999px; padding: 3px 10px;
  }
  .kindchip svg { width: 13px; height: 13px; }
  .kindchip .lock { color: var(--ink-3); font-weight: 500; }

  .label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
  .label-row > label { margin-bottom: 0; }
  .label-row-actions { display: flex; align-items: center; gap: 10px; flex: none; }
  .charcount { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-3); flex: none; }
  .charcount.near { color: var(--warn); }
  .charcount.over { color: var(--ember); }

  /* ---- KB new-item kind picker ---- */
  .kindpick { display: flex; flex-direction: column; gap: 22px; max-width: 760px; }
  .kindpick-grouphead { margin-bottom: 10px; }
  .kindpick-grouphead b { font-size: 13px; font-weight: 600; }
  .kindpick-grouphead span { display: block; font-size: 12px; color: var(--ink-3); margin-top: 1px; }
  .kindpick-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .kindcard {
    display: flex; gap: 12px; padding: 14px; text-decoration: none;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--ink);
    transition: border-color .14s, box-shadow .14s, background .14s;
  }
  .kindcard:hover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
  .kindcard-ic { width: 36px; height: 36px; border-radius: 8px; background: var(--accent-weaker); color: var(--accent-text); display: grid; place-items: center; flex: none; }
  .kindcard-body { min-width: 0; }
  .kindcard-body b { display: block; font-size: 14px; font-weight: 600; }
  .kindcard-body span { display: block; font-size: 12px; color: var(--ink-3); margin-top: 2px; line-height: 1.5; }

  /* ================= MOBILE BOTTOM TABBAR ================= */
  .tabbar { display: none; }
  .drawer-scrim {
    position: fixed; inset: 0; background: rgba(15,23,42,.44);
    opacity: 0; pointer-events: none; transition: opacity .18s; z-index: 40;
  }
  .drawer-scrim.show { opacity: 1; pointer-events: auto; }

  /* ================= RESPONSIVE ================= */
  @media (max-width: 860px) {
    :root { --topbar-h: 56px; }

    .signin { grid-template-columns: 1fr; }
    .signin-brandcol { display: none; }
    .signin-mobilebrand { display: flex; }

    /* app becomes single column; sidebar out, bottom tabbar in */
    .app { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .main { padding-bottom: var(--tabbar-h); }

    .topbar { padding: 0 16px; }
    .topbar .top-brand { display: flex; }
    .topbar .crumb, .topbar h1 { display: none; }
    .topbar .theme-toggle { margin-left: 0; }
    .account-wrap { display: block; }

    .content { padding: 20px 16px 32px; }
    .dash-grid { grid-template-columns: 1fr; }

    /* chat: list becomes a left drawer, main fills the screen */
    .chat-wrap { display: block; height: auto; }
    .chat-main { height: calc(100dvh - var(--topbar-h) - var(--tabbar-h) - var(--imp-banner-h)); }
    .chat-mobilebar {
      display: flex; align-items: center; gap: 8px;
      padding: 9px 14px; border-bottom: 1px solid var(--border); background: var(--surface);
    }
    .chat-mobilebar .cur { flex: 1; min-width: 0; font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .chat-scroll { padding: 20px 0; }
    .thread { padding: 0 16px; gap: 20px; }
    .composer { padding: 12px 14px 14px; }

    .chat-list {
      position: fixed; left: 0; top: 0; bottom: 0; width: 82%; max-width: 320px;
      z-index: 50; transform: translateX(-100%); transition: transform .2s ease;
      box-shadow: var(--shadow-lg); border-right: 1px solid var(--border);
    }
    .chat-list.open { transform: translateX(0); }
    .chat-list-h { display: flex; }

    /* KB table collapses into stacked cards */
    .table-scroll { border: none; box-shadow: none; overflow: visible; }
    .kb-table, .kb-table tbody, .kb-table tr, .kb-table td { display: block; width: 100%; }
    .kb-table thead { display: none; }
    .kb-table tr {
      background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
      box-shadow: var(--shadow-xs); padding: 6px 14px 10px; margin-bottom: 12px;
    }
    .kb-table tbody tr:hover { background: var(--surface); }
    .kb-table td { border: none; padding: 7px 0; display: flex; align-items: center; gap: 12px; }
    .kb-table td::before {
      content: attr(data-label); flex: none; width: 88px;
      font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3);
    }
    .kb-table td.cell-title { display: block; padding-top: 4px; padding-right: 40px; }
    .kb-table td.cell-title::before { display: none; }
    /* kebab pins to the card's top-right corner */
    .kb-table tr { position: relative; }
    .kb-table td.cell-actions { position: absolute; top: 8px; right: 10px; width: auto; padding: 0; }
    .kb-table td.cell-actions::before { display: none; }
    .kb-menu { min-width: 200px; }
    .kb-empty td { justify-content: center; }
    .kb-empty td::before { display: none; }

    .editor-grid { grid-template-columns: 1fr; }
    .greet h2 { font-size: 20px; }

    /* file card wraps its actions below the name so nothing runs off-screen */
    .filecard { flex-wrap: wrap; }
    .filecard-actions { flex-basis: 100%; }
    .filecard-actions .btn { flex: 1; justify-content: center; }

    /* editor header stacks: back on its own line, title, then full-width actions */
    .editor-head { flex-wrap: wrap; }
    .editor-head-title { flex-basis: 100%; order: 2; }
    .editor-back { order: 1; }
    .editor-actions { order: 3; flex-basis: 100%; }
    .editor-actions .btn { flex: 1; justify-content: center; }

    .kindpick-cards { grid-template-columns: 1fr; }

    /* the tabbar itself */
    .tabbar {
      display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: var(--tabbar-h);
      background: var(--surface); border-top: 1px solid var(--border);
      z-index: 45; padding-bottom: env(safe-area-inset-bottom);
    }
    .tab {
      flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
      border: none; background: transparent; color: var(--ink-3);
      font-size: 11px; font-weight: 500; cursor: pointer; padding: 8px 4px;
    }
    .tab svg { width: 21px; height: 21px; }
    .tab.active { color: var(--accent-text); }
    .tab.active svg { stroke-width: 2.1; }
    /* Overflow slot: the More button fills one tab slot and anchors its popover. */
    .more-wrap { flex: 1; display: flex; position: relative; }
    .more-tab { width: 100%; }
    .more-menu {
      position: absolute; right: 8px; bottom: calc(100% + 8px); min-width: 180px;
      background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
      box-shadow: var(--shadow-lg); padding: 8px; z-index: 60;
    }
    .more-item {
      display: flex; align-items: center; gap: 10px; width: 100%;
      padding: 9px 8px; border-radius: var(--radius-sm);
      color: var(--ink-2); font-size: 13.5px; font-weight: 500; text-align: left;
    }
    .more-item:hover { background: var(--surface-2); color: var(--ink); }
    .more-item svg { width: 16px; height: 16px; flex: none; color: var(--ink-3); }
    .more-item.active { color: var(--accent-text); }
    .more-item.active svg { color: var(--accent-text); stroke-width: 2.1; }
  }
  @media (max-width: 400px) {
    .role-split { grid-template-columns: 1fr; }
  }

  .theme-toggle {
    width: 36px; height: 36px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
    background: var(--surface); color: var(--ink-2); cursor: pointer; display: grid; place-items: center;
  }
  .theme-toggle:hover { background: var(--surface-2); color: var(--ink); }
  .theme-toggle svg { width: 16px; height: 16px; }

  /* One-time credentials reveal (users manager: created / reset) */
  .cred-scrim {
    position: fixed; inset: 0; background: rgba(15,23,42,.5);
    z-index: 80; display: flex; align-items: center; justify-content: center; padding: 20px;
  }
  .cred-modal {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg); width: min(460px, 100%); max-height: 92vh; overflow-y: auto;
    padding: 20px;
  }
  .cred-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
  .cred-icon {
    flex: none; width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
    background: var(--accent-weak); color: var(--accent-text);
  }
  .cred-head h3 { margin: 0 0 3px; font-size: 16px; }
  .cred-head p { margin: 0; font-size: 12.5px; line-height: 1.45; color: var(--ink-3); }
  .cred-body { display: flex; flex-direction: column; gap: 10px; }
  .cred-field {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface-2);
  }
  .cred-label {
    flex: none; width: 100%; font-size: 10.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3);
  }
  .cred-value { flex: 1; min-width: 0; font-size: 14px; color: var(--ink); word-break: break-all; }
  .cred-password { font-size: 16px; font-weight: 600; letter-spacing: .02em; }
  .cred-copy { flex: none; }
  .cred-copy.is-copied { color: var(--accent-text); }
  .cred-note {
    display: flex; align-items: flex-start; gap: 8px; margin: 14px 0 4px;
    padding: 10px 12px; border-radius: var(--radius); font-size: 12px; line-height: 1.45;
    background: var(--warn-weak); color: var(--warn);
  }
  .cred-note svg { flex: none; margin-top: 1px; }
  .cred-actions { display: flex; justify-content: flex-end; margin-top: 14px; }

  @media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
