:root {
  --bg: #f3f6fa; --surface: #ffffff; --surface-2: #f8fafc; --border: #e3e8ef; --border-strong: #cfd7e2;
  --text: #17212f; --text-2: #5b6878; --text-3: #8a96a6;
  --primary: #1b64be; --primary-600: #1757ac; --primary-50: #eaf3fe; --primary-100: #cce3fd;
  --side: #0f1f35; --side-2: #172b47; --side-text: #b9c6d8;
  --good: #0a8a1e; --good-bg: #e6f6e9; --warn: #a76a00; --warn-bg: #fff4d9;
  --serious: #c2521d; --serious-bg: #fdeee6; --crit: #c42e2f; --crit-bg: #fdeaea; --info-bg: #eaf3fe;
  --series-1: #257de0; --series-2: #f47230; --series-3: #00b894; --series-4: #f2a600;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 32, 56, .06), 0 1px 8px rgba(16, 32, 56, .04);
  --font: 'Segoe UI', system-ui, -apple-system, Roboto, 'Helvetica Neue', Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
.tnum, td.num, .num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); } .small { font-size: 12px; } .nowrap { white-space: nowrap; }
.right { text-align: right; } .center { text-align: center; }
.hidden { display: none !important; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-hero { background: linear-gradient(150deg, #0f1f35 0%, #1b3f6e 60%, #1b64be 100%); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.login-hero h1 { font-size: 34px; line-height: 1.15; max-width: 460px; }
.login-hero ul { list-style: none; padding: 0; margin: 28px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 24px; color: #d3e2f5; }
.login-hero li::before { content: '✓  '; color: #7fd1ff; }
.login-box { display: flex; align-items: center; justify-content: center; padding: 32px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h2 { font-size: 24px; margin-bottom: 4px; }
.demo-logins { margin-top: 22px; font-size: 12px; color: var(--text-2); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.demo-logins button { all: unset; cursor: pointer; color: var(--primary); margin-right: 10px; line-height: 2; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: #e8f1fd; color: #1b64be; display: grid; place-items: center; font-size: 20px; font-weight: 800; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-text); position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.sidebar .brand { color: #fff; padding: 18px 18px 14px; font-size: 15px; }
.sidebar .brand small { display: block; font-weight: 400; font-size: 11px; color: var(--side-text); }
.nav { padding: 6px 10px 20px; flex: 1; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6f83a0; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--side-text); font-weight: 500; }
.nav a:hover { background: var(--side-2); color: #fff; text-decoration: none; }
.nav a.active { background: #1b64be; color: #fff; }
.nav .ico { width: 20px; text-align: center; font-size: 15px; opacity: .95; }
.nav .count { margin-left: auto; background: #c42e2f; color: #fff; font-size: 11px; border-radius: 10px; padding: 0 7px; line-height: 18px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 58px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 16px; padding: 0 24px; position: sticky; top: 0; z-index: 20; }
.topbar .title { font-size: 17px; font-weight: 600; }
.topbar .spacer { flex: 1; }
.global-search { position: relative; width: 320px; }
.global-search input { width: 100%; padding-left: 32px; }
.global-search::before { content: '⌕'; position: absolute; left: 11px; top: 6px; color: var(--text-3); font-size: 17px; }
.user-chip { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 4px 8px; border-radius: 8px; position: relative; }
.user-chip:hover { background: var(--surface-2); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary-50); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.user-chip .role { font-size: 11px; color: var(--text-2); text-transform: capitalize; }
.dropdown { position: absolute; right: 0; top: 46px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.12); min-width: 190px; padding: 6px; z-index: 40; }
.dropdown button { all: unset; display: block; width: 100%; box-sizing: border-box; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.dropdown button:hover { background: var(--surface-2); }
.content { padding: 22px 24px 48px; }

/* ---------- page parts ---------- */
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { font-size: 21px; }
.page-head .sub { color: var(--text-2); font-size: 13px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.card-head h3 { font-size: 15px; }
.card-head .actions { margin-left: auto; display: flex; gap: 6px; }
.card-body { padding: 16px; }
.card-body.flush { padding: 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)); } .g-2-1 { grid-template-columns: 2fr 1fr; } .g-1-2 { grid-template-columns: 1fr 2fr; }
.mb { margin-bottom: 16px; } .mt { margin-top: 16px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.toolbar input[type=search] { width: 260px; }
.toolbar .spacer { flex: 1; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { all: unset; cursor: pointer; padding: 10px 14px; color: var(--text-2); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.active { color: var(--primary); border-color: var(--primary); }
.tabs button:hover { color: var(--text); }

/* ---------- stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: block; color: inherit; }
a.stat:hover { border-color: var(--primary-100); text-decoration: none; }
.stat .label { color: var(--text-2); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 26px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat .foot { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.meter { height: 6px; border-radius: 3px; background: #e9eef5; margin-top: 8px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--series-1); border-radius: 3px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-weight: 600; font-size: 12px; color: var(--text-2); background: var(--surface-2); padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl tbody tr:hover { background: #f9fbfe; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl .num, .tbl th.num { text-align: right; }
.tbl td .sub { display: block; color: var(--text-2); font-size: 12px; }
.empty { padding: 36px 16px; text-align: center; color: var(--text-2); }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: #eef1f5; color: #4a5566; text-transform: capitalize; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge.good { background: var(--good-bg); color: var(--good); } .badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.serious { background: var(--serious-bg); color: var(--serious); } .badge.crit { background: var(--crit-bg); color: var(--crit); }
.badge.info { background: var(--info-bg); color: var(--primary); } .badge.plain::before { display: none; }

/* ---------- forms ---------- */
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px; min-height: 36px; outline: none; width: 100%; }
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(27, 100, 190, .14); }
input[type=checkbox] { width: auto; min-height: 0; }
.toolbar input, .toolbar select { width: auto; }
label.f { display: block; }
label.f > span { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
label.f > span .req { color: var(--crit); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-grid .span2 { grid-column: span 2; } .form-grid .full { grid-column: 1 / -1; }
.form-section { grid-column: 1 / -1; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); font-weight: 700; padding-top: 6px; border-top: 1px dashed var(--border); margin-top: 2px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.btn { display: inline-flex; align-items: center; gap: 6px; justify-content: center; font: inherit; font-weight: 600; border-radius: 8px; padding: 7px 14px; min-height: 36px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.danger { color: var(--crit); border-color: #f1c6c6; }
.btn.danger:hover { background: var(--crit-bg); }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.sm { padding: 3px 10px; min-height: 28px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- patient picker ---------- */
.picker { position: relative; }
.picker-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); z-index: 60; max-height: 260px; overflow-y: auto; }
.picker-list div { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--border); }
.picker-list div:hover, .picker-list div.hl { background: var(--primary-50); }
.picker-list div:last-child { border-bottom: 0; }
.picked { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border: 1px solid var(--primary-100); background: var(--primary-50); border-radius: 8px; min-height: 36px; }
.picked .x { margin-left: auto; cursor: pointer; color: var(--text-2); font-size: 16px; }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 25, 40, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 100; overflow-y: auto; animation: fade .12s ease-out; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.lg { max-width: 900px; } .modal.xl { max-width: 1140px; } .modal.sm { max-width: 440px; }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); gap: 10px; }
.modal-head h3 { font-size: 17px; }
.modal-head .close { margin-left: auto; all: unset; cursor: pointer; font-size: 22px; color: var(--text-2); line-height: 1; padding: 2px 6px; margin-left: auto; }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-2); border-radius: 0 0 12px 12px; }
@keyframes fade { from { opacity: 0; } }

/* ---------- toast ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #17212f; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 380px; animation: fade .15s; }
.toast.err { background: #a12424; } .toast.ok { background: #0b6b1b; }

/* ---------- info lists ---------- */
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13.5px; }
.kv dt { color: var(--text-2); } .kv dd { margin: 0; }
.pt-banner { display: flex; gap: 16px; align-items: center; padding: 16px; flex-wrap: wrap; }
.pt-banner .avatar { width: 52px; height: 52px; font-size: 18px; }
.pt-banner h2 { font-size: 20px; }
.pt-banner .meta { display: flex; gap: 14px; flex-wrap: wrap; color: var(--text-2); font-size: 13px; margin-top: 2px; }
.alert { padding: 10px 14px; border-radius: 8px; background: var(--warn-bg); color: #6d4600; font-size: 13px; }
.alert.crit { background: var(--crit-bg); color: #8f1d1e; }
.alert.info { background: var(--info-bg); color: #164f96; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 10px 0 10px 18px; border-left: 2px solid var(--border); position: relative; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 15px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--series-1); }
.pre { white-space: pre-wrap; }

/* ---------- bed board ---------- */
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.ward { margin-bottom: 18px; }
.ward-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.ward-head h3 { font-size: 15px; }
.beds { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.bed { border-radius: 9px; padding: 9px 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; min-height: 76px; border-left-width: 4px; }
.bed:hover { box-shadow: 0 4px 14px rgba(16,32,56,.1); }
.bed .no { font-weight: 700; display: flex; justify-content: space-between; align-items: center; }
.bed .no small { font-weight: 500; font-size: 11px; color: var(--text-3); }
.bed .who { font-size: 12.5px; margin-top: 4px; line-height: 1.3; }
.bed .st { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; margin-top: 4px; }
.bed.available { border-left-color: var(--good); } .bed.available .st { color: var(--good); }
.bed.occupied { border-left-color: var(--primary); background: #f6faff; } .bed.occupied .st { color: var(--primary); }
.bed.cleaning { border-left-color: #f2a600; } .bed.cleaning .st { color: var(--warn); }
.bed.maintenance { border-left-color: #8a96a6; background: #f6f7f9; } .bed.maintenance .st { color: #5b6878; }

/* ---------- ICU monitor ---------- */
.icu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.icu-card { background: #0f1b2b; color: #d9e4f2; border-radius: 12px; padding: 14px; border: 1px solid #1f3149; }
.icu-card.alarm { border-color: #dc3c3d; box-shadow: 0 0 0 1px #dc3c3d inset; }
.icu-card .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.icu-card .bedno { font-weight: 700; font-size: 15px; color: #fff; }
.icu-card .pname { font-size: 13px; color: #9fb2c9; }
.vitals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 8px; }
.vital { background: #15263b; border-radius: 8px; padding: 6px 8px; }
.vital .k { font-size: 10.5px; color: #8ea3bd; text-transform: uppercase; letter-spacing: .06em; }
.vital .v { font-size: 21px; font-weight: 650; font-variant-numeric: tabular-nums; color: #fff; }
.vital .v small { font-size: 11px; color: #8ea3bd; font-weight: 500; }
.vital.bad { background: #3a1517; } .vital.bad .v { color: #ff9c9c; }
.icu-alerts { display: flex; gap: 6px; flex-wrap: wrap; min-height: 22px; }
.icu-alerts span { background: #5b1b1d; color: #ffc9c9; border-radius: 6px; font-size: 11.5px; padding: 1px 7px; font-weight: 600; }
.icu-alerts span::before { content: '⚠ '; }
.icu-card .spark { height: 46px; margin-top: 6px; }
.icu-card .foot { display: flex; justify-content: space-between; font-size: 11.5px; color: #8ea3bd; margin-top: 8px; gap: 8px; }
.icu-card .btn { background: #1b3352; border-color: #2a4669; color: #dce8f7; }
.icu-card .btn:hover { background: #24416a; }

/* ---------- charts ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .axis text { fill: var(--text-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .grid line { stroke: #edf1f6; }
.chart .baseline { stroke: #cfd7e2; }
.chart-tip { position: absolute; pointer-events: none; background: #17212f; color: #fff; font-size: 12px; padding: 6px 9px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -100%); margin-top: -10px; z-index: 5; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
.chart-tip b { font-variant-numeric: tabular-nums; }
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; align-items: center; gap: 10px; font-size: 13px; }
.bar-row .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.bar-row .track { height: 12px; position: relative; }
.bar-row .fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-row .val { font-variant-numeric: tabular-nums; color: var(--text-2); font-size: 12.5px; min-width: 56px; text-align: right; }
.bar-row:hover .fill { filter: brightness(.9); }
.chart-legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.chart-legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }

/* ---------- queue ---------- */
.queue-item { display: flex; gap: 12px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.queue-item:last-child { border-bottom: 0; }
.token { width: 38px; height: 38px; border-radius: 9px; background: var(--primary-50); color: var(--primary); font-weight: 700; display: grid; place-items: center; flex: none; font-variant-numeric: tabular-nums; }
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
.slot { all: unset; text-align: center; padding: 6px 0; border: 1px solid var(--border-strong); border-radius: 7px; cursor: pointer; font-variant-numeric: tabular-nums; font-size: 13px; }
.slot:hover { border-color: var(--primary); }
.slot.sel { background: var(--primary); border-color: var(--primary); color: #fff; }
.slot.booked { background: #f1f3f6; color: #a8b1bd; cursor: not-allowed; text-decoration: line-through; }
.items-table input, .items-table select { min-height: 32px; padding: 4px 8px; }
.total-box { margin-left: auto; width: 320px; }
.total-box .row { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }
.total-box .row.grand { font-size: 17px; font-weight: 700; border-top: 1px solid var(--border); padding-top: 8px; margin-top: 4px; }
.loading { padding: 40px; text-align: center; color: var(--text-2); }
.result-flag { font-weight: 700; }
.result-flag.high, .result-flag.low { color: var(--serious); } .result-flag.critical { color: var(--crit); }

@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, 1fr); } .g-2-1, .g-1-2, .g3 { grid-template-columns: 1fr; } }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; } .sidebar { position: fixed; left: -260px; width: 250px; z-index: 90; transition: left .2s; }
  .app.nav-open .sidebar { left: 0; } .menu-btn { display: inline-flex !important; } .global-search { display: none; }
  .g2 { grid-template-columns: 1fr; } .form-grid, .form-grid.c3, .form-grid.c4 { grid-template-columns: 1fr; } .form-grid .span2 { grid-column: auto; }
  .login-wrap { grid-template-columns: 1fr; } .login-hero { display: none; }
}
.menu-btn { display: none !important; }
