/* ============================================================================
   Shared brand + chart tokens.

   The chart colors are NOT the brand colors. Brand maroon #601218 has OKLCH
   lightness 0.324 — below the 0.43 floor for a chart fill — and brand gold
   #c6a15b has chroma 0.099, under the 0.10 floor where a hue stops reading as a
   color at all. Both are correct for chrome and wrong for data. The --series-*
   values below are the nearest legal steps on the same two hues, validated for
   lightness band, chroma floor, CVD separation and contrast in both modes
   (worst adjacent CVD ΔE: 38.6 light / 33.8 dark, against a >=12 target).

   Diverging uses blue<->red, not maroon<->gold: the brand has no cool pole, and
   two warm poles leave the midpoint reading as a value instead of as zero.
   ========================================================================== */

:root {
  color-scheme: light;

  /* ---- brand chrome ---- */
  --maroon: #601218;
  --maroon-dark: #480d12;
  --maroon-soft: #f3e9ea;
  --gold: #c6a15b;

  /* ---- surfaces & ink ---- */
  --page: #eceded;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --ink: #1b1b1b;
  --ink-2: #52514e;
  --muted: #6b6b6b;
  --line: #dedfde;
  --line-2: #bfc0c0;

  /* ---- data: categorical (identity) ---- */
  --series-self: #8d3234;     /* maroon family, snapped into band */
  --series-raters: #b6892b;   /* gold family,  snapped into band */

  /* ---- data: diverging (polarity around zero) ---- */
  --div-pos: #e34948;         /* self rates above peers */
  --div-neg: #2a78d6;         /* peers rate above self  */
  --div-mid: #f0efec;         /* the scale's midpoint — a near-surface gray */
  /* A near-surface midpoint is right for a *scale* and unreadable as a *mark*:
     an "aligned" bar painted --div-mid vanishes into the track. --div-null is
     the neutral for drawn marks — still hueless, but 3.21:1 on the track. */
  --div-null: #8f8c86;

  /* ---- data: ordinal (ضعيف → ممتاز), one hue, monotone lightness ----
     Validated as an ordinal ramp: monotone L, adjacent ΔL >= 0.06,
     light end 2.63:1 on white. Better = darker in light mode. */
  --ord-1: #ed807e;   /* ضعيف */
  --ord-2: #d56766;   /* مقبول */
  --ord-3: #bd4e4f;   /* جيد */
  --ord-4: #a63439;   /* جيد جداً */
  --ord-5: #8e1623;   /* ممتاز */

  /* ---- status (reserved; always with icon + label) ---- */
  --ok: #0ca30c;
  --warn: #fab219;
  --bad: #d03b3b;

  /* ---- chart chrome ---- */
  --grid: #e1e0d9;
  --axis: #c3c2b7;

  --radius: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .08);
  --font: 'Tajawal', 'Segoe UI', Tahoma, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --maroon: #8a2028;
    --maroon-dark: #601218;
    --maroon-soft: #2a1a1c;
    --page: #0d0d0d;
    --surface: #1a1817;
    --surface-2: #211f1e;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #a09e99;
    --line: #2f2d2c;
    --line-2: #3d3a39;
    --series-self: #a84a4a;
    --series-raters: #b6892b;
    --div-pos: #e66767;
    --div-neg: #3987e5;
    --div-mid: #383835;
    --div-null: #8a8781;
    /* dark ordinal ramp: its own steps, lifted so the dark end still clears
       2:1 on the dark surface (2.76:1). Better = lighter in dark mode. */
    --ord-1: #a03f40;
    --ord-2: #b95555;
    --ord-3: #d36c6a;
    --ord-4: #ed8381;
    --ord-5: #faa29f;
    --grid: #2c2c2a;
    --axis: #383835;
    --shadow: 0 6px 24px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --maroon: #8a2028;
  --maroon-dark: #601218;
  --maroon-soft: #2a1a1c;
  --page: #0d0d0d;
  --surface: #1a1817;
  --surface-2: #211f1e;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #a09e99;
  --line: #2f2d2c;
  --line-2: #3d3a39;
  --series-self: #a84a4a;
  --series-raters: #b6892b;
  --div-pos: #e66767;
  --div-neg: #3987e5;
  --div-mid: #383835;
  --div-null: #8a8781;
  --ord-1: #a03f40;
  --ord-2: #b95555;
  --ord-3: #d36c6a;
  --ord-4: #ed8381;
  --ord-5: #faa29f;
  --grid: #2c2c2a;
  --axis: #383835;
  --shadow: 0 6px 24px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* [hidden] is a UA-stylesheet rule, so ANY author `display:` beats it — an
   element with class .sso{display:flex} stays visible while hidden. Every
   hidden-toggled element here would need to remember that; this makes it
   structural instead. */
