:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f1f3f6; --border: #dfe3e8;
  --text: #17202a; --muted: #5f6b7a; --accent: #0f766e; --accent-ink: #ffffff; --accent-soft: #e0f2f0;
  --red: #b42318; --red-soft: #fde8e7; --orange: #b54708; --orange-soft: #fef0e1; --amber: #8a6100; --amber-soft: #fdf5d8;
  --green: #067647; --green-soft: #e3f6ec; --blue: #1d4ed8; --blue-soft: #e5edfd; --teal: #0e7490; --teal-soft: #e0f4f8;
  --grey: #4b5563; --grey-soft: #eceff3; --sim: #6d28d9; --sim-soft: #efe7fd;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419; --surface: #171d24; --surface-2: #1e252e; --border: #2c3540;
    --text: #e6eaef; --muted: #9aa5b1; --accent: #2bb3a3; --accent-ink: #0b1210; --accent-soft: #123a36;
    --red: #f97066; --red-soft: #3a1714; --orange: #f79009; --orange-soft: #3a2410; --amber: #fac515; --amber-soft: #352b0b;
    --green: #47cd89; --green-soft: #0f2e20; --blue: #84a9ff; --blue-soft: #16223f; --teal: #5fc9dd; --teal-soft: #0f2d33;
    --grey: #b4bcc6; --grey-soft: #252d36; --sim: #b69cf8; --sim-soft: #2a1f45;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1419; --surface: #171d24; --surface-2: #1e252e; --border: #2c3540;
  --text: #e6eaef; --muted: #9aa5b1; --accent: #2bb3a3; --accent-ink: #0b1210; --accent-soft: #123a36;
  --red: #f97066; --red-soft: #3a1714; --orange: #f79009; --orange-soft: #3a2410; --amber: #fac515; --amber-soft: #352b0b;
  --green: #47cd89; --green-soft: #0f2e20; --blue: #84a9ff; --blue-soft: #16223f; --teal: #5fc9dd; --teal-soft: #0f2d33;
  --grey: #b4bcc6; --grey-soft: #252d36; --sim: #b69cf8; --sim-soft: #2a1f45;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.45rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .85em; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.container { max-width: 1240px; margin: 0 auto; padding: 16px; }

