:root {
  color-scheme: light;
  --ink: #17211c;
  --muted: #68736d;
  --line: #dce2de;
  --surface: #ffffff;
  --canvas: #f3f5f3;
  --green: #247451;
  --green-soft: #e5f1eb;
  --red: #b64b43;
  --red-soft: #f6e9e7;
  --amber: #a46c22;
  --blue: #326b8b;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--canvas); }
body { margin: 0; min-width: 320px; }
button, input, select { font: inherit; letter-spacing: 0; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner { width: min(1770px, calc(100% - 40px)); height: 64px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark { width: 46px; height: 46px; display: grid; place-items: center; background: var(--ink); color: white; border-radius: 6px; font-weight: 800; }
.brand-mark.small { width: 32px; height: 32px; font-size: 12px; }
.quiet-button { border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 8px 12px; border-radius: 5px; cursor: pointer; }
.quiet-button:hover { background: var(--canvas); }

.page-shell { width: min(1770px, calc(100% - 40px)); margin: 0 auto; padding: 34px 0 60px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.page-heading h1 { margin: 2px 0 0; font-size: 30px; letter-spacing: 0; }
.eyebrow { margin: 0; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0; }
.period-select { display: grid; gap: 5px; }
.period-select label { color: var(--muted); font-size: 12px; }
.period-controls { display: flex; gap: 8px; }
.period-select select { min-width: 210px; border: 1px solid var(--line); background: var(--surface); border-radius: 5px; padding: 9px 34px 9px 10px; color: var(--ink); }
.period-select button { border: 0; border-radius: 5px; padding: 9px 13px; background: var(--green); color: white; font-weight: 700; cursor: pointer; }
.period-select button:hover { background: #1d6143; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); background: var(--surface); margin-bottom: 20px; }
.metric { min-width: 0; padding: 20px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 7px; }
.metric strong { display: block; font-size: 23px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.positive { color: var(--green); }
.negative { color: var(--red); }

.dashboard-grid { display: grid; grid-template-columns: minmax(300px, 3fr) minmax(0, 7fr); gap: 20px; margin-bottom: 20px; }
.panel { min-width: 0; background: var(--surface); border: 1px solid var(--line); }
.panel-heading { min-height: 54px; padding: 12px 16px; display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.panel-heading h2 { margin: 3px 0 0; font-size: 18px; letter-spacing: 0; }
.category-list { padding: 6px 16px 10px; }
.category-row { display: block; margin: 1px -7px; padding: 6px 7px; border-left: 3px solid transparent; color: inherit; text-decoration: none; }
.category-row:hover { background: #f5f8f6; }
.category-row.selected { border-left-color: var(--green); background: var(--green-soft); }
.category-row.dimmed { color: #929a96; }
.category-row.dimmed small { color: #a1a8a4; }
.category-row.dimmed .category-expense, .category-row.dimmed .category-income { color: #a1a8a4; }
.category-row.dimmed .category-bar-wrap { filter: grayscale(1); opacity: .38; }
.category-row.dimmed:hover { color: var(--ink); background: #f5f8f6; }
.category-meta { display: flex; justify-content: space-between; gap: 16px; font-size: 13px; line-height: 1.2; }
.category-meta span { min-width: 0; overflow-wrap: anywhere; }
.category-meta strong { font-variant-numeric: tabular-nums; white-space: nowrap; }
.category-expense { color: var(--red); }
.category-income { color: var(--green); font-size: 10px; line-height: 1.2; text-align: right; }
.category-income strong { font-variant-numeric: tabular-nums; white-space: nowrap; }
.category-row small { display: block; color: var(--muted); margin-top: 3px; font-size: 10px; line-height: 1.2; }
.category-row .category-footer { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.bar-track { height: 4px; margin-top: 5px; background: #edf0ee; overflow: hidden; }
.category-bar-wrap { display: flex; height: 100%; overflow: hidden; }
.category-bar { display: block; width: 100%; height: 100%; background: var(--red); }
.category-segment { display: block; height: 100%; }

.daily-panel { display: flex; flex-direction: column; }
.chart-heading { justify-content: space-between; gap: 16px; }
.chart-legend { display: flex; gap: 14px; color: var(--muted); font-size: 11px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend span::before { content: ""; width: 9px; height: 9px; display: inline-block; }
.expense-key::before { background: var(--red); }
.income-key::before { background: var(--green); }
.daily-chart { flex: 1 1 auto; min-height: 260px; padding: 14px 16px 12px 8px; display: flex; align-items: stretch; overflow: hidden; }
.y-axis { position: relative; flex: 0 0 64px; color: var(--muted); font-size: 9px; font-variant-numeric: tabular-nums; }
.y-axis-scale { position: absolute; inset: 0 7px 17px 0; }
.y-axis-label { position: absolute; right: 0; transform: translateY(50%); white-space: nowrap; }
.chart-plot { position: relative; flex: 1 1 auto; min-width: 0; display: flex; align-items: stretch; gap: 4px; padding-left: 4px; }
.chart-plot::before { content: ""; position: absolute; left: 0; right: 0; bottom: 17px; border-bottom: 1px solid #9ca7a1; }
.chart-plot::after { content: ""; position: absolute; left: 0; top: 0; bottom: 17px; border-left: 1px solid #9ca7a1; }
.grid-lines { position: absolute; z-index: 0; inset: 0 0 17px 4px; pointer-events: none; }
.grid-line { position: absolute; left: 0; right: 0; border-top: 1px solid #e2e7e4; }
.day-column { position: relative; z-index: 1; flex: 1 1 0; min-width: 4px; display: flex; flex-direction: column; justify-content: end; align-items: center; gap: 6px; }
.chart-bars { width: 100%; flex: 1 1 auto; min-height: 0; display: flex; align-items: end; justify-content: center; gap: 2px; }
.day-bar { flex: 0 0 var(--bar-width, 12px); width: var(--bar-width, 12px); min-height: 0; border-radius: 2px 2px 0 0; transition: height .18s ease, opacity .18s ease; }
.expense-bar { background: var(--red); }
.income-bar { background: var(--green); }
.chart-bars:hover .day-bar { opacity: .72; }
.day-column small { color: var(--muted); font-size: 9px; }

.table-wrap { overflow-x: auto; }
.transactions-heading { justify-content: space-between; gap: 18px; }
.transaction-filters { display: flex; align-items: center; gap: 8px; }
.transaction-filters label { color: var(--muted); font-size: 11px; }
.transaction-filters select { min-width: 155px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--ink); padding: 7px 28px 7px 8px; }
.result-count { color: var(--muted); font-size: 13px; font-weight: 600; }
.clear-filter { border: 1px solid var(--line); border-radius: 5px; padding: 8px 10px; color: var(--ink); text-decoration: none; white-space: nowrap; }
.clear-filter:hover { background: var(--canvas); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { color: var(--muted); font-weight: 600; text-align: left; background: #fafbfa; }
th, td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.sort-button { display: inline-flex; align-items: center; gap: 6px; border: 0; padding: 0; background: transparent; color: inherit; font-weight: inherit; cursor: pointer; }
.sort-button:hover, th[aria-sort]:not([aria-sort="none"]) .sort-button { color: var(--ink); }
.sort-button:focus-visible { outline: 2px solid var(--green); outline-offset: 4px; border-radius: 2px; }
.amount-sort-button { justify-content: flex-end; }
.sort-indicator { width: 12px; color: #a8b0ac; text-align: center; }
th[aria-sort]:not([aria-sort="none"]) .sort-indicator { color: var(--green); }
tbody tr:last-child td { border-bottom: 0; }
.description-cell { max-width: 520px; }
.description-primary, .recipient-message { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recipient-message { margin-top: 3px; color: var(--muted); font-size: 11px; line-height: 1.25; }
.amount-cell { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 650; }
.category-select { width: 100%; min-width: 150px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--ink); padding: 6px 28px 6px 8px; }
.category-select:focus { border-color: var(--green); outline: 2px solid var(--green-soft); }
.category-select:disabled { color: var(--muted); cursor: wait; }
.back-to-top { position: fixed; right: 24px; bottom: 24px; z-index: 20; width: 46px; height: 46px; border: 0; border-radius: 6px; background: var(--ink); color: white; font-size: 24px; line-height: 1; cursor: pointer; box-shadow: 0 4px 14px rgba(23, 33, 28, .22); }
.back-to-top:hover { background: var(--green); }
.back-to-top:focus-visible { outline: 3px solid var(--green-soft); outline-offset: 2px; }

.login-page { min-height: 100vh; background: var(--canvas); }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(410px, 100%); border: 1px solid var(--line); background: var(--surface); padding: 34px; }
.login-panel .brand-mark { margin-bottom: 28px; }
.login-panel h1 { margin: 4px 0 8px; font-size: 28px; letter-spacing: 0; }
.muted { color: var(--muted); line-height: 1.5; }
.login-form { display: grid; gap: 9px; margin-top: 26px; }
.login-form label { font-size: 13px; font-weight: 650; }
.login-form input { width: 100%; border: 1px solid #aeb8b2; border-radius: 5px; padding: 11px 12px; outline: none; }
.login-form input:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.login-form button { margin-top: 7px; border: 0; border-radius: 5px; padding: 12px; background: var(--green); color: white; font-weight: 700; cursor: pointer; }
.login-form button:hover { background: #1d6143; }
.form-error { border-left: 3px solid var(--red); background: var(--red-soft); color: #83372f; padding: 10px 12px; font-size: 13px; }
.empty-state { padding: 80px 0; }

@media (max-width: 820px) {
  .topbar-inner, .page-shell { width: min(100% - 24px, 1770px); }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .daily-chart { height: 260px; }
}

@media (max-width: 520px) {
  .page-shell { padding-top: 24px; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .period-select select { width: 100%; min-width: 0; }
  .period-controls { align-items: stretch; }
  .metrics { grid-template-columns: 1fr; }
  .metric { border-right: 0; border-bottom: 1px solid var(--line); }
  .metric:nth-child(3) { border-bottom: 1px solid var(--line); }
  .metric:last-child { border-bottom: 0; }
  .metric strong { font-size: 21px; }
  .login-panel { padding: 26px 22px; }
  .description-cell { min-width: 240px; }
  .transactions-heading { align-items: flex-start; }
  .transaction-filters { align-items: stretch; flex-direction: column; }
  .transaction-filters label { display: none; }
  .transaction-filters select { min-width: 130px; max-width: 150px; }
  .back-to-top { right: 14px; bottom: 14px; width: 44px; height: 44px; }
}
