/* ==========================================================================
   Arkenso design system
   Chart colours are the validated reference palette from the data-viz method
   (validated against this app's own surfaces: #ffffff light, #16181d dark).
   Three light-mode slots sit below 3:1 on white, so every chart ships direct
   labels and a table view — the documented relief for that warning.
   ========================================================================== */

:root {
  color-scheme: light;

  /* --- surfaces & ink ---------------------------------------------------- */
  --page:           #f6f7f9;
  --surface:        #ffffff;
  --surface-2:      #f2f4f7;
  --surface-sunken: #eceff3;
  --surface-inverse:#111419;

  --text:           #10131a;
  --text-secondary: #4a5260;
  --text-muted:     #6f7887;
  --text-inverse:   #f8fafc;

  --border:         #e2e6ec;
  --border-strong:  #cbd2dc;
  --ring:           rgba(42, 120, 214, 0.35);

  /* --- brand ------------------------------------------------------------- */
  --brand:          #2a78d6;
  --brand-hover:    #256abf;
  --brand-ink:      #184f95;
  --brand-wash:     #eef5fd;

  /* --- status (fixed, never themed; always paired with icon + label) ----- */
  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;
  --status-good-wash:     #e8f7e8;
  --status-warning-wash:  #fdf4e0;
  --status-serious-wash:  #fdeee7;
  --status-critical-wash: #fbeaea;
  --success-text:   #006300;

  /* --- categorical series (fixed order, never cycled) ------------------- */
  --series-1: #2a78d6;  /* blue    */
  --series-2: #eb6834;  /* orange  */
  --series-3: #1baf7a;  /* aqua    */
  --series-4: #eda100;  /* yellow  */
  --series-5: #e87ba4;  /* magenta */
  --series-6: #008300;  /* green   */
  --series-7: #4a3aa7;  /* violet  */
  --series-8: #e34948;  /* red     */

  /* --- sequential (one hue, light to dark) ------------------------------- */
  --seq-100: #cde2fb; --seq-200: #9ec5f4; --seq-300: #6da7ec; --seq-400: #3987e5;
  --seq-500: #256abf; --seq-600: #184f95; --seq-700: #0d366b;
  /* ordinal steps: wide enough lightness gaps to read as distinct */
  --ord-1: #86b6ef; --ord-2: #5598e7; --ord-3: #2a78d6; --ord-4: #1c5cab; --ord-5: #104281;

  /* --- diverging (warm/cool poles, neutral grey midpoint) --------------- */
  --div-neg-strong: #d03b3b;
  --div-neg:        #e88c8c;
  --div-mid:        #eceff3;
  --div-pos:        #86b6ef;
  --div-pos-strong: #2a78d6;

  /* --- chart chrome ----------------------------------------------------- */
  --grid:     #eceff3;
  --axis:     #cbd2dc;
  --chart-bg: #ffffff;

  /* --- geometry --------------------------------------------------------- */
  --r-sm: 6px; --r: 10px; --r-lg: 14px; --r-xl: 20px; --r-pill: 999px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px;
  --sp-6: 32px; --sp-7: 48px; --sp-8: 64px;

  --shadow-sm: 0 1px 2px rgba(16, 19, 26, .06), 0 1px 3px rgba(16, 19, 26, .04);
  --shadow:    0 1px 3px rgba(16, 19, 26, .07), 0 8px 24px -12px rgba(16, 19, 26, .18);
  --shadow-lg: 0 2px 6px rgba(16, 19, 26, .08), 0 24px 48px -16px rgba(16, 19, 26, .22);

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

  --sidebar-w: 248px;
  --header-h: 60px;
}

