/* Clinic dashboard tokens (defined once; light and dark)
   ink     #241430  plum-black text           page    #FFFFFF  white everywhere; cards white with a light grey border
   brand   #5B2A86  purple accent: primary buttons, links, focus rings, selected states (never large backgrounds)
   role accents (tab underline, selected sub-tab, section headings), AA on white:
     dentist #5B2A86 (10.2:1)   front desk #0F766E (5.5:1)   analyst #1D4ED8 (6.7:1)
   status (distinct from the accents): live #15803D  warn #9A5B06  bad #B42318                                  */
:root {
  --ink: #241430; --muted: #675E73; --faint: #766E84; --line: #E5E1EB; --line-2: #D6D0DF;
  --surface: #F7F6F9; --page: #FFFFFF; --card: #FFFFFF; --brand: #5B2A86; --brand-ink: #3E1A5E; --brand-soft: #EFE8F6; --on-brand: #FFFFFF;
  --role-owner: #9A5B06; --role-dentist: #5B2A86; --role-front-desk: #0F766E; --role-analyst: #1D4ED8; --role-admin: #5B2A86;
  --live: #137A3A; --live-soft: #E7F6EC; --warn: #9A5B06; --warn-soft: #FBF0DD; --bad: #B42318; --bad-soft: #FDECEA;
  --radius: 10px; --radius-sm: 6px;
  --font: "Instrument Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #EEE9F4; --muted: #B3AABF; --faint: #8C8398; --line: #34293F; --line-2: #45384F;
    --surface: #17111C; --page: #17111C; --card: #211928; --brand: #B88CE0; --brand-ink: #D9C2EF; --brand-soft: #2E2238; --on-brand: #17111C;
    --role-owner: #E2A84B; --role-dentist: #C9A6EE; --role-front-desk: #5FD4C4; --role-analyst: #93B4FF; --role-admin: #C9A6EE;
    --live: #6EDB8F; --live-soft: #15301E; --warn: #E2A84B; --warn-soft: #33270F; --bad: #F2867B; --bad-soft: #3A1916;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #EEE9F4; --muted: #B3AABF; --faint: #8C8398; --line: #34293F; --line-2: #45384F;
  --surface: #17111C; --page: #17111C; --card: #211928; --brand: #B88CE0; --brand-ink: #D9C2EF; --brand-soft: #2E2238; --on-brand: #17111C;
  --role-owner: #E2A84B; --role-dentist: #C9A6EE; --role-front-desk: #5FD4C4; --role-analyst: #93B4FF; --role-admin: #C9A6EE;
  --live: #6EDB8F; --live-soft: #15301E; --warn: #E2A84B; --warn-soft: #33270F; --bad: #F2867B; --bad-soft: #3A1916;
  color-scheme: dark;
}
* { box-sizing: border-box; }
:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
html, body { height: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font: 15px/1.5 var(--font); font-variant-numeric: tabular-nums; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
img, svg { max-width: 100%; }

/* shell: header, role tabs, sub-tabs, content */
.shell { min-height: 100%; --accent: var(--brand); }
.apphead { display: flex; align-items: center; gap: 12px; padding: 12px 28px; background: var(--page); border-bottom: 1px solid var(--line); }
.apphead .spacer { flex: 1; }
.brandmark { display: flex; gap: 10px; align-items: center; min-width: 0; }
.brandmark .dot { width: 30px; height: 30px; flex: none; border-radius: 8px; background: var(--brand); display: grid; place-items: center; color: var(--on-brand); font-weight: 700; }
.brandmark b { display: block; font-size: 16px; }
.brandmark small { color: var(--muted); font-size: 12px; }
.who { color: var(--muted); font-size: 13.5px; text-align: right; line-height: 1.3; }
.rolebar, .subbar { background: var(--page); border-bottom: 1px solid var(--line); padding: 0 28px; position: sticky; z-index: 5; }
.rolebar { top: env(safe-area-inset-top, 0px); }
.subbar { top: calc(env(safe-area-inset-top, 0px) + 0px); }
.rolebar:not([hidden]) + .subbar { top: calc(env(safe-area-inset-top, 0px) + 47px); }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: thin; }
.roletab, .subtab { display: inline-flex; align-items: center; gap: 6px; padding: 12px 14px 10px; color: var(--muted); text-decoration: none; white-space: nowrap; border-bottom: 3px solid transparent; font-weight: 500; }
.roletab { font-size: 15px; }
.subtab { font-size: 14px; padding: 9px 12px 8px; border-bottom-width: 2px; }
.roletab:hover, .subtab:hover { color: var(--ink); }
.role-owner { --accent: var(--role-owner); } .role-dentist { --accent: var(--role-dentist); } .role-front-desk { --accent: var(--role-front-desk); }
.role-analyst { --accent: var(--role-analyst); } .role-admin { --accent: var(--role-admin); }
.roletab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.subtab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.roletab .count, .subtab .count { background: var(--brand); color: var(--on-brand); border-radius: 99px; font-size: 11.5px; padding: 0 7px; min-width: 20px; text-align: center; }
.content { padding: 22px 28px 64px; max-width: 1360px; background: var(--page); }
.content:focus { outline: none; }
.tabtitle { font-size: 22px; font-weight: 600; margin: 0 0 6px; }
.lede { color: var(--muted); margin: 0 0 20px; max-width: 72ch; }
.subbar.role-owner ~ .content .section > header h2 { color: var(--role-owner); }
.subbar.role-dentist ~ .content .section > header h2 { color: var(--role-dentist); }
.subbar.role-front-desk ~ .content .section > header h2 { color: var(--role-front-desk); }
.subbar.role-analyst ~ .content .section > header h2 { color: var(--role-analyst); }

