/* ─────────────────────────────────────────────────────────────────────────────
   Cortex Agent — design system
   Tokens first, then base elements, the app shells (public, admin, auth, chat),
   shared components, and finally page-specific pieces. Class names used by the
   Razor pages and chat.js are kept stable; restyle here rather than renaming.
   ───────────────────────────────────────────────────────────────────────────── */

:root {
  --font: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Code", "Cascadia Mono", ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;

  --bg: #f5f6fa;
  --bg-subtle: #eef0f5;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --fg: #111827;
  --fg-2: #374151;
  --muted: #6b7280;
  --border: #e3e6ec;
  --border-strong: #cfd4dc;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-fg: #ffffff;
  --ring: rgba(79, 70, 229, .28);

  --ok: #047857;      --ok-soft: #ecfdf5;      --ok-border: #a7f3d0;
  --warn: #b45309;    --warn-soft: #fffbeb;    --warn-border: #fde68a;
  --danger: #dc2626;  --danger-soft: #fef2f2;  --danger-border: #fecaca;
  --info: #1d4ed8;    --info-soft: #eff6ff;    --info-border: #bfdbfe;

  --sidebar-bg: #0f172a;
  --sidebar-fg: #cbd5e1;
  --sidebar-muted: #64748b;
  --sidebar-hover: rgba(255, 255, 255, .06);
  --sidebar-active: rgba(99, 102, 241, .18);
  --sidebar-active-fg: #ffffff;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 20px 40px -12px rgba(16, 24, 40, .25);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f17;
    --bg-subtle: #111722;
    --surface: #141a25;
    --surface-2: #19202d;
    --fg: #e7eaf0;
    --fg-2: #c3c9d4;
    --muted: #8b95a7;
    --border: #252d3b;
    --border-strong: #334055;

    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-soft: rgba(129, 140, 248, .14);
    --accent-fg: #0b0f17;
    --ring: rgba(129, 140, 248, .35);

    --ok: #34d399;      --ok-soft: rgba(52, 211, 153, .1);    --ok-border: rgba(52, 211, 153, .35);
    --warn: #fbbf24;    --warn-soft: rgba(251, 191, 36, .1);  --warn-border: rgba(251, 191, 36, .35);
    --danger: #f87171;  --danger-soft: rgba(248, 113, 113, .1); --danger-border: rgba(248, 113, 113, .35);
    --info: #60a5fa;    --info-soft: rgba(96, 165, 250, .1);  --info-border: rgba(96, 165, 250, .35);

    --sidebar-bg: #080b12;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    --shadow-lg: 0 20px 40px -12px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

/* ── base ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 14.5px; background: var(--bg); color: var(--fg); line-height: 1.55; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { color: var(--fg); letter-spacing: -.01em; line-height: 1.25; }
h1 { font-size: 1.6rem; font-weight: 650; margin: 0 0 .35rem; }
h2 { font-size: 1.1rem; font-weight: 600; margin: 2rem 0 .75rem; }
h3 { font-size: .98rem; font-weight: 600; margin: 1.1rem 0 .4rem; }
p { margin: .5rem 0; }
code { font-family: var(--mono); font-size: .86em; background: var(--bg-subtle); border: 1px solid var(--border); padding: .05rem .35rem; border-radius: 5px; }
pre { font-family: var(--mono); }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.5rem 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Blazor focuses the page's h1 after each navigation (for screen readers): no ring, and never tucked under the sticky header. */
[tabindex="-1"]:focus { outline: none; }
h1 { scroll-margin-top: 72px; }
/* Component rules like p.error set display, which would otherwise override the hidden attribute. */
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
small.muted { display: block; margin-top: .2rem; font-size: .82rem; }
.spacer { flex: 1; }
svg.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ── buttons ──────────────────────────────────────────────────────────────── */
button.primary, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  margin-top: 1rem; padding: .5rem .95rem; min-height: 36px;
  background: var(--accent); color: var(--accent-fg); border: 1px solid var(--accent);
  border-radius: var(--radius-sm); font: inherit; font-weight: 550; line-height: 1.2;
  cursor: pointer; text-decoration: none; box-shadow: var(--shadow-sm);
  transition: background .15s, border-color .15s, box-shadow .15s, color .15s;
}
button.primary:hover, .btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; }
.btn.secondary { background: var(--surface); color: var(--fg-2); border-color: var(--border-strong); }
.btn.secondary:hover { background: var(--surface-2); color: var(--fg); border-color: var(--muted); }
.btn.ghost { background: transparent; color: var(--fg-2); border-color: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--bg-subtle); color: var(--fg); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(.92); }
.btn.sm { padding: .3rem .65rem; min-height: 30px; font-size: .86rem; margin-top: 0; }
.btn svg.icon { width: 16px; height: 16px; }
.btn:disabled, button:disabled { opacity: .55; cursor: not-allowed; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; font-weight: 500; }
button.link:hover { text-decoration: underline; }
button.link.danger { color: var(--danger); background: none; }
.actions-row, .toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.actions-row .btn, .toolbar .btn { margin-top: 0; }

