/* حالات العيادة – one stylesheet. RTL first (logical properties), light theme first, dark by system setting. */

:root {
  color-scheme: light;
  --font: "Segoe UI", "Noto Sans Arabic", "Noto Naskh Arabic", Tahoma, system-ui, sans-serif;
  --fs-xs: 0.8125rem;
  --fs-sm: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.375rem;
  --fs-2xl: 1.75rem;
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2rem;
  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;
  --nav-w: 15.5rem;

  --bg: #f3f6f5;
  --surface: #ffffff;
  --sunken: #f6f8f7;
  --nav-bg: #e9efed;
  --text: #15232a;
  --text-2: #4b5c63;
  --line: #d9e2df;
  --line-2: #c2cfcb;
  --accent: #0a6b61;
  --accent-hover: #075a51;
  --accent-soft: #dcefeb;
  --on-accent: #ffffff;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --danger-text: #8c1d14;
  --warn-soft: #fff3dc;
  --warn-line: #efcb85;
  --warn-text: #7a3d04;
  --info-soft: #e5eefc;
  --info-text: #1d4a9e;
  --ok-soft: #e0f3e7;
  --ok-text: #155f35;
  --shadow: 0 1px 2px rgba(18, 38, 34, 0.06), 0 2px 6px rgba(18, 38, 34, 0.05);
  --shadow-lift: 0 4px 14px rgba(18, 38, 34, 0.12);
  --scrim: rgba(10, 20, 18, 0.45);

  /* case status: background, text, dot */
  --st-new-bg: #e5eefc;   --st-new-fg: #1d4a9e;   --st-new: #3a6fd8;
  --st-prep-bg: #fff1d6;  --st-prep-fg: #7a4500;  --st-prep: #d98a00;
  --st-ready-bg: #ddf3e5; --st-ready-fg: #145c33; --st-ready: #22a052;
  --st-list-bg: #eee8fd;  --st-list-fg: #4c2fb0;  --st-list: #7a5ae0;
  --st-done-bg: #eaeef1;  --st-done-fg: #46535c;  --st-done: #7d8b95;
  --st-fu-bg: #dcf2f6;    --st-fu-fg: #0c5d6c;    --st-fu: #1595ad;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0e1416;
    --surface: #162024;
    --sunken: #121a1d;
    --nav-bg: #111a1c;
    --text: #e3ebe9;
    --text-2: #a6b6b3;
    --line: #263438;
    --line-2: #35474b;
    --accent: #4ec3b4;
    --accent-hover: #6fd3c6;
    --accent-soft: #143430;
    --on-accent: #04241f;
    --danger: #ff8a7e;
    --danger-soft: #3a1a18;
    --danger-text: #ffc4bd;
    --warn-soft: #33270f;
    --warn-line: #6b5120;
    --warn-text: #f6d38f;
    --info-soft: #172a47;
    --info-text: #b5cdfa;
    --ok-soft: #12301f;
    --ok-text: #a6e3bd;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-lift: 0 6px 18px rgba(0, 0, 0, 0.45);
    --scrim: rgba(0, 0, 0, 0.6);
    --st-new-bg: #172a47;   --st-new-fg: #b5cdfa;   --st-new: #6f9cf0;
    --st-prep-bg: #34260c;  --st-prep-fg: #f6d38f;  --st-prep: #e6a52a;
    --st-ready-bg: #12301f; --st-ready-fg: #a6e3bd; --st-ready: #43c374;
    --st-list-bg: #261d45;  --st-list-fg: #cfc2fb;  --st-list: #9a80f0;
    --st-done-bg: #222b31;  --st-done-fg: #b9c4cb;  --st-done: #8696a1;
    --st-fu-bg: #0f2f36;    --st-fu-fg: #a5e0ea;    --st-fu: #3cb8cf;
  }
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { font-size: 100%; -webkit-text-size-adjust: 100%; scrollbar-color: var(--line-2) transparent; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.7;
  accent-color: var(--accent);
  caret-color: var(--accent);
}

::selection { background: var(--accent-soft); color: var(--text); }

a { color: var(--accent); text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-hover); }

h1, h2, h3 { line-height: 1.35; text-wrap: balance; }
h1 { margin: 0; font-size: var(--fs-xl); font-weight: 700; }
h2 { margin: var(--s5) 0 var(--s3); font-size: var(--fs-lg); font-weight: 700; }
h3 { margin: var(--s4) 0 var(--s2); font-size: var(--fs-md); }
p { margin: 0 0 var(--s3); }
ul, ol { margin: 0 0 var(--s3); padding-inline-start: 1.25rem; }
s, .undone { color: var(--text-2); }
.undone { text-decoration: line-through; }
[dir="ltr"] { unicode-bidi: isolate; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.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;
}

