/* AgentDeduct v2 — design system. Mobile-first, thumb-friendly, dark-mode ready. */
:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --bg-grad: linear-gradient(180deg, #fbfdfb 0%, #f4f6f3 60%, #eef1ec 100%);
  --surface: #ffffff;
  --surface-2: #f7f9f6;
  --ink: #10160f;
  --ink-2: #33402f;
  --muted: #68766a;
  --line: rgba(20, 35, 22, 0.1);
  --green: #157347;
  --green-deep: #0d4d2f;
  --green-soft: #e3f3e9;
  --gold: #b07d1e;
  --gold-soft: #fdf3dd;
  --red: #b3372f;
  --red-soft: #fbe9e7;
  --blue: #2563a8;
  --blue-soft: #e8f0fa;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 14px 40px rgba(18, 40, 24, 0.1);
  --shadow-sm: 0 4px 14px rgba(18, 40, 24, 0.07);
  --tabbar-h: 76px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d120e;
  --bg-grad: linear-gradient(180deg, #101711 0%, #0d120e 60%, #0a0e0b 100%);
  --surface: #151c16;
  --surface-2: #1a221b;
  --ink: #f0f4ee;
  --ink-2: #cfd8cc;
  --muted: #93a093;
  --line: rgba(255, 255, 255, 0.09);
  --green: #4cc38a;
  --green-deep: #2f9e68;
  --green-soft: rgba(76, 195, 138, 0.14);
  --gold: #e0a83e;
  --gold-soft: rgba(224, 168, 62, 0.14);
  --red: #e0705f;
  --red-soft: rgba(224, 112, 95, 0.13);
  --blue: #6aa5e8;
  --blue-soft: rgba(106, 165, 232, 0.13);
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.3);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg-grad); background-attachment: fixed;
  color: var(--ink); font-family: var(--font); -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; font-weight: 700; }
img { max-width: 100%; }

.app { max-width: 560px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .app { max-width: 640px; } }

