/* Track2Care CRM design system — "Ward".
 * Fluid type: everything is in rem and the root size grows with the viewport,
 * so the same layout is crisp on a phone, a 1080p desk monitor and a 4K/5K wall display. */

:root {
  /* Palette sampled from the Track2Care Amplify dashboard. */
  --bg: #eef2f7; --surface: #ffffff; --surface-2: #f5f8fc; --line: #d5e0ec; --line-2: #b8cce0;
  --ink: #0e1525; --ink-2: #44546b;
  --ink-3: #72829a;
  --brand: #1d6fa4; --brand-ink: #14557f; --brand-soft: #e8f0f6; --on-brand: #ffffff;
  --rail: #0e1525; --rail-2: #131e32; --rail-ink: #9db2d0; --rail-ink-strong: #ffffff;
  --ok: #16a34a; --ok-soft: #dcf4e6;
  --warn: #d97706; --warn-soft: #fdf0d9;
  --crit: #dc2626; --crit-soft: #fde2e2;
  --info: #2563eb; --info-soft: #e0eaff;
  --mute: #7d8ba0; --mute-soft: #e6ecf4;
  --role: var(--brand);
  --shadow: 0 1px 2px rgba(14, 21, 37, .06), 0 8px 24px -12px rgba(14, 21, 37, .18);
  --shadow-lg: 0 24px 60px -20px rgba(8, 13, 24, .55);
  --r-s: .4rem; --r-m: .65rem; --r-l: 1rem;
  --font: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Bricolage Grotesque", "Figtree", system-ui, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #080d18; --surface: #0e1525; --surface-2: #131e32; --line: #1c2840; --line-2: #2a3b5e;
  --ink: #e6edf7; --ink-2: #9fb0c8; --ink-3: #6b7e9c;
  --brand: #3b82f6; --brand-ink: #7fb0ff; --brand-soft: #13203a; --on-brand: #ffffff;
  --rail: #0e1525; --rail-2: #131e32; --rail-ink: #9db2d0; --rail-ink-strong: #ffffff;
  --ok: #22c55e; --ok-soft: #0f2e22;
  --warn: #f59e0b; --warn-soft: #35280c;
  --crit: #ef4444; --crit-soft: #2f1620;
  --info: #60a5fa; --info-soft: #13203a;
  --mute: #7a8aa6; --mute-soft: #131e32;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .6);
  --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, .8);
  color-scheme: dark;
}
body[data-role="global-admin"] { --role: #a855f7; }
body[data-role="super-user"] { --role: var(--brand); }
body[data-role="normal-user"] { --role: #16a34a; }

*, *::before, *::after { box-sizing: border-box; }
html { font-size: clamp(15px, .3vw + 12px, 26px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 400 1rem/1.5 var(--font);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; font-family: var(--font-display); font-weight: 650; letter-spacing: -.015em; line-height: 1.15; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: .15rem solid var(--role); outline-offset: .15rem; border-radius: var(--r-s); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num { font-family: var(--font-display); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.muted { color: var(--ink-2); } .faint { color: var(--ink-3); }
.row { display: flex; align-items: center; gap: .6rem; } .row.wrap { flex-wrap: wrap; } .grow { flex: 1 1 auto; min-width: 0; }
.col { display: flex; flex-direction: column; gap: .6rem; }
.right { margin-left: auto; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── icons ── */
.ico { width: 1.15em; height: 1.15em; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ── app shell ── */
.app { display: grid; grid-template-columns: 15.5rem minmax(0, 1fr); min-height: 100vh; }
.rail {
  background: var(--rail); color: var(--rail-ink); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; padding: 1.1rem .8rem; gap: .25rem; z-index: 30;
}
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: .35rem; padding: .3rem .5rem 1.1rem; color: var(--rail-ink-strong); }
.brand .logo { height: 2rem; width: auto; display: block; }
.brand b { font: 650 1.12rem var(--font-display); letter-spacing: -.02em; }
.brand small { display: block; font-size: .74rem; font-weight: 600; color: var(--rail-ink); padding-left: .15rem; }
.rail nav { display: flex; flex-direction: column; gap: .15rem; }
.rail a.nav {
  display: flex; align-items: center; gap: .7rem; padding: .62rem .75rem; border-radius: var(--r-m);
  color: var(--rail-ink); text-decoration: none; font-weight: 500; position: relative;
}
.rail a.nav:hover { background: var(--rail-2); color: var(--rail-ink-strong); }
.rail a.nav[aria-current="page"] { background: var(--rail-2); color: var(--rail-ink-strong); }
.rail a.nav[aria-current="page"]::before {
  content: ""; position: absolute; left: -.8rem; top: .55rem; bottom: .55rem; width: .22rem; border-radius: 0 .2rem .2rem 0; background: var(--role-bright, #60a5fa);
}
body[data-role="global-admin"] { --role-bright: #c084fc; }
body[data-role="normal-user"] { --role-bright: #4ade80; }
.rail .badge { margin-left: auto; background: var(--crit); color: #fff; font-size: .72rem; font-weight: 700; border-radius: 99rem; padding: .05rem .45rem; }
.rail .sect { font-size: .78rem; color: #6b82a6; padding: .9rem .75rem .3rem; font-weight: 600; }
.rail .foot { margin-top: auto; border-top: 1px solid #ffffff1c; padding-top: .8rem; display: flex; align-items: center; gap: .6rem; }
.rail .foot .who { min-width: 0; flex: 1; line-height: 1.2; }
.rail .foot .who b { display: block; color: var(--rail-ink-strong); font-weight: 600; font-size: .9rem; }
.rail .foot .who span { font-size: .78rem; }
.rail .iconbtn { background: transparent; border: 0; color: var(--rail-ink); padding: .45rem; border-radius: var(--r-s); display: grid; place-items: center; }
.rail .iconbtn:hover { background: var(--rail-2); color: #fff; }

.main { min-width: 0; display: flex; flex-direction: column; }
.top {
  display: flex; align-items: center; gap: 1rem; padding: .9rem 1.6rem; position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 1.45rem; }
.top .sub { color: var(--ink-2); font-size: .9rem; }
.search { position: relative; margin-left: auto; width: min(26rem, 40vw); }
.search input { width: 100%; padding: .55rem .8rem .55rem 2.3rem; border-radius: 99rem; border: 1px solid var(--line-2); background: var(--surface); }
.search .ico { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.search kbd { position: absolute; right: .7rem; top: 50%; transform: translateY(-50%); font: 600 .7rem var(--font); color: var(--ink-3); border: 1px solid var(--line-2); border-radius: .3rem; padding: .05rem .35rem; }
.page { padding: 1.5rem 1.6rem 4rem; display: flex; flex-direction: column; gap: 1.4rem; width: 100%; }

/* ── buttons & fields ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem; border: 1px solid var(--line-2); background: var(--surface);
  color: var(--ink); padding: .52rem .95rem; border-radius: var(--r-m); font-weight: 600; transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--role); border-color: var(--role); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); background: var(--role); }
.btn.danger { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 40%, var(--line)); }
.btn.danger:hover { background: var(--crit-soft); }
.btn.solid-danger { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn.small { padding: .3rem .65rem; font-size: .88rem; border-radius: var(--r-s); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--mute-soft); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.iconbtn { background: transparent; border: 0; padding: .45rem; border-radius: var(--r-s); color: var(--ink-2); display: grid; place-items: center; }
.iconbtn:hover { background: var(--mute-soft); color: var(--ink); }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field > label { font-weight: 600; font-size: .9rem; }
.field .hint { font-size: .82rem; color: var(--ink-3); }
.input, select.input, textarea.input {
  width: 100%; padding: .6rem .75rem; border-radius: var(--r-m); border: 1px solid var(--line-2); background: var(--surface); min-height: 2.5rem;
}
textarea.input { min-height: 5rem; resize: vertical; }
.input:focus { outline: none; border-color: var(--role); box-shadow: 0 0 0 .18rem color-mix(in srgb, var(--role) 25%, transparent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; } .grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; }
.msg { padding: .6rem .8rem; border-radius: var(--r-m); font-size: .92rem; }
.msg.err { background: var(--crit-soft); color: var(--crit); } .msg.ok { background: var(--ok-soft); color: var(--ok); } .msg.info { background: var(--info-soft); color: var(--info); }

/* ── pills / avatar / ring ── */
.pill { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; font-weight: 650; padding: .12rem .6rem; border-radius: 99rem; background: var(--mute-soft); color: var(--ink-2); white-space: nowrap; }
.pill::before { content: ""; width: .45rem; height: .45rem; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); } .pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.crit { background: var(--crit-soft); color: var(--crit); } .pill.info { background: var(--info-soft); color: var(--info); }
.pill.role { background: color-mix(in srgb, var(--role) 14%, transparent); color: var(--role); }
.pill.plain::before { display: none; }
.avatar { width: 2.4rem; height: 2.4rem; border-radius: 50%; display: grid; place-items: center; font: 650 .9rem var(--font-display); color: #fff; flex: none; background: hsl(var(--h, 180) 45% 38%); }
.avatar.lg { width: 4rem; height: 4rem; font-size: 1.4rem; }
.avatar.sm { width: 1.9rem; height: 1.9rem; font-size: .75rem; }

/* ── stat strip (not cards: one band, dividers carry the structure) ── */
.strip { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); box-shadow: var(--shadow); overflow: hidden; }
.strip > div { padding: 1.05rem 1.3rem; border-left: 1px solid var(--line); min-width: 0; }
.strip > div:first-child { border-left: 0; }
.strip .v { font: 650 2.3rem/1 var(--font-display); letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.strip .l { color: var(--ink-2); font-size: .9rem; margin-top: .3rem; }
.strip .v.crit { color: var(--crit); } .strip .v.warn { color: var(--warn); } .strip .v.ok { color: var(--ok); }
.strip .d { font-size: .8rem; color: var(--ink-3); }

/* ── panels ── */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); box-shadow: var(--shadow); }
.panel > header { display: flex; align-items: center; gap: .7rem; padding: .95rem 1.2rem; border-bottom: 1px solid var(--line); }
.panel > header h2, .panel > header h3 { font-size: 1.08rem; white-space: nowrap; }
.panel > header .faint, .panel > header .muted { white-space: nowrap; font-size: .88rem; }
.panel .body { padding: 1.1rem 1.2rem; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 22rem; gap: 1.4rem; align-items: start; }
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.seg { display: inline-flex; background: var(--mute-soft); border-radius: var(--r-m); padding: .2rem; gap: .1rem; }
.seg button { border: 0; background: transparent; padding: .35rem .8rem; border-radius: calc(var(--r-m) - .15rem); font-weight: 600; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px #0002; }

/* ── ward board ── */
.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(17.5rem, 1fr)); gap: 1rem; }
.pt {
  position: relative; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); padding: 1rem 1rem .9rem;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .7rem; transition: transform .12s, box-shadow .12s, border-color .12s; width: 100%;
}
.pt:hover { transform: translateY(-2px); border-color: var(--line-2); box-shadow: 0 2px 4px rgba(14,21,37,.08), 0 18px 36px -16px rgba(14,21,37,.3); }
.pt .head { display: flex; align-items: center; gap: .75rem; }
.pt .name { font: 650 1.05rem var(--font-display); }
.pt .meta { font-size: .84rem; color: var(--ink-2); }
.pt .vit { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.pt .vit div { background: var(--surface-2); border-radius: var(--r-m); padding: .45rem .55rem; }
.pt .vit .k { font-size: .72rem; color: var(--ink-3); font-weight: 600; }
.pt .vit .n { font: 650 1.2rem/1.15 var(--font-display); font-variant-numeric: tabular-nums; }
.pt .vit .n small { font: 500 .7rem var(--font); color: var(--ink-3); margin-left: .12rem; }
.pt .vit .n.crit { color: var(--crit); } .pt .vit .n.warn { color: var(--warn); }
.pt .foot { display: flex; align-items: center; gap: .5rem; font-size: .8rem; color: var(--ink-3); }
.pt .ring { position: absolute; inset: 0; border-radius: inherit; pointer-events: none; }
.pt[data-s="critical"] { border-color: color-mix(in srgb, var(--crit) 55%, var(--line)); background: linear-gradient(180deg, var(--crit-soft), var(--surface) 55%); }
.pt[data-s="warning"] { border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); }
.pt[data-s="critical"] .alertbar { display: flex; }
.alertbar { display: none; align-items: center; gap: .4rem; background: var(--crit); color: #fff; font-weight: 700; font-size: .82rem; border-radius: var(--r-s); padding: .25rem .6rem; }
@keyframes beat { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
.pt[data-s="critical"] .alertbar .ico { animation: beat 1.1s infinite; }
.spark { width: 100%; height: 2.2rem; display: block; }
.dot { width: .55rem; height: .55rem; border-radius: 50%; background: var(--mute); display: inline-block; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.crit { background: var(--crit); }

/* ── tables ── */
.tablewrap { overflow: auto; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: .82rem; color: var(--ink-3); font-weight: 650; padding: .7rem 1rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); white-space: nowrap; }
table.t td { padding: .75rem 1rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr { transition: background .1s; }
table.t tbody tr.click { cursor: pointer; } table.t tbody tr.click:hover { background: var(--surface-2); }
table.t td.actions { text-align: right; white-space: nowrap; }

/* ── drawer / modal / toast ── */
.scrim { position: fixed; inset: 0; background: rgba(4, 8, 16, .6); z-index: 90; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(46rem, 100vw); background: var(--bg); z-index: 91; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slidein .22s cubic-bezier(.2, .8, .2, 1); }
@keyframes slidein { from { transform: translateX(2rem); opacity: 0; } }
.drawer > header { display: flex; align-items: center; gap: .8rem; padding: 1rem 1.2rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.drawer .scroll { overflow: auto; flex: 1; padding: 1.2rem; display: flex; flex-direction: column; gap: 1.1rem; }
.drawer .scroll > * { flex: none; }
.modal { position: fixed; z-index: 95; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(34rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); overflow: auto; background: var(--surface); border-radius: var(--r-l); box-shadow: var(--shadow-lg); animation: pop .16s cubic-bezier(.2, .8, .2, 1); }
@keyframes pop { from { transform: translate(-50%, -48%) scale(.97); opacity: 0; } }
.modal > header { padding: 1.1rem 1.3rem .2rem; } .modal > header h2 { font-size: 1.25rem; }
.modal .mbody { padding: .8rem 1.3rem; display: flex; flex-direction: column; gap: .9rem; }
.modal > footer { padding: .9rem 1.3rem 1.2rem; display: flex; justify-content: flex-end; gap: .6rem; }
.toasts { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); z-index: 99; display: flex; flex-direction: column; gap: .5rem; align-items: center; }
.toast { background: var(--ink); color: var(--bg); padding: .65rem 1.1rem; border-radius: 99rem; box-shadow: var(--shadow-lg); font-weight: 600; max-width: 90vw; animation: pop2 .2s; }
.toast.err { background: var(--crit); color: #fff; }
@keyframes pop2 { from { transform: translateY(.6rem); opacity: 0; } }

/* ── tabs / lists ── */
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: .65rem .9rem; font-weight: 600; color: var(--ink-2); border-bottom: .15rem solid transparent; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); border-color: var(--role); }
.list { display: flex; flex-direction: column; }
.list .li { display: flex; gap: .8rem; padding: .8rem 0; border-bottom: 1px solid var(--line); align-items: flex-start; }
.list .li:last-child { border-bottom: 0; }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--ink-2); display: flex; flex-direction: column; align-items: center; gap: .6rem; }
.empty .ico { width: 2.2rem; height: 2.2rem; color: var(--ink-3); }
.empty b { color: var(--ink); font: 650 1.1rem var(--font-display); }
.skel { background: linear-gradient(90deg, var(--mute-soft), var(--surface-2), var(--mute-soft)); background-size: 200% 100%; animation: sh 1.3s infinite; border-radius: var(--r-m); min-height: 4rem; }
@keyframes sh { to { background-position: -200% 0; } }

/* profile hero */
.hero { background: var(--rail); color: #fff; border-radius: var(--r-l); padding: 1.1rem 1.2rem; display: grid; gap: .9rem; position: relative; overflow: hidden; }
.hero .name { font: 650 1.5rem var(--font-display); }
.hero .meta { color: #9db2d0; font-size: .92rem; }
.hero .trace { position: absolute; inset: auto 0 0 0; width: 100%; height: 5rem; opacity: .28; pointer-events: none; }
.vitals { display: grid; grid-template-columns: repeat(3, 1fr); gap: .7rem; position: relative; z-index: 1; }
@media (max-width: 480px) { .vitals { grid-template-columns: repeat(2, 1fr); } }
.vitals .v { background: #ffffff12; border-radius: var(--r-m); padding: .55rem .7rem; }
.vitals .v .k { font-size: .74rem; color: #9db2d0; display: flex; align-items: center; gap: .3rem; }
.vitals .v .n { font: 650 1.55rem/1.1 var(--font-display); font-variant-numeric: tabular-nums; }
.vitals .v .n small { font: 500 .78rem var(--font); color: #9db2d0; margin-left: .15rem; }
.vitals .v.crit .n { color: #ff8b90; } .vitals .v.warn .n { color: #ffcf7a; }
.chart { width: 100%; height: 9rem; display: block; }
.chart text { font: 500 .62rem var(--font); fill: var(--ink-3); }

/* brand ECG draw-in: one orchestrated moment */
@keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
.ecg path { stroke-dasharray: 1; stroke-dashoffset: 0; animation: draw 2.4s ease-out both; }

/* ── responsive ── */
@media (max-width: 1100px) {
  .app { grid-template-columns: 4.6rem minmax(0, 1fr); }
  .rail { padding-inline: .5rem; align-items: center; }
  .rail .brand { padding-inline: 0; } .rail .brand small { display: none; }
  .rail .brand .logo { width: 2.2rem; height: 2.2rem; object-fit: cover; object-position: 0 50%; }
  .rail a.nav span, .rail .sect, .rail .foot .who, .rail .badge { display: none; }
  .rail a.nav { padding: .75rem; } .rail a.nav[aria-current="page"]::before { left: -.5rem; }
  .split { grid-template-columns: 1fr; }
  .rail .foot { flex-direction: column; }
}
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; padding-bottom: 4.2rem; }
  .rail { position: fixed; inset: auto 0 0 0; height: auto; flex-direction: row; padding: .35rem .4rem; justify-content: space-around; top: auto; border-top: 1px solid #ffffff22; }
  .rail .brand, .rail .foot, .rail .sect { display: none; }
  .rail nav { flex-direction: row; width: 100%; justify-content: space-around; }
  .rail a.nav[aria-current="page"]::before { display: none; }
  .top { padding: .7rem 1rem; flex-wrap: wrap; } .search { width: 100%; order: 3; margin: 0; }
  .page { padding: 1rem 1rem 5rem; }
  .strip { grid-auto-flow: row; grid-template-columns: 1fr 1fr; } .strip > div { border-left: 0; border-top: 1px solid var(--line); } .strip > div:nth-child(-n+2) { border-top: 0; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .drawer { width: 100vw; }
  .board { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media print { .rail, .top, .scrim { display: none !important; } .app { display: block; } }
