/* Design read: personal finance dashboard for one owner, calm and dense enough
   to scan on a phone. Neutral zinc base, one emerald accent, Geist + Noto Sans
   Georgian, Phosphor icons. Radius system: panels 16px, controls 10px. */

:root {
  color-scheme: light;
  --bg: #f7f7f6;
  --panel: #ffffff;
  --panel-2: #f1f1ef;
  --line: #e6e6e3;
  --text: #18181b;
  --text-2: #52525b;
  --muted: #71717a;
  --accent: #047857;
  --accent-ink: #ffffff;
  --accent-soft: #e3f3ec;
  --bar: #059669;
  --bar-soft: #a7d8c4;
  --neg: #b4b4ad;
  --warn: #b45309;
  --danger: #be123c;
  --shadow: 0 1px 2px rgb(24 24 27 / .04), 0 4px 16px rgb(24 24 27 / .04);
  --r-panel: 16px;
  --r-ctl: 10px;
  --font: "Geist Variable", "Noto Sans Georgian Variable", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono Variable", ui-monospace, "SF Mono", Menlo, monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111111;
    --panel: #19191b;
    --panel-2: #222225;
    --line: #2c2c30;
    --text: #f4f4f5;
    --text-2: #c4c4ca;
    --muted: #8e8e96;
    --accent: #10b981;
    --accent-ink: #062a1d;
    --accent-soft: #0f2a20;
    --bar: #10b981;
    --bar-soft: #1f5c45;
    --neg: #55555c;
    --warn: #f59e0b;
    --danger: #fb7185;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111111; --panel: #19191b; --panel-2: #222225; --line: #2c2c30;
  --text: #f4f4f5; --text-2: #c4c4ca; --muted: #8e8e96; --accent: #10b981; --accent-ink: #062a1d;
  --accent-soft: #0f2a20; --bar: #10b981; --bar-soft: #1f5c45; --neg: #55555c; --warn: #f59e0b;
  --danger: #fb7185; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px 20px calc(40px + env(safe-area-inset-bottom));
  display: grid;
  gap: 16px;
}
h1 { font-size: 20px; line-height: 1.2; margin: 0; font-weight: 600; letter-spacing: -0.015em; }
h2 { font-size: 15px; margin: 0 0 14px; font-weight: 600; letter-spacing: -0.005em; }
h3 { font-size: 14px; margin: 0; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.num, .big, dd, .amt, .val, .bal-val { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.count { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 4px; }
[hidden] { display: none !important; }
i.ph { font-size: 18px; line-height: 1; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  padding: 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}

/* ---------- controls ---------- */
.btn {
  appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: var(--r-ctl); padding: 0 14px; height: 40px;
  font: 500 14px/1 var(--font); white-space: nowrap; cursor: pointer; position: relative;
  transition: background .2s var(--ease), transform .12s var(--ease), border-color .2s var(--ease);
}
.btn:hover { background: var(--panel-2); }
.btn:active { transform: translateY(1px) scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  appearance: none; border: 0; background: transparent; color: var(--text-2);
  width: 36px; height: 36px; border-radius: var(--r-ctl); cursor: pointer;
  display: inline-grid; place-items: center;
  transition: background .2s var(--ease), transform .12s var(--ease);
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn:disabled { opacity: .3; cursor: default; background: none; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; font-size: 13px; padding: 8px; }
.link:hover { color: var(--text); }

input, select, textarea {
  font: inherit; font-size: 15px; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--r-ctl); padding: 0 12px; height: 40px; width: 100%;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
textarea { height: auto; padding: 10px 12px; resize: vertical; font: 13px/1.5 var(--mono); }
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }

.field { display: grid; gap: 6px; }
.field label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.hint { font-size: 12.5px; color: var(--muted); }
.field-error { font-size: 13px; color: var(--danger); }
.check { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.badge {
  position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); color: #fff; font: 600 11px/18px var(--font); text-align: center;
}

/* ---------- skeletons ---------- */
.sk {
  display: inline-block; border-radius: 6px; vertical-align: middle;
  background: linear-gradient(90deg, var(--panel-2) 0%, var(--line) 50%, var(--panel-2) 100%);
  background-size: 200% 100%; animation: shimmer 1.4s linear infinite;
}
.sk-title { width: 140px; height: 20px; }
.sk-big { width: 190px; height: 44px; }
.sk-num { width: 80px; height: 18px; }
.sk-row { display: block; height: 14px; margin: 12px 0; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: grid; gap: 18px; }
.logo {
  width: 44px; height: 44px; border-radius: 12px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 22px; font-weight: 600;
}

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.month { display: flex; align-items: center; gap: 2px; }
.month h1 { min-width: 156px; text-align: center; }
.actions { display: flex; gap: 8px; }

/* ---------- overview ---------- */
.overview {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  grid-template-areas: "head stats" "daily daily";
  gap: 20px 32px;
  padding: 24px;
}
.headline { grid-area: head; align-self: end; }
.label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.big { font-family: var(--font); font-variant-numeric: tabular-nums; font-size: clamp(40px, 6vw, 58px); line-height: 1.05; font-weight: 600; letter-spacing: -0.04em; margin: 6px 0 8px; }
.side-stats dd small { display: block; font: 12px var(--font); color: var(--muted); letter-spacing: 0; }
.big .cur { color: var(--muted); font-size: .55em; font-weight: 400; letter-spacing: -0.01em; }
.delta { font-size: 13.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.delta .pill {
  display: inline-flex; align-items: center; gap: 3px; padding: 1px 8px; border-radius: 999px;
  font-weight: 500; font-size: 12.5px; background: var(--panel-2); color: var(--text-2);
}
.delta .pill.more { color: var(--warn); }
.delta .pill.less { color: var(--accent); }
.side-stats {
  grid-area: stats; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 16px 24px; align-self: end;
}
.side-stats div { border-left: 2px solid var(--line); padding-left: 12px; }
.side-stats dt { font-size: 12.5px; color: var(--muted); }
.side-stats dd { margin: 2px 0 0; font-size: 19px; font-weight: 500; white-space: nowrap; }
.side-stats dd.pos { color: var(--accent); }
.daily { grid-area: daily; border-top: 1px solid var(--line); padding-top: 18px; }

.chart { position: relative; height: 150px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .axis { fill: var(--muted); font: 10.5px var(--mono); }
.chart .base { stroke: var(--line); }
.chart .bar { fill: var(--bar-soft); transition: fill .2s var(--ease); }
.chart .bar.on { fill: var(--bar); }
.chart .hit { fill: transparent; cursor: default; }
.chart .col:hover .bar { fill: var(--bar); }
.chart .today { fill: var(--text); font-weight: 600; }

/* ---------- balances strip ---------- */
.balances { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.bal {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-panel); box-shadow: var(--shadow);
}
.bank-mark {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none;
  font: 600 11px/1 var(--font); letter-spacing: .02em; background: var(--panel-2); color: var(--text-2);
}
.bal-name { font-size: 13px; color: var(--muted); }
.bal-val { font-size: 17px; font-weight: 500; }
.bal-when { font-size: 12px; color: var(--muted); }

/* ---------- split grid ---------- */
.split { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.stack { display: grid; gap: 16px; }

/* Bars: no background tracks, the bar length alone carries the value. */
.bars { display: grid; gap: 4px; }
.hbar {
  display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; gap: 2px 12px; align-items: center;
  padding: 8px; margin: 0 -8px; border-radius: var(--r-ctl); cursor: pointer; text-align: left;
  background: none; border: 0; color: inherit; font: inherit; width: calc(100% + 16px);
  transition: background .2s var(--ease);
}
.hbar:hover { background: var(--panel-2); }
.hbar .ico {
  grid-row: span 2; width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.hbar .name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .val { font-size: 14px; font-weight: 500; text-align: right; }
.hbar .line { grid-column: 2 / 4; display: flex; align-items: center; gap: 8px; }
.hbar .fill { height: 6px; border-radius: 3px; background: var(--bar); min-width: 3px; transition: width .6s var(--ease); }
.hbar .fill.neg { background: var(--neg); }
.hbar .pct { font-size: 12px; color: var(--muted); font-family: var(--mono); }

.merchants { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.merchant {
  border-radius: var(--r-ctl); background: var(--panel-2); padding: 14px; display: grid; gap: 2px; min-width: 0;
  cursor: pointer; border: 0; text-align: left; color: inherit; font: inherit;
  transition: transform .2s var(--ease), background .2s var(--ease);
}
.merchant:hover { transform: translateY(-1px); }
.merchant .mname { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.merchant .mval { font: 500 17px var(--mono); letter-spacing: -0.02em; }
.merchant .mcount { font-size: 12px; color: var(--muted); }
.merchant:first-child { background: var(--accent-soft); }
.merchant:first-child .mval { color: var(--accent); }

.rec { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 12px; padding: 8px 0; }
.rec + .rec { border-top: 1px solid var(--line); }
.rec .rname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.rec .rsub { font-size: 12.5px; color: var(--muted); }
.rec .amt { grid-row: span 2; align-self: center; font-size: 14px; }

.empty { display: grid; justify-items: center; gap: 6px; text-align: center; color: var(--muted); padding: 22px 8px; font-size: 13.5px; }
.empty i.ph { font-size: 26px; color: var(--text-2); }

/* ---------- transactions ---------- */
.tx-head { display: grid; gap: 12px; margin-bottom: 6px; }
.tx-head h2 { margin: 0; }
.filters { display: grid; grid-template-columns: minmax(0, 2fr) repeat(3, minmax(0, 1fr)); gap: 8px; }
.search { position: relative; display: block; }
.search i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { padding-left: 36px; }
.tx-day {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12.5px; color: var(--muted); padding: 18px 8px 6px; font-weight: 500;
}
.tx-day .num { font-size: 12.5px; }
.tx {
  display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 0 12px; align-items: center;
  width: 100%; padding: 9px 8px; border: 0; background: none; color: inherit; font: inherit; text-align: left;
  border-radius: var(--r-ctl); cursor: pointer; transition: background .2s var(--ease);
}
.tx:hover { background: var(--panel-2); }
.tx .ico {
  grid-row: span 2; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: var(--panel-2); color: var(--text-2);
}
.tx:hover .ico { background: var(--panel); }
.tx .m { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; font-size: 14.5px; }
.tx .sub { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .amt { text-align: right; font-weight: 500; font-size: 14.5px; white-space: nowrap; }
.tx .amt2 { text-align: right; color: var(--muted); font-size: 12px; white-space: nowrap; font-family: var(--mono); }
.tx.in .amt { color: var(--accent); }
.tx.in .ico { background: var(--accent-soft); color: var(--accent); }
.tx.declined .m, .tx.declined .amt, .tx.excluded .amt { text-decoration: line-through; color: var(--muted); }
.tag {
  display: inline-block; font-size: 11px; font-weight: 500; padding: 1px 7px; border-radius: 999px;
  background: var(--panel-2); color: var(--text-2); margin-left: 6px; vertical-align: 1px;
}
.tag.warn { color: var(--warn); }

.foot { text-align: center; }

/* ---------- tooltip & toast ---------- */
.tooltip {
  position: fixed; z-index: 30; pointer-events: none; background: var(--text); color: var(--bg);
  padding: 6px 10px; border-radius: 8px; font: 12.5px/1.4 var(--font); white-space: nowrap;
  transform: translate(-50%, calc(-100% - 10px));
}
.tooltip b { font-family: var(--mono); font-weight: 500; }
.toast {
  position: fixed; z-index: 40; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px;
  border-radius: 12px; font-size: 14px; box-shadow: 0 8px 30px rgb(0 0 0 / .18);
}
.toast.err { background: var(--danger); color: #fff; }

/* ---------- dialogs ---------- */
dialog {
  border: 1px solid var(--line); border-radius: 18px; padding: 0; background: var(--panel); color: var(--text);
  width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  box-shadow: 0 24px 80px rgb(0 0 0 / .22);
}
dialog.wide { width: min(660px, calc(100vw - 24px)); }
dialog::backdrop { background: rgb(17 17 17 / .45); backdrop-filter: blur(2px); }
dialog[open] { animation: pop .28s var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.dlg { padding: 22px; display: grid; gap: 16px; }
.dlg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.dlg-head h2 { margin: 0; font-size: 18px; }
.dlg-head .muted { font-size: 13px; margin-top: 2px; }
.dlg-amount { font: 500 20px var(--mono); letter-spacing: -0.02em; white-space: nowrap; }
.dlg pre { white-space: pre-wrap; font: 12.5px/1.5 var(--mono); background: var(--panel-2); padding: 12px; border-radius: var(--r-ctl); margin: 8px 0 0; }
details summary { cursor: pointer; font-size: 13.5px; color: var(--text-2); }
.dlg-actions { display: flex; gap: 8px; align-items: center; padding-top: 4px; }
.spacer { flex: 1; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-inline { display: flex; gap: 8px; flex-wrap: wrap; }
.result { font-size: 14px; padding: 10px 12px; border-radius: var(--r-ctl); background: var(--accent-soft); }
.set-section { display: grid; gap: 10px; padding-top: 16px; border-top: 1px solid var(--line); }
.set-section:first-of-type { border-top: 0; padding-top: 0; }
.cards-list { display: grid; gap: 8px; }
.card-row { display: grid; grid-template-columns: 96px 1fr 1fr; gap: 8px; align-items: center; }
.card-row .cid { font: 13px var(--mono); color: var(--text-2); }
.rule-add { display: grid; grid-template-columns: 1.3fr 1fr auto; gap: 8px; }
.rules-list { display: flex; flex-wrap: wrap; gap: 6px; }
.rule {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 4px 4px 10px; border-radius: 999px;
  background: var(--panel-2); font-size: 13px;
}
.rule code { font: 12.5px var(--mono); }
.rule .arrow { color: var(--muted); }
.rule button { border: 0; background: none; color: var(--muted); cursor: pointer; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; }
.rule button:hover { background: var(--line); color: var(--danger); }
.unparsed-list { display: grid; gap: 8px; }
.un-item { position: relative; background: var(--panel-2); border-radius: var(--r-ctl); padding: 10px 40px 10px 12px; font: 12.5px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; }
.un-item button { position: absolute; top: 6px; right: 6px; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .merchants { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  main { padding: 12px 16px calc(32px + env(safe-area-inset-bottom)); gap: 12px; }
  .top { flex-wrap: wrap; }
  .month { flex: 1; justify-content: space-between; }
  .month h1 { min-width: 0; font-size: 18px; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; }
  .actions #settingsBtn { flex: 0 0 48px; }
  .overview { grid-template-columns: minmax(0, 1fr); grid-template-areas: "head" "stats" "daily"; padding: 18px; gap: 18px; }
  .panel { padding: 16px; }
  .filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filters .search { grid-column: 1 / -1; }
  .balances {
    display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 10px;
    margin: 0 -16px; padding: 0 16px; scroll-padding-inline: 16px; scrollbar-width: none;
  }
  .balances::-webkit-scrollbar { display: none; }
  .bal { flex: 0 0 auto; min-width: 170px; scroll-snap-align: start; }
  .card-row { grid-template-columns: 1fr 1fr; }
  .card-row .cid { grid-column: 1 / -1; }
  .rule-add { grid-template-columns: 1fr 1fr; }
  .rule-add .btn { grid-column: 1 / -1; }
}

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