/* Dark mode is selected, not flipped: its own steps from the same ramps,
   validated against the dark surface. Declared under both the OS media query
   and the explicit toggle so the toggle wins either way. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0c0e12; --surface: #16181d; --surface-2: #1d2027; --surface-sunken: #111318;
    --surface-inverse: #f8fafc;
    --text: #f2f4f8; --text-secondary: #b3bbc8; --text-muted: #8a93a3; --text-inverse: #10131a;
    --border: #272b33; --border-strong: #3a3f4a;
    --brand: #3987e5; --brand-hover: #5598e7; --brand-ink: #9ec5f4; --brand-wash: #15233a;
    --status-good-wash: #10240f; --status-warning-wash: #2c2309;
    --status-serious-wash: #2e1c13; --status-critical-wash: #2d1414;
    --success-text: #0ca30c;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --seq-100: #15233a; --seq-200: #1c4a80; --seq-300: #256abf; --seq-400: #3987e5;
    --seq-500: #6da7ec; --seq-600: #9ec5f4; --seq-700: #cde2fb;
    --ord-1: #9ec5f4; --ord-2: #6da7ec; --ord-3: #3987e5; --ord-4: #256abf; --ord-5: #184f95;
    --div-neg-strong: #e66767; --div-neg: #8a3636; --div-mid: #272b33;
    --div-pos: #1c4a80; --div-pos-strong: #3987e5;
    --grid: #22262d; --axis: #3a3f4a; --chart-bg: #16181d;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow: 0 1px 3px rgba(0,0,0,.45), 0 8px 24px -12px rgba(0,0,0,.6);
    --shadow-lg: 0 2px 6px rgba(0,0,0,.5), 0 24px 48px -16px rgba(0,0,0,.7);
    --ring: rgba(57, 135, 229, .45);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0c0e12; --surface: #16181d; --surface-2: #1d2027; --surface-sunken: #111318;
  --surface-inverse: #f8fafc;
  --text: #f2f4f8; --text-secondary: #b3bbc8; --text-muted: #8a93a3; --text-inverse: #10131a;
  --border: #272b33; --border-strong: #3a3f4a;
  --brand: #3987e5; --brand-hover: #5598e7; --brand-ink: #9ec5f4; --brand-wash: #15233a;
  --status-good-wash: #10240f; --status-warning-wash: #2c2309;
  --status-serious-wash: #2e1c13; --status-critical-wash: #2d1414;
  --success-text: #0ca30c;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  --seq-100: #15233a; --seq-200: #1c4a80; --seq-300: #256abf; --seq-400: #3987e5;
  --seq-500: #6da7ec; --seq-600: #9ec5f4; --seq-700: #cde2fb;
  --ord-1: #9ec5f4; --ord-2: #6da7ec; --ord-3: #3987e5; --ord-4: #256abf; --ord-5: #184f95;
  --div-neg-strong: #e66767; --div-neg: #8a3636; --div-mid: #272b33;
  --div-pos: #1c4a80; --div-pos-strong: #3987e5;
  --grid: #22262d; --axis: #3a3f4a; --chart-bg: #16181d;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow: 0 1px 3px rgba(0,0,0,.45), 0 8px 24px -12px rgba(0,0,0,.6);
  --shadow-lg: 0 2px 6px rgba(0,0,0,.5), 0 24px 48px -16px rgba(0,0,0,.7);
  --ring: rgba(57, 135, 229, .45);
}

/* ---------------------------------------------------------------- reset --- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

img, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: var(--r-sm); }

h1, h2, h3, h4 { line-height: 1.2; font-weight: 650; letter-spacing: -0.015em; }
h1 { font-size: clamp(2rem, 5vw, 3.1rem); }
h2 { font-size: clamp(1.5rem, 3.2vw, 2.1rem); }
h3 { font-size: 1.2rem; }
h4 { font-size: 1rem; }

code, kbd, pre { font-family: var(--mono); font-size: .875em; }
pre {
  background: var(--surface-sunken); border: 1px solid var(--border);
  border-radius: var(--r); padding: var(--sp-4); overflow-x: auto;
}
code:not(pre code) {
  background: var(--surface-sunken); padding: .1em .36em;
  border-radius: var(--r-sm); border: 1px solid var(--border);
}

/* ---------------------------------------------------------------- layout -- */
.wrap { width: 100%; max-width: 1200px; margin-inline: auto; padding-inline: var(--sp-5); }
.wrap-narrow { max-width: 760px; }
.wrap-wide { max-width: 1480px; }

.stack > * + * { margin-top: var(--sp-4); }
.stack-sm > * + * { margin-top: var(--sp-2); }
.stack-lg > * + * { margin-top: var(--sp-6); }

