/* ============================================================
   SpendLocal — clean, minimalistic dashboard
   Design tokens sourced from the validated data-viz palette.
   Theme-aware: light default, [data-theme="dark"] override.
   ============================================================ */

:root {
  --page:        #f9f9f7;
  --surface:     #fcfcfb;
  --surface-2:   #f4f3f0;
  --ink:         #0b0b0b;
  --ink-2:       #52514e;
  --muted:       #898781;
  --grid:        #e1e0d9;
  --baseline:    #c3c2b7;
  --border:      rgba(11, 11, 11, 0.10);
  --series:      #2a78d6;
  --series-soft: rgba(42, 120, 214, 0.12);
  --good:        #006300;

  /* Categorical slots (fixed order) — validated data-viz palette, light */
  --c1: #2a78d6; --c2: #1baf7a; --c3: #eda100; --c4: #008300;
  --c5: #4a3aa7; --c6: #e34948; --c7: #e87ba4; --c8: #eb6834;
  --c-other: #898781;

  --radius:      14px;
  --radius-sm:   9px;
  --gap:         20px;
  --font:        system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

:root[data-theme="dark"] {
  --page:        #0d0d0d;
  --surface:     #1a1a19;
  --surface-2:   #232321;
  --ink:         #ffffff;
  --ink-2:       #c3c2b7;
  --muted:       #898781;
  --grid:        #2c2c2a;
  --baseline:    #383835;
  --border:      rgba(255, 255, 255, 0.10);
  --series:      #3987e5;
  --series-soft: rgba(57, 135, 229, 0.16);
  --good:        #0ca30c;

  /* Categorical slots stepped for the dark surface */
  --c1: #3987e5; --c2: #199e70; --c3: #c98500; --c4: #008300;
  --c5: #9085e9; --c6: #e66767; --c7: #d55181; --c8: #d95926;
  --c-other: #898781;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 24px 48px;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

.brand { display: flex; gap: 14px; align-items: center; }

.brand-mark {
  font-size: 30px;
  line-height: 1;
  color: var(--series);
}

.brand-name {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand-tag {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--ink-2);
  max-width: 460px;
}

.header-controls { display: flex; align-items: center; gap: 12px; }

.month-picker {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
}

.month-label {
  font-size: 13.5px;
  font-weight: 550;
  padding: 5px 10px;
  min-width: 108px;
  text-align: center;
  border: none;
  background: transparent;
  color: inherit;
  font-family: inherit;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s ease;
}
.month-label:hover { background: var(--surface-2); }

.icon-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: background .15s ease;
}
.icon-btn:hover { background: var(--surface-2); }

.theme-toggle {
  border: 1px solid var(--border);
  background: var(--surface);
}

/* ---------- Stat tiles ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
  margin-bottom: var(--gap);
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-label {
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 500;
}

.stat-value {
  font-size: 25px;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-sub {
  font-size: 12px;
  color: var(--ink-2);
}

/* ---------- Expense / income toggle + balance ---------- */
.flow-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: var(--gap);
}

.flow-switch {
  display: inline-flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
}
.flow-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: none;
  background: transparent;
  color: var(--ink-2);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 20px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.flow-btn:hover { color: var(--ink); }
.flow-btn.is-active { color: var(--ink); }
.flow-btn[data-flow="expense"].is-active { background: var(--series-soft); }
.flow-btn[data-flow="income"].is-active { background: rgba(12, 163, 12, 0.14); }

.flow-arrow { font-size: 15px; font-weight: 800; line-height: 1; }
.flow-arrow--out { color: var(--series); }
.flow-arrow--in { color: var(--good); }

