/* Rapid-PACS design system. Loaded after app.css and overrides it: app.css keeps the per-screen layout rules,
   this file holds the look (tokens, components, shell, light/dark, RTL). Screens need no changes to use it.
   Rules here use logical properties (inline-start/end) so the Arabic (dir=rtl) layout mirrors by itself.
   Theme: <html data-theme="light|dark">, set by js/ui.js (follows the system until the user picks one). */

/* ------------------------------------------------------------------ tokens */
:root {
  color-scheme: light;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-ar: "Segoe UI", Tahoma, "Noto Sans Arabic", "Noto Naskh Arabic", "Geeza Pro", "Arial", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --surface-3: #eef2f7;
  --border: #e1e6ee;
  --border-strong: #c7d0dc;
  --text: #172033;
  --text-2: #3c4759;
  --muted: #637083;

  --primary: #2459d6;
  --primary-hover: #1c4bb8;
  --primary-soft: #e8effd;
  --primary-text: #1b4ab3;
  --on-primary: #ffffff;
  --focus: #2f6bff;

  --success: #16794a;  --success-soft: #e3f4ea;
  --warning: #8a5a00;  --warning-soft: #fff3d6;  --warning-strong: #f2b53a;
  --danger: #b42318;   --danger-soft: #fdecea;
  --info: #1d5fa8;     --info-soft: #e5f0fb;
  --violet: #5b3cc4;   --violet-soft: #efeafd;

  --side-bg: #0f1b2e;
  --side-bg-2: #16263f;
  --side-text: #b8c4d6;
  --side-text-strong: #ffffff;
  --side-active: #2459d6;
  --side-muted: #7c8aa1;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16);

  --s1: .25rem; --s2: .5rem; --s3: .75rem; --s4: 1rem; --s5: 1.5rem; --s6: 2rem;
  --side-w: 248px;
  --bar-h: 56px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1220;
  --surface: #121b2c;
  --surface-2: #162134;
  --surface-3: #1c2940;
  --border: #243249;
  --border-strong: #34465f;
  --text: #e6ebf3;
  --text-2: #c3ccda;
  --muted: #8f9cb0;

  --primary: #4f82f7;
  --primary-hover: #6a95fa;
  --primary-soft: #1a2b4d;
  --primary-text: #8fb1ff;
  --on-primary: #ffffff;
  --focus: #7aa2ff;

  --success: #4cc38a;  --success-soft: #11301f;
  --warning: #f2c063;  --warning-soft: #3a2c0c;  --warning-strong: #f2b53a;
  --danger: #ff7b6e;   --danger-soft: #3d1614;
  --info: #7cb4f0;     --info-soft: #132a45;
  --violet: #b9a3ff;   --violet-soft: #272046;

  --side-bg: #080e1a;
  --side-bg-2: #111b2d;

  --shadow-sm: none;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, .55);
}

/* ------------------------------------------------------------------ base */
html { -webkit-text-size-adjust: 100%; }
body { font: 14px/1.5 var(--font); color: var(--text); background: var(--bg); }
:lang(ar), [lang=ar] body, html[lang=ar] body { font-family: var(--font-ar); }
html[lang=ar] body { font-size: 15px; }
a { color: var(--primary-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
p a, li a, dd a, .notice a { text-decoration: underline; text-underline-offset: 2px; }   /* links inside text stay underlined */
.dash-list a, .health a { text-decoration: none; }
button svg, a.button svg { width: 16px; height: 16px; flex: none; }
::selection { background: var(--primary-soft); }
h1 { font-size: 1.45rem; font-weight: 650; letter-spacing: -.01em; margin: 0 0 var(--s4); display: flex; flex-wrap: wrap;
  align-items: center; gap: var(--s2); }
h1 .muted { font-size: .95rem; font-weight: 500; }
h2 { font-size: 1.05rem; font-weight: 620; margin: var(--s5) 0 var(--s3); }
h3 { font-weight: 620; color: var(--text-2); }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
hr { border: 0; border-top: 1px solid var(--border); }

/* Keyboard focus: always visible, never on mouse click. */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; }
.skip-link { position: absolute; inset-inline-start: var(--s3); top: -3rem; z-index: 100; background: var(--primary);
  color: var(--on-primary); padding: var(--s2) var(--s3); border-radius: var(--radius-sm); text-decoration: none; }
.skip-link:focus { top: var(--s3); }

/* ------------------------------------------------------------------ shell: sidebar + top bar + content */
.shell { min-height: 100vh; }
body.signed-in .shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr);
  background: linear-gradient(90deg, var(--side-bg) var(--side-w), transparent var(--side-w)); }
