/* Thira Diagnostics. Palette taken from the stains themselves:
   glass = slide glass, dab = DAB chromogen (IHC brown), hema = hematoxylin, eosin = eosin. */
:root {
  color-scheme: light;
  --glass: #F2F5F6;
  --surface: #FFFFFF;
  --frost: #E3E9EC;
  --ink: #1D2733;
  --muted: #5B6673;
  --rule: #D5DCE2;
  --dab: #7A4A1E;
  --dab-ink: #FFFFFF;
  --dab-soft: #F4E9DE;
  --hema: #34407A;
  --hema-soft: #E7E9F5;
  --eosin: #B8326A;
  --eosin-soft: #F8E4EC;
  --ok: #2E7048;
  --ok-soft: #E2F0E7;
  --bad: #A8261B;
  --bad-soft: #F8E2DF;
  --warn: #8A5A00;
  --warn-soft: #FBF0D9;
  --radius: 6px;
  --font: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --code: "Atkinson Hyperlegible Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --glass: #151A1F; --surface: #1C2329; --frost: #252E36; --ink: #E5EAEE; --muted: #9AA5B0; --rule: #33404B;
    --dab: #C68D57; --dab-ink: #1A1206; --dab-soft: #3A2A1B; --hema: #A3ADEB; --hema-soft: #262B47;
    --eosin: #EE7FA9; --eosin-soft: #46202F; --ok: #74C495; --ok-soft: #1E3628; --bad: #F08A80; --bad-soft: #43201D;
    --warn: #E3B45C; --warn-soft: #3D3018;
  }
}
*, *::before, *::after { box-sizing: inherit; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--glass); color: var(--ink); font-family: var(--font);
  font-size: 15px; line-height: 1.45; font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--hema); text-underline-offset: 2px; }
h1 { font-size: 1.5rem; line-height: 1.2; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin: 1.6rem 0 .6rem; font-weight: 700; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; font-weight: 600; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.code { font-family: var(--code); font-size: .92em; letter-spacing: .01em; }
:focus-visible { outline: 3px solid var(--hema); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100%; }
.rail { background: var(--surface); border-right: 1px solid var(--rule); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 0 8px 16px; }
.brand-mark { width: 30px; height: 15px; border-radius: 2px; background: linear-gradient(90deg, var(--dab) 0 30%, var(--frost) 30%); border: 1px solid var(--hema); flex: none; }
.brand b { display: block; font-size: 1rem; }
.brand small { color: var(--muted); font-size: .8rem; }
.nav-group { margin: 14px 0 4px; padding: 0 8px; color: var(--muted); font-size: .8rem; }
.rail a.nav { display: flex; justify-content: space-between; padding: 7px 10px; border-radius: var(--radius); color: var(--ink); text-decoration: none; }
.rail a.nav:hover { background: var(--frost); }
.rail a.nav[aria-current="page"] { background: var(--dab-soft); color: var(--dab); font-weight: 600; }
.rail .who { margin-top: 20px; padding: 12px 8px 0; border-top: 1px solid var(--rule); font-size: .85rem; color: var(--muted); }
.main { min-width: 0; padding: 18px 28px 60px; }
.page-head { display: flex; gap: 16px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; margin: 20px 0 14px; }
.page-head .sub { color: var(--muted); margin-top: 4px; }

/* ---------- the scan bar: a glass slide with a frosted label end ---------- */
.scanbar { display: flex; align-items: stretch; max-width: 920px; height: 56px; border: 1.5px solid var(--hema); border-radius: 3px; background: var(--surface); box-shadow: 0 1px 0 var(--rule); }
.scanbar .frost {
  flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 0 12px;
  background: repeating-linear-gradient(135deg, var(--frost) 0 3px, transparent 3px 6px), var(--frost);
  border-right: 1.5px solid var(--hema); color: var(--hema); font-weight: 700;
}
.scanbar .frost select { border: 0; background: transparent; color: var(--ink); font: inherit; font-weight: 600; padding: 4px 2px; }
.scanbar input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 0 16px; font: 600 1.15rem var(--code); color: var(--ink); letter-spacing: .03em; }
.scanbar input::placeholder { font-family: var(--font); font-weight: 400; color: var(--muted); letter-spacing: 0; }
.scanbar input:focus { outline: none; }
.scanbar:focus-within { box-shadow: 0 0 0 3px var(--hema-soft); }
.scanbar .hint { align-self: center; padding: 0 14px; color: var(--muted); font-size: .8rem; white-space: nowrap; }

/* ---------- content blocks ---------- */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.kv { display: grid; grid-template-columns: 9.5rem 1fr; gap: 4px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 10px; }

/* tables */
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: .85rem; border-bottom: 1.5px solid var(--ink); padding: 6px 10px 6px 0; white-space: nowrap; }
td { border-bottom: 1px solid var(--rule); padding: 8px 10px 8px 0; vertical-align: top; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--glass); }
tr.selected td { background: var(--hema-soft); }
tr.flash td { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: var(--dab-soft); } to { background: transparent; } }
td.num, th.num { text-align: right; }

