/* تقارير وطنية للطرق — design system (RTL, light/dark, print A4). No external assets. */

/* ---------- tokens ---------- */
:root {
  color-scheme: light;
  --page: #f5f6f4;
  --surface: #ffffff;
  --surface-2: #f2f3f0;
  --ink: #14171c;
  --ink-2: #474e5a;
  --muted: #646b76;
  --line: #e1e3df;
  --grid: #e8e8e3;
  --axis: #c3c2b7;
  --accent: #1d5aa6;
  --accent-ink: #ffffff;
  --accent-wash: #e8f0fa;
  --series-1: #2a78d6;   /* kWh */
  --series-2: #eb6834;   /* EGP charges */
  --ok: #1a7f4b;
  --ok-wash: #e5f3ea;
  --err: #b3261e;
  --err-wash: #fbe9e7;
  --focus: #1d5aa6;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
  --radius: 12px;
  --font: "Segoe UI", "Noto Sans Arabic", "Geeza Pro", Tahoma, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0e1014;
    --surface: #171a20;
    --surface-2: #1d2128;
    --ink: #eef0f3;
    --ink-2: #c4c9d1;
    --muted: #9aa2ad;
    --line: #2a2f37;
    --grid: #252930;
    --axis: #3b404a;
    --accent: #8ab6f0;
    --accent-ink: #0e1014;
    --accent-wash: #1b2738;
    --series-1: #3987e5;
    --series-2: #d95926;
    --ok: #4cc38a;
    --ok-wash: #15281f;
    --err: #f2867f;
    --err-wash: #321a19;
    --focus: #8ab6f0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font-family: var(--font); font-size: 15px; line-height: 1.6;
  overflow-wrap: anywhere;
}
h1, h2, h3 { line-height: 1.3; margin: 0 0 .4rem; font-weight: 700; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .6rem; }
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
.num, td, .kpi-v, .chip { font-variant-numeric: tabular-nums; }
.num { white-space: nowrap; }
.muted { color: var(--muted); }
.sp { flex: 1; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; inset-inline-start: .5rem; top: -3rem; z-index: 10;
  background: var(--surface); padding: .4rem .8rem; border-radius: 8px; }
.skip:focus { top: .5rem; }

/* ---------- top bar ---------- */
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.topbar-in {
  max-width: 1180px; margin: 0 auto; padding: .55rem 1rem;
  display: flex; gap: .4rem 1rem; align-items: center; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .55rem; color: var(--ink); text-decoration: none; font-weight: 700; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent);
  display: grid; place-items: center; flex: none; }
.brand-mark svg { width: 16px; height: 16px; stroke: var(--accent-ink); }
.nav { display: flex; gap: .15rem; flex-wrap: wrap; }
.nav a { color: var(--ink-2); text-decoration: none; padding: .3rem .6rem; border-radius: 8px; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-wash); color: var(--accent); font-weight: 600; }
.who { display: flex; align-items: center; gap: .6rem; color: var(--muted); font-size: .9rem; }

/* ---------- layout ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 1.1rem 1rem 2.5rem; }
.page-head { display: flex; gap: .75rem 1rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head .t { flex: 1 1 18rem; min-width: 0; }
.page-head .sub { color: var(--muted); margin: 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.crumbs { font-size: .88rem; color: var(--muted); margin-bottom: .35rem; }
.crumbs a { color: var(--muted); }
.grid { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 720px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .grid.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.stack > * + * { margin-top: 1rem; }

/* ---------- cards ---------- */
.card, .pcard, .panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1rem; min-width: 0;
}
.grid > .pcard, .grid > .card { margin-bottom: 0; }
.pcard { display: flex; flex-direction: column; gap: .8rem; }
.pcard-h { display: flex; align-items: flex-start; gap: .5rem; justify-content: space-between; }
.pcard-h h2 { margin: 0; font-size: 1.08rem; }
.pcard-h h2 a { color: var(--ink); text-decoration: none; }
.pcard-h h2 a:hover { color: var(--accent); }
.pcard-f { display: flex; gap: .3rem 1rem; flex-wrap: wrap; margin-top: auto;
  border-top: 1px solid var(--line); padding-top: .7rem; font-size: .9rem; }
.panel-h { display: flex; gap: .5rem 1rem; align-items: baseline; flex-wrap: wrap; margin-bottom: .6rem; }
.panel-h h2 { margin: 0; }
.panel-h .sub { color: var(--muted); font-size: .9rem; }

