/* ==========================================================================
   Sawn · صَوْن — application stylesheet (DESIGN SYSTEM v2)
   Tokens → base → shell → components → pages → motion → responsive.
   No inline styles are needed by the templates (CSP). Font families come
   from type.css (Agent I); the variables below are local fallbacks only.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */
:root {
  /* Fonts: type.css overrides these when present */
  --font-ar-display: "Alexandria", "Noto Naskh Arabic", "Geeza Pro", serif;
  --font-ar-text: "Vazirmatn", "IBM Plex Sans Arabic", "Noto Sans Arabic", "Geeza Pro", sans-serif;
  --font-latin: "Manrope", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Brand constants */
  --sawn-teal-900: #06343A;
  --sawn-teal-700: #0E5C63;
  --sawn-teal-500: #178A93;
  --sawn-teal-300: #5FC2CB;
  --sawn-gold-600: #A97B18;
  --sawn-gold-400: #E4BE4A;
  --sawn-paper: #F6F4EE;
  --sawn-ink: #15222A;
  --sawn-night: #0B1518;
  --sawn-coral: #E2614B;
  --sawn-moss: #3E9B86;

  /* Semantic — light */
  --canvas: var(--sawn-paper);
  --canvas-deep: #EEEBE2;
  --surface: #FFFFFF;
  --surface-2: #F1EFE8;
  --surface-3: #E8E5DC;
  --line: #DEDBD1;
  --line-strong: #C6C2B5;
  --text: var(--sawn-ink);
  --text-2: #46565F;
  --text-3: #6B7A82;
  --primary: var(--sawn-teal-700);
  --primary-strong: #0A454B;
  --primary-soft: #DCEEF0;
  --primary-ink: #FFFFFF;
  --accent: #8A6414;          /* gold, text-safe on light */
  --accent-graphic: var(--sawn-gold-600);
  --accent-soft: #F4EBD0;
  --ok: #1F7A4D;
  --ok-soft: #DDF1E6;
  --warn: #8A6414;
  --warn-soft: #F6ECCF;
  --danger: #B42318;
  --danger-soft: #FBE3DF;
  --info: var(--sawn-teal-700);
  --info-soft: var(--primary-soft);
  --heat-neg: var(--sawn-coral);
  --heat-pos: var(--sawn-teal-700);
  --heat-mid: #E6E3DA;
  --focus: #178A93;
  --shadow-1: 0 1px 2px rgb(21 34 42 / .06);
  --shadow-2: 0 10px 30px -18px rgb(21 34 42 / .35);
  --shadow-pop: 0 24px 60px -24px rgb(21 34 42 / .45);
  --sidebar-bg: #FBFAF6;
  --topbar-bg: rgb(246 244 238 / .82);

  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --sidebar-w: 256px;
  --sidebar-w-collapsed: 72px;
  --topbar-h: 60px;
  --content-max: 1320px;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-spring: cubic-bezier(.34, 1.4, .64, 1);
  --dur: 220ms;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --canvas: var(--sawn-night);
    --canvas-deep: #08100F;
    --surface: #122023;
    --surface-2: #17282C;
    --surface-3: #1E3237;
    --line: #213438;
    --line-strong: #2E464C;
    --text: #ECEFE9;
    --text-2: #AFBCBF;
    --text-3: #8696A0;
    --primary: var(--sawn-teal-300);
    --primary-strong: #86D6DD;
    --primary-soft: #113338;
    --primary-ink: #06343A;
    --accent: var(--sawn-gold-400);
    --accent-graphic: var(--sawn-gold-400);
    --accent-soft: #2E2612;
    --ok: #4CC38A;
    --ok-soft: #0F2E22;
    --warn: var(--sawn-gold-400);
    --warn-soft: #2E2612;
    --danger: #F27A6B;
    --danger-soft: #3A1915;
    --info: var(--sawn-teal-300);
    --info-soft: var(--primary-soft);
    --heat-neg: #F27A6B;
    --heat-pos: var(--sawn-teal-300);
    --heat-mid: #1E3237;
    --focus: var(--sawn-teal-300);
    --shadow-1: 0 1px 2px rgb(0 0 0 / .4);
    --shadow-2: 0 12px 30px -16px rgb(0 0 0 / .7);
    --shadow-pop: 0 30px 70px -30px rgb(0 0 0 / .9);
    --sidebar-bg: #0D191C;
    --topbar-bg: rgb(11 21 24 / .8);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --canvas: var(--sawn-night);
  --canvas-deep: #08100F;
  --surface: #122023;
  --surface-2: #17282C;
  --surface-3: #1E3237;
  --line: #213438;
  --line-strong: #2E464C;
  --text: #ECEFE9;
  --text-2: #AFBCBF;
  --text-3: #8696A0;
  --primary: var(--sawn-teal-300);
  --primary-strong: #86D6DD;
  --primary-soft: #113338;
  --primary-ink: #06343A;
  --accent: var(--sawn-gold-400);
  --accent-graphic: var(--sawn-gold-400);
  --accent-soft: #2E2612;
  --ok: #4CC38A;
  --ok-soft: #0F2E22;
  --warn: var(--sawn-gold-400);
  --warn-soft: #2E2612;
  --danger: #F27A6B;
  --danger-soft: #3A1915;
  --info: var(--sawn-teal-300);
  --info-soft: var(--primary-soft);
  --heat-neg: #F27A6B;
  --heat-pos: var(--sawn-teal-300);
  --heat-mid: #1E3237;
  --focus: var(--sawn-teal-300);
  --shadow-1: 0 1px 2px rgb(0 0 0 / .4);
  --shadow-2: 0 12px 30px -16px rgb(0 0 0 / .7);
  --shadow-pop: 0 30px 70px -30px rgb(0 0 0 / .9);
  --sidebar-bg: #0D191C;
  --topbar-bg: rgb(11 21 24 / .8);
  color-scheme: dark;
}

