/* ==========================================================================
   Radiology Department Dashboard — Jubail Hospital
   Visual identity derived from the Eastern Health Cluster logo
   ========================================================================== */

:root {
  --font: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;

  /* surfaces & ink */
  --bg: #f1f5f9;
  --bg-tint: #e8f2f9;
  --surface: #ffffff;
  --surface-2: #f6f9fc;
  --surface-3: #edf3f8;
  --border: #e1e9f0;
  --border-strong: #cad7e2;
  --text: #0d2233;
  --text-2: #465a6b;
  --muted: #74879a;

  /* brand (from logo) */
  --brand-navy: #0c549e;
  --brand-blue: #2490cc;
  --brand-sky: #2fa8df;
  --brand-teal: #3dc0c3;
  --brand-green: #00a57c;
  --brand-lime: #9cca3b;
  --primary: #1878b8;
  --primary-hover: #0f66a1;
  --primary-soft: #e4f1fa;
  --primary-ink: #0b4f8a;
  --hero: linear-gradient(125deg, #0b4a8f 0%, #1674b6 48%, #1f9fcf 100%);

  /* chart chrome */
  --grid: #e8eef3;
  --axis: #c6d3de;
  --s1: #2490cc; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --s1-soft: #b8dbf0;

  /* status (reserved) */
  --good: #0ca30c;  --good-text: #0a7433;  --good-soft: #e3f4e7;
  --warn: #fab219;  --warn-text: #8a5a00;  --warn-soft: #fff3d6;
  --serious: #ec835a; --serious-text: #a9431b; --serious-soft: #fdece4;
  --crit: #d03b3b;  --crit-text: #b02a2a;  --crit-soft: #fce8e8;
  --neutral-soft: #eef2f6; --neutral-text: #4f6273;

  --shadow-sm: 0 1px 2px rgba(13, 42, 68, .05);
  --shadow: 0 1px 2px rgba(13, 42, 68, .05), 0 6px 20px rgba(13, 42, 68, .05);
  --shadow-lg: 0 18px 50px rgba(13, 42, 68, .22);
  --radius: 16px;
  --radius-sm: 10px;
  --sidebar-w: 268px;
  --topbar-h: 72px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0a131b;
  --bg-tint: #0e1b26;
  --surface: #122029;
  --surface-2: #162632;
  --surface-3: #1b2e3c;
  --border: #22384a;
  --border-strong: #2e4a60;
  --text: #e7f0f6;
  --text-2: #b1c3d1;
  --muted: #7f95a7;

  --primary: #3aa0dd;
  --primary-hover: #58b2e8;
  --primary-soft: #133449;
  --primary-ink: #8fcdf2;
  --hero: linear-gradient(125deg, #0a3a6d 0%, #0f5c93 50%, #1682ad 100%);

  --grid: #1f3242;
  --axis: #2e4658;
  --s1: #2f95d3; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --s1-soft: #1f4966;

  --good-text: #4fd06a; --good-soft: #10301c;
  --warn-text: #ffc857; --warn-soft: #33290d;
  --serious-text: #f4a582; --serious-soft: #3a2117;
  --crit-text: #ff8a8a; --crit-soft: #3a1a1c;
  --neutral-soft: #1c2d3a; --neutral-text: #a9bccb;

  --shadow-sm: none;
  --shadow: 0 1px 0 rgba(255, 255, 255, .02);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
body.modal-open { overflow: hidden; }
h1, h2, h3, p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.block { display: block; }
.grow { flex: 1 1 auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }

.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.i-sm { width: 15px; height: 15px; vertical-align: -3px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 14px;
  padding: 18px 16px;
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  overflow-y: auto;
  z-index: 40;
}
.brand { padding: 6px 8px 12px; border-bottom: 1px solid var(--border); }
.brand img { display: block; width: 100%; height: auto; max-width: 220px; margin-inline: auto; }
:root[data-theme="dark"] .brand img, :root[data-theme="dark"] .print-head img { filter: brightness(1.35) saturate(1.1); }
.dept {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border-radius: 14px;
  background: linear-gradient(135deg, var(--primary-soft), var(--surface-2));
  border: 1px solid var(--border);
}
.dept strong { display: block; font-size: 15px; font-weight: 700; color: var(--primary-ink); }
.dept small { display: block; font-size: 12.5px; color: var(--text-2); }
.dept-ico {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; flex: none;
  color: #fff; background: var(--hero); box-shadow: 0 6px 14px rgba(22, 116, 182, .3);
}
.dept-ico .i { width: 24px; height: 24px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group { font-size: 11.5px; font-weight: 600; letter-spacing: .02em; color: var(--muted); padding: 12px 12px 6px; text-transform: uppercase; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  color: var(--text-2); font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface-3); color: var(--text); }
.nav-link.active { background: var(--primary-soft); color: var(--primary-ink); font-weight: 600; box-shadow: inset 3px 0 0 var(--primary); }
[dir="rtl"] .nav-link.active { box-shadow: inset -3px 0 0 var(--primary); }
.side-foot {
  margin-top: auto; display: flex; gap: 10px; align-items: flex-start;
  padding: 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12.5px; color: var(--text-2);
}
.side-foot .i { color: var(--brand-green); margin-top: 2px; }
.side-foot small { display: block; color: var(--muted); font-size: 11.5px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px;
  min-height: var(--topbar-h); padding: 12px 28px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.top-title { min-width: 0; flex: 1 1 auto; }
.top-title h1 { font-size: 21px; font-weight: 700; line-height: 1.3; }
.top-title p { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.view { padding: 24px 28px 48px; display: flex; flex-direction: column; gap: 20px; max-width: 1560px; width: 100%; }

.only-mobile, .show-sm { display: none !important; }
.scrim { display: none; }
.bottom-nav { display: none; }
.fab { display: none; }

/* ---------- buttons & controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px;
  border: 1px solid transparent; border-radius: 10px;
  font-weight: 600; font-size: 14px; line-height: 1.2;
  cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn .i { width: 18px; height: 18px; }
.btn.sm { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(24, 120, 184, .25); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-soft { background: var(--primary-soft); color: var(--primary-ink); }
.btn-soft:hover { border-color: color-mix(in srgb, var(--primary) 35%, transparent); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text-2); }
.btn-ghost:hover { border-color: var(--border-strong); color: var(--text); background: var(--surface-2); }
.btn-danger { background: var(--crit); color: #fff; }
.btn-danger:hover { filter: brightness(.94); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.file-btn { cursor: pointer; }

.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  cursor: pointer; transition: background .15s, color .15s, border-color .15s;
  font-size: 18px; font-weight: 600; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.icon-btn.sm { width: 34px; height: 34px; border-radius: 9px; }
.icon-btn.sm .i { width: 17px; height: 17px; }
.icon-btn.xs { width: 30px; height: 30px; border-radius: 8px; border-color: transparent; background: transparent; }
.icon-btn.xs .i { width: 16px; height: 16px; }
.icon-btn.xs:hover { background: var(--surface-3); }
.icon-btn.danger:hover { color: var(--crit-text); background: var(--crit-soft); border-color: transparent; }
.icon-btn.ok { color: var(--good-text); }
.icon-btn.ok:hover { background: var(--good-soft); border-color: transparent; }
.icon-btn:disabled { opacity: .3; cursor: default; }
.lang-btn { padding-inline: 12px; }

select, input[type="text"], input[type="search"], input[type="number"], input[type="date"], input[type="month"], input:not([type]), textarea {
  width: 100%; min-height: 42px; padding: 8px 12px;
  border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 64px; }
select { appearance: none; -webkit-appearance: none; padding-inline-end: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2374879a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-size: 16px; background-position: right 10px center; }
[dir="rtl"] select { background-position: left 10px center; }
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
input[readonly] { background: var(--surface-2); }

.search { position: relative; display: flex; align-items: center; min-width: 220px; flex: 1 1 240px; max-width: 360px; }
.search .i { position: absolute; inset-inline-start: 12px; color: var(--muted); width: 18px; height: 18px; pointer-events: none; }
.search input { padding-inline-start: 38px; }
.filter-select { width: auto; min-width: 150px; max-width: 240px; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; color: var(--text-2); user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 40px; height: 22px; border-radius: 22px; background: var(--border-strong); position: relative; transition: background .2s; flex: none; }
.switch .thumb { position: absolute; top: 3px; inset-inline-start: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: inset-inline-start .2s; }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track .thumb { inset-inline-start: 21px; }
.switch input:focus-visible + .track { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; min-width: 0;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h3 { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card-head h3 .i { width: 18px; height: 18px; color: var(--primary); }
.card-head p { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.link { font-size: 13px; font-weight: 600; white-space: nowrap; padding-top: 2px; }
.link:hover { text-decoration: underline; }

.grid { display: grid; gap: 20px; }
.grid-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack-col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* ---------- demo banner / tip ---------- */
.demo-banner, .tip {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  padding: 10px 14px; border-radius: 12px;
  background: var(--warn-soft); color: var(--warn-text);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  font-size: 14px; font-weight: 500;
}
.tip { background: var(--primary-soft); color: var(--primary-ink); border-color: color-mix(in srgb, var(--primary) 25%, transparent); }
.demo-banner .btn-ghost { background: transparent; }

/* ---------- filters row ---------- */
.filters, .toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.fld-inline { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text-2); font-weight: 500; }
.fld-inline .i { color: var(--primary); }
.fld-inline select { width: auto; min-width: 110px; min-height: 38px; }

/* ---------- hero ---------- */
.hero {
  position: relative; overflow: hidden;
  display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1.4fr) minmax(0, 1fr); gap: 24px; align-items: center;
  padding: 26px 28px; border-radius: 20px;
  background: var(--hero); color: #fff;
  box-shadow: 0 14px 34px rgba(12, 84, 158, .22);
}
.hero::before, .hero::after {
  content: ""; position: absolute; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, rgba(255, 255, 255, .16), rgba(255, 255, 255, 0) 70%);
}
.hero::before { width: 380px; height: 380px; top: -190px; inset-inline-end: -80px; }
.hero::after { width: 260px; height: 260px; bottom: -160px; inset-inline-start: 30%; }
.hero > * { position: relative; }
.hero-label { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; opacity: .92; }
.hero-label .i { width: 20px; height: 20px; }
.hero-value { font-size: 56px; font-weight: 700; line-height: 1.1; margin: 6px 0 10px; letter-spacing: -.01em; }
.hero-delta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 13px; }
.delta { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-weight: 700; background: rgba(255, 255, 255, .18); }
.delta .i { width: 16px; height: 16px; }
.delta.down { background: rgba(255, 120, 120, .28); }
.delta-cap { opacity: .85; }
.hero-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.hs { padding: 12px 14px; border-radius: 14px; background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .16); min-width: 0; }
.hs span { display: block; font-size: 12.5px; opacity: .85; }
.hs strong { display: block; font-size: 22px; font-weight: 700; line-height: 1.35; }
.hs strong small { font-size: 12px; font-weight: 500; opacity: .85; }
.hs .hs-name { font-size: 15px; line-height: 1.35; overflow-wrap: anywhere; }
.hero-spark { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.hero-spark span { font-size: 12px; opacity: .8; }
.spark-box { position: relative; height: 64px; margin: 6px 4px 0; }
.spark { width: 100%; height: 100%; display: block; overflow: visible; }
.spark-line { fill: none; stroke: #fff; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.spark-fill { fill: rgba(255, 255, 255, .14); }
.spark-dot { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 2px rgba(12, 84, 158, .9); }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi {
  display: flex; align-items: center; gap: 14px;
  padding: 18px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  color: var(--text); transition: border-color .15s, transform .15s; min-width: 0;
}
a.kpi:hover { border-color: var(--border-strong); transform: translateY(-2px); }
.kpi-ico { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 14px; flex: none; }
.kpi-ico .i { width: 24px; height: 24px; }
.kpi-body { display: flex; flex-direction: column; min-width: 0; }
.kpi-label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.kpi-value { font-size: 28px; font-weight: 700; line-height: 1.25; }
.kpi-value small { font-size: 14px; font-weight: 500; color: var(--text-2); }
.kpi-sub { font-size: 12.5px; color: var(--muted); }
.tone-primary { background: var(--primary-soft); color: var(--primary-ink); }
.tone-warn { background: var(--warn-soft); color: var(--warn-text); }
.tone-serious { background: var(--serious-soft); color: var(--serious-text); }
.tone-crit { background: var(--crit-soft); color: var(--crit-text); }
.tone-good { background: var(--good-soft); color: var(--good-text); }
.tone-neutral { background: var(--neutral-soft); color: var(--neutral-text); }
.ring { flex: none; }
.ring-track { fill: none; stroke: var(--surface-3); stroke-width: 7; }
.ring-val { fill: none; stroke-width: 7; stroke-linecap: round; transition: stroke-dasharray .6s ease; }
.ring-check { fill: none; stroke: var(--muted); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- charts ---------- */
.chart-card { display: flex; flex-direction: column; }
.chart-body { position: relative; flex: 1; }
.chart { width: 100%; min-height: 60px; }
.chart svg { display: block; overflow: visible; }
.chart-table { display: none; }
.chart-body.show-table .chart { display: none; }
.chart-body.show-table .chart-table { display: block; }
svg .gl { stroke: var(--grid); stroke-width: 1; }
svg .axis { stroke: var(--axis); stroke-width: 1; }
svg .ax-label { fill: var(--muted); font-size: 11.5px; font-family: var(--font); }
svg .ax-strong { fill: var(--text); font-weight: 700; }
svg .val-label { fill: var(--text); font-size: 12px; font-weight: 700; font-family: var(--font); }
svg .bar { fill: var(--s1-soft); transition: fill .15s, opacity .15s; }
svg .bar.bar-hi { fill: var(--s1); }
svg .bar.hover { fill: var(--primary-hover); }
svg .hit { fill: transparent; cursor: pointer; outline: none; }
svg .hit:focus-visible { stroke: var(--primary); stroke-width: 1.5; }
svg .area-line { fill: none; stroke: var(--s1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg .area-fill { fill: var(--s1); opacity: .1; }
svg .dot { fill: var(--s1); stroke: var(--surface); stroke-width: 2; }
svg .dot-hover { pointer-events: none; }
svg .crosshair { stroke: var(--axis); stroke-width: 1; pointer-events: none; }

.hb { display: flex; flex-direction: column; gap: 10px; }
.hb-row { display: grid; grid-template-columns: minmax(80px, 38%) minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 2px 4px; border-radius: 8px; cursor: default; outline: none; }
.hb-row:hover, .hb-row:focus-visible { background: var(--surface-2); }
.hb-label { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: match-parent; }
.hb-track { height: 14px; display: flex; }
.hb-bar { height: 100%; min-width: 2px; border-start-end-radius: 4px; border-end-end-radius: 4px; transition: width .7s cubic-bezier(.2, .8, .2, 1); }
.hb-val { font-size: 13px; font-weight: 700; min-width: 36px; text-align: end; }

.st-bar { display: flex; gap: 2px; height: 16px; border-radius: 5px; overflow: hidden; margin: 4px 0 14px; }
.st-seg { min-width: 4px; height: 100%; cursor: default; outline: none; transition: opacity .15s; }
.st-seg:hover, .st-seg:focus-visible { opacity: .82; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.legend li { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto 44px; align-items: center; gap: 8px; font-size: 13px; }
.legend li.is-zero { opacity: .5; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex: none; }
.lg-label { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: match-parent; }
.lg-val { font-weight: 700; }
.lg-pct { color: var(--muted); text-align: end; }
.chart-empty { display: grid; place-items: center; min-height: 120px; color: var(--muted); font-size: 13.5px; border: 1px dashed var(--border-strong); border-radius: 12px; }

.tooltip {
  position: fixed; z-index: 100; pointer-events: none;
  min-width: 120px; max-width: 260px; padding: 10px 12px;
  border-radius: 10px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); box-shadow: var(--shadow-lg);
  font-size: 12.5px;
}
.tooltip[hidden] { display: none; }
.tt-title { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.tt-row { display: flex; align-items: center; gap: 8px; line-height: 1.6; }
.tt-key { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.tt-key-line { height: 3px; width: 14px; border-radius: 2px; }
.tt-val { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tt-lab { color: var(--text-2); }

.table-wrap { max-height: 320px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.mini-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.mini-table th, .mini-table td { padding: 8px 12px; text-align: start; border-bottom: 1px solid var(--border); }
.mini-table th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; color: var(--text-2); }
.mini-table td.num { text-align: end; font-variant-numeric: tabular-nums; }
.mini-table tr:last-child td { border-bottom: none; }

/* ---------- alerts ---------- */
.alert-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.alert-list li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.alert-list li:last-child { border-bottom: none; padding-bottom: 0; }
.al-ico { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; flex: none; }
.al-ico .i { width: 19px; height: 19px; }
.al-main { flex: 1; min-width: 0; }
.al-main strong { display: block; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.al-main small { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.late { color: var(--crit-text) !important; font-weight: 600; }
.all-clear { display: flex; align-items: center; gap: 10px; padding: 18px; border-radius: 12px; background: var(--good-soft); color: var(--good-text); font-weight: 600; font-size: 14px; }

/* ---------- badges, chips, pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; line-height: 1.5; white-space: nowrap;
  background: var(--neutral-soft); color: var(--neutral-text);
}
.badge .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.badge .i { width: 13px; height: 13px; }
.badge.st-open { background: var(--surface-3); color: var(--text); }
.badge.st-done { background: var(--good-soft); color: var(--good-text); }
.badge.st-cancelled { background: var(--neutral-soft); color: var(--neutral-text); }
.badge.pr-crit { background: var(--crit-soft); color: var(--crit-text); }
.badge.pr-serious { background: var(--serious-soft); color: var(--serious-text); }
.badge.pr-warn { background: var(--warn-soft); color: var(--warn-text); }
.badge.pr-neutral { background: var(--neutral-soft); color: var(--neutral-text); }
.days-pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; color: var(--muted); font-weight: 500; direction: ltr; unicode-bidi: isolate; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: 13px; color: var(--text-2); }
.chip .i { width: 16px; height: 16px; }
.chip strong { color: inherit; font-weight: 700; }
.chip.chip-strong { background: var(--primary-soft); color: var(--primary-ink); border-color: transparent; }
.chip.tone-warn, .chip.tone-crit, .chip.tone-good, .chip.tone-primary { border-color: transparent; }

/* ---------- data tables ---------- */
.table-card { padding: 0; overflow: hidden; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: start; font-size: 12.5px; font-weight: 600; color: var(--text-2);
  background: var(--surface-2); padding: 12px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table td.strong { font-weight: 600; }
.table .num { text-align: end; font-variant-numeric: tabular-nums; }
.table td.notes { color: var(--muted); font-size: 13px; max-width: 260px; }
.table td.desc { max-width: 280px; }
.table .actions { width: 1%; white-space: nowrap; text-align: end; }
.row-actions { display: inline-flex; gap: 6px; }
.type-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 8px; vertical-align: 1px; }

.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 14px; }
.pager-info { font-size: 13px; color: var(--muted); }

.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 40px 16px; text-align: center; color: var(--muted); }
.empty .i { width: 36px; height: 36px; color: var(--border-strong); }
.empty strong { color: var(--text); font-size: 15px; }

/* ---------- lists page ---------- */
.lists-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 18px; align-items: start; }
.lc-title { display: flex; align-items: flex-start; gap: 12px; }
.lc-ico { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; flex: none; background: var(--primary-soft); color: var(--primary-ink); }
.items { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.item { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 10px; }
.item:hover { background: var(--surface-2); }
.item.is-archived .item-names { opacity: .55; }
.item-n { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 6px; background: var(--surface-3); font-size: 11.5px; color: var(--muted); font-weight: 600; flex: none; }
.item-names { flex: 1; min-width: 0; }
.item-names strong { display: block; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-names small { display: block; font-size: 12px; color: var(--muted); }
.item-names strong, .item-names small { text-align: match-parent; }
.item-actions { display: flex; gap: 0; opacity: .55; transition: opacity .15s; }
.item:hover .item-actions, .item:focus-within .item-actions { opacity: 1; }
.add-item { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.add-item input, .add-item select { flex: 1 1 120px; min-height: 38px; width: auto; }
.add-item .btn { flex: none; }

/* ---------- settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.action-rows { display: flex; flex-wrap: wrap; gap: 10px; }
.hint { display: flex; gap: 8px; align-items: flex-start; margin-top: 12px; font-size: 13px; color: var(--muted); }
.hint .i { width: 16px; height: 16px; margin-top: 2px; flex: none; }
.help { margin: 0; padding-inline-start: 20px; display: flex; flex-direction: column; gap: 8px; color: var(--text-2); font-size: 14px; }
.danger-card { border-color: color-mix(in srgb, var(--crit) 30%, var(--border)); }

/* ---------- forms & modal ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.fld { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fld.full { grid-column: 1 / -1; }
.fld label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.req { color: var(--crit-text); }
.err { color: var(--crit-text); font-size: 12px; min-height: 0; }
.err:empty { display: none; }
.fld.has-err input, .fld.has-err select, .fld.has-err textarea { border-color: var(--crit); }
.select-add { display: flex; gap: 8px; }
.select-add select { flex: 1; min-width: 0; }
.add-btn { width: 42px; height: 42px; color: var(--primary); }
.inline-add { display: flex; gap: 6px; margin-top: 4px; padding: 8px; border-radius: 10px; background: var(--primary-soft); }
.inline-add[hidden] { display: none; }
.inline-add input { min-height: 36px; }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center; padding: 20px;
  background: rgba(8, 24, 38, .45);
  opacity: 0; transition: opacity .16s;
}
.modal-backdrop.in { opacity: 1; }
.modal-backdrop.out { opacity: 0; }
.modal {
  width: min(640px, 100%); max-height: calc(100vh - 40px);
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-lg); border: 1px solid var(--border);
  transform: translateY(8px) scale(.98); transition: transform .16s;
}
.modal-backdrop.in .modal { transform: none; }
.modal-sm { width: min(440px, 100%); }
.modal-md { width: min(560px, 100%); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 12px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 18px; font-weight: 700; }
.modal-head p { font-size: 13px; color: var(--muted); margin-top: 2px; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 18px 18px; }
.confirm-msg { font-size: 15px; color: var(--text-2); }

.quick .form-grid { margin-bottom: 16px; }
.qe-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.qe-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.qe-row:last-child { border-bottom: none; }
.qe-row:nth-child(even) { background: var(--surface-2); }
.qe-row label { flex: 1; font-weight: 600; font-size: 14px; }
.qe-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper input { width: 76px; text-align: center; min-height: 36px; padding: 4px 6px; font-weight: 700; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qe-total { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; padding: 12px 14px; border-radius: 12px; background: var(--primary-soft); color: var(--primary-ink); font-weight: 600; }
.qe-total strong { font-size: 22px; }

/* ---------- toast ---------- */
.toast-root { position: fixed; z-index: 120; bottom: 24px; inset-inline-start: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
[dir="rtl"] .toast-root { transform: translateX(50%); }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-radius: 12px;
  background: #0f2536; color: #fff; box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500;
  animation: toast-in .2s ease-out; max-width: min(92vw, 520px);
}
:root[data-theme="dark"] .toast { background: #e7f0f6; color: #0d2233; }
.toast .i { width: 18px; height: 18px; }
.toast-good .i { color: #4fd06a; }
.toast-bad .i { color: #ff8a8a; }
.toast-info .i { color: #7cc6f2; }
:root[data-theme="dark"] .toast-good .i { color: var(--good); }
:root[data-theme="dark"] .toast-bad .i { color: var(--crit); }
:root[data-theme="dark"] .toast-info .i { color: var(--primary); }
.toast.out { opacity: 0; transform: translateY(6px); transition: all .3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.print-head { display: none; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1280px) {
  .hero { grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); }
  .hero-spark { grid-column: 1 / -1; }
  .spark-box { height: 56px; }
}
@media (max-width: 1180px) {
  .grid-2-1 { grid-template-columns: minmax(0, 1fr); }
  .grid-2-1 .stack-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1024px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; top: 0; bottom: 0; inset-inline-start: 0; width: min(300px, 86vw); height: 100%;
    transform: translateX(-105%); transition: transform .25s ease; box-shadow: var(--shadow-lg); z-index: 70;
  }
  [dir="rtl"] .sidebar { transform: translateX(105%); }
  body.drawer-open .sidebar { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 65; background: rgba(8, 24, 38, .45); opacity: 0; pointer-events: none; transition: opacity .2s; }
  body.drawer-open .scrim { opacity: 1; pointer-events: auto; }
  .only-mobile { display: inline-grid !important; }
  .hide-mobile { display: none !important; }
  .topbar { padding: 10px 16px; gap: 10px; }
  .view { padding: 18px 16px 110px; gap: 16px; }

  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
  }
  .bn-link {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 6px 2px; border: 0; background: none; border-radius: 10px;
    color: var(--muted); font-size: 11px; font-weight: 600; cursor: pointer; min-width: 0;
  }
  .bn-link span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .bn-link .i { width: 22px; height: 22px; }
  .bn-link.active { color: var(--primary); }
  .bn-link.active .i { stroke-width: 2.2; }

  .fab {
    display: grid; place-items: center;
    position: fixed; z-index: 55; bottom: calc(78px + env(safe-area-inset-bottom)); inset-inline-end: 18px;
    width: 56px; height: 56px; border-radius: 18px; border: 0;
    background: var(--hero); color: #fff; box-shadow: 0 10px 24px rgba(12, 84, 158, .38); cursor: pointer;
  }
  .fab[hidden] { display: none; }
  .fab .i { width: 26px; height: 26px; }
  .toast-root { bottom: calc(150px + env(safe-area-inset-bottom)); }
}
@media (max-width: 760px) {
  body { font-size: 14.5px; }
  .top-title h1 { font-size: 18px; }
  .top-title p { font-size: 12px; }
  .hide-sm { display: none !important; }
  .show-sm { display: inline !important; }
  .lang-btn { padding-inline: 10px; min-width: 40px; }

  .hero { grid-template-columns: minmax(0, 1fr); padding: 20px; gap: 16px; border-radius: 18px; }
  .hero-value { font-size: 46px; }
  .hero-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .hs { padding: 10px; }
  .hs strong { font-size: 18px; }
  .hs .hs-name { font-size: 14px; }
  .kpis { gap: 12px; }
  .kpi { flex-direction: column; align-items: flex-start; gap: 10px; padding: 14px; }
  .kpi-ico { width: 40px; height: 40px; border-radius: 12px; }
  .kpi-value { font-size: 24px; }
  .kpi-ring { flex-direction: row; align-items: center; }
  .kpi-ring .ring { width: 52px; height: 52px; }
  .grid-3, .grid-2, .grid-2-1 .stack-col { grid-template-columns: minmax(0, 1fr); }
  .grid, .stack-col { gap: 16px; }
  .card { padding: 16px; }
  .filters .grow, .toolbar .grow { display: none; }
  .filters .btn-ghost span { display: none; }
  .search { max-width: none; flex-basis: 100%; }
  .filter-select { flex: 1 1 140px; max-width: none; }

  /* tables become cards */
  .table-card { background: transparent; border: 0; box-shadow: none; border-radius: 0; overflow: visible; padding: 0; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tbody { display: flex; flex-direction: column; gap: 10px; }
  .table tr { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow-sm); }
  .table tr.is-open { border-inline-start: 3px solid var(--primary); }
  .table tbody tr:hover { background: var(--surface); }
  .table td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 5px 0; border: 0; text-align: end; }
  .table td::before { content: attr(data-label); font-size: 12.5px; color: var(--muted); font-weight: 500; text-align: start; flex: none; }
  .table td.num { text-align: end; }
  .table td.notes:empty { display: none; }
  .table td.notes, .table td.desc { max-width: none; }
  .table td.actions { width: 100%; justify-content: flex-end; padding-top: 10px; margin-top: 6px; border-top: 1px solid var(--border); }
  .table td.actions::before { display: none; }
  .table td .code.block { display: inline; margin-inline-start: 6px; }

  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .modal-backdrop { place-items: end center; padding: 0; }
  .modal { width: 100%; max-height: 92vh; border-radius: 20px 20px 0 0; transform: translateY(40px); }
  .modal-foot { border-radius: 0; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; }
  .settings-grid, .lists-grid { grid-template-columns: minmax(0, 1fr); }
  .item-actions { opacity: 1; }
  .legend li { grid-template-columns: 12px minmax(0, 1fr) auto 40px; }
}
@media (max-width: 400px) {
  .hero-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero-stats .hs:last-child { grid-column: 1 / -1; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ==========================================================================
   Print — monthly report
   ========================================================================== */
@media print {
  @page { size: A4; margin: 12mm; }
  :root { --bg: #fff; }
  body { background: #fff; font-size: 12px; }
  .app { display: block; }
  .sidebar, .topbar, .bottom-nav, .fab, .scrim, .filters, .demo-banner, .toast-root, .tooltip, .chart-card .icon-btn, .link { display: none !important; }
  .view { padding: 0; gap: 12px; max-width: none; }
  .print-head { display: flex; align-items: center; gap: 16px; padding-bottom: 10px; border-bottom: 2px solid var(--brand-blue); }
  .print-head img { width: 200px; height: auto; }
  .print-head h2 { font-size: 18px; color: var(--brand-navy); }
  .print-head p { font-size: 12px; color: var(--text-2); }
  .hero { -webkit-print-color-adjust: exact; print-color-adjust: exact; box-shadow: none; padding: 16px 20px; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
  .grid-2-1 { grid-template-columns: 2fr 1fr; }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .chart svg { max-width: 100%; height: auto; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