.demo-banner { background: var(--sim); color: #fff; text-align: center; padding: 6px 16px; font-size: .85rem; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 16px; padding: 10px 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand .clinic { font-weight: 650; }
.logo { font-size: 1.6rem; } .logo.big { font-size: 2.6rem; }
.brand-mark { display: inline-flex; align-items: center; gap: 7px; text-decoration: none; color: var(--accent); font-weight: 750; letter-spacing: -.01em; flex: 0 0 auto; }
.brand-mark img { width: 28px; height: 28px; border-radius: 7px; display: block; }
.brand-mark .wordmark { font-size: 1.02rem; }
.brand-sep { width: 1px; align-self: stretch; background: var(--border); margin: 2px 2px; }
.auth-logo { display: block; margin: 0 auto; border-radius: 14px; }
.auth-brand .tagline { margin: 2px 0 6px; color: var(--accent); font-weight: 600; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: thin; }
.nav a { padding: 7px 11px; border-radius: 8px; text-decoration: none; color: var(--muted); white-space: nowrap; font-weight: 550; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.who { display: flex; align-items: center; gap: 10px; margin: 0; text-align: right; line-height: 1.25; }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin: 8px 0 14px; }
.section { margin: 22px 0 10px; }
.count { background: var(--surface-2); border-radius: 99px; padding: 1px 9px; font-size: .85rem; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.empty { text-align: center; color: var(--muted); padding: 28px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.wrap { align-items: flex-end; }
.grow { flex: 1; min-width: 160px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.narrow { max-width: 420px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 38px; }
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: .85rem; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ok { background: var(--green); border-color: var(--green); color: #fff; }
.btn.warn { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

label { display: flex; flex-direction: column; gap: 4px; font-weight: 550; font-size: .9rem; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-height: 38px; width: 100%; }
input[type="checkbox"], input[type="radio"] { width: 18px; min-height: 18px; height: 18px; padding: 0; flex: 0 0 auto; accent-color: var(--accent); }
.outcome { cursor: pointer; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.hint { font-weight: 400; font-size: .8rem; color: var(--muted); }
.field-error, .error-text { color: var(--red); font-size: .82rem; font-weight: 500; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin: 0; }
legend { font-weight: 650; padding: 0 6px; }
.checks { display: flex; flex-wrap: wrap; gap: 14px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px 16px; }
.grid-form .full, .filters .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-top: 12px; }
form.inline { margin: 0; }
.tpl-lang { min-width: 70px; align-self: center; }

.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; align-items: end; }
.filters .grow { grid-column: span 2; }
.filter-actions { display: flex; gap: 6px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: var(--green-soft); color: var(--green); border: 1px solid transparent; font-weight: 500; }
.flash.error { background: var(--red-soft); color: var(--red); }

.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.metrics.compact { margin-bottom: 12px; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; }
.metric-link { text-decoration: none; color: inherit; }
.metric-value { font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.metric-label { font-weight: 600; color: var(--muted); font-size: .88rem; }
.metric-sub { font-size: .78rem; color: var(--muted); }
.def summary { font-size: .75rem; color: var(--muted); cursor: pointer; }
.def p { font-size: .8rem; margin: 4px 0 0; color: var(--muted); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .76rem; font-weight: 650; white-space: nowrap; }
.badge.red { background: var(--red-soft); color: var(--red); } .badge.orange { background: var(--orange-soft); color: var(--orange); }
.badge.amber { background: var(--amber-soft); color: var(--amber); } .badge.green { background: var(--green-soft); color: var(--green); }
.badge.blue { background: var(--blue-soft); color: var(--blue); } .badge.teal { background: var(--teal-soft); color: var(--teal); }
.badge.grey { background: var(--grey-soft); color: var(--grey); } .badge.sim { background: var(--sim-soft); color: var(--sim); letter-spacing: .03em; }

.queue { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.task { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--grey); border-radius: var(--radius); padding: 12px 14px; }
.task.p1 { border-left-color: var(--red); } .task.p2 { border-left-color: var(--orange); } .task.p3 { border-left-color: var(--amber); }
.task-head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.task-ref { text-decoration: none; }
.task-reason { margin: 4px 0; }
.task-actions { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-top: 8px; }
.task-actions label { flex-direction: row; align-items: center; gap: 6px; }
.task-actions select { width: auto; }

.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { background: var(--surface-2); font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.table tr:last-child td { border-bottom: 0; }
.table tr.stale td { opacity: .6; }
.table tr.row-error td { background: var(--red-soft); }
.table select { min-width: 170px; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 14px 0; }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 12px; margin: 0; }
.kv dt { color: var(--muted); font-size: .88rem; } .kv dd { margin: 0; }
.mini-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.quote { border-left: 3px solid var(--border); padding: 4px 10px; margin-top: 4px; background: var(--surface-2); border-radius: 0 6px 6px 0; }
.timeline { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; max-height: 420px; overflow: auto; }
.sim-card { border-color: var(--sim); background: linear-gradient(0deg, var(--surface), var(--surface)), var(--sim-soft); }
.sim-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.sim-grid form { margin: 0; display: flex; }
.sim-grid fieldset { display: flex; flex-wrap: wrap; gap: 6px; align-content: flex-start; flex: 1; }
.sim-grid input { min-width: 0; flex: 1; }
.danger-zone { border-color: var(--red); }
.btn.call { background: var(--green); border-color: var(--green); color: #fff; }
.call-row { margin-top: 6px; }
.outcomes { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 6px 14px; }
.outcome { padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; }
.outcome:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.call-form .row { margin-top: 10px; }
[hidden] { display: none !important; }
.summary-text { white-space: pre-wrap; font-family: inherit; margin: 0; background: var(--surface-2); padding: 12px; border-radius: 8px; }
.checklist { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 6px; }
.checklist li.ok span { color: var(--green); font-weight: 700; } .checklist li.no span { color: var(--red); font-weight: 700; }
.steps { display: flex; gap: 6px; list-style: none; padding: 0; margin: 0 0 14px; flex-wrap: wrap; counter-reset: s; }
.steps li { counter-increment: s; padding: 5px 12px; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-size: .85rem; font-weight: 600; }
.steps li::before { content: counter(s) ". "; }
.steps li.active { background: var(--accent); color: var(--accent-ink); } .steps li.done { background: var(--accent-soft); color: var(--accent); }
.big-list { display: flex; gap: 20px; flex-wrap: wrap; list-style: none; padding: 0; font-size: 1.05rem; }
.walk li { margin-bottom: 6px; }

/* AI receptionist */
.subnav { display: flex; gap: 4px; overflow-x: auto; margin: 0 0 14px; border-bottom: 1px solid var(--border); scrollbar-width: thin; }
.subnav a { padding: 8px 12px; text-decoration: none; color: var(--muted); font-weight: 600; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.subnav a:hover { color: var(--text); }
.subnav a.active { color: var(--accent); border-bottom-color: var(--accent); }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
fieldset.plain > .card { margin-bottom: 0; }
.mode-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.mode-card { background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; font-weight: 400; gap: 8px; box-shadow: var(--shadow); }
.mode-card:has(input:checked), .mode-card.selected { border-color: var(--accent); background: linear-gradient(0deg, var(--surface), var(--surface)), var(--accent-soft); }
.mode-card .kv { grid-template-columns: 150px 1fr; margin-top: 4px; }
.status-detail { margin-top: 4px; color: var(--muted); }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; border-top: 1px solid var(--border); }
.table.hours input { min-width: 0; }
.chat { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; max-height: 460px; overflow: auto; }
.bubble { max-width: 85%; padding: 8px 12px; border-radius: 12px; font-size: .92rem; }
.bubble.ai { background: var(--sim-soft); align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.caller { background: var(--accent-soft); align-self: flex-end; border-bottom-right-radius: 4px; }

.auth-card { max-width: 420px; margin: 48px auto; }
.auth-card.wide { max-width: 560px; }
.auth-brand { text-align: center; margin-bottom: 14px; }
.auth-brand h1 { margin-top: 4px; }

@media (max-width: 860px) {
  .detail-grid { grid-template-columns: 1fr; }
  .who { margin-left: auto; }
  .nav { order: 3; flex-basis: 100%; }
}
@media (max-width: 640px) {
  .container { padding: 12px 16px; }
  .kv { grid-template-columns: 1fr; gap: 0 0; } .kv dd { margin-bottom: 8px; }
  .filters { grid-template-columns: 1fr 1fr; } .filters .grow { grid-column: 1 / -1; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric-value { font-size: 1.45rem; }
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive { border: 0; background: transparent; }
  .table.responsive thead { display: none; }
  .table.responsive tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; padding: 6px 0; }
  .table.responsive td { border: 0; padding: 4px 12px; display: flex; gap: 10px; }
  .table.responsive td::before { content: attr(data-label); flex: 0 0 100px; color: var(--muted); font-size: .8rem; font-weight: 600; }
  .task-actions input.grow { flex-basis: 100%; }
}
