:root {
  color-scheme: light;
  --ink: #17352d;
  --muted: #6d7c76;
  --paper: #fbfaf6;
  --card: #ffffff;
  --line: #e3e8e4;
  --green: #173f35;
  --mint: #dcebe2;
  --yellow: #f1c75b;
  --red: #b84f43;
  --shadow: 0 14px 40px rgba(24, 55, 46, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button, .file-button { cursor: pointer; }

.auth-gate { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: linear-gradient(145deg, #eef4f0 0%, var(--paper) 55%); }
.auth-card { width: min(440px, 100%); padding: clamp(25px, 7vw, 42px); border: 1px solid var(--line); border-radius: 24px; background: white; box-shadow: var(--shadow); }
.auth-card h1 { margin-bottom: 12px; }
.auth-intro { margin-bottom: 25px; color: var(--muted); line-height: 1.55; }
.login-form { display: grid; gap: 16px; }
.login-form .primary { width: 100%; margin-top: 3px; }
.login-form .primary:disabled { cursor: wait; opacity: .65; }
.login-status { min-height: 21px; margin: -3px 0 0; color: var(--muted); font-size: .84rem; line-height: 1.45; }
.login-status.error { color: var(--red); }
.auth-note { margin: 20px 0 0; color: var(--muted); font-size: .78rem; text-align: center; }

.topbar, main { width: min(1100px, calc(100% - 32px)); margin-inline: auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 28px 0 18px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.sync-status { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.sync-status.syncing { color: #8b6415; }
.sync-status.error { color: var(--red); }
.sync-status.synced { color: #227357; }
.logout-button { min-height: 40px; padding-inline: 7px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.6rem, 4vw, 2.2rem); letter-spacing: -0.04em; }
h2 { margin-bottom: 0; font-size: clamp(1.3rem, 3vw, 1.8rem); letter-spacing: -0.025em; }
.eyebrow { margin-bottom: 5px; color: var(--muted); font-size: .75rem; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }

.hero { display: flex; justify-content: space-between; gap: 30px; margin: 12px 0 42px; padding: clamp(24px, 5vw, 48px); border-radius: 28px; background: var(--green); color: white; box-shadow: var(--shadow); }
.hero .eyebrow { color: #b9d0c6; }
.remaining-label { margin: 20px 0 0; color: #d9e7e1; }
.remaining { margin-bottom: 8px; font-size: clamp(3rem, 9vw, 5.8rem); font-weight: 800; line-height: 1; letter-spacing: -.07em; }
.forecast { max-width: 590px; margin-bottom: 0; color: #d9e7e1; }
.hero-side { display: flex; flex-direction: column; align-items: flex-end; justify-content: flex-end; gap: 7px; color: #d9e7e1; white-space: nowrap; }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.primary, .secondary, .file-button { min-height: 44px; padding: 10px 16px; border-radius: 12px; border: 1px solid transparent; font-weight: 750; }
.primary { background: var(--green); color: white; }
.primary:hover { background: #235447; }
.secondary, .file-button { background: white; color: var(--ink); border-color: var(--line); }
.secondary:hover, .file-button:hover { border-color: #aabbb3; }

.budget-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 52px; }
.budget-card { padding: 20px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); box-shadow: 0 8px 24px rgba(24,55,46,.04); }
.budget-card-top, .budget-values { display: flex; justify-content: space-between; gap: 12px; }
.budget-card h3 { margin-bottom: 18px; font-size: 1rem; }
.budget-values { margin-top: 11px; color: var(--muted); font-size: .85rem; }
.budget-values strong { color: var(--ink); }
.section-intro { max-width: 720px; margin: -5px 0 18px; color: var(--muted); }
.money-overview, .pots-section { margin-bottom: 52px; }
.heading-actions { display: flex; flex-wrap: wrap; gap: 9px; justify-content: flex-end; }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.summary-card { display: grid; gap: 7px; padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: white; }
.summary-card span { color: var(--muted); font-size: .82rem; }
.summary-card strong { font-size: 1.35rem; }
.import-message { min-height: 24px; margin-bottom: 8px; color: var(--muted); font-size: .86rem; }
.transaction-list { display: grid; gap: 8px; }
.fixed-expense-list { display: grid; gap: 8px; margin-bottom: 34px; }
.fixed-expense-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 12px 14px; border: 1px solid var(--line); border-radius: 13px; background: white; }
.fixed-expense-row strong { min-width: 105px; text-align: right; }
.fixed-expense-actions { display: flex; gap: 5px; }
.subsection-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; padding-top: 24px; border-top: 1px solid var(--line); }
.subsection-heading h3 { margin-bottom: 0; }
.transaction-row { display: grid; grid-template-columns: 95px minmax(0, 1fr) 125px auto 36px; gap: 10px; align-items: center; padding: 11px 12px; border: 1px solid var(--line); border-radius: 13px; background: white; }
.transaction-row small { color: var(--muted); }
.transaction-row strong { text-align: right; }
.transaction-row select { min-height: 38px; padding-block: 6px; }
.mini-delete { width: 36px; height: 36px; padding: 0; border: 1px solid #ecd0cc; border-radius: 9px; background: white; color: var(--red); }
.pots-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.pot-card { padding: 18px; border: 1px solid var(--line); border-radius: 17px; background: white; }
.pot-card-top { display: flex; justify-content: space-between; gap: 10px; }
.pot-type { color: var(--muted); font-size: .76rem; }
.pot-values { display: flex; justify-content: space-between; gap: 10px; margin: 10px 0; color: var(--muted); font-size: .82rem; }
.pot-actions { display: flex; gap: 8px; margin-top: 12px; }
.pot-actions button { flex: 1; min-height: 36px; padding: 6px 8px; }
.progress { height: 9px; overflow: hidden; border-radius: 999px; background: #edf1ee; }
.progress > span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--green); transition: width .25s ease; }
.progress.warn > span { background: var(--yellow); }
.progress.over > span { background: var(--red); }
.product-insights { margin-bottom: 52px; }
.insight-list { display: grid; gap: 10px; }
.insight-row { display: grid; grid-template-columns: minmax(120px, .8fr) minmax(150px, 2fr) auto; gap: 14px; align-items: center; padding: 12px 15px; border: 1px solid var(--line); border-radius: 14px; background: white; }
.insight-row strong:last-child { text-align: right; }
.insight-row small { display: block; margin-top: 4px; color: var(--muted); line-height: 1.45; }
.insight-bar { height: 10px; overflow: hidden; border-radius: 999px; background: #edf1ee; }
.insight-bar span { display: block; height: 100%; border-radius: inherit; background: #6b9c89; }
.insight-empty { padding: 25px; border: 1px dashed #b8c5bf; border-radius: 16px; color: var(--muted); text-align: center; }
.food-choice-heading { margin: 28px 0 13px; }
.food-choice-heading h3 { margin-bottom: 0; font-size: 1.15rem; }
.food-class-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); gap: 10px; margin-bottom: 13px; }
.food-class-card { display: grid; gap: 6px; padding: 15px; border: 1px solid var(--line); border-radius: 14px; background: white; }
.food-class-card span { color: var(--muted); font-size: .78rem; }
.food-class-card strong { font-size: 1.2rem; }
.food-class-card.snack { border-color: #e8c8a4; background: #fffaf2; }

.history { min-height: 250px; }
select { min-height: 42px; padding: 8px 34px 8px 12px; border: 1px solid var(--line); border-radius: 11px; background: white; color: var(--ink); }
.empty-state { padding: 45px 20px; border: 1px dashed #b8c5bf; border-radius: 20px; text-align: center; background: rgba(255,255,255,.45); }
.empty-state p { max-width: 480px; margin-inline: auto; color: var(--muted); }
.empty-icon { display: grid; place-items: center; width: 46px; height: 46px; margin: 0 auto 15px; border-radius: 50%; background: var(--mint); font-size: 1.7rem; }
.receipt-list { display: grid; gap: 10px; }
.receipt { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 15px; background: white; }
.receipt-date { text-align: center; color: var(--muted); font-size: .75rem; text-transform: uppercase; }
.receipt-date strong { display: block; color: var(--ink); font-size: 1.35rem; }
.receipt h3 { overflow: hidden; margin-bottom: 3px; font-size: 1rem; text-overflow: ellipsis; white-space: nowrap; }
.receipt-meta { margin: 0; color: var(--muted); font-size: .82rem; }
.receipt-amount { text-align: right; font-weight: 800; }
.receipt-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 7px; }
.text-button { padding: 2px 3px; border: 0; background: transparent; color: var(--muted); font-size: .78rem; }
.text-button.danger { color: var(--red); }

.data-tools { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin: 50px 0 35px; padding: 23px; border-radius: 18px; background: var(--mint); }
.data-tools p:last-child { margin-bottom: 0; color: #547067; }
.tool-actions { display: flex; gap: 9px; }
.file-button { display: inline-flex; align-items: center; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }

dialog { width: min(680px, calc(100% - 24px)); max-height: calc(100vh - 24px); padding: 0; overflow: auto; border: 0; border-radius: 24px; color: var(--ink); box-shadow: 0 30px 90px rgba(0,0,0,.2); }
dialog::backdrop { background: rgba(12, 30, 25, .57); backdrop-filter: blur(4px); }
dialog form { padding: clamp(20px, 5vw, 32px); }
.dialog-heading { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.icon-button { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 50%; background: white; color: var(--ink); font-size: 1.6rem; line-height: 1; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.scan-panel { display: flex; align-items: center; gap: 13px; margin-top: 13px; padding: 13px; border: 1px solid var(--line); border-radius: 13px; background: #f6f9f7; }
.scan-panel button { flex: 0 0 auto; }
.scan-panel button:disabled { cursor: wait; opacity: .65; }
.scan-status { margin: 0; color: var(--muted); font-size: .82rem; line-height: 1.4; }
.scan-status.valid { color: #227357; }
.scan-status.review { color: #8b6415; }
.scan-status.invalid { color: var(--red); }
label { display: grid; gap: 7px; font-size: .86rem; font-weight: 750; }
input, textarea { width: 100%; padding: 11px 12px; border: 1px solid #cdd7d2; border-radius: 11px; background: white; color: var(--ink); }
input:focus, textarea:focus, select:focus { outline: 3px solid rgba(39, 112, 91, .18); border-color: #4d806f; }
fieldset { margin: 22px 0; padding: 18px; border: 1px solid var(--line); border-radius: 15px; }
legend { padding: 0 6px; font-weight: 800; }
.form-help { margin-bottom: 14px; color: var(--muted); font-size: .82rem; }
.split-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.split-status { min-height: 21px; margin: 13px 0 0; color: var(--muted); font-size: .84rem; }
.split-status.valid { color: #227357; }
.split-status.invalid { color: var(--red); }
.category-settings { display: grid; gap: 10px; }
.category-row { display: grid; grid-template-columns: minmax(0, 1fr) 140px 42px; gap: 9px; align-items: end; padding: 12px; border: 1px solid var(--line); border-radius: 13px; background: #fafbf9; }
.category-row .remove-category { width: 42px; height: 42px; padding: 0; border: 1px solid #ecd0cc; border-radius: 10px; background: white; color: var(--red); font-size: 1.2rem; }
.category-row .remove-category:disabled { cursor: not-allowed; opacity: .35; }
.add-category { width: 100%; margin-top: 12px; border-style: dashed; }
.product-group-settings { margin-top: 24px; }
.product-rows { display: grid; gap: 9px; }
.product-row { display: grid; grid-template-columns: minmax(110px, 1.2fr) minmax(110px, 1fr) minmax(135px, 1fr) 100px 40px; gap: 8px; align-items: end; }
.product-row .remove-product { width: 40px; height: 42px; padding: 0; border: 1px solid #ecd0cc; border-radius: 10px; background: white; color: var(--red); font-size: 1.1rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 24px; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 5; max-width: calc(100% - 40px); padding: 12px 16px; border-radius: 12px; background: var(--green); color: white; opacity: 0; transform: translateY(15px); pointer-events: none; transition: .2s ease; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: none; }

@media (max-width: 720px) {
  .topbar, main { width: min(100% - 22px, 1100px); }
  .topbar { padding-top: 18px; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
  .sync-status { flex-basis: 100%; text-align: right; }
  .hero { flex-direction: column; margin-bottom: 32px; border-radius: 22px; }
  .hero-side { align-items: flex-start; }
  .budget-grid { grid-template-columns: 1fr; margin-bottom: 38px; }
  .summary-grid, .pots-grid { grid-template-columns: 1fr; }
  .food-class-grid { grid-template-columns: 1fr 1fr; }
  .heading-actions { width: 100%; justify-content: stretch; }
  .heading-actions > * { flex: 1; justify-content: center; }
  .fixed-expense-row { grid-template-columns: minmax(0, 1fr) auto; }
  .fixed-expense-actions { grid-column: 1 / -1; }
  .subsection-heading { align-items: stretch; flex-direction: column; }
  .transaction-row { grid-template-columns: 78px minmax(0, 1fr) auto; }
  .transaction-row select { grid-column: 2; }
  .transaction-row .mini-delete { grid-column: 3; grid-row: 2; }
  .section-heading { align-items: center; }
  .section-heading .primary { flex-shrink: 0; }
  .data-tools { align-items: stretch; flex-direction: column; }
  .tool-actions > * { flex: 1; justify-content: center; }
  .form-grid, .split-grid { grid-template-columns: 1fr; }
  .scan-panel { align-items: stretch; flex-direction: column; }
  .category-row { grid-template-columns: minmax(0, 1fr) 105px 42px; }
  .product-row { grid-template-columns: 1fr 1fr; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
  .insight-row { grid-template-columns: 1fr auto; }
  .insight-bar { grid-column: 1 / -1; grid-row: 2; }
}

@media (max-width: 430px) {
  .topbar { align-items: flex-start; }
  .topbar .secondary { padding-inline: 11px; }
  .topbar-actions { max-width: 175px; }
  .section-heading { align-items: stretch; flex-direction: column; }
  .section-heading .primary { width: 100%; }
  .receipt { grid-template-columns: 46px minmax(0, 1fr) auto; gap: 9px; }
  .receipt-meta { max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