[hidden] { display: none !important; }

html, body {
  background: var(--page); color: var(--ink);
  font-family: var(--font); line-height: 1.6;
}

/* ---- header ---- */
header.brand {
  background: var(--surface); border-bottom: 3px solid var(--gold);
  padding: 18px 28px; position: relative; text-align: center;
}
header.brand::before {
  content: ""; position: absolute; inset: 0 0 auto 0;
  height: 6px; background: var(--maroon);
}
header.brand img { height: 72px; margin: 6px auto 4px; display: block; }
header.brand h1 { color: var(--maroon); font-size: 22px; font-weight: 800; }
header.brand p.sub { color: var(--muted); font-size: 14px; }

/* ---- nav ---- */
.topnav {
  background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; gap: 4px; align-items: center;
  padding: 0 20px; flex-wrap: wrap; position: sticky; top: 0; z-index: 40;
}
.topnav a {
  color: var(--ink-2); text-decoration: none; font-weight: 700; font-size: 14px;
  padding: 13px 14px; border-bottom: 3px solid transparent;
}
.topnav a:hover { color: var(--maroon); }
.topnav a.active { color: var(--maroon); border-bottom-color: var(--maroon); }
.topnav .spacer { flex: 1; }
.topnav .who { font-size: 13px; color: var(--muted); }

/* ---- buttons ---- */
.btn {
  border: none; border-radius: 8px; padding: 9px 16px; font-family: var(--font);
  font-weight: 700; font-size: 14px; cursor: pointer; transition: .15s;
}
.btn-primary { background: var(--maroon); color: #fff; }
.btn-primary:hover { background: var(--maroon-dark); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost { background: var(--surface); color: var(--maroon); border: 1.5px solid var(--maroon); }
.btn-ghost:hover { background: var(--maroon-soft); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

/* ---- cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px;
}
.card h2 { font-size: 16px; color: var(--maroon); margin-bottom: 4px; }
.card .card-sub { font-size: 12.5px; color: var(--muted); margin-bottom: 14px; }

/* ---- stat tiles ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
}
.tile .v { font-size: 28px; font-weight: 800; color: var(--maroon); line-height: 1.15; }
.tile .v small { font-size: 14px; color: var(--muted); font-weight: 600; }
.tile .l { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* ---- legend (identity is never color-alone) ---- */
.legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 12.5px; color: var(--ink-2); }
.legend .k { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 11px; height: 11px; border-radius: 3px; flex: none; }

/* ---- table ---- */
table.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.grid th, table.grid td {
  padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: right;
}
table.grid th { color: var(--muted); font-size: 12px; font-weight: 700; white-space: nowrap; }
table.grid td.num { font-variant-numeric: tabular-nums; }
table.grid tbody tr:hover { background: var(--surface-2); }

/* ---- misc ---- */
.pill {
  display: inline-flex; align-items: center; gap: 5px; border-radius: 20px;
  padding: 2px 10px; font-size: 12px; font-weight: 700;
}
.pill.ok { background: rgba(12,163,12,.12); color: var(--ok); }
.pill.warn { background: rgba(250,178,25,.16); color: #8a5a00; }
.pill.bad { background: rgba(208,59,59,.12); color: var(--bad); }
.pill.mute { background: var(--line); color: var(--muted); }
:root[data-theme="dark"] .pill.warn, :root:where(:not([data-theme="light"])) .pill.warn { color: var(--warn); }

.notice {
  background: var(--maroon-soft); border: 1px solid var(--line);
  border-inline-start: 4px solid var(--gold);
  border-radius: 8px; padding: 11px 14px; font-size: 13.5px; color: var(--ink-2);
}
.empty { padding: 40px; text-align: center; color: var(--muted); }
.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;
}

/* Wide content scrolls inside its own box; the page never scrolls sideways. */
.scroll-x { overflow-x: auto; }

@media print {
  .topnav, .noprint { display: none !important; }
  body { background: #fff; }
  .card { break-inside: avoid; border-color: #ccc; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