/* sections */
.grid { display: grid; gap: 18px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span3 { grid-column: 1 / -1; }
.section { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
.section > header { display: flex; align-items: baseline; gap: 10px; padding: 14px 18px 10px; flex-wrap: wrap; }
.section > header h2 { font-size: 16px; font-weight: 600; }
.section > header .sub { color: var(--muted); font-size: 13px; }
.section > header .spacer { flex: 1; }
.section > header .stamp { color: var(--faint); font-size: 12.5px; white-space: nowrap; }
.section .body { padding: 4px 18px 18px; }
.section .body.flush { padding: 0 0 6px; }
.section.loading .body { opacity: .55; }

/* controls */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-2); background: var(--card); padding: 6px 12px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13.5px; font-weight: 500; white-space: nowrap; color: var(--ink); text-decoration: none; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { background: var(--brand-ink); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 9px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: none; color: var(--muted); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.refresh svg { width: 14px; height: 14px; }
.section.loading .refresh svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 4px 11px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 0 0 1px var(--line-2); font-weight: 600; }
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label.field > span { font-weight: 500; }
input[type=text], input[type=email], input[type=number], input[type=date], input[type=datetime-local], input[type=url], input[type=tel], select, textarea {
  border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 7px 9px; background: var(--card); color: var(--ink); width: 100%; min-width: 0; }
textarea { resize: vertical; min-height: 70px; }
.form { display: grid; gap: 12px; }
.form .cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--ink); font-size: 13.5px; }
.checks label { display: inline-flex; gap: 6px; align-items: center; }
.err { color: var(--bad); font-size: 13px; }