/* --------------------------------------------------------------------------
   2. Base
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--canvas);
  color: var(--text);
  font-family: var(--font-latin);
  font-size: 15px;
  line-height: 1.55;
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.015em; line-height: 1.2; text-wrap: balance; }
h1 { font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem); font-weight: 800; letter-spacing: -0.03em; }
h2 { font-size: 1.0625rem; }
h3 { font-size: .9375rem; }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; text-underline-offset: .15em; }
a:hover { text-decoration: underline; }
code, kbd, pre, .mono { font-family: var(--font-mono); font-size: .86em; font-feature-settings: "zero"; }
pre { margin: 0; white-space: pre-wrap; word-break: break-word; }
ul, ol { margin: 0; padding: 0; }
img, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-xs); }
::selection { background: var(--primary-soft); color: var(--text); }

[lang="ar"] { font-family: var(--font-ar-text); }
.ar-display { font-family: var(--font-ar-display); font-weight: 700; }
.num, .tabular { font-variant-numeric: tabular-nums lining-nums; }
.muted { color: var(--text-2); }
.small { font-size: .8125rem; }
.strong { font-weight: 700; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; inset-inline-start: 12px; top: -60px; z-index: 100; padding: 8px 14px; background: var(--primary); color: var(--primary-ink); border-radius: var(--radius-sm); font-weight: 600; }
.skip-link:focus { top: 12px; }
.nowrap { white-space: nowrap; }

/* --------------------------------------------------------------------------
   3. Shell: sidebar, topbar, main
   -------------------------------------------------------------------------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100dvh; transition: grid-template-columns var(--dur) var(--ease-out); }
.shell.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

.sidebar {
  position: sticky; top: 0; height: 100dvh; overflow: hidden auto;
  display: flex; flex-direction: column; gap: 6px;
  padding: 14px 12px;
  background: var(--sidebar-bg);
  border-inline-end: 1px solid var(--line);
  view-transition-name: sidebar;
  scrollbar-width: thin;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 14px; color: var(--text); text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-mark { flex: 0 0 auto; width: 36px; height: 36px; display: grid; place-items: center; }
.brand-mark img { width: 36px; height: 36px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; min-width: 0; white-space: nowrap; }
.brand-ar { font-family: var(--font-ar-display); font-weight: 700; font-size: 1.35rem; color: var(--text); }
.brand-lat { font-size: .6875rem; font-weight: 700; letter-spacing: .16em; color: var(--primary); margin-top: 3px; }

.nav { display: flex; flex-direction: column; gap: 18px; flex: 1; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-heading { margin: 4px 10px 6px; font-size: .6875rem; font-weight: 700; color: var(--text-3); letter-spacing: .02em; }
.nav-link {
  position: relative; display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 600; font-size: .9rem; text-decoration: none; white-space: nowrap;
  transition: background var(--dur), color var(--dur);
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.is-active { background: var(--primary-soft); color: var(--primary); }
.nav-link.is-active::before { content: ""; position: absolute; inset-inline-start: -12px; top: 8px; bottom: 8px; width: 3px; border-start-end-radius: 3px; border-end-end-radius: 3px; background: var(--primary); }
.nav-icon { flex: 0 0 auto; width: 20px; height: 20px; }
.nav-kbd { margin-inline-start: auto; font-family: var(--font-mono); font-size: .6875rem; color: var(--text-3); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 8px; min-width: 0; }
.avatar { flex: 0 0 auto; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--primary); color: var(--primary-ink); font-weight: 800; font-size: .875rem; }
.user-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.user-meta strong { font-size: .875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-actions { display: flex; gap: 4px; padding: 0 4px; }
.sidebar-actions .link-quiet { flex: 1; text-align: center; font-size: .78rem; color: var(--text-2); padding: 6px 4px; border-radius: var(--radius-xs); white-space: nowrap; }
.sidebar-actions .link-quiet:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.collapse-btn { display: none; }

/* Collapsed rail */
.shell.is-collapsed .sidebar { padding-inline: 10px; }
.shell.is-collapsed .brand-text,
.shell.is-collapsed .nav-heading,
.shell.is-collapsed .nav-link > span,
.shell.is-collapsed .nav-kbd,
.shell.is-collapsed .user-meta,
.shell.is-collapsed .sidebar-actions { display: none; }
.shell.is-collapsed .brand { justify-content: center; padding-inline: 0; }
.shell.is-collapsed .nav-link { justify-content: center; padding: 10px; }
.shell.is-collapsed .nav-link.is-active::before { inset-inline-start: -10px; }
.shell.is-collapsed .user-chip { justify-content: center; padding-inline: 0; }
.shell.is-collapsed .nav-group { gap: 4px; }

.content { display: flex; flex-direction: column; min-width: 0; min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-h); padding: 0 24px;
  background: var(--topbar-bg); backdrop-filter: blur(12px) saturate(140%); -webkit-backdrop-filter: blur(12px) saturate(140%);
  border-bottom: 1px solid var(--line);
}
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer;
  transition: background var(--dur), color var(--dur), border-color var(--dur);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }
.menu-btn { display: none; }

.crumbs { display: flex; align-items: center; gap: 4px; min-width: 0; flex: 1; font-size: .875rem; }
.crumbs ol { display: flex; align-items: center; gap: 4px; list-style: none; min-width: 0; }
.crumbs li { display: flex; align-items: center; gap: 4px; min-width: 0; color: var(--text-3); white-space: nowrap; }
.crumbs li + li::before { content: ""; width: 14px; height: 14px; background: currentColor; opacity: .5; mask: center / contain no-repeat url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'><path d='m8 5 5 5-5 5' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/></svg>"); -webkit-mask: center / contain no-repeat url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'><path d='m8 5 5 5-5 5' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/></svg>"); }
.crumbs a { color: var(--text-2); font-weight: 500; padding: 4px 6px; border-radius: var(--radius-xs); }
.crumbs a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.crumbs [aria-current] { color: var(--text); font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; padding: 4px 6px; }

.topbar-tools { display: flex; align-items: center; gap: 6px; margin-inline-start: auto; }
.cmd-btn {
  display: inline-flex; align-items: center; gap: 10px; height: 36px; padding-block: 0; padding-inline: 12px 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text-3); border-radius: var(--radius-sm);
  font-size: .8125rem; cursor: pointer; transition: border-color var(--dur), color var(--dur), box-shadow var(--dur);
}
.cmd-btn:hover { border-color: var(--line-strong); color: var(--text-2); box-shadow: var(--shadow-1); }
.cmd-btn svg { width: 16px; height: 16px; }
.cmd-btn kbd { font-size: .6875rem; border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; color: var(--text-3); background: var(--surface-2); }
.theme-btn .sun, .theme-btn .moon { transition: opacity var(--dur), transform 400ms var(--ease-spring); grid-area: 1 / 1; }
.theme-btn .moon { opacity: 0; transform: rotate(-60deg) scale(.6); }
:root[data-theme="dark"] .theme-btn .sun { opacity: 0; transform: rotate(60deg) scale(.6); }
:root[data-theme="dark"] .theme-btn .moon { opacity: 1; transform: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn .sun { opacity: 0; transform: rotate(60deg) scale(.6); }
  :root:not([data-theme="light"]) .theme-btn .moon { opacity: 1; transform: none; }
}