.skip {
  position: absolute; inset-inline-start: var(--s3); top: -4rem; z-index: 50;
  padding: var(--s2) var(--s4); background: var(--accent); color: var(--on-accent); border-radius: var(--r);
}
.skip:focus { top: var(--s3); color: var(--on-accent); }

.muted, .privacy { color: var(--text-2); }

/* ---------- shell ---------- */

.topbar {
  position: sticky; top: 0; z-index: 15;
  display: flex; align-items: center; gap: var(--s3);
  min-height: 3.5rem; padding: var(--s2) var(--s4);
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { margin: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .logout { margin-inline-start: auto; }

button.icon-btn {
  margin: 0; min-height: 44px; padding: var(--s2) var(--s3);
  color: var(--text); background: transparent; border: 1px solid var(--line); font-weight: 600;
}
button.icon-btn:hover { background: var(--sunken); color: var(--text); border-color: var(--line-2); }
.icon { width: 1.25rem; height: 1.25rem; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.sidebar {
  position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 30;
  display: flex; flex-direction: column;
  width: min(var(--nav-w), 85vw);
  background: var(--nav-bg); border-inline-end: 1px solid var(--line);
  transform: translateX(100%); visibility: hidden;
  transition: transform 200ms cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s 200ms;
}
.nav-open .sidebar { transform: none; visibility: visible; transition-delay: 0s; box-shadow: var(--shadow-lift); }
.scrim { position: fixed; inset: 0; z-index: 25; background: var(--scrim); }
.scrim[hidden] { display: none; }
.nav-open body { overflow: hidden; }

.sidebar-head { display: flex; align-items: center; gap: var(--s2); padding: var(--s4) var(--s4) var(--s2); }
.sidebar-head .brand { flex: 1; font-size: var(--fs-lg); white-space: normal; }
.sidebar nav { flex: 1; overflow-y: auto; padding: 0 var(--s3) var(--s4); }
.nav-title { margin: var(--s4) var(--s3) var(--s1); font-size: var(--fs-xs); font-weight: 700; color: var(--text-2); }
.sidebar ul { margin: 0; padding: 0; list-style: none; }
.sidebar nav a {
  display: flex; align-items: center; gap: var(--s2);
  min-height: 2.6rem; padding: var(--s1) var(--s3); margin-block: 1px;
  color: var(--text); text-decoration: none; border-radius: var(--r-sm);
}
.sidebar nav a:hover { background: var(--surface); color: var(--text); }
.sidebar nav a[aria-current="page"] { background: var(--surface); color: var(--accent); font-weight: 700; box-shadow: var(--shadow); }
.count {
  margin-inline-start: auto; min-width: 1.6rem; padding: 0 var(--s2);
  font-size: var(--fs-xs); font-weight: 700; line-height: 1.6rem; text-align: center;
  font-variant-numeric: tabular-nums; color: var(--warn-text); background: var(--warn-soft);
  border: 1px solid var(--warn-line); border-radius: 999px;
}
.sidebar-foot {
  display: flex; align-items: center; gap: var(--s2); padding: var(--s3) var(--s4);
  border-top: 1px solid var(--line); font-size: var(--fs-sm);
}
.sidebar-foot .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--text-2); }
.sidebar-foot form, .logout { margin: 0; }
.sidebar-foot button, .logout button { margin: 0; }

.main-wrap { min-width: 0; }
.notices { display: grid; gap: var(--s2); margin: var(--s4) var(--s4) 0; max-width: 90rem; }
.notices:not(:has(*)) { display: none; }

main { padding: var(--s4) var(--s4) var(--s6); max-width: 52rem; }
main.wide { max-width: 90rem; }
main.narrow { max-width: 28rem; margin-inline: auto; padding-top: 10vh; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s4); margin-bottom: var(--s4); }
.page-head p { margin: 0; color: var(--text-2); }
.page-head .actions { margin-inline-start: auto; }
.back { display: inline-block; margin-bottom: var(--s2); font-size: var(--fs-sm); }

