:root {
  --ink: #262a30;
  --muted: #6b7280;
  --faint: #9aa1ab;
  --line: #e2e5e9;
  --line-strong: #cfd4da;
  --bg: #f3f4f6;
  --card: #ffffff;
  --accent: #3b5170;
  --accent-soft: #e8edf4;
  --danger: #b42318;
  --ok: #1d7a46;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- App chrome ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 20px; background: var(--accent); color: #fff;
}
.topbar .brand { color: #fff; font-weight: 600; text-decoration: none; font-size: 16px; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: #dfe6f0; text-decoration: none; padding: 6px 12px; border-radius: 6px; }
.topbar nav a.active, .topbar nav a:hover { background: rgba(255,255,255,.14); color: #fff; }

main { padding: 24px 20px 60px; }
.narrow { max-width: 760px; margin: 0 auto; }
h1.page { font-size: 22px; margin: 0 0 16px; font-weight: 600; }
.crumbs { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.crumbs a { text-decoration: none; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.search-row { display: flex; gap: 8px; }
.search-row input { flex: 1; }
input[type=text], input[type=number], input[type=url], input[type=password], input[type=date], select, textarea {
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 8px 10px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { min-height: 90px; resize: vertical; }
.btn {
  border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 6px;
  padding: 8px 16px; cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn.secondary { background: #fff; color: var(--accent); }
.btn.danger { background: #fff; color: var(--danger); border-color: #e6b4ae; }
.btn:disabled { opacity: .55; cursor: default; }
.hint { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); background: #fdf1f0; border: 1px solid #f3c9c4; padding: 10px 12px; border-radius: 8px; }
.empty { color: var(--muted); padding: 20px; text-align: center; }

.list { list-style: none; margin: 12px 0 0; padding: 0; }
.list li + li { border-top: 1px solid var(--line); }
.list a {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 16px; text-decoration: none; color: var(--ink);
}
.list a:hover { background: var(--accent-soft); }
.list .main { font-weight: 600; }
.list .sub { color: var(--muted); font-size: 13px; }
.list .amt { font-variant-numeric: tabular-nums; text-align: right; }

.plan-pick-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin: 8px 0 10px; flex-wrap: wrap; }
.plan-pick-head input { max-width: 260px; }
h2.step { font-size: 16px; margin: 0; font-weight: 600; }
.plan-table { width: 100%; border-collapse: collapse; }
.plan-table th { text-align: left; font-size: 12.5px; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line-strong); }
.plan-table td { padding: 10px 14px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.plan-table tbody tr { cursor: pointer; }
.plan-table tbody tr:hover { background: var(--accent-soft); }
.plan-table tbody tr:last-child td { border-bottom: 0; }
.plan-table .r { text-align: right; }
.plan-table .main { font-weight: 600; }
.nowrap { white-space: nowrap; }
.btn.small { padding: 4px 12px; font-size: 13px; text-decoration: none; display: inline-block; }
#plan-select { font-size: 13.5px; }

/* ---------- Plan preview layout ---------- */
.preview-layout { display: grid; grid-template-columns: 280px 1fr; gap: 24px; align-items: start; max-width: 1200px; margin: 0 auto; }
.controls { position: sticky; top: 16px; padding: 16px; }
.controls h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 8px; }
.controls h2:first-of-type { margin-top: 0; }
.check { display: flex; gap: 8px; align-items: flex-start; padding: 5px 0; cursor: pointer; }
.check input { margin-top: 3px; }
.check .why { display: block; color: var(--faint); font-size: 12px; }
.controls .btn { width: 100%; margin-top: 16px; padding: 10px; }
.paper-wrap { overflow-x: auto; }
@media (max-width: 900px) {
  .preview-layout { grid-template-columns: 1fr; }
  .controls { position: static; }
}

/* ---------- The printed treatment plan ---------- */
.paper {
  width: 8.5in; min-height: 11in; margin: 0 auto; padding: 0.5in;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 8px 24px rgba(0,0,0,.06);
  font-size: 10.5pt; line-height: 1.4; color: #2b2f33;
}
.tp-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.4in; }
.tp-brand { text-align: center; max-width: 3.4in; }
.tp-brand img { max-width: 3.2in; max-height: 1.6in; display: block; margin: 0 auto 4px; }
.tp-brand .contact { color: #666; font-size: 9.5pt; }
.tp-brand .placeholder { border: 1px dashed var(--line-strong); color: var(--faint); padding: 28px 24px; font-size: 9pt; }
.tp-benefits { flex: 0 1 3.6in; font-size: 8.5pt; }
.tp-benefits .label { color: #777; margin-bottom: 4px; font-size: 9pt; }
.tp-benefits table { width: 100%; border-collapse: collapse; }
.tp-benefits th { font-weight: 600; padding: 6px 4px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.tp-benefits td { padding: 6px 4px; text-align: center; }
.tp-benefits td:first-child, .tp-benefits th:first-child { text-align: left; }

.tp-title { text-align: center; font-size: 19pt; font-weight: 700; margin: 0.3in 0 2px; color: #33373c; }
.tp-sub { text-align: center; color: #777; margin: 0 0 0.2in; font-size: 9.5pt; }

.tp-procs { width: 100%; border-collapse: collapse; }
.tp-procs thead th { color: #999; font-weight: 600; font-size: 9pt; padding: 7px 10px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line-strong); text-align: left; }
.tp-procs td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tp-procs .tooth { width: 0.9in; white-space: nowrap; }
.tp-procs .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; width: 0.95in; }
.tp-procs .code { color: #777; margin-right: 6px; }
.tp-procs tr { break-inside: avoid; }
.tp-group { font-weight: 600; font-size: 10pt; margin: 0.18in 0 4px; color: #444; break-after: avoid; }
.tp-group-sub td { font-weight: 600; background: #fafafa; }

.tp-totals { width: 100%; border-collapse: collapse; margin-top: 0.25in; break-inside: avoid; }
.tp-totals td { padding: 7px 10px; border-top: 1px solid var(--line); font-weight: 600; }
.tp-totals td:last-child { text-align: right; width: 1.4in; font-variant-numeric: tabular-nums; }
.tp-totals tr.patient td { font-size: 11.5pt; color: #222; border-top: 2px solid var(--line-strong); }

.tp-options { margin-top: 0.3in; break-inside: avoid; }
.tp-options h2 { text-align: center; font-weight: 400; font-size: 14pt; color: #555; margin: 0 0 6px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.tp-option-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(1.55in, 1fr)); gap: 0.15in; padding: 10px 0 12px; border-bottom: 1px solid var(--line); }
.tp-option { text-align: center; display: flex; flex-direction: column; align-items: center; break-inside: avoid; }
.tp-option .t { font-weight: 700; font-size: 10.5pt; }
.tp-option .d { color: #555; font-size: 9.5pt; min-height: 2.6em; margin: 2px 0 8px; }
.tp-option .amt { font-weight: 700; font-size: 10.5pt; line-height: 1.3; }
.tp-option .qr { width: 0.95in; height: 0.95in; margin-top: 2px; }
.tp-option .qr svg, .tp-option .qr img { width: 100%; height: 100%; display: block; }
.tp-option .box { margin-top: auto; padding-top: 10px; font-size: 9pt; color: #555; display: flex; align-items: center; gap: 5px; }
.tp-option .box::before { content: ""; width: 12px; height: 12px; border: 1.5px solid #777; border-radius: 2px; display: inline-block; }

.tp-note { margin-top: 0.25in; break-inside: avoid; }
.tp-note h3 { font-weight: 400; font-size: 12.5pt; color: #444; margin: 0 0 6px; }
.tp-note p { margin: 0; white-space: pre-line; font-size: 9.5pt; }

.tp-signature { margin-top: 0.3in; break-inside: avoid; }
.tp-signature .who { margin: 0 0 0.35in; }
.sig-lines { display: grid; grid-template-columns: 1fr 1.6in; gap: 0.35in; }
.sig-lines div { border-top: 1px solid #555; padding-top: 4px; font-size: 8.5pt; color: #555; }

.tp-disclaimer { margin-top: 0.25in; padding-top: 6px; border-top: 1px solid var(--line); font-size: 7.5pt; color: #555; text-align: center; break-inside: avoid; }

@page { size: letter; margin: 0.5in 0.5in 0.55in; @bottom-center { content: "Page " counter(page) " of " counter(pages); font-size: 8pt; color: #888; } }
@media print {
  body { background: #fff; }
  main { padding: 0; }
  .no-print, .controls, .crumbs { display: none !important; }
  .preview-layout { display: block; }
  .paper { width: auto; min-height: 0; padding: 0; margin: 0; box-shadow: none; }
  .tp-procs thead { display: table-header-group; }
}

/* ---------- Settings ---------- */
.settings-layout { display: grid; grid-template-columns: 200px 1fr; gap: 24px; max-width: 1060px; margin: 0 auto; align-items: start; }
.settings-nav { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 2px; }
.settings-nav a { padding: 8px 12px; border-radius: 6px; text-decoration: none; color: var(--ink); border-left: 3px solid transparent; }
.settings-nav a.active { background: var(--card); border-left-color: var(--accent); font-weight: 600; }
.settings-section { padding: 4px 20px; }
.settings-section h2 { font-size: 17px; margin: 16px 0 4px; }
.field { display: grid; grid-template-columns: 1fr minmax(220px, 380px); gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line); align-items: center; }
.field:last-child { border-bottom: 0; }
.field.wide { grid-template-columns: 1fr; }
.field .lbl { font-weight: 600; font-size: 14px; }
.field .help { color: var(--muted); font-size: 12.5px; }
.field .ctl { justify-self: stretch; }
.field .ctl.toggle { justify-self: end; }
.field.disabled { opacity: .5; }
.switch { position: relative; display: inline-block; width: 42px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cfd4da; border-radius: 24px; transition: .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.pct { display: flex; align-items: center; gap: 6px; }
.pct input { max-width: 120px; }
.provider { border: 1px solid var(--line); border-radius: 8px; padding: 4px 16px; margin: 14px 0; }
.provider-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-top: 10px; }
.provider-head strong { font-size: 15px; }
.qr-preview { width: 96px; height: 96px; }
.qr-preview svg { width: 100%; height: 100%; }
.header-preview { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.header-preview img { max-height: 90px; max-width: 260px; border: 1px solid var(--line); padding: 6px; background: #fff; }
.savebar { position: sticky; bottom: 0; display: flex; justify-content: flex-end; align-items: center; gap: 12px; padding: 12px 20px; background: var(--card); border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; }
.savebar input { max-width: 140px; }
.status-ok { color: var(--ok); font-size: 14px; }
@media (max-width: 800px) {
  .settings-layout { grid-template-columns: 1fr; }
  .settings-nav { position: static; flex-direction: row; flex-wrap: wrap; }
  .field { grid-template-columns: 1fr; }
  .field .ctl.toggle { justify-self: start; }
}