.main { flex: 1; width: 100%; max-width: var(--content-max); margin: 0 auto; padding: 28px 24px 56px; display: flex; flex-direction: column; gap: 24px; }
.main:focus { outline: none; }
.main-bare { max-width: none; padding: 0; gap: 0; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.page-head .lede { margin-top: 6px; max-width: 64ch; color: var(--text-2); font-size: .9375rem; }
.page-head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-head-actions form { display: contents; }
.eyebrow { font-size: .8125rem; font-weight: 600; color: var(--primary); margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }

.foot { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 18px 24px; border-top: 1px solid var(--line); color: var(--text-3); font-size: .78rem; }
.foot .ar-display { font-size: .95rem; color: var(--text-2); }

/* --------------------------------------------------------------------------
   4. Components
   -------------------------------------------------------------------------- */
/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font-weight: 600; font-size: .875rem; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background var(--dur), border-color var(--dur), color var(--dur), transform 160ms var(--ease-out), box-shadow var(--dur);
}
.btn:hover { text-decoration: none; border-color: var(--text-3); background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); box-shadow: inset 0 1px 0 rgb(255 255 255 / .12); }
.btn-primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); color: var(--primary-ink); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.92); background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-ghost { border-color: transparent; color: var(--danger); background: transparent; }
.btn-danger-ghost:hover { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn-sm { height: 30px; padding: 0 10px; font-size: .8125rem; border-radius: 6px; }
.btn-block { width: 100%; height: 44px; font-size: .9375rem; }
.btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.btn-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; min-width: 0; }
.card-flush { padding: 0; overflow: hidden; }
.card-quiet { background: transparent; border-style: dashed; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { display: flex; align-items: center; gap: 8px; }
.card-flush .card-head { padding: 16px 18px 0; margin-bottom: 12px; }
.card-lift { transition: transform var(--dur) var(--ease-out), box-shadow var(--dur), border-color var(--dur); }
.card-lift:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--line-strong); }
.sub-title { margin-top: 20px; margin-bottom: 4px; }
.link { font-weight: 600; }
.link-quiet { color: inherit; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.grid-2-wide { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
.grid-form { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, .8fr); gap: 20px; align-items: start; }
.narrow { max-width: 560px; }

/* Tables */
.table-wrap { overflow: auto; -webkit-overflow-scrolling: touch; scrollbar-width: thin; container-type: scroll-state; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .875rem; }
.table th, .table td { padding: 11px 14px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2); color: var(--text-2); font-weight: 600; font-size: .75rem; letter-spacing: .01em;
  white-space: nowrap;
}
.table-dense th, .table-dense td { padding: 8px 12px; font-size: .8125rem; }
.table tbody tr { transition: background 120ms; }
.table tbody tr:hover > td { background: var(--primary-soft); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: end; font-variant-numeric: tabular-nums lining-nums; }
.table .actions-col { width: 1%; text-align: end; white-space: nowrap; }
.table .actions-col .btn-row { flex-wrap: nowrap; justify-content: flex-end; }
.table-zebra tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.table-zebra tbody tr:hover > td { background: var(--primary-soft); }
.row-highlight td { background: var(--accent-soft) !important; }
.row-bad td { background: var(--danger-soft) !important; }
.cell-primary { font-weight: 700; color: var(--text); }
.cell-sub { color: var(--text-3); font-size: .78rem; margin-top: 2px; }
.cell-ellipsis { display: block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.details { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px; border-top: 1px solid var(--line); color: var(--text-3); font-size: .8125rem; flex-wrap: wrap; }

/* Hashes & ids */
.hash { font-family: var(--font-mono); font-size: .76rem; color: var(--text-2); background: var(--surface-2); padding: 2px 6px; border-radius: 4px; letter-spacing: 0; white-space: nowrap; }
.hash-full { word-break: break-all; }
.id-mono { font-family: var(--font-mono); font-size: .8rem; color: var(--text-2); }

/* Badges, tags, pills */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 999px; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-off { background: var(--surface-3); color: var(--text-2); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; position: relative; }
.badge-ok .dot::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 1.5px solid currentColor; opacity: 0; }
.tag { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2); font-size: .74rem; font-weight: 600; font-family: var(--font-mono); letter-spacing: 0; white-space: nowrap; }
.tag-auth { color: var(--info); }
.tag-dataset { color: var(--ok); }
.tag-analysis { color: var(--primary); }
.tag-user, .tag-admin { color: var(--accent); }
.role { display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 999px; font-size: .72rem; font-weight: 700; text-transform: capitalize; }
.role-admin { background: var(--accent-soft); color: var(--accent); }
.role-doctor { background: var(--primary-soft); color: var(--primary); }
.role-analyst { background: var(--surface-3); color: var(--text-2); }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; }
.chip { padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); font-size: .8rem; font-family: var(--font-mono); color: var(--text-2); }
.chip-num { background: var(--primary-soft); border-color: transparent; color: var(--primary); font-weight: 600; }

/* Definition lists */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 10px 18px; font-size: .9rem; }
.dl dt { font-weight: 700; color: var(--text); }
.dl dd { margin: 0; color: var(--text-2); }
.meta { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px 20px; margin: 0; }
.meta > div { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.meta dt { font-size: .75rem; font-weight: 600; color: var(--text-3); }
.meta dd { margin: 0; font-weight: 700; font-size: 1rem; }
.meta dd.num { text-align: start; }
.meta-wide { grid-column: 1 / -1; }
.steps { padding-inline-start: 20px; display: grid; gap: 10px; color: var(--text-2); font-size: .9rem; }
.steps li::marker { color: var(--primary); font-weight: 800; font-variant-numeric: tabular-nums; }
.notes { padding-inline-start: 18px; display: grid; gap: 8px; color: var(--text-2); font-size: .875rem; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-weight: 600; font-size: .875rem; }
.input, .select, .textarea {
  width: 100%; height: 42px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font: inherit; font-size: .9375rem;
  transition: border-color var(--dur), box-shadow var(--dur);
}
.textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; }
.select { appearance: none; padding-inline-end: 36px; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'><path d='m5 8 5 5 5-5' fill='none' stroke='%236B7A82' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/></svg>"); background-repeat: no-repeat; background-position: right 12px center; background-size: 16px; }
.select-sm { height: 32px; font-size: .8125rem; padding-inline-end: 30px; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); }
.field.has-error .input, .field.has-error .select { border-color: var(--danger); }
.help { font-size: .8rem; color: var(--text-3); }
.error { font-size: .8rem; color: var(--danger); font-weight: 600; }
.check { display: inline-flex; align-items: center; gap: 10px; font-size: .9rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); margin: 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }
.inline-label { display: inline-flex; align-items: center; gap: 8px; font-size: .8125rem; color: var(--text-2); }
.dropzone { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 28px 16px; border: 1.5px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface-2); text-align: center; transition: border-color var(--dur), background var(--dur); }
.dropzone:hover, .dropzone.is-over { border-color: var(--primary); background: var(--primary-soft); }
.dropzone:has(:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.file-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.dropzone-text { font-weight: 600; }
.dropzone-hint { font-size: .8rem; color: var(--text-3); }
.filter-row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.filter-row .field { gap: 4px; }
.filter-row .label { font-size: .75rem; color: var(--text-3); }
.filter-row .input, .filter-row .select { height: 36px; font-size: .875rem; min-width: 160px; }

/* Toasts */
.flash-stack { position: fixed; top: calc(var(--topbar-h) + 12px); inset-inline-end: 16px; z-index: 80; display: flex; flex-direction: column; gap: 10px; width: min(380px, calc(100vw - 28px)); pointer-events: none; }
.flash {
  pointer-events: auto; display: grid; grid-template-columns: auto 1fr auto; align-items: start; gap: 10px;
  padding-block: 12px; padding-inline: 14px 12px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); box-shadow: var(--shadow-pop); font-size: .875rem; overflow: hidden; position: relative;
}
.flash::after { content: ""; position: absolute; inset-inline-start: 0; bottom: 0; height: 2px; width: 100%; background: var(--flash-color, var(--primary)); transform-origin: left; }
[dir="rtl"] .flash::after { transform-origin: right; }
.flash-dot { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--flash-color) 16%, transparent); color: var(--flash-color); margin-top: 1px; }
.flash-dot svg { width: 14px; height: 14px; }
.flash p { padding-top: 2px; }
.flash-success { --flash-color: var(--ok); }
.flash-error { --flash-color: var(--danger); }
.flash-warning { --flash-color: var(--warn); }
.flash-info { --flash-color: var(--info); }
.flash-close { border: 0; background: transparent; color: var(--text-3); font-size: 1.2rem; line-height: 1; cursor: pointer; width: 26px; height: 26px; border-radius: 6px; }
.flash-close:hover { background: var(--surface-2); color: var(--text); }
.flash.is-leaving { opacity: 0; transform: translateX(16px); transition: opacity 200ms, transform 200ms; }
[dir="rtl"] .flash.is-leaving { transform: translateX(-16px); }