@media (min-width: 60rem) {
  body.has-nav { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); }
  .has-nav .topbar, .has-nav .scrim, .nav-close { display: none; }
  .has-nav .sidebar {
    position: sticky; top: 0; height: 100vh; width: auto;
    transform: none; visibility: visible; transition: none; box-shadow: none;
  }
  .nav-open body { overflow: auto; }
  main { padding: var(--s5) var(--s6) var(--s6); }
  .notices { margin: var(--s5) var(--s6) 0; }
}

/* ---------- surfaces ---------- */

.card {
  margin: 0 0 var(--s4); padding: var(--s4) var(--s5);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow);
}
.card > h2:first-child, .card > form > h2:first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }

.alert, .error, .flash {
  margin: 0 0 var(--s3); padding: var(--s3) var(--s4);
  border: 1px solid transparent; border-radius: var(--r); font-weight: 600;
}
.alert-danger, .error { color: var(--danger-text); background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.alert-warn, p.notice { color: var(--warn-text); background: var(--warn-soft); border-color: var(--warn-line); }
.flash, .alert-ok { color: var(--ok-text); background: var(--ok-soft); }
.notices .alert { margin: 0; }
.alert a { color: inherit; }
span.error { display: block; margin-top: var(--s1); padding: var(--s1) var(--s3); }

.rows { margin: 0 0 var(--s4); padding: 0; list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); }
.rows > li { padding: var(--s3) var(--s4); }
.rows > li + li { border-top: 1px solid var(--line); }
.rows p { margin: 0; }
.meta { color: var(--text-2); font-size: var(--fs-sm); }
.row-main { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s1) var(--s3); }
.row-main .title { font-weight: 700; }
.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin-top: var(--s2); }
.row-actions form { margin: 0; }
.empty { margin: 0 0 var(--s4); padding: var(--s4); color: var(--text-2); background: var(--sunken); border: 1px dashed var(--line-2); border-radius: var(--r-lg); }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: var(--s3) var(--s5); margin: 0 0 var(--s4); }
.facts div { min-width: 0; }
.facts dt { font-size: var(--fs-sm); color: var(--text-2); }
.facts dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.facts .full { grid-column: 1 / -1; }
.facts p { margin: 0; overflow-wrap: anywhere; }

/* ---------- badges and chips ---------- */

.badge, .chip {
  display: inline-flex; align-items: center; gap: 0.4em;
  padding: 0.05rem 0.6rem; font-size: var(--fs-sm); font-weight: 600; line-height: 1.6;
  border-radius: 999px; white-space: nowrap;
}
.badge { color: var(--st-c-fg, var(--text-2)); background: var(--st-c-bg, var(--sunken)); }
.badge::before, .col-head::before { content: ""; width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--st-c, var(--text-2)); flex: none; }
.st-new { --st-c-bg: var(--st-new-bg); --st-c-fg: var(--st-new-fg); --st-c: var(--st-new); }
.st-preparing { --st-c-bg: var(--st-prep-bg); --st-c-fg: var(--st-prep-fg); --st-c: var(--st-prep); }
.st-ready { --st-c-bg: var(--st-ready-bg); --st-c-fg: var(--st-ready-fg); --st-c: var(--st-ready); }
.st-listed { --st-c-bg: var(--st-list-bg); --st-c-fg: var(--st-list-fg); --st-c: var(--st-list); }
.st-done, .st-archived { --st-c-bg: var(--st-done-bg); --st-c-fg: var(--st-done-fg); --st-c: var(--st-done); }
.st-followup { --st-c-bg: var(--st-fu-bg); --st-c-fg: var(--st-fu-fg); --st-c: var(--st-fu); }
.badge.danger { --st-c-bg: var(--danger-soft); --st-c-fg: var(--danger-text); --st-c: var(--danger); }
.badge.ok { --st-c-bg: var(--ok-soft); --st-c-fg: var(--ok-text); --st-c: var(--st-ready); }

.chips { display: flex; flex-wrap: wrap; gap: var(--s1); margin: 0; padding: 0; list-style: none; }
.chip { font-size: var(--fs-xs); white-space: normal; border: 1px solid transparent; }
.tone-warn { color: var(--warn-text); background: var(--warn-soft); border-color: var(--warn-line); }
.tone-muted { color: var(--text-2); background: var(--sunken); border-color: var(--line); }
.tone-info { color: var(--info-text); background: var(--info-soft); }
.tone-danger { color: var(--danger-text); background: var(--danger-soft); }

/* ---------- forms ---------- */

