/* CPAI Portal — design system "scan-light on cool graphite" (EPIC W).
   Single base stylesheet, mobile-first, no framework, no JavaScript.
   Registers: staff console (dense, sidebar shell) lives here;
   external portals load portal.css on top; the radiologist reading
   room loads reading.css (dark token override) on top. */

/* ---------- fonts (self-hosted, CSP font-src 'self') ---------- */
@font-face {
  font-family: 'Bricolage Grotesque';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../fonts/bricolage-grotesque-var-latin.c47ac31e5437.woff2") format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("../fonts/ibm-plex-sans-var-latin.d28498895ed7.woff2") format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/ibm-plex-mono-400-latin.814fe1615d4d.woff2") format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/ibm-plex-mono-500-latin.6708425c446b.woff2") format('woff2');
}

/* ---------- design tokens ---------- */
:root {
  /* scan-cyan brand ramp */
  --brand-50: #EEF7F9;
  --brand-100: #D8EEF2;
  --brand-200: #B0DEE6;
  --brand-300: #7CC8D6;
  --brand-400: #45C4DA;   /* accent on dark surfaces */
  --brand-500: #1B8FA6;
  --brand-600: #0F758B;   /* primary action on light */
  --brand-700: #0C5D70;
  --brand-800: #0A4A59;
  --brand-900: #08333E;

  /* graphite neutrals, cyan-biased */
  --n-0: #FFFFFF;
  --n-50: #F6F9FA;
  --n-100: #EEF3F5;
  --n-200: #DFE8EB;
  --n-300: #C3D1D6;
  --n-400: #93A6AD;
  --n-500: #5D7078;
  --n-700: #35454B;
  --n-800: #223137;
  --n-900: #132027;
  --graphite: #0B2830;    /* sidebar / dark chrome ground */

  /* semantic surfaces (the five badge tones) */
  --ok: #197A46; --ok-bg: #E3F4EA;
  --warn: #8A5A08; --warn-bg: #FBF1DA;
  --danger: #B3271E; --danger-bg: #FBE7E5;
  --info: #1D5FBF; --info-bg: #E6EFFB;

  /* roles */
  --bg: var(--n-50);
  --card: var(--n-0);
  --text: var(--n-900);
  --muted: var(--n-500);
  --line: var(--n-200);
  --line-soft: var(--n-100);
  --brand: var(--brand-600);       /* legacy alias, keep working */
  --brand-dark: var(--brand-700);  /* legacy alias, keep working */
  --focus: var(--brand-400);
  --field-bg: var(--n-0);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-pop: 0 6px 24px rgba(11, 40, 48, .18);

  --font-display: 'Bricolage Grotesque', 'Avenir Next', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 16px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-display); letter-spacing: -.01em; line-height: 1.2; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
a { color: var(--brand-700); }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 1rem; }
main.wrap { padding-top: 1rem; padding-bottom: 3rem; }
.mono { font-family: var(--font-mono); font-size: .92em; }
.num { font-variant-numeric: tabular-nums; }
td.num, th.num { text-align: right; }

/* ---------- public / auth header (default shell) ---------- */
.site-header { background: var(--card); color: var(--text); border-bottom: 1px solid var(--line); }
.header-inner { display: flex; align-items: center; justify-content: space-between; min-height: 3.4rem; gap: 1rem; }
.brand { color: var(--text); font-family: var(--font-display); font-weight: 600; text-decoration: none; font-size: 1.05rem; display: inline-flex; align-items: center; gap: .55rem; }
.brand svg { display: block; flex-shrink: 0; }
.nav-toggle summary { list-style: none; cursor: pointer; padding: .5rem .75rem; border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: .9rem; font-weight: 500; }
.nav-toggle summary::-webkit-details-marker { display: none; }
.site-nav { position: absolute; right: 1rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem; display: flex; flex-direction: column; min-width: 13rem; z-index: 30; box-shadow: var(--shadow-pop); }
.site-nav a, .site-nav .linklike { color: var(--text); text-decoration: none; padding: .65rem .75rem; border-radius: var(--radius-sm); display: block; text-align: left; width: 100%; font-weight: 500; font-size: .95rem; }
.site-nav a:hover, .site-nav .linklike:hover { background: var(--brand-50); color: var(--brand-700); }
.inline-form { margin: 0; }
.linklike { background: none; border: none; font: inherit; cursor: pointer; color: var(--brand-700); }