/* ── forms ────────────────────────────────────────────────────────────────── */
label { display: block; margin: .9rem 0 .3rem; font-weight: 550; font-size: .9rem; color: var(--fg-2); }
input[type=email], input[type=password], input[type=text], input[type=number], input[type=search], input[type=url], input[type=datetime-local], input[type=date], select, textarea {
  width: 100%; padding: .5rem .7rem; min-height: 38px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--fg); font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: auto; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 16px; height: 16px; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
.form { max-width: 52rem; }
.shell .content .form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: .4rem 1.4rem 1.3rem; margin: 1rem 0 1.5rem; box-shadow: var(--shadow-sm); }
.shell .content .form > h2:first-child { margin-top: 1rem; }
.form textarea.code, textarea.code { font-family: var(--mono); font-size: .85rem; background: var(--surface-2); }
.row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-end; }
.row > div { flex: 1 1 12rem; }
label.inline, label.choice { display: flex; align-items: flex-start; gap: .55rem; margin: .45rem 0; font-weight: 450; color: var(--fg); }
label.choice input, label.inline input { margin-top: .2rem; }
label.choice small { margin-left: .25rem; }
label.danger { padding: .7rem; border: 1px solid var(--danger-border); background: var(--danger-soft); border-radius: var(--radius-sm); }
.stack-gap { height: .6rem; }
.field-hint { font-size: .82rem; color: var(--muted); margin: .3rem 0 0; }
.input-group { display: flex; gap: .5rem; align-items: stretch; }
.input-group input { flex: 1; }
.input-group .btn { margin-top: 0; white-space: nowrap; }

/* segmented choice (radio buttons that look like tabs) */
.segmented { display: inline-flex; background: var(--bg-subtle); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented label { margin: 0; padding: .35rem .8rem; border-radius: 5px; font-weight: 500; font-size: .87rem; color: var(--muted); cursor: pointer; display: inline-flex; align-items: center; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label.on { background: var(--surface); color: var(--fg); box-shadow: var(--shadow-sm); }

/* toggle switch */
.switch { display: inline-flex; align-items: center; gap: .6rem; margin: .6rem 0; font-weight: 500; cursor: pointer; color: var(--fg); }
.switch input { appearance: none; -webkit-appearance: none; width: 36px; height: 20px; border-radius: 999px; background: var(--border-strong); position: relative; cursor: pointer; transition: background .15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); }

/* ── messages & alerts ────────────────────────────────────────────────────── */
.error { color: var(--danger); margin: .5rem 0; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
p.error, p.ok, p.notice, .alert {
  display: flex; gap: .6rem; align-items: flex-start;
  padding: .7rem .9rem; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); margin: .9rem 0;
}
p.error { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger); }
p.ok { background: var(--ok-soft); border-color: var(--ok-border); color: var(--ok); }
.notice { padding: .9rem 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--fg-2); }
p.notice { background: var(--info-soft); border-color: var(--info-border); color: var(--fg); }
.alert.warn { background: var(--warn-soft); border-color: var(--warn-border); color: var(--fg); }
.alert.info { background: var(--info-soft); border-color: var(--info-border); color: var(--fg); }
.alert.danger { background: var(--danger-soft); border-color: var(--danger-border); color: var(--fg); }
.alert svg.icon { margin-top: 1px; }
.alert.warn svg.icon { color: var(--warn); } .alert.info svg.icon { color: var(--info); } .alert.danger svg.icon { color: var(--danger); }