.row { display: flex; align-items: center; gap: var(--sp-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.row-wrap { flex-wrap: wrap; }
.row-top { align-items: flex-start; }
.spacer { flex: 1; }

.grid { display: grid; gap: var(--sp-4); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
.grid-sidebar { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 900px) { .grid-sidebar { grid-template-columns: 1fr; } }

.section { padding-block: clamp(var(--sp-6), 7vw, var(--sp-8)); }

/* --------------------------------------------------------------- surfaces - */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
}
.card-flush { padding: 0; overflow: hidden; }
.card-hd {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--sp-3); padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.card-hd h3, .card-hd h4 { margin: 0; }
.card-bd { padding: var(--sp-5); }
.card-ft { padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); background: var(--surface-2); }
.card-link { display: block; color: inherit; transition: border-color .15s, transform .15s, box-shadow .15s; }
.card-link:hover { text-decoration: none; border-color: var(--border-strong); box-shadow: var(--shadow); }

.panel { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); padding: var(--sp-4); }
.hairline { height: 1px; background: var(--border); border: 0; }

/* ---------------------------------------------------------------- text ---- */
.eyebrow {
  font-size: .75rem; font-weight: 650; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-muted);
}
.lede { font-size: 1.12rem; color: var(--text-secondary); }
.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.small { font-size: .8125rem; }
.tiny { font-size: .75rem; }
.strong { font-weight: 650; }
.nums { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.center { text-align: center; }
.right { text-align: end; }
.pos { color: var(--success-text); }
.neg { color: var(--status-critical); }

/* -------------------------------------------------------------- buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 9px 16px; border-radius: var(--r);
  border: 1px solid transparent; background: var(--brand); color: #fff;
  font-size: .9375rem; font-weight: 550; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, opacity .15s;
}
.btn:hover { background: var(--brand-hover); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--status-critical); }
.btn-danger:hover { background: #b73232; }
.btn-sm { padding: 5px 10px; font-size: .8125rem; border-radius: var(--r-sm); }
.btn-lg { padding: 13px 24px; font-size: 1.0625rem; }
.btn-block { width: 100%; }

.btn-group { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--r); overflow: hidden; }
.btn-group button {
  padding: 6px 12px; background: var(--surface); border: 0; cursor: pointer;
  font-size: .8125rem; color: var(--text-secondary); border-inline-end: 1px solid var(--border);
}
.btn-group button:last-child { border-inline-end: 0; }
.btn-group button[aria-pressed="true"] { background: var(--brand-wash); color: var(--brand-ink); font-weight: 600; }

/* ---------------------------------------------------------------- forms --- */
.field { display: block; }
.field + .field { margin-top: var(--sp-4); }
.field > label, .label {
  display: block; font-size: .8125rem; font-weight: 600;
  color: var(--text-secondary); margin-bottom: var(--sp-1);
}
.input, .select, .textarea {
  width: 100%; padding: 9px 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r);
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring);
}
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--status-critical); }
.textarea { min-height: 120px; resize: vertical; font-family: inherit; }
.select { appearance: none; padding-inline-end: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%236f7887' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; }
.hint { font-size: .75rem; color: var(--text-muted); margin-top: var(--sp-1); }
.error-text { font-size: .75rem; color: var(--status-critical); margin-top: var(--sp-1); font-weight: 550; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
@media (max-width: 560px) { .field-row { grid-template-columns: 1fr; } }

.check { display: flex; gap: var(--sp-2); align-items: flex-start; font-size: .875rem; }
.check input { margin-top: 3px; accent-color: var(--brand); width: 16px; height: 16px; }

.segmented { display: inline-flex; background: var(--surface-sunken); padding: 3px; border-radius: var(--r-pill); gap: 2px; }
.segmented button {
  border: 0; background: transparent; padding: 6px 14px; border-radius: var(--r-pill);
  cursor: pointer; font-size: .8125rem; font-weight: 550; color: var(--text-secondary);
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* --------------------------------------------------------------- badges --- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: var(--r-pill);
  font-size: .75rem; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--text-secondary);
  border: 1px solid var(--border);
}
/* Status badges always carry a glyph plus a word — never colour alone. */
.badge-good     { background: var(--status-good-wash);     color: var(--success-text);      border-color: transparent; }
.badge-warning  { background: var(--status-warning-wash);  color: #7a5600;                  border-color: transparent; }
.badge-serious  { background: var(--status-serious-wash);  color: #9c4418;                  border-color: transparent; }
.badge-critical { background: var(--status-critical-wash);  color: var(--status-critical);   border-color: transparent; }
.badge-brand    { background: var(--brand-wash);           color: var(--brand-ink);         border-color: transparent; }
:root[data-theme="dark"] .badge-warning, :root[data-theme="dark"] .badge-serious { color: var(--status-warning); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .badge-warning { color: var(--status-warning); }
  :root:not([data-theme="light"]) .badge-serious { color: var(--status-serious); }
}
.badge-glyph { font-size: .9em; line-height: 1; }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--text-muted); }

/* --------------------------------------------------------------- tables --- */
.table-scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.data th, table.data td {
  text-align: start; padding: 10px var(--sp-4);
  border-bottom: 1px solid var(--border); vertical-align: middle;
}
table.data thead th {
  font-size: .75rem; font-weight: 650; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); background: var(--surface-2); white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.clickable:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: end; font-variant-numeric: tabular-nums; }
