/* RIS Dummy — design system. System fonts only (works offline on hospital networks). */
:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e3e8ef;
  --line-strong: #cfd7e2;
  --text: #16202c;
  --text-2: #44515f;
  --muted: #6b7889;
  --primary: #0b63c5;
  --primary-hover: #0a56ab;
  --primary-soft: #e8f1fc;
  --ok: #157f4a;
  --ok-soft: #e3f4ea;
  --warn: #946200;
  --warn-soft: #fff3d6;
  --err: #b42318;
  --err-soft: #fdeceb;
  --pacs: #6941c6;
  --pacs-soft: #f1ebfd;
  --side: #0f1f33;
  --side-2: #17304d;
  --side-text: #b9c7d8;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
  --side-w: 248px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 1.25; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0; font-weight: 650; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 650; color: var(--text-2); }
code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--line); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 12px; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- app shell ---------- */
.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--side); color: var(--side-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #2f8cff, #0b63c5); display: grid; place-items: center; flex: none; }
.brand-mark svg { width: 20px; height: 20px; }
.brand b { display: block; font-size: 14px; letter-spacing: .01em; }
.brand span { display: block; font-size: 11px; color: var(--side-text); }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7f93ab; padding: 12px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; color: var(--side-text); padding: 9px 10px; border-radius: 8px; font-weight: 500; }
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav a:hover { background: var(--side-2); color: #fff; text-decoration: none; }
.nav a.on { background: var(--side-2); color: #fff; box-shadow: inset 3px 0 0 #4ea1ff; }
.side-foot { margin-top: auto; padding: 14px; border-top: 1px solid rgba(255, 255, 255, .08); }
.conn { display: flex; flex-direction: column; gap: 8px; font-size: 12px; }
.conn-row { display: flex; align-items: center; gap: 8px; color: #dfe8f2; font-weight: 600; }
.conn small { color: #8fa3ba; }
.conn button { background: var(--side-2); border-color: transparent; color: #fff; justify-content: center; }
.conn button:hover { border-color: #4ea1ff; }

.mobilebar { display: none; }
.content { min-width: 0; display: flex; flex-direction: column; }
.page { width: 100%; max-width: 1240px; margin: 0 auto; padding: 28px 32px 48px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head p { margin: 4px 0 0; color: var(--muted); max-width: 70ch; }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 6px; display: flex; gap: 6px; align-items: center; }
.crumbs a { color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-head p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.card-body { padding: 18px; }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; align-items: center; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.grid-2 > .card { margin-bottom: 0; }
.stack { display: grid; gap: 20px; margin-bottom: 20px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; display: flex; gap: 12px; align-items: center; }
.stat-icon { width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; flex: none; background: var(--primary-soft); color: var(--primary); }
.stat-icon svg { width: 20px; height: 20px; }
.stat-icon.pacs { background: var(--pacs-soft); color: var(--pacs); }
.stat-icon.ok { background: var(--ok-soft); color: var(--ok); }
.stat-icon.warn { background: var(--warn-soft); color: var(--warn); }
.stat b { display: block; font-size: 20px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

/* ---------- patient header ---------- */
.patient-hero { display: flex; gap: 16px; align-items: center; padding: 18px; flex-wrap: wrap; }
.avatar { width: 52px; height: 52px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 17px; flex: none; }
.avatar.sm { width: 34px; height: 34px; font-size: 12px; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-top: 6px; font-size: 13px; color: var(--text-2); }
.facts span b { color: var(--muted); font-weight: 500; margin-right: 4px; }
.person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.person b { display: block; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 18px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f5f9ff; }
td .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.act { text-align: right; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 36px 18px; }
.empty svg { width: 34px; height: 34px; display: block; margin: 0 auto 8px; color: var(--line-strong); }

/* ---------- controls ---------- */
button, .btn {
  font: inherit; font-weight: 550; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: var(--radius-sm); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  line-height: 1.2; min-height: 36px; transition: background .12s, border-color .12s, box-shadow .12s;
}
button:hover, .btn:hover { border-color: var(--primary); text-decoration: none; }
button svg, .btn svg { width: 16px; height: 16px; flex: none; }
.btn.primary, button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover, button.primary:hover { background: var(--primary-hover); }
.btn.ghost, button.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover, button.ghost:hover { background: var(--surface-2); border-color: var(--line); }
.btn.sm, button.sm { padding: 5px 10px; min-height: 30px; font-size: 13px; }
button.danger { color: var(--err); }
button.danger:hover { border-color: var(--err); }
button:disabled { opacity: .55; cursor: default; }

label { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 5px; font-weight: 600; }
input, select, textarea {
  font: inherit; width: 100%; min-height: 38px; padding: 8px 11px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(11, 99, 197, .15); }
input:disabled { background: var(--surface-2); color: var(--muted); }
.field { margin-bottom: 14px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 14px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.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; width: 300px; max-width: 100%; }

.dropzone { border: 1.5px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface-2); padding: 22px; text-align: center; cursor: pointer; transition: border-color .12s, background .12s; display: block; font-weight: 500; color: var(--text-2); margin: 0; }
.dropzone:hover, .dropzone.over { border-color: var(--primary); background: var(--primary-soft); }
.dropzone svg { width: 28px; height: 28px; color: var(--primary); display: block; margin: 0 auto 6px; }
.dropzone input { display: none; }
.result-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; font-size: 13px; }

/* ---------- settings layout ---------- */
.settings-section { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 28px; padding: 22px 0; border-bottom: 1px solid var(--line); }
.settings-section:first-child { padding-top: 0; }
.settings-section > div:first-child p { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.save-bar { position: sticky; bottom: 0; z-index: 10; margin-top: 20px; background: rgba(255, 255, 255, .94); backdrop-filter: blur(6px); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 12px 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.save-bar .grow { flex: 1; min-width: 200px; }

/* ---------- badges, alerts, switches ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 650; padding: 2px 9px; border-radius: 999px; background: #edf1f6; color: #3d4b5c; white-space: nowrap; line-height: 1.6; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.pacs { background: var(--pacs-soft); color: var(--pacs); }
.badge.mod { background: var(--primary-soft); color: var(--primary); font-family: var(--mono); font-size: 11px; }
.badge::before { content: none; }
.badge.dotted::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.alert { padding: 10px 14px; border-radius: var(--radius-sm); margin: 0; font-size: 13px; border: 1px solid transparent; display: flex; gap: 8px; align-items: flex-start; }
.alert.ok { background: var(--ok-soft); color: var(--ok); border-color: #bfe5cf; }
.alert.err { background: var(--err-soft); color: var(--err); border-color: #f6c9c5; }
.alert.warn { background: var(--warn-soft); color: var(--warn); border-color: #f3dc9e; }
.alert.info { background: var(--primary-soft); color: var(--primary); border-color: #c5dcf6; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 12px; cursor: pointer; font-weight: 600; color: var(--text); font-size: 14px; margin: 0; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; min-height: 0; }
.switch .track { width: 42px; height: 24px; border-radius: 12px; background: #c3ccd8; position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); transition: left .15s; }
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { left: 21px; }
.switch input:focus-visible + .track { outline: 2px solid var(--primary); outline-offset: 2px; }
.link-toggle { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px; flex-wrap: wrap; }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: #8895a4; flex: none; }
.dot.ok { background: #36d17c; box-shadow: 0 0 0 3px rgba(54, 209, 124, .2); }
.dot.err { background: #ff6b6b; box-shadow: 0 0 0 3px rgba(255, 107, 107, .2); }

details summary { cursor: pointer; font-weight: 600; color: var(--primary); }
pre.code { background: #0f1720; color: #d5e4f2; padding: 14px; border-radius: var(--radius-sm); overflow: auto; font: 12px/1.55 var(--mono); }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 14px; font-size: 13px; align-items: center; }
.kv > span { color: var(--muted); }

.toast { position: fixed; right: 20px; bottom: 20px; width: min(420px, calc(100vw - 32px)); z-index: 60; display: grid; gap: 8px; }
.toast .alert { box-shadow: var(--shadow-lg); animation: toast-in .18s ease-out; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.overlay { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-section { grid-template-columns: 1fr; gap: 12px; }
}

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(280px, 86vw); transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .overlay { display: block; position: fixed; inset: 0; background: rgba(15, 31, 51, .45); z-index: 35; }
  .mobilebar { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 30; background: var(--side); color: #fff; padding: 10px 14px; }
  .mobilebar .brand { padding: 0; }
  .mobilebar button { background: transparent; border-color: rgba(255, 255, 255, .18); color: #fff; min-height: 36px; padding: 6px 9px; }
  .mobilebar .spacer { flex: 1; }
  .mobilebar .dot { margin-right: 2px; }
  .page { padding: 20px 16px 40px; }
  .grid-2 { grid-template-columns: 1fr; }
}

/* Tables collapse into labelled cards on phones. */
@media (max-width: 720px) {
  h1 { font-size: 19px; }
  .page-head { align-items: stretch; }
  .page-head .actions, .search input { width: 100%; }
  .actions > * { flex: 1 1 auto; }
  .card-head, .card-body { padding-left: 14px; padding-right: 14px; }
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  table.responsive tbody tr:last-child { border-bottom: 0; }
  table.responsive td { border: 0; padding: 4px 0; display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 10px; text-align: left; }
  table.responsive td > * { justify-self: start; max-width: 100%; }
  table.responsive td::before { content: attr(data-label); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding-top: 2px; }
  table.responsive td.primary-cell { grid-template-columns: 1fr; padding-bottom: 6px; }
  table.responsive td.primary-cell::before { content: none; }
  table.responsive td.act { justify-content: start; grid-template-columns: 1fr; padding-top: 8px; }
  table.responsive td.act::before { content: none; }
  table.responsive td.act > div { display: flex; gap: 8px; }
  table.responsive td.act .btn { flex: 1; }
  table.responsive td.empty { grid-template-columns: 1fr; }
  table.responsive td.empty::before { content: none; }
  tr.click:hover td { background: transparent; }
  .stats { gap: 10px; }
  .stat { padding: 12px; }
  .stat-icon { width: 32px; height: 32px; }
  .save-bar { position: static; flex-direction: column; align-items: stretch; box-shadow: var(--shadow); }
  .save-bar button { width: 100%; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv > span { margin-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- account box & dialog ---------- */
.user-box { padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px solid rgba(255, 255, 255, .08); display: grid; gap: 8px; }
.user-box:empty { display: none; }
.user-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-row .avatar { background: #24476b; color: #fff; }
.user-meta { min-width: 0; }
.user-meta b { display: block; color: #fff; font-size: 13px; }
.user-meta span { display: block; font-size: 11px; color: #8fa3ba; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-left { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #b9c7d8; }
.session-left svg { width: 14px; height: 14px; }
.session-left.warn { color: #ffcf66; }
.user-actions { display: flex; gap: 6px; }
.user-actions button { flex: 1; background: var(--side-2); border-color: transparent; color: #fff; }
.user-actions button:hover { border-color: #4ea1ff; }
dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(440px, calc(100vw - 32px)); box-shadow: var(--shadow-lg); color: var(--text); }
dialog::backdrop { background: rgba(15, 31, 51, .5); }
