/* One stylesheet for the staff app and the patient pages.
   The clinic's colour arrives as --brand (set from Settings); everything else
   is derived from it, so a new clinic is a setting, not a stylesheet. */

:root {
  --brand: #0F6E5E;
  --brand-ink: #0A5448;
  --brand-tint: color-mix(in srgb, var(--brand) 9%, #fff);
  --brand-tint-2: color-mix(in srgb, var(--brand) 18%, #fff);
  --on-brand: #fff;

  --ink: #17232B;
  --muted: #4A5860;
  --line: #DCE3E6;
  --line-strong: #8A989F;
  --paper: #fff;
  --paper-2: #F5F8F9;
  --page: #EEF3F4;

  --danger: #B3261E;
  --danger-tint: #FCEFEE;
  --warn: #8A5300;
  --warn-tint: #FFF4DD;
  --ok: #17693A;
  --ok-tint: #E6F5EC;
  --info: #1D4F8C;
  --info-tint: #E8F0FB;

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;
  --shadow: 0 1px 2px rgba(23,35,43,.06), 0 6px 18px -10px rgba(23,35,43,.18);
  --shadow-lg: 0 2px 6px rgba(23,35,43,.10), 0 28px 60px -24px rgba(23,35,43,.35);
  --tap: 44px;
  --nav-w: 232px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 72px; }
body {
  margin: 0; font-family: var(--sans); font-size: 16px; line-height: 1.5;
  color: var(--ink); background: var(--page); -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
a { color: var(--brand-ink); }
img { max-width: 100%; }
small, .small { font-size: .875rem; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; }

:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 70%, #000); outline-offset: 2px; border-radius: 4px; }

/* ---------- controls ---------- */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
.hint { font-weight: 400; color: var(--muted); font-size: .85rem; display: block; margin-top: 3px; }
input, select, textarea {
  width: 100%; min-height: var(--tap); padding: 9px 12px; font: inherit; color: inherit;
  background: var(--paper); border: 1.5px solid var(--line-strong); border-radius: var(--r-sm);
}
textarea { min-height: 84px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); flex: none; }
input:disabled, select:disabled { background: var(--paper-2); color: var(--muted); }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1 1 180px; min-width: 0; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
.check span { padding-top: 1px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap);
  padding: 8px 16px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  border-radius: var(--r-sm); border: 1.5px solid var(--brand); background: var(--brand); color: var(--on-brand);
}
.btn:hover { background: var(--brand-ink); border-color: var(--brand-ink); }
.btn.ghost { background: var(--paper); color: var(--brand-ink); border-color: var(--line-strong); }
.btn.ghost:hover { background: var(--brand-tint); border-color: var(--brand); }
.btn.danger { background: var(--paper); color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger-tint); }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: .875rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--brand-ink); text-decoration: underline; cursor: pointer; }