.balance {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
.balance-label { font-size: 11.5px; color: var(--muted); }
.balance-value {
  font-size: 18px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.balance-value.is-positive { color: var(--good); }
.balance-value.is-negative { color: var(--series); }

/* Income amounts in the table read as positive/green */
.cell-amount.is-income { color: var(--good); }

/* ---------- Main grid ---------- */
.main-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: var(--gap);
  align-items: start;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.table-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Removable "day filter" chip (set by clicking a trend bar) */
.day-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--series);
  background: var(--series-soft);
  color: var(--ink);
  font-family: inherit;
  font-size: 12px;
  font-weight: 550;
  padding: 3px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.day-chip span { color: var(--muted); font-weight: 700; }
.day-chip:hover span { color: #d03b3b; }
/* `display: inline-flex` above would otherwise override the `hidden` attribute */
.day-chip[hidden] { display: none; }

.card-hint {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Trend chart (spend over time) ---------- */
.trend-card { margin-bottom: var(--gap); }

/* Compact segmented control in a card head (reuses .seg / .seg-btn) */
.card-head .seg { width: auto; background: var(--surface-2); border-radius: 999px; }
.card-head .seg-btn { flex: 0 0 auto; padding: 6px 14px; font-size: 12.5px; border-radius: 999px; }

.trend {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 2px;                 /* 2px surface gap between bars */
  height: 150px;
  padding-top: 10px;
  border-bottom: 1px solid var(--baseline);
}
.trend-col {
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  cursor: pointer;
}
.trend-bar {
  width: 100%;
  max-width: 30px;
  background: var(--series);
  border-radius: 4px 4px 0 0;   /* rounded data-end */
  transition: height .4s cubic-bezier(.4, 0, .1, 1), opacity .12s ease;
}
.trend.has-hover .trend-col:not(.is-hot) .trend-bar { opacity: 0.35; }
/* Selected day (table drilled down to it) stays highlighted even without hover */
.trend-col.is-selected .trend-bar { background: var(--good); opacity: 1; }
.trend.has-hover .trend-col.is-selected:not(.is-hot) .trend-bar { opacity: 0.55; }

.trend-x { display: flex; gap: 2px; margin-top: 6px; }
.trend-xlabel {
  flex: 1 1 0;
  min-width: 0;
  text-align: center;
  font-size: 10.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.trend-tooltip {
  position: absolute;
  z-index: 5;
  transform: translate(-50%, -130%);
  background: var(--ink);
  color: var(--surface);
  font-size: 12px;
  line-height: 1.35;
  padding: 6px 9px;
  border-radius: 8px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
}
.trend-tooltip b { font-weight: 650; }

/* ---------- Dimension switcher (segmented control) ---------- */
.dim-switch {
  display: flex;
  gap: 3px;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px;
  margin-bottom: 22px;
}
.dim-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--ink-2);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 550;
  padding: 7px 4px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.dim-btn:hover { color: var(--ink); }
.dim-btn.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* ---------- Donut (pie) chart ---------- */
.donut-wrap {
  position: relative;
  width: 190px;
  height: 190px;
  margin: 4px auto 20px;
}
.donut { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut .slice {
  fill: none;
  stroke-width: 18;
  transition: opacity .15s ease, stroke-width .15s ease;
  cursor: pointer;
}
.donut.has-hover .slice:not(.is-hot) { opacity: 0.32; }
.donut .slice.is-hot { stroke-width: 20; }
.donut .slice.is-selected { stroke-width: 22; }

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  gap: 2px;
}
.donut-total {
  font-size: 21px;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.donut-caption { font-size: 11.5px; color: var(--muted); }

.chart-tooltip {
  position: absolute;
  z-index: 5;
  transform: translate(-50%, -130%);
  background: var(--ink);
  color: var(--surface);
  font-size: 12px;
  line-height: 1.35;
  padding: 6px 9px;
  border-radius: 8px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
}
.chart-tooltip b { font-weight: 650; }

/* ---------- Legend ---------- */
.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.legend-item {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: default;
  transition: background .12s ease;
}
.legend-item:hover { background: var(--surface-2); }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; }
.legend-name {
  font-size: 13px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.legend-val {
  font-size: 12.5px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.legend-pct { color: var(--muted); margin-left: 4px; }

.chart-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 24px 0;
  text-align: center;
}

/* ---------- Table ---------- */
.table-tools { display: flex; gap: 10px; flex-wrap: wrap; }

.search {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 11px;
  color: var(--muted);
  font-size: 15px;
  pointer-events: none;
}
.search input {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 8px 12px 8px 32px;
  font-size: 13px;
  font-family: inherit;
  width: 200px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.search input:focus {
  border-color: var(--series);
  box-shadow: 0 0 0 3px var(--series-soft);
}

/* ---------- Custom dropdown (category filter) ---------- */
.dropdown { position: relative; }

.dropdown-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 190px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
}
.dropdown-btn:focus-visible { border-color: var(--series); box-shadow: 0 0 0 3px var(--series-soft); }
.dropdown-caret { color: var(--muted); font-size: 11px; transition: transform .15s ease; }
.dropdown.is-open .dropdown-caret { transform: rotate(180deg); }

.dropdown-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 40;
  min-width: 230px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
  padding: 6px;
  max-height: 340px;
  overflow-y: auto;
}
.dropdown-sheet-head { display: none; }

.dropdown-options { display: flex; flex-direction: column; gap: 2px; }
.dropdown-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--ink);
  cursor: pointer;
  text-transform: capitalize;
  transition: background .12s ease;
}
.dropdown-option:hover { background: var(--surface-2); }
.dropdown-option .opt-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--muted); }
.dropdown-option .opt-check { margin-left: auto; color: var(--series); font-weight: 700; opacity: 0; }
.dropdown-option.is-selected { background: var(--series-soft); }
.dropdown-option.is-selected .opt-check { opacity: 1; }