/* Banners */
.banner { display: flex; align-items: flex-start; gap: 12px; padding: 12px 16px; border-radius: var(--radius); border: 1px solid; font-size: .9rem; }
.banner svg { flex: 0 0 auto; width: 20px; height: 20px; margin-top: 1px; }
.banner-ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 30%, transparent); color: var(--ok); }
.banner-warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); color: var(--warn); }
.banner-danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); color: var(--danger); }
.banner strong { color: inherit; }
.banner-live { position: relative; overflow: hidden; }
.banner-live::before { content: ""; position: absolute; inset: 0; background: linear-gradient(100deg, transparent 30%, rgb(255 255 255 / .35) 50%, transparent 70%); transform: translateX(-100%); }

/* Empty state */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 48px 20px; text-align: center; color: var(--text-2); }
.empty svg { width: 52px; height: 52px; color: var(--primary); opacity: .7; margin-bottom: 6px; }
.empty h3 { color: var(--text); font-size: 1.05rem; }
.empty p { max-width: 42ch; }
.empty .btn { margin-top: 10px; }

/* Pager */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px; border-top: 1px solid var(--line); }
.pager-status { font-size: .8125rem; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* Command palette */
.cmdk { border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: var(--shadow-pop); margin: 12vh auto auto; }
.cmdk::backdrop { background: rgb(6 20 24 / .45); backdrop-filter: blur(3px); }
.cmdk-input { width: 100%; height: 54px; padding: 0 18px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--text); font: inherit; font-size: 1rem; outline: none; }
.cmdk-list { list-style: none; max-height: 50vh; overflow: auto; padding: 8px; }
.cmdk-list a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm); color: var(--text); font-weight: 600; font-size: .9rem; }
.cmdk-list a:hover, .cmdk-list a:focus-visible, .cmdk-list li.is-active a { background: var(--primary-soft); color: var(--primary); text-decoration: none; outline: none; }
.cmdk-list a svg { width: 18px; height: 18px; opacity: .8; }
.cmdk-list a small { margin-inline-start: auto; direction: ltr; color: var(--text-3); font-weight: 500; }
.cmdk-foot { display: flex; gap: 14px; padding: 8px 16px; border-top: 1px solid var(--line); font-size: .74rem; color: var(--text-3); }
.cmdk-foot kbd { font-size: .7rem; border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; background: var(--surface-2); }

/* Skeleton */
.skeleton { position: relative; overflow: hidden; background: var(--surface-2); border-radius: var(--radius-sm); }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 70%, transparent), transparent); }

/* --------------------------------------------------------------------------
   5. Pages
   -------------------------------------------------------------------------- */
/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 20px 22px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: inherit; text-decoration: none; min-width: 0; overflow: hidden; }
a.stat { transition: transform var(--dur) var(--ease-out), box-shadow var(--dur), border-color var(--dur); }
a.stat:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--line-strong); }
.stat-label { order: -1; font-size: .8125rem; font-weight: 600; color: var(--text-2); }
.stat-value { font-size: 2.25rem; font-weight: 800; letter-spacing: -0.04em; line-height: 1; color: var(--text); font-variant-numeric: lining-nums; }
.stat-value.is-text { font-size: 1.5rem; letter-spacing: -0.02em; font-family: var(--font-mono); font-weight: 700; color: var(--primary); margin-top: 6px; }
.stat-note { font-size: .78rem; color: var(--text-3); margin-top: 6px; text-wrap: pretty; }
.stat-accent { background: linear-gradient(135deg, var(--surface), var(--primary-soft)); }
.stat-accent::after { content: ""; position: absolute; inset-inline-end: -30px; top: -30px; width: 110px; height: 110px; border-radius: 50%; border: 18px solid color-mix(in srgb, var(--primary) 12%, transparent); }
.stat-gold .stat-value { color: var(--accent); }

/* Encryption rail — the dashboard's signature element */
.rail-card { position: relative; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 22px 24px 20px; }
.rail-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.rail-head h2 { font-size: 1.125rem; }
.rail-head p { color: var(--text-2); font-size: .875rem; }
.rail { position: relative; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 34px; min-height: 92px; }
.rail-side { position: relative; height: 84px; border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; font-family: var(--font-mono); font-size: .8rem; display: flex; align-items: flex-end; padding-bottom: 18px; }
.rail-plain { background: var(--surface-2); color: var(--text-2); }
.rail-cipher { background: var(--sawn-teal-900); color: var(--sawn-teal-300); border-color: transparent; }
.rail-tape { display: flex; gap: 28px; white-space: nowrap; padding-left: 16px; will-change: transform; direction: ltr; }
.rail-tape span { display: inline-block; }
.rail-cipher .rail-tape { color: var(--sawn-teal-300); opacity: .9; }
.rail-side::after { content: ""; position: absolute; inset: 0; pointer-events: none; }
.rail-plain::after { background: linear-gradient(90deg, var(--surface-2) 0%, transparent 9%, transparent 91%, var(--surface-2) 100%); }
.rail-cipher::after { background: linear-gradient(90deg, var(--sawn-teal-900) 0%, transparent 9%, transparent 91%, var(--sawn-teal-900) 100%); }
.rail-label { position: absolute; inset-inline-start: 12px; top: 10px; font-family: var(--font-latin); font-size: .68rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--text-2); z-index: 1; }
.rail-cipher .rail-label { background: var(--sawn-teal-900); color: var(--sawn-teal-300); border-color: rgb(95 194 203 / .3); }
.rail-lock { position: relative; width: 84px; height: 84px; display: grid; place-items: center; border-radius: 50%; background: var(--primary); color: var(--primary-ink); box-shadow: 0 0 0 8px color-mix(in srgb, var(--primary) 12%, transparent), 0 0 0 18px color-mix(in srgb, var(--primary) 5%, transparent); }
.rail-lock svg { width: 36px; height: 36px; }
.rail-lock .ring { position: absolute; inset: -8px; border-radius: 50%; border: 1.5px solid color-mix(in srgb, var(--primary) 45%, transparent); }
.rail-arrow { position: absolute; top: 50%; height: 2px; width: 24px; background: repeating-linear-gradient(90deg, var(--primary) 0 6px, transparent 6px 10px); transform: translateY(-50%); }
.rail-arrow-in { inset-inline-start: -36px; }
.rail-arrow-out { inset-inline-end: -36px; }
.rail-facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 18px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.rail-facts div { display: flex; flex-direction: column; gap: 2px; font-size: .8125rem; color: var(--text-2); }
.rail-facts strong { color: var(--text); font-size: .9rem; }
.rail-facts code { color: var(--primary); }

/* Audit feed */
.audit-feed { list-style: none; display: flex; flex-direction: column; }
.audit-feed li { display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "action meta time" "action hash hash"; column-gap: 12px; row-gap: 2px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.audit-feed li:last-child { border-bottom: 0; }
.audit-feed .audit-action { grid-area: action; }
.audit-feed .audit-meta { grid-area: meta; font-size: .85rem; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audit-feed .audit-time { grid-area: time; font-family: var(--font-mono); font-size: .74rem; color: var(--text-3); }
.audit-feed .hash { grid-area: hash; justify-self: start; }
.feed-live { display: inline-flex; align-items: center; gap: 6px; font-size: .75rem; font-weight: 700; color: var(--ok); }
.feed-live .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 0 currentColor; }

/* Role card */
.role-card h2 { margin-bottom: 12px; }

/* Analysis */
.analysis-grid { display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); gap: 20px; align-items: start; }
.result-card { min-height: 100%; }
.result-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 8px; min-height: 180px; color: var(--text-2); }
.result-empty svg { width: 40px; height: 40px; color: var(--primary); opacity: .6; }
.result-body { padding: 8px 0 4px; }
.big-number { font-size: clamp(2.6rem, 2rem + 2.5vw, 4rem); font-weight: 800; letter-spacing: -0.045em; line-height: 1; color: var(--primary); }
.big-label { display: block; margin-top: 10px; font-family: var(--font-mono); font-size: .78rem; font-weight: 500; letter-spacing: 0; color: var(--text-3); }
.summary-grid.is-meta { margin-top: 18px; }
.summary-grid.is-meta dd { font-size: 1rem; }
.summary-grid.is-meta > div:first-child { background: var(--surface-2); border-color: var(--line); }
.summary-grid.is-meta > div:first-child dd { color: var(--text); }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin: 0; }
.summary-grid > div { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.summary-grid dt { font-size: .72rem; font-weight: 700; color: var(--text-3); font-family: var(--font-mono); }
.summary-grid dd { margin: 0; font-size: 1.25rem; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.summary-grid > div:first-child { background: var(--primary-soft); border-color: transparent; }
.summary-grid > div:first-child dd { color: var(--primary); }
.result-meta { list-style: none; display: flex; gap: 18px; flex-wrap: wrap; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); font-size: .8125rem; color: var(--text-2); }
.result-meta strong { color: var(--text); font-variant-numeric: tabular-nums; }
.result-raw, .raw pre { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line); font-size: .8rem; }
.raw { margin-top: 12px; }
.raw summary { cursor: pointer; font-size: .8125rem; font-weight: 600; color: var(--text-2); }
.raw pre { margin-top: 8px; }
.result-inline { font-size: .75rem; color: var(--text-2); }
.chart-box { position: relative; height: 300px; }
.chart-box-tall { height: 340px; }
.chart-box canvas { position: absolute; inset: 0; }
.chart-status { position: absolute; inset: 0; display: grid; place-items: center; font-size: .85rem; color: var(--text-3); z-index: 1; }
.chart-skeleton { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 6px; padding: 12px 8px 28px; }
.chart-skeleton span { flex: 1; border-radius: 4px 4px 0 0; }
.chart-skeleton span:nth-child(1) { height: 30%; } .chart-skeleton span:nth-child(2) { height: 55%; } .chart-skeleton span:nth-child(3) { height: 80%; } .chart-skeleton span:nth-child(4) { height: 100%; } .chart-skeleton span:nth-child(5) { height: 72%; } .chart-skeleton span:nth-child(6) { height: 48%; } .chart-skeleton span:nth-child(7) { height: 30%; } .chart-skeleton span:nth-child(8) { height: 16%; }
.chart-box.is-loading canvas { opacity: 0; }
.chart-box:not(.is-loading) .chart-skeleton { display: none; }

/* Heatmap */
.heatmap-wrap { position: relative; min-height: 220px; overflow-x: auto; }
.heatmap { display: grid; gap: 3px; align-items: stretch; }
.heatmap-corner { }
.heatmap-head { writing-mode: vertical-rl; transform: rotate(180deg); font-family: var(--font-mono); font-size: .72rem; color: var(--text-2); padding: 0 0 6px; max-height: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; align-self: end; justify-self: center; }
.heatmap-row { font-family: var(--font-mono); font-size: .72rem; color: var(--text-2); display: block; align-self: center; padding-inline: 4px 8px; direction: ltr; text-align: end; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
[dir="rtl"] .heatmap-row { text-align: start; padding-inline: 8px 4px; }
.heatmap-cell { aspect-ratio: 1; min-height: 24px; min-width: 0; border-radius: 5px; display: grid; place-items: center; font-family: var(--font-mono); font-size: .68rem; font-variant-numeric: tabular-nums; color: var(--text); transition: transform 120ms var(--ease-out), box-shadow 120ms; }
.heatmap-cell:hover { transform: scale(1.08); box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--primary); z-index: 1; }
.heatmap-cell.is-diag { opacity: .55; }
.heatmap.is-compact .heatmap-cell { font-size: 0; min-height: 18px; }
.heatmap-legend { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-family: var(--font-mono); font-size: .72rem; color: var(--text-3); }
.heatmap-scale { flex: 0 0 160px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--heat-neg), var(--heat-mid), var(--heat-pos)); }
.heatmap-table { margin-top: 14px; }
.heatmap-table summary { cursor: pointer; font-size: .8125rem; font-weight: 600; color: var(--text-2); }

