:root {
  --bg: #0f1419;
  --surface: #1a222d;
  --surface2: #232d3b;
  --border: #2f3d4f;
  --text: #e8eef5;
  --muted: #8fa3b8;
  --accent: #3dd6c3;
  --accent-dim: #2a9d8f;
  --danger: #f07178;
  --income: #7fd99a;
  --radius: 12px;
  --font: "DM Sans", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: radial-gradient(ellipse 120% 80% at 50% -20%, #1e3a4a 0%, var(--bg) 55%);
  color: var(--text);
  line-height: 1.5;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.gate {
  min-height: 100vh;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.gate.is-visible {
  display: flex;
}

body.is-authed .gate {
  display: none !important;
}

.gate-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}

.gate-card h1 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
}

.gate-error {
  color: var(--danger);
  font-size: 0.9rem;
}

.app {
  display: none;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1.25rem 3rem;
}

.app.is-visible,
body.is-authed .app {
  display: block;
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
}

.brand-mark {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

.tabs {
  display: flex;
  gap: 0.35rem;
  flex: 1;
}

.tab {
  font: inherit;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  cursor: pointer;
}

.tab.is-active {
  background: var(--surface2);
  color: var(--text);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.year-picker select,
.month-picker input {
  font: inherit;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
}

.btn {
  font: inherit;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--accent);
  color: #0a1218;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-dim);
  color: var(--text);
}

.btn-secondary {
  background: var(--surface2);
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}

.link-btn {
  font: inherit;
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.lede {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0 0 1rem;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.kpi-label {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value {
  font-size: 1.45rem;
  font-weight: 700;
  margin-top: 0.25rem;
}

.kpi-value.negative {
  color: var(--danger);
}

.kpi-value.positive {
  color: var(--income);
}

.kpi-sub {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.chart-wide {
  grid-column: 1 / -1;
}

@media (max-width: 768px) {
  .charts-grid {
    grid-template-columns: 1fr;
  }
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  transition: border-color 0.15s, background 0.15s;
}

.dropzone.is-dragover {
  border-color: var(--accent);
  background: rgba(61, 214, 195, 0.06);
}

.field,
.gate-card label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.field input,
.gate-card input,
.map-grid select {
  font: inherit;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
}

.map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.import-result {
  margin-top: 0.75rem;
  color: var(--accent);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
  align-items: center;
}

.toolbar input[type="search"] {
  flex: 1;
  min-width: 180px;
  font: inherit;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
}

.check-inline {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.data-table th {
  color: var(--muted);
  font-weight: 500;
}

.data-table select,
.data-table input {
  font: inherit;
  max-width: 100%;
  padding: 0.25rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
}

.amount-expense {
  color: var(--danger);
}

.amount-income {
  color: var(--income);
}

.rule-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.rule-form input,
.rule-form select {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  flex: 1;
  min-width: 140px;
}

.rules-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.rules-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.reminder-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  background: rgba(61, 214, 195, 0.1);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  font-size: 0.95rem;
}

.dashboard-filters {
  margin-bottom: 0.75rem;
}

.dashboard-filters input {
  width: min(320px, 100%);
  font: inherit;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

.budget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.budget-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
}

.budget-row input {
  font: inherit;
  padding: 0.4rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
}

.fixed-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
}

.rule-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.rules-list button {
  font: inherit;
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
}
