:root {
  --bg: #eef2f6; --panel: #fff; --ink: #14202e; --muted: #5d6b7b; --line: #d9e0e8; --soft: #f6f8fb;
  --brand: #19456b; --accent: #1e6b52; --warn: #b45309; --warn-bg: #fff7e6; --crit: #b42318; --crit-bg: #fdecea;
  --info: #1d4ed8; --info-bg: #eaf1ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
button { font: inherit; cursor: pointer; }
.muted { color: var(--muted); }

.bar { height: 46px; display: flex; align-items: center; gap: 14px; padding: 0 14px; background: var(--brand); color: #fff; }
.brand { font-weight: 800; font-size: 18px; letter-spacing: .2px; }
.brand span { color: #8fe3c6; font-weight: 600; margin-left: 2px; }
.env { font-size: 12px; background: #fef3c7; color: #78350f; padding: 2px 8px; border-radius: 4px; font-weight: 600; }
.home { margin-left: auto; color: #cfe3f5; text-decoration: none; font-size: 13px; }
.icon-btn { display: none; background: none; border: 0; color: #fff; font-size: 20px; }

.layout { display: grid; grid-template-columns: 270px minmax(0, 1fr) 400px; height: calc(100% - 46px); }
.patients { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.search { padding: 10px; }
.search input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.filters { display: flex; gap: 4px; padding: 0 10px 8px; }
.filters button { flex: 1; border: 1px solid var(--line); background: var(--soft); border-radius: 5px; padding: 3px; font-size: 12px; }
.filters button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
#plist { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
#plist li { padding: 8px 12px; border-top: 1px solid #edf1f5; cursor: pointer; }
#plist li:hover { background: var(--soft); }
#plist li.on { background: #e3eef8; box-shadow: inset 3px 0 var(--brand); }
#plist .n { font-weight: 600; }
#plist .d { color: var(--muted); font-size: 12px; }
#plist .tag { font-size: 10px; font-weight: 700; color: var(--accent); text-transform: uppercase; margin-left: 4px; }

.chart { overflow: auto; min-width: 0; }
.welcome { max-width: 640px; margin: 60px auto; padding: 0 24px; }
.welcome h1 { color: var(--brand); }

.banner { background: var(--panel); border-bottom: 1px solid var(--line); padding: 12px 18px; display: flex; flex-wrap: wrap; gap: 6px 22px; align-items: baseline; position: sticky; top: 0; z-index: 2; }
.banner .who { font-size: 20px; font-weight: 700; }
.banner .facts { color: var(--muted); }
.banner .facts b { color: var(--ink); font-weight: 600; }
.chip { display: inline-block; border-radius: 4px; padding: 1px 7px; font-size: 12px; font-weight: 600; }
.chip.allergy { background: var(--crit-bg); color: var(--crit); }
.chip.nka { background: #e8f5ee; color: var(--accent); }
.chip.syn { background: #fef3c7; color: #78350f; }

.cards { padding: 10px 18px 0; display: grid; gap: 8px; }
.cds { border-radius: 8px; padding: 10px 12px 10px 14px; border-left: 5px solid; background: var(--panel); box-shadow: 0 1px 2px rgba(0,0,0,.06); display: flex; gap: 10px; }
.cds.info { border-color: var(--info); background: var(--info-bg); }
.cds.warning { border-color: var(--warn); background: var(--warn-bg); }
.cds.critical { border-color: var(--crit); background: var(--crit-bg); }
.cds .s { font-weight: 700; }
.cds .src { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.cds .x { margin-left: auto; background: none; border: 0; color: var(--muted); }

.tabs { display: flex; gap: 2px; padding: 12px 18px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 1px solid transparent; border-bottom: 0; background: none; padding: 7px 14px; border-radius: 6px 6px 0 0; color: var(--muted); white-space: nowrap; }
.tabs button.on { background: var(--panel); border-color: var(--line); color: var(--ink); font-weight: 600; margin-bottom: -1px; }
.pane { padding: 16px 18px 40px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.box { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.box h3 { margin: 0; padding: 8px 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: var(--brand); background: var(--soft); border-bottom: 1px solid var(--line); }
.box .body { padding: 8px 12px; }
.box ul { margin: 0; padding: 0; list-style: none; }
.box li { padding: 5px 0; border-top: 1px solid #f0f3f6; display: flex; gap: 8px; justify-content: space-between; }
.box li:first-child { border-top: 0; }
.box li .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.empty { color: var(--muted); font-style: italic; padding: 4px 0; }

table.data { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
table.data th, table.data td { text-align: left; padding: 6px 10px; border-top: 1px solid #edf1f5; vertical-align: middle; }
table.data th { background: var(--soft); font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .3px; border-top: 0; }
table.data tr.click { cursor: pointer; }
table.data tr.click:hover td { background: #f3f8fd; }
.flag { color: var(--crit); font-weight: 700; }
.spark { vertical-align: middle; }
.bigchart { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 14px; }

.timeline { position: relative; margin-left: 10px; border-left: 2px solid var(--line); padding-left: 18px; }
.tl { position: relative; margin-bottom: 14px; }
.tl::before { content: ""; position: absolute; left: -25px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); border: 2px solid #fff; }
.tl .when { font-size: 12px; color: var(--muted); }
.tl .what { font-weight: 600; }

.note { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 12px; }
.note summary { padding: 10px 12px; cursor: pointer; font-weight: 600; }
.note summary span { color: var(--muted); font-weight: 400; margin-left: 8px; }
.note pre, .note .txt { margin: 0; padding: 0 14px 14px; white-space: pre-wrap; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }

.widgets { background: var(--soft); border-left: 1px solid var(--line); overflow: auto; padding: 10px; }
.whead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.small { border: 1px solid var(--line); background: var(--panel); border-radius: 5px; padding: 3px 10px; font-size: 12px; }
.w { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 10px; overflow: hidden; }
.w .wt { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: #f1f5f9; border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 600; }
.w .wt a { color: var(--muted); text-decoration: none; }
.w .wt .sp { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w .wt button { background: none; border: 0; color: var(--muted); padding: 0 2px; }
.w iframe { width: 100%; height: 420px; border: 0; display: block; background: #fff; }
.wempty { color: var(--muted); text-align: center; padding: 30px 12px; font-size: 13px; }

dialog { border: 0; border-radius: 12px; padding: 0; width: min(520px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.pick { padding: 18px 20px; }
.pick h2 { margin: 0 0 4px; }
#choices { max-height: 46vh; overflow: auto; margin: 10px 0; }
.choice { display: block; width: 100%; text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; }
.choice:hover { border-color: var(--brand); }
.choice b { display: block; }
.choice .muted { font-size: 12px; }
.pick label { display: block; font-weight: 600; margin-top: 6px; }
.pick input { width: 100%; margin-top: 4px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.pick .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.pick .row button { border: 0; border-radius: 6px; padding: 7px 16px; background: var(--brand); color: #fff; }
.pick .row .ghost { background: #e8edf2; color: var(--ink); }

@media (max-width: 1150px) {
  .layout { grid-template-columns: 250px minmax(0, 1fr); grid-template-rows: auto; height: auto; min-height: calc(100% - 46px); }
  .widgets { grid-column: 2; border-left: 0; border-top: 1px solid var(--line); }
  .chart { overflow: visible; }
  .patients { position: sticky; top: 0; height: calc(100vh - 46px); grid-row: span 2; }
}
@media (max-width: 760px) {
  .icon-btn { display: block; }
  .env { display: none; }
  .layout { grid-template-columns: 1fr; }
  .widgets { grid-column: 1; }
  .patients { position: fixed; top: 46px; left: 0; bottom: 0; width: 86vw; max-width: 320px; z-index: 20; height: auto;
              transform: translateX(-100%); transition: transform .25s; box-shadow: 4px 0 20px rgba(0,0,0,.15); }
  body.menu .patients { transform: none; }
  .grid { grid-template-columns: 1fr; }
}
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: r 1s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes r { to { transform: rotate(360deg); } }