/* ---------- KPIs ---------- */
.kpis { display: grid; gap: .75rem; margin: 0; grid-template-columns: minmax(0, 1fr); }
.kpis.strip { grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); margin-bottom: 1rem; }
.pcard .kpis { grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); }
.kpi { margin: 0; min-width: 0; }
.kpis.strip .kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .8rem 1rem; box-shadow: var(--shadow); }
.kpi dt, .kpi-l { color: var(--muted); font-size: .84rem; margin: 0; }
.kpi dd { margin: 0; }
.kpi-v { font-size: 1.45rem; font-weight: 700; letter-spacing: -.01em; line-height: 1.25; white-space: nowrap; }
.kpis.strip .kpi-v { font-size: 1.6rem; }
.kpi-s { color: var(--muted); font-size: .84rem; }
.spark-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  background: var(--surface-2); border-radius: 10px; padding: .35rem .7rem; }
.spark-row .kpi-l { flex: 1; }
.spark { display: block; overflow: visible; }
.spark-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark-area { fill: var(--series-1); opacity: .1; }
.spark-dot { fill: var(--series-1); stroke: var(--surface-2); stroke-width: 2; }
.spark-empty { color: var(--muted); font-size: .84rem; }

/* ---------- chips / badges / buttons ---------- */
.chip { display: inline-flex; align-items: center; gap: .3rem; border: 1px solid var(--line);
  border-radius: 999px; padding: .05rem .6rem; font-size: .8rem; color: var(--ink-2);
  background: var(--surface); white-space: nowrap; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.badge { display: inline-block; border-radius: 6px; padding: .05rem .5rem; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-wash); color: var(--ok); }
.badge.old { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.badge.ver { background: var(--accent-wash); color: var(--accent); }

input, select, button, .btn {
  font: inherit; font-size: .95rem; padding: .42rem .75rem; border: 1px solid var(--line);
  border-radius: 8px; background: var(--surface); color: var(--ink);
}
button, .btn { cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .35rem; line-height: 1.4; }
button:hover, .btn:hover { background: var(--surface-2); }
button.pri, .btn.pri { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.pri:hover, .btn.pri:hover { filter: brightness(1.08); background: var(--accent); }
button.danger { color: var(--err); }
.btn svg, button svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }
.btn.sm { padding: .2rem .55rem; font-size: .85rem; }

/* ---------- forms / flashes (shared with admin) ---------- */
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .6rem; }
form.inline { display: inline; }
.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; }
.filters label { display: grid; gap: .15rem; font-size: .84rem; color: var(--muted); }
.flash { padding: .6rem .9rem; border-radius: 10px; margin-bottom: .9rem; border: 1px solid transparent; }
.flash.ok { background: var(--ok-wash); color: var(--ok); }
.flash.err { background: var(--err-wash); color: var(--err); }
details { margin-bottom: .6rem; }
summary { cursor: pointer; font-weight: 600; padding: .3rem 0; color: var(--ink-2); }
tr.hide, tr.fold { display: none; }
td.mod { background: var(--accent-wash); }

/* ---------- empty states ---------- */
.empty { display: flex; align-items: center; gap: .7rem; color: var(--muted);
  border: 1px dashed var(--axis); border-radius: 10px; padding: .9rem 1rem; background: var(--surface-2); }
.empty svg { width: 22px; height: 22px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; }
.empty strong { color: var(--ink-2); display: block; }

/* ---------- tables ---------- */
table { border-collapse: separate; border-spacing: 0; width: 100%; }
th, td { overflow-wrap: normal; border-bottom: 1px solid var(--line); padding: .45rem .7rem; text-align: center; vertical-align: middle; }
th { background: var(--surface-2); color: var(--ink-2); font-weight: 600; font-size: .86rem; white-space: nowrap; }
td:first-child, th:first-child { text-align: right; }
.tbl-wrap { overflow: auto; max-width: 100%; border: 1px solid var(--line); border-radius: 10px; }
.tbl-wrap.tall { max-height: 70vh; }
.tbl th { position: sticky; top: 0; z-index: 1; }
.tbl thead tr:nth-child(2) th { top: 2.2rem; }
.tbl tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 70%, var(--surface)); }
.tbl tbody tr:hover td { background: var(--accent-wash); }
.tbl tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--axis); border-bottom: 0; }
.tbl td.n, .tbl th.n { text-align: right; }
.tbl td.n { white-space: nowrap; }
.tbl .stick { position: sticky; inset-inline-start: 0; background: var(--surface); z-index: 1; }
.tbl th.stick { z-index: 2; background: var(--surface-2); }
.tbl tr.is-old td { color: var(--muted); }
.tbl tr.is-old td:first-child { text-decoration: line-through; text-decoration-color: var(--axis); }
.tbl tr:last-child td { border-bottom: 0; }
.card table:not(.tbl) th, .card table:not(.tbl) td { border: 1px solid var(--line); }

