/* Scalenex RPM — brand palette taken from the Scalenex logo */
:root {
  --navy: #0b1f45;
  --navy-2: #12305f;
  --blue: #0e6c9c;
  --teal: #12b2be;
  --teal-soft: #e3f6f7;
  --ink: #142037;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f3f6f9;
  --card: #ffffff;
  --crit: #c93838;
  --crit-soft: #fdecec;
  --warn: #b7791f;
  --warn-soft: #fdf3e1;
  --ok: #17885b;
  --ok-soft: #e4f5ec;
  --info: #0e6c9c;
  --info-soft: #e5f1f8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(11, 31, 69, .06), 0 1px 8px rgba(11, 31, 69, .04);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { color: var(--navy); margin: 0; font-weight: 600; }
h1 { font-size: 22px; letter-spacing: -.01em; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 { font-size: 17px; }
h3 { font-size: 15px; margin-bottom: 10px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.boot { padding: 40px; color: var(--muted); }
.crit-text { color: var(--crit); }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; color: var(--navy); font: 600 13px var(--font); cursor: pointer;
  text-decoration: none !important; white-space: nowrap;
}
.btn:hover { border-color: var(--teal); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: linear-gradient(135deg, var(--blue), var(--teal)); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; justify-content: center; padding: 11px; font-size: 14px; }

input, select, textarea {
  font: 14px var(--font); color: var(--ink); padding: 8px 10px; border: 1px solid #cfd8e3; border-radius: 8px;
  background: #fff; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--teal); outline-offset: 1px; border-color: var(--teal);
}
input[type=checkbox] { width: auto; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 600; color: #3b4a63; }
label.check { flex-direction: row; align-items: center; gap: 6px; font-weight: 500; }
.inline-field { flex-direction: row; align-items: center; gap: 8px; }
.inline-field select, .inline-field input { width: auto; max-width: 340px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-brand {
  background: radial-gradient(circle at 20% 10%, #16467e 0, var(--navy) 55%), var(--navy);
  color: #d9e6f5; padding: 64px 56px; display: flex; flex-direction: column; justify-content: center;
}
.login-mark { width: 92px; height: auto; background: #fff; border-radius: 18px; padding: 10px; margin-bottom: 28px; }
.login-brand h1 { color: #fff; font-size: 34px; margin-bottom: 12px; }
.login-brand p { font-size: 16px; max-width: 460px; color: #b9cbe2; }
.login-brand ul { padding: 0; list-style: none; margin: 18px 0 0; }
.login-brand li { padding: 6px 0 6px 26px; position: relative; }
.login-brand li::before { content: ""; position: absolute; left: 0; top: 12px; width: 12px; height: 12px; border-radius: 3px; background: var(--teal); }
.login-form { display: flex; align-items: center; justify-content: center; padding: 32px 16px; }
.login-form .card { width: 100%; max-width: 400px; padding: 32px; display: flex; flex-direction: column; gap: 14px; }
.login-logo { width: 240px; max-width: 100%; margin: 0 auto 6px; display: block; }
.login-form h2 { text-align: center; }
.form-error { color: var(--crit); min-height: 1em; margin: 0; font-size: 13px; }
.fine { font-size: 11.5px; color: var(--muted); margin: 10px 0 0; }

/* ---------- Shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; height: 60px; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px; padding: 0 20px;
}
.brand img { height: 34px; display: block; }
.product { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--blue);
  background: var(--teal-soft); padding: 4px 10px; border-radius: 99px; }
.spacer { flex: 1; }
.who { text-align: right; line-height: 1.25; }
.who strong { display: block; color: var(--navy); font-size: 13.5px; }
.who small { color: var(--muted); font-size: 11.5px; }
.menu-btn { display: none; border: 0; background: none; font-size: 22px; color: var(--navy); cursor: pointer; }

.layout { display: grid; grid-template-columns: 236px 1fr; min-height: calc(100vh - 60px); }
.sidebar { background: var(--navy); padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 60px; height: calc(100vh - 60px); overflow-y: auto; }
.sidebar a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: #c4d3e6; font-weight: 500; text-decoration: none; }
.sidebar a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar a.active { background: linear-gradient(90deg, rgba(18, 178, 190, .25), rgba(18, 178, 190, .05)); color: #fff; box-shadow: inset 3px 0 0 var(--teal); }
.nav-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: #6f86a6; padding: 14px 12px 4px; font-weight: 700; }
.nav-foot { margin-top: auto; font-size: 11px; color: #6f86a6; padding: 12px; }
.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

main { padding: 24px 28px 48px; min-width: 0; transition: opacity .15s; }
main.loading { opacity: .55; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.sub { margin: 4px 0 0; color: var(--muted); }
.head-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.back { display: inline-block; margin-bottom: 10px; font-weight: 600; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin: 22px 0 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.stack > .card:last-child { margin-bottom: 0; }
.empty { text-align: center; color: var(--muted); padding: 28px; }
.empty.small { padding: 40px 10px; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); border-top: 3px solid var(--blue); }
.kpi span { display: block; color: var(--muted); font-size: 12px; font-weight: 600; }
.kpi strong { display: block; font-size: 28px; color: var(--navy); font-weight: 650; line-height: 1.2; margin-top: 4px; }
.kpi small { color: var(--muted); font-size: 12px; }
.kpi.crit { border-top-color: var(--crit); } .kpi.crit strong { color: var(--crit); }
.kpi.warn { border-top-color: var(--warn); }
.kpi.ok { border-top-color: var(--teal); }
.kpis.small .kpi strong { font-size: 22px; }

/* ---------- Tables ---------- */
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type=search] { max-width: 340px; }
.count { margin-left: auto; color: var(--muted); font-size: 12.5px; }
.table-wrap { overflow-x: auto; }
.table-wrap.scroll { max-height: 460px; overflow-y: auto; }
.table-wrap.scroll.short { max-height: 220px; }
.table-wrap.scroll.tall { max-height: 640px; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line); background: #fafbfd; position: sticky; top: 0; z-index: 1; white-space: nowrap; }
.table td { padding: 11px 10px; border-bottom: 1px solid #eef2f6; vertical-align: top; }
.table.compact td { padding: 7px 10px; }
.table.clickable tbody tr { cursor: pointer; }
.table.clickable tbody tr:hover td { background: #f6fafc; }
.table tr.acknowledged td { opacity: .7; }
.pname { font-weight: 600; color: var(--navy); }
.dx { max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
td.stale { color: var(--warn); font-weight: 600; }

.vital { display: inline-block; margin: 2px 6px 2px 0; padding: 2px 8px; border-radius: 6px; background: #f1f5f9; font-size: 12.5px; white-space: nowrap; }
.vital b { color: var(--muted); font-weight: 700; font-size: 11px; margin-right: 2px; }
.vital.warning { background: var(--warn-soft); color: #7a4f0e; }
.vital.critical { background: var(--crit-soft); color: var(--crit); font-weight: 600; }

.days { display: flex; align-items: center; gap: 8px; min-width: 110px; }
.days span { font-size: 12.5px; font-variant-numeric: tabular-nums; }
.progress { width: 80px; height: 6px; display: block; }
.progress .bg { fill: #e6ebf1; }
.progress .fg { fill: var(--blue); }
.progress.done .fg { fill: var(--ok); }
.billing-box .progress { width: 100%; margin: 4px 0 10px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; white-space: nowrap; text-transform: capitalize; vertical-align: middle; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.crit { background: var(--crit-soft); color: var(--crit); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.muted { background: #eef1f5; color: var(--muted); }
.badge.code { background: var(--navy); color: #fff; font-family: var(--mono); text-transform: none; margin: 2px 4px 2px 0; }

/* ---------- Patient ---------- */
.patient-head { display: grid; grid-template-columns: 1fr 280px; gap: 24px; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 20px; margin-top: 8px; color: #334155; }
.facts b { color: var(--muted); font-weight: 600; font-size: 12px; margin-right: 4px; }
.billing-box { background: #f7fafc; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.bb-title { font-weight: 700; color: var(--navy); font-size: 13px; margin-bottom: 8px; }
.bb-row { display: flex; justify-content: space-between; font-size: 13px; }

.alert-strip { border-left: 4px solid var(--crit); }
.alert-row { display: flex; gap: 12px; align-items: center; padding: 8px 0; border-top: 1px solid #f0f2f5; flex-wrap: wrap; }
.alert-row .msg { flex: 1; min-width: 200px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: none; padding: 6px 12px; font: 600 12.5px var(--font); color: var(--muted); cursor: pointer; text-transform: capitalize; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--navy); color: #fff; }

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.charts .card { margin-bottom: 0; }
.charts + .grid2 { margin-top: 16px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.chart-stats { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.chart-stats b { color: var(--navy); }
.chart-stats b.warning { color: var(--warn); } .chart-stats b.critical { color: var(--crit); }
svg.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: #edf1f5; }
.chart .axis { fill: #8a97ab; font-size: 11px; font-family: var(--font); }
.chart .threshold { stroke: var(--warn); stroke-dasharray: 5 4; stroke-width: 1.2; opacity: .8; }
.chart .threshold-label { fill: var(--warn); font-size: 10.5px; font-weight: 600; font-family: var(--font); }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; }
.chart .line.s0 { stroke: var(--blue); } .chart .line.s1 { stroke: var(--teal); }
.chart .dot { stroke: #fff; stroke-width: 1.2; }
.chart .dot.s0 { fill: var(--blue); } .chart .dot.s1 { fill: var(--teal); }
.chart .dot.warning { fill: #e0a21b; } .chart .dot.critical { fill: var(--crit); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.sw { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.sw.s0 { background: var(--blue); } .sw.s1 { background: var(--teal); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.grid2.wide-left { grid-template-columns: 1.6fr 1fr; }
.device { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid #f0f2f5; }
.device.past { opacity: .55; }
.device-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.inline-form { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 160px; }
.time-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.time-form input[name=minutes] { width: 76px; }
.time-form select { width: auto; }
.time-form .grow { flex: 1; min-width: 140px; }
details.card summary { cursor: pointer; list-style: none; }
details.card summary h3 { display: inline; }
details.card summary::after { content: "▾"; color: var(--muted); margin-left: 6px; }
.thresholds { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
.thresholds .full { grid-column: 1 / -1; }

/* ---------- Forms ---------- */
.form-grid fieldset { border: 0; padding: 0; margin: 0 0 20px; display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 16px; }
.form-grid legend { font-weight: 700; color: var(--navy); font-size: 15px; margin-bottom: 12px; padding: 0; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.form-grid.one { display: flex; flex-direction: column; gap: 12px; }
.form-grid.one h3 { margin: 0; }
.narrow { max-width: 420px; }
.device-row { display: grid; grid-template-columns: 2fr 1fr 2fr; gap: 12px; margin-bottom: 10px; }
.success { background: var(--ok-soft); border: 1px solid #b9e2cd; border-radius: 8px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.route-chain > div { padding: 2px 0; }
.trace { margin-top: 12px; padding: 12px 14px; border-radius: 8px; }
.trace.ok { background: var(--ok-soft); }
.trace.warn { background: var(--warn-soft); }

.flow .steps { list-style: none; padding: 0; margin: 6px 0 0; display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; counter-reset: s; }
.flow .steps li { background: #f6f9fc; border: 1px solid var(--line); border-radius: 8px; padding: 12px; position: relative; counter-increment: s; }
.flow .steps li::before { content: counter(s); position: absolute; top: 10px; right: 12px; font-weight: 700; color: var(--teal); }
.flow .steps b { display: block; color: var(--navy); }
.flow .steps span { font-size: 12.5px; color: var(--muted); }

pre.code { background: var(--navy); color: #d6e6f7; padding: 12px 14px; border-radius: 8px; overflow-x: auto; font: 12.5px/1.5 var(--mono); }
code.payload { display: block; max-width: 520px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 30px); background: var(--navy); color: #fff; padding: 11px 18px; border-radius: 8px; font-weight: 600; opacity: 0; pointer-events: none; transition: all .2s; z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--crit); }
#toast.warn { background: var(--warn); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid2, .grid2.wide-left, .patient-head { grid-template-columns: 1fr; }
  .flow .steps { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 820px) {
  .login { grid-template-columns: 1fr; }
  .login-brand { padding: 36px 24px; }
  .login-brand h1 { font-size: 26px; }
  .layout { grid-template-columns: 1fr; }
  .menu-btn { display: block; }
  .sidebar { position: fixed; left: 0; top: 60px; bottom: 0; width: 250px; transform: translateX(-100%); transition: transform .2s; z-index: 30; height: auto; }
  .sidebar.open { transform: none; }
  .who small { display: none; }
  .product { font-size: 10px; letter-spacing: .04em; padding: 3px 7px; white-space: nowrap; }
  .who { min-width: 0; }
  .who strong { display: block; max-width: 26vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  main { padding: 16px; }
  .charts { grid-template-columns: 1fr; }
  .device-row { grid-template-columns: 1fr; }
  .brand img { height: 24px; }
}

/* ---------- v2: MioConnect ---------- */
.warn-text { color: var(--warn); font-weight: 600; }
.warn-box, .ok-box { border-radius: 8px; padding: 10px 12px; margin-top: 10px; }
.warn-box { background: var(--warn-soft); color: #6b4a12; }
.ok-box { background: var(--ok-soft); color: #155c41; }
.warn-box ul, .ok-box ul { margin: 6px 0 0; padding-left: 18px; }
.health { margin-top: 2px; }
.health-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.health-grid > div { background: #f7fafc; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.health-grid span { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.health-grid b { font-size: 17px; color: var(--navy); }
.table.kv th { position: static; width: 38%; text-transform: none; letter-spacing: 0; font-size: 13px; color: #3b4a63; background: #fafbfd; border-bottom: 1px solid #eef2f6; white-space: normal; }
.table.kv code { word-break: break-all; }
h3.flush { margin: 0; }
input[type=file] { padding: 6px; background: #f7fafc; }