/* Benchmark */
.bench-hero { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 20px; align-items: stretch; }
.bench-callout { position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: center; gap: 8px; padding: 30px 32px; border-radius: var(--radius-lg); background: var(--sawn-teal-900); color: #F6F4EE; }
.bench-callout::before { content: ""; position: absolute; inset-inline-end: -80px; bottom: -120px; width: 340px; height: 340px; border-radius: 50%; border: 48px solid rgb(95 194 203 / .12); }
.bench-callout .k { font-size: .875rem; color: var(--sawn-teal-300); font-weight: 600; }
.bench-callout .v { font-size: clamp(3rem, 2.4rem + 3vw, 5rem); font-weight: 800; letter-spacing: -0.05em; line-height: .95; }
.bench-callout .v em { font-style: normal; color: var(--sawn-gold-400); }
.bench-callout .d { color: rgb(246 244 238 / .78); font-size: .9375rem; max-width: 40ch; margin-top: 6px; text-wrap: pretty; }
.bench-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.bench-tiles .stat { padding: 16px 18px; }
.bench-tiles .stat-value { font-size: 1.6rem; }
.bench-tiles .stat-value small { font-size: .9rem; font-weight: 600; color: var(--text-3); letter-spacing: 0; margin-inline-start: 3px; }
.bench-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: .8125rem; color: var(--text-2); }
.bench-legend span { display: inline-flex; align-items: center; gap: 6px; }
.bench-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* Records */
.records-banner { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: var(--radius); border: 1px solid color-mix(in srgb, var(--accent-graphic) 45%, transparent); background: var(--accent-soft); color: var(--text); font-size: .875rem; }
.records-banner svg { flex: 0 0 auto; width: 20px; height: 20px; color: var(--accent); }
.records-banner strong { color: var(--accent); }
.records-banner .spacer { flex: 1; }
.records-banner .mem { font-family: var(--font-mono); font-size: .74rem; color: var(--accent); white-space: nowrap; }
.table-records thead th:first-child, .table-records td:first-child { position: sticky; inset-inline-start: 0; z-index: 3; background: var(--surface-2); }
.table-records thead th:first-child { z-index: 4; }
.table-records td:first-child { font-family: var(--font-mono); font-size: .76rem; color: var(--text-3); }
.table-records td.is-num { text-align: end; font-variant-numeric: tabular-nums; font-family: var(--font-mono); font-size: .8rem; }
.table-records td.is-id { font-family: var(--font-mono); font-size: .8rem; color: var(--primary); font-weight: 600; }