/* ---------- header ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 18px 0 6px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; letter-spacing: -0.01em; }
.brand img { width: 34px; height: 34px; border-radius: 10px; object-fit: cover; }
.year-pill {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 14px; font-weight: 700; font-size: 14px; display: flex; gap: 6px; align-items: center;
}
.year-pill select { border: 0; background: none; font-weight: 800; font-size: 14px; }

/* ---------- views ---------- */
.view { display: none; animation: rise 240ms ease; }
.view.active { display: block; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- hero ---------- */
.hero {
  background: linear-gradient(135deg, var(--green-deep), var(--green));
  color: #fff; border-radius: 22px; padding: 22px 20px; margin: 10px 0 14px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 170px; height: 170px;
  border-radius: 50%; background: rgba(255,255,255,0.09);
}
.hero .eyebrow { font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.85; }
.hero .big { font-size: 44px; font-weight: 800; letter-spacing: -0.03em; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.hero .sub { font-size: 14px; opacity: 0.9; }
.hero .bracket { margin-top: 10px; font-size: 12.5px; opacity: 0.85; }
.hero .bracket button { color: #fff; text-decoration: underline; font-size: 12.5px; padding: 0; }

/* ---------- cards & stats ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 16px; margin-bottom: 14px; }
.card h3 { margin: 0 0 10px; font-size: 15px; letter-spacing: -0.01em; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 10px; text-align: center; }
.stat .v { font-size: 19px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 11.5px; color: var(--muted); margin-top: 3px; font-weight: 600; }

/* ---------- nudges ---------- */
.nudge { display: flex; gap: 12px; align-items: flex-start; border-radius: var(--radius-sm); padding: 13px 14px; margin-bottom: 10px; font-size: 14px; line-height: 1.45; border: 1px solid var(--line); background: var(--surface); }
.nudge .ico { font-size: 20px; flex: 0 0 auto; }
.nudge.gold { background: var(--gold-soft); border-color: rgba(176, 125, 30, 0.25); }
.nudge.blue { background: var(--blue-soft); border-color: rgba(37, 99, 168, 0.2); }
.nudge b { font-weight: 800; }
.nudge .act { margin-left: auto; flex: 0 0 auto; align-self: center; }
.btn-inline { background: var(--green); color: #fff; border-radius: 999px; padding: 9px 16px; font-size: 13.5px; }
.btn-inline.ghost { background: none; color: var(--green); border: 1.5px solid var(--green); }

/* ---------- lists ---------- */
.row-item { display: flex; gap: 12px; align-items: center; padding: 12px 2px; border-bottom: 1px solid var(--line); }
.row-item:last-child { border-bottom: 0; }
.row-ico { width: 42px; height: 42px; border-radius: 13px; background: var(--green-soft); display: flex; align-items: center; justify-content: center; font-size: 20px; flex: 0 0 auto; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 700; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.row-amt { font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; text-align: right; }
.row-amt small { display: block; font-size: 11px; color: var(--green); font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; font-size: 14px; }
.empty .big-ico { font-size: 34px; display: block; margin-bottom: 8px; }
.link-more { display: block; text-align: center; font-size: 13.5px; color: var(--green); font-weight: 700; padding: 10px; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -8px 30px rgba(18, 40, 24, 0.08);
}
.tabbar-in { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: 1fr 1fr 1.3fr 1fr 1fr; height: var(--tabbar-h); }
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 10.5px; font-weight: 700; }
.tab .ti { font-size: 21px; }
.tab.active { color: var(--green); }
.fab {
  width: 62px; height: 62px; border-radius: 50%; margin: -24px auto 0;
  background: linear-gradient(135deg, var(--green-deep), var(--green)); color: #fff;
  font-size: 30px; line-height: 1; box-shadow: 0 10px 24px rgba(21, 115, 71, 0.4);
  display: flex; align-items: center; justify-content: center;
}
.fab:active { transform: scale(0.94); }
.fab-label { font-size: 10.5px; font-weight: 700; color: var(--muted); }

/* ---------- bottom sheet ---------- */
.scrim { position: fixed; inset: 0; background: rgba(8, 14, 9, 0.55); z-index: 60; opacity: 0; pointer-events: none; transition: opacity 200ms; }
.scrim.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61; max-width: 560px; margin: 0 auto;
  background: var(--surface); border-radius: 24px 24px 0 0; padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(105%); transition: transform 260ms cubic-bezier(0.32, 0.72, 0.24, 1);
  max-height: 92vh; overflow-y: auto;
}
.sheet.open { transform: none; }
.grabber { width: 42px; height: 5px; border-radius: 99px; background: var(--line); margin: 6px auto 12px; }
.sheet h2 { margin: 0 0 4px; font-size: 19px; letter-spacing: -0.02em; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 999px; padding: 4px; margin: 10px 0 14px; }
.seg button { border-radius: 999px; padding: 10px; font-size: 14px; color: var(--muted); }
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* ---------- forms ---------- */
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 13px; font-weight: 700; color: var(--ink-2); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); padding: 13px 14px; font-size: 16px;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.amount-input { font-size: 34px !important; font-weight: 800; letter-spacing: -0.02em; text-align: center; font-variant-numeric: tabular-nums; }
.amount-wrap { position: relative; }
.amount-wrap .cur { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); font-size: 22px; font-weight: 800; color: var(--muted); }
.amount-wrap input { padding-left: 40px; }
.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cat-cell { border: 1.5px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); padding: 10px 4px; display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: 10.5px; font-weight: 700; color: var(--ink-2); text-align: center; line-height: 1.2; min-height: 74px; justify-content: center; }
.cat-cell .ci { font-size: 21px; }
.cat-cell.active { border-color: var(--green); background: var(--green-soft); color: var(--ink); }
.choice-row { display: flex; gap: 8px; }
.choice { flex: 1; border: 1.5px solid var(--line); border-radius: var(--radius-sm); padding: 12px; font-size: 14px; text-align: center; background: var(--surface); }
.choice.active { border-color: var(--green); background: var(--green-soft); }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; line-height: 1.45; }
.warn { background: var(--gold-soft); border: 1px solid rgba(176, 125, 30, 0.3); border-radius: var(--radius-sm); padding: 11px 13px; font-size: 13.5px; margin: 10px 0; line-height: 1.45; }
.warn b { font-weight: 800; }
.ocr-status { font-size: 13px; color: var(--muted); margin-top: 8px; line-height: 1.45; min-height: 20px; }
.ocr-status.working { color: var(--blue); }
.ocr-status.success { color: var(--green); }
.ocr-status.warning { color: var(--gold); }
.btn-primary {
  width: 100%; background: linear-gradient(135deg, var(--green-deep), var(--green)); color: #fff;
  border-radius: 16px; padding: 16px; font-size: 17px; font-weight: 800; letter-spacing: -0.01em;
  box-shadow: 0 10px 24px rgba(21, 115, 71, 0.35); margin-top: 6px;
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.55; }
.btn-ghost { width: 100%; border: 1.5px solid var(--line); border-radius: 16px; padding: 14px; font-size: 15px; margin-top: 10px; background: var(--surface); }
.btn-danger { color: var(--red); }
.receipt-btn { display: flex; align-items: center; gap: 10px; border: 1.5px dashed var(--line); border-radius: var(--radius-sm); padding: 13px 14px; width: 100%; font-size: 14.5px; background: var(--surface); text-align: left; }
.receipt-btn .ri { font-size: 20px; }
.hidden-file { display: none; }

