/* KNH Care Alliance — self-contained stylesheet. No CDN, no build step. */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #94a3b8;
  --brand: #0b6b5e;
  --brand-dark: #084f46;
  --brand-tint: #e6f4f1;
  --danger: #b91c1c;
  --danger-tint: #fef2f2;
  --warn: #b45309;
  --warn-tint: #fffbeb;
  --ok: #15803d;
  --ok-tint: #f0fdf4;
  --info-tint: #eff6ff;
  --info: #1d4ed8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .04);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .4rem; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 .75rem; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 234px; flex: 0 0 234px; background: #0c1b2a; color: #cbd5e1;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { padding: .8rem 1rem .7rem; border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: .6rem; }
/* The crest sits on a white chip so it reads on the dark rail whichever
   colourway of the logo file is dropped in — the gold-on-navy official asset
   or a blue-on-white one. Swap app/static/img/knh-logo.png; nothing else. */
.brand .crest {
  width: 38px; height: 38px; flex: 0 0 38px; object-fit: contain;
  background: #fff; border-radius: 8px; padding: 2px;
}
.brand .mark { font-weight: 700; color: #fff; font-size: 1rem; letter-spacing: -.01em; }
.brand .sub { font-size: .72rem; color: #7d90a5; margin-top: .15rem; }
/* The nav has grown twice now. Keep it dense enough to fit a full admin menu
   on a 720px laptop, and when it does eventually overflow make that visible
   with a slim scrollbar rather than silently clipping the last item. */
.nav { padding: .45rem .55rem; overflow-y: auto; flex: 1; scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.22) transparent; }
.nav::-webkit-scrollbar { width: 6px; }
.nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.22); border-radius: 3px; }
.nav::-webkit-scrollbar-track { background: transparent; }
.nav .group { font-size: .65rem; text-transform: uppercase; letter-spacing: .09em;
  color: #64798f; padding: .42rem .55rem .14rem; font-weight: 650; }
.nav a {
  display: block; padding: .24rem .6rem; border-radius: 7px; color: #cbd5e1;
  font-size: .835rem; line-height: 1.35; margin-bottom: 1px;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav a.active { background: var(--brand); color: #fff; font-weight: 550; }
.nav .badge-nav { float: right; background: rgba(255,255,255,.14); border-radius: 20px;
  padding: 0 .4rem; font-size: .72rem; }
.side-foot { padding: .65rem 1.1rem; border-top: 1px solid rgba(255,255,255,.08); font-size: .78rem; }
.side-foot .who { color: #fff; font-weight: 600; }
.side-foot .role { color: #7d90a5; text-transform: capitalize; }
.side-foot a { color: #93c5fd; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: .85rem 1.5rem; display: flex; align-items: center; gap: 1rem;
  position: sticky; top: 0; z-index: 20;
}
.topbar .title { font-size: 1.05rem; font-weight: 650; }
.topbar .crumb { color: var(--ink-3); font-size: .8rem; }
.topbar .spacer { flex: 1; }
.content { padding: 1.4rem 1.5rem 3rem; max-width: 1500px; width: 100%; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1.15rem;
}
.card > .card-head {
  padding: .8rem 1.1rem; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
}
.card > .card-head h2, .card > .card-head h3 { margin: 0; }
.card > .card-head .spacer { flex: 1; }
.card > .card-body { padding: 1.1rem; }
.card > .card-body.tight { padding: 0; }
.card-note { font-size: .8rem; color: var(--ink-2); margin: .35rem 0 0; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .85rem; margin-bottom: 1.15rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .85rem 1rem; box-shadow: var(--shadow); }
.stat .label { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-3); font-weight: 650; }
.stat .value { font-size: 1.42rem; font-weight: 680; margin-top: .3rem; letter-spacing: -.02em; }
.stat .hint { font-size: .78rem; color: var(--ink-2); margin-top: .2rem; }
.stat.accent { border-left: 3px solid var(--brand); }
.stat.warn { border-left: 3px solid var(--warn); }
.stat.ok { border-left: 3px solid var(--ok); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .87rem; }
table.data th, table.data td { padding: .55rem .7rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data thead th {
  background: var(--surface-2); font-size: .72rem; text-transform: uppercase;
  letter-spacing: .05em; color: var(--ink-2); font-weight: 680; white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data tfoot td { background: var(--surface-2); font-weight: 680; border-top: 2px solid var(--line-strong); }
/* Wide reports (10+ columns) — tighter gutters so the last column is not
   pushed into the card's horizontal scroll. */
table.data.compact th, table.data.compact td { padding: .5rem .45rem; }
table.data.compact { font-size: .84rem; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--ink-3); }
.nowrap { white-space: nowrap; }
.small { font-size: .8rem; }
.mono { font-family: var(--mono); font-size: .85em; }
.empty { padding: 2.2rem 1.1rem; text-align: center; color: var(--ink-3); }
.empty .big { font-size: 1rem; color: var(--ink-2); margin-bottom: .3rem; }

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: .1rem .45rem; border-radius: 20px;
  font-size: .72rem; font-weight: 650; border: 1px solid transparent; white-space: nowrap;
}
.badge.silver   { background: #f1f5f9; color: #475569; border-color: #cbd5e1; }
.badge.gold     { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.badge.platinum { background: #e0e7ff; color: #3730a3; border-color: #a5b4fc; }
.badge.diamond  { background: #cffafe; color: #0e7490; border-color: #67e8f9; }
.badge.slate    { background: #f1f5f9; color: #475569; border-color: #cbd5e1; }
.badge.ok       { background: var(--ok-tint); color: var(--ok); border-color: #86efac; }
.badge.pend     { background: var(--warn-tint); color: var(--warn); border-color: #fcd34d; }
.badge.dead     { background: #f1f5f9; color: var(--ink-3); border-color: var(--line-strong); }
.badge.danger   { background: var(--danger-tint); color: var(--danger); border-color: #fca5a5; }
.badge.info     { background: var(--info-tint); color: var(--info); border-color: #bfdbfe; }

/* ---------- forms ---------- */
.field { margin-bottom: .9rem; }
.field label, .lbl { display: block; font-size: .78rem; font-weight: 650; color: var(--ink-2); margin-bottom: .25rem; }
.field .help { font-size: .76rem; color: var(--ink-3); margin-top: .22rem; }
/* Match by exclusion, not by an explicit type= — an <input> with no type
   attribute defaults to text but is NOT matched by input[type=text], which
   silently left every untyped field (OTP entry, master name fields) unstyled. */
input:not([type=checkbox]):not([type=radio]):not([type=submit]):not([type=button]):not([type=file]):not([type=hidden]),
select, textarea {
  width: 100%; padding: .48rem .6rem; border: 1px solid var(--line-strong);
  border-radius: 7px; font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint);
}
input[readonly], input:disabled, select:disabled { background: var(--surface-2); color: var(--ink-2); }
textarea { min-height: 68px; resize: vertical; }
.grid { display: grid; gap: .9rem; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.check { display: flex; align-items: flex-start; gap: .5rem; font-size: .87rem; }
.check input { margin-top: .2rem; }
.filters { display: flex; gap: .65rem; align-items: flex-end; flex-wrap: wrap; }
.filters .field { margin-bottom: 0; }
.filters select, .filters input { min-width: 150px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .35rem; padding: .45rem .85rem;
  border-radius: 7px; border: 1px solid var(--line-strong); background: #fff;
  color: var(--ink); font: inherit; font-weight: 600; font-size: .87rem;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { background: #fff; border-color: #fca5a5; color: var(--danger); }
.btn.danger:hover { background: var(--danger-tint); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--brand); }
.btn.ghost:hover { background: var(--brand-tint); }
.btn.sm { padding: .25rem .55rem; font-size: .79rem; }
.btn.lg { padding: .62rem 1.3rem; font-size: .95rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: .55rem; flex-wrap: wrap; align-items: center; }

/* ---------- alerts ---------- */
.alerts { margin-bottom: 1rem; }
.alert { padding: .65rem .9rem; border-radius: 8px; border: 1px solid; margin-bottom: .5rem; font-size: .88rem; }
.alert.success { background: var(--ok-tint); border-color: #86efac; color: #14532d; }
.alert.danger  { background: var(--danger-tint); border-color: #fca5a5; color: #7f1d1d; }
.alert.warning { background: var(--warn-tint); border-color: #fcd34d; color: #78350f; }
.alert.info    { background: var(--info-tint); border-color: #bfdbfe; color: #1e3a8a; }

/* ---------- calc panel (business upload) ---------- */
.calc { background: linear-gradient(160deg, #0c1b2a, #123040); color: #e2e8f0;
  border-radius: var(--radius); padding: 1.1rem; }
.calc .row { display: flex; justify-content: space-between; align-items: baseline;
  padding: .4rem 0; border-bottom: 1px solid rgba(255,255,255,.09); }
.calc .row:last-child { border-bottom: 0; }
.calc .k { font-size: .8rem; color: #93a7bc; }
.calc .v { font-weight: 650; font-variant-numeric: tabular-nums; }
.calc .big { font-size: 1.75rem; font-weight: 700; letter-spacing: -.02em; color: #fff; }
.calc .tier-line { display: flex; align-items: center; gap: .5rem; }
.calc .override-note { font-size: .76rem; color: #fcd34d; margin-top: .5rem; }

/* ---------- OTP ---------- */
.otp-box { text-align: center; padding: 1.4rem 1rem; }
.otp-input {
  font-family: var(--mono); font-size: 2rem; letter-spacing: .55em;
  text-align: center; padding: .6rem .4rem .6rem 1rem; max-width: 300px; margin: 0 auto;
  text-indent: .55em;
}
.otp-reveal {
  display: inline-block; font-family: var(--mono); font-size: 2.1rem; font-weight: 700;
  letter-spacing: .35em; padding: .5rem 1rem .5rem 1.35rem; background: var(--warn-tint);
  border: 1px dashed #f59e0b; border-radius: 10px; color: #78350f;
}
.step { display: flex; gap: .7rem; margin-bottom: .7rem; align-items: flex-start; }
.step .n { flex: 0 0 22px; height: 22px; border-radius: 50%; background: var(--brand);
  color: #fff; font-size: .76rem; font-weight: 700; display: flex; align-items: center;
  justify-content: center; margin-top: .05rem; }
.step .t { font-size: .87rem; color: var(--ink-2); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(150deg, #0c1b2a, #0b6b5e); padding: 1.5rem; }
.login-card { background: #fff; border-radius: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.28);
  padding: 2rem; width: 100%; max-width: 400px; }
/* The brand block is centred on the card; form labels stay left-aligned. */
.login-card .brand-block { text-align: center; margin-bottom: 1.4rem; }
.login-card .crest {
  width: 84px; height: 84px; object-fit: contain; display: block;
  margin: 0 auto .7rem; border-radius: 12px;
}
.login-card .logo { font-weight: 700; font-size: 1.25rem; letter-spacing: -.02em; }
.login-card .sub { color: var(--ink-3); font-size: .84rem; margin-top: .1rem; }
.card-foot-link { text-align: center; margin-top: 1.1rem; padding-top: .9rem;
  border-top: 1px solid var(--line); font-size: .85rem; }
.reset-link { word-break: break-all; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 7px; padding: .6rem .7rem; font-size: .78rem; color: var(--ink-2); }

/* ---------- misc ---------- */
.pill-row { display: flex; gap: .35rem; flex-wrap: wrap; }
.bar { height: 7px; background: var(--line); border-radius: 4px; overflow: hidden; min-width: 60px; }
.bar > span { display: block; height: 100%; background: var(--brand); }
.hr { height: 1px; background: var(--line); margin: 1rem 0; border: 0; }
.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin-bottom: 1.1rem; flex-wrap: wrap; }
.tabs a { padding: .5rem .85rem; font-size: .88rem; font-weight: 600; color: var(--ink-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }
.inline-form { display: inline; }
.notice { background: var(--info-tint); border: 1px solid #bfdbfe; border-radius: 8px;
  padding: .6rem .8rem; font-size: .84rem; color: #1e3a8a; }
.notice.warn { background: var(--warn-tint); border-color: #fcd34d; color: #78350f; }

/* ---------- confirm dialogs ---------- */
/* Native <dialog>, so the browser handles focus trapping and Esc. Must be
   rendered OUTSIDE the form it confirms - a nested <form> would break it. */
dialog.modal {
  padding: 0; border: 1px solid var(--line-strong); border-radius: var(--radius);
  width: min(460px, calc(100vw - 2rem)); color: var(--ink); background: var(--surface);
  box-shadow: 0 18px 44px rgba(15, 23, 42, .24);
}
dialog.modal::backdrop { background: rgba(15, 23, 42, .45); }
dialog.modal .modal-head {
  padding: .8rem 1.05rem; border-bottom: 1px solid var(--line);
  font-weight: 700; font-size: .98rem;
}
dialog.modal .modal-body { padding: .9rem 1.05rem; font-size: .87rem; }
dialog.modal .modal-foot {
  display: flex; gap: .55rem; padding: .75rem 1.05rem;
  border-top: 1px solid var(--line); background: var(--surface-2);
}
table.confirm { width: 100%; border-collapse: collapse; }
table.confirm th {
  text-align: left; font-weight: 600; color: var(--ink-2);
  padding: .3rem 0; white-space: nowrap;
}
table.confirm td { text-align: right; padding: .3rem 0; font-variant-numeric: tabular-nums; }
table.confirm tr.rule th, table.confirm tr.rule td { border-top: 1px solid var(--line); padding-top: .5rem; }
table.confirm tr.grand th, table.confirm tr.grand td {
  border-top: 2px solid var(--line-strong); padding-top: .5rem;
  font-size: 1.02rem; font-weight: 750; color: var(--ink);
}

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; }
  .nav { display: flex; flex-wrap: wrap; gap: .2rem; }
  .nav .group { width: 100%; padding: .5rem .55rem .15rem; }
  .content { padding: 1rem; }
  .topbar { padding: .75rem 1rem; }
}

@media print {
  .sidebar, .topbar, .btn, .filters, .alerts, .no-print { display: none !important; }
  body { background: #fff; font-size: 11px; }
  .content { padding: 0; }
  .card { box-shadow: none; border-color: #999; break-inside: avoid; }
  table.data thead th { position: static; }
}