.dropdown-backdrop {
  display: none; /* desktop: no dim overlay; click-outside handles close */
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.45);
}

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

.txn-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.txn-table thead th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}

.txn-table tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--grid);
  vertical-align: middle;
}
.txn-table tbody tr:last-child td { border-bottom: none; }
.txn-table tbody tr { transition: background .12s ease; }
.txn-table tbody tr:hover { background: var(--surface-2); }

.col-amount { text-align: right; }
.col-date { white-space: nowrap; }

.cell-date { color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-merchant { font-weight: 500; }
.cell-desc { display: block; font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.cell-merchant .mv { display: inline-block; }

/* Row actions (edit / delete) */
.col-actions { width: 1%; white-space: nowrap; text-align: right; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.row-btn {
  border: none;
  background: transparent;
  color: var(--ink-2);
  width: 30px;
  height: 30px;
  border-radius: 7px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .12s ease, color .12s ease;
}
.row-btn:hover { background: var(--surface-2); color: var(--ink); }
.row-btn--danger:hover { color: #d03b3b; }

.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;
}
.cell-source { color: var(--ink-2); font-size: 12.5px; }
.cell-amount {
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Category pill — text label always present; color is reinforcement only */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  text-transform: capitalize;
  white-space: nowrap;
}
.pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dot, var(--muted));
}

.empty-state {
  color: var(--muted);
  font-size: 13.5px;
  text-align: center;
  padding: 32px 0;
}

/* ---------- Footer ---------- */
.app-footer { margin-top: 28px; text-align: center; }
.privacy-badge {
  font-size: 12.5px;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
  display: inline-block;
}

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 16px;
  cursor: pointer;
  white-space: nowrap;
  transition: filter .15s ease, background .15s ease, border-color .15s ease;
}
.btn-primary { background: var(--series); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-danger { background: #d03b3b; color: #fff; }
.btn-danger:hover { filter: brightness(1.06); }
.btn-ghost {
  background: transparent;
  color: var(--ink-2);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.add-btn, .import-btn, .clear-btn { display: inline-flex; align-items: center; gap: 5px; }
.clear-btn:hover { border-color: #d03b3b; color: #d03b3b; }

/* Toast (import result / errors) */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  z-index: 90;
  max-width: calc(100vw - 32px);
  background: var(--ink);
  color: var(--surface);
  font-size: 13.5px;
  font-weight: 500;
  padding: 12px 18px;
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity .25s ease, transform .25s ease;
  pointer-events: none;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: #d03b3b; color: #fff; }

/* ---------- Add modal / bottom sheet ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(0, 0, 0, 0.5);
}
.modal {
  position: fixed;
  z-index: 80;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
}
.add-form { padding: 20px 22px 22px; display: flex; flex-direction: column; gap: 16px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 650; }

/* Segmented control (form flow toggle) */
.seg {
  display: flex;
  gap: 3px;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 3px;
}
.seg-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--ink-2);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 9px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.seg-btn.is-active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }

/* Fields */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12.5px; font-weight: 550; color: var(--ink-2); }
.field-label .opt { color: var(--muted); font-weight: 400; }

.add-form input[type="text"],
.add-form input[type="date"] {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 15px;
  font-family: inherit;
  width: 100%;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.add-form input:focus { border-color: var(--series); box-shadow: 0 0 0 3px var(--series-soft); }

.amount-input { position: relative; display: flex; align-items: center; }
.amount-input input { padding-right: 46px; font-weight: 600; font-variant-numeric: tabular-nums; }
.amount-cur {
  position: absolute;
  right: 13px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  pointer-events: none;
}

/* Category chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 13px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  text-transform: capitalize;
  transition: background .12s ease, border-color .12s ease;
}
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--dot, var(--muted)); }
.chip:hover { border-color: var(--muted); }
.chip.is-active { background: var(--series-soft); border-color: var(--series); color: var(--ink); }

.form-error {
  margin: 0;
  color: var(--series);
  font-size: 13px;
}
:root[data-theme] .form-error { color: #d03b3b; }

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
.modal-actions .btn { padding: 11px 18px; font-size: 14px; }

/* ---------- Range calendar ---------- */
.cal-modal { width: min(420px, calc(100vw - 32px)); }
.cal { padding: 20px 22px 22px; display: flex; flex-direction: column; gap: 16px; }

.cal-presets { display: flex; flex-wrap: wrap; gap: 8px; }
.cal-presets button {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}
.cal-presets button:hover { border-color: var(--series); background: var(--series-soft); }

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.cal-month-label { font-size: 15px; font-weight: 600; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-wd {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  padding-bottom: 4px;
}
.cal-cell {
  aspect-ratio: 1 / 1;
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  border-radius: 9px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .12s ease, color .12s ease;
}
.cal-cell:hover { background: var(--surface-2); }
.cal-cell.is-today { box-shadow: inset 0 0 0 1.5px var(--baseline); }
.cal-cell.in-range { background: var(--series-soft); border-radius: 0; }
.cal-cell.is-edge { background: var(--series); color: #fff; }
.cal-cell.is-start { border-radius: 9px 0 0 9px; }
.cal-cell.is-end { border-radius: 0 9px 9px 0; }
.cal-cell.is-start.is-end { border-radius: 9px; }

.cal-selection {
  margin: 0;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.cal-selection.is-error { color: #d03b3b; }
.cal-selection.is-error::after { content: " — max 1 rok"; }

/* Confirm (delete) dialog */
.modal--sm { width: min(380px, calc(100vw - 32px)); }
.confirm-body { padding: 22px; display: flex; flex-direction: column; gap: 10px; }
.confirm-body h2 { margin: 0; font-size: 16.5px; font-weight: 650; }
.confirm-body p { margin: 0 0 6px; font-size: 13.5px; color: var(--ink-2); line-height: 1.45; }

/* ---------- Responsive ---------- */

/* Global guards against horizontal overflow */
html, body { max-width: 100%; overflow-x: hidden; }
.main-grid > * { min-width: 0; }           /* let grid children shrink */
.table-wrap { max-width: 100%; }

@media (max-width: 900px) {
  .main-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 560px) {
  .app { padding: 20px 14px 36px; }
  .app-header { gap: 16px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat-value { font-size: 20px; }

  .flow-bar { gap: 12px; }
  .flow-switch { flex: 1; }
  .flow-btn { flex: 1; justify-content: center; padding: 11px 12px; }
  .balance { flex-direction: row; align-items: baseline; gap: 8px; width: 100%; justify-content: space-between; }
  .card { padding: 18px 16px; }

  .card-head { flex-direction: column; align-items: stretch; }
  .table-tools { width: 100%; }
  .search { flex: 1; }
  .search { width: 100%; }

  /* 16px controls: readable text + no iOS focus-zoom */
  .search input,
  .dropdown-btn {
    width: 100%;
    font-size: 16px;
    padding: 12px 14px;
  }
  .search input { padding-left: 38px; }
  .search-icon { font-size: 17px; }
  .dropdown { width: 100%; }
  .dropdown-btn { min-width: 0; }

  /* Category selector opens as a full-width bottom sheet */
  .dropdown-panel {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 60;
    width: 100%;
    min-width: 0;
    max-height: 80vh;
    border: none;
    border-top: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
    padding: 8px 10px calc(env(safe-area-inset-bottom, 0px) + 16px);
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.35);
    animation: sheet-up .22s cubic-bezier(.2, .7, .2, 1);
  }
  .dropdown-sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 12px 14px;
    font-size: 16px;
    font-weight: 600;
  }
  .dropdown-close {
    border: none;
    background: var(--surface-2);
    color: var(--ink);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 15px;
    cursor: pointer;
    display: grid;
    place-items: center;
  }
  .dropdown-option {
    font-size: 17px;
    padding: 16px 14px;
  }
  .dropdown-option .opt-dot { width: 11px; height: 11px; }
  .dropdown-option:not(:last-child) { border-bottom: 1px solid var(--grid); }

  .dropdown-backdrop:not([hidden]) { display: block; }

  .add-btn, .import-btn, .clear-btn { width: 100%; justify-content: center; padding: 12px; font-size: 15px; }

  /* Add modal → full-width bottom sheet */
  .modal {
    top: auto;
    bottom: 0;
    left: 0;
    transform: none;
    width: 100%;
    max-height: 92vh;
    border: none;
    border-top: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
    animation: sheet-up .22s cubic-bezier(.2, .7, .2, 1);
  }
  .add-form { padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 18px); }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; }

  /* Table → stacked cards (no horizontal scroll) */
  .table-wrap { overflow-x: visible; }
  .txn-table thead { display: none; }
  .txn-table, .txn-table tbody, .txn-table tr, .txn-table td { display: block; width: 100%; }
  .txn-table tr {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px 14px;
    margin-bottom: 10px;
  }
  .txn-table tbody tr:hover { background: var(--surface); }
  .txn-table td {
    border: none !important;
    padding: 7px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
  }
  .txn-table td:not(:last-child) { border-bottom: 1px solid var(--grid) !important; }
  .txn-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    flex: none;
  }
  .col-source { display: flex !important; }
  .cell-merchant, .cell-amount, .cell-date { text-align: right; }
}

@keyframes sheet-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

/* ============================================================
   First-run onboarding + sample-data banner
   ============================================================ */

/* When there is no data at all, hide the data panels so the user sees a clear
   call to action instead of empty charts. */
.app.is-empty .flow-bar,
.app.is-empty .stats,
.app.is-empty .trend-card,
.app.is-empty .main-grid { display: none; }

/* These set display:flex below, which would override the UA [hidden] rule — restore
   it so toggling the `hidden` attribute actually hides them. */
.onboarding[hidden],
.demo-banner[hidden] { display: none; }

.onboarding {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 44px 28px;
  margin-top: var(--gap);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.onboarding-mark { font-size: 40px; color: var(--series); line-height: 1; }
.onboarding-title { font-size: 20px; font-weight: 700; color: var(--ink); }
.onboarding-text {
  max-width: 440px;
  color: var(--ink-2);
  font-size: 14px;
  line-height: 1.55;
}
.onboarding-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 6px;
}
.onboarding-actions .btn { padding: 11px 18px; font-size: 14px; }
.onboarding-demo {
  margin-top: 8px;
  padding: 10px 18px;
  background: var(--series-soft);
  border: 1px solid var(--series);
  border-radius: var(--radius-sm);
  color: var(--series);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s ease, background .15s ease;
}
.onboarding-demo:hover { filter: brightness(1.05); }

.demo-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: var(--gap);
  padding: 10px 14px;
  background: var(--series-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.demo-banner-text { font-size: 13px; color: var(--ink-2); }
.demo-banner .btn { padding: 7px 12px; font-size: 12.5px; }

@media (max-width: 560px) {
  .onboarding { padding: 36px 20px; }
  .onboarding-actions { flex-direction: column; align-self: stretch; }
  .onboarding-actions .btn { width: 100%; }
  .onboarding-demo { align-self: stretch; }
}