/* ---------- charts (inline SVG from charts.py) ---------- */
.chart { overflow-x: auto; }
.chart svg.ch { display: block; width: 100%; height: auto; min-width: 460px; }
.chart svg.ch-is-empty { min-width: 0; max-height: 140px; }
.ch { font-family: var(--font); }
.ch-grid { stroke: var(--grid); stroke-width: 1; }
.ch-axis { stroke: var(--axis); stroke-width: 1; }
.ch-tick { fill: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.ch-sub { font-size: 11px; }
.ch-val { fill: var(--ink-2); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.ch-empty { fill: var(--muted); font-size: 15px; }
.ch-bar { fill: var(--series-1); }
.ch.s2 .ch-bar { fill: var(--series-2); }
.ch-hit { fill: transparent; }
.ch-pt:hover .ch-bar { opacity: .78; }
.legend-note { color: var(--muted); font-size: .84rem; margin-top: .35rem; }

/* ---------- month switcher ---------- */
.mnav { display: inline-flex; align-items: center; gap: .3rem; border: 1px solid var(--line); border-radius: 10px; padding: .15rem; }
.mnav a, .mnav span.off { padding: .2rem .6rem; border-radius: 8px; text-decoration: none; }
.mnav a:hover { background: var(--surface-2); }
.mnav strong { padding: 0 .4rem; font-variant-numeric: tabular-nums; }
.mnav .off { color: var(--axis); }

/* ---------- meta list ---------- */
.meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: .6rem 1rem; margin: 0; }
.meta div { min-width: 0; }
.meta dt { color: var(--muted); font-size: .82rem; }
.meta dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.notice { border-inline-start: 4px solid var(--axis); background: var(--surface-2); padding: .6rem .9rem; border-radius: 8px; margin-bottom: 1rem; }

/* ---------- login ---------- */
.login { max-width: 380px; margin: 3rem auto; }
.login label { display: grid; gap: .2rem; width: 100%; color: var(--ink-2); font-size: .9rem; }
.login input, .login button { width: 100%; justify-content: center; }

.print-only { display: none; }

/* ---------- phone ---------- */
@media (max-width: 520px) {
  body { font-size: 14.5px; }
  .wrap { padding: .8rem .75rem 2rem; }
  .card, .pcard, .panel { padding: .85rem .9rem; }
  h1 { font-size: 1.25rem; }
  .kpi-v { font-size: 1.3rem; }
  .who .uname { display: none; }
}

/* ---------- print (A4, black on white) ---------- */
@media print {
  @page { size: A4; margin: 12mm; }
  :root {
    --page: #fff; --surface: #fff; --surface-2: #f3f3f3; --ink: #000; --ink-2: #111;
    --muted: #444; --line: #bbb; --grid: #ddd; --axis: #888; --accent: #000;
    --accent-wash: #fff; --series-1: #555; --series-2: #555; --ok: #000; --ok-wash: #fff;
    --shadow: none;
  }
  body { font-size: 11pt; background: #fff; color: #000; }
  .topbar, .no-print, nav, button, .btn, .actions, .filters, .skip, .mnav a, .pcard-f { display: none !important; }
  .print-only { display: block; }
  .print-head { border-bottom: 1px solid #000; padding-bottom: 4pt; margin-bottom: 8pt; font-size: 9pt; }
  .wrap { max-width: none; padding: 0; }
  .card, .pcard, .panel, .kpis.strip .kpi { box-shadow: none; border-color: #bbb; break-inside: avoid; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tbl-wrap, .tbl-wrap.tall { overflow: visible; max-height: none; border: 0; }
  .tbl th { position: static; }
  .tbl tbody tr:nth-child(even) td { background: #f3f3f3; }
  .chart { overflow: visible; }
  .chart svg.ch { min-width: 0; }
  details > summary { display: none; }
  details:not([open]) > *:not(summary) { display: none; }
  a { color: #000; text-decoration: none; }
}
@media (forced-colors: active) {
  .ch-bar, .spark-dot { fill: CanvasText; }
  .spark-line { stroke: CanvasText; }
}