label { display: block; margin: var(--s3) 0 var(--s1); font-weight: 600; font-size: var(--fs-sm); }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="time"],
input[type="email"], input[type="tel"], input[type="url"], textarea, select {
  display: block; width: 100%; min-height: 44px; padding: 0.55rem 0.8rem;
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line-2); border-radius: var(--r);
  transition: border-color 150ms, box-shadow 150ms;
}
textarea { min-height: 6rem; resize: vertical; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input:disabled, select:disabled, textarea:disabled { color: var(--text-2); background: var(--sunken); cursor: not-allowed; }
input[type="checkbox"], input[type="radio"] { width: 1.15rem; height: 1.15rem; margin: 0; flex: none; }
::placeholder { color: var(--text-2); opacity: 1; }

label.choice, .choices label {
  display: inline-flex; align-items: center; gap: var(--s2);
  margin: 0; padding: var(--s2) var(--s3); min-height: 44px;
  font-weight: 500; font-size: var(--fs-md);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); cursor: pointer;
}
label.choice:has(input:checked), .choices label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
label.choice:has(input:disabled), .choices label:has(input:disabled) { cursor: default; }
.choices { display: flex; flex-wrap: wrap; gap: var(--s2); }
.stack { display: grid; gap: var(--s2); justify-items: start; }

fieldset { margin: var(--s4) 0 0; padding: 0; border: 0; min-width: 0; }
legend { margin-bottom: var(--s2); padding: 0; font-weight: 600; font-size: var(--fs-sm); }

.form-grid { display: grid; gap: 0 var(--s4); }
@media (min-width: 40rem) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid .full { grid-column: 1 / -1; }
}
.help { margin: var(--s1) 0 0; font-size: var(--fs-sm); color: var(--text-2); }
.inline-form { display: flex; flex-wrap: wrap; align-items: end; gap: var(--s2) var(--s3); }
.inline-form > div { flex: 1 1 12rem; }
.inline-form label { margin-top: 0; }
.inline-form button { margin: 0; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin-top: var(--s4); }
.form-actions button, .form-actions p { margin: 0; }
.sticky-actions {
  position: sticky; bottom: 0; z-index: 5; margin: var(--s4) 0 0; padding: var(--s3) 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent); border-top: 1px solid var(--line);
}

/* ---------- buttons ---------- */

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  margin-top: var(--s4); min-height: 44px; padding: 0.5rem 1.1rem;
  font: inherit; font-weight: 700; line-height: 1.3; text-decoration: none;
  color: var(--on-accent); background: var(--accent);
  border: 1px solid var(--accent); border-radius: var(--r); cursor: pointer;
  transition: background-color 150ms, border-color 150ms, color 150ms;
}
button:hover, .btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.btn-quiet, .btn-quiet { color: var(--text); background: var(--surface); border-color: var(--line-2); font-weight: 600; }
button.btn-quiet:hover, .btn-quiet:hover { color: var(--text); background: var(--sunken); border-color: var(--text-2); }
button.btn-danger { color: var(--danger); background: var(--surface); border-color: color-mix(in srgb, var(--danger) 55%, transparent); font-weight: 600; }
button.btn-danger:hover { color: #fff; background: var(--danger); border-color: var(--danger); }
button.btn-sm, .btn-sm { min-height: 36px; padding: 0.3rem 0.8rem; font-size: var(--fs-sm); }
.row-actions button, .sticky-actions button { margin-top: 0; }

/* ---------- tabs ---------- */

.tabs {
  display: flex; flex-wrap: wrap; gap: 0 var(--s1); margin: 0 0 var(--s4);
  border-bottom: 1px solid var(--line);
}
.tabs[hidden] { display: none; }
.tabs button {
  margin: 0 0 -1px; min-height: 44px; padding: var(--s2) var(--s4);
  color: var(--text-2); background: transparent; border: 0; border-radius: 0;
  font-weight: 600; white-space: nowrap;
}
.tabs button:hover { color: var(--text); background: var(--sunken); box-shadow: inset 0 -2px 0 var(--line-2); }
.tabs button[aria-selected="true"] { color: var(--accent); background: transparent; box-shadow: inset 0 -3px 0 var(--accent); }
.tabs .n { font-size: var(--fs-xs); color: var(--text-2); font-variant-numeric: tabular-nums; }
.tabs-ready > [role="tabpanel"]:not(.is-active) { display: none; }
.tabs-ready > [role="tabpanel"] > .tab-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[role="tabpanel"]:focus-visible { outline-offset: 4px; border-radius: var(--r); }

/* ---------- tables (cards on phones) ---------- */

.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: var(--s3) var(--s4); text-align: start; vertical-align: top; border-bottom: 1px solid var(--line); }
th { font-size: var(--fs-sm); font-weight: 700; color: var(--text-2); background: var(--sunken); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--sunken); }
td a { font-weight: 700; }

