/* Soldi — design system + layout. Light and dark, mobile-first. */

:root {
  --bg: #f5f6fb;
  --bg-elev: #ffffff;
  --bg-sunken: #eef0f7;
  --ink: #1c2030;
  --ink-soft: #5b6478;
  --ink-faint: #8a92a6;
  --line: #e2e5f0;
  --brand: #5566ff;
  --brand-ink: #ffffff;
  --accent: #12b886;
  --expense: #e8546b;
  --income: #12b886;
  --warn: #f08c00;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 24, 40, 0.04), 0 12px 32px rgba(20, 24, 40, 0.08);
  --shadow-sm: 0 1px 3px rgba(20, 24, 40, 0.08);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --maxw: 1080px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1220;
    --bg-elev: #171a2b;
    --bg-sunken: #1e2236;
    --ink: #eef0f7;
    --ink-soft: #aab2c8;
    --ink-faint: #7b839a;
    --line: #282d44;
    --brand: #7c8dff;
    --accent: #2dd4a7;
    --expense: #ff6b83;
    --income: #2dd4a7;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 16px 40px rgba(0, 0, 0, 0.45);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  width: 100%;
  overflow-x: hidden; /* never allow sideways panning on a phone */
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- Boot / loading ---------- */
.boot {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-content: center;
  gap: 14px;
  justify-items: center;
  color: var(--ink-soft);
}
.boot-mark {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- App shell ---------- */
.shell {
  display: grid;
  grid-template-columns: 244px 1fr;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 100%;
  overflow-x: hidden;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  padding: calc(22px + env(safe-area-inset-top)) 16px 22px;
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 6px 10px 18px;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.brand svg { width: 30px; height: 30px; flex: none; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  text-decoration: none;
  font-weight: 550;
  font-size: 0.94rem;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-link svg { width: 20px; height: 20px; flex: none; }
.nav-link:hover { background: var(--bg-sunken); color: var(--ink); }
.nav-link.active { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); }
.nav-spacer { flex: 1; }

.main {
  padding: 28px clamp(16px, 4vw, 40px) 120px;
  padding-left: max(clamp(16px, 4vw, 40px), env(safe-area-inset-left));
  padding-right: max(clamp(16px, 4vw, 40px), env(safe-area-inset-right));
  max-width: var(--maxw);
  width: 100%;
  min-width: 0;
  margin: 0 auto;
  overflow-x: hidden;
}


.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.page-head > div:first-child { min-width: 0; flex: 1 1 auto; }
.page-head h1 { font-size: 1.6rem; letter-spacing: -0.02em; }
.page-head p { color: var(--ink-faint); font-size: 0.9rem; }
.page-head .btn { flex: none; white-space: nowrap; }
.page-head > div:last-child { flex: none; }
@media (max-width: 560px) {
  .page-head { align-items: center; }
  .page-head h1 { font-size: 1.3rem; }
  .page-head p { font-size: 0.82rem; }
  .page-head .btn { padding: 9px 12px; }
}

/* ---------- Bottom nav (mobile) ---------- */
.tabbar { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main {
    padding-top: calc(20px + env(safe-area-inset-top));
    padding-bottom: 96px;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  .tabbar {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    background: color-mix(in srgb, var(--bg-elev) 94%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    padding: 8px max(2px, env(safe-area-inset-left)) calc(8px + env(safe-area-inset-bottom)) max(2px, env(safe-area-inset-right));
    z-index: 40;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabbar::-webkit-scrollbar { display: none; }
  .tabbar button {
    flex: 1 0 auto;
    min-width: 14.2vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    background: none;
    border: none;
    padding: 6px 2px;
    color: var(--ink-faint);
    font-size: 0.62rem;
    font-weight: 600;
  }
  .tabbar button span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .tabbar button svg { width: 21px; height: 21px; }
  .tabbar button.active { color: var(--brand); }
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 18px; }

.grid { display: grid; gap: 16px; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 720px) {
  .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
}

/* ---------- Dashboard hero ---------- */
.dash-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
@media (max-width: 640px) {
  .dash-controls { flex-direction: column; align-items: stretch; gap: 10px; }
  .dash-controls .scope-seg { align-self: center; }
  .dash-controls .period-nav { justify-content: center; }
}
.hero {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  padding: 22px;
  color: #fff;
  background: linear-gradient(135deg, #6c8cff 0%, #12b886 100%);
  box-shadow: 0 12px 30px color-mix(in srgb, var(--brand) 30%, transparent);
}
.hero.neg { background: linear-gradient(135deg, #f0617f 0%, #f4a259 100%); box-shadow: 0 12px 30px color-mix(in srgb, var(--expense) 32%, transparent); }
.hero-bg { position: absolute; inset: auto -30px -50px auto; width: 260px; height: 260px; opacity: 0.18; }
.hero-bg svg { width: 100%; height: 100%; stroke-width: 1.1; }
.hero-label { font-size: 0.8rem; font-weight: 600; opacity: 0.9; letter-spacing: 0.03em; text-transform: uppercase; }
.hero-value { display: block; font-size: 2.4rem; font-weight: 800; letter-spacing: -0.03em; margin: 4px 0 14px; }
.hero-chips { display: flex; gap: 10px; flex-wrap: wrap; position: relative; }
.hero-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 650;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(4px);
}
.hero-chip svg { width: 14px; height: 14px; }

/* ---------- Stat cards ---------- */
.stat {
  padding: 18px;
  display: grid;
  gap: 6px;
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
}
.stat.income { background: linear-gradient(160deg, color-mix(in srgb, var(--income) 12%, var(--bg-elev)), var(--bg-elev) 70%); border-color: color-mix(in srgb, var(--income) 22%, var(--line)); }
.stat.expense { background: linear-gradient(160deg, color-mix(in srgb, var(--expense) 12%, var(--bg-elev)), var(--bg-elev) 70%); border-color: color-mix(in srgb, var(--expense) 22%, var(--line)); }
.stat-head { display: flex; align-items: center; gap: 8px; }
.stat-ico { width: 26px; height: 26px; border-radius: 8px; display: grid; place-content: center; flex: none; color: #fff; }
.stat-ico svg { width: 15px; height: 15px; }
.stat.income .stat-ico { background: var(--income); }
.stat.expense .stat-ico { background: var(--expense); }
.stat .label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  font-weight: 650;
}
.stat .value { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; }
.stat .sub { font-size: 0.82rem; color: var(--ink-faint); }
.stat.income .value { color: var(--income); }
.stat.expense .value { color: var(--expense); }
.stat .spark { position: absolute; right: 0; bottom: 0; opacity: 0.55; pointer-events: none; }
@media (max-width: 720px) { .stat .spark { display: none; } }

/* ---------- Segmented control ---------- */
.segment {
  display: inline-flex;
  background: var(--bg-sunken);
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
}
.segment button {
  border: none;
  background: none;
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink-soft);
}
.segment button.active {
  background: var(--bg-elev);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.segment button svg { width: 14px; height: 14px; vertical-align: -2px; margin-right: 5px; }
.scope-seg { display: flex; }

/* Scope badge on transaction rows */
.scope-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px 1px 5px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  vertical-align: 1px;
  border: 1px solid transparent;
}
.scope-badge svg { width: 11px; height: 11px; }
.scope-badge.personal { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); }
.scope-badge.home { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.scope-badge.fissa { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }

/* Dashboard KPI card: Personale / Casa sub-line */
.stat-split { display: flex; gap: 14px; }
.stat-split span { display: inline-flex; align-items: center; gap: 4px; }
.stat-split svg { width: 12px; height: 12px; opacity: 0.8; }

/* Toggle switch (Personale / Casa) */
.switch-row { display: flex; align-items: center; gap: 12px; padding: 4px 0; }
.switch-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink-faint);
}
.switch-label svg { width: 15px; height: 15px; }
.switch-label.on { color: var(--ink); }
.switch { position: relative; width: 46px; height: 26px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--brand);
  transition: background 0.15s;
}
.switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 30%, transparent); }

/* Category select with inline "+ new category" */
.with-add { display: flex; gap: 8px; align-items: center; }
.with-add select { flex: 1; min-width: 0; }
.with-add .qc-add { flex: none; }
.quick-cat {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 8px;
  padding: 8px;
  background: var(--bg-sunken);
  border-radius: var(--radius-sm);
}
.quick-cat .qc-name { flex: 1 1 160px; min-width: 0; }
.quick-cat input[type="color"] { width: 44px; height: 40px; padding: 3px; flex: none; }
.quick-cat .qc-save { flex: none; padding: 10px 16px; }

/* Budget progress bar (Previsioni) */
.budget-bar {
  height: 7px;
  border-radius: 999px;
  background: var(--bg-sunken);
  overflow: hidden;
  margin-top: 6px;
  max-width: 260px;
}
.budget-bar span { display: block; height: 100%; border-radius: 999px; }

/* Personale vs Casa proportion bar */
.split-bar {
  display: flex;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-sunken);
}
.split-bar span { display: block; height: 100%; }

.period-nav { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.period-nav .range { font-weight: 600; font-size: 0.95rem; min-width: 190px; text-align: center; }
.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-content: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ink-soft);
}
.icon-btn:hover { color: var(--ink); border-color: var(--ink-faint); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-elev);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink);
}
.btn:hover { border-color: var(--ink-faint); }
.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: none; border-color: transparent; color: var(--ink-soft); }
.btn.danger { color: var(--expense); border-color: color-mix(in srgb, var(--expense) 40%, var(--line)); background: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn svg { width: 17px; height: 17px; }

/* ---------- Charts ---------- */
.chart-card h3 {
  font-size: 1rem;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chart-card h3::before {
  content: "";
  width: 4px;
  height: 16px;
  border-radius: 2px;
  background: linear-gradient(var(--brand), var(--accent));
  flex: none;
}
.chart-card .hint { color: var(--ink-faint); font-size: 0.82rem; margin-bottom: 12px; }
.donut-wrap { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.donut-wrap svg { flex: none; max-width: 100%; height: auto; }
.legend { display: grid; gap: 8px; flex: 1 1 150px; min-width: 0; }
.legend .row { min-width: 0; flex-wrap: wrap; }
.legend .amt { flex: none; }
.legend .row { display: flex; align-items: center; gap: 10px; font-size: 0.88rem; }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend .amt { margin-left: auto; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.bars { display: block; width: 100%; max-width: 100%; height: auto; overflow: hidden; }

/* ---------- Transaction list ---------- */
.tx-day { margin-top: 20px; }
.tx-day-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0 4px 8px;
  color: var(--ink-faint);
  font-size: 0.82rem;
  font-weight: 600;
}
.tx {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
}
.tx:last-child { border-bottom: none; }
.tx:hover { background: var(--bg-sunken); }
.tx .swatch {
  width: 38px; height: 38px;
  border-radius: 11px;
  display: grid; place-content: center;
  font-size: 0.9rem; font-weight: 700;
  color: #fff;
  flex: none;
}
.tx .meta { min-width: 0; flex: 1; }
.tx .meta .name { font-weight: 600; font-size: 0.94rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .meta .cat { color: var(--ink-faint); font-size: 0.8rem; }
.tx .amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx .amount.expense { color: var(--expense); }
.tx .amount.income { color: var(--income); }
.tx .row-actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.12s; }
.tx:hover .row-actions, .tx:focus-within .row-actions { opacity: 1; }
@media (max-width: 860px) { .tx .row-actions { opacity: 1; } }

/* ---------- Forms ---------- */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 0.83rem; font-weight: 600; color: var(--ink-soft); }
.field input, .field select, .field textarea {
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg);
  outline: none;
  font-size: 16px; /* iOS: <16px triggers auto-zoom on focus */
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent);
}
.field .error { color: var(--expense); font-size: 0.8rem; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
@media (max-width: 560px) { .row-2 { grid-template-columns: 1fr; } }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 12, 22, 0.5);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 60;
}
.modal {
  width: min(460px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  max-height: 90dvh;
  overflow: auto;
}
.modal h2 { font-size: 1.2rem; margin-bottom: 16px; letter-spacing: -0.01em; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- Auth ---------- */
.auth {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(20px + env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
           calc(20px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  position: relative;
  overflow: hidden;
}
.auth .blob { position: absolute; filter: blur(60px); opacity: 0.5; z-index: 0; }
.auth-card {
  position: relative;
  z-index: 1;
  width: min(400px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 30px 26px;
}
.auth-card .brand { justify-content: center; padding: 4px 0 8px; font-size: 1.3rem; }
.auth-card .tagline { text-align: center; color: var(--ink-faint); font-size: 0.9rem; margin-bottom: 22px; }
.auth-tabs { display: flex; gap: 4px; background: var(--bg-sunken); border-radius: 999px; padding: 4px; margin-bottom: 20px; }
.auth-tabs button { flex: 1; border: none; background: none; padding: 9px; border-radius: 999px; font-weight: 600; font-size: 0.9rem; color: var(--ink-soft); }
.auth-tabs button.active { background: var(--bg-elev); color: var(--ink); box-shadow: var(--shadow-sm); }

/* ---------- Misc ---------- */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--ink-faint);
  display: grid;
  gap: 12px;
  justify-items: center;
}
.empty svg { width: 120px; height: auto; opacity: 0.9; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  background: var(--bg-sunken);
  color: var(--ink-soft);
}
.kv {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.92rem;
}
.kv span:first-child { color: var(--ink-faint); }

.section-title {
  font-size: 1.05rem;
  margin: 26px 0 12px;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 9px;
}
.section-title::before {
  content: "";
  width: 4px;
  height: 18px;
  border-radius: 2px;
  background: linear-gradient(var(--brand), var(--accent));
  flex: none;
}
.muted { color: var(--ink-faint); }
.mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; font-size: 0.85em; }
code.block {
  display: block;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 8px 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: var(--bg-elev);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 80;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--expense); color: #fff; }

.list-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select {
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-elev);
  font-size: 16px;
}

.cat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.cat-row:last-child { border-bottom: none; }
.cat-row .dot { width: 14px; height: 14px; border-radius: 5px; flex: none; }
.cat-row .name { font-weight: 600; }
.cat-row > .meta { flex: 1 1 auto; min-width: 0; }
.cat-row .count { color: var(--ink-faint); font-size: 0.82rem; margin-left: auto; }
.cat-row .meta .cat { color: var(--ink-faint); font-size: 0.8rem; }
.cat-row .amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cat-row .amount.expense { color: var(--expense); }
.cat-row .amount.income { color: var(--income); }
.cat-row .switch, .cat-row .icon-btn { flex: none; }
.cat-row .meta .name { overflow-wrap: anywhere; }
/* trailing controls (amount + toggle + edit/delete) — wrap under the text on phones */
.cat-row .row-tail { display: flex; align-items: center; gap: 8px; flex: none; margin-left: auto; }
.cat-row .row-tail .count { margin-left: 0; }
@media (max-width: 560px) {
  .cat-row { flex-wrap: wrap; row-gap: 10px; }
  .cat-row > .meta { flex-basis: calc(100% - 26px); }
  .cat-row .row-tail { flex-basis: 100%; justify-content: flex-end; margin-left: 0; }
}
.cat-row .amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cat-row .amount.expense { color: var(--expense); }
.cat-row .amount.income { color: var(--income); }
.cat-row.is-off { opacity: 0.5; }
.cat-row.is-off .amount { color: var(--ink-faint); }
.cat-row .switch { width: 42px; height: 24px; }
.cat-row .switch-track::after { width: 18px; height: 18px; }
.cat-row .switch input:checked + .switch-track::after { transform: translateX(18px); }

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(78px + env(safe-area-inset-bottom));
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  border: none;
  box-shadow: var(--shadow);
  display: none;
  place-content: center;
  z-index: 45;
}
.fab svg { width: 24px; height: 24px; }
@media (max-width: 860px) { .fab { display: grid; } }
