:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafd;
  --fg: #142033;
  --muted: #5e6b80;
  --line: #e3e8f0;
  --brand: #1f5fd6;
  --brand-ink: #ffffff;
  --brand-soft: #e8effc;
  --red: #c42b2b;
  --red-soft: #fdeeee;
  --amber: #9a5a00;
  --amber-soft: #fff4e0;
  --green: #1d7a46;
  --green-soft: #e7f6ed;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 32, 51, .05), 0 4px 16px rgba(20, 32, 51, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1520; --surface: #172030; --surface-2: #1c2738; --fg: #e8edf5; --muted: #9aa7ba;
    --line: #2a3648; --brand: #6c9cff; --brand-ink: #0f1520; --brand-soft: #1d2c48;
    --red: #ff7b7b; --red-soft: #3a1f24; --amber: #f2b860; --amber-soft: #382c18;
    --green: #6fd39b; --green-soft: #17322a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  font: 16px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--fg);
}
a { color: var(--brand); }
main { width: 100%; max-width: 820px; margin: 0 auto; padding: 28px 18px 56px; flex: 1; }
h1 { font-size: 1.75rem; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
.sub, .meta { color: var(--muted); margin: 4px 0 0; }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 820px; margin: 0 auto; padding: 12px 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--fg); text-decoration: none; }
.logo { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: #d93a3a; }
.logo svg { width: 18px; height: 18px; fill: #fff; }
.tag { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; background: var(--amber-soft); color: var(--amber); padding: 2px 7px; border-radius: 5px; }
nav { display: flex; align-items: center; gap: 10px; }
nav form { margin: 0; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; font-weight: 600; padding: 4px 10px; border-radius: 999px; }
.pill.nurse { background: var(--green-soft); color: var(--green); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* Buttons and inputs */
button, .button {
  font: inherit; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--brand); color: var(--brand-ink); border: 1px solid transparent; border-radius: 10px;
  padding: 10px 18px; cursor: pointer; text-decoration: none; transition: filter .15s, background .15s;
}
button:hover, .button:hover { filter: brightness(1.08); }
.ghost { background: transparent; color: var(--fg); border-color: var(--line); }
.ghost:hover { background: var(--surface-2); filter: none; }
.small { padding: 6px 12px; font-size: .9rem; }
.block { width: 100%; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 2px; }
input, select {
  font: inherit; color: var(--fg); width: 100%; padding: 11px 13px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface); transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent); }
label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 6px; }