ul.issues { list-style: none; padding: 0; margin: 1rem 0; display: grid; gap: .4rem; }
ul.issues li { padding: .55rem .8rem; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); font-size: .92rem; }
ul.issues li strong { margin-right: .35rem; }
ul.issues li.error { border-color: var(--danger-border); background: var(--danger-soft); color: var(--fg); }
ul.issues li.error strong { color: var(--danger); }
ul.issues li.warn { border-color: var(--warn-border); background: var(--warn-soft); color: var(--fg); }
ul.issues li.warn strong { color: var(--warn); }
ul.plain { list-style: none; padding-left: 0; }
ul.plain li { padding: .15rem 0; }
ul.doc-list { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1rem 0 1.5rem; }
ul.doc-list li { padding: 0; }
ul.doc-list a { display: inline-flex; align-items: center; padding: .4rem .8rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--fg-2); font-weight: 500; font-size: .9rem; box-shadow: var(--shadow-sm); }
ul.doc-list a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
ul.doc-list li.current a { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ── badges ───────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .1rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 550; line-height: 1.5; border: 1px solid var(--border); background: var(--surface-2); color: var(--fg-2); vertical-align: middle; white-space: nowrap; }
.badge::before { content: none; }
.badge.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.risk-low, .badge.succeeded, .badge.public-ok, .badge.success { color: var(--ok); background: var(--ok-soft); border-color: var(--ok-border); }
.badge.risk-medium, .badge.waiting, .badge.warning { color: var(--warn); background: var(--warn-soft); border-color: var(--warn-border); }
.badge.risk-high, .badge.failed, .badge.timedout, .badge.restricted, .badge.danger { color: var(--danger); background: var(--danger-soft); border-color: var(--danger-border); }
.badge.public { color: var(--ok); background: var(--ok-soft); border-color: var(--ok-border); }
.badge.running, .badge.pending, .badge.info { color: var(--info); background: var(--info-soft); border-color: var(--info-border); }
.badge.cancelled, .badge.neutral { color: var(--muted); }

/* ── cards & tables ───────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-body { padding: 1.15rem 1.25rem; }
.card-head { display: flex; align-items: center; gap: .75rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.card-head h2, .card-head h3 { margin: 0; font-size: 1rem; }
.card-foot { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; padding: .8rem 1.25rem; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.card-foot .btn { margin-top: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr)); gap: 1rem; }

table.grid, table.status { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin: 1rem 0; box-shadow: var(--shadow-sm); }
table.grid th, table.grid td, table.status th, table.status td { text-align: left; padding: .65rem .85rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.grid tr:last-child td, table.status tr:last-child td, table.status tr:last-child th { border-bottom: 0; }
table.grid thead th { background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; }
table.grid tbody tr:hover td { background: var(--surface-2); }
table.grid input[type=text], table.grid input[type=number], table.grid select { min-height: 32px; padding: .3rem .5rem; }
table.grid tr.details td { background: var(--bg); }
table.status th { width: 14rem; color: var(--muted); font-weight: 500; background: var(--surface-2); }
td.actions { white-space: nowrap; text-align: right; }
td.actions .link, .pager .link { margin-left: .75rem; margin-right: 0; }
.pager { display: flex; gap: .75rem; align-items: center; margin: .75rem 0; }

pre.json { white-space: pre-wrap; word-break: break-word; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .75rem .9rem; max-height: 28rem; overflow: auto; font-size: .83rem; }
details { margin: 1rem 0; }
details > summary { cursor: pointer; font-weight: 550; color: var(--fg-2); padding: .35rem 0; }
details.preview, details.reference { margin: 1rem 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .4rem 1rem; }
details.preview[open], details.reference[open] { padding-bottom: 1rem; }

/* ── public shell (home, not found) ───────────────────────────────────────── */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1.25rem; padding: 0 1.5rem; height: 60px; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: saturate(160%) blur(10px); border-bottom: 1px solid var(--border); }
.topbar .brand { display: inline-flex; align-items: center; gap: .6rem; font-weight: 650; font-size: 1.02rem; color: var(--fg); text-decoration: none; letter-spacing: -.01em; }
.topbar nav { display: flex; gap: .25rem; }
.topbar nav a { padding: .4rem .7rem; border-radius: var(--radius-sm); color: var(--fg-2); font-weight: 500; }
.topbar nav a:hover { background: var(--bg-subtle); text-decoration: none; color: var(--fg); }
.topbar form { margin: 0; }
.topbar .who { color: var(--muted); font-size: .9rem; }
.brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #6366f1, #8b5cf6 55%, #ec4899); color: #fff; box-shadow: 0 4px 12px -4px rgba(99,102,241,.6); }
.brand-mark svg { width: 18px; height: 18px; stroke: #fff; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.user-chip { display: inline-flex; align-items: center; gap: .5rem; }
.avatar { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 650; font-size: .8rem; text-transform: uppercase; flex: none; }
main { max-width: 72rem; margin: 2rem auto; padding: 0 1.5rem; }

.hero { padding: 2.75rem 2rem; border-radius: var(--radius-lg); background: radial-gradient(1200px 300px at 0% 0%, rgba(99,102,241,.16), transparent 60%), radial-gradient(800px 300px at 100% 100%, rgba(236,72,153,.10), transparent 60%), var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm); margin-bottom: 2rem; }
.hero h1 { font-size: 2rem; margin-bottom: .5rem; }
.hero p { color: var(--muted); font-size: 1.02rem; max-width: 40rem; margin: 0; }
.hero .actions-row { margin-top: 1.25rem; }
a.agent-card { display: flex; gap: .9rem; align-items: center; padding: 1rem 1.1rem; color: var(--fg); text-decoration: none; transition: border-color .15s, box-shadow .15s, transform .15s; }
a.agent-card:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); text-decoration: none; }
a.agent-card .agent-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); flex: none; }
a.agent-card strong { display: block; font-weight: 600; }
a.agent-card span.muted { font-size: .85rem; }
a.agent-card .go { margin-left: auto; color: var(--muted); }
ul.agents { padding-left: 1.25rem; }

