:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --chart-credit: #2a78d6;
  --chart-debit: #e34948;
  --delta-good: #006300;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page-plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --chart-credit: #3987e5;
    --chart-debit: #e66767;
    --delta-good: #0ca30c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 32px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px 0 16px;
}
.topbar h1 { font-size: 20px; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.muted { color: var(--text-muted); font-size: 13px; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--chart-credit); color: #fff; }
.btn-primary:disabled { opacity: 0.6; cursor: default; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
@media (min-width: 640px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}
.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-label { font-size: 12px; color: var(--text-muted); }
.stat-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-credit { color: var(--chart-credit); }
.stat-debit { color: var(--chart-debit); }
.stat-positive { color: var(--delta-good); }
.stat-negative { color: var(--chart-debit); }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 16px;
}
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label { font-size: 12px; color: var(--text-muted); }
.filter-group select, .filter-group input {
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}
.search-group { flex: 1; min-width: 160px; }
.search-group input { width: 100%; }

.charts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
@media (min-width: 720px) {
  .charts { grid-template-columns: 1fr 1fr; }
}
.chart-card, .table-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.chart-card h2, .table-card h2 {
  font-size: 14px;
  margin: 0 0 10px;
  color: var(--text-secondary);
}
.chart-svg-wrap { width: 100%; }
.chart-svg { width: 100%; height: auto; display: block; }
.chart-empty { color: var(--text-muted); font-size: 13px; margin: 24px 0; text-align: center; }

.chart-baseline { stroke: var(--baseline); stroke-width: 1; }
.chart-axis-label { font-size: 10px; fill: var(--text-muted); }
.chart-row-label { font-size: 11px; fill: var(--text-secondary); dominant-baseline: middle; }
.chart-value-label { font-size: 11px; fill: var(--text-primary); font-variant-numeric: tabular-nums; dominant-baseline: middle; }

.chart-legend { display: flex; gap: 14px; margin-top: 8px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.legend-item i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.chart-tooltip {
  position: fixed;
  z-index: 100;
  background: var(--text-primary);
  color: var(--surface-1);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  pointer-events: none;
  max-width: 220px;
}

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--gridline); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty-state { color: var(--text-muted); font-size: 13px; text-align: center; padding: 20px 0; }

.chart-hscroll { overflow-x: auto; }
.chart-svg-fixed { width: auto; max-width: none; }
.tag-manual {
  font-size: 10px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 4px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.section-header h2 { margin: 0; }
.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.date-coverage { font-size: 12px; color: var(--text-muted); margin: 2px 0 0; }

.income-total {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--chart-credit);
  margin: 0 0 12px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 200;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  width: 100%;
  max-width: 340px;
}
.modal h2 { margin: 0 0 14px; font-size: 16px; }
.modal .field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.modal label { font-size: 12px; color: var(--text-muted); }
.modal input {
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 15px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
