/* WebPacs shared UI styles (login, worklists, report, admin).
   Self-hosted fonts and no CDN so the app works on an offline hospital network. */

@font-face { font-family: 'IBM Plex Sans'; font-style: normal; font-weight: 400; font-display: swap; src: url('../fonts/ibm-plex-sans-latin-400-normal.woff2') format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'IBM Plex Sans'; font-style: normal; font-weight: 400; font-display: swap; src: url('../fonts/ibm-plex-sans-latin-ext-400-normal.woff2') format('woff2'); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: 'IBM Plex Sans'; font-style: normal; font-weight: 500; font-display: swap; src: url('../fonts/ibm-plex-sans-latin-500-normal.woff2') format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'IBM Plex Sans'; font-style: normal; font-weight: 500; font-display: swap; src: url('../fonts/ibm-plex-sans-latin-ext-500-normal.woff2') format('woff2'); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: 'IBM Plex Sans'; font-style: normal; font-weight: 600; font-display: swap; src: url('../fonts/ibm-plex-sans-latin-600-normal.woff2') format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'IBM Plex Sans'; font-style: normal; font-weight: 600; font-display: swap; src: url('../fonts/ibm-plex-sans-latin-ext-600-normal.woff2') format('woff2'); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: 'IBM Plex Sans'; font-style: normal; font-weight: 700; font-display: swap; src: url('../fonts/ibm-plex-sans-latin-700-normal.woff2') format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'IBM Plex Sans'; font-style: normal; font-weight: 700; font-display: swap; src: url('../fonts/ibm-plex-sans-latin-ext-700-normal.woff2') format('woff2'); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: 'IBM Plex Mono'; font-style: normal; font-weight: 400; font-display: swap; src: url('../fonts/ibm-plex-mono-latin-400-normal.woff2') format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'IBM Plex Mono'; font-style: normal; font-weight: 400; font-display: swap; src: url('../fonts/ibm-plex-mono-latin-ext-400-normal.woff2') format('woff2'); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family: 'IBM Plex Mono'; font-style: normal; font-weight: 500; font-display: swap; src: url('../fonts/ibm-plex-mono-latin-500-normal.woff2') format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'IBM Plex Mono'; font-style: normal; font-weight: 500; font-display: swap; src: url('../fonts/ibm-plex-mono-latin-ext-500-normal.woff2') format('woff2'); unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }

:root {
  --ink: #0F1722;
  --ink-2: #3A4553;
  --muted: #5B6675;
  --ground: #F4F6F8;
  --surface: #FFFFFF;
  --surface-2: #F2F7FF;
  --border: #DDE2E8;
  --border-soft: #EEF1F4;
  --field-border: #C9D1DB;
  --accent: #1A5FD0;
  --accent-hover: #164FB0;
  --accent-ink: #1A4FA8;
  --accent-soft: #E8F0FD;
  --nav-bg: #0B1420;
  --nav-item: #1B2838;
  --nav-border: #2C3A4C;
  --nav-text: #E6EBF1;
  --nav-muted: #B4C0CE;
  --ok-bg: #E3F4EA; --ok-ink: #155D39; --ok-dot: #3CC47C;
  --warn-bg: #FDF1E8; --warn-ink: #8A3B07; --warn-line: #F3C9A6; --warn: #C2570C;
  --info-bg: #EDE7FB; --info-ink: #4B2F96;
  --neutral-bg: #EEF1F4;
  --danger: #B42318; --danger-bg: #FDECEA; --danger-ink: #7A1A12; --danger-line: #F4C7C2;
  --link-hover: #123F8C;
  --hover: #F7F9FB;
  --row-hover: #F8FAFC;
  --segmented-bg: #E7EBF0; --segmented-ink: #4A5563;
  --switch-off: #B8C2CE;
  --track: #E3E8EE;
  --spinner-track: #D5DCE4;
  --toast-bg: #0F1722;
  --radius: 8px;
  --radius-lg: 12px;
  --font: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;
}