html[dir=rtl] body.signed-in .shell { background: linear-gradient(270deg, var(--side-bg) var(--side-w), transparent var(--side-w)); }
.content { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }

header#top { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; align-items: stretch; gap: 0;
  padding: 0; background: var(--side-bg); color: var(--side-text); overflow: hidden; z-index: 30; }
header#top[hidden] { display: none; }
header#top .brand { display: flex; align-items: center; gap: var(--s3); padding: var(--s4) var(--s4) var(--s3); font-size: 1.05rem;
  font-weight: 700; color: var(--side-text-strong); text-decoration: none; letter-spacing: -.01em; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, #3b82f6, #14b8a6); color: #fff; }
.brand-mark svg { width: 19px; height: 19px; }
.brand small { display: block; font-size: .72rem; font-weight: 500; color: var(--side-muted); letter-spacing: 0; }

header#top nav { flex: 1; display: flex; flex-direction: column; gap: 1px; padding: var(--s2) var(--s3) var(--s4);
  overflow-y: auto; flex-wrap: nowrap; scrollbar-width: thin; scrollbar-color: var(--side-bg-2) transparent; }
header#top nav .nav-group { font-size: .7rem; font-weight: 650; text-transform: uppercase; letter-spacing: .08em;
  color: var(--side-muted); padding: var(--s4) var(--s3) var(--s2); }
html[lang=ar] header#top nav .nav-group { letter-spacing: 0; font-size: .78rem; }
header#top nav a { display: flex; align-items: center; gap: var(--s3); padding: .5rem var(--s3); border-radius: 8px;
  color: var(--side-text); text-decoration: none; font-weight: 500; line-height: 1.25; }
header#top nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
header#top nav a .label { flex: 1; min-width: 0; }
header#top nav a:hover { background: var(--side-bg-2); color: var(--side-text-strong); }
header#top nav a.on { background: var(--side-active); color: #fff; }
header#top nav a.on svg { opacity: 1; }
header#top nav a:focus-visible { outline-color: #9dbbff; }
header#top nav .badge { margin: 0; background: var(--side-bg-2); color: var(--side-text-strong); }
header#top nav .badge.prio-stat { background: #e5483b; color: #fff; }
header#top nav .badge.warn { background: var(--warning-strong); color: #3a2600; }

header#top #who { display: flex; flex-direction: column; gap: var(--s2); padding: var(--s3); border-top: 1px solid var(--side-bg-2);
  font-size: .85rem; color: var(--side-text); }
header#top #who .me { display: flex; align-items: center; gap: var(--s3); color: var(--side-text-strong); text-decoration: none;
  padding: var(--s2); border-radius: 8px; }
header#top #who .me:hover { background: var(--side-bg-2); }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; flex: none; font-weight: 700;
  font-size: .8rem; background: #2a3e5e; color: #dbe6f7; text-transform: uppercase; }
header#top #who .me .who-text { min-width: 0; }
header#top #who .me .who-name { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header#top #who .me .who-role { display: block; color: var(--side-muted); font-size: .78rem; }
header#top #who .chips { display: flex; flex-wrap: wrap; gap: var(--s1); padding-inline: var(--s2); }
header#top #who .badge { margin: 0; background: var(--side-bg-2); color: var(--side-text); font-weight: 500; }
header#top #who .badge.linked { color: #7ee2b8; }
header#top #who button { margin: 0; width: 100%; justify-content: center; background: transparent; color: var(--side-text);
  border-color: #2a3a55; }
header#top #who button:hover { background: var(--side-bg-2); color: #fff; }

.topbar { position: sticky; top: 0; z-index: 20; height: var(--bar-h); display: flex; align-items: center; gap: var(--s3);
  padding: 0 var(--s5); background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border); }