/* ── admin shell ──────────────────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
/* dvh: on phones 100vh is taller than the visible screen, which pushed the menu's foot off-screen and shifted the page. */
.sidebar { position: sticky; top: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; background: var(--sidebar-bg); color: var(--sidebar-fg); border-right: 1px solid rgba(255,255,255,.04); }
.sidebar-brand { display: flex; align-items: center; gap: .65rem; padding: 1.1rem 1.15rem 1rem; color: #fff; font-weight: 650; font-size: 1.02rem; text-decoration: none; letter-spacing: -.01em; }
.sidebar-brand:hover { text-decoration: none; }
.sidebar-brand small { display: block; font-weight: 500; font-size: .72rem; color: var(--sidebar-muted); letter-spacing: .02em; }
.sidebar nav.side { flex: 1; overflow-y: auto; padding: .25rem .7rem 1rem; display: flex; flex-direction: column; gap: 1px; scrollbar-width: thin; scrollbar-color: #334155 transparent; }
.nav-label { padding: 1rem .6rem .35rem; font-size: .68rem; font-weight: 650; text-transform: uppercase; letter-spacing: .08em; color: var(--sidebar-muted); }
.sidebar nav.side a { display: flex; align-items: center; gap: .65rem; padding: .48rem .65rem; border-radius: 7px; color: var(--sidebar-fg); font-weight: 500; font-size: .9rem; text-decoration: none; transition: background .12s, color .12s; }
.sidebar nav.side a svg.icon { width: 17px; height: 17px; opacity: .75; }
.sidebar nav.side a:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar nav.side a.active { background: var(--sidebar-active); color: var(--sidebar-active-fg); box-shadow: inset 2px 0 0 #818cf8; }
.sidebar nav.side a.active svg.icon { opacity: 1; color: #a5b4fc; }
.sidebar-foot { border-top: 1px solid rgba(255,255,255,.06); padding: .85rem 1rem; display: flex; align-items: center; gap: .6rem; }
.sidebar-foot .avatar { background: rgba(129,140,248,.18); color: #c7d2fe; }
.sidebar-foot .who { flex: 1; min-width: 0; font-size: .82rem; color: var(--sidebar-fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot form { margin: 0; }
.sidebar-foot button.icon-btn { background: none; border: 0; color: var(--sidebar-muted); cursor: pointer; padding: .3rem; border-radius: 6px; display: grid; place-items: center; }
.sidebar-foot button.icon-btn:hover { color: #fff; background: var(--sidebar-hover); }

.shell-main { min-width: 0; display: flex; flex-direction: column; }
.shell-top { position: sticky; top: 0; z-index: 15; display: flex; align-items: center; gap: .75rem; height: 56px; padding: 0 2rem; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.shell-top .crumbs { color: var(--muted); font-size: .88rem; display: flex; gap: .4rem; align-items: center; }
.shell-top .crumbs a { color: var(--muted); }
.shell-top .menu-btn { display: none; background: none; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .35rem; color: var(--fg); cursor: pointer; }
.shell-top .btn { margin-top: 0; }
.admin .content, .shell .content { width: 100%; max-width: 76rem; padding: 1.75rem 2rem 4rem; }
.content > h1:first-child { margin-top: .25rem; }
.content > h1 + p.muted { margin-top: 0; margin-bottom: 1.5rem; max-width: 60rem; }
.page-head { display: flex; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-head > div:first-child { flex: 1; min-width: 16rem; }
.page-head h1 { margin: .25rem 0 .3rem; }
.page-head p { margin: 0; color: var(--muted); max-width: 52rem; }
.page-head .btn { margin-top: .25rem; }
.section-head { display: flex; align-items: center; gap: .75rem; margin: 2.25rem 0 .9rem; flex-wrap: wrap; }
.section-head h2 { margin: 0; }
.section-head p { margin: 0; flex-basis: 100%; color: var(--muted); font-size: .9rem; }
.section-head .btn { margin-top: 0; margin-left: auto; }

/* stat tiles (dashboard, workflow monitor) */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: .9rem; margin: 1rem 0 1.5rem; }
.tile { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: .2rem; box-shadow: var(--shadow-sm); position: relative; }
.tile-number { font-size: 1.75rem; font-weight: 650; line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile-label { color: var(--muted); font-size: .82rem; font-weight: 500; }
.tile-sub { color: var(--muted); font-size: .8rem; }
.tile .tile-icon { position: absolute; top: .95rem; right: 1rem; color: var(--muted); opacity: .7; }
.tile.attention { border-color: var(--warn-border); background: linear-gradient(var(--warn-soft), var(--warn-soft)), var(--surface); }
.tile.attention .tile-number { color: var(--warn); }
.tile.bad { border-color: var(--danger-border); background: linear-gradient(var(--danger-soft), var(--danger-soft)), var(--surface); }
.tile.bad .tile-number { color: var(--danger); }
.tile.good .tile-number { color: var(--ok); }
a.tile { color: inherit; text-decoration: none; transition: border-color .15s, box-shadow .15s; }
a.tile:hover { border-color: var(--accent); box-shadow: var(--shadow); text-decoration: none; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: .4rem; vertical-align: middle; }
.status-dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.status-dot.off { background: var(--border-strong); }
.status-dot.bad { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.status-dot.wait { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }

/* ── channels page ────────────────────────────────────────────────────────── */
.channel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(21rem, 1fr)); gap: 1rem; }
.channel-card { display: flex; flex-direction: column; }
.channel-card .card-body { flex: 1; }
.channel-logo { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; color: #fff; flex: none; }
.channel-logo svg { width: 22px; height: 22px; }
.channel-logo.telegram { background: linear-gradient(135deg, #37aee2, #1e96c8); }
.channel-logo.whatsapp { background: linear-gradient(135deg, #25d366, #128c7e); }
.channel-logo.webapi { background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.channel-logo.email { background: linear-gradient(135deg, #f59e0b, #d97706); }
.channel-logo.teams { background: linear-gradient(135deg, #7b83eb, #5059c9); }
.channel-logo.notify { background: linear-gradient(135deg, #ef4444, #b91c1c); }
.dialog-body h3.form-section { font-size: .95rem; margin: 1.4rem 0 .5rem; padding-top: .9rem; border-top: 1px solid var(--border); }
.field-row { display: flex; gap: .6rem; align-items: flex-end; }
.field-row .grow { flex: 1 1 auto; min-width: 0; }
.field-row .narrow { flex: 0 0 7rem; }
.target-row { align-items: center; margin-bottom: .5rem; }
.target-row select { flex: 0 0 9rem; }
.channel-title { flex: 1; min-width: 0; }
.channel-title strong { display: block; font-weight: 600; }
.channel-title span { color: var(--muted); font-size: .84rem; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1rem; margin: 0; font-size: .9rem; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.empty-state { text-align: center; padding: 2.25rem 1rem; color: var(--muted); }
.empty-state .empty-icon { display: inline-grid; place-items: center; width: 48px; height: 48px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); margin-bottom: .75rem; }
.empty-state strong { display: block; color: var(--fg); font-size: 1rem; margin-bottom: .25rem; }
.endpoint { font-family: var(--mono); font-size: .82rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: .1rem .4rem; overflow-wrap: anywhere; }
.secret-once { margin-top: .6rem; padding: .7rem .8rem; border: 1px dashed var(--warn-border); background: var(--warn-soft); border-radius: var(--radius-sm); font-size: .88rem; }
.secret-once code { display: block; margin-top: .35rem; padding: .4rem .5rem; user-select: all; overflow-wrap: anywhere; background: var(--surface); }

/* ── main site shell (same shell as admin; menu from navigation.json) ─────── */
.nav-backdrop { display: none; }
.sidebar nav.side a svg.icon.trailing { margin-left: auto; width: 13px; height: 13px; opacity: .45; }
.sidebar-foot .sidebar-signin { width: 100%; margin: 0; }
.shell .content.flush, .shell .content:has(> .custom-page) { max-width: none; padding: 0; }
/* A custom page's own HTML, placed straight into the shell (wwwroot/js/cortex.js); its CSS is scoped to this box. */
.custom-page { display: flow-root; position: relative; isolation: isolate; min-height: calc(100dvh - 56px); }
.custom-page-status { padding: 1.75rem 2rem; }
.app-shell .chat { height: calc(100vh - 56px - 2rem); margin: 1rem 0; max-width: none; padding: 0 1.5rem; }
.app-shell .chat-directory { margin: 2rem auto; }

/* navigation editor */
.nav-editor { display: grid; grid-template-columns: minmax(0, 1fr) 19rem; gap: 1.25rem; align-items: start; }
.shell .content .nav-editor .form { max-width: none; margin-top: 0; }
.nav-preview { overflow: hidden; }
.nav-preview .card-head { gap: .5rem; }
.nav-preview .card-head .muted { font-size: .8rem; margin-left: auto; }
.preview-sidebar { position: static; height: auto; min-height: 14rem; padding-bottom: .75rem; border-right: 0; }
.preview-sidebar nav.side { overflow: visible; }
.preview-error { color: #fca5a5; padding: 0 1.15rem; font-size: .85rem; }
.icon-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr)); gap: .4rem .6rem; font-size: .82rem; }
.icon-list span { display: flex; gap: .4rem; align-items: center; color: var(--fg-2); }
.icon-list svg.icon { width: 16px; height: 16px; color: var(--muted); }

/* providers */
td.api-key { min-width: 15rem; }
td.api-key input[type=password] { margin-top: .35rem; }
td.api-key label.inline { margin: .3rem 0 0; font-size: .85rem; }

/* web chat widgets */
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: .5rem; vertical-align: -1px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.snippet input { font-family: var(--mono); font-size: .82rem; background: var(--surface-2); }
input.color-pick { flex: none; width: 44px; min-height: 38px; padding: 3px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; }

/* ── dialog (slide-over) ──────────────────────────────────────────────────── */
.dialog-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px); display: flex; justify-content: flex-end; animation: fade .15s ease-out; }
.dialog { width: min(34rem, 100%); height: 100%; background: var(--surface); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slide .2s ease-out; }
.dialog-head { display: flex; align-items: center; gap: .75rem; padding: 1.1rem 1.4rem; border-bottom: 1px solid var(--border); }
.dialog-head h2 { margin: 0; font-size: 1.08rem; flex: 1; }
.dialog-body { flex: 1; overflow-y: auto; padding: .5rem 1.4rem 1.5rem; }
.dialog-foot { display: flex; gap: .5rem; justify-content: flex-end; align-items: center; padding: .9rem 1.4rem; border-top: 1px solid var(--border); background: var(--surface-2); }
.dialog-foot .btn { margin-top: 0; }
.dialog-foot .test-result { margin-right: auto; font-size: .86rem; }
.icon-btn { background: none; border: 0; padding: .35rem; border-radius: var(--radius-sm); color: var(--muted); cursor: pointer; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--bg-subtle); color: var(--fg); }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(24px); opacity: .6; } }

/* ── auth pages ───────────────────────────────────────────────────────────── */
body.auth-page { min-height: 100vh; display: flex; flex-direction: column; background: radial-gradient(900px 500px at 10% -10%, rgba(99,102,241,.18), transparent 60%), radial-gradient(700px 500px at 110% 110%, rgba(236,72,153,.12), transparent 60%), var(--bg); }
.auth-brand { display: flex; justify-content: center; align-items: center; gap: .6rem; padding: 3rem 1rem 1.25rem; font-weight: 650; font-size: 1.15rem; color: var(--fg); text-decoration: none; }
.auth-brand:hover { text-decoration: none; }
.auth { width: calc(100% - 2rem); max-width: 25rem; margin: 0 auto 3rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 2rem; box-shadow: var(--shadow-lg); }
.auth h1 { font-size: 1.35rem; margin-bottom: .25rem; }
.auth button.primary, .auth .btn { width: 100%; margin-top: 1.4rem; }
.sso { margin-top: 1.5rem; padding-top: 1.1rem; border-top: 1px solid var(--border); }
.sso p { color: var(--muted); font-size: .88rem; text-align: center; margin-top: 0; }
.sso form { margin: .5rem 0 0; }
.sso .btn { margin-top: 0; }
.auth-foot { text-align: center; color: var(--muted); font-size: .8rem; margin-top: auto; padding: 1.5rem; }

/* ── chat ─────────────────────────────────────────────────────────────────── */
.chat { display: grid; grid-template-columns: 15.5rem 1fr; gap: 1rem; max-width: 76rem; margin: 1rem auto; padding: 0 1.5rem; height: calc(100vh - 60px - 2rem); min-height: 26rem; }
body.embedded .chat { height: 100vh; margin: 0; max-width: none; padding: .5rem; }

.chat-side { display: flex; flex-direction: column; gap: .35rem; overflow: auto; padding: .25rem 0; }
.chat-side .btn { margin-top: 0; width: 100%; justify-content: flex-start; border-radius: var(--radius); min-height: 40px; }
.chat-side-head { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; margin: .9rem .6rem .25rem; }
.chat-side-head .chat-side-label { margin: 0; }
.chat-clear-all { font-size: .76rem; color: var(--muted); font-weight: 500; }
.chat-clear-all:hover { color: var(--danger); text-decoration: none; }
.chat-side-label { margin: .9rem .6rem .25rem; font-size: .72rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.chat-side ul { margin: 0; padding: 0; display: grid; gap: 1px; }
.chat-side li { display: flex; justify-content: space-between; align-items: center; gap: .25rem; padding: .45rem .6rem; border-radius: 8px; font-size: .9rem; }
.chat-side li:hover { background: var(--bg-subtle); }
.chat-side li.current { background: var(--surface); box-shadow: var(--shadow-sm); }
.chat-side li button.link { font-weight: 450; }
.chat-side li button.link:first-child { text-align: left; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.chat-side li button.link:not(:first-child) { color: var(--muted); font-size: 1rem; line-height: 1; padding: 0 .2rem; opacity: 0; transition: opacity .15s; }
.chat-side li:hover button.link:not(:first-child), .chat-side li.current button.link:not(:first-child), .chat-side li button.link:focus-visible { opacity: 1; }
.chat-side li button.link:not(:first-child):hover { color: var(--danger); text-decoration: none; }

.chat-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden; }
.chat-head { display: flex; align-items: center; gap: .75rem; padding: .85rem 1.25rem; border-bottom: 1px solid var(--border); }
.chat-head h1 { margin: 0; font-size: 1.02rem; font-weight: 600; }
.chat-head p { margin: .1rem 0 0; font-size: .8rem; }
.chat-head-text { flex: 1; min-width: 0; }
.chat-icon-btn { display: inline-grid; place-items: center; flex: none; width: 34px; height: 34px; padding: 0; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; transition: background .15s, color .15s, border-color .15s; }
.chat-icon-btn:hover { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger); }
.chat-icon-btn svg.icon { width: 17px; height: 17px; }

.chat-confirm { width: min(26rem, calc(100vw - 2rem)); padding: 1.25rem 1.35rem 1.1rem; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); color: var(--fg); box-shadow: var(--shadow-lg); }
.chat-confirm[open] { animation: msg-in .18s ease-out; }
.chat-confirm::backdrop { background: rgba(15, 23, 42, .45); }
.chat-confirm h2 { margin: 0 0 .4rem; font-size: 1.05rem; }
.chat-confirm p { margin: 0; font-size: .9rem; }
.chat-confirm-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.1rem; }
.chat-confirm-actions .btn { margin-top: 0; }
.chat-avatar { display: inline-grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); }
.chat-captcha { padding: .75rem 1.25rem 0; }

.chat-log { flex: 1; overflow: auto; padding: 1.5rem clamp(1rem, 4vw, 2.5rem); scroll-behavior: smooth; }
.chat-empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; animation: fade .3s ease-out; }
.chat-empty-title { margin: 0; font-size: 1.35rem; font-weight: 600; color: var(--fg); }

.msg { display: flex; align-items: flex-start; gap: .65rem; margin: 0 auto 1.1rem; max-width: 48rem; animation: msg-in .22s ease-out; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; min-width: 0; }
.msg-assistant::before { content: ""; flex: none; width: 28px; height: 28px; margin-top: .1rem; border-radius: 50%; background: var(--accent-soft) center / 16px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236366f1' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='4' y='8' width='16' height='12' rx='3'/%3E%3Cpath d='M12 8V4M9 13v2M15 13v2'/%3E%3C/svg%3E"); }
.msg-assistant .msg-body { padding: .2rem 0; color: var(--fg); flex: 1; }
.msg-user { justify-content: flex-end; }
.msg-user .msg-body { background: var(--accent); color: var(--accent-fg); padding: .6rem .95rem; border-radius: 18px 18px 5px 18px; max-width: min(36rem, 85%); }
.msg-error { margin-top: .4rem; padding: .5rem .75rem; border-radius: var(--radius-sm); background: var(--danger-soft); border: 1px solid var(--danger-border); color: var(--danger); font-size: .9rem; white-space: normal; }
.msg-meta { margin-top: .35rem; font-size: .76rem; color: var(--muted); }
.msg-tools { font-size: .78rem; color: var(--muted); margin: 0 0 .5rem; white-space: normal; }
.msg-tools li { display: inline-block; margin: 0 .35rem .3rem 0; padding: .1rem .55rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); }

/* Three dots that bounce in turn while the reply is being written. */
.typing { display: inline-flex; gap: 5px; align-items: center; height: 1.6em; padding: 0 .1rem; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: .4; animation: typing 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-5px); opacity: 1; } }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } }

.chat-compose { padding: .5rem clamp(1rem, 4vw, 2.5rem) .75rem; }
.chat-error { max-width: 48rem; margin: 0 auto .5rem; padding: .5rem .8rem; border-radius: var(--radius-sm); background: var(--danger-soft); border: 1px solid var(--danger-border); color: var(--danger); font-size: .88rem; animation: fade .2s ease-out; }
.chat-form { display: flex; gap: .5rem; align-items: flex-end; max-width: 48rem; margin: 0 auto; padding: .4rem .4rem .4rem .9rem; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 22px; box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s; }
.chat-form:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.chat-form textarea { flex: 1; resize: none; border: 0; outline: 0; box-shadow: none; background: transparent; padding: .5rem 0; min-height: 0; max-height: 12rem; font: inherit; line-height: 1.5; color: var(--fg); }
.chat-form textarea:focus { border: 0; box-shadow: none; outline: 0; }
.chat-send { display: inline-grid; place-items: center; flex: none; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%; background: var(--accent); color: var(--accent-fg); cursor: pointer; transition: background .15s, transform .1s; }
.chat-send:hover { background: var(--accent-hover); }
.chat-send:active { transform: scale(.94); }
.chat-send svg.icon { width: 18px; height: 18px; stroke-width: 2.2; }
.chat-hint { max-width: 48rem; margin: .4rem auto 0; text-align: center; font-size: .74rem; }

@media (prefers-reduced-motion: reduce) {
  .msg, .chat-empty, .chat-error, .chat-confirm[open] { animation: none; }
  .typing span { animation-duration: 2.4s; }
  .chat-log { scroll-behavior: auto; }
}
.chat-directory { max-width: 56rem; margin: 2.5rem auto; padding: 0 1.5rem; }

/* ── knowledge ────────────────────────────────────────────────────────────── */
.hit { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; margin: .7rem 0; background: var(--surface); box-shadow: var(--shadow-sm); }
.hit pre { white-space: pre-wrap; word-break: break-word; margin: .4rem 0 0; font: inherit; }
.upload { margin: .75rem 0; padding: 1rem; border: 1.5px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface); }

/* ── voice ────────────────────────────────────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: .6rem 0; min-height: 32px; }
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: .15rem .25rem .15rem .65rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); font-size: .88rem; }
.chip code { font-size: .75rem; padding: 0 .3rem; }
.chip .icon-btn { padding: .15rem; }
.chip .icon-btn svg.icon { width: 14px; height: 14px; }
.form .alert .btn { margin-top: .5rem; }

/* ── workflows ────────────────────────────────────────────────────────────── */
.approval-message { font-size: 1.05rem; white-space: pre-wrap; }
.filters { display: flex; gap: 1rem; flex-wrap: wrap; margin: .5rem 0; align-items: flex-end; }
.filters label { margin-top: 0; }
svg.workflow-graph { max-width: 100%; height: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
svg.workflow-graph .node rect { fill: var(--surface-2); stroke: var(--accent); stroke-width: 1.5; }
svg.workflow-graph .node.unreachable rect { stroke: var(--danger); stroke-dasharray: 4 3; }
svg.workflow-graph .node.delay rect, svg.workflow-graph .node.approval rect { stroke: var(--warn); }
svg.workflow-graph .node.http rect, svg.workflow-graph .node.workflow rect { stroke: var(--info); }
svg.workflow-graph .node-id { fill: var(--fg); font-size: 13px; font-weight: 600; }
svg.workflow-graph .node-detail, svg.workflow-graph .edge-label { fill: var(--muted); font-size: 11px; }
svg.workflow-graph .edge { fill: none; stroke: var(--muted); stroke-width: 1.4; }
svg.workflow-graph .arrowhead { fill: var(--muted); }

/* ── responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; width: 264px; transform: translateX(-100%); transition: transform .2s ease-out; box-shadow: var(--shadow-lg); }
  .shell.nav-open .sidebar { transform: none; }
  .nav-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(15,23,42,.45); }
  .shell.nav-open .nav-backdrop { display: block; }
  /* The page behind the open menu stays put instead of scrolling under it. */
  body:has(.shell.nav-open) { overflow: hidden; }
  .app-shell .chat { height: auto; padding: 0 1rem; }
  .nav-editor { grid-template-columns: 1fr; }
  .shell-top { padding: 0 1rem; }
  .shell-top .menu-btn { display: inline-grid; place-items: center; }
  .admin .content, .shell .content { padding: 1.25rem 1rem 3rem; }
  table.grid { display: block; overflow-x: auto; }
  table.status th { width: auto; }
  .chat { grid-template-columns: 1fr; height: auto; padding: 0 1rem; }
  .chat-side { max-height: 11rem; }
  .chat-side li button.link:not(:first-child) { opacity: 1; }
  .chat-log { min-height: 55vh; }
  main { padding: 0 1rem; margin: 1.25rem auto; }
  .topbar { padding: 0 1rem; }
  .hero { padding: 1.75rem 1.25rem; }
}
