/* ---------- tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e4e3df;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #8a8984;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e4effc;
  --good: #0ca30c;
  --good-text: #006300;
  --critical: #d03b3b;
  --warning: #fab219;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --grid: #ebeae6;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 4px 16px rgb(0 0 0 / .05);
  --radius: 14px;
  --sidebar: 232px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2c;
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #8d8c85;
    --accent: #3987e5; --accent-soft: #1c2c42;
    --good-text: #4cc44c;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --grid: #2a2a28;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 16px rgb(0 0 0 / .25);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2c;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #8d8c85;
  --accent: #3987e5; --accent-soft: #1c2c42;
  --good-text: #4cc44c;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --grid: #2a2a28;
  --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 16px rgb(0 0 0 / .25);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
h1 { font-size: 26px; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; color: var(--text); }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--good-text); }
.neg { color: var(--critical); }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); flex: none; position: sticky; top: 0; height: 100vh;
  border-right: 1px solid var(--border); background: var(--surface);
  display: flex; flex-direction: column; padding: 20px 14px; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 0 8px; }
.brand.big { font-size: 26px; justify-content: center; margin-bottom: 10px; }
.logo {
  width: 32px; height: 32px; border-radius: 10px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 17px;
}
.brand.big .logo { width: 44px; height: 44px; font-size: 24px; border-radius: 13px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 10px;
  color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.add-desktop { margin-top: 4px; }
.theme-toggle {
  margin-top: auto; align-self: flex-start; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-2); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer;
}
.main { flex: 1; min-width: 0; padding: 28px 32px 60px; max-width: 1280px; }
.fab { display: none; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--text-2); font-size: 14px; margin-top: 2px; }

/* ---------- cards & grid ---------- */
.grid { display: grid; gap: 16px; }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); min-width: 0;
}
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.card-head .link { font-size: 13px; color: var(--accent); cursor: pointer; }
.mt { margin-top: 16px; }

.stat .label { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .delta { font-size: 12.5px; color: var(--text-2); margin-top: 4px; }
.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; flex: none; }

.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 320px; }
.chart-box.short { height: 200px; }

