:root {
  --brand: #0E5FAE;
  --brand-ink: #0A4A8A;
  --brand-soft: #E6F0FB;
  --accent: #F07A2B;
  --bg: #F4F6FA;
  --surface: #FFFFFF;
  --surface-2: #F8FAFD;
  --text: #172033;
  --muted: #5B6475;
  --border: #E1E6EE;
  --danger: #C62828;
  --danger-soft: #FDECEC;
  --warn: #9A5B00;
  --warn-soft: #FFF4E0;
  --ok: #1E7B45;
  --ok-soft: #E6F5EC;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --radius: 14px;
  --bar-h: 56px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #5AA2F0;
    --brand-ink: #8CC0FA;
    --brand-soft: #16304F;
    --accent: #F59150;
    --bg: #0E131D;
    --surface: #161E2C;
    --surface-2: #1B2536;
    --text: #E7ECF5;
    --muted: #9AA5B8;
    --border: #283347;
    --danger: #F07171;
    --danger-soft: #3A1C20;
    --warn: #F2B35B;
    --warn-soft: #36291A;
    --ok: #5CCB8A;
    --ok-soft: #173125;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
img { max-width: 100%; }
.tnum { font-variant-numeric: tabular-nums; }

#app { max-width: 640px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.boot { flex: 1; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); }
.boot img { border-radius: 18px; }

/* ---------- top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 4px;
  min-height: var(--bar-h);
  padding: env(safe-area-inset-top) 6px 0;
  background: var(--brand);
  color: #fff;
}
@media (prefers-color-scheme: dark) { .bar { background: #10284A; } }
.bar h1 { flex: 1; font-size: 19px; font-weight: 600; padding: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .sub { display: block; font-size: 12.5px; font-weight: 400; opacity: .85; }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: transparent; color: inherit; display: grid; place-items: center; flex: none;
}
.icon-btn:active { background: rgba(255, 255, 255, .18); }
.icon-btn svg { width: 24px; height: 24px; }

/* ---------- content ---------- */
.content { flex: 1; padding: 14px 14px 24px; display: flex; flex-direction: column; gap: 14px; }
.content.has-actionbar { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px;
}
.card h2, .section-title { font-size: 15px; font-weight: 650; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; padding: 4px 2px 0; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-size: 12.5px; }
.card h2 { margin-bottom: 10px; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }

/* ---------- fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13.5px; font-weight: 600; color: var(--muted); }
.input, select.input {
  width: 100%; min-height: 48px; padding: 10px 12px;
  border: 1.5px solid var(--border); border-radius: 10px;
  background: var(--surface-2); outline: none;
  -webkit-appearance: none; appearance: none;
}
select.input { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 21px, calc(100% - 13px) 21px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.input:focus { border-color: var(--brand); background: var(--surface); }
.input.money { text-align: right; font-variant-numeric: tabular-nums; }
.money-wrap { position: relative; }
.money-wrap::before { content: "Rs"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; pointer-events: none; }
.money-wrap .input { padding-left: 36px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (max-width: 380px) { .grid-3 { grid-template-columns: 1fr; } }
.hint { font-size: 13px; color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 0;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 600; font-size: 15.5px; background: var(--surface-2); color: var(--text);
  border: 1.5px solid var(--border);
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
@media (prefers-color-scheme: dark) { .btn.primary { background: #2F7FD6; border-color: #2F7FD6; } }
.btn.accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { color: var(--danger); background: transparent; border-color: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; }
.btn:active:not(:disabled) { transform: translateY(1px); filter: brightness(.96); }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
}
.actionbar-inner { max-width: 612px; margin: 0 auto; display: flex; gap: 10px; }
.actionbar-inner .btn { flex: 1; padding: 0 8px; min-width: 0; }
@media (max-width: 400px) { .actionbar-inner .btn svg { display: none; } }

.fab {
  position: fixed; z-index: 20; right: max(18px, calc((100vw - 640px) / 2 + 18px)); bottom: calc(20px + env(safe-area-inset-bottom));
  height: 56px; padding: 0 22px 0 18px; border-radius: 18px; border: 0;
  background: var(--brand); color: #fff; font-weight: 650; font-size: 16px;
  display: inline-flex; align-items: center; gap: 8px; box-shadow: var(--shadow-lg);
}
@media (prefers-color-scheme: dark) { .fab { background: #2F7FD6; } }
.fab svg { width: 24px; height: 24px; }

/* ---------- chips / badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 650; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.badge.draft { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge.generated { background: var(--brand-soft); color: var(--brand-ink); }
.badge.submitted { background: var(--ok-soft); color: var(--ok); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px; padding: 6px 14px; border-radius: 999px; border: 1.5px solid var(--border);
  background: var(--surface-2); font-size: 14.5px; font-weight: 550; display: inline-flex; align-items: center; gap: 6px;
}
.chip small { color: var(--muted); font-weight: 500; font-size: 12px; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip.on small { color: rgba(255, 255, 255, .8); }

/* ---------- home ---------- */
.hero-sum { background: linear-gradient(135deg, var(--brand), var(--brand-ink)); color: #fff; border: 0; }
@media (prefers-color-scheme: dark) { .hero-sum { background: linear-gradient(135deg, #1C4F8A, #143A66); } }
.hero-sum .label { font-size: 13px; opacity: .85; }
.hero-sum .big { font-size: 28px; font-weight: 700; letter-spacing: -.01em; margin-top: 2px; }
.hero-sum .meta { font-size: 13.5px; opacity: .9; margin-top: 4px; }
.claim-card { display: flex; align-items: center; gap: 12px; padding: 14px; text-align: left; width: 100%; color: inherit; }
.claim-card .cal {
  width: 50px; height: 54px; border-radius: 12px; background: var(--brand-soft); color: var(--brand-ink);
  display: grid; place-content: center; text-align: center; flex: none; line-height: 1.1;
}
.claim-card .cal b { font-size: 16px; }
.claim-card .cal small { font-size: 11.5px; font-weight: 600; }
.claim-card .t { font-weight: 650; font-size: 16px; }
.claim-card .amt { font-weight: 700; font-size: 16px; text-align: right; white-space: nowrap; }
.list { display: flex; flex-direction: column; gap: 10px; }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); display: grid; gap: 10px; justify-items: center; }
.empty svg { width: 56px; height: 56px; color: var(--brand); opacity: .5; }
.banner { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: var(--radius); background: var(--brand-soft); color: var(--brand-ink); }
.banner svg { width: 24px; height: 24px; flex: none; }
.banner .grow { flex: 1; font-size: 14px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- claim editor ---------- */
.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.totals .cell { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.totals .cell span { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.totals .cell b { font-size: 15px; }
.grand { display: flex; align-items: baseline; justify-content: space-between; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
.grand b { font-size: 24px; }
.rcpt { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; padding: 12px; color: inherit; }
.rcpt .date { width: 46px; flex: none; text-align: center; line-height: 1.1; }
.rcpt .date b { display: block; font-size: 19px; }
.rcpt .date small { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.rcpt .who { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rcpt .split { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rcpt .amt { font-weight: 700; white-space: nowrap; }
.rcpt .flag { color: var(--warn); }
.rcpt .flag svg { width: 18px; height: 18px; vertical-align: -3px; }
.rownum { font-size: 11px; color: var(--muted); }

/* ---------- checks ---------- */
.checks { display: flex; flex-direction: column; gap: 8px; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.check svg { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.check.err { background: var(--danger-soft); color: var(--danger); }
.check.warn { background: var(--warn-soft); color: var(--warn); }
.check.ok { background: var(--ok-soft); color: var(--ok); }
.check.info { background: var(--brand-soft); color: var(--brand-ink); }
.decl { display: flex; flex-direction: column; gap: 10px; font-size: 14px; }
.decl p { padding-left: 22px; position: relative; }
.decl p::before { content: "☑"; position: absolute; left: 0; top: 0; color: var(--muted); }
.confirm { display: flex; gap: 12px; align-items: center; padding: 12px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--surface-2); font-weight: 600; margin-top: 12px; }
.confirm input { width: 24px; height: 24px; accent-color: var(--brand); flex: none; }
.confirm.on { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.switch-row { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; z-index: 1; cursor: pointer; }
.switch i { position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: background .2s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.switch input:checked + i { background: var(--brand); }
.switch input:checked + i::after { transform: translateX(20px); }
.sig-preview { background: #fff; border: 1px dashed var(--border); border-radius: 10px; height: 84px; display: grid; place-items: center; padding: 8px; }
.sig-preview img { max-height: 66px; max-width: 100%; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }

/* ---------- family editor ---------- */
.fam-list { display: flex; flex-direction: column; gap: 8px; }
.fam-item { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.fam-item .grow b { display: block; font-weight: 600; }
.fam-item .grow small { color: var(--muted); }
.fam-item .icon-btn { width: 40px; height: 40px; color: var(--muted); }
.fam-add { display: grid; grid-template-columns: 1fr 120px; gap: 8px; }
.fam-add .btn { grid-column: 1 / -1; }

/* ---------- sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(10, 15, 25, .45); animation: fade .18s ease-out; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; margin: 0 auto; max-width: 640px;
  background: var(--surface); border-radius: 20px 20px 0 0; box-shadow: var(--shadow-lg);
  max-height: 92vh; max-height: 92dvh; display: flex; flex-direction: column;
  animation: up .22s cubic-bezier(.2, .8, .2, 1);
}
.sheet.full { top: 0; max-height: none; border-radius: 0; }
.sheet-head { display: flex; align-items: center; gap: 6px; padding: 10px 8px 6px 18px; border-bottom: 1px solid var(--border); }
.sheet.full .sheet-head { padding-top: calc(10px + env(safe-area-inset-top)); }
.sheet-head h2 { flex: 1; font-size: 18px; font-weight: 650; }
.sheet-head .icon-btn { color: var(--muted); }
.sheet-body { overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 10px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); display: flex; gap: 10px; flex-wrap: wrap; }
.sheet-foot .btn { flex: 1; }
.live-total { display: flex; align-items: baseline; justify-content: space-between; padding: 12px 14px; border-radius: 12px; background: var(--brand-soft); color: var(--brand-ink); }
.live-total b { font-size: 22px; }
.inline-warn { font-size: 13.5px; color: var(--warn); background: var(--warn-soft); padding: 8px 10px; border-radius: 8px; }
.inline-warn:empty { display: none; }

/* ---------- preview ---------- */
.sheet.full .sheet-body { flex: 1; }
.preview-body { background: #5f6673; padding: 12px; gap: 12px; align-items: flex-start; overflow: auto; }
.preview-page { width: 100%; max-width: 900px; margin: 0 auto; flex: none; background: #fff; box-shadow: 0 4px 16px rgba(0, 0, 0, .35); cursor: zoom-in; }
.preview-body.zoom .preview-page { width: 220%; max-width: none; cursor: zoom-out; }
.preview-page canvas { display: block; width: 100%; height: auto; }
.preview-label { color: #dfe3ea; font-size: 12.5px; align-self: center; }

/* ---------- signature pad ---------- */
.sigpad-wrap { position: relative; background: #fff; border: 1.5px solid var(--border); border-radius: 12px; height: 220px; overflow: hidden; touch-action: none; }
.sigpad-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.sigpad-wrap .line { position: absolute; left: 22px; right: 22px; bottom: 52px; border-bottom: 1.5px solid #c9d1de; pointer-events: none; }
.sigpad-wrap .x { position: absolute; left: 22px; bottom: 56px; color: #9aa6b8; font-size: 18px; pointer-events: none; }
.sigpad-wrap .ph { position: absolute; inset: 0; display: grid; place-items: center; color: #9aa6b8; pointer-events: none; font-size: 15px; }
.seg { display: inline-flex; border: 1.5px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 8px 14px; min-height: 40px; font-weight: 600; font-size: 14px; display: inline-flex; gap: 6px; align-items: center; }
.seg button.on { background: var(--brand-soft); color: var(--brand-ink); }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }

/* ---------- dialog / toast ---------- */
.dialog-backdrop { position: fixed; inset: 0; z-index: 70; background: rgba(10, 15, 25, .5); display: grid; place-items: center; padding: 24px; animation: fade .15s ease-out; }
.dialog { background: var(--surface); border-radius: 18px; padding: 20px; width: 100%; max-width: 380px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: 10px; }
.dialog h3 { font-size: 18px; }
.dialog p { color: var(--muted); font-size: 15px; }
.dialog .row { justify-content: flex-end; margin-top: 8px; }
#toast {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  z-index: 90; background: #1c2433; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14.5px;
  box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { background: transparent; border: 0; color: #8CC0FA; font-weight: 700; margin-left: 12px; }

.busy { position: fixed; inset: 0; z-index: 80; background: rgba(10, 15, 25, .35); display: grid; place-items: center; }
.busy div { background: var(--surface); padding: 18px 22px; border-radius: 14px; display: flex; gap: 12px; align-items: center; box-shadow: var(--shadow-lg); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--brand); animation: spin .8s linear infinite; }

/* ---------- setup ---------- */
.setup-hero { text-align: center; padding: 28px 16px 8px; display: grid; justify-items: center; gap: 10px; }
.setup-hero img { width: 76px; height: 76px; border-radius: 20px; box-shadow: var(--shadow); }
.setup-hero h1 { font-size: 24px; }
.setup-hero p { color: var(--muted); max-width: 380px; }

@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.btn.danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; }
.inline-err { font-size: 14px; font-weight: 600; color: var(--danger); background: var(--danger-soft); padding: 8px 10px; border-radius: 8px; }
.inline-err:empty { display: none; }
.dialog .checks { margin-top: 4px; }
.grow { min-width: 0; }