table.compact th, table.compact td { padding: 6px var(--sp-3); }

/* ------------------------------------------------------------ stat tiles -- */
/* A single number is a stat tile, not a one-bar chart. */
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-4) var(--sp-5); }
.stat-label { font-size: .75rem; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--text-muted); }
.stat-value { font-size: 1.85rem; font-weight: 650; letter-spacing: -0.02em; margin-top: 2px; line-height: 1.1; }
.stat-sub { font-size: .8125rem; color: var(--text-secondary); margin-top: 2px; }
.stat-delta { display: inline-flex; align-items: center; gap: 3px; font-size: .8125rem; font-weight: 600; }

.hero-figure { font-size: clamp(2.5rem, 7vw, 4rem); font-weight: 680; letter-spacing: -0.03em; line-height: 1; }

/* ------------------------------------------------------------- charts ----- */
.chart { width: 100%; display: block; overflow: visible; }
.chart text { font-family: var(--font); fill: var(--text-muted); font-size: 11px; }
.chart .axis-label { fill: var(--text-muted); font-size: 10.5px; }
.chart .value-label { fill: var(--text-secondary); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-line { stroke: var(--axis); stroke-width: 1; }
.chart .zero-line { stroke: var(--axis); stroke-width: 1.5; }
.chart .series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-area { opacity: .13; }
.chart .marker { stroke: var(--chart-bg); stroke-width: 2; }
.chart .bar { }
.chart .hover-target { fill: transparent; cursor: crosshair; }
.chart .crosshair { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }

.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.chart-title { font-size: .9375rem; font-weight: 650; }
.chart-note { font-size: .75rem; color: var(--text-muted); }

/* A legend is present whenever two or more series share a plot. */
.legend { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-top: var(--sp-3); font-size: .8125rem; color: var(--text-secondary); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; }

.chart-tooltip {
  position: fixed; z-index: 60; pointer-events: none;
  background: var(--surface-inverse); color: var(--text-inverse);
  padding: 7px 10px; border-radius: var(--r-sm); font-size: .75rem; line-height: 1.45;
  box-shadow: var(--shadow-lg); max-width: 260px; opacity: 0; transition: opacity .1s;
}
.chart-tooltip[data-show="true"] { opacity: 1; }
.chart-tooltip b { font-weight: 650; }

/* Every chart ships a table view — the documented relief for low-contrast
   slots and the accessibility fallback. */
.chart-table { margin-top: var(--sp-3); }
.chart-table[hidden] { display: none; }

/* Meters: a labelled bar, used where a proportion is the whole story. */
.meter { height: 8px; background: var(--surface-sunken); border-radius: var(--r-pill); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: var(--r-pill); background: var(--series-1); }
.meter-good > span { background: var(--status-good); }
.meter-warning > span { background: var(--status-warning); }
.meter-critical > span { background: var(--status-critical); }

/* ------------------------------------------------------------ app shell --- */
.app { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
.sidebar {
  background: var(--surface); border-inline-end: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-hd { padding: var(--sp-4) var(--sp-4) var(--sp-3); border-bottom: 1px solid var(--border); }
.sidebar-nav { padding: var(--sp-3) var(--sp-2); flex: 1; }
.sidebar-ft { padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border); }
.nav-group + .nav-group { margin-top: var(--sp-4); }
.nav-group-label {
  font-size: .6875rem; font-weight: 650; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-muted); padding: 0 var(--sp-3) var(--sp-1);
}
.nav-link {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 7px var(--sp-3); border-radius: var(--r-sm);
  color: var(--text-secondary); font-size: .875rem; font-weight: 500;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link[aria-current="page"] { background: var(--brand-wash); color: var(--brand-ink); font-weight: 600; }
.nav-link .dot { width: 7px; height: 7px; }
.nav-count { margin-inline-start: auto; font-size: .75rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--header-h); display: flex; align-items: center; gap: var(--sp-3);
  padding-inline: var(--sp-5); border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 20;
}
.content { padding: var(--sp-5); flex: 1; }
.page-head { margin-bottom: var(--sp-5); }
.page-head h1 { font-size: 1.6rem; }

.sidebar-toggle { display: none; }
@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(84vw, var(--sidebar-w));
    z-index: 50; transform: translateX(-100%); transition: transform .2s;
    box-shadow: var(--shadow-lg);
  }
  .sidebar[data-open="true"] { transform: none; }
  .sidebar-toggle { display: inline-flex; }
  .content { padding: var(--sp-4); }
}