/* ---------- drive tracking ---------- */
.drive-live { text-align: center; padding: 18px 10px; }
.drive-miles { font-size: 52px; font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.drive-meta { color: var(--muted); font-size: 14px; margin: 4px 0 16px; }
.btn-drive { width: 100%; border-radius: 18px; padding: 18px; font-size: 18px; font-weight: 800; background: linear-gradient(135deg, var(--green-deep), var(--green)); color: #fff; box-shadow: 0 10px 24px rgba(21, 115, 71, 0.35); }
.btn-drive.stop { background: linear-gradient(135deg, #8c2b25, var(--red)); box-shadow: 0 10px 24px rgba(179, 55, 47, 0.35); }
.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

/* ---------- deals ---------- */
.deal-card { display: block; width: 100%; text-align: left; }
.deal-addr { font-weight: 800; font-size: 16px; letter-spacing: -0.01em; }
.deal-client { font-size: 13px; color: var(--muted); margin-top: 2px; }
.deal-nums { display: flex; gap: 14px; margin-top: 10px; }
.deal-nums .dn .v { font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums; }
.deal-nums .dn .l { font-size: 11px; color: var(--muted); font-weight: 600; }
.pill { display: inline-block; font-size: 11px; font-weight: 800; padding: 4px 10px; border-radius: 999px; background: var(--green-soft); color: var(--green-deep); }
[data-theme="dark"] .pill { color: var(--green); }
.pill.closed { background: var(--surface-2); color: var(--muted); }

/* ---------- reports ---------- */
.cpa-line { display: flex; justify-content: space-between; gap: 10px; padding: 11px 2px; border-bottom: 1px solid var(--line); font-size: 14px; }
.cpa-line:last-child { border-bottom: 0; }
.cpa-line .t { font-weight: 600; }
.cpa-line .t small { display: block; color: var(--muted); font-weight: 600; font-size: 12px; }
.cpa-line .a { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.total-line { display: flex; justify-content: space-between; padding: 14px 2px 2px; font-size: 16px; font-weight: 800; }

/* ---------- settings ---------- */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 2px; border-bottom: 1px solid var(--line); font-size: 15px; }
.set-row:last-child { border-bottom: 0; }
.set-row .t { font-weight: 700; }
.set-row .s { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.set-row select { border: 1.5px solid var(--line); border-radius: 10px; padding: 9px 12px; background: var(--surface); font-weight: 700; max-width: 170px; }
.privacy-note { font-size: 13px; color: var(--muted); line-height: 1.55; }
.privacy-note b { color: var(--ink-2); }

/* ---------- misc ---------- */
.page-title { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; margin: 14px 0 4px; }
.page-sub { color: var(--muted); font-size: 14px; margin: 0 0 14px; }
.mt { margin-top: 14px; }
.center { text-align: center; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 18px); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 13px 20px; border-radius: 999px; font-size: 14.5px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: all 240ms ease; z-index: 80; max-width: 90vw; text-align: center;
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%); }
@keyframes tickpop { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }
.tickpop { animation: tickpop 420ms ease; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* print: CPA export */
@media print {
  body { padding-bottom: 0; background: #fff; }
  .tabbar, .topbar .year-pill, .no-print { display: none !important; }
  .app { max-width: 100%; }
  .view { display: none; }
  .view.active { display: block; }
  .card { box-shadow: none; break-inside: avoid; }
}
