:root {
    color-scheme: light;
    --green: #0db866;
    --green-dark: #07894a;
    --green-soft: #e8f8f0;
    --ink: #17201c;
    --muted: #6d7772;
    --line: #e7ebe9;
    --canvas: #f5f7f6;
    --surface: #ffffff;
    --danger: #c73955;
    --shadow: 0 8px 30px rgba(20, 44, 32, .08);
    --radius: 22px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--canvas); }
body { margin: 0; color: var(--ink); background: var(--canvas); min-height: 100vh; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { border-radius: 12px; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
    outline: 3px solid rgba(13, 184, 102, .28);
    outline-offset: 2px;
}

.topbar {
    position: sticky; top: 0; z-index: 30;
    min-height: 68px; padding: 12px max(18px, env(safe-area-inset-left));
    display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 10px;
    background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px);
}
.topbar strong { text-align: center; font-size: 1.02rem; font-weight: 650; }
.brand-mark, .avatar, .auth-logo {
    display: inline-grid; place-items: center; background: var(--green); color: white; font-weight: 800;
}
.brand-mark, .avatar { width: 38px; height: 38px; border-radius: 14px; }
.avatar { justify-self: end; background: var(--green-soft); color: var(--green-dark); }
.icon-button { width: 42px; height: 42px; border: 0; background: transparent; color: var(--green); font-size: 2.3rem; line-height: 1; cursor: pointer; }

.page-shell { width: min(100%, 1120px); margin: 0 auto; padding: 22px 18px 112px; }
.surface { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.eyebrow { margin: 0 0 6px; color: var(--green-dark); font-weight: 750; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; }
.muted { color: var(--muted); }
.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; }
.empty-state { color: var(--muted); text-align: center; padding: 24px 12px; }

.flash { position: fixed; top: 78px; left: 50%; transform: translateX(-50%); z-index: 80; width: min(calc(100% - 36px), 560px); padding: 13px 16px; border-radius: 14px; box-shadow: var(--shadow); }
.flash-success { color: #075c35; background: #dcf8e9; border: 1px solid #a9e8c8; }
.flash-error { color: #8f1d34; background: #ffe8ed; border: 1px solid #f6b8c6; }

.welcome-block { padding: 10px 2px 24px; }
.welcome-block h1, .auth-brand h1 { margin: 0; font-size: clamp(1.7rem, 6vw, 2.4rem); letter-spacing: -.04em; }
.welcome-block p:last-child { margin-bottom: 0; }
.module-grid { display: grid; gap: 14px; }
.module-card { min-height: 116px; padding: 20px; display: grid; grid-template-columns: 58px 1fr auto; align-items: center; gap: 16px; }
.module-card strong { display: block; margin-bottom: 6px; font-size: 1.05rem; }
.module-card small { display: block; color: var(--muted); line-height: 1.4; }
.module-icon { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 18px; background: var(--green-soft); color: var(--green-dark); font-weight: 800; font-size: 1.05rem; }
.module-active { transition: transform .18s ease, box-shadow .18s ease; }
.module-active:hover { transform: translateY(-2px); box-shadow: 0 14px 40px rgba(20, 44, 32, .12); }
.module-active b { color: var(--green); font-size: 2rem; font-weight: 400; }
.module-disabled { box-shadow: none; opacity: .67; }
.module-disabled em { padding: 6px 9px; border-radius: 999px; background: #eef1ef; color: var(--muted); font-size: .7rem; font-style: normal; }
.privacy-note { margin: 24px 4px 0; display: flex; align-items: center; gap: 12px; color: var(--muted); }
.privacy-note > span { color: var(--green); }
.privacy-note p { margin: 0; }

.bottom-nav {
    position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); z-index: 40;
    width: min(100%, 1120px); min-height: 74px; padding: 8px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom));
    display: grid; grid-template-columns: repeat(5, 1fr); background: rgba(255,255,255,.97); border-top: 1px solid var(--line); backdrop-filter: blur(14px);
}
.bottom-nav a { min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: #8a938f; font-size: .68rem; font-weight: 650; }
.bottom-nav a span { font-size: 1.35rem; line-height: 1; }
.bottom-nav a.active { color: var(--green-dark); }
.bottom-nav .nav-add span { width: 42px; height: 42px; margin-top: -26px; display: grid; place-items: center; border-radius: 50%; color: white; background: var(--green); box-shadow: 0 8px 20px rgba(13,184,102,.28); font-size: 1.8rem; }

.month-control { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; margin-bottom: 14px; }
.month-control a, .month-control > span { text-align: center; color: var(--green); font-size: 2rem; }
.month-control input { width: 100%; border: 0; background: transparent; color: var(--ink); text-align: center; font-weight: 750; font-size: 1rem; }
.total-hero { padding: 24px; display: grid; grid-template-columns: minmax(0,1fr) 180px; align-items: center; gap: 18px; overflow: hidden; }
.total-hero h1 { margin: 4px 0 10px; font-size: clamp(2rem, 8vw, 3.2rem); letter-spacing: -.055em; }
.total-hero p { margin-top: 0; }
.trend { margin-bottom: 0; font-size: .82rem; font-weight: 650; }
.trend-up { color: var(--danger); }
.trend-down { color: var(--green-dark); }
.gauge-chart { width: 180px; height: 110px; }
.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 14px 0; }
.metric { padding: 17px; box-shadow: none; }
.metric span { display: block; color: var(--muted); font-size: .78rem; margin-bottom: 9px; }
.metric strong { font-size: clamp(1rem, 4vw, 1.35rem); }

