:root {
  color-scheme: light;
  --ink: #0b1220;
  --muted: #64748b;
  --line: #e2e8f0;
  --surface: #ffffff;
  --canvas: #f3f6f9;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --brand-soft: #ccfbf1;
  --danger: #b91c1c;
  --shadow: 0 16px 42px rgb(15 23 42 / 7%);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--canvas); font-size: 16px; line-height: 1.5; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar {
  position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: center; min-height: 70px; padding: 0 5vw; border-bottom: 1px solid rgb(226 232 240 / 85%);
  background: rgb(255 255 255 / 92%); backdrop-filter: blur(16px);
}
.brand { display: inline-flex; align-items: center; gap: 10px; width: fit-content; font-size: 1.08rem; font-weight: 800; letter-spacing: -.02em; }
.brand-mark { display: grid; width: 36px; height: 36px; place-items: center; border-radius: 11px; color: var(--ink); background: #2dd4bf; font-weight: 900; }
.desktop-nav { display: flex; gap: 6px; padding: 5px; border: 1px solid var(--line); border-radius: 14px; background: #f8fafc; }
.desktop-nav a { padding: 7px 14px; border-radius: 9px; color: var(--muted); font-size: .9rem; font-weight: 700; }
.desktop-nav a[aria-current="page"] { color: var(--ink); background: var(--surface); box-shadow: 0 2px 7px rgb(15 23 42 / 9%); }
.account { justify-self: end; display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: .9rem; }
.account form { margin: 0; }
.link-button { padding: 0; border: 0; color: var(--brand-dark); background: transparent; cursor: pointer; font-weight: 750; }

.shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 44px 0 72px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.page-heading h1 { margin: 0; font-size: clamp(1.85rem, 3vw, 2.55rem); line-height: 1.1; letter-spacing: -.045em; }
.eyebrow { margin: 0 0 5px; color: var(--brand); font-size: .75rem; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
.muted { color: var(--muted); }
.month-switcher { display: flex; align-items: center; gap: 14px; }
.month-switcher a { display: grid; width: 36px; height: 36px; place-items: center; border: 1px solid var(--line); border-radius: 50%; color: var(--muted); background: var(--surface); }
.month-switcher a:hover { color: var(--ink); border-color: #94a3b8; }

.button { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; padding: 10px 17px; border: 1px solid transparent; border-radius: 12px; cursor: pointer; font-weight: 800; line-height: 1.2; transition: transform .15s ease, background .15s ease, border-color .15s ease; }
.button:hover { transform: translateY(-1px); }
.button-primary { color: #fff; background: var(--brand); box-shadow: 0 7px 18px rgb(15 118 110 / 22%); }
.button-primary:hover { background: var(--brand-dark); }
.button-secondary { color: var(--ink); border-color: var(--line); background: #fff; }
.button-quiet { color: var(--muted); background: transparent; }
.button-danger { color: #fff; background: var(--danger); }
.button-full { width: 100%; }
.danger-link { color: var(--danger); font-weight: 750; }

.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 24px 24px 18px; }
.panel-heading h2 { margin: 0; font-size: 1.2rem; letter-spacing: -.025em; }
.panel-heading a { color: var(--brand-dark); font-size: .9rem; font-weight: 800; }

.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.summary-card { min-height: 144px; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.summary-card span { display: block; color: var(--muted); font-size: .84rem; font-weight: 700; }
.summary-card strong { display: block; margin: 13px 0 9px; font-size: clamp(1.5rem, 3vw, 2rem); line-height: 1; letter-spacing: -.05em; }
.summary-card small { color: var(--muted); font-size: .76rem; }
.summary-main { color: #fff; border-color: #0b1220; background: var(--ink); }
.summary-main span, .summary-main small { color: #cbd5e1; }
.summary-main strong { color: #5eead4; }
.summary-empty strong { color: #94a3b8; }
.trend-up { color: #fca5a5 !important; }
.trend-down { color: #5eead4 !important; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(360px, .85fr); gap: 18px; margin-bottom: 18px; }
.category-bars { display: grid; gap: 20px; padding: 5px 24px 26px; }
.bar-label { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 8px; font-size: .87rem; }
.bar-label span { display: flex; align-items: center; gap: 9px; color: #334155; }
.bar-label i { width: 9px; height: 9px; border-radius: 50%; background: var(--dot); }
.bar-track { height: 8px; overflow: hidden; border-radius: 99px; background: #eef2f6; }
.bar-fill { min-width: 5px; height: 100%; border-radius: inherit; background: var(--bar); }
.month-chart { display: flex; height: 250px; align-items: flex-end; justify-content: space-between; gap: 10px; padding: 40px 24px 24px; }
.month-column { position: relative; display: flex; height: 100%; flex: 1; flex-direction: column; justify-content: flex-end; align-items: center; gap: 7px; color: var(--muted); font-size: .72rem; font-weight: 750; text-transform: uppercase; }
.chart-bar { width: min(34px, 75%); min-height: 5px; border-radius: 8px 8px 3px 3px; background: linear-gradient(180deg, #2dd4bf, var(--brand)); }
.chart-value { position: absolute; top: -27px; display: none; padding: 4px 6px; border-radius: 6px; color: #fff; background: var(--ink); white-space: nowrap; text-transform: none; }
.month-column:hover .chart-value { display: block; }

.expense-rows { display: grid; }
.expense-row { display: grid; grid-template-columns: 46px minmax(0, 1fr) auto; align-items: center; gap: 14px; min-height: 76px; padding: 13px 24px; border-top: 1px solid var(--line); }
.expense-row:hover { background: #f8fafc; }
.category-icon { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 13px; color: var(--category); background: color-mix(in srgb, var(--category) 13%, white); font-size: .9rem; font-weight: 900; }
.expense-main { min-width: 0; }
.expense-main strong, .expense-main small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.expense-main strong { font-size: .94rem; }
.expense-main small { margin-top: 3px; color: var(--muted); font-size: .77rem; }
.expense-amount { font-size: .98rem; font-weight: 850; letter-spacing: -.02em; }
.recent-panel { overflow: hidden; }
.empty-state { display: grid; min-height: 190px; place-items: center; align-content: center; gap: 7px; padding: 26px; color: var(--muted); text-align: center; }
.empty-state strong { color: var(--ink); }
.empty-state .button { margin-top: 10px; }

.filters { display: grid; grid-template-columns: repeat(4, minmax(130px, 1fr)) auto; align-items: end; gap: 14px; padding: 18px; margin-bottom: 14px; }
.field { display: grid; gap: 7px; }
.field label { color: #334155; font-size: .82rem; font-weight: 800; }
input, select, textarea { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 10px; color: var(--ink); background: #fff; outline: none; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgb(15 118 110 / 13%); }
input[type="color"] { width: 72px; padding: 4px; }
input[type="checkbox"] { width: 20px; min-height: 20px; accent-color: var(--brand); }
.filter-actions { display: flex; gap: 5px; }
.list-summary { display: flex; align-items: center; justify-content: space-between; padding: 10px 5px; color: var(--muted); font-size: .9rem; }
.list-summary strong { color: var(--ink); font-size: 1.08rem; }
.expense-list-panel { overflow: hidden; }
.list-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 5px; color: var(--muted); font-size: .86rem; }
.pagination { display: flex; gap: 18px; }
.pagination a, .export-link { color: var(--brand-dark); font-weight: 800; }

.narrow-page { width: min(720px, 100%); margin: 0 auto; }
.stack-form { display: grid; gap: 20px; padding: 26px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.field-wide { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }
.errorlist { margin: 0; padding: 0; color: var(--danger); font-size: .78rem; list-style: none; }
.form-errors { padding: 12px 14px; border: 1px solid #fecaca; border-radius: 10px; color: #991b1b; background: #fef2f2; }
.help-text { color: var(--muted); font-size: .75rem; }
.dialog-card { width: min(480px, 100%); margin: 8vh auto 0; padding: 34px; text-align: center; }
.dialog-card h1 { margin: 14px 0 8px; font-size: 1.65rem; }
.dialog-card p { margin: 0 0 26px; color: var(--muted); }
.danger-icon { display: grid; width: 54px; height: 54px; margin: 0 auto; place-items: center; border-radius: 50%; color: var(--danger); background: #fee2e2; font-size: 1.4rem; font-weight: 900; }
.dialog-actions { display: flex; justify-content: center; gap: 8px; }

.category-list { overflow: hidden; }
.category-item { display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 14px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.category-item:last-child { border-bottom: 0; }
.category-item:hover { background: #f8fafc; }
.category-item strong, .category-item small { display: block; }
.category-item small { margin-top: 2px; color: var(--muted); font-size: .78rem; }
.status-pill { padding: 5px 9px; border-radius: 99px; color: #64748b; background: #f1f5f9; font-size: .72rem; font-weight: 800; }
.status-pill.active { color: #047857; background: #d1fae5; }
.checkbox-field:has(input[type="checkbox"]) { grid-template-columns: 1fr auto; align-items: center; }
.checkbox-field:has(input[type="checkbox"]) .errorlist { grid-column: 1 / -1; }

.auth-body { display: grid; min-height: 100vh; place-items: center; background: var(--ink); }
.auth-body::before { position: fixed; inset: 0; content: ""; pointer-events: none; background: radial-gradient(circle at 15% 15%, rgb(45 212 191 / 20%), transparent 32%), radial-gradient(circle at 90% 85%, rgb(37 99 235 / 15%), transparent 35%); }
.auth-shell { position: relative; width: min(440px, calc(100% - 32px)); padding: 30px 0; }
.login-card { padding: 38px; border: 1px solid rgb(255 255 255 / 13%); border-radius: 24px; background: #fff; box-shadow: 0 30px 80px rgb(0 0 0 / 32%); }
.login-card h1 { margin: 20px 0 28px; font-size: 1.8rem; letter-spacing: -.04em; }
.login-logo { display: grid; width: 52px; height: 52px; place-items: center; border-radius: 15px; color: var(--ink); background: #2dd4bf; font-size: 1.4rem; font-weight: 950; }
.messages { position: fixed; top: 82px; right: 20px; z-index: 50; display: grid; width: min(380px, calc(100% - 40px)); gap: 8px; }
.message { padding: 12px 15px; border: 1px solid var(--line); border-radius: 12px; color: #334155; background: #fff; box-shadow: var(--shadow); font-size: .88rem; }
.message-success { border-color: #99f6e4; }
.message-error { border-color: #fecaca; }
.mobile-nav { display: none; }

@media (max-width: 900px) {
  .topbar { grid-template-columns: 1fr auto; padding: 0 24px; }
  .desktop-nav { display: none; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .filters { grid-template-columns: repeat(2, 1fr); }
  .filter-actions { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  body { padding-bottom: 76px; }
  .topbar { min-height: 62px; padding: 0 18px; }
  .brand-mark { width: 33px; height: 33px; }
  .brand > span:last-child, .account > span { display: none; }
  .shell { width: min(100% - 28px, 1180px); padding: 28px 0 36px; }
  .page-heading { align-items: center; margin-bottom: 19px; }
  .page-heading h1 { font-size: 1.75rem; }
  .dashboard-heading { align-items: flex-end; }
  .month-switcher { gap: 9px; }
  .month-switcher a { width: 32px; height: 32px; }
  .summary-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .summary-card { min-height: 126px; padding: 17px; border-radius: 15px; }
  .summary-card strong { font-size: 1.35rem; }
  .summary-card small { line-height: 1.3; }
  .panel { border-radius: 15px; }
  .panel-heading { padding: 20px 18px 15px; }
  .category-bars { padding: 5px 18px 22px; }
  .month-chart { height: 220px; padding: 34px 14px 19px; }
  .expense-row { grid-template-columns: 42px minmax(0, 1fr) auto; min-height: 72px; gap: 11px; padding: 12px 14px; }
  .category-icon { width: 39px; height: 39px; border-radius: 12px; }
  .expense-main small { max-width: 50vw; }
  .expense-amount { font-size: .91rem; }
  .filters { grid-template-columns: 1fr 1fr; padding: 14px; }
  .filters .field:nth-child(3), .filters .field:nth-child(4) { grid-column: auto; }
  .filter-actions .button { flex: 1; }
  .list-footer { align-items: flex-start; flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .stack-form { padding: 20px 17px; }
  .form-actions { position: sticky; bottom: 74px; padding: 10px 0 0; background: linear-gradient(transparent, white 25%); }
  .form-actions .button { flex: 1; }
  .category-item { padding: 14px; }
  .status-pill { font-size: .66rem; }
  .login-card { padding: 30px 24px; border-radius: 20px; }
  .messages { top: 70px; right: 14px; width: calc(100% - 28px); }
  .desktop-only { display: none; }
  .mobile-nav { position: fixed; right: 0; bottom: 0; left: 0; z-index: 30; display: grid; grid-template-columns: 1fr 76px 1fr; align-items: center; height: 68px; padding: 0 18px max(0px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgb(255 255 255 / 96%); backdrop-filter: blur(14px); }
  .mobile-nav > a:not(.mobile-add) { display: grid; place-items: center; gap: 1px; color: var(--muted); font-size: .67rem; font-weight: 750; }
  .mobile-nav > a:not(.mobile-add) span { font-size: 1.25rem; line-height: 1; }
  .mobile-nav a[aria-current="page"] { color: var(--brand-dark); }
  .mobile-add { display: grid; width: 52px; height: 52px; margin: -25px auto 0; place-items: center; border: 5px solid var(--canvas); border-radius: 50%; color: #fff; background: var(--brand); box-shadow: 0 8px 22px rgb(15 118 110 / 30%); font-size: 1.55rem; }
}

@media (max-width: 400px) {
  .summary-grid { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr; }
  .filters .field { grid-column: 1; }
  .expense-main small { max-width: 43vw; }
}

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