/* -------------------------------------------------------- marketing nav --- */
.site-header {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--page) 86%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.site-header .wrap { display: flex; align-items: center; gap: var(--sp-5); height: 64px; }
.site-nav { display: flex; gap: var(--sp-4); align-items: center; }
.site-nav a { color: var(--text-secondary); font-size: .9375rem; font-weight: 500; }
.site-nav a:hover { color: var(--text); text-decoration: none; }
@media (max-width: 760px) { .site-nav.collapsible { display: none; } }

.logo { display: inline-flex; align-items: center; gap: var(--sp-2); font-weight: 680; font-size: 1.05rem; color: var(--text); letter-spacing: -0.02em; }
.logo:hover { text-decoration: none; }
.logo-mark {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, var(--brand), var(--series-7));
  display: grid; place-items: center; color: #fff; font-size: .8rem; font-weight: 700;
}

.site-footer { border-top: 1px solid var(--border); padding-block: var(--sp-6); margin-top: var(--sp-8); background: var(--surface); }
.footer-grid { display: grid; gap: var(--sp-5); grid-template-columns: 1.4fr repeat(3, 1fr); }
@media (max-width: 760px) { .footer-grid { grid-template-columns: 1fr 1fr; } }
.footer-grid h4 { font-size: .8125rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: var(--sp-2); }
.footer-grid ul { list-style: none; padding: 0; display: grid; gap: 6px; font-size: .875rem; }
.footer-grid a { color: var(--text-secondary); }

/* ----------------------------------------------------------------- hero --- */
.hero { padding-block: clamp(var(--sp-6), 8vw, 96px) var(--sp-7); text-align: center; }
.hero h1 { max-width: 20ch; margin-inline: auto; }
.hero .lede { max-width: 58ch; margin: var(--sp-4) auto 0; font-size: 1.2rem; }
.hero-actions { display: flex; gap: var(--sp-3); justify-content: center; flex-wrap: wrap; margin-top: var(--sp-5); }
.hero-proof { display: flex; gap: var(--sp-5); justify-content: center; flex-wrap: wrap; margin-top: var(--sp-6); color: var(--text-muted); font-size: .875rem; }