@media (max-width: 47.99rem) {
  .table-cards { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  .table-cards thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table-cards tr {
    display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2) var(--s3); margin-bottom: var(--s3); padding: var(--s3) var(--s4);
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow);
  }
  .table-cards td { padding: 0; border: 0; min-width: 0; overflow-wrap: anywhere; }
  .table-cards tbody tr:hover td { background: none; }
  .table-cards td[data-label]::before { content: attr(data-label); display: block; font-size: var(--fs-xs); color: var(--text-2); }
  .table-cards td.lead, .table-cards td.span { grid-column: 1 / -1; }
  .table-cards td.lead { font-size: var(--fs-lg); }
  .table-cards td:empty { display: none; }
}

/* ---------- home ---------- */

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: var(--s3); margin: 0 0 var(--s5); padding: 0; list-style: none; }
.tile {
  display: flex; flex-direction: column; gap: 2px; height: 100%; padding: var(--s3) var(--s4);
  color: var(--text); text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow);
  transition: border-color 150ms, box-shadow 150ms;
}
.tile:hover { color: var(--text); border-color: var(--line-2); box-shadow: var(--shadow-lift); }
.tile .label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
.tile .value { font-size: var(--fs-2xl); font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: var(--fs-xs); color: var(--text-2); }
.tile.hot { border-color: var(--warn-line); background: linear-gradient(var(--warn-soft), var(--warn-soft)) top / 100% 4px no-repeat, var(--surface); }
.tile.hot .value { color: var(--warn-text); }
.tile.good .value { color: var(--st-ready-fg); }

.board { display: grid; gap: var(--s3); align-items: start; }
.board > .tabs { grid-column: 1 / -1; margin-bottom: 0; }
@media (min-width: 40rem) {
  .board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .board > .tabs { display: none; }
  .board.tabs-ready > [role="tabpanel"]:not(.is-active) { display: block; }
}
@media (min-width: 75rem) { .board { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 39.99rem) {
  .board.tabs-ready .col-head { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .board > .tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; overflow: visible; }
  .board > .tabs button { flex-direction: column; gap: 0; padding: var(--s2) var(--s1); font-size: var(--fs-sm); white-space: normal; line-height: 1.3; }
  .board > .tabs[hidden] { display: none; }
}
.col { min-width: 0; padding: var(--s3); background: var(--sunken); border: 1px solid var(--line); border-radius: var(--r-lg); }
.col-head { display: flex; align-items: center; gap: var(--s2); margin: 0 0 var(--s3); padding: 0 var(--s1); font-size: var(--fs-md); }
.col-head a { color: inherit; text-decoration: none; }
.col-head a:hover { text-decoration: underline; }
.col ul { display: grid; gap: var(--s2); margin: 0; padding: 0; list-style: none; }
.col .empty { margin: 0; padding: var(--s3); font-size: var(--fs-sm); text-align: center; }

.case-card {
  position: relative; display: grid; gap: var(--s1); padding: var(--s3);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow);
  transition: border-color 150ms, box-shadow 150ms;
}
.case-card:hover { border-color: var(--line-2); box-shadow: var(--shadow-lift); }
.case-card h4 { margin: 0; font-size: var(--fs-md); }
.case-card h4 a { color: var(--text); text-decoration: none; }
.case-card h4 a::after { content: ""; position: absolute; inset: 0; border-radius: var(--r); }
.case-card h4 a:focus-visible { outline: none; }
.case-card:has(a:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.case-card .meta { margin: 0; overflow-wrap: anywhere; }
.case-card .foot { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s1); }
.case-card .foot .chips { display: contents; }
.case-card .photos { margin-inline-end: var(--s1); }
.photos { display: inline-flex; align-items: center; gap: 0.3em; font-size: var(--fs-sm); color: var(--text-2); font-variant-numeric: tabular-nums; }
.photos .icon { width: 1rem; height: 1rem; }

.closed { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); margin: var(--s4) 0; padding: 0; list-style: none; font-size: var(--fs-sm); color: var(--text-2); }
.cost { margin: 0 0 var(--s3); font-weight: 700; }

/* ---------- case page ---------- */