@media (min-width: 800px) {
  @supports selector(details::details-content) {
    .site-header .nav-toggle summary { display: none; }
    .site-header .nav-toggle { display: contents; }
    .site-header .nav-toggle::details-content { content-visibility: visible; }
    .site-header .site-nav { position: static; flex-direction: row; background: none; border: 0; box-shadow: none; padding: 0; min-width: 0; align-items: center; }
    .site-header .site-nav a, .site-header .site-nav .linklike { width: auto; padding: .4rem .6rem; }
  }
}

/* ---------- staff shell: graphite sidebar + topbar ---------- */
.shell-staff { font-size: 14px; }
.shell { display: grid; grid-template-columns: 15rem minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--graphite); color: #B8CDD4; display: flex; flex-direction: column; padding: .9rem .6rem; }
.side-brand { display: flex; align-items: center; gap: .55rem; color: #fff; text-decoration: none; font-family: var(--font-display); font-weight: 600; font-size: .95rem; padding: .25rem .5rem .9rem; }
.side-brand svg { flex-shrink: 0; }
.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-nav .grp { font-size: .62rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: #7E97A0; padding: .8rem .5rem .3rem; }
.side-nav a { color: #B8CDD4; text-decoration: none; padding: .5rem .55rem; border-radius: var(--radius-sm); display: flex; align-items: center; gap: .5rem; font-weight: 500; font-size: .86rem; }
.side-nav a:hover { background: rgba(69, 196, 218, .08); color: #fff; }
.side-nav a[aria-current="page"], .side-nav a.active { background: rgba(69, 196, 218, .14); color: #fff; box-shadow: inset 2px 0 0 var(--brand-400); }
.side-nav .side-count { margin-left: auto; font-family: var(--font-mono); font-size: .62rem; background: rgba(69, 196, 218, .2); color: #7BD6E6; border-radius: 999px; padding: .1rem .45rem; }
.side-user { margin-top: auto; border-top: 1px solid rgba(184, 205, 212, .16); padding: .7rem .5rem .2rem; display: flex; align-items: center; gap: .55rem; }
.side-user .avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--brand-400); color: #06222B; display: grid; place-items: center; font-weight: 700; font-size: .68rem; flex-shrink: 0; }
.side-user .who { min-width: 0; }
.side-user .who b { display: block; color: #fff; font-size: .8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user .who small { color: #6B8891; font-size: .68rem; }
.side-user .linklike { color: #B8CDD4; margin-left: auto; font-size: .78rem; padding: .35rem; }
.side-user .linklike:hover { color: #fff; }

.shell-main { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: .75rem; background: var(--card); border-bottom: 1px solid var(--line); padding: .55rem 1.25rem; }
.topbar-search { flex: 1; max-width: 24rem; display: flex; }
.topbar-search input { width: 100%; font: inherit; font-size: .88rem; color: var(--text); background: var(--n-100); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .5rem .75rem; min-height: 40px; }
.topbar-search input::placeholder { color: var(--muted); }
.topbar-search input:focus { background: var(--card); }
.topbar .btn { margin-left: auto; }
.shell-content { padding: 1.25rem 1.5rem 3rem; max-width: 90rem; width: 100%; }

/* narrow screens: sidebar becomes a top strip with a dropdown menu */
@media (max-width: 899px) {
  .shell { display: block; }
  .sidebar { flex-direction: row; align-items: center; gap: .6rem; padding: .5rem .9rem; position: relative; }
  .side-brand { padding: 0; }
  .sidebar .nav-toggle { margin-left: auto; }
  .sidebar .nav-toggle summary { list-style: none; cursor: pointer; color: #fff; border: 1px solid rgba(184, 205, 212, .4); border-radius: var(--radius-sm); padding: .45rem .8rem; font-size: .85rem; }
  .sidebar .nav-toggle summary::-webkit-details-marker { display: none; }
  .side-nav { position: absolute; top: 100%; right: .6rem; z-index: 40; background: var(--graphite); border-radius: var(--radius); box-shadow: var(--shadow-pop); padding: .5rem; min-width: 14rem; }
  .side-nav a { padding: .65rem .75rem; }
  .side-user { display: none; }
  .side-user-menu { display: flex; }
  .shell-content { padding: 1rem; }
}
@media (min-width: 900px) {
  .sidebar .nav-toggle summary { display: none; }
  .sidebar .nav-toggle { display: contents; }
  .sidebar .nav-toggle::details-content { content-visibility: visible; }
  .side-user-menu { display: none; }
}

/* ---------- page furniture ---------- */
.page-title { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.page-title h1, .page-title h2 { margin: 0; }
.shell-staff h1 { font-size: 1.45rem; }
.page-sub { color: var(--muted); font-size: .88em; margin-top: .15rem; }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.15rem; margin-bottom: 1rem; }
.card h2, .card h3 { margin-top: 0; font-size: 1.02rem; }
.card-grid { display: grid; gap: 1rem; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 700px) { .card-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) { .card-grid-3 { grid-template-columns: repeat(3, 1fr); } }

/* stat tiles: triage numbers, left-aligned display digits */
.stat-grid { display: grid; gap: .75rem; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 800px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1100px) { .stat-grid { grid-template-columns: repeat(6, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .9rem; text-align: left; }
.stat .num { font-family: var(--font-display); font-size: 1.55rem; font-weight: 700; display: block; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat .lbl { color: var(--muted); font-size: .74rem; font-weight: 500; }
.stat-warn { border-color: #F3CFA0; background: #FDF8EE; }
.stat-danger { border-color: #F0B9B4; background: #FDF1F0; }

/* ---------- badges: tone + leading state dot ---------- */
.badge { display: inline-flex; align-items: center; gap: .35rem; padding: .16rem .6rem; border-radius: 999px; font-size: .74rem; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--line-soft); color: var(--muted); }

/* modality / code chips */
.chip { font-family: var(--font-mono); font-size: .7rem; font-weight: 500; background: var(--line-soft); color: var(--n-700); border-radius: 5px; padding: .18rem .4rem; white-space: nowrap; }

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.data th, table.data td { padding: .55rem .8rem; text-align: left; border-bottom: 1px solid var(--line-soft); font-size: .9em; vertical-align: middle; }
table.data th { background: var(--card); font-family: var(--font-body); font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); border-bottom: 1px solid var(--line); position: sticky; top: 0; }
table.data tbody tr:hover td, table.data tr:hover td { background: #F3FAFB; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.num { font-variant-numeric: tabular-nums; }

/* ---------- card lists (external/mobile, queues) ---------- */
.list-cards { display: flex; flex-direction: column; gap: .75rem; }
.list-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; display: block; color: inherit; text-decoration: none; }
a.list-card:hover, .list-card:hover { border-color: var(--brand-300); }
.list-card .row1 { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.list-card .title { font-weight: 600; }
.list-card .meta { color: var(--muted); font-size: .85em; }

/* ---------- forms — 44px+ tap targets ---------- */
form.stack label { display: block; font-weight: 600; font-size: .92em; margin: .9rem 0 .3rem; }
form.stack input[type="text"], form.stack input[type="email"], form.stack input[type="password"],
form.stack input[type="date"], form.stack input[type="datetime-local"], form.stack input[type="tel"],
form.stack input[type="number"], form.stack input[type="file"], form.stack select, form.stack textarea {
  width: 100%; padding: .6rem .75rem; font: inherit; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--field-bg); color: var(--text); min-height: 44px;
}
form.stack textarea { min-height: 6rem; }
form.stack .helptext { color: var(--muted); font-size: .82em; display: block; margin-top: .25rem; }
.errorlist { color: var(--danger); margin: .25rem 0; padding-left: 1.1rem; font-size: .9em; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; background: var(--brand-600); color: #fff; border: 1px solid transparent; border-radius: var(--radius-sm); padding: .65rem 1.15rem; font: inherit; font-size: .95em; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 44px; }
.btn:hover { background: var(--brand-700); }
.btn-secondary { background: transparent; color: var(--brand-700); border-color: var(--brand-200); }
.btn-secondary:hover { background: var(--brand-50); }
.btn-danger { background: transparent; color: var(--danger); border-color: #F0B9B4; }
.btn-danger:hover { background: var(--danger-bg); }
.btn-small { padding: .3rem .7rem; min-height: 0; font-size: .82em; }
.btn-block { display: flex; width: 100%; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }

/* ---------- messages ---------- */
.messages { margin-bottom: 1rem; }
.message { padding: .7rem 1rem; border-radius: var(--radius-sm); margin-bottom: .5rem; font-size: .95em; border: 1px solid transparent; }
.message-success { background: var(--ok-bg); color: var(--ok); border-color: #BFE3CD; }
.message-error { background: var(--danger-bg); color: var(--danger); border-color: #F0B9B4; }
.message-warning { background: var(--warn-bg); color: var(--warn); border-color: #F3CFA0; }
.message-info { background: var(--info-bg); color: var(--info); border-color: #BBD3F3; }

/* ---------- tabs: segmented control ---------- */
.tabs { display: inline-flex; gap: .15rem; flex-wrap: wrap; margin-bottom: 1rem; background: var(--line-soft); border-radius: 10px; padding: .2rem; border-bottom: 0; }
.tabs a { padding: .45rem .9rem; text-decoration: none; color: var(--muted); border-radius: var(--radius-sm); font-weight: 500; font-size: .92em; }
.tabs a:hover { color: var(--text); }
.tabs a.active { background: var(--card); color: var(--brand-700); font-weight: 600; border: 0; margin-bottom: 0; box-shadow: 0 1px 2px rgba(19, 32, 39, .1); }

/* ---------- filter bar ---------- */
.filter-bar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.filter-bar input, .filter-bar select { padding: .5rem .65rem; border: 1px solid var(--line); border-radius: var(--radius-sm); font: inherit; font-size: .92em; min-height: 44px; background: var(--field-bg); color: var(--text); }

/* ---------- shared page patterns ---------- */
table.data td .actions { margin-top: 0; }
.form-card { max-width: 36rem; }
td.t-name, .t-name { font-weight: 600; }
td.t-time, .t-time { font-family: var(--font-mono); font-size: .85em; white-space: nowrap; }
.acc { font-family: var(--font-mono); font-size: .78em; color: var(--n-400); }
.card-warn { border-color: #F3CFA0; background: #FDF8EE; }
.card-danger { border-color: #F0B9B4; background: #FDF1F0; }
.pager { display: flex; align-items: center; gap: .75rem; margin-top: 1rem; font-size: .9em; color: var(--muted); }
.pager a { font-weight: 600; text-decoration: none; }

/* ---------- misc ---------- */
.muted { color: var(--muted); }
.auth-box { max-width: 26rem; margin: 3rem auto; }
.auth-box .card { border-radius: var(--radius-lg); padding: 1.75rem; }
.site-footer { color: var(--muted); font-size: .78rem; padding-bottom: 1.5rem; }
.divided > * + * { border-top: 1px solid var(--line-soft); padding-top: .75rem; margin-top: .75rem; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem .9rem; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .85em; }
dl.kv dd { margin: 0; }

/* ---------- calendar ---------- */
.calendar-day { display: grid; gap: .4rem; }
.cal-slot { display: flex; gap: .6rem; align-items: baseline; background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--brand-500); border-radius: var(--radius-sm); padding: .5rem .7rem; text-decoration: none; color: inherit; flex-wrap: wrap; font-size: .92em; }
.cal-slot:hover { border-color: var(--brand-300); border-left-color: var(--brand-500); }
.cal-slot .mono, .cal-slot time { font-family: var(--font-mono); font-size: .85em; }
.week-grid { display: grid; gap: .5rem; grid-template-columns: 1fr; }
@media (min-width: 900px) { .week-grid { grid-template-columns: repeat(7, 1fr); } }

/* ---------- two-factor auth ---------- */
.backup-codes { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; }
.backup-codes code { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .5rem .7rem; font-family: var(--font-mono); font-size: 1rem; letter-spacing: .05em; text-align: center; }
.otp-input, form.stack .otp-field input { font-family: var(--font-mono) !important; font-size: 1.35rem !important; letter-spacing: .55em; text-align: center; }

/* ---------- print ---------- */
@media print {
  .sidebar, .topbar, .site-header, .site-footer, .actions, .btn, .tabs, .filter-bar { display: none !important; }
  body { background: #fff; font-size: 12px; }
  .card, table.data { border-color: #999; box-shadow: none; }
  .shell { display: block; }
}