/* --------------------------------------------------------- product cards -- */
.product-card { display: flex; flex-direction: column; gap: var(--sp-3); height: 100%; }
.product-icon {
  width: 38px; height: 38px; border-radius: 10px; flex: none;
  display: grid; place-items: center; font-size: 1.15rem;
  background: var(--accent-wash, var(--brand-wash));
}
.product-card h3 { font-size: 1.0625rem; }
.product-meta { display: flex; gap: var(--sp-3); flex-wrap: wrap; font-size: .8125rem; color: var(--text-muted); margin-top: auto; padding-top: var(--sp-3); }
.accent-rule { height: 3px; border-radius: 3px; background: var(--accent, var(--brand)); width: 32px; }

.feature-list { list-style: none; padding: 0; display: grid; gap: var(--sp-2); font-size: .875rem; }
.feature-list li { display: flex; gap: var(--sp-2); align-items: flex-start; color: var(--text-secondary); }
.feature-list .tick { color: var(--success-text); flex: none; font-weight: 700; }

/* --------------------------------------------------------- pricing cards -- */
.plan { display: flex; flex-direction: column; gap: var(--sp-3); position: relative; height: 100%; }
.plan[data-popular="true"] { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.plan-flag {
  position: absolute; top: -11px; left: 50%; transform: translateX(-50%);
  background: var(--brand); color: #fff; font-size: .6875rem; font-weight: 650;
  padding: 2px 10px; border-radius: var(--r-pill); letter-spacing: .03em;
}
.price { display: flex; align-items: baseline; gap: 4px; }
.price-amount { font-size: 2.1rem; font-weight: 680; letter-spacing: -0.03em; }
.price-period { color: var(--text-muted); font-size: .875rem; }

/* --------------------------------------------------------------- misc ----- */
.empty {
  text-align: center; padding: var(--sp-7) var(--sp-5); color: var(--text-muted);
  border: 1px dashed var(--border-strong); border-radius: var(--r-lg);
}
.empty h4 { color: var(--text); margin-bottom: var(--sp-2); }

.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-sunken) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: var(--r-sm); color: transparent; }
@keyframes shimmer { to { background-position: -200% 0; } }

.toasts { position: fixed; bottom: var(--sp-5); right: var(--sp-5); z-index: 80; display: grid; gap: var(--sp-2); max-width: 380px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-inline-start: 3px solid var(--brand);
  border-radius: var(--r); padding: var(--sp-3) var(--sp-4); box-shadow: var(--shadow-lg);
  font-size: .875rem; animation: toast-in .18s ease-out;
}
.toast[data-kind="error"] { border-inline-start-color: var(--status-critical); }
.toast[data-kind="success"] { border-inline-start-color: var(--status-good); }
.toast strong { display: block; margin-bottom: 2px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

dialog.modal {
  border: 1px solid var(--border); border-radius: var(--r-lg); padding: 0;
  background: var(--surface); color: var(--text);
  max-width: min(560px, 94vw); width: 100%; box-shadow: var(--shadow-lg);
}
dialog.modal::backdrop { background: rgba(16, 19, 26, .5); backdrop-filter: blur(2px); }
dialog.modal.wide { max-width: min(880px, 95vw); }
.modal-hd { padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); }
.modal-bd { padding: var(--sp-5); max-height: min(68vh, 640px); overflow-y: auto; }
.modal-ft { padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--sp-2); background: var(--surface-2); }
.modal-close { background: none; border: 0; cursor: pointer; color: var(--text-muted); font-size: 1.3rem; line-height: 1; padding: 2px 6px; border-radius: var(--r-sm); }
.modal-close:hover { background: var(--surface-sunken); color: var(--text); }

.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  padding: 9px var(--sp-4); border: 0; background: none; cursor: pointer; white-space: nowrap;
  font-size: .875rem; font-weight: 550; color: var(--text-secondary);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--brand-ink); border-bottom-color: var(--brand); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: var(--sp-2) var(--sp-4); font-size: .875rem; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; text-align: end; font-variant-numeric: tabular-nums; }

.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none; display: grid; place-items: center;
  color: #fff; font-size: .75rem; font-weight: 650; background: var(--brand);
}
.avatar-lg { width: 44px; height: 44px; font-size: .9375rem; }

.timeline { list-style: none; padding: 0; display: grid; gap: 0; }
.timeline li { display: grid; grid-template-columns: 18px 1fr; gap: var(--sp-3); padding-bottom: var(--sp-4); position: relative; }
.timeline li::before { content: ''; position: absolute; left: 8px; top: 16px; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child { padding-bottom: 0; }
.timeline li:last-child::before { display: none; }
.timeline-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--brand); margin-top: 6px; margin-inline-start: 4px; z-index: 1; }

.board { display: grid; gap: var(--sp-3); grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); overflow-x: auto; padding-bottom: var(--sp-3); }
.board-col { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); padding: var(--sp-3); min-height: 120px; }
.board-col-hd { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--sp-3); font-size: .8125rem; font-weight: 650; color: var(--text-secondary); }
.board-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); padding: var(--sp-3); font-size: .8125rem; }
.board-card + .board-card { margin-top: var(--sp-2); }

.chat { display: grid; gap: var(--sp-3); }
.msg { display: grid; grid-template-columns: 30px 1fr; gap: var(--sp-3); }
.msg-body { background: var(--surface-2); border-radius: var(--r); padding: var(--sp-3); font-size: .875rem; }
.msg-meta { display: flex; gap: var(--sp-2); align-items: baseline; margin-bottom: 2px; font-size: .8125rem; }
.msg-author { font-weight: 650; }
.msg[data-own="true"] .msg-body { background: var(--brand-wash); }

.pill-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media print { .sidebar, .topbar, .site-header, .site-footer, .btn { display: none !important; } }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ── FAQ (server-rendered, so it must look right before any JS runs) ──── */

#seo-detail { border-top: 1px solid var(--border); }
#seo-detail > h2 { font-size: 1.35rem; margin: 0 0 var(--sp-3); }
#seo-detail > p { color: var(--text-secondary); }
#seo-detail .feature-list { margin: var(--sp-4) 0; max-width: 68ch; }
#seo-detail .feature-list li { display: list-item; list-style: none; }
#seo-detail .feature-list li strong { color: var(--text); }

.faq-list { display: grid; gap: var(--sp-2); max-width: 72ch; margin-top: var(--sp-3); }

.faq-item {
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  overflow: hidden;
}
.faq-item > summary {
  cursor: pointer;
  padding: var(--sp-3) var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  list-style: none;
}
.faq-item > summary::-webkit-details-marker { display: none; }
/* A rotating caret rather than the native triangle, which varies by browser. */
.faq-item > summary::after {
  content: '';
  margin-inline-start: auto;
  flex: none;
  width: 8px; height: 8px;
  /* Physical on purpose: this is a geometric chevron, not a directional one.
     A disclosure arrow points down in RTL exactly as it does in LTR, so
     mirroring it with logical properties would aim it sideways. */
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(45deg);
  transition: transform .15s ease;
}
.faq-item[open] > summary::after { transform: rotate(225deg); }
.faq-item > summary:hover { background: var(--surface-2); }
.faq-item > summary:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
/* The heading carries the question for crawlers; visually it is summary text. */
.faq-item > summary h3 { font-size: .95rem; font-weight: 600; margin: 0; }
.faq-item > p {
  margin: 0;
  padding: 0 var(--sp-4) var(--sp-4);
  color: var(--text-secondary);
  font-size: .9rem;
  line-height: 1.65;
}
@media (prefers-reduced-motion: reduce) {
  .faq-item > summary::after { transition: none; }
}

/* ── Long-form product copy (server-rendered, must read well pre-JS) ──── */

#detail { border-top: 1px solid var(--border); }
#detail h2 { font-size: 1.3rem; margin: var(--sp-6) 0 var(--sp-3); }
#detail h2:first-of-type { margin-top: var(--sp-4); }
#detail p { color: var(--text-secondary); line-height: 1.7; }
#detail .grid { margin-top: var(--sp-3); }

.formula {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: var(--sp-3) var(--sp-4);
  max-width: max-content;
  overflow-x: auto;
}
.formula code { background: none; padding: 0; font-size: .9rem; color: var(--text); }

.term-list { margin: var(--sp-3) 0 0; max-width: 72ch; }
.term-list dt {
  font-weight: 600;
  color: var(--text);
  margin-top: var(--sp-3);
  font-size: .95rem;
}
.term-list dt:first-child { margin-top: 0; }
.term-list dd {
  margin: 4px 0 0;
  padding-inline-start: var(--sp-3);
  border-inline-start: 2px solid var(--border);
  color: var(--text-secondary);
  font-size: .9rem;
  line-height: 1.65;
}