.case-head { display: grid; gap: var(--s2); margin-bottom: var(--s4); }
.case-head .line { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); }
.case-head .actions { display: flex; flex-wrap: wrap; gap: var(--s2); }
.case-head form { margin: 0; }
.case-head button { margin: 0; }
.history { white-space: pre-line; }
details.edit { margin-top: var(--s4); }
details.edit > summary { display: flex; align-items: center; min-height: 44px; cursor: pointer; font-weight: 700; color: var(--accent); }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr)); gap: var(--s2); }
button.thumb, a.thumb {
  display: block; margin: 0; padding: 0; min-height: 0; aspect-ratio: 1; overflow: hidden;
  background: var(--sunken); border: 1px solid var(--line); border-radius: var(--r);
}
button.thumb:hover, a.thumb:hover { background: var(--sunken); border-color: var(--accent); }
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
a.thumb { width: 9rem; max-width: 100%; margin-bottom: var(--s3); }
.retry-note { display: block; font-size: var(--fs-xs); color: var(--text-2); }

#viewer[hidden] { display: none; }
#viewer { position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; background: rgba(8, 12, 14, 0.94); }
.viewer-stage { flex: 1; overflow: hidden; touch-action: none; display: flex; align-items: center; justify-content: center; }
#viewer-img { max-width: 92%; max-height: 78vh; transform-origin: 0 0; cursor: grab; }
.viewer-tools { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--s2); padding: var(--s3); }
.viewer-tools button { margin: 0; }

.timeline { margin: 0; padding: 0; list-style: none; }
.timeline li { position: relative; padding-inline-start: var(--s5); padding-bottom: var(--s3); }
.timeline li::before { content: ""; position: absolute; inset-inline-start: 0.3rem; top: 0.6rem; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--accent); }
.timeline li::after { content: ""; position: absolute; inset-inline-start: calc(0.55rem - 1px); top: 1.3rem; bottom: 0; width: 2px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline .meta { display: block; }
.sub-list { margin: var(--s2) 0 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: var(--s1) var(--s3); font-size: var(--fs-sm); color: var(--text-2); }

/* ---------- misc pages ---------- */

.tray-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: var(--s4); align-items: start; }
.tray-grid .card { margin: 0; }
.link-grid { display: grid; gap: var(--s4); align-items: start; }
@media (min-width: 64rem) { .link-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .link-grid .card { margin: 0; } }
.alert.row-main form { margin: 0; margin-inline-start: auto; }
.alert.row-main button { margin: 0; }
.code-line { padding: var(--s2) var(--s3); background: var(--sunken); border: 1px solid var(--line); border-radius: var(--r); overflow-wrap: anywhere; font-size: var(--fs-sm); }
button.block { width: 100%; }
.inline-form + .inline-form, .row-actions + .inline-form { margin-top: var(--s3); }

img.qr { display: block; width: 220px; max-width: 100%; height: auto; margin: var(--s2) 0 var(--s4); padding: var(--s2); background: #fff; border-radius: var(--r); }
.code, .has-code strong { font-size: var(--fs-xl); font-weight: 700; letter-spacing: 0.08em; font-variant-numeric: tabular-nums; }
.steps { margin: 0 0 var(--s3); padding-inline-start: 1.25rem; }
.login-brand { margin-bottom: var(--s5); text-align: center; }
.login-brand p { margin: 0; color: var(--text-2); }
.entry-num { display: inline-grid; place-items: center; min-width: 1.9rem; height: 1.9rem; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 50%; font-variant-numeric: tabular-nums; }
details.more > summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: var(--fs-sm); min-height: 36px; display: flex; align-items: center; }
details.more[open] { padding-bottom: var(--s2); }

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

@media print {
  .sidebar, .topbar, .scrim, .tabs, .notices, button { display: none !important; }
  body.has-nav { display: block; }
  .tabs-ready > [role="tabpanel"]:not(.is-active) { display: block; }
}

/* Groups page */
.group-search { display: grid; gap: var(--space-2, .5rem); margin-block-end: var(--space-4, 1rem); }
.group-search input[type=search] { inline-size: 100%; max-inline-size: 32rem; }
.group-list { display: grid; gap: var(--space-2, .5rem); }
.group-row { padding-block: var(--space-3, .75rem); }
.group-row-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3, .75rem); }
.group-name { font-weight: 600; }
.group-settings summary { cursor: pointer; color: var(--muted, #667); margin-block-start: var(--space-2, .5rem); }