/* ---------- controls ---------- */
.btn {
  font: inherit; font-weight: 550; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: 9px 14px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--critical); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); width: 36px; height: 36px; border-radius: 10px; cursor: pointer; font-size: 18px; display: grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar .grow { flex: 1; min-width: 180px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 11px; width: 100%; min-width: 0;
}
select { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-2); margin-bottom: 14px; }
.field > span { font-weight: 550; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 11px; padding: 3px; gap: 2px; }
.seg button {
  font: inherit; font-size: 14px; font-weight: 550; border: 0; background: transparent; color: var(--text-2);
  padding: 7px 14px; border-radius: 8px; cursor: pointer;
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.seg.full { display: flex; }
.seg.full button { flex: 1; }

.month-nav { display: inline-flex; align-items: center; gap: 6px; }
.month-nav .label { min-width: 140px; text-align: center; font-weight: 600; }

/* ---------- lists ---------- */
.tx-day { padding: 3px 18px; font-size: 11.5px; font-weight: 600; color: var(--text-2); background: var(--surface-2); display: flex; justify-content: space-between; position: sticky; top: 0; }
.tx {
  display: flex; align-items: center; gap: 10px; padding: 5px 18px; min-height: 36px; border-top: 1px solid var(--border); cursor: pointer; font-size: 14px;
}
/* Rows of the same day are separated by a faint line, a new day by a full one. */
.tx-date + .tx-icon { margin-left: -2px; }
#mv-list .tx:not(.new-day) { border-top-color: transparent; }
#mv-list .tx:first-child { border-top: 0; }
.tx-date { width: 58px; flex: none; font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx:hover { background: var(--surface-2); }
.tx-icon { width: 24px; height: 24px; display: grid; place-items: center; font-size: 15px; flex: none; }
/* Title and category on one line: the category shrinks first. */
.tx-main { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.tx-title { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; min-width: 0; }
.tx-sub { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1 1 0; min-width: 0; }
.tx-amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.empty { padding: 40px 20px; text-align: center; color: var(--text-2); }
.more { padding: 14px; text-align: center; }

.bar-list .item { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 7px 0; cursor: pointer; }
.bar-list .name { display: flex; align-items: center; gap: 8px; font-size: 14px; min-width: 0; }
.bar-list .name span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-list .val { font-variant-numeric: tabular-nums; font-size: 14px; font-weight: 550; }
.bar-list .track { grid-column: 1 / -1; height: 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-list .fill { height: 100%; border-radius: 4px; background: var(--accent); }
.bar-list .fill.over { background: var(--critical); }
.bar-list .sub { grid-column: 1 / -1; font-size: 12px; color: var(--text-3); margin-top: -2px; }

/* ---------- pivot table ---------- */
.table-wrap { overflow: auto; max-width: 100%; }
table.pivot { border-collapse: separate; border-spacing: 0; font-size: 13px; width: 100%; font-variant-numeric: tabular-nums; }
.pivot th, .pivot td { padding: 8px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
.pivot th { font-weight: 600; color: var(--text-2); background: var(--surface); position: sticky; top: 0; z-index: 1; font-size: 12px; }
.pivot th.grp-entrata { box-shadow: inset 0 -2px 0 var(--s1); }
.pivot th.grp-spesa { box-shadow: inset 0 -2px 0 var(--s2); }
.pivot td:first-child, .pivot th:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 2; font-weight: 600; }
.pivot tr.total td { font-weight: 650; background: var(--surface-2); }
.pivot tr.total td:first-child { background: var(--surface-2); }
.pivot td.tot { font-weight: 650; background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.pivot td.click { cursor: pointer; }
.pivot td.click:hover { background: var(--accent-soft); }
.pivot td.zero { color: var(--text-3); }
.pivot td.heat { position: relative; }

/* ---------- budget table ---------- */
table.edit { width: 100%; border-collapse: collapse; font-size: 14px; }
.edit th { text-align: left; font-size: 12px; color: var(--text-2); font-weight: 600; padding: 6px; }
.edit td { padding: 3px; }
.edit input { padding: 7px 8px; }
.edit td.r, .edit th.r { text-align: right; }
.edit input.r { text-align: right; }

/* ---------- sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / .35); z-index: 40; animation: fade .15s; }
.sheet {
  position: fixed; z-index: 41; background: var(--surface); color: var(--text);
  left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 48px); overflow: auto; border-radius: 18px; padding: 22px; box-shadow: 0 20px 60px rgb(0 0 0 / .3);
  animation: pop .18s ease-out;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.sheet-head h2 { margin: 0; font-size: 18px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -48%); } }
@keyframes up { from { transform: translateY(100%); } }

.amount-input { position: relative; margin-bottom: 14px; }
.amount-input input {
  font-size: 38px; font-weight: 650; text-align: center; padding: 14px 40px; letter-spacing: -.02em;
  border-radius: 14px; font-variant-numeric: tabular-nums;
}
.amount-input .cur { position: absolute; left: 18px; top: 50%; transform: translateY(-50%); font-size: 24px; color: var(--text-3); }
.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 14px; }
.cat-chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 12px;
  padding: 8px 4px; font: inherit; font-size: 11.5px; cursor: pointer; display: flex; flex-direction: column;
  align-items: center; gap: 3px; line-height: 1.15; min-height: 62px; text-align: center;
}
.cat-chip .ic { font-size: 20px; }
.cat-chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; box-shadow: inset 0 0 0 1px var(--accent); }
.suggest { position: relative; }
.suggest-list {
  position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); z-index: 5; max-height: 220px; overflow: auto;
}
.suggest-list div { padding: 9px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; font-size: 14px; color: var(--text); }
.suggest-list div:hover, .suggest-list div.hl { background: var(--surface-2); }
.suggest-list small { color: var(--text-3); }
.sheet-actions { display: flex; gap: 8px; margin-top: 6px; }
.sheet-actions .btn { flex: 1; padding: 12px; }

/* ---------- misc ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 28px; box-shadow: var(--shadow); }
.error { color: var(--critical); font-size: 13px; min-height: 18px; margin: 10px 0 0; text-align: center; }
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; z-index: 60; font-size: 14px; font-weight: 550; box-shadow: var(--shadow);
  display: flex; gap: 12px; align-items: center;
}
.toast button { background: none; border: 0; color: var(--accent); font: inherit; font-weight: 700; cursor: pointer; padding: 0; }
.banner { background: var(--accent-soft); color: var(--text); border-radius: 12px; padding: 10px 14px; margin-bottom: 16px; font-size: 14px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--text-2); margin-bottom: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend i.line { height: 3px; border-radius: 2px; width: 14px; }
.legend i.dash { height: 0; border-top: 2px dashed var(--text-3); width: 14px; border-radius: 0; }
.settings-list .it { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.settings-list .it:first-child { border-top: 0; }
.settings-list .it .grow { flex: 1; min-width: 0; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.kv { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; border-top: 1px solid var(--border); }
.kv:first-child { border-top: 0; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button { font: inherit; font-size: 14px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); padding: 7px 14px; border-radius: 999px; cursor: pointer; }
.tabs button.on { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-3-1 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  body { font-size: 15px; }
  .shell { flex-direction: column; }
  .sidebar {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; width: auto; height: auto; z-index: 30;
    flex-direction: row; padding: 4px 6px calc(4px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  }
  .sidebar .brand, .add-desktop, .theme-toggle { display: none; }
  .nav { flex-direction: row; flex: 1; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 2px; font-size: 10.5px; padding: 6px 4px; flex: 1; align-items: center; }
  .nav a.active, .nav a:hover { background: transparent; }
  .nav a:hover:not(.active) { color: var(--text-2); }
  table.edit .hide-sm { display: none; }
  table.edit { font-size: 13px; }
  .nav a[data-view="impostazioni"] span { font-size: 0; }
  .nav a[data-view="impostazioni"] span::after { content: "Altro"; font-size: 10.5px; }
  .main { padding: calc(16px + env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom)); }
  h1 { font-size: 22px; }
  .cols-2 { grid-template-columns: minmax(0, 1fr); }
  .cols-4 { gap: 10px; }
  .card { padding: 14px; }
  .stat .value { font-size: 20px; }
  .fab {
    display: grid; place-items: center; position: fixed; right: 18px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 31;
    width: 58px; height: 58px; border-radius: 18px; border: 0; background: var(--accent); color: var(--accent-ink);
    font-size: 28px; box-shadow: 0 8px 24px rgb(42 120 214 / .45); cursor: pointer;
  }
  .sheet {
    left: 0; right: 0; top: auto; bottom: 0; transform: none; width: auto; border-radius: 20px 20px 0 0;
    max-height: 92vh; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); animation: up .22s ease-out;
  }
  .tx { padding: 5px 12px; }
  .tx-date { width: 46px; font-size: 11.5px; }
  /* Filters: one horizontally scrolling row instead of four wrapped lines. */
  .toolbar { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px 12px; padding: 0 16px 2px; scrollbar-width: none; }
  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar > * { flex: none; }
  .toolbar .grow { min-width: 170px; }
  .toolbar select, .toolbar input { padding: 7px 9px; }
  /* iOS Safari zooms into any field under 16px and stays zoomed: keep every field at 16px. */
  input, select, textarea { font-size: 16px; }
  .hide-sm { display: none !important; }
  .tx-day { padding: 3px 12px; }
  .chart-box { height: 220px; }
  .chart-box.tall { height: 260px; }
  .month-nav .label { min-width: 110px; }
  .toast { bottom: calc(150px + env(safe-area-inset-bottom)); }
  .amount-input input { font-size: 34px; }
}

/* Movimenti summary: keep each "label amount" pair together when the line wraps */
#mv-sum span, #mv-cur span, #mv-sum b, #mv-cur b { white-space: nowrap; }

/* Recurring movements */
.rec { color: var(--text-3); font-weight: 400; font-size: 12px; }
.rec-actions { display: flex; gap: 6px; flex: none; }
.hint { font-size: 12.5px; color: var(--text-2); background: var(--surface-2); border-radius: 10px; padding: 8px 10px; margin: 0 0 12px; }
#rec-list .tx .pill { flex: none; }
.sg-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--border); }
.sg-row input[type=checkbox] { width: auto; flex: none; }
.sg-row .sg-amt { width: 84px; flex: none; text-align: right; padding: 6px 8px; }
.sg-row select { flex: none; padding: 6px; font-size: 13px; }
@media (max-width: 760px) {
  #rec-list .tx .pill { display: none; }
  .sg-row { flex-wrap: wrap; }
  .sg-row .tx-main { flex: 1 1 calc(100% - 30px); }
  .sg-row .sg-amt { margin-left: 26px; }
}
.kv .num span { white-space: nowrap; }

.rec-box { display: flex; align-items: center; gap: 10px; border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; margin-bottom: 14px; }
.rec-box .rec-ic { font-size: 20px; color: var(--accent); flex: none; }
.rec-box .grow { flex: 1; min-width: 0; }
.rec-box b { display: block; font-size: 14px; }
.rec-box small { color: var(--text-2); font-size: 12.5px; line-height: 1.35; }
.mk-rec { margin: -4px 0 12px; padding-left: 0; color: var(--accent); }

/* Inline entry row (Movimenti → ＋ Riga) */
.new-row {
  display: grid; grid-template-columns: 150px minmax(0, 2fr) minmax(0, 1.4fr) 90px 120px auto auto; gap: 8px;
  align-items: center; padding: 10px 12px; margin-bottom: 12px; border-color: var(--accent);
}
.new-row input, .new-row select { padding: 8px 9px; width: 100%; }
.new-row [data-f="amount"] { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.new-row [data-f="amount"].in { color: var(--good-text); }
.new-row [data-f="amount"].out { color: var(--critical); }
.new-row .btn { padding: 8px 12px; }
.nr-hint { grid-column: 1 / -1; font-size: 12px; color: var(--text-3); }
.tx.flash { background: var(--accent-soft); transition: background .3s; }
@media (max-width: 1180px) and (min-width: 761px) {
  .new-row { grid-template-columns: 150px 90px minmax(0, 1fr) auto auto; }
  .new-row [data-f="note"] { grid-column: 1 / 3; grid-row: 1; }
  .new-row [data-f="cat"] { grid-column: 3 / 6; grid-row: 1; }
  .new-row [data-f="date"] { grid-column: 1; grid-row: 2; }
  .new-row [data-f="acc"] { grid-column: 2; grid-row: 2; }
  .new-row [data-f="amount"] { grid-column: 3; grid-row: 2; }
}
@media (max-width: 760px) {
  .new-row { grid-template-columns: 1fr 1fr auto; }
  .new-row [data-f="note"] { grid-column: 1 / -1; grid-row: 1; }
  .new-row [data-f="cat"] { grid-column: 1 / 3; grid-row: 2; }
  .new-row [data-f="close"] { grid-column: 3; grid-row: 2; }
  .new-row [data-f="date"] { grid-column: 1; grid-row: 3; }
  .new-row [data-f="acc"] { grid-column: 2; grid-row: 3; }
  .new-row [data-f="amount"] { grid-column: 1 / 3; grid-row: 4; }
  .new-row [data-f="save"] { grid-column: 3; grid-row: 3 / 5; align-self: stretch; }
  .nr-hint { display: none; }
}

/* iPhone: Safari draws date fields with its own (taller/centred) style and ignores padding.
   Drop the native look and give every field the same height. */
@media (max-width: 760px) {
  input:not([type="checkbox"]):not([type="file"]), select { height: 44px; line-height: normal; }
  .amount-input #tx-amount { height: auto; }
  input[type="date"] { -webkit-appearance: none; appearance: none; display: block; text-align: left; background-color: var(--surface); }
  input[type="date"]::-webkit-date-and-time-value { text-align: left; margin: 0; }
  input[type="date"]::-webkit-datetime-edit { padding: 0; }
  .new-row input:not([type="checkbox"]), .new-row select { height: 42px; }
  .new-row [data-f="save"] { height: auto; }
}

/* Income amounts in lists: a brighter green than --good-text, which reads as black at small bold sizes */
:root { --in-amt: #16a34a; }
:root[data-theme="dark"] { --in-amt: #4cc44c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --in-amt: #4cc44c; } }
.tx-amt.pos { color: var(--in-amt); }

/* Refresh: sidebar button on desktop, small round button top-right on phones */
.theme-toggle svg { width: 14px; height: 14px; vertical-align: -2px; }
.theme-toggle[data-action="refresh"] { margin-top: auto; }
.theme-toggle[data-action="refresh"] + .theme-toggle { margin-top: 0; }
.sidebar .theme-toggle { display: inline-flex; align-items: center; gap: 6px; }
.refresh-btn { display: none; }
.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 760px) {
  .refresh-btn {
    display: grid; place-items: center; position: fixed; z-index: 32; top: calc(env(safe-area-inset-top) + 10px); right: 12px;
    width: 38px; height: 38px; border-radius: 12px; border: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 90%, transparent); color: var(--text-2);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); cursor: pointer;
  }
  .refresh-btn svg { width: 18px; height: 18px; }
  .sidebar .theme-toggle { display: none; }
  .page-head { padding-right: 46px; }
}
.toast span { white-space: nowrap; }

/* Users */
.who { padding: 0 8px; display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; }
.who select { width: 100%; padding: 6px 8px; font-size: 13px; }
.banner.viewing { background: color-mix(in srgb, var(--warning) 22%, var(--surface)); border: 1px solid var(--warning); }
.banner .btn { margin-left: 6px; }
@media (max-width: 760px) { .who { display: none; } }
.sidebar .theme-toggle:not([data-action="refresh"]) { margin-top: 0; }
