:root {
  --bg: #F3F6FB;
  --card: #FFFFFF;
  --ink: #12203D;
  --ink-2: #4A5A78;
  --muted: #7A88A3;
  --line: #E1E7F1;
  --brand: #1F4FD1;
  --brand-ink: #FFFFFF;
  --brand-soft: #E9EFFE;
  --navy: #0F2A5F;
  --ok: #157A47;      --ok-bg: #E4F5EC;
  --warn: #9A5B00;    --warn-bg: #FFF2DB;
  --bad: #B42318;     --bad-bg: #FDE8E6;
  --info: #1F4FD1;    --info-bg: #E9EFFE;
  --gray: #5B6780;    --gray-bg: #EEF1F6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 32, 61, .06), 0 4px 14px rgba(16, 32, 61, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0C1324; --card: #141E35; --ink: #E8EDF7; --ink-2: #B5C0D6; --muted: #8592AD; --line: #24314F;
    --brand: #6B95FF; --brand-ink: #0C1324; --brand-soft: #1B2A4E; --navy: #0A1530;
    --ok: #5FD39A; --ok-bg: #133325; --warn: #F2B85B; --warn-bg: #3A2C12; --bad: #FF8A80; --bad-bg: #3D1916;
    --info: #8FB0FF; --info-bg: #1B2A4E; --gray: #A6B1C7; --gray-bg: #1D2843;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0C1324; --card: #141E35; --ink: #E8EDF7; --ink-2: #B5C0D6; --muted: #8592AD; --line: #24314F;
  --brand: #6B95FF; --brand-ink: #0C1324; --brand-soft: #1B2A4E; --navy: #0A1530;
  --ok: #5FD39A; --ok-bg: #133325; --warn: #F2B85B; --warn-bg: #3A2C12; --bad: #FF8A80; --bad-bg: #3D1916;
  --info: #8FB0FF; --info-bg: #1B2A4E; --gray: #A6B1C7; --gray-bg: #1D2843;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background:
  radial-gradient(1200px 500px at 50% -10%, var(--brand-soft), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 28px 22px 22px; box-shadow: var(--shadow); }
.brand-mark { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; background: var(--brand); color: var(--brand-ink); margin-bottom: 18px; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--brand); }
.login h1 { font-size: 24px; margin: 4px 0 6px; }
.hint { margin-top: 16px; font-size: 13px; color: var(--muted); text-align: center; }

