:root {
  color-scheme: light dark;
  --bg: light-dark(#f1f5f2, #0f1511);
  --surface: light-dark(#ffffff, #18211b);
  --surface-soft: light-dark(#e8f0ea, #223027);
  --text: light-dark(#17211a, #edf5ef);
  --muted: light-dark(#607067, #a9b8af);
  --border: light-dark(#d8e2da, #334239);
  --primary: light-dark(#176b43, #66d797);
  --primary-strong: light-dark(#105332, #3cad70);
  --on-primary: light-dark(#ffffff, #07140c);
  --warning-bg: light-dark(#fff4d8, #3a2d12);
  --warning-text: light-dark(#73510b, #ffdc86);
  --danger: light-dark(#a63838, #ff9c98);
  --shadow: 0 16px 44px color-mix(in srgb, var(--text) 10%, transparent);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background: var(--bg);
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, .file-button:focus-within {
  outline: 3px solid color-mix(in srgb, var(--primary) 42%, transparent);
  outline-offset: 2px;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.05rem; }
h2 { font-size: 1.28rem; letter-spacing: -0.02em; }
h3 { font-size: 1rem; }
small { color: var(--muted); }

.app-shell {
  width: min(100%, 540px);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  border-inline: 1px solid var(--border);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: var(--on-primary);
  background: var(--primary);
  font-size: .78rem;
  font-weight: 800;
}

.brand-copy { flex: 1; }
.brand-copy p { color: var(--muted); font-size: .75rem; }

main { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }

.page { padding: 18px 16px 28px; }
.page[hidden] { display: none; }

.page-heading, .section-heading, .dialog-heading, .live-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.page-heading { margin-bottom: 14px; }
.section-heading { margin: 22px 0 10px; }
.section-heading.no-margin { margin: 0 0 12px; }
.eyebrow { color: var(--muted); font-size: .7rem; font-weight: 800; letter-spacing: .08em; }

.icon-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 13px;
  color: var(--text);
  background: var(--surface);
  font-size: 1.4rem;
}

.rate-badge, .status-badge, .record-tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  color: var(--warning-text);
  background: var(--warning-bg);
  font-size: .7rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-badge.is-live, .record-tag.business {
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 13%, var(--surface));
}

.record-tag.excluded {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 11%, var(--surface));
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card, .instruction-card, .form-card, .report-card, .record-card, .live-card {
  border: 1px solid var(--border);
  border-radius: 17px;
  background: var(--surface);
}

.stat-card { min-width: 0; padding: 13px; }
.stat-card strong { display: block; margin: 4px 0 2px; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.stat-card small { display: block; font-size: .68rem; }
.stat-label { color: var(--muted); font-size: .75rem; }

.primary-button, .secondary-button, .danger-text-button, .file-button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 15px;
  border-radius: 13px;
  font-weight: 750;
  text-align: center;
}

.primary-button { border: 1px solid var(--primary-strong); color: var(--on-primary); background: var(--primary); }
.secondary-button, .file-button { border: 1px solid var(--border); color: var(--text); background: var(--surface); }
.danger-text-button { border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border)); color: var(--danger); background: transparent; }
.full-width { width: 100%; }
.small-button { min-height: 40px; padding: 8px 11px; font-size: .8rem; }
.text-button { min-height: 40px; border: 0; padding: 6px; color: var(--primary); background: transparent; font-weight: 750; }

.info-strip, .warning-strip {
  display: grid;
  gap: 3px;
  margin-top: 14px;
  padding: 12px;
  border-left: 4px solid var(--primary);
  color: var(--muted);
  background: color-mix(in srgb, var(--primary) 7%, transparent);
  font-size: .78rem;
}
.info-strip strong, .warning-strip strong { color: var(--text); }
.warning-strip { border-left-color: var(--warning-text); }

.record-list { display: grid; gap: 9px; }
.record-list:empty::after {
  content: "No records yet.";
  display: block;
  padding: 22px 12px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 14px;
  font-size: .85rem;
}
.record-list.compact { gap: 7px; }

.record-card { padding: 12px; }
.record-card-header, .record-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.record-card h3 { margin-bottom: 3px; }
.record-card p { color: var(--muted); font-size: .75rem; }
.record-amount { color: var(--primary); font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.record-card-footer { align-items: center; margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--border); color: var(--muted); font-size: .72rem; }
.record-actions { display: flex; gap: 8px; }
.record-actions button { min-height: 36px; border: 0; padding: 4px; color: var(--primary); background: transparent; font-size: .72rem; font-weight: 750; }
.record-actions button.delete { color: var(--danger); }

.instruction-card, .form-card, .report-card { padding: 15px; margin-bottom: 13px; }
.instruction-card h3 { margin-bottom: 9px; }
.instruction-card ol, .instruction-card ul { margin: 0; padding-left: 20px; color: var(--muted); font-size: .84rem; }
.instruction-card li + li { margin-top: 7px; }
.legal-card { margin-top: 13px; }

.field { display: grid; gap: 6px; margin-bottom: 12px; color: var(--text); font-size: .8rem; font-weight: 700; }
.field small { font-weight: 500; }
.field input, .field select, .year-select select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 9px 11px;
  color: var(--text);
  background: var(--bg);
  font-size: 1rem;
}
.field input[type="range"] { padding: 0; accent-color: var(--primary); }
.form-note { color: var(--muted); font-size: .73rem; line-height: 1.45; }
.form-card > .form-note { margin: -4px 0 13px; }
.two-column-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

.check-row {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 4px 0 12px;
}
.check-row span { display: grid; gap: 2px; font-size: .83rem; }
.check-row input { width: 22px; height: 22px; accent-color: var(--primary); }

.live-card {
  padding: 15px;
  margin-bottom: 13px;
  border-color: color-mix(in srgb, var(--primary) 70%, var(--border));
  background: color-mix(in srgb, var(--primary) 8%, var(--surface));
}
.live-card-top strong { display: block; margin-top: 3px; font-size: .86rem; }
.live-label { color: var(--primary); font-size: .68rem; font-weight: 850; letter-spacing: .07em; }
#live-elapsed { font-variant-numeric: tabular-nums; font-weight: 800; }
.live-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 15px 0 10px; }
.live-metrics div { min-width: 0; }
.live-metrics span { display: block; color: var(--muted); font-size: .67rem; }
.live-metrics strong { display: block; margin-top: 3px; font-size: 1rem; font-variant-numeric: tabular-nums; }

.action-stack { display: grid; gap: 9px; }

.filter-row { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.inline-field { flex: 1; margin: 0; }

.report-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: .81rem;
}
.report-row strong { font-variant-numeric: tabular-nums; text-align: right; }
.report-row:last-child { border-bottom: 0; }
.report-total { padding-top: 13px; font-weight: 800; }
.large-number { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.progress-track { height: 10px; overflow: hidden; margin: 6px 0 7px; border-radius: 999px; background: var(--surface-soft); }
.progress-track span { display: block; width: 0; height: 100%; background: var(--primary); transition: width .25s ease; }

.year-select select { min-height: 40px; width: auto; padding: 7px 9px; font-size: .8rem; }

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 30;
  width: min(100%, 540px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 7px 7px calc(7px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(16px);
}
.nav-button {
  min-height: 52px;
  display: grid;
  place-items: center;
  gap: 2px;
  border: 0;
  border-radius: 11px;
  padding: 5px 2px;
  color: var(--muted);
  background: transparent;
  font-size: .66rem;
}
.nav-button span { font-size: 1.05rem; line-height: 1; }
.nav-button.is-active { color: var(--primary); background: var(--surface-soft); font-weight: 800; }

dialog {
  width: min(calc(100% - 24px), 500px);
  max-height: calc(100dvh - 24px);
  margin: auto;
  padding: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: color-mix(in srgb, #000 55%, transparent); backdrop-filter: blur(4px); }
.dialog-form { padding: 16px; }
.dialog-heading { margin-bottom: 16px; }
.dialog-close { border: 0; background: var(--surface-soft); }

.heading-actions { display: flex; align-items: center; gap: 7px; }
.ocr-panel {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--primary) 28%, var(--border));
  border-radius: 14px;
  background: color-mix(in srgb, var(--primary) 6%, var(--surface));
}
.ocr-panel .form-note { margin: 0; }
.ocr-panel summary { color: var(--primary); cursor: pointer; font-size: .78rem; font-weight: 750; }
.ocr-text {
  max-height: 150px;
  margin: 8px 0 0;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--muted);
  font: .72rem/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.file-button { position: relative; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  z-index: 60;
  width: min(calc(100% - 32px), 460px);
  transform: translateX(-50%);
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 13px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: .82rem;
  text-align: center;
}

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 360px) {
  .page { padding-inline: 12px; }
  .app-header { padding-inline: 12px; }
  .stat-grid { gap: 8px; }
  .stat-card { padding: 11px; }
  .stat-card strong { font-size: 1.2rem; }
  .live-metrics { grid-template-columns: 1fr 1fr; }
  .live-metrics div:last-child { grid-column: 1 / -1; }
  .two-column-fields { grid-template-columns: 1fr; gap: 0; }
  .heading-actions { flex-direction: column; align-items: stretch; }
}

@media print {
  .app-header, .bottom-nav, .action-stack, .warning-strip, .year-select { display: none !important; }
  .app-shell { width: 100%; border: 0; }
  .page { display: none !important; }
  #page-taxes { display: block !important; padding: 0; }
  body { background: #fff; color: #000; }
  .report-card { break-inside: avoid; border-color: #bbb; background: #fff; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