.topbar .crumb { font-weight: 600; color: var(--text-2); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
.topbar .crumb .brand-mini { display: none; align-items: center; gap: var(--s2); color: var(--text); font-weight: 700; }
body:not(.signed-in) .topbar .crumb .brand-mini { display: inline-flex; }
body:not(.signed-in) .topbar .crumb .page-name { display: none; }
.topbar .brand-mini .brand-mark { width: 26px; height: 26px; border-radius: 7px; }
.topbar .brand-mini .brand-mark svg { width: 15px; height: 15px; }
.topbar .tools { display: flex; align-items: center; gap: var(--s2); }
button.icon-btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-width: 36px; height: 36px;
  padding: 0 var(--s2); background: var(--surface); color: var(--text-2); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: none; font-weight: 600; font-size: .85rem; }
button.icon-btn:hover { background: var(--surface-3); color: var(--text); }
button.icon-btn svg { width: 18px; height: 18px; }
button.icon-btn.menu-btn { display: none; }

main#main { width: 100%; max-width: 1280px; margin: 0 auto; padding: var(--s5); flex: 1; }
body:not(.signed-in) main#main { max-width: none; }

#critical-banner { margin: var(--s4) var(--s5) 0; }

/* ------------------------------------------------------------------ cards, layout helpers */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--s5);
  margin-bottom: var(--s4); box-shadow: var(--shadow-sm); }
.card > h2:first-child, .card > h2.first, .card > form > h2:first-child { margin-top: 0; }
form.card.row, .card.row { padding: var(--s4) var(--s5); }
.row { gap: var(--s3); }
.row > label, .lines > label { color: var(--text-2); font-weight: 550; font-size: .82rem; }
.grid2 { gap: var(--s4); }
dl.kv dt { color: var(--muted); }
details > summary { cursor: pointer; font-weight: 600; color: var(--text-2); }
details > summary:hover { color: var(--text); }
details.card > summary, .card details > summary { list-style-position: inside; }
ul, ol { padding-inline-start: 1.4rem; }

/* Wide tables scroll inside their card instead of stretching the page (tablets). */
main .card, main div:has(> table) { overflow-x: auto; }
main .card:has(> dialog), main .card:has(select:focus) { overflow-x: visible; }

/* ------------------------------------------------------------------ forms */
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: .48rem .65rem; min-height: 36px; transition: border-color .12s, box-shadow .12s; }
textarea { line-height: 1.55; }
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--border-strong) 60%, var(--text) 20%); }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-3); color: var(--muted); }
input[type=checkbox], input[type=radio] { min-height: 0; accent-color: var(--primary); width: 1rem; height: 1rem; }
input[type=file] { padding: .35rem; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 80%, transparent); }
select { padding-inline-end: 1.8rem; }
label:has(> input[type=checkbox]) { cursor: pointer; }