/* Auth */
body.auth { background: var(--canvas); }
.auth-wrap { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); min-height: 100dvh; }
.auth-scene { position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; padding: 40px 48px; color: #F6F4EE; background: var(--sawn-teal-900); isolation: isolate; }
.auth-scene::before, .auth-scene::after { content: ""; position: absolute; inset: -40%; z-index: -1; filter: blur(70px); opacity: .8; }
.auth-scene::before { background: radial-gradient(40% 40% at 30% 30%, rgb(23 138 147 / .9), transparent 70%), radial-gradient(35% 35% at 75% 70%, rgb(95 194 203 / .55), transparent 70%); }
.auth-scene::after { background: radial-gradient(30% 30% at 70% 25%, rgb(228 190 74 / .35), transparent 70%), radial-gradient(45% 45% at 20% 80%, rgb(6 52 58 / 1), transparent 70%); mix-blend-mode: screen; }
.auth-grid { position: absolute; inset: 0; z-index: -1; background-image: linear-gradient(rgb(246 244 238 / .05) 1px, transparent 1px), linear-gradient(90deg, rgb(246 244 238 / .05) 1px, transparent 1px); background-size: 48px 48px; mask-image: radial-gradient(70% 70% at 50% 50%, black, transparent); -webkit-mask-image: radial-gradient(70% 70% at 50% 50%, black, transparent); }
.auth-scene .brand { color: #F6F4EE; padding: 0; }
.auth-scene .brand-ar { color: #F6F4EE; }
.auth-scene .brand-lat { color: var(--sawn-teal-300); }
.auth-scene .brand-mark { width: 44px; height: 44px; filter: brightness(0) invert(1) sepia(.1) saturate(.6) brightness(1.05); }
.auth-hero { display: flex; flex-direction: column; gap: 16px; }
.auth-hero .ar-display { font-size: clamp(2.6rem, 2rem + 3vw, 4.4rem); line-height: 1.3; letter-spacing: 0; font-weight: 700; color: #F6F4EE; text-align: left; }
[dir="rtl"] .auth-hero .ar-display { text-align: right; }
.auth-hero .ar-display em { font-style: normal; color: var(--sawn-gold-400); }
.auth-hero .en { max-width: 36ch; font-size: 1.0625rem; color: rgb(246 244 238 / .82); text-wrap: pretty; }
.auth-points { display: grid; gap: 10px; list-style: none; margin-top: 8px; }
.auth-points li { display: flex; align-items: center; gap: 10px; font-size: .875rem; color: rgb(246 244 238 / .85); }
.auth-points svg { width: 18px; height: 18px; color: var(--sawn-teal-300); flex: 0 0 auto; }
.auth-foot { font-size: .78rem; color: rgb(246 244 238 / .55); }
.auth-panel { position: relative; display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.auth-card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 22px; }
.auth-card h1 { font-size: 1.75rem; }
.auth-card .auth-sub { color: var(--text-2); margin-top: 6px; }
.auth-notes { list-style: none; display: grid; gap: 8px; padding-top: 18px; border-top: 1px solid var(--line); font-size: .8125rem; color: var(--text-3); }
.auth-notes li { display: flex; gap: 8px; align-items: flex-start; }
.auth-notes svg { width: 16px; height: 16px; flex: 0 0 auto; margin-top: 2px; color: var(--primary); }
.auth-tools { position: absolute; top: 14px; inset-inline-end: 14px; display: flex; align-items: center; gap: 6px; }

/* Errors */
.error-page { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; max-width: 560px; margin: 6vh auto; padding: 0 8px; }
.error-code { font-family: var(--font-mono); font-size: clamp(4rem, 3rem + 6vw, 8rem); font-weight: 700; letter-spacing: -0.06em; line-height: .9; color: var(--primary); position: relative; }
.error-code::after { content: ""; position: absolute; inset-inline-start: 0; bottom: -10px; height: 3px; width: 48px; background: var(--accent-graphic); border-radius: 2px; }
.error-page h2 { font-size: 1.5rem; letter-spacing: -0.02em; margin-top: 10px; }
.error-page p { color: var(--text-2); max-width: 52ch; }
.error-page .ar-display { font-size: 1.25rem; color: var(--text-3); font-weight: 500; }
.error-art { width: 100%; max-width: 320px; color: var(--primary); margin-top: 8px; }

/* --------------------------------------------------------------------------
   6. Motion (only inside no-preference; static otherwise)
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
  ::view-transition-old(root) { animation: 160ms ease-in both vt-out; }
  ::view-transition-new(root) { animation: 260ms var(--ease-out) both vt-in; }
  ::view-transition-group(sidebar) { animation: none; }
  @keyframes vt-out { to { opacity: 0; } }
  @keyframes vt-in { from { opacity: 0; transform: translateY(6px); } }

  .flash { animation: toast-in 420ms var(--ease-spring) both; }
  .flash::after { animation: toast-bar var(--toast-life, 6s) linear forwards; }
  .flash-error::after, .flash-warning::after { animation: none; }
  @keyframes toast-in { from { opacity: 0; transform: translateX(24px) scale(.96); } }
  [dir="rtl"] .flash { animation-name: toast-in-rtl; }
  @keyframes toast-in-rtl { from { opacity: 0; transform: translateX(-24px) scale(.96); } }
  @keyframes toast-bar { from { transform: scaleX(1); } to { transform: scaleX(0); } }

  .badge-ok .dot::after { animation: pulse-ring 2.4s ease-out infinite; }
  .feed-live .dot { animation: pulse-dot 2s ease-out infinite; }
  @keyframes pulse-ring { 0% { transform: scale(.5); opacity: .8; } 100% { transform: scale(1.4); opacity: 0; } }
  @keyframes pulse-dot { 0% { box-shadow: 0 0 0 0 currentColor; } 100% { box-shadow: 0 0 0 8px transparent; } }

  .rail-tape { animation: tape 22s linear infinite; }
  .rail-cipher .rail-tape { animation-duration: 16s; }
  .rail-lock .ring { animation: lock-ring 3s ease-in-out infinite; }
  .rail-arrow { animation: dash 900ms linear infinite; background-size: 10px 2px; }
  @keyframes tape { to { transform: translateX(-50%); } }
  @keyframes lock-ring { 0%, 100% { transform: scale(1); opacity: .5; } 50% { transform: scale(1.12); opacity: 1; } }
  @keyframes dash { to { background-position: 10px 0; } }

  .skeleton::after, .chart-skeleton span::after { animation: shimmer 1.4s ease-in-out infinite; }
  @keyframes shimmer { to { transform: translateX(100%); } }

  .banner-live::before { animation: sweep 3.2s ease-in-out infinite; }
  @keyframes sweep { 0%, 35% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

  .audit-feed li { animation: feed-in 520ms var(--ease-out) both; }
  .audit-feed li:nth-child(1) { animation-delay: 60ms; } .audit-feed li:nth-child(2) { animation-delay: 160ms; } .audit-feed li:nth-child(3) { animation-delay: 260ms; } .audit-feed li:nth-child(4) { animation-delay: 360ms; } .audit-feed li:nth-child(5) { animation-delay: 460ms; } .audit-feed li:nth-child(6) { animation-delay: 560ms; } .audit-feed li:nth-child(7) { animation-delay: 660ms; } .audit-feed li:nth-child(8) { animation-delay: 760ms; } .audit-feed li:nth-child(9) { animation-delay: 860ms; } .audit-feed li:nth-child(10) { animation-delay: 960ms; }
  @keyframes feed-in { from { opacity: 0; transform: translateY(-8px); background: var(--primary-soft); } 60% { background: var(--primary-soft); } to { background: transparent; } }

  .auth-scene::before { animation: mesh-a 18s ease-in-out infinite alternate; }
  .auth-scene::after { animation: mesh-b 24s ease-in-out infinite alternate; }
  @keyframes mesh-a { to { transform: translate(6%, 4%) rotate(8deg) scale(1.08); } }
  @keyframes mesh-b { to { transform: translate(-5%, -6%) rotate(-10deg) scale(1.1); } }

  .cmdk[open] { animation: cmdk-in 200ms var(--ease-out); }
  .cmdk[open]::backdrop { animation: fade 200ms ease; }
  @keyframes cmdk-in { from { opacity: 0; transform: translateY(-8px) scale(.98); } }
  @keyframes fade { from { opacity: 0; } }

  @supports ((animation-timeline: view()) and (animation-range: entry)) {
    .reveal { animation: reveal linear both; animation-timeline: view(); animation-range: entry 0% entry 35%; }
    @keyframes reveal { from { opacity: .4; transform: translateY(10px); } }
  }
}

/* Scroll affordance on wide tables */
.table-wrap::before, .table-wrap::after { content: ""; display: none; }
@supports (container-type: scroll-state) {
  .table-wrap { position: relative; }
}

/* --------------------------------------------------------------------------
   7. Responsive
   -------------------------------------------------------------------------- */
@media (min-width: 981px) {
  .collapse-btn { display: inline-grid; }
}
@media (max-width: 1180px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rail-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bench-hero { grid-template-columns: 1fr; }
}
@media (max-width: 980px) {
  .shell, .shell.is-collapsed { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset-block: 0; inset-inline: 0 auto; width: min(300px, 86vw); z-index: 60; transform: translateX(-100%); transition: transform 260ms var(--ease-out); box-shadow: none; view-transition-name: none; }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  .sidebar.is-open, [dir="rtl"] .sidebar.is-open { transform: none; box-shadow: var(--shadow-pop); }
  .shell.is-collapsed .brand-text, .shell.is-collapsed .nav-heading, .shell.is-collapsed .nav-link > span, .shell.is-collapsed .user-meta, .shell.is-collapsed .sidebar-actions, .shell.is-collapsed .nav-kbd { display: revert; }
  .shell.is-collapsed .nav-link { justify-content: flex-start; padding: 9px 10px; }
  .shell.is-collapsed .brand { justify-content: flex-start; padding: 6px 8px 14px; }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 55; background: rgb(6 20 24 / .45); backdrop-filter: blur(2px); }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 0 16px; }
  .cmd-btn span { display: none; }
  .cmd-btn { padding: 0 9px; }
  .main { padding: 20px 16px 48px; gap: 18px; }
  .grid-2, .grid-2-wide, .grid-form, .analysis-grid { grid-template-columns: 1fr; }
  .meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-scene { padding: 28px 24px; min-height: 0; gap: 26px; }
  .auth-hero .ar-display { font-size: 2.4rem; }
  .auth-points { display: none; }
  .auth-panel { padding: 28px 16px 40px; }
}
@media (max-width: 560px) {
  body { font-size: 14.5px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 14px 14px; }
  .stat-value { font-size: 1.75rem; }
  .stat-value.is-text { font-size: 1.05rem; }
  .stat-note { display: none; }
  .rail { grid-template-columns: 1fr; gap: 14px; min-height: 0; }
  .rail-lock { width: 64px; height: 64px; justify-self: center; }
  .rail-lock svg { width: 28px; height: 28px; }
  .rail-arrow { display: none; }
  .rail-facts { grid-template-columns: 1fr 1fr; }
  .page-head-actions { width: 100%; }
  .page-head-actions .btn { flex: 1; }
  .card { padding: 16px; }
  .meta { grid-template-columns: 1fr 1fr; }
  .bench-tiles { grid-template-columns: 1fr 1fr; }
  .bench-callout { padding: 24px 22px; }
  .crumbs li:not(:last-child) { display: none; }
  .crumbs li:last-child::before { display: none; }
  .auth-panel { padding-top: 64px; }
  .foot { flex-direction: column; gap: 6px; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; }
  .flash-stack { top: auto; bottom: 12px; inset-inline: 12px; width: auto; }
  .heatmap-row { font-size: .64rem; padding-inline-end: 4px; }
  .heatmap-cell { min-height: 22px; font-size: 0; }
  .heatmap-head { font-size: .64rem; max-height: 200px; }
  .chart-box-tall { height: 380px; }
  .records-banner .mem { display: none; }
}

@media print {
  .sidebar, .topbar, .foot, .flash-stack, .page-head-actions { display: none !important; }
  .shell { display: block; }
  .card { break-inside: avoid; }
}

/* --------------------------------------------------------------------------
   8. Language switch + RTL (Arabic) — fonts, mirrored decorations, bidi
   -------------------------------------------------------------------------- */
.lang-form { display: contents; }
.lang-btn {
  display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--text-2); cursor: pointer; font-weight: 600; font-size: .8125rem;
  transition: border-color var(--dur), color var(--dur), background var(--dur);
}
.lang-btn:hover { border-color: var(--line-strong); color: var(--text); background: var(--surface-2); }
.lang-btn svg { width: 16px; height: 16px; flex: 0 0 auto; }
.lang-btn span[lang="ar"] { font-family: var(--font-ar-text); font-weight: 600; line-height: 1; padding-top: 1px; }
.lang-btn span[lang="en"] { font-family: var(--font-latin); }
.auth-tools .lang-btn { background: transparent; border-color: transparent; }
.auth-tools .lang-btn:hover { background: var(--surface-2); }

/* Always-LTR fields and tokens (usernames, passwords, hashes, column names) */
.ltr-input, [dir="rtl"] .ltr-input { direction: ltr; text-align: left; }
.hash, .id-mono, .tag, .chip, .result-inline, .stat-value.is-text, .rail-side, .table-records td, .table-records th { direction: ltr; unicode-bidi: isolate; }
[dir="rtl"] .table .num, [dir="rtl"] .meta dd.num, [dir="rtl"] .stat-value, [dir="rtl"] .pager-status, [dir="rtl"] .audit-time, [dir="rtl"] .records-banner .mem { font-variant-numeric: tabular-nums lining-nums; }

/* Arabic typography: Vazirmatn body, Alexandria headings, extra leading for harakat */
[dir="rtl"] body, body[dir="rtl"] { font-family: var(--font-ar-text), var(--font-latin); font-size: 15.5px; line-height: 1.75; font-feature-settings: "kern" 1, "liga" 1, "calt" 1, "rlig" 1, "mark" 1, "mkmk" 1; }
[dir="rtl"] :is(h1, h2, h3, h4) { font-family: var(--font-ar-display), var(--font-latin); letter-spacing: 0; line-height: 1.45; }
[dir="rtl"] h1 { font-weight: 700; }
[dir="rtl"] .page-head .lede, [dir="rtl"] .stat-note, [dir="rtl"] .cell-sub { text-wrap: pretty; }
[dir="rtl"] .brand-lat { letter-spacing: .16em; }
[dir="rtl"] .brand-ar { line-height: 1.35; }
[dir="rtl"] .nav-link { font-weight: 600; }
[dir="rtl"] .stat-value { letter-spacing: 0; }
[dir="rtl"] .auth-hero .en { font-size: 1.0625rem; line-height: 1.8; max-width: 42ch; }
[dir="rtl"] .empty h3 { line-height: 1.5; }
[dir="rtl"] .cmd-btn kbd { direction: ltr; }
[dir="rtl"] .topbar-tools { flex-direction: row; }
[dir="rtl"] .foot .ar-display { font-size: 1rem; }

/* Mirrored decorations */
[dir="rtl"] .crumbs li + li::before { transform: scaleX(-1); }
[dir="rtl"] .select { background-position: left 12px center; }
[dir="rtl"] .heatmap-scale { background: linear-gradient(270deg, var(--heat-neg), var(--heat-mid), var(--heat-pos)); }
[dir="rtl"] .rail-arrow { background: repeating-linear-gradient(270deg, var(--primary) 0 6px, transparent 6px 10px); }
[dir="rtl"] .collapse-btn svg, [dir="rtl"] .nav-link .nav-icon[data-mirror] { transform: scaleX(-1); }
[dir="rtl"] .rail-label { font-family: var(--font-ar-text); font-weight: 600; }
[dir="rtl"] .error-page { align-items: flex-start; }
[dir="rtl"] .error-page .ar-display { text-align: start; }
[dir="rtl"] .audit-feed .hash { justify-self: start; }
[dir="rtl"] .dl dt { text-align: start; }
[dir="rtl"] .summary-grid dt, [dir="rtl"] .summary-grid dd, [dir="rtl"] .big-number { direction: ltr; text-align: start; }
[dir="rtl"] .heatmap-head { transform: rotate(180deg); direction: ltr; }
[dir="rtl"] .heatmap-table th, [dir="rtl"] .heatmap-table td { direction: ltr; }
[dir="rtl"] .result-meta li { direction: rtl; }
[dir="rtl"] .bench-callout .v em { font-family: var(--font-ar-text); font-size: .32em; vertical-align: middle; }
[dir="rtl"] .bench-legend { direction: rtl; }
[dir="rtl"] .bench-legend span { direction: rtl; }
[dir="rtl"] .records-banner .mem { font-family: var(--font-ar-text); font-size: .8rem; }
[dir="rtl"] .table-foot, [dir="rtl"] .pager { direction: rtl; }
[dir="rtl"] .filter-row { direction: rtl; }
[dir="rtl"] .check input { margin: 0; }
@media (prefers-reduced-motion: no-preference) {
  [dir="rtl"] .rail-tape { animation-direction: normal; }
}

/* Round 2 fixes */
.heatmap-cell, .heatmap-legend span { direction: ltr; unicode-bidi: isolate; }
[dir="rtl"] .tag-op { font-family: var(--font-ar-text); direction: rtl; unicode-bidi: isolate; font-size: .78rem; letter-spacing: 0; }
.tag-op { font-family: var(--font-latin); font-size: .76rem; }
[dir="rtl"] .cell-sub[dir="auto"], [dir="rtl"] .lede > span[dir="auto"] { display: inline-block; max-width: 100%; }
[dir="rtl"] .page-head .lede { text-align: start; }

/* --- Account switcher (sidebar) --- */
.accounts { margin: 10px 0 6px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2, var(--surface)); }
.accounts__summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; font-size: .8125rem; font-weight: 600; color: var(--text-2); }
.accounts__summary::-webkit-details-marker { display: none; }
.accounts__summary::after { content: "▾"; font-size: .7rem; opacity: .7; margin-inline-start: 6px; }
.accounts[open] .accounts__summary::after { content: "▴"; }
.accounts__count { min-width: 1.4em; height: 1.4em; display: inline-grid; place-items: center; border-radius: 999px; background: var(--primary); color: #fff; font-size: .7rem; margin-inline-start: auto; }
.accounts__panel { padding: 4px 10px 10px; border-top: 1px solid var(--border); }
.accounts__hint { font-size: .72rem; color: var(--text-3); margin: 6px 0 8px; line-height: 1.5; }
.accounts__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.accounts__item { display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: 10px; }
.accounts__item.is-current { background: color-mix(in oklab, var(--primary) 10%, transparent); }
.accounts__item form { margin: 0; }
.accounts__meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.accounts__meta strong { font-size: .8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.accounts__current { font-size: .7rem; font-weight: 600; color: var(--primary); }
.avatar--sm { width: 28px; height: 28px; font-size: .75rem; }
.btn-xs { padding: 4px 10px; font-size: .75rem; border-radius: 8px; }
.accounts__add { display: block; margin-top: 10px; font-size: .8rem; font-weight: 600; color: var(--primary); text-decoration: none; }
.accounts__add:hover { text-decoration: underline; }
.sidebar.is-collapsed .accounts { display: none; }
.notice { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; font-size: .875rem; background: var(--surface-2, var(--surface)); }
.notice-info { border-color: color-mix(in oklab, var(--primary) 35%, var(--border)); }
.notice p { margin: 0 0 6px; }