/* Dark theme: set by static/js/theme.js (data-theme on <html>), toggled from the worklist header. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #E6EBF1;
  --ink-2: #C3CCD7;
  --muted: #95A2B3;
  --ground: #0E141B;
  --surface: #161E28;
  --surface-2: #1A2A40;
  --border: #2A3544;
  --border-soft: #212B38;
  --field-border: #3A4757;
  --accent: #2F6FDB;
  --accent-hover: #3A7BE8;
  --accent-ink: #8DB6FF;
  --accent-soft: #1C2D4A;
  --nav-bg: #080D14;
  --nav-item: #18222F;
  --nav-border: #2A3544;
  --ok-bg: #12301F; --ok-ink: #8AE0AE;
  --warn-bg: #3A2312; --warn-ink: #F5B987; --warn-line: #5C3A1E; --warn: #D9661A;
  --info-bg: #2A2145; --info-ink: #C4B2F5;
  --neutral-bg: #222C38;
  --danger: #E5534B; --danger-bg: #3A1A19; --danger-ink: #F7A49C; --danger-line: #5C2724;
  --link-hover: #B3CEFF;
  --hover: #1D2632;
  --row-hover: #1A2330;
  --segmented-bg: #0E141B; --segmented-ink: #B4C0CE;
  --switch-off: #475467;
  --track: #2A3544;
  --spinner-track: #2F3B4B;
  --toast-bg: #2A3544;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--ground); font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
a:hover { color: var(--link-hover); }
h1, h2, h3 { margin: 0; font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.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; }
.mono { font-family: var(--mono); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

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

/* Icons: <svg class="icon"><use href="#i-search"></use></svg> (sprite in _icons.html) */
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 22px; height: 22px; }

/* ---------- App shell ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.app-header { background: var(--nav-bg); color: var(--nav-text); display: flex; flex-wrap: wrap; align-items: center; gap: 12px 32px; padding: 12px 24px; }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--accent); display: flex; align-items: center; justify-content: center; color: #FFFFFF; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: 0.02em; }
.brand-sub { font-size: 12px; color: #93A1B3; }
.app-nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1 1 auto; }
.app-nav a, .app-nav button { color: var(--nav-muted); text-decoration: none; font-size: 14px; padding: 8px 12px; border-radius: 6px; background: transparent; border: none; cursor: pointer; }
.app-nav a:hover, .app-nav button:hover { color: #FFFFFF; }
.app-nav [aria-current="page"] { color: #FFFFFF; font-weight: 600; background: var(--nav-item); }
.app-user { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; font-size: 13px; }
.app-user .who { color: var(--nav-muted); }
.pill-dark { padding: 4px 10px; border-radius: 999px; background: var(--nav-item); color: #C9D3DE; }
.status-dot { display: inline-flex; align-items: center; gap: 6px; color: #9FD8B8; }
.status-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok-dot); }
.btn-nav { color: var(--nav-text); text-decoration: none; border: 1px solid var(--nav-border); border-radius: 6px; padding: 6px 12px; background: transparent; cursor: pointer; font-size: 13px; }
.btn-nav:hover { background: var(--nav-item); color: #FFFFFF; }
.btn-theme { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 32px; padding: 0; }

.page { padding: 24px; display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.page-main { flex: 999 1 640px; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.page-side { flex: 1 1 300px; max-width: 380px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.page-title { font-size: 22px; }
.page-sub { margin: 4px 0 0; font-size: 13px; color: var(--muted); }

/* ---------- Surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.card-pad { padding: 20px; }
.card-head { padding: 16px 20px; border-bottom: 1px solid var(--border-soft); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.toolbar-strip { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; padding: 16px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.hint { font-size: 12px; color: var(--muted); }
.input, .select, .textarea { height: 40px; padding: 0 12px; border: 1px solid var(--field-border); border-radius: var(--radius); background: var(--surface); font-size: 14px; width: 100%; min-width: 0; }
.textarea { height: auto; padding: 10px 12px; min-height: 120px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.input-lg { height: 44px; font-size: 15px; }
.input-icon { position: relative; }
.input-icon .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon .input { padding-left: 36px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
fieldset.plain { border: none; margin: 0; padding: 0; min-width: 0; }
fieldset.plain legend { padding: 0; margin-bottom: 8px; font-size: 12px; font-weight: 600; color: var(--ink-2); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 40px; padding: 0 16px; border-radius: var(--radius); border: 1px solid var(--field-border); background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--hover); color: var(--ink); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #FFFFFF; font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #FFFFFF; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); color: var(--danger); }
.btn-warn { background: var(--warn); border-color: var(--warn); color: #FFFFFF; font-weight: 600; }
.btn-dashed { border-style: dashed; border-color: #8FA0B3; color: var(--accent-ink); font-weight: 600; }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; }
.btn-lg { height: 48px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-icon { width: 34px; padding: 0; }
.btn-ghost { border-color: transparent; background: transparent; }

/* Toggle chips (date ranges, modalities) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.chip { height: 34px; padding: 0 10px; border-radius: 6px; border: 1px solid var(--field-border); background: var(--surface); color: var(--ink-2); font-size: 13px; cursor: pointer; }
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }

/* Segmented tabs */
.segmented { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; padding: 4px; background: var(--segmented-bg); border-radius: 10px; }
.segmented button { height: 40px; border: none; border-radius: 7px; background: transparent; color: var(--segmented-ink); font-size: 14px; font-weight: 500; cursor: pointer; }
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(15,23,34,0.12); }