/* ------------------------------------------------------------------ buttons */
button, a.button { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); font: inherit; font-weight: 600;
  min-height: 36px; padding: .45rem 1rem; border-radius: 8px; border: 1px solid var(--primary); background: var(--primary);
  color: var(--on-primary); cursor: pointer; line-height: 1.2; text-decoration: none; box-shadow: var(--shadow-sm);
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s; }
button:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button:active { transform: translateY(1px); }
button.secondary, a.button { background: var(--surface); color: var(--text-2); border-color: var(--border-strong); }
button.secondary:hover, a.button:hover { background: var(--surface-3); color: var(--text); border-color: var(--border-strong); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.danger:hover { background: color-mix(in srgb, var(--danger) 88%, #000); }
button.danger-text { background: var(--surface); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
button.danger-text:hover { background: var(--danger-soft); }
button.sign { background: var(--success); border-color: var(--success); color: #fff; }
button.sign:hover { background: color-mix(in srgb, var(--success) 88%, #000); }
button:disabled, button:disabled:hover { opacity: .5; cursor: not-allowed; transform: none; }
td button, td a.button { min-height: 30px; padding: .25rem .7rem; font-size: .85rem; margin: 0 0 var(--s1); margin-inline-end: var(--s1); }
.segs .seg { background: var(--surface); color: var(--text-2); border-color: var(--border-strong); box-shadow: none; }
.segs .seg[aria-pressed=true] { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ------------------------------------------------------------------ tables */
table { background: var(--surface); border-collapse: separate; border-spacing: 0; font-size: .92rem; }
th, td { text-align: start; padding: .65rem .8rem; border-bottom: 1px solid var(--border); }
thead th { position: sticky; top: 0; font-size: .74rem; font-weight: 650; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); background: var(--surface-2); white-space: nowrap; }
html[lang=ar] thead th { letter-spacing: 0; font-size: .8rem; }
tbody th { background: transparent; text-transform: none; letter-spacing: 0; font-size: .88rem; color: var(--text-2); font-weight: 600; }
tbody tr:last-child > * { border-bottom: 0; }
tbody tr:hover > td { background: color-mix(in srgb, var(--primary-soft) 45%, transparent); }
tr.click:hover { background: transparent; }
/* A table straight in the page or a plain box gets the card frame. */
main > table, main div:not(.card) > table, main section:not(.card) > table { border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); overflow: hidden; }
main > table thead th:first-child, main div:not(.card) > table thead th:first-child { border-start-start-radius: var(--radius); }
main > table thead th:last-child, main div:not(.card) > table thead th:last-child { border-start-end-radius: var(--radius); }
td .muted { font-size: .84rem; }

/* ------------------------------------------------------------------ badges (status chips) */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .55rem; border-radius: 999px; font-size: .76rem;
  font-weight: 600; line-height: 1.5; background: var(--surface-3); color: var(--text-2); white-space: nowrap; text-transform: capitalize;
  text-decoration: none; }
a.badge:hover { filter: brightness(.97); }
.badge.scheduled, .badge.hms-queued { background: var(--info-soft); color: var(--info); }
.badge.images_received, .badge.signed, .badge.hms-delivered { background: var(--success-soft); color: var(--success); }
.badge.reported, .badge.amended { background: var(--violet-soft); color: var(--violet); }
.badge.cancelled, .badge.hms-failed { background: var(--danger-soft); color: var(--danger); }
.badge.warn, .badge.draft { background: var(--warning-soft); color: var(--warning); }
.badge.prio-stat { background: #d92d20; color: #fff; }
.badge.prio-urgent { background: var(--warning-strong); color: #3a2600; }
.badge.prio-routine { background: transparent; color: var(--muted); }
.badge.scheduled::before, .badge.images_received::before, .badge.reported::before, .badge.cancelled::before,
.badge.draft::before, .badge.signed::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ------------------------------------------------------------------ messages: notice, error, toast */
.notice { background: var(--warning-soft); color: var(--warning); border: 1px solid color-mix(in srgb, var(--warning) 25%, transparent);
  padding: .65rem .9rem; border-radius: var(--radius-sm); }
.error { color: var(--danger); }
p.error:empty, div.error:empty { display: none; }
p.error:not(:empty), div.error:not(:empty), .notice.error { background: var(--danger-soft); color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 28%, transparent); padding: .6rem .85rem; border-radius: var(--radius-sm);
  font-weight: 500; }
#toast { inset-inline-end: var(--s5); right: auto; bottom: var(--s5); background: var(--text); color: var(--bg); padding: .75rem 1.1rem;
  border-radius: var(--radius); box-shadow: var(--shadow-lg); font-weight: 500; z-index: 60; animation: toast-in .18s ease-out; }
html[dir=ltr] #toast { right: var(--s5); left: auto; }
html[dir=rtl] #toast { left: var(--s5); right: auto; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* Empty states: a muted line alone in a result box ("No orders.") is shown as a framed empty state. */
main div:not(.card):not(.row) > p.muted:only-child { text-align: center; padding: var(--s6) var(--s4); margin: 0 0 var(--s4);
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--muted); }

/* Loading state: shown while a screen has put nothing on the page yet. */
main#main:empty::before, .loading-state { content: ""; display: block; height: 4px; width: 100%; max-width: 280px; margin: 20vh auto 0;
  border-radius: 99px; background: linear-gradient(90deg, var(--surface-3) 0%, var(--primary) 50%, var(--surface-3) 100%);
  background-size: 200% 100%; animation: shimmer 1.1s linear infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.skeleton { border-radius: var(--radius-sm); background: linear-gradient(90deg, var(--surface-3) 0%, var(--surface-2) 50%, var(--surface-3) 100%);
  background-size: 200% 100%; animation: shimmer 1.2s linear infinite; color: transparent !important; }

/* Error state of a whole screen (render failed). */
.state { text-align: center; padding: var(--s6) var(--s4); max-width: 520px; margin: 10vh auto; }
.state .state-icon { width: 48px; height: 48px; margin: 0 auto var(--s3); border-radius: 50%; display: grid; place-items: center;
  background: var(--danger-soft); color: var(--danger); }
.state .state-icon svg { width: 24px; height: 24px; }
.state h2 { margin: 0 0 var(--s2); }
.state p { color: var(--muted); margin: 0 0 var(--s4); }

/* ------------------------------------------------------------------ dialogs */
dialog { color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); }
dialog::backdrop, dialog.sign-dialog::backdrop { background: rgba(9, 16, 30, .5); backdrop-filter: blur(2px); }

/* ------------------------------------------------------------------ sign-in */
body:not(.signed-in) main#main { display: grid; place-items: start center; padding-top: 8vh; }
.login { width: min(420px, 100%); margin: 0 auto; }
.login.card, .login > .card, form.card.login { padding: var(--s6); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.login h1 { font-size: 1.5rem; margin-bottom: var(--s2); }
.login label { display: flex; flex-direction: column; gap: var(--s1); margin-bottom: var(--s4); font-weight: 550; color: var(--text-2); }
.login button[type=submit] { width: 100%; min-height: 42px; }
.login .row button[type=submit] { width: auto; flex: 1; }
.login-foot { text-align: center; color: var(--muted); font-size: .8rem; margin-top: var(--s4); }

/* ------------------------------------------------------------------ reporting and misc (from app.css, re-coloured) */
.editor.dirty { border-inline-start-color: var(--warning-strong); }
label.section .sec-title, section.signed h3 { color: var(--text-2); }
section.signed { border-block-start-color: var(--border); }
section.signed.addendum { background: var(--violet-soft); border-inline-start-color: color-mix(in srgb, var(--violet) 50%, transparent); }
section.signed .sig { color: var(--muted); }
img.logo { border-color: var(--border); }
.preview { border-radius: var(--radius-sm); }

/* ------------------------------------------------------------------ dashboard (js/screens/home.js) */
.dash-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s5); }
.dash-head h1 { margin: 0; }
.dash-head p { margin: var(--s1) 0 0; color: var(--muted); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: var(--s4); margin-bottom: var(--s5); }
a.kpi { position: relative; display: flex; flex-direction: column; gap: var(--s1); padding: var(--s4) var(--s5); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); text-decoration: none; box-shadow: var(--shadow-sm);
  transition: border-color .12s, box-shadow .12s, transform .12s; overflow: hidden; }
a.kpi:hover { border-color: var(--primary); box-shadow: var(--shadow); transform: translateY(-1px); }
a.kpi::before { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 4px; background: var(--tone, var(--primary)); }
.kpi .kpi-top { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.kpi .kpi-label { font-size: .84rem; font-weight: 600; color: var(--muted); }
.kpi .kpi-icon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; flex: none;
  background: var(--tone-soft, var(--primary-soft)); color: var(--tone, var(--primary)); }
.kpi .kpi-icon svg { width: 18px; height: 18px; }
.kpi .kpi-value { font-size: 2rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .kpi-sub { font-size: .82rem; color: var(--muted); }
.kpi .kpi-value.skeleton { width: 3ch; }
.kpi.tone-ok { --tone: var(--success); --tone-soft: var(--success-soft); }
.kpi.tone-warn { --tone: var(--warning-strong); --tone-soft: var(--warning-soft); }
.kpi.tone-bad { --tone: var(--danger); --tone-soft: var(--danger-soft); }
.kpi.tone-info { --tone: var(--info); --tone-soft: var(--info-soft); }
.kpi.tone-violet { --tone: var(--violet); --tone-soft: var(--violet-soft); }
.kpi.tone-bad .kpi-value { color: var(--danger); }

.dash-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: var(--s4); align-items: start; }
.dash-grid > .card { margin: 0; }
.dash-grid .card h2 { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin: 0 0 var(--s3); }
.dash-grid .card h2 a { font-size: .84rem; font-weight: 600; text-decoration: none; }
.health { list-style: none; margin: 0; padding: 0; }
.health li { display: flex; align-items: center; gap: var(--s3); padding: .6rem 0; border-bottom: 1px solid var(--border); }
.health li:last-child { border-bottom: 0; }
.health .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--muted); box-shadow: 0 0 0 3px var(--surface-3); }
.health .dot.ok { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.health .dot.warn { background: var(--warning-strong); box-shadow: 0 0 0 3px var(--warning-soft); }
.health .dot.bad { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.health .h-text { flex: 1; min-width: 0; }
.health .h-text strong { display: block; font-weight: 600; color: var(--text); }
.health a.h-text-link { flex: 1; min-width: 0; color: inherit; }
.health a.h-text-link:hover strong { color: var(--primary-text); }
.health .h-text span { color: var(--muted); font-size: .84rem; }
.bars { display: flex; flex-direction: column; gap: var(--s2); }
.bars .bar-row { display: grid; grid-template-columns: 4.5rem minmax(0, 1fr) 2.5rem; align-items: center; gap: var(--s2); font-size: .88rem; }
.bars .bar-track { height: 10px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.bars .bar-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--primary), #14b8a6); min-width: 4px; }
html[dir=rtl] .bars .bar-fill { background: linear-gradient(270deg, var(--primary), #14b8a6); }
.bars .bar-n { text-align: end; font-variant-numeric: tabular-nums; font-weight: 600; }
.quick { display: flex; flex-wrap: wrap; gap: var(--s2); }
.quick a.button svg { width: 16px; height: 16px; }
.dash-list { list-style: none; margin: 0; padding: 0; }
.dash-list li { display: flex; align-items: center; gap: var(--s3); padding: .55rem 0; border-bottom: 1px solid var(--border); }
.dash-list li:last-child { border-bottom: 0; }
.dash-list .when { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .84rem; width: 3.2rem; flex: none; }
.dash-list .what { flex: 1; min-width: 0; }
.dash-list .what span { display: block; color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-empty { color: var(--muted); padding: var(--s4) 0; text-align: center; }
.dash-stack { display: flex; flex-direction: column; gap: var(--s4); }
.dash-stack > .card { margin: 0; }

/* ------------------------------------------------------------------ RTL fixes for rules in app.css */
html[dir=rtl] header #who button { margin-left: 0; }
html[dir=rtl] .flip-rtl { transform: scaleX(-1); }
html[dir=rtl] dl.kv dd, html[dir=rtl] td, html[dir=rtl] th { text-align: start; }
/* Codes, AE titles, accession numbers and file names stay left-to-right inside Arabic text. */
html[dir=rtl] .mono, html[dir=rtl] input[type=number], html[dir=rtl] input[type=email], html[dir=rtl] input[type=url],
html[dir=rtl] input[name=aeTitle], html[dir=rtl] input[name$=Ip], html[dir=rtl] input[name=host] { direction: ltr; text-align: end; }

/* ------------------------------------------------------------------ responsive */
.side-backdrop { display: none; }
@media (max-width: 1180px) {
  :root { --side-w: 220px; }
  main#main { padding: var(--s4); }
  .topbar { padding: 0 var(--s4); }
}
@media (max-width: 960px) {
  body.signed-in .shell, html[dir=rtl] body.signed-in .shell { grid-template-columns: minmax(0, 1fr); background: none; }
  header#top { position: fixed; inset-block: 0; inset-inline-start: 0; width: 280px; height: 100%; transform: translateX(-105%);
    transition: transform .2s ease; box-shadow: var(--shadow-lg); z-index: 50; }
  html[dir=rtl] header#top { transform: translateX(105%); }
  body.nav-open header#top { transform: none; }
  body.nav-open .side-backdrop { display: block; position: fixed; inset: 0; background: rgba(9, 16, 30, .45); z-index: 40; }
  body.signed-in button.icon-btn.menu-btn { display: inline-flex; }
  .dash-grid { grid-template-columns: minmax(0, 1fr); }
  .grid2, .template-sections { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
  main#main { padding: var(--s3); }
  .card { padding: var(--s4); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); }
  .kpi .kpi-value { font-size: 1.6rem; }
  .topbar .tools .lbl { display: none; }
  .row > label { flex: 1 1 100%; }
  .row > label > input, .row > label > select { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ------------------------------------------------------------------ print: plain, light, no shell */
@media print {
  :root, :root[data-theme="dark"] { color-scheme: light; --bg: #fff; --surface: #fff; --text: #000; --text-2: #222; --muted: #555; --border: #ccc; }
  body.signed-in .shell { display: block; }
  header#top, .topbar, .side-backdrop, #critical-banner { display: none !important; }
  main#main { padding: 0; max-width: none; }
  .card { box-shadow: none; }
}