/* ---------- surfaces ---------- */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.stack > * + * { margin-top: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions.end { justify-content: flex-end; }

.notice { padding: 12px 14px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--paper-2); margin-bottom: 14px; }
.notice.warn { background: var(--warn-tint); border-color: #E7C77F; color: #5C3700; }
.notice.danger { background: var(--danger-tint); border-color: #E6A8A4; color: #7A1812; }
.notice.ok { background: var(--ok-tint); border-color: #98D0AE; color: #0F4A28; }
.notice.info { background: var(--info-tint); border-color: #A9C4E8; color: #163E6E; }
.notice > :last-child { margin-bottom: 0; }
.error-text { color: var(--danger); font-weight: 600; min-height: 1.4em; }

.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 650;
  background: var(--paper-2); border: 1px solid var(--line-strong); color: var(--ink); white-space: nowrap;
}
.pill.booked { background: var(--info-tint); border-color: #A9C4E8; color: #163E6E; }
.pill.arrived { background: var(--warn-tint); border-color: #E7C77F; color: #5C3700; }
.pill.in_progress { background: var(--ok-tint); border-color: #98D0AE; color: #0F4A28; }
.pill.done { background: var(--paper-2); color: var(--muted); }
.pill.cancelled, .pill.no_show { background: var(--danger-tint); border-color: #E6A8A4; color: #7A1812; }
.pill.walk_in { background: #F1E9FB; border-color: #C9B3EA; color: #46267A; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; }
.table-wrap { overflow-x: auto; }

.empty { padding: 28px 12px; text-align: center; color: var(--muted); }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } * { scroll-behavior: auto !important; } }

/* ---------- dialog and toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 25, 31, .5); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 12px; overflow-y: auto; z-index: 50; }
.dialog { background: var(--paper); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; padding: 22px; }
.dialog.wide { max-width: 760px; }
.dialog h2 { margin-top: 0; }
.dialog-foot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: min(92vw, 460px); }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: var(--r-sm); box-shadow: var(--shadow-lg); }
.toast.error { background: var(--danger); }

/* ---------- staff shell ---------- */
.shell { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); min-height: 100vh; }
.shell > div { min-width: 0; }
.nav { background: var(--paper); border-right: 1px solid var(--line); padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 700; font-size: 1.05rem; text-decoration: none; color: var(--ink); }
.brand img { max-height: 34px; max-width: 150px; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--brand); flex: none; }
.nav a.item { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 8px 12px; border-radius: var(--r-sm); color: var(--ink); text-decoration: none; font-weight: 550; }
.nav a.item:hover { background: var(--paper-2); }
.nav a.item[aria-current="page"] { background: var(--brand-tint-2); color: var(--brand-ink); font-weight: 700; }
.nav .grow { flex: 1; }
.nav .who { font-size: .85rem; color: var(--muted); padding: 8px 12px; }
.topbar { display: none; }
main.main { padding: 22px 26px 60px; max-width: 1180px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--paper); border-bottom: 1px solid var(--line); padding: 8px 14px; position: sticky; top: 0; z-index: 20; }
  .nav { position: fixed; inset: 0 auto 0 0; width: min(82vw, 300px); height: 100vh; z-index: 40; transform: translateX(-102%); transition: transform .18s ease; box-shadow: var(--shadow-lg); }
  .nav.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(15,25,31,.45); z-index: 30; }
  main.main { padding: 16px 14px 60px; }
}
@media (prefers-reduced-motion: reduce) { .nav { transition: none; } }

/* ---------- today / lines ---------- */
.provider-card { padding: 0; overflow: hidden; }
.provider-head { padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--brand-tint); display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }
.provider-head h2 { margin: 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 2px 10px; border-radius: 999px; background: var(--paper); border: 1px solid var(--line); font-size: .85rem; font-weight: 600; }
.chip b { font-variant-numeric: tabular-nums; }
.provider-tools { padding: 10px 18px; display: flex; gap: 8px; flex-wrap: wrap; border-bottom: 1px solid var(--line); background: var(--paper); }
.delay-bar { padding: 10px 18px; background: var(--warn-tint); color: #5C3700; border-bottom: 1px solid #E7C77F; font-weight: 600; }
.line { list-style: none; margin: 0; padding: 0; }
.line-row { display: grid; grid-template-columns: 78px 1fr auto; gap: 12px; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--line); cursor: pointer; }
.line-row:hover { background: var(--paper-2); }
.line-row.current { background: var(--ok-tint); }
.line-row:last-child { border-bottom: 0; }
.line-time { font-variant-numeric: tabular-nums; font-weight: 700; }
.line-time small { display: block; font-weight: 500; color: var(--muted); }
.line-name { font-weight: 650; }
.line-meta { color: var(--muted); font-size: .875rem; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.line-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.group-label { padding: 6px 18px; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; color: var(--muted); background: var(--paper-2); border-bottom: 1px solid var(--line); }
.q-no { display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 6px; border-radius: 13px; background: var(--ink); color: #fff; font-size: .8rem; font-weight: 700; }
@media (max-width: 640px) {
  .line-row { grid-template-columns: 62px 1fr; }
  .line-actions { grid-column: 1 / -1; justify-content: flex-start; }
}

/* ---------- agenda ---------- */
.week { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.day-col { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-sm); min-height: 120px; }
.day-col.today { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-tint-2); }
.day-col.closed { background: var(--paper-2); }
.day-col h3 { margin: 0; padding: 8px 10px; font-size: .85rem; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 6px; }
.day-col h3 a { text-decoration: none; color: inherit; }
.day-item { display: block; width: 100%; text-align: left; font: inherit; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 6px 10px; cursor: pointer; font-size: .85rem; }
.day-item:hover { background: var(--brand-tint); }
.day-item b { font-variant-numeric: tabular-nums; }
.day-item.cancelled, .day-item.no_show { text-decoration: line-through; color: var(--muted); }
.away-tag { display: block; padding: 6px 10px; font-size: .8rem; background: var(--warn-tint); color: #5C3700; }
@media (max-width: 900px) { .week { grid-template-columns: 1fr; } }

/* ---------- slots and dates ---------- */
.slot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.slot { min-height: var(--tap); border: 1.5px solid var(--line-strong); background: var(--paper); border-radius: var(--r-sm); font: inherit; font-weight: 600; cursor: pointer; font-variant-numeric: tabular-nums; }
.slot:hover { border-color: var(--brand); background: var(--brand-tint); }
.slot[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.date-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x proximity; }
.date-chip { flex: none; scroll-snap-align: start; min-width: 74px; min-height: 66px; border: 1.5px solid var(--line-strong); background: var(--paper); border-radius: var(--r-sm); font: inherit; cursor: pointer; padding: 6px 8px; text-align: center; }
.date-chip .dow { display: block; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.date-chip .dom { display: block; font-size: 1.15rem; font-weight: 700; }
.date-chip .free { display: block; font-size: .75rem; color: var(--ok); font-weight: 600; }
.date-chip.none { background: var(--paper-2); color: var(--muted); cursor: not-allowed; }
.date-chip.none .free { color: var(--muted); font-weight: 500; }
.date-chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.date-chip[aria-pressed="true"] .dow, .date-chip[aria-pressed="true"] .free { color: var(--on-brand); }

/* ---------- hours editor ---------- */
.hours-row { display: grid; grid-template-columns: 110px 1fr; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: start; }
.hours-row .ranges { display: grid; gap: 8px; }
.range { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.range input { width: 150px; }
@media (max-width: 560px) { .hours-row { grid-template-columns: 1fr; } }

/* ---------- reports ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; }
.kpi .n { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi .l { color: var(--muted); font-size: .85rem; }
.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 56px 1fr 36px; gap: 8px; align-items: center; font-size: .85rem; }
.bar { height: 14px; background: var(--paper-2); border-radius: 7px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 7px; }

/* ---------- public pages ---------- */
.public { max-width: 640px; margin: 0 auto; padding: 18px 14px 60px; }
.public-head { display: flex; align-items: center; gap: 12px; padding: 6px 2px 16px; }
.public-head img { max-height: 44px; max-width: 160px; }
.public-head h1 { margin: 0; font-size: 1.25rem; }
.public-head .sub { color: var(--muted); font-size: .875rem; }
.step { margin-bottom: 14px; }
.step > h2 { display: flex; align-items: center; gap: 10px; font-size: 1.05rem; }
.step-n { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: var(--on-brand); font-size: .9rem; font-weight: 700; flex: none; }
.choice { display: block; width: 100%; text-align: left; font: inherit; background: var(--paper); border: 1.5px solid var(--line-strong); border-radius: var(--r); padding: 14px; cursor: pointer; margin-bottom: 8px; }
.choice:hover { border-color: var(--brand); background: var(--brand-tint); }
.choice[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-tint-2); box-shadow: 0 0 0 2px var(--brand); }
.choice b { display: block; }
.choice span { color: var(--muted); font-size: .9rem; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.status-hero { text-align: center; padding: 26px 16px; border-radius: var(--r-lg); background: var(--brand-tint); border: 1px solid var(--brand-tint-2); margin-bottom: 16px; }
.status-hero.now { background: var(--ok-tint); border-color: #98D0AE; }
.status-hero.bad { background: var(--danger-tint); border-color: #E6A8A4; }
.status-hero .big { font-size: 2.6rem; font-weight: 750; line-height: 1.1; font-variant-numeric: tabular-nums; }
.status-hero .lead { font-size: 1.1rem; font-weight: 650; margin-bottom: 4px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }

/* ---------- auth pages ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px 14px; }
.auth-card { width: 100%; max-width: 440px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); padding: 28px; }
.auth-card h1 { font-size: 1.4rem; }

/* ---------- poster and print ---------- */
.poster { background: #fff; border: 2px solid var(--ink); border-radius: var(--r-lg); padding: 40px 30px; text-align: center; max-width: 560px; margin: 0 auto; }
.poster h2 { font-size: 2rem; margin: 0 0 8px; }
.poster .qr { width: min(320px, 70%); height: auto; image-rendering: pixelated; margin: 16px auto; display: block; }
.poster .url { font-size: 1.15rem; font-weight: 700; word-break: break-all; }
@media print {
  body { background: #fff; }
  .nav, .topbar, .no-print, .toasts { display: none !important; }
  .shell { display: block; }
  main.main { padding: 0; max-width: none; }
  .poster { border-width: 3px; max-width: none; margin-top: 8mm; }
  .card { box-shadow: none; }
}

/* ---------- live mark, summary strip, activity ---------- */
.live { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); white-space: nowrap; }
.live .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; }
.live.off .dot { background: var(--warn); }
.strip { display: flex; flex-wrap: wrap; gap: 8px 22px; align-items: baseline; padding: 12px 16px; margin-bottom: 14px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); }
.strip h2 { margin: 0; font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); flex: 1 1 100%; }
.strip .num { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-right: 6px; }
.strip .lbl { color: var(--muted); font-size: .9rem; }
.strip .minor { color: var(--muted); font-size: .85rem; margin-left: auto; }
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: grid; grid-template-columns: 78px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.activity li:last-child { border-bottom: 0; }
.activity .when { color: var(--muted); font-variant-numeric: tabular-nums; }