.chart-section { margin-top: 14px; padding: 22px; }
.section-heading { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; }
.section-heading > div:first-child, .section-heading > h2:first-child { margin-right: auto; }
.section-heading h2 { margin: 0; font-size: 1.12rem; }
.section-heading a { color: var(--green-dark); font-size: .85rem; font-weight: 700; }
.segmented { min-width: 44px; height: 36px; border: 1px solid var(--line); background: white; color: var(--muted); cursor: pointer; }
.segmented.active { background: var(--green); border-color: var(--green); color: white; }
.chart-layout { display: grid; grid-template-columns: minmax(220px, .85fr) minmax(280px, 1.15fr); gap: 28px; align-items: center; }
.donut-chart { width: min(100%, 280px); height: auto; margin: 0 auto; }
.line-chart { width: 100%; height: 260px; }
.category-list { min-width: 0; }
.category-row, .transaction-row { min-width: 0; display: grid; grid-template-columns: auto minmax(0,1fr) auto; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.category-row:last-child, .transaction-row:last-child { border-bottom: 0; }
.category-row > span:nth-child(2), .transaction-row > span:nth-child(2) { min-width: 0; }
.category-row strong, .transaction-row strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.category-row small, .transaction-row small { display: block; margin-top: 3px; color: var(--muted); font-size: .72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.category-row b, .transaction-row b { white-space: nowrap; font-size: .9rem; }
.category-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--category-color); }
.transaction-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 14px; color: var(--category-color); background: color-mix(in srgb, var(--category-color) 13%, white); font-size: .72rem; font-weight: 800; }
.palette-0 { --category-color: #11b968; }
.palette-1 { --category-color: #5aa6de; }
.palette-2 { --category-color: #4f6fa8; }
.palette-3 { --category-color: #f2a93b; }
.palette-4 { --category-color: #e75b79; }
.palette-5 { --category-color: #815ac0; }
.palette-6 { --category-color: #00a6a6; }
.palette-7 { --category-color: #78909c; }
.section-block { margin-top: 20px; }
.transaction-list { padding: 0 18px; box-shadow: none; }
.review-bar { margin: 16px 0; }
.floating-add { position: fixed; right: max(20px, calc((100vw - 1100px)/2)); bottom: 92px; z-index: 35; width: 58px; height: 58px; display: grid; place-items: center; border-radius: 50%; background: var(--green); color: white; box-shadow: 0 10px 28px rgba(13,184,102,.33); font-size: 2rem; }

.auth-shell { min-height: calc(100vh - 150px); display: grid; grid-template-columns: 1fr minmax(320px, 430px); gap: 46px; align-items: center; }
.auth-shell.compact { grid-template-columns: minmax(280px, 480px); justify-content: center; }
.auth-brand { max-width: 520px; }
.auth-brand p { color: var(--muted); font-size: 1.05rem; }
.auth-logo { width: 68px; height: 68px; border-radius: 24px; margin-bottom: 24px; font-size: 1.35rem; box-shadow: 0 12px 28px rgba(13,184,102,.24); }
.auth-card { padding: 28px; }
.auth-card h1, .auth-card h2 { margin-top: 0; }
.text-link { display: block; margin-top: 18px; text-align: center; color: var(--green-dark); font-size: .86rem; font-weight: 650; }
.form-error { padding: 12px 14px; color: #8f1d34; background: #ffe8ed; border-radius: 12px; font-size: .86rem; }
.field { display: block; margin: 14px 0; }
.field > span { display: block; margin-bottom: 7px; color: var(--muted); font-size: .78rem; font-weight: 650; }
.field input, .field select, .field textarea { width: 100%; min-height: 48px; padding: 11px 13px; color: var(--ink); background: white; border: 1px solid #d9dfdc; }
.field textarea { resize: vertical; }
.button { min-height: 50px; padding: 12px 18px; border: 0; border-radius: 14px; font-weight: 750; cursor: pointer; }
.button-block { width: 100%; }
.button-primary { color: white; background: var(--green); box-shadow: 0 8px 18px rgba(13,184,102,.18); }
.button-secondary { color: var(--green-dark); background: var(--green-soft); }
.button-ghost { color: var(--muted); background: #f0f3f2; }

.expense-form { max-width: 760px; margin: 0 auto; }
.amount-entry { padding: 18px 6px 26px; text-align: center; }
.amount-entry > label { display: block; color: var(--muted); margin-bottom: 8px; }
.amount-entry > div { display: flex; justify-content: center; align-items: baseline; gap: 8px; }
.amount-entry span { color: var(--green-dark); font-size: 1.4rem; font-weight: 800; }
.amount-entry input { width: min(100%, 360px); padding: 0; border: 0; background: transparent; color: var(--ink); font-size: clamp(2.6rem, 12vw, 4.2rem); font-weight: 750; text-align: center; letter-spacing: -.06em; }
.amount-entry input::placeholder { color: #c9cfcc; }
.form-section { margin-bottom: 18px; }
.form-section h2 { font-size: 1rem; }
.category-picker { display: flex; flex-wrap: wrap; gap: 9px; }
.category-choice input { position: absolute; opacity: 0; pointer-events: none; }
.category-choice span { min-height: 43px; padding: 10px 13px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 999px; background: white; color: var(--muted); cursor: pointer; }
.category-choice input:checked + span { color: var(--category-color); border-color: var(--category-color); background: color-mix(in srgb, var(--category-color) 10%, white); font-weight: 750; }
.compact-fields { padding: 8px 18px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; box-shadow: none; }
.optional-fields { margin-bottom: 18px; box-shadow: none; overflow: hidden; }
.optional-fields summary { padding: 17px 19px; cursor: pointer; color: var(--green-dark); font-weight: 700; }
.optional-fields summary small { float: right; color: var(--muted); font-weight: 500; }
.details-body { padding: 0 18px 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.details-body .field:last-child { grid-column: 1 / -1; }
.save-expense { position: sticky; bottom: 86px; z-index: 20; }

.list-toolbar { display: grid; grid-template-columns: minmax(180px, 260px) 1fr; gap: 18px; align-items: end; margin-bottom: 18px; }
.list-toolbar > div { text-align: right; padding-bottom: 14px; }
.list-toolbar > div span { display: block; color: var(--muted); font-size: .75rem; }
.list-toolbar > div strong { font-size: 1.5rem; }
.list-total a { display: block; margin-top: 4px; color: var(--green-dark); font-size: .72rem; font-weight: 700; }
.transaction-actions { text-align: right; }
.transaction-actions b { display: block; }
.transaction-actions form { margin-top: 5px; }
.transaction-actions button { padding: 0; border: 0; background: transparent; color: var(--danger); font-size: .68rem; cursor: pointer; }
.full-list { padding: 0 20px; }
.settings-stack, .settings-card { max-width: 680px; margin-left: auto; margin-right: auto; }
.settings-card { padding: 22px; margin-bottom: 14px; box-shadow: none; }
.settings-card h2 { margin-top: 0; }
.switch { position: relative; width: 48px; height: 28px; }
.switch input { position: absolute; opacity: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: #cdd4d1; transition: .2s; }
.switch span::after { content: ''; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; border-radius: 50%; background: white; transition: .2s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(20px); }

@media (max-width: 700px) {
    .page-shell { padding: 16px 14px 108px; }
    .auth-shell { display: block; }
    .auth-brand { text-align: center; margin: 8px auto 26px; }
    .auth-logo { margin: 0 auto 18px; }
    .auth-card { padding: 22px 18px; }
    .total-hero { grid-template-columns: 1fr; text-align: center; }
    .gauge-chart { margin: 0 auto; }
    .metric-grid { grid-template-columns: 1fr 1fr; }
    .metric:last-child { grid-column: 1 / -1; }
    .chart-section { padding: 18px 15px; }
    .chart-layout { grid-template-columns: 1fr; gap: 10px; }
    .compact-fields, .details-body { grid-template-columns: 1fr; }
    .details-body .field:last-child { grid-column: auto; }
    .module-card { grid-template-columns: 52px 1fr; }
    .module-card > b, .module-card > em { grid-column: 2; justify-self: start; }
    .list-toolbar { grid-template-columns: 1fr 1fr; }
}

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