.step-list {
  counter-reset: step;
  list-style: none;
  padding: 0;
  margin: var(--sp-3) 0 var(--sp-4);
  max-width: 72ch;
  display: grid;
  gap: var(--sp-3);
}
.step-list li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: var(--sp-3);
  align-items: start;
}
.step-list li::before {
  content: counter(step);
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: .8rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.step-list li strong { display: block; color: var(--text); font-size: .95rem; }
.step-list li span { display: block; color: var(--text-secondary); font-size: .9rem; line-height: 1.6; }

/* ── Writing systems ──────────────────────────────────────────────────── */

/*
 * The layout mirrors through CSS logical properties, which the rules above
 * use throughout, so `dir="rtl"` on <html> is enough for the structure. What
 * remains is the handful of things logical properties do not cover.
 */

/* Latin font stack is the default; these override per script so Japanese and
   Chinese do not fall back to a font with the wrong glyph shapes, and Arabic
   gets a face designed for it rather than a Latin fallback. */
html[lang="ja"] body,
html[lang="ja"] .input,
html[lang="ja"] .select {
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP",
               "Meiryo", system-ui, sans-serif;
}
html[lang^="zh"] body,
html[lang^="zh"] .input,
html[lang^="zh"] .select {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
               "Noto Sans SC", system-ui, sans-serif;
}
html[lang="ar"] body,
html[lang="ar"] .input,
html[lang="ar"] .select {
  font-family: "SF Arabic", "Geeza Pro", "Segoe UI", "Noto Naskh Arabic",
               "Noto Sans Arabic", system-ui, sans-serif;
}

/* CJK has no inter-word spaces, so the browser may break anywhere. These keep
   it from breaking in places that read badly, and widen the line a little
   because dense glyphs need more vertical room than Latin at the same size. */
html[lang="ja"] body,
html[lang^="zh"] body {
  line-height: 1.8;
  word-break: normal;
  overflow-wrap: anywhere;
  line-break: strict;
}
html[lang="ja"] h1, html[lang="ja"] h2, html[lang="ja"] h3,
html[lang^="zh"] h1, html[lang^="zh"] h2, html[lang^="zh"] h3 {
  line-height: 1.45;
  /* Latin headings are tightened with negative tracking; CJK must not be. */
  letter-spacing: normal;
}

/* Arabic script sits lower and needs more leading than Latin at the same
   size, and its letterforms are damaged by negative tracking. */
html[lang="ar"] body { line-height: 1.9; letter-spacing: normal; }
html[lang="ar"] h1,
html[lang="ar"] h2,
html[lang="ar"] h3 { letter-spacing: normal; line-height: 1.5; }

/* Numbers, money and dates stay left-to-right inside an RTL run. The bidi
   algorithm mostly handles this, but tabular figures in a table cell need to
   be told explicitly or a currency symbol can land on the wrong side. */
html[dir="rtl"] .num,
html[dir="rtl"] .stat-value,
html[dir="rtl"] td.num,
html[dir="rtl"] th.num {
  direction: ltr;
  text-align: end;
}

/* Charts are drawn in SVG user space, which does not mirror. Flipping the
   plot would put the time axis backwards; the surrounding layout mirrors and
   the chart itself stays as drawn. */
html[dir="rtl"] svg.chart { direction: ltr; }

/* The one arrow that is directional rather than geometric: a "back" link
   points toward the start of the line, so it mirrors with the text. */
html[dir="rtl"] .back-arrow { transform: scaleX(-1); display: inline-block; }

/* Language switcher: chrome, not a primary action. */
.lang-switch { display: inline-flex; align-items: center; }
.lang-switch .select {
  padding: 5px 26px 5px 9px;
  font-size: .8125rem;
  min-width: auto;
  background-color: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}
.lang-switch .select:hover { border-color: var(--border); background-color: var(--surface-2); }
html[dir="rtl"] .lang-switch .select { padding: 5px 9px 5px 26px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