/* Home */
.hero { margin-bottom: 18px; }
.search { position: relative; display: flex; gap: 8px; margin-top: 18px; }
.search input { padding-left: 42px; height: 50px; font-size: 1.05rem; box-shadow: var(--shadow); }
.search-ic { position: absolute; left: 14px; top: 16px; color: var(--muted); }
.search button { height: 50px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip { font-size: .88rem; font-weight: 600; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); text-decoration: none; }
.chip:hover { color: var(--fg); }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 22px 0; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat strong { display: block; font-size: 1.6rem; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat.alert strong { color: var(--red); }

.list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.list a {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--fg);
  box-shadow: var(--shadow); transition: transform .12s, border-color .12s;
}
.list a:hover { border-color: var(--brand); transform: translateY(-1px); }
.who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.name { font-weight: 650; }
.who .meta { margin: 0; font-size: .88rem; }
.flags { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.chev { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 32px; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

.avatar {
  display: grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: .95rem;
}
.avatar.alert { background: var(--red-soft); color: var(--red); }
.avatar.lg { width: 60px; height: 60px; font-size: 1.2rem; }
.badge { font-size: .75rem; font-weight: 650; padding: 3px 9px; border-radius: 999px; white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.green { background: var(--green-soft); color: var(--green); }

/* Card */
.back { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; text-decoration: none; margin-bottom: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 16px; padding: 22px 24px; border-bottom: 1px solid var(--line); }
.card-title { flex: 1; min-width: 0; }
.blood {
  display: flex; flex-direction: column; align-items: center; min-width: 96px; padding: 10px 14px;
  border-radius: 14px; background: var(--red-soft); color: var(--red);
}
.blood svg { width: 20px; height: 20px; fill: currentColor; }
.blood strong { font-size: 1.9rem; line-height: 1.1; }
.blood small { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.banner {
  display: flex; gap: 12px; align-items: flex-start; margin: 18px 24px 0; padding: 12px 16px;
  border-radius: 12px; background: var(--red-soft); color: var(--red); border: 1px solid color-mix(in srgb, var(--red) 30%, transparent);
}
.banner .ic { margin-top: 2px; }
.banner strong { display: block; }
.banner span { color: var(--fg); font-size: .92rem; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 18px 24px 24px; }
.tile { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; background: var(--surface-2); }
.tile h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.tile p { margin: 0; font-size: 1.05rem; font-weight: 550; }
.tile.danger { background: var(--red-soft); border-color: color-mix(in srgb, var(--red) 30%, transparent); }
.tile.danger h2, .tile.danger p { color: var(--red); }
.tile.warn { background: var(--amber-soft); border-color: color-mix(in srgb, var(--amber) 30%, transparent); }
.tile.warn h2, .tile.warn p { color: var(--amber); }
.tile.contact .button { margin-top: 10px; }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* Panels / forms */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 24px; box-shadow: var(--shadow); }
.auth { display: grid; place-items: center; padding-top: 24px; }
.auth .panel { width: 100%; max-width: 380px; text-align: center; }
.auth label { text-align: left; margin-top: 22px; }
.auth .block { margin-top: 14px; }
.lock { display: inline-grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: var(--brand-soft); color: var(--brand); margin-bottom: 12px; }
.lock svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.pin { text-align: center; font-size: 1.4rem; letter-spacing: .5em; }
.hint { color: var(--muted); font-size: .85rem; margin: 14px 0 0; }
.edit-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 16px; }
.field.wide, .actions.wide { grid-column: 1 / -1; }
.field small { display: block; color: var(--muted); font-size: .8rem; margin-top: 5px; }
.form .actions { margin-top: 4px; }

.flash { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 12px; margin-bottom: 18px; font-weight: 600; }
.flash.error { background: var(--red-soft); color: var(--red); }
.flash.ok { background: var(--green-soft); color: var(--green); }
footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 20px; }

@media (max-width: 620px) {
  h1 { font-size: 1.45rem; }
  .brand > span:nth-child(2) { display: none; }
  .grid, .form { grid-template-columns: 1fr; }
  .card-head { flex-wrap: wrap; padding: 18px; gap: 12px 14px; }
  .card-head .avatar { width: 48px; height: 48px; font-size: 1rem; }
  .blood { flex: 1 0 100%; flex-direction: row; justify-content: center; gap: 10px; padding: 8px 14px; }
  .blood strong { font-size: 1.5rem; }
  .grid { padding: 16px 18px 18px; }
  .banner { margin: 16px 18px 0; }
  .flags .badge.amber { display: none; }
  .stat { padding: 12px; }
  .stat strong { font-size: 1.3rem; }
}
@media print {
  :root { --bg: #fff; --surface: #fff; --surface-2: #fff; --shadow: none; }
  .topbar, .actions, footer, .back { display: none !important; }
  main { padding: 0; }
  .card { border: 1.5px solid #000; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Login tabs and role pills */
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin: 20px 0 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; }
.tab { padding: 8px; border-radius: 9px; font-weight: 600; text-decoration: none; color: var(--muted); }
.tab.on { background: var(--surface); color: var(--fg); box-shadow: var(--shadow); }
.auth form label { text-align: left; margin-top: 16px; }
.hint.left { text-align: left; margin-top: 8px; }
.demo-note { margin-top: 18px; padding: 10px 12px; border-radius: 10px; background: var(--amber-soft); color: var(--amber); font-size: .85rem; text-align: left; }
.demo-note code, .meta code, small code { font-size: .85em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; color: var(--fg); }
.pill.parent { background: var(--brand-soft); color: var(--brand); }
.field.divider { border-top: 1px solid var(--line); padding-top: 18px; }
.opt { font-weight: 400; color: var(--muted); }