/* data */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: var(--card); }
.kpi { background: var(--card); padding: 14px 16px; box-shadow: 1px 0 0 var(--line), 0 1px 0 var(--line); }
.kpi .v { font-size: 26px; font-weight: 600; letter-spacing: -.01em; }
.kpi .l { color: var(--muted); font-size: 13px; }
.kpi .d { font-size: 12.5px; margin-top: 2px; color: var(--faint); }
.kpi .d.good { color: var(--live); } .kpi .d.bad { color: var(--bad); }
.tablewrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12.5px; padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t tr:last-child td { border-bottom: 0; }
table.t td.n, table.t th.n { text-align: right; }
table.t tr.clickable { cursor: pointer; } table.t tr.clickable:hover td { background: var(--surface); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.live { background: var(--live-soft); color: var(--live); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.brand { background: var(--brand-soft); color: var(--brand-ink); border-color: transparent; }
.badge.sample { background: var(--warn-soft); color: var(--warn); border: 1px dashed var(--warn); }
.badge.sample[hidden] { display: none; }
.muted { color: var(--muted); } .small { font-size: 13px; } .faint { color: var(--faint); }
.empty { padding: 26px 18px; text-align: center; color: var(--muted); }
.list { display: grid; }
.item { padding: 12px 18px; border-top: 1px solid var(--line); display: grid; gap: 4px; }
.item:first-child { border-top: 0; }
.item .top { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.bars { display: grid; gap: 7px; }
.bar { display: grid; grid-template-columns: 180px 1fr 80px; gap: 10px; align-items: center; font-size: 13.5px; }
.bar .track { background: var(--surface); border-radius: 4px; height: 12px; overflow: hidden; }
.bar .fill { background: var(--brand); height: 100%; border-radius: 4px; }
.bar .num { text-align: right; }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.links { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.linkcard { display: block; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; text-decoration: none; color: var(--ink); background: var(--card); }
.linkcard:hover { border-color: var(--brand); }
.linkcard b { display: block; } .linkcard span { color: var(--muted); font-size: 13px; }

/* call center: the one loud element */
.ring { display: grid; grid-template-columns: auto 1fr auto; gap: 18px; align-items: center; background: var(--page); color: var(--ink); border: 1px solid var(--line); border-left: 6px solid var(--accent, var(--brand)); border-radius: var(--radius); padding: 16px 20px; margin-bottom: 18px; }
.ring .pulse { position: relative; width: 44px; height: 44px; border-radius: 50%; background: var(--brand-soft); display: grid; place-items: center; }
.ring .pulse svg { width: 22px; height: 22px; color: var(--accent, var(--brand)); }
.ring .pulse::before, .ring .pulse::after { content: ""; position: absolute; inset: -6px; border: 2px solid var(--accent, var(--brand)); opacity: .5; border-radius: 50%; animation: ringout 1.6s ease-out infinite; }
.ring .pulse::after { animation-delay: .8s; }
@keyframes ringout { from { transform: scale(.85); opacity: 1; } to { transform: scale(1.5); opacity: 0; } }
.ring .who-calls { font-size: 22px; font-weight: 600; letter-spacing: .01em; }
.ring .what { color: var(--muted); }
.ring .btn { background: var(--brand); color: #fff; border-color: var(--brand); }
.ring.emergency { background: var(--bad-soft); border-left-color: var(--bad); }
.ring.emergency .pulse svg { color: var(--bad); }
.cc { display: grid; grid-template-columns: 360px 1fr; gap: 18px; align-items: start; }
.queue .item { cursor: pointer; }
.queue .item[aria-selected="true"] { background: var(--brand-soft); }
.callcard .bigline { font-size: 22px; font-weight: 600; }
.callcard dl { display: grid; grid-template-columns: 160px 1fr; gap: 6px 14px; margin: 14px 0; }
.callcard dt { color: var(--muted); font-size: 13.5px; } .callcard dd { margin: 0; }
.callcard .summary { font-size: 16px; line-height: 1.55; max-width: 70ch; margin: 10px 0; }
.nba { border-left: 3px solid var(--live); background: var(--live-soft); padding: 10px 12px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* previews */
.postcard { aspect-ratio: 3 / 2; border-radius: 6px; border: 1px solid var(--line-2); overflow: hidden; display: grid; grid-template-columns: 1fr 1fr; background: #fff; color: #241430; }
.postcard .art { background: var(--pc-accent, #5B2A86); color: #fff; padding: 18px; display: flex; flex-direction: column; justify-content: flex-end; background-size: cover; background-position: center; }
.postcard .art h3 { font-size: clamp(16px, 2.2vw, 24px); }
.postcard .copy { padding: 16px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.postcard .cta { margin-top: auto; font-weight: 700; color: var(--pc-accent, #5B2A86); }
.swatch { width: 18px; height: 18px; border-radius: 4px; display: inline-block; vertical-align: middle; border: 1px solid var(--line-2); }
.timeline { display: flex; gap: 2px; margin: 6px 0; max-width: 260px; }
.timeline span { flex: 1; height: 6px; background: var(--line); border-radius: 3px; }
.timeline span.on { background: var(--live); }

/* login, dialog, toast */
/* Sign-in: neutral (the clinic is unknown until sign-in), one centred white card, one purple primary button. */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: var(--page); }
.login .panel { width: min(400px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 32px 28px; display: grid; gap: 16px; text-align: center; }
.login h1 { font-size: 24px; margin: 0; color: var(--ink); }
.login .muted { margin: 0; font-size: 14.5px; }
.login .btn.signin { justify-content: center; width: 100%; padding: 11px 16px; font-size: 15px; font-weight: 600; border-radius: 8px; color: var(--on-brand); }
.login .btn.signin:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
.login .btn.signin[disabled] { opacity: .7; }
.login .err { margin: 0; font-size: 14px; }
.login .err:empty { display: none; }
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(680px, calc(100% - 32px)); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(20, 10, 30, .45); }
dialog header { padding: 16px 20px 0; } dialog header h2 { font-size: 18px; }
dialog .dbody { padding: 14px 20px; max-height: 70vh; overflow-y: auto; }
dialog footer { padding: 12px 20px 16px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line); }
#toasts { position: fixed; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); right: 16px; display: grid; gap: 8px; z-index: 50; }
.toast { background: var(--ink); color: var(--card); padding: 10px 14px; border-radius: 8px; max-width: 380px; font-size: 14px; }
.toast.bad { background: var(--bad); color: #fff; }
.skeleton { height: 90px; border-radius: 8px; background: linear-gradient(90deg, var(--surface), var(--line), var(--surface)); background-size: 200% 100%; animation: sk 1.2s linear infinite; }
@keyframes sk { to { background-position: -200% 0; } }

@media (max-width: 1100px) { .g3 { grid-template-columns: 1fr 1fr; } .cc { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .rolebar { padding: 8px 16px; }
  .rolebar .tabs { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
  .rolebar .roletab { flex: 1; justify-content: center; padding: 7px 8px; border-bottom: 0; border-radius: 7px; font-size: 14px; }
  .rolebar .roletab[aria-selected="true"] { background: var(--page); box-shadow: 0 1px 2px rgba(20, 10, 30, .12); }
  .rolebar:not([hidden]) + .subbar { top: calc(env(safe-area-inset-top, 0px) + 54px); }
  .apphead .who { display: none; }
  .g2, .g3 { grid-template-columns: 1fr; } .span2 { grid-column: auto; }
  .content, .apphead, .subbar { padding-left: 16px; padding-right: 16px; }
  .bar { grid-template-columns: 110px 1fr 60px; }
  .callcard dl { grid-template-columns: 1fr; }
  .ring { grid-template-columns: auto 1fr; } .ring > :last-child { grid-column: 1 / -1; }
  .who { display: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
.form > .btn, .form > div > .btn.primary { justify-self: start; }

/* Data pipelines: 30-day status strips per layer (design 2r-B section 8) */
.strips { display: grid; gap: 8px; }
.strip { display: grid; grid-template-columns: 72px 1fr; align-items: center; gap: 8px; }
.strip .lname { font-size: 12px; color: var(--muted); font-weight: 600; }
.strip .cells { display: grid; grid-template-columns: repeat(30, minmax(0, 1fr)); gap: 2px; }
.cell { display: inline-block; height: 18px; min-width: 6px; border-radius: 3px; background: var(--surface); border: 1px solid var(--line); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend .cell { width: 12px; height: 12px; }
.cell.s-succeeded, .cell.s-dry_run { background: var(--live); border-color: transparent; }
.cell.s-partial, .cell.s-waiting_upstream { background: var(--warn); border-color: transparent; }
.cell.s-failed, .cell.s-refused { background: var(--bad); border-color: transparent; }
.cell.s-running { background: var(--brand-ink); border-color: transparent; }
.cell.s-disabled, .cell.s-skipped_concurrent { background: var(--muted); border-color: transparent; opacity: .55; }
.cell.s-not_configured { background: var(--surface); border: 1px dashed var(--muted); }
.cell.s-idle { background: var(--line); border-color: transparent; }
.cell.s-none { background: transparent; border: 1px dotted var(--line); }