/* Switch */
.switch { position: relative; width: 44px; height: 26px; border: none; border-radius: 999px; padding: 0; cursor: pointer; background: var(--switch-off); flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #FFFFFF; box-shadow: 0 1px 2px rgba(0,0,0,0.25); transition: left 0.15s; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { left: 21px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--neutral-bg); color: var(--ink-2); }
.badge-ok { background: var(--ok-bg); color: var(--ok-ink); }
.badge-warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge-info { background: var(--info-bg); color: var(--info-ink); }
.badge-accent { background: var(--accent-soft); color: var(--accent-ink); }
.mod { display: inline-block; min-width: 28px; text-align: center; padding: 3px 6px; border-radius: 5px; background: var(--accent-soft); color: var(--accent-ink); font-size: 12px; font-weight: 700; }

/* ---------- Alerts ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); font-size: 13px; line-height: 1.5; }
.alert .icon { margin-top: 1px; }
.alert-warn { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-line); }
.alert-error { background: var(--danger-bg); color: var(--danger-ink); border: 1px solid var(--danger-line); }
.alert-ok { background: var(--ok-bg); color: var(--ok-ink); }

/* ---------- Tables ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; padding: 12px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th.sortable { cursor: pointer; user-select: none; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--row-hover); }
.table tbody tr.is-selected { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
.table .t-right { text-align: right; }
.table .sub { font-size: 12px; color: var(--muted); }
.table .strong { font-weight: 600; }
.table-message td { padding: 40px 16px; text-align: center; color: var(--muted); }

.progress { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.2s; }
.progress.indeterminate > span { width: 35%; animation: indeterminate 1.2s ease-in-out infinite; }
@keyframes indeterminate { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } }

.spinner { width: 28px; height: 28px; border: 3px solid var(--spinner-track); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Dialogs ---------- */
.dialog-backdrop { position: fixed; inset: 0; background: rgba(11,20,32,0.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 100; }
.dialog { width: 100%; max-width: 480px; max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: var(--radius-lg); box-shadow: 0 20px 50px rgba(11,20,32,0.3); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border-soft); }
.dialog-head h2 { font-size: 17px; }
.dialog-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border-soft); }

/* Toast */
.toast-host { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { min-width: 240px; max-width: 380px; padding: 12px 14px; border-radius: var(--radius); background: var(--toast-bg); color: #FFFFFF; font-size: 13px; box-shadow: 0 8px 24px rgba(11,20,32,0.3); }
.toast.error { background: #7A1A12; }
.toast.ok { background: #155D39; }

/* ---------- Responsive tables: stack rows under 720px ---------- */
@media (max-width: 720px) {
  .page { padding: 16px; gap: 16px; }
  .app-header { padding: 10px 16px; }
  .page-side { max-width: none; }
  .table.stack-mobile { min-width: 0 !important; }
  .table.stack-mobile thead { display: none; }
  .table.stack-mobile tr { display: block; padding: 12px 16px; border-bottom: 1px solid var(--border-soft); }
  .table.stack-mobile td { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border: none; text-align: right; }
  .table.stack-mobile td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; }
  .table.stack-mobile td.t-actions { justify-content: flex-end; padding-top: 8px; }
  .table.stack-mobile td.t-actions::before { content: none; }
}