/* ---------- forms ---------- */
.form { display: grid; gap: 14px; margin-top: 20px; }
.form label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--card); font-size: 16px; outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.form-error { color: var(--bad); background: var(--bad-bg); padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.req::after { content: " *"; color: var(--bad); }

.btn { min-height: 46px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 650; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; color: var(--ink); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }

/* ---------- shell ---------- */
.top { position: sticky; top: 0; z-index: 5; background: var(--navy); color: #fff; padding-top: env(safe-area-inset-top); }
.top-in { max-width: 720px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.top-lab { font-size: 12px; opacity: .75; font-weight: 600; letter-spacing: .02em; }
.top-doc { font-size: 17px; font-weight: 700; }
.top-btns { display: flex; gap: 8px; }
.icon-btn { position: relative; text-decoration: none; width: 40px; height: 40px; border-radius: 12px; border: 0; background: rgba(255,255,255,.1); color: #fff; display: grid; place-items: center; cursor: pointer; }
.page { max-width: 720px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); }
.tabs a { display: grid; justify-items: center; gap: 2px; padding: 6px 2px; border-radius: 12px; color: var(--muted); text-decoration: none; font-size: 11.5px; font-weight: 600; }
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.on { color: var(--brand); background: var(--brand-soft); }
@media (min-width: 760px) { .tabs { max-width: 720px; margin: 0 auto 12px; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); } }

/* ---------- cards / stats ---------- */
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 2px 10px; }
.section-title h2 { font-size: 17px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); text-align: left; cursor: pointer; }
.stat b { display: block; font-size: 22px; font-weight: 750; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat.warn b { color: var(--warn); } .stat.bad b { color: var(--bad); }
.balance { background: var(--navy); color: #fff; border-radius: 18px; padding: 16px 18px; display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.balance small { display: block; opacity: .75; font-size: 12.5px; font-weight: 600; }
.balance strong { font-size: 24px; font-variant-numeric: tabular-nums; }
.balance .btn { background: rgba(255,255,255,.12); border-color: transparent; color: #fff; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--gray-bg); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: transparent; min-height: 36px; padding: 0 4px; border-radius: 9px; font-weight: 650; font-size: 13.5px; white-space: nowrap; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.search { margin: 10px 0 12px; }

.list { display: grid; gap: 10px; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.item-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.item h3 { font-size: 16px; font-weight: 700; }
.item .sub { color: var(--ink-2); font-size: 14px; margin-top: 2px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.meta b { color: var(--ink-2); font-weight: 600; }
.pill { white-space: nowrap; font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: 999px; }
.pill.ok { color: var(--ok); background: var(--ok-bg); } .pill.warn { color: var(--warn); background: var(--warn-bg); }
.pill.bad { color: var(--bad); background: var(--bad-bg); } .pill.info { color: var(--info); background: var(--info-bg); }
.pill.gray { color: var(--gray); background: var(--gray-bg); }
.empty { text-align: center; color: var(--muted); padding: 34px 12px; }
.more { margin-top: 12px; }

/* ---------- new case ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.teeth { display: grid; gap: 6px; }
.arch { display: grid; grid-template-columns: repeat(16, 1fr); gap: 3px; }
.arch .mid { border-left: 2px solid var(--line); }
.tooth { min-height: 34px; padding: 0; border-radius: 8px; border: 1px solid var(--line); background: var(--card); font-size: 11px; font-weight: 700; color: var(--ink-2); cursor: pointer; font-variant-numeric: tabular-nums; }
.tooth.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.teeth-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 600; cursor: pointer; }
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.photos { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ph { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--gray-bg); border: 1px dashed var(--line); display: grid; place-items: center; }
.ph img { width: 100%; height: 100%; object-fit: cover; }
.ph button { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; }
.ph label { width: 100%; height: 100%; display: grid; place-items: center; cursor: pointer; color: var(--brand); font-size: 26px; font-weight: 300; }
.ph input { display: none; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.done { text-align: center; padding: 28px 10px; }
.done .tick { width: 64px; height: 64px; border-radius: 50%; margin: 0 auto 14px; display: grid; place-items: center; background: var(--ok-bg); color: var(--ok); font-size: 32px; }

/* ---------- statement ---------- */
.st-head { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.st-head label { display: grid; gap: 4px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); min-width: 0; }
.st-head input { min-width: 0; }
.led { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.led-row { display: flex; justify-content: space-between; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.led-row:last-child { border-bottom: 0; }
.led-l { min-width: 0; }
.led-l b { display: block; font-size: 14.5px; }
.led-l span, .led-r span { display: block; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.led-r { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.led-r b { font-size: 14.5px; }
.led-r b.cr { color: var(--ok); }
.st-sum { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 12px 0; }
@media (min-width: 560px) { .st-sum { grid-template-columns: repeat(4, 1fr); } }
.st-sum div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.st-sum span { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.st-sum b { font-variant-numeric: tabular-nums; }
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 700; background: var(--gray-bg); position: sticky; top: 0; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.print-only { display: none; }

/* ---------- account ---------- */
.rows { display: grid; gap: 0; }
.rows a, .rows button { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 4px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-decoration: none; color: var(--ink); font-weight: 600; cursor: pointer; text-align: left; width: 100%; }
.rows :last-child { border-bottom: 0; }
.rows small { color: var(--muted); font-weight: 500; }

.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; z-index: 20; max-width: calc(100% - 32px); }

@media print {
  .top, .tabs, .no-print, .toast { display: none !important; }
  body { background: #fff; color: #000; }
  .page { padding: 0; max-width: none; }
  .print-only { display: block; margin-bottom: 12px; }
  .table-wrap, .st-sum div, .led, .led-row { border-color: #999; }
  .led-row { break-inside: avoid; }
  th { background: #eee; }
}

/* ---------- v3: updates, quick actions, invoice, pickup, problems ---------- */
.bell .badge { position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #E5484D; color: #fff; font-size: 11px; font-weight: 800; display: grid; place-items: center; }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.quick .btn { font-size: 14px; }
.invite { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 10px; padding: 12px 14px; border-radius: var(--radius); background: var(--brand-soft); border: 1px solid var(--line); }
.invite b { display: block; font-size: 14.5px; }
.invite span { font-size: 13px; color: var(--ink-2); }
.invite-btns { display: flex; gap: 8px; }
.item-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.item-actions .pill { margin-right: auto; }
.back { display: flex; align-items: center; gap: 10px; margin: 2px 0 14px; }
.back h2 { font-size: 19px; }
.icon-link { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--card); border: 1px solid var(--line); color: var(--ink); }
a.item.note { display: block; text-decoration: none; color: inherit; }
a.item.note.unread { border-color: var(--brand); box-shadow: inset 3px 0 0 var(--brand), var(--shadow); }
.led-row.link { cursor: pointer; }
.led-row.link:hover { background: var(--gray-bg); }
.led-row.link .led-l b::after { content: "  ›"; color: var(--brand); }
.lbl { font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 0 0 6px; }
.stepper { display: grid; grid-template-columns: 46px 1fr 46px; gap: 8px; }
.stepper button { border: 1px solid var(--line); background: var(--card); border-radius: 11px; font-size: 22px; cursor: pointer; }
.stepper input { text-align: center; font-weight: 700; }
.invoice { padding: 18px; }
.inv-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; padding-bottom: 14px; border-bottom: 2px solid var(--ink); }
.inv-head h2 { font-size: 19px; }
.inv-no { text-align: right; }
.inv-no span { display: block; font-size: 11px; letter-spacing: .14em; font-weight: 800; color: var(--muted); }
.inv-no b { display: block; font-size: 17px; }
.inv-no small { color: var(--muted); }
.inv-to { margin: 14px 0; }
.inv-to span { display: block; font-size: 11px; letter-spacing: .1em; font-weight: 800; color: var(--muted); text-transform: uppercase; }
.inv-to b { display: block; font-size: 16px; }
.inv-to small { color: var(--muted); }
.invoice tfoot td { border-top: 2px solid var(--line); border-bottom: 0; font-size: 15px; }
.inv-bal { margin-top: 12px; font-size: 13px; }
@media print { .invoice { border: 0; box-shadow: none; padding: 0; } .inv-head { border-color: #000; } }

/* ---------- 3D scan files ---------- */
.scan-list { display: grid; gap: 6px; margin-bottom: 8px; }
.scan-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 11px; background: var(--card); }
.scan-ico { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-size: 11px; font-weight: 800; flex: none; }
.scan-name { flex: 1; min-width: 0; }
.scan-name b { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scan-name small { color: var(--muted); font-size: 12px; }
.scan-rm { width: 30px; height: 30px; border-radius: 50%; border: 0; background: var(--gray-bg); color: var(--ink-2); font-size: 18px; cursor: pointer; flex: none; }
.scan-add { position: relative; width: 100%; cursor: pointer; }
.scan-add input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.scan-ok { color: var(--ok); font-weight: 650; margin-bottom: 12px; }
.form label.scan-add { display: flex; font-size: 15px; font-weight: 650; color: var(--ink); gap: 8px; }

/* rate list */
.rate-r { text-align: right; white-space: nowrap; }
.rate-r b { font-size: 15px; font-variant-numeric: tabular-nums; }
.rate-r s { display: block; font-size: 12px; color: var(--muted); }
.rate-mine { color: var(--ok, #15803D); }
.rate-link { display: inline-block; margin-top: -6px; font-size: 13.5px; font-weight: 600; color: var(--brand); text-decoration: none; }