/* status, priority */
.status { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--hema); }
.status.s-REPORTED::before { background: var(--ok); }
.status.s-CLOSED_REJECTED::before, .status.s-REJ_SIGNOFF::before, .status.s-REJ_CONTACT::before { background: var(--bad); }
.status.s-INFO_PENDING::before { background: var(--warn); }
.status.s-BENCH::before, .status.s-ACCESSIONED::before { background: var(--dab); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .8rem; font-weight: 600; background: var(--frost); color: var(--ink); white-space: nowrap; }
.tag.urgent { background: var(--eosin-soft); color: var(--eosin); }
.tag.out { background: var(--hema-soft); color: var(--hema); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }

/* forms */
label.f { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }
label.f > span.req::after { content: " *"; color: var(--eosin); }
.f small { color: var(--muted); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 8px 10px; min-height: 40px; }
textarea { min-height: 84px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { min-height: 0; width: 18px; height: 18px; accent-color: var(--dab); }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; }
.form .wide { grid-column: 1 / -1; }
.choices { display: flex; gap: 6px; flex-wrap: wrap; }
.choice { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--rule); border-radius: var(--radius); color: var(--ink); cursor: pointer; background: var(--surface); }
.choice:has(input:checked) { border-color: var(--dab); background: var(--dab-soft); }
.choice.disabled { opacity: .5; cursor: not-allowed; }
fieldset { border: 0; margin: 0; padding: 0; }
legend { color: var(--muted); font-size: .9rem; margin-bottom: 6px; padding: 0; }

/* buttons */
button, .btn { font: inherit; font-weight: 600; border-radius: var(--radius); padding: 8px 14px; min-height: 40px; cursor: pointer; border: 1px solid var(--rule); background: var(--surface); color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: var(--muted); }
button.primary { background: var(--dab); color: var(--dab-ink); border-color: var(--dab); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); border-color: var(--bad); }
button.link { border: 0; background: none; color: var(--hema); padding: 0 2px; min-height: 0; text-decoration: underline; text-underline-offset: 2px; font-weight: 400; }
button:disabled { opacity: .55; cursor: progress; }
button.small { min-height: 32px; padding: 4px 10px; font-size: .9rem; }

/* action panel on the case page */
.action { border-left: 4px solid var(--dab); }
.action h2 { color: var(--dab); }

/* scan result drawer */
.drawer { position: fixed; right: 0; top: 0; bottom: 0; width: min(440px, 100%); background: var(--surface); border-left: 1.5px solid var(--hema); box-shadow: -12px 0 30px rgba(20, 30, 50, .12); padding: calc(env(safe-area-inset-top, 0px) + 18px) 20px 24px; overflow-y: auto; z-index: 20; transform: translateX(0); transition: transform .18s ease-out; }
.drawer[hidden] { display: block; transform: translateX(105%); visibility: hidden; }
.drawer .close { position: absolute; right: 14px; top: calc(env(safe-area-inset-top, 0px) + 14px); }
.drawer .bc { font: 600 1.05rem var(--code); word-break: break-all; color: var(--hema); }
.warning { background: var(--warn-soft); color: var(--warn); border-radius: var(--radius); padding: 8px 10px; font-weight: 600; }

/* toasts */
#toasts { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 18px); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 40; width: min(520px, calc(100% - 24px)); }
.toast { background: var(--ink); color: var(--surface); padding: 10px 14px; border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.bad { background: var(--bad); color: #fff; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login .panel { width: min(420px, 100%); padding: 28px; }
.login .slide { height: 44px; border: 1.5px solid var(--hema); border-radius: 3px; display: flex; margin-bottom: 20px; }
.login .slide i { width: 34%; background: repeating-linear-gradient(135deg, var(--frost) 0 3px, transparent 3px 6px), var(--frost); border-right: 1.5px solid var(--hema); }
.login .slide b { flex: 1; display: flex; align-items: center; padding-left: 14px; font-size: 1.05rem; }

/* dashboard bars */
.bar { position: relative; height: 12px; background: var(--frost); border-radius: 2px; min-width: 120px; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--dab); border-radius: 2px; }
.bar b { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--hema); }
.stacked { display: flex; height: 12px; border-radius: 2px; overflow: hidden; min-width: 140px; background: var(--frost); }
.stacked span:nth-child(1) { background: var(--ok); } .stacked span:nth-child(2) { background: var(--hema); }
.stacked span:nth-child(3) { background: var(--warn); } .stacked span:nth-child(4) { background: var(--eosin); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.big { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.stats { display: flex; gap: 32px; flex-wrap: wrap; }
.stats > div small { display: block; color: var(--muted); }

.empty { color: var(--muted); padding: 18px 0; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: sticky; top: 0; height: auto; display: flex; gap: 4px; overflow-x: auto; padding: 8px; border-right: 0; border-bottom: 1px solid var(--rule); z-index: 10; }
  .rail .brand, .rail .nav-group, .rail .who { display: none; }
  .rail a.nav { white-space: nowrap; }
  .main { padding: 12px 14px 60px; }
  .scanbar { height: 52px; }
  .scanbar .hint { display: none; }
  .kv { grid-template-columns: 7.5rem 1fr; }
}
@media print { .rail, .scanbar, #toasts, .drawer { display: none !important; } .shell { display: block; } }

/* refinements after screen review */
.panel textarea, .action textarea { width: 100%; }
td.code, .kv .code { white-space: nowrap; }
.kv dd .status { white-space: normal; }
.drawer .kv { grid-template-columns: 7.5rem 1fr; }
[hidden]:not(.drawer) { display: none !important; }
.form input:not([type="checkbox"]):not([type="radio"]), .form select { width: 100%; }
