/* RadAssist — "reading room" layout: dark navigation rail like a PACS workstation,
   bright, calm workspace for reports and billing. Teal accent; semantic colours separate. */
@font-face { font-family: "Inter"; src: url("/fonts/inter.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Jakarta"; src: url("/fonts/jakarta.woff2") format("woff2"); font-weight: 200 800; font-display: swap; }

:root {
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Jakarta", "Inter", system-ui, sans-serif;

  --bg: #f3f6f8;          /* workspace */
  --surface: #ffffff;     /* cards */
  --surface-2: #f7f9fb;   /* inputs, table heads */
  --ink: #0f1d26;
  --ink-2: #3c4d59;
  --muted: #6a7c88;
  --line: #e1e8ed;
  --line-strong: #cdd7de;

  --accent: #0b7f8c;      /* teal */
  --accent-ink: #ffffff;
  --accent-soft: #e2f3f4;
  --accent-strong: #08656f;

  --rail: #0e1a21;        /* navigation rail */
  --rail-2: #16252e;
  --rail-ink: #c3d1d9;
  --rail-muted: #7f939f;

  --ok: #13804f;  --ok-soft: #e1f4ea;
  --warn: #a35f00; --warn-soft: #fcefd9;
  --bad: #c2352f;  --bad-soft: #fbe6e5;
  --info: #3159c8; --info-soft: #e7edfc;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 29, 38, .05);
  --shadow-lg: 0 18px 50px rgba(15, 29, 38, .18);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1318; --surface: #111c23; --surface-2: #0e181e;
    --ink: #e4ecf0; --ink-2: #b6c5ce; --muted: #8094a0; --line: #1f2e37; --line-strong: #2b3d48;
    --accent: #2fb5c2; --accent-ink: #04181b; --accent-soft: #0f2c31; --accent-strong: #5fcbd5;
    --rail: #070e12; --rail-2: #0f1a20; --rail-ink: #c3d1d9; --rail-muted: #7f939f;
    --ok: #45c486; --ok-soft: #0f2a1d; --warn: #e6a63e; --warn-soft: #2c2210; --bad: #f2736c; --bad-soft: #321716;
    --info: #7b9cf2; --info-soft: #172242;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 18px 50px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1318; --surface: #111c23; --surface-2: #0e181e;
  --ink: #e4ecf0; --ink-2: #b6c5ce; --muted: #8094a0; --line: #1f2e37; --line-strong: #2b3d48;
  --accent: #2fb5c2; --accent-ink: #04181b; --accent-soft: #0f2c31; --accent-strong: #5fcbd5;
  --rail: #070e12; --rail-2: #0f1a20; --rail-ink: #c3d1d9; --rail-muted: #7f939f;
  --ok: #45c486; --ok-soft: #0f2a1d; --warn: #e6a63e; --warn-soft: #2c2210; --bad: #f2736c; --bad-soft: #321716;
  --info: #7b9cf2; --info-soft: #172242;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 18px 50px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--font-display); text-wrap: balance; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 15px; font-weight: 700; margin: 0 0 12px; }
h3 { font-family: var(--font); font-size: 11px; font-weight: 600; margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num, .mono { font-variant-numeric: tabular-nums; }

/* ---------- Top progress bar (shown while any request is in flight) ---------- */
#progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 100; pointer-events: none; opacity: 0; transition: opacity .2s; }
#progress.on { opacity: 1; }
#progress::before { content: ""; position: absolute; inset: 0; width: 40%; background: linear-gradient(90deg, transparent, var(--accent), transparent); animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(260%); } }

/* ---------- Shell ---------- */
.layout { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--rail); color: var(--rail-ink); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; color: #fff; font: 700 17px var(--font-display); letter-spacing: -.01em; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(140deg, #19a7b5, #0b6f7b); display: grid; place-items: center; box-shadow: inset 0 0 0 1px rgba(255,255,255,.15); }
.brand-mark svg { width: 18px; height: 18px; color: #fff; }
.brand small { display: block; font: 500 11px var(--font); color: var(--rail-muted); letter-spacing: 0; }
.nav-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--rail-muted); padding: 14px 12px 6px; }
.side a.nav { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 9px; color: var(--rail-ink); font-weight: 500; transition: background .15s, color .15s; }
.side a.nav svg { width: 18px; height: 18px; opacity: .75; flex: none; }
.side a.nav:hover { background: var(--rail-2); text-decoration: none; color: #fff; }
.side a.nav.active { background: rgba(47, 181, 194, .14); color: #fff; box-shadow: inset 2px 0 0 #2fb5c2; }
.side a.nav.active svg { opacity: 1; color: #5fcbd5; }
.side .foot { margin-top: auto; padding: 12px; border-top: 1px solid var(--rail-2); font-size: 12px; color: var(--rail-muted); display: grid; gap: 10px; }
.me { display: flex; gap: 10px; align-items: center; }
.me b { color: #fff; font-weight: 600; display: block; font-size: 13px; }
.me span { font-size: 11.5px; text-transform: capitalize; }
.side .foot .row button { background: var(--rail-2); color: var(--rail-ink); border-color: transparent; }
.side .foot .row button:hover { color: #fff; border-color: var(--rail-muted); }
.ai-chip { display: inline-flex; gap: 6px; align-items: center; font-size: 11.5px; }
.ai-chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--rail-muted); }
.ai-chip.on i { background: #45c486; box-shadow: 0 0 0 3px rgba(69,196,134,.2); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; padding: 12px 28px; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); min-height: 60px; }
.topbar .crumb { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }
main#app { padding: 24px 28px 48px; max-width: 1440px; width: 100%; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .sub { color: var(--muted); margin-top: 4px; font-size: 13px; }

/* ---------- Building blocks ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mt { margin-top: 16px; }
.stack { display: grid; gap: 16px; }

/* stat tiles */
.stat { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: center; color: inherit; text-decoration: none !important; transition: border-color .15s, transform .15s; }
a.stat:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.stat .ico { grid-row: span 2; width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.stat .ico svg { width: 19px; height: 19px; }
.stat .ico.warn { background: var(--warn-soft); color: var(--warn); }
.stat .ico.bad { background: var(--bad-soft); color: var(--bad); }
.stat .ico.ok { background: var(--ok-soft); color: var(--ok); }
.stat .ico.info { background: var(--info-soft); color: var(--info); }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat .value { font: 700 22px/1.15 var(--font-display); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td, table tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; transition: background .12s; }
tr.click:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who b { font-weight: 600; display: block; }
.avatar { width: 32px; height: 32px; border-radius: 50%; flex: none; display: grid; place-items: center; font: 600 12px var(--font); color: var(--accent-strong); background: var(--accent-soft); }
.avatar.lg { width: 44px; height: 44px; font-size: 15px; }

/* buttons */
button, .btn { font: 500 13.5px var(--font); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); padding: 8px 14px; border-radius: var(--radius-sm); cursor: pointer; display: inline-flex; gap: 7px; align-items: center; justify-content: center; white-space: nowrap; transition: background .15s, border-color .15s, color .15s, box-shadow .15s; }
button svg, .btn svg { width: 16px; height: 16px; }
button:hover, .btn:hover { border-color: var(--accent); color: var(--accent-strong); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); box-shadow: 0 1px 2px rgba(11, 127, 140, .25); }
button.primary:hover, .btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--accent-ink); }
button.ghost { background: transparent; border-color: transparent; }
button.danger { color: var(--bad); }
button.danger:hover { border-color: var(--bad); color: var(--bad); }
button.ai { justify-content: flex-start; background: var(--surface-2); border-color: var(--line); color: var(--ink-2); }
button.ai svg { color: var(--accent); }
button.ai:hover { border-color: var(--accent); color: var(--accent-strong); background: var(--accent-soft); }
button:disabled { opacity: .55; cursor: progress; }
button.sm, .btn.sm { padding: 5px 10px; font-size: 12.5px; }

/* forms */
input, select, textarea { font: 14px var(--font); color: var(--ink); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 11px; width: 100%; transition: border-color .15s, box-shadow .15s, background .15s; }
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
input[readonly], textarea[readonly] { background: var(--surface); border-style: dashed; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); padding: 0; }
textarea { resize: vertical; min-height: 72px; line-height: 1.55; }
textarea.report { min-height: 220px; font-size: 14.5px; line-height: 1.65; }
label { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 6px; font-weight: 500; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: 13.5px; margin: 0; }
.field { margin-bottom: 14px; }
.search { position: relative; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.search input { padding-left: 34px; }

/* status pills */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.badge.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-Pending { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.b-Draft { background: var(--info-soft); color: var(--info); border-color: transparent; }
.b-Signed, .b-Paid, .b-Active { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.b-Unpaid, .b-STAT, .b-crit, .b-Disabled { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.b-Partial, .b-Urgent { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.b-Cancelled { text-decoration: line-through; }
.mod { font: 600 11px var(--font); letter-spacing: .04em; padding: 3px 7px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-strong); }

/* reporting workspace */
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
.assist { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 14px; max-height: calc(100vh - 92px); overflow: auto; }
.assist .ai-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.assist .ai-head .ico { width: 32px; height: 32px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.assist .ai-head .ico svg { width: 17px; height: 17px; }
.issue { border: 1px solid var(--line); border-left: 3px solid var(--line-strong); padding: 9px 12px; margin: 8px 0; background: var(--surface-2); border-radius: 0 8px 8px 0; }
.issue.high { border-left-color: var(--bad); }
.issue.medium { border-left-color: var(--warn); }
.issue.low { border-left-color: var(--accent); }
.critical-banner { display: flex; gap: 10px; align-items: center; background: var(--bad-soft); color: var(--bad); padding: 11px 14px; border-radius: 10px; font-weight: 600; margin-bottom: 16px; }
.critical-banner svg { width: 18px; height: 18px; flex: none; }
.pt-strip { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.pt-strip .kv { display: grid; gap: 1px; }
.pt-strip .kv span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.pt-strip .kv b { font-weight: 600; font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 12px; overflow-x: auto; }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 10px; color: var(--muted); font-size: 13px; }
.tabs button:hover { color: var(--ink); }
.tabs button.on { border-bottom-color: var(--accent); color: var(--accent-strong); font-weight: 600; }
pre.addendum { white-space: pre-wrap; font: inherit; background: var(--warn-soft); padding: 12px; border-radius: 10px; margin: 0; }
details summary { cursor: pointer; }

/* filter toolbar */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.toolbar .search { flex: 1 1 260px; max-width: 380px; }
.toolbar select, .toolbar input[type="date"] { width: auto; }
.chips { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.chips button { border: 0; background: transparent; padding: 5px 11px; font-size: 12.5px; color: var(--muted); border-radius: 7px; }
.chips button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }

/* modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(6, 14, 19, .5); backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 120; padding: 16px; animation: fade .15s ease-out; }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; width: min(660px, 100%); max-height: 90vh; overflow: auto; padding: 24px; box-shadow: var(--shadow-lg); animation: rise .18s ease-out; }
.modal h2 { font-size: 18px; margin-bottom: 16px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.toast-wrap { position: fixed; bottom: 20px; right: 20px; display: grid; gap: 8px; z-index: 130; }
.toast { display: flex; gap: 10px; align-items: center; background: var(--ink); color: var(--surface); padding: 11px 16px; border-radius: 10px; max-width: 420px; box-shadow: var(--shadow-lg); animation: rise .2s ease-out; font-weight: 500; }
.toast.err { background: var(--bad); color: #fff; }

/* chart */
.bars { display: flex; align-items: flex-end; gap: 5px; height: 140px; padding-top: 8px; border-bottom: 1px solid var(--line); }
.bars div { flex: 1; background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 55%, transparent)); border-radius: 5px 5px 0 0; min-height: 3px; position: relative; transition: opacity .15s; }
.bars div:hover { opacity: .8; }
.bars div:hover::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--surface); font-size: 11px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; z-index: 2; }

/* loading: spinner, skeleton shimmer, busy lists */
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.sk { display: block; border-radius: 8px; background: linear-gradient(90deg, var(--surface-2) 0%, var(--line) 50%, var(--surface-2) 100%); background-size: 200% 100%; animation: shimmer 1.3s ease-in-out infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.sk-line { height: 12px; margin: 10px 0; }
.is-loading { position: relative; pointer-events: none; }
.is-loading > * { opacity: .45; transition: opacity .15s; }
.is-loading::after { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 2px; background: linear-gradient(90deg, transparent, var(--accent), transparent); background-size: 50% 100%; background-repeat: no-repeat; animation: slide2 1s linear infinite; }
@keyframes slide2 { from { background-position: -50% 0; } to { background-position: 150% 0; } }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty svg { width: 34px; height: 34px; color: var(--line-strong); display: block; margin: 0 auto 10px; }
.error-card { border-color: var(--bad-soft); }

/* sign-in */
body.signed-out .side, body.signed-out .topbar { display: none; }
body.signed-out .layout { grid-template-columns: 1fr; }
body.signed-out main#app { max-width: none; }
.auth-wrap { min-height: calc(100vh - 80px); display: grid; place-items: center; }
.auth-card { width: min(420px, 100%); padding: 28px; }
.auth-card .brand { color: var(--ink); padding: 0 0 18px; }
.auth-card .brand small { color: var(--muted); }

@media (max-width: 1150px) { .workspace { grid-template-columns: 1fr; } .assist { position: static; max-height: none; } .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 70; left: 0; top: 0; bottom: 0; width: 260px; transform: translateX(-100%); transition: transform .2s ease; }
  body.nav-open .side { transform: none; box-shadow: var(--shadow-lg); }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(6,14,19,.45); z-index: 65; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); }
  main#app { padding: 18px max(16px, env(safe-area-inset-right, 0px)) 40px max(16px, env(safe-area-inset-left, 0px)); }
  .g2, .g3 { grid-template-columns: 1fr; }
  .topbar .hide-sm { display: none; }
  th, td { white-space: nowrap; }
  .page-head > .row { width: 100%; }
}
@media (max-width: 520px) { .g4 { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
