/* ==========================================================================
   Ledger — wallets, operations, the month overview, history, debts.
   Mobile first: the phone is where operations are entered, several times a
   day. Built on the platform tokens in style.css; class prefixes:
   bnav- bottom bar · ops- operation sheet · opf- operation feed · lt- line
   tile · wt-/wr- wallet tile/row · wal- wallets pages · ov- overview ·
   hist- history · rec- reconciliation · wedit- wallet form
   ========================================================================== */

:root {
  /* Wallet colours: a wallet wears one, as its card did in CoinKeeper. Most
     are the validated data hues; gold, slate and white are the three a bank
     card needs that the data palette does not have. */
  --wallet-red: var(--data-8);
  --wallet-orange: var(--data-3);
  --wallet-amber: var(--data-1);
  --wallet-gold: #B8933A;
  --wallet-green: #3C9A5F;
  --wallet-teal: var(--data-2);
  --wallet-blue: var(--data-4);
  --wallet-indigo: #4F4A8C;
  --wallet-slate: #7D8E9C;
  --wallet-white: #E9E7E2;
  --wallet-pink: #D64A7E;
  --wallet-navy: #2D4C8C;
  --wallet-graphite: #3B3E44;
  --wallet-ink: #FFFFFF;
  --wallet-ink-light: #2B2724;

  --bnav-h: 60px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --wallet-gold: #C7A24A;
    --wallet-green: #3FA968;
    --wallet-indigo: #6D66B8;
    --wallet-slate: #8A9BA8;
    --wallet-white: #D9D6D0;
    --wallet-pink: #E0648F;
    --wallet-navy: #4A67A8;
    --wallet-graphite: #50545B;
  }
}
html[data-theme="dark"] {
  --wallet-gold: #C7A24A;
  --wallet-green: #3FA968;
  --wallet-indigo: #6D66B8;
  --wallet-slate: #8A9BA8;
  --wallet-white: #D9D6D0;
  --wallet-pink: #E0648F;
  --wallet-navy: #4A67A8;
  --wallet-graphite: #50545B;
}

.wc-red { --wc: var(--wallet-red); }
.wc-orange { --wc: var(--wallet-orange); }
.wc-amber { --wc: var(--wallet-amber); --wci: var(--wallet-ink-light); }
.wc-gold { --wc: var(--wallet-gold); }
.wc-green { --wc: var(--wallet-green); }
.wc-teal { --wc: var(--wallet-teal); }
.wc-blue { --wc: var(--wallet-blue); }
.wc-indigo { --wc: var(--wallet-indigo); }
.wc-slate { --wc: var(--wallet-slate); }
.wc-white { --wc: var(--wallet-white); --wci: var(--wallet-ink-light); }
.wc-pink { --wc: var(--wallet-pink); }
.wc-navy { --wc: var(--wallet-navy); }
.wc-graphite { --wc: var(--wallet-graphite); }

/* ---------- glyphs ----------
   Three shapes, each saying what a thing is:
   - a wallet is a card: its own colour, a soft sheen, the one bright thing
     on a screen;
   - a budget line is a circle with a thin ring of the plan spent;
   - anything else (an operation, a person, a key) is a quiet circle.
   Icons are ink on a neutral ground; colour is kept for meaning. */

.wt-disc {
  --size: 44px;
  flex: none;
  width: calc(var(--size) * 1.32);
  height: calc(var(--size) * 0.9);
  border-radius: calc(var(--size) * 0.2);
  display: inline-grid;
  place-items: center;
  background:
    linear-gradient(155deg, rgba(255, 255, 255, 0.22) 0%, rgba(255, 255, 255, 0) 46%),
    linear-gradient(180deg, var(--wc, var(--wallet-slate)), color-mix(in oklab, var(--wc, var(--wallet-slate)), #000 14%));
  color: var(--wci, var(--wallet-ink));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.16),
    0 1px 1px rgba(28, 25, 23, 0.10),
    0 4px 10px -6px color-mix(in oklab, var(--wc, var(--wallet-slate)), #000 30%);
}
.wt-disc svg { width: calc(var(--size) * 0.42); height: calc(var(--size) * 0.42); stroke-width: 1.75; }
/* No wallet: an empty card slot. */
.wt-disc.is-ghost { background: none; box-shadow: none; border: 1.5px dashed var(--border-strong); color: var(--text-tertiary); }

.glyph {
  --size: 40px;
  flex: none;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  background: var(--bg-secondary);
  color: var(--text-primary);
}
.glyph svg { width: calc(var(--size) * 0.46); height: calc(var(--size) * 0.46); stroke-width: 1.75; }
.glyph.is-profit { color: var(--profit); }
.glyph.is-loss { color: var(--loss); }

/* A budget line: its icon inside a thin ring of the plan spent. Over the
   plan the ring is red, within it green, no plan no ring — the state,
   never the category. */
.lt-disc {
  --ring: var(--text-tertiary);
  --track: var(--border);
  position: relative;
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
/* The ring is its own layer, masked to a 2.5px band with air inside it, so
   it sits on any tile background. */
.lt-disc::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(var(--ring) calc(var(--p, 0) * 1%), var(--track) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2.5px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2.5px));
}
.lt-disc::before {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: color-mix(in oklab, var(--ring) 18%, var(--bg-card));
}
.lt-disc svg { position: relative; width: 22px; height: 22px; color: var(--ring); stroke-width: 2; }
.lt-disc.is-ok { --ring: var(--profit); }
.lt-disc.is-over { --ring: var(--loss); --p: 100; }
.lt-disc.is-under { --ring: var(--info); }
/* No plan: the line's own blue, as CoinKeeper paints a category. */
.lt-disc.is-none { --ring: var(--info); --track: transparent; --p: 0; }
.lt-add .lt-disc { border: 1.5px dashed var(--border-strong); }
.lt-add .lt-disc::before, .lt-add .lt-disc::after { display: none; }
.lt-add .lt-disc svg { color: var(--text-tertiary); }

/* ---------- tiles (overview grids and the sheet) ---------- */

.lt, .wt {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: var(--sp-2) 2px var(--sp-3);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-primary);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--dur-fast);
}
.lt:hover, .wt:hover { background: var(--bg-secondary); color: var(--text-primary); }
.lt:focus-visible, .wt:focus-visible { outline: none; box-shadow: var(--ring-focus); }
.lt .lt-disc, .lt .wt-disc { margin-bottom: var(--sp-1); }
.lt-name, .wt-name {
  font-size: 12.5px;
  line-height: 1.25;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: break-word;
  hyphens: auto;
  -webkit-hyphens: auto;
  /* Hyphenate only long words: «ПБ: Долла-ры» read as a typo. */
  hyphenate-limit-chars: 10 4 4;
  -webkit-hyphenate-limit-before: 4;
  -webkit-hyphenate-limit-after: 4;
  max-width: 100%;
  min-height: 2.5em;
}
.lt-fact, .wt-balance {
  font-size: 14px;
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.lt-fact.is-over, .wt-balance.is-neg { color: var(--loss); }
.lt-plan { font-size: var(--fs-2xs); color: var(--text-tertiary); white-space: nowrap; font-variant-numeric: tabular-nums; }
.wt-balance { color: var(--text-primary); }

/* ---------- operation feed ---------- */

.opf { padding: 0; overflow: hidden; }
.opf-day + .opf-day { border-top: 1px solid var(--border); }
.opf-day-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0;
  padding: var(--sp-3) var(--sp-4) var(--sp-1);
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--text-secondary);
}
.opf-day-sum { font-variant-numeric: tabular-nums; letter-spacing: 0; text-transform: none; }
.opf-list { list-style: none; margin: 0; padding: 0; }
.opf-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--sp-3);
  padding: 10px var(--sp-4);
  color: var(--text-primary);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--dur-fast);
}
.opf-row:hover, .opf-row:focus-visible { background: var(--bg-secondary); color: var(--text-primary); outline: none; }
.opf-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--bg-secondary);
  color: var(--text-primary);
}
.opf-icon svg { width: 19px; height: 19px; }
.opf-icon.is-expense { background: color-mix(in oklab, var(--info) 16%, var(--bg-card)); color: var(--info); }
.opf-icon.is-income { background: var(--profit-bg); color: var(--profit); }
.opf-icon.is-move { background: var(--info-bg); color: var(--info); }
.opf-icon.is-debt { background: var(--warn-bg); color: var(--warn); }
.opf-main { display: flex; flex-direction: column; min-width: 0; }
.opf-title {
  font-size: 15px;
  font-weight: var(--fw-medium);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.opf-arrow { font-style: normal; color: var(--text-tertiary); margin: 0 6px; }
.opf-sub {
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.opf-amount { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.opf-figure { font-size: 15px; font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; white-space: nowrap; }
.opf-amount.is-income .opf-figure { color: var(--profit); }
.opf-amount.is-move .opf-figure { color: var(--text-secondary); }
.opf-second { font-size: var(--fs-xs); color: var(--text-tertiary); white-space: nowrap; font-variant-numeric: tabular-nums; }
.opf-more {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-4);
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: var(--fs-sm);
}
.opf-more-spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: opsSpin 0.8s linear infinite;
}
.opf-row.is-fresh { animation: opsFresh 1.6s var(--ease-out); }

/* ---------- wallets ---------- */

.wal-hero { margin-bottom: var(--sp-4); }
.wal-month { color: inherit; text-decoration: none; }
.wal-month:hover { color: inherit; box-shadow: var(--shadow-md); }
.wal-progress { margin-block: var(--sp-3) var(--sp-2); }
.progress-fill.is-over { background: var(--loss); }
/* The quick actions are one toolbar, not three cards: a single surface
   split by hairlines, the verb in ink and the sign in its colour. */
.wal-quick {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  margin-bottom: var(--gap-section);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  overflow: hidden;
}
.wal-quick-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 52px;
  padding: 0 var(--sp-3);
  border: 0;
  background: transparent;
  color: var(--text-primary);
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--dur-fast);
}
.wal-quick-btn + .wal-quick-btn { border-left: 1px solid var(--border); }
.wal-quick-btn:hover { background: var(--bg-secondary); }
.wal-quick-btn:active { background: var(--bg-secondary); }
.wal-quick-btn:focus-visible { outline: none; box-shadow: inset var(--ring-focus); }
.wal-quick-btn svg { width: 20px; height: 20px; stroke-width: 1.75; color: var(--text-secondary); }
.wal-quick-btn.is-expense svg { color: var(--loss); }
.wal-quick-btn.is-income svg { color: var(--profit); }
.wal-quick-btn.is-move svg { color: var(--info); }

.wal-columns { display: grid; grid-template-columns: 1fr; gap: var(--gap-section); }
@media (min-width: 1000px) { .wal-columns { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); align-items: start; } }
.wal-section + .wal-section { margin-top: var(--sp-6); }
.wal-section-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sp-3);
  margin-block: 0 var(--sp-3);
  font-family: var(--font-sans);
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
}
.wal-section-title span { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.wal-section-title a { font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.wal-list { padding: var(--sp-1) 0; }
.wr-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--sp-3);
  padding: 10px var(--sp-4);
  color: var(--text-primary);
  text-decoration: none;
  transition: background var(--dur-fast);
}
.wr-row + .wr-row { border-top: 1px solid var(--border); }
.wr-row:hover { background: var(--bg-secondary); color: var(--text-primary); }
.wr-row .wt-disc { --size: 38px; }
.wr-name { font-size: var(--fs-md); font-weight: var(--fw-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wr-name small { display: block; font-size: var(--fs-xs); font-weight: var(--fw-normal); color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; }
/* The side nobody is on reads as empty, not as a figure. */
.ov-sum-cell.is-none .ov-sum-value { color: var(--text-tertiary); }
.wr-balance {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.wr-balance.is-neg { color: var(--loss); }
.wr-balance small { font-size: var(--fs-xs); font-weight: var(--fw-regular); color: var(--text-tertiary); }
a.card-panel.wal-debts {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-top: var(--sp-5);
  padding: var(--sp-3) var(--sp-4);
  color: inherit;
  text-decoration: none;
}
.wal-debts:hover { color: inherit; background: var(--bg-secondary); }
.wal-debts-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.wal-debts-text b { font-weight: var(--fw-semibold); }
.wal-debts-text small { font-size: var(--fs-sm); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.wal-debts-go { width: 18px; height: 18px; color: var(--text-tertiary); flex: none; }
.wal-archived { margin-top: var(--sp-3); font-size: var(--fs-xs); color: var(--text-secondary); }

.wal-one-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.wal-one-bar .page-back { margin: 0; }
.wal-one-settings {
  width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--bg-secondary); color: var(--text-secondary);
}
.wal-one-settings:hover { color: var(--text-primary); }
.wal-one-settings svg { width: 20px; height: 20px; }
.wal-one-id { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-5); min-width: 0; }
.wal-one-name { min-width: 0; }
.wal-one-name .page-title { margin: 0; line-height: 1.1; overflow-wrap: anywhere; }
.wal-one-name .page-subtitle { margin: 2px 0 0; }
.wal-one-disc { --size: 44px; }
.wal-one-sub { display: flex; flex-wrap: wrap; gap: 4px var(--sp-3); }
.wal-one-sub b { font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.wal-one .dash-hero { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); margin-bottom: var(--sp-4); }
.wal-one-chart { padding-bottom: var(--sp-3); }
.wal-one .wal-section-title { margin-top: 0; }

/* ---------- overview ---------- */

.ov-sum {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: var(--gap-section);
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.ov-sum--two { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: var(--sp-4); }
.ov-sum-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--sp-4) var(--sp-5);
  color: var(--text-primary);
  text-decoration: none;
  min-width: 0;
}
.ov-sum-cell + .ov-sum-cell { border-left: 1px solid var(--border); }
a.ov-sum-cell:hover { background: var(--bg-secondary); color: var(--text-primary); }
.ov-sum-label { font-size: var(--fs-sm); color: var(--text-secondary); display: flex; align-items: center; gap: var(--sp-1); }
.ov-sum-value { font-size: var(--fs-xl); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ov-sum-sub { font-size: var(--fs-xs); color: var(--text-secondary); }
.ov-sum-bar { height: 4px; border-radius: var(--radius-pill); background: var(--bg-secondary); margin-top: var(--sp-2); overflow: hidden; }
.ov-sum-bar i { display: block; height: 100%; border-radius: inherit; background: var(--profit); }
.ov-sum-bar i.is-over { background: var(--loss); }
.ov-sum-bar.is-income i { background: var(--info); }

.ov-section { margin-bottom: var(--sp-6); }
.ov-section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-block: 0 var(--sp-2);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
}
.ov-section-title span { font-size: var(--fs-sm); font-variant-numeric: tabular-nums; font-weight: var(--fw-semibold); }
.ov-section-title small { font-weight: var(--fw-regular); color: var(--text-secondary); }
.ov-section-title .ov-section-note { font-weight: var(--fw-regular); color: var(--text-secondary); }
.ov-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--sp-1); }
.ov-grid--wallets .wt-disc { --size: 52px; }
.ov-add-line { display: flex; justify-content: center; margin: calc(-1 * var(--sp-2)) 0 var(--gap-section); }

.ov-view-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--sp-2); margin: calc(-1 * var(--sp-4)) 0 var(--sp-5); }
.ov-view-row .seg-control { margin: 0; }
.ov-view a { display: inline-flex; align-items: center; gap: 6px; }
.ov-view svg { width: 15px; height: 15px; }

.ov-donut-card { display: grid; grid-template-columns: 1fr; gap: var(--sp-5); }
/* On a phone the investments follow the list; beside it they sit under the donut. */
.ov-donut-side { display: contents; }
.ov-donut-side .ov-invest { order: 1; }
@media (min-width: 900px) {
  .ov-donut-card { grid-template-columns: 320px minmax(0, 1fr); align-items: start; }
  .ov-donut-side { display: block; }
}
.ov-donut { position: relative; height: 260px; }
.ov-donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.ov-donut-center small { font-size: var(--fs-xs); color: var(--text-secondary); }
.ov-donut-center b { font-size: var(--fs-xl); font-variant-numeric: tabular-nums; }
.ov-share-list { list-style: none; margin: 0; padding: 0; }
.ov-share-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  grid-template-areas: "icon name fact" "icon bar bar";
  align-items: center;
  column-gap: var(--sp-3);
  row-gap: 6px;
  padding: 10px 0;
  color: var(--text-primary);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}
.ov-share-row:hover { color: var(--text-primary); }
.ov-share-icon { grid-area: icon; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in oklab, var(--c, var(--data-other)) 16%, transparent); color: var(--c, var(--text-secondary)); }
.ov-share-icon svg { width: 18px; height: 18px; }
.ov-share-name { grid-area: name; font-weight: var(--fw-medium); display: flex; flex-direction: column; min-width: 0; }
.ov-share-name small { font-size: var(--fs-xs); color: var(--text-secondary); font-weight: var(--fw-regular); }
.ov-share-fact { grid-area: fact; font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ov-share-bar { grid-area: bar; height: 4px; border-radius: var(--radius-pill); background: var(--bg-secondary); overflow: hidden; }
.ov-share-bar i { display: block; height: 100%; background: var(--c, var(--data-other)); border-radius: inherit; }

/* ---------- history ---------- */

.wal-page, .ov-page, .hist-page, .debt-page, .wal-one { min-width: 0; max-width: 100%; }
.hist-filters { display: flex; flex-direction: column; gap: var(--sp-3); margin-bottom: var(--sp-3); min-width: 0; }
.hist-search {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 46px;
  padding: 0 var(--sp-4);
  border-radius: var(--radius-pill);
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
}
.hist-search svg { width: 18px; height: 18px; color: var(--text-tertiary); flex: none; }
.hist-search input { flex: 1; min-width: 0; border: 0; background: transparent; font-size: 16px; color: var(--text-primary); outline: none; }
.hist-search:focus-within { box-shadow: var(--shadow-sm), var(--ring-focus); }
.hist-selects { display: flex; gap: var(--sp-2); overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; min-width: 0; max-width: 100%; }
.hist-select { flex: none; position: relative; margin: 0; }
.hist-selects::-webkit-scrollbar { display: none; }
.hist-select select {
  appearance: none;
  -webkit-appearance: none;
  min-height: 36px;
  padding: 0 30px 0 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--bg-card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23A39C95' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center;
  font-size: var(--fs-sm);
  color: var(--text-primary);
  max-width: 220px;
}
.hist-select.is-set select { border-color: var(--accent); background-color: var(--accent-soft); color: var(--accent-ink); font-weight: var(--fw-semibold); }
.hist-chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; margin-bottom: var(--sp-3); }
.hist-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 10px 0 12px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  text-decoration: none;
}
.hist-chip svg { width: 14px; height: 14px; }
.hist-chip:hover { color: var(--accent-ink); filter: brightness(0.97); }
.hist-reset { align-self: flex-start; font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--accent-ink); text-decoration: none; }
.hist-reset:hover { color: var(--accent-ink); text-decoration: underline; }
.hist-summary {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
}
.hist-summary-icon { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--bg-secondary); color: var(--text-secondary); }
.hist-summary-icon.is-over { background: var(--loss-bg); color: var(--loss); }
.hist-summary-icon.is-ok { background: var(--profit-bg); color: var(--profit); }
.hist-summary-icon svg { width: 20px; height: 20px; }
.hist-summary-main { display: flex; flex-direction: column; min-width: 0; }
.hist-summary-title { display: flex; align-items: baseline; gap: var(--sp-2); font-weight: var(--fw-semibold); min-width: 0; }
.hist-summary-title small { font-size: var(--fs-xs); font-weight: var(--fw-regular); color: var(--text-secondary); white-space: nowrap; }
.hist-summary-figures { font-variant-numeric: tabular-nums; font-size: var(--fs-lg); white-space: nowrap; }
.hist-summary-plan { color: var(--text-secondary); font-size: var(--fs-sm); }
.hist-summary .ov-sum-bar { margin-top: 6px; }
.hist-summary-add { background: var(--btn-primary-bg); color: var(--btn-primary-ink); border-color: transparent; }
.hist-summary-add:hover { background: var(--btn-primary-hover); color: var(--btn-primary-ink); }
.wal-section-title a { color: var(--accent-ink); text-decoration: none; }
.wal-section-title a:hover { color: var(--accent-ink); text-decoration: underline; }
.hist-summary-actions { display: flex; gap: var(--sp-2); align-items: center; }

/* ---------- debts, reconciliation, wallet form ---------- */

.rec-done { display: flex; gap: var(--sp-2); align-items: center; margin-bottom: var(--sp-4); color: var(--profit); font-weight: var(--fw-semibold); }
.rec-form { display: flex; flex-direction: column; gap: 0; }
.rec-date { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.rec-date input { max-width: 200px; }
.rec-head, .rec-row {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1.2fr);
  gap: var(--sp-3);
  align-items: center;
}
.rec-head { font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: var(--tracking-caps); color: var(--text-secondary); padding-bottom: var(--sp-2); border-bottom: 1px solid var(--border); }
.rec-row { padding: var(--sp-2) 0; border-bottom: 1px solid var(--border); }
.rec-group { margin: var(--sp-5) 0 0; padding-bottom: var(--sp-2); font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-secondary); border-bottom: 1px solid var(--border); }
.rec-name { display: flex; align-items: center; gap: var(--sp-2); font-weight: var(--fw-medium); min-width: 0; overflow-wrap: anywhere; }
.rec-name .wt-disc { --size: 30px; }
.rec-now { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--text-secondary); }
.rec-actual { display: flex; flex-direction: column; gap: 2px; }
.rec-diff { font-size: var(--fs-xs); min-height: 1em; font-variant-numeric: tabular-nums; }
.rec-diff.is-ok { color: var(--profit); }
.rec-diff.is-up { color: var(--info); }
.rec-diff.is-down { color: var(--warn); }
.rec-foot { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); flex-wrap: wrap; margin-top: var(--sp-4); }
@media (max-width: 640px) {
  .rec-head { display: none; }
  /* One line per wallet: name over its balance on the left, the field on
     the right. Most balances match, so the list has to read at a glance. */
  .rec-row { grid-template-columns: minmax(0, 1fr) 132px; grid-template-areas: "name actual" "now actual"; column-gap: var(--sp-3); row-gap: 0; padding: var(--sp-2) 0; }
  .rec-name { grid-area: name; align-self: end; font-size: var(--fs-sm); }
  .rec-name .wt-disc { --size: 26px; }
  .rec-now { grid-area: now; align-self: start; font-size: var(--fs-xs); padding-left: calc(26px + var(--sp-2)); }
  .rec-actual { grid-area: actual; }
  .rec-actual .form-control { height: 40px; font-size: 16px; padding-block: 0; }
  .rec-diff { text-align: right; }
}

.form-error { display: flex; gap: var(--sp-2); align-items: center; margin-bottom: var(--sp-4); color: var(--loss); background: var(--loss-bg); }
.wedit-page { max-width: 640px; }
.wedit-form { display: flex; flex-direction: column; gap: var(--sp-5); }
/* The card is the wallet as it will look: colour, icon, name and balance,
   typed straight into it. */
.wedit-card {
  display: flex; flex-direction: column; gap: var(--sp-3);
  padding: var(--sp-4); border-radius: var(--radius-lg);
  background:
    linear-gradient(155deg, rgba(255, 255, 255, 0.20) 0%, rgba(255, 255, 255, 0) 46%),
    linear-gradient(180deg, var(--wc), color-mix(in oklab, var(--wc), #000 14%));
  color: var(--wci, var(--wallet-ink));
  box-shadow: 0 12px 28px -14px color-mix(in srgb, var(--wc) 80%, transparent);
  transition: background .2s ease, box-shadow .2s ease;
}
.wedit-card-top { display: flex; align-items: center; gap: var(--sp-3); }
.wedit-card-disc { --size: 52px; background: rgba(0, 0, 0, 0.16); color: inherit; }
.wedit-card input {
  font: inherit; color: inherit; border: 0; outline: 0; min-width: 0;
  background: rgba(0, 0, 0, 0.16); border-radius: var(--radius-md);
}
.wedit-card input::placeholder { color: inherit; opacity: .55; }
.wedit-card input:focus-visible { box-shadow: 0 0 0 2px color-mix(in srgb, currentColor 70%, transparent); }
.wedit-card input.is-invalid { box-shadow: 0 0 0 2px var(--loss); }
.wedit-card-name { flex: 1; height: 48px; padding: 0 var(--sp-3); font-size: var(--fs-lg) !important; font-weight: var(--fw-semibold) !important; }
.wedit-card-bal { display: flex; flex-direction: column; gap: var(--sp-1); margin: 0; }
.wedit-card-label { font-size: var(--fs-xs); opacity: .8; }
.wedit-card-sum { display: flex; align-items: center; gap: var(--sp-3); }
.wedit-card-sum input { flex: 1; height: 56px; padding: 0 var(--sp-3); font-size: 28px !important; font-weight: var(--fw-semibold) !important; font-variant-numeric: tabular-nums; text-align: right; }
.wedit-card-cur { font-size: 24px; font-weight: var(--fw-semibold); min-width: 1.2em; }
.wedit-card-hint { margin: 0; font-size: var(--fs-xs); opacity: .8; line-height: 1.4; }
.wedit-date { display: flex; align-items: center; gap: var(--sp-3); margin-top: calc(-1 * var(--sp-2)); color: var(--text-secondary); font-size: var(--fs-sm); }
.wedit-date input { max-width: 180px; }
.wedit-section { display: flex; flex-direction: column; gap: var(--sp-3); }
.wedit-h { font-size: var(--fs-md); font-weight: var(--fw-semibold); margin: 0; }
.wedit-colors { display: flex; flex-wrap: wrap; gap: var(--sp-3); }
.wedit-color {
  position: relative; width: 40px; height: 40px; border-radius: 50%; background: var(--wc); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; color: var(--wci, var(--wallet-ink));
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.wedit-color input { position: absolute; opacity: 0; inset: 0; cursor: pointer; margin: 0; }
.wedit-color svg { width: 20px; height: 20px; opacity: 0; transition: opacity .15s ease; }
.wedit-color:has(input:checked) svg { opacity: 1; }
.wedit-color:has(input:checked) { box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--wc); }
.wedit-color:has(input:focus-visible) { box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--accent); }
.wedit-kinds { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.wedit-kind { margin: 0; cursor: pointer; }
.wedit-kind input { position: absolute; opacity: 0; pointer-events: none; }
.wedit-kind span {
  display: inline-flex; align-items: center; gap: var(--sp-2); min-height: 40px; padding: 0 var(--sp-3);
  border-radius: var(--radius-pill); border: 1px solid var(--border); background: var(--bg-card);
  font-size: var(--fs-sm); font-weight: var(--fw-medium);
}
.wedit-kind span svg { width: 16px; height: 16px; color: var(--text-secondary); }
.wedit-kind input:checked + span { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--bg-card)); color: var(--accent-ink); }
.wedit-kind input:checked + span svg { color: var(--accent-ink); }
.wedit-kind input:focus-visible + span { box-shadow: 0 0 0 2px var(--accent); }
.wedit-switches { gap: 0; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-card); }
.wedit-switch { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); margin: 0; cursor: pointer; }
.wedit-switch + .wedit-switch { border-top: 1px solid var(--border); }
.wedit-switch > span:first-child { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.wedit-switch small { color: var(--text-secondary); font-size: var(--fs-xs); line-height: 1.4; }
.icon-picker-btn input { position: absolute; opacity: 0; pointer-events: none; }
.icon-picker-btn:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.wedit-foot { display: flex; justify-content: flex-end; }
@media (max-width: 767px) {
  /* Save stays under the thumb above the tab bar, as in the sheet. */
  .wedit-foot {
    position: sticky; bottom: calc(var(--bnav-h) + env(safe-area-inset-bottom) + var(--sp-2)); z-index: 5;
    padding: var(--sp-2) 0;
  }
  .wedit-foot .btn-primary { width: 100%; min-height: 50px; font-size: var(--fs-md); box-shadow: var(--shadow-lg, 0 8px 24px rgba(0,0,0,.18)); }
  .wedit-colors { flex-wrap: nowrap; overflow-x: auto; margin-inline: calc(-1 * var(--sp-3)); padding: 6px var(--sp-3); scrollbar-width: none; }
  .wedit-colors::-webkit-scrollbar { display: none; }
  .wedit-color { flex: none; }
}
.choice--wrap { flex-wrap: wrap; }

/* The budget page: a ledger month's facts are links, not fields. */
.budget-fact-link { display: block; text-decoration: none; }
.fact-input.is-ledger { cursor: pointer; background: transparent; border-color: transparent; color: var(--text-primary); }
.budget-fact-link:hover .fact-input.is-ledger { background: var(--bg-secondary); }
.budget-fact-head { display: inline-flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.budget-fact-head small { font-size: var(--fs-2xs); font-weight: var(--fw-regular); text-transform: none; letter-spacing: 0; color: var(--text-tertiary); }

/* ==========================================================================
   The operation sheet
   ========================================================================== */

/* The dialog covers what is visible: with the phone's keyboard up that is
   the strip above it (--vvh/--vvt from visualViewport, ledger.js), so the
   sheet sits on the keyboard instead of the page sliding under it. */
.ops-dialog {
  padding: 0;
  margin: 0;
  border: 0;
  width: 100%;
  inset: var(--vvt, 0px) 0 auto 0;
  height: var(--vvh, 100%);
  max-width: none;
  max-height: none;
  background: transparent;
  overflow: hidden;
}
.ops-dialog[open] { display: flex; align-items: flex-end; justify-content: center; }
.ops-dialog::backdrop { background: rgba(12, 10, 9, 0.5); backdrop-filter: blur(2px); }
.ops-dialog-body {
  position: relative;
  display: flex;
  width: min(560px, 100%);
  /* As tall as what it holds: the short form is short. */
  max-height: min(calc(var(--vvh, 100dvh) - 12px), 920px);
  background: var(--bg-card);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: opsUp 0.32s var(--ease-out);
}
.ops-dialog.is-closing .ops-dialog-body { animation: opsDown 0.2s ease-in forwards; }
@media (min-width: 768px) {
  .ops-dialog[open] { align-items: center; }
  .ops-dialog-body { border-radius: var(--radius-lg); max-height: min(88vh, 860px); }
}

.ops-page { max-width: 560px; margin-inline: auto; }
.ops-page .ops-sheet { background: var(--bg-card); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); min-height: 80vh; }

.ops-sheet { display: flex; flex-direction: column; width: 100%; min-height: 0; color: var(--text-primary); }
.ops-head {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-3) var(--sp-2);
}
.ops-head::before {
  content: "";
  position: absolute;
  top: 6px;
  left: 50%;
  width: 36px;
  height: 4px;
  margin-left: -18px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
}
@media (min-width: 768px) { .ops-head::before { display: none; } }
.ops-title { margin: 0; text-align: center; font-family: var(--font-sans); font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.ops-icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  display: grid;
  place-items: center;
  background: var(--bg-secondary);
  color: var(--text-primary);
  cursor: pointer;
}
.ops-icon-btn svg { width: 20px; height: 20px; }
.ops-icon-btn.is-danger { color: var(--loss); }
.ops-icon-btn:focus-visible { outline: none; box-shadow: var(--ring-focus); }
.ops-adjust-note { margin: 0 var(--sp-4) var(--sp-2); font-size: var(--fs-sm); color: var(--text-secondary); text-align: center; }

.ops-tabs {
  display: flex;
  gap: 2px;
  margin: 0 var(--sp-4) var(--sp-2);
  padding: 3px;
  border-radius: var(--radius-pill);
  background: var(--bg-secondary);
}
.ops-tabs button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 4px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.ops-tabs button svg { width: 16px; height: 16px; }
.ops-tabs button[aria-selected="true"] { background: var(--bg-card); color: var(--text-primary); box-shadow: var(--shadow-sm); }
/* Icons stay on a phone, as in CoinKeeper; the labels tighten instead. */
@media (max-width: 420px) { .ops-tabs button { gap: 4px; font-size: 13px; padding-inline: 4px; } .ops-tabs button svg { width: 15px; height: 15px; } }
.ops-tabs button[data-set-type="expense"] svg { color: var(--loss); }
.ops-tabs button[data-set-type="income"] svg { color: var(--profit); }
.ops-tabs button[data-set-type="transfer"] svg { color: var(--info); }
.ops-tabs button[data-set-type="debt"] svg { color: var(--warn); }

.ops-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--sp-2) var(--sp-4) var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  scroll-padding-top: var(--sp-4);
}

.ops-end {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 56px;
  padding: var(--sp-2) 10px;
  border-radius: var(--radius-md);
  border: 1.5px solid transparent;
  background: var(--bg-secondary);
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
}
.ops-end.is-empty { border-style: dashed; border-color: var(--border-strong); background: transparent; }
.ops-end.is-missing { border-color: var(--loss); animation: opsShake 0.35s; }
.ops-end-disc { flex: none; }
.ops-end-disc .wt-disc, .ops-end-disc .lt-disc { --size: 34px; width: 34px; height: 34px; }
.ops-end-disc .lt-disc::before { inset: 2px; }
.ops-end-disc .lt-disc svg, .ops-end-disc .wt-disc svg { width: 16px; height: 16px; }
.ops-end-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.ops-end-text small { font-size: var(--fs-2xs); color: var(--text-secondary); }
.ops-end-text b { font-size: var(--fs-sm); font-weight: var(--fw-semibold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ops-end-text span { font-size: var(--fs-xs); color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.ops-end.is-empty b { color: var(--text-tertiary); font-weight: var(--fw-medium); }

/* A spend is the ordinary case, written in ink; money in is green. */

.ops-adjust-sign { margin-bottom: var(--sp-2); }

.ops-tile.is-picked .lt-disc, .ops-tile.is-picked .wt-disc { animation: opsPick 0.28s var(--ease-out); }
@keyframes opsPick { 40% { transform: scale(0.9); } 100% { transform: none; } }

.ops-link { border: 0; background: none; padding: 0; color: var(--accent-ink); font-weight: var(--fw-semibold); cursor: pointer; font-size: inherit; }

.ops-meta { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

.ops-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  cursor: pointer;
}
.ops-chip svg { width: 15px; height: 15px; }
.ops-chip[aria-pressed="true"], .ops-chip.is-on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }

.ops-error {
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-md);
  background: var(--loss-bg);
  color: var(--loss);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
}
.ops-error[hidden] { display: none; }

.ops-scroll > .ops-error { order: -10; }
.ops-panel[hidden] { display: none; }
.ops-panel-head { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-2); }
.ops-panel-head .ops-panel-title { margin: 0; }
.ops-panel-title {
  margin: 0 0 var(--sp-2);
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--text-secondary);
}
.ops-panel-title small { text-transform: none; letter-spacing: 0; font-weight: var(--fw-regular); color: var(--text-tertiary); }
.ops-empty { margin: 0 0 var(--sp-2); padding: var(--sp-3); border-radius: var(--radius-md); background: var(--bg-secondary); font-size: var(--fs-sm); color: var(--text-secondary); }
.ops-empty a { color: var(--accent-ink); font-weight: var(--fw-semibold); }
.ops-group + .ops-group { margin-top: var(--sp-2); }
.ops-group-title { margin: 0 0 2px; font-family: var(--font-sans); font-size: var(--fs-xs); font-weight: var(--fw-medium); color: var(--text-tertiary); }
.ops-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px; }
@media (min-width: 480px) { .ops-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.ops-tile { position: relative; }
.ops-tile.wt .wt-disc { --size: 48px; }
.ops-tile[aria-pressed="true"] { background: var(--accent-soft); }
.ops-tile[aria-pressed="true"] .lt-name, .ops-tile[aria-pressed="true"] .wt-name { color: var(--text-primary); font-weight: var(--fw-semibold); }
.ops-tile[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  top: 6px;
  right: calc(50% - 30px);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--bg-card);
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / 10px no-repeat;
}
.ops-tile.is-disabled { opacity: 0.35; pointer-events: none; }
.ops-chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.ops-switch { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--text-secondary); cursor: pointer; margin: 0; }
.ops-switch input { width: 36px; height: 22px; appearance: none; -webkit-appearance: none; border-radius: var(--radius-pill); background: var(--border-strong); position: relative; cursor: pointer; transition: background var(--dur-fast); margin: 0; }
.ops-switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform var(--dur-fast) var(--ease-out); }
.ops-switch input:checked { background: var(--accent); }
.ops-switch input:checked::after { transform: translateX(14px); }
.ops-switch:has(input:checked) { color: var(--accent-ink); font-weight: var(--fw-semibold); }
.ops-person { margin: var(--sp-3) 0 var(--sp-2); display: block; }
.ops-person input { font-size: 16px; }

.ops-foot {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4) calc(var(--sp-3) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}
.ops-submit {
  width: 100%;
  min-height: 52px;
  height: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  border-radius: var(--radius-lg);
  font-size: var(--fs-lg);
  line-height: 1.2;
}
.ops-submit-route { font-size: var(--fs-xs); font-weight: var(--fw-medium); opacity: 0.85; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ops-submit-route:empty { display: none; }
.ops-submit.is-waiting { opacity: 0.55; }
.ops-submit.is-busy { pointer-events: none; opacity: 0.75; }


/* ---------- the «+», the bottom bar, the toast ---------- */

/* The «+» belongs to the money pages (wallets, overview, history, debts —
   marked data-money-page); elsewhere it only crowded the chat button. The key
   N and every [data-op-new] still open the sheet anywhere. */
.ops-fab {
  display: none;
  position: fixed;
  right: calc(var(--sp-6) + 52px + var(--sp-3));
  bottom: var(--sp-6);
  z-index: 1000;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 0;
  place-items: center;
  background: var(--fab-bg);
  color: var(--fab-ink);
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  transition: transform var(--dur-fast), background var(--dur-fast);
}
body:has([data-money-page]) .ops-fab { display: grid; }
.ops-fab:hover { background: var(--fab-hover); transform: translateY(-1px); }
.ops-fab:active { transform: scale(0.95); }
.ops-fab svg { width: 24px; height: 24px; stroke-width: 2.5; }
.ops-fab:focus-visible { outline: none; box-shadow: var(--shadow-lg), var(--ring-focus); }
body:has(.chatpage) .ops-fab { display: none; }

.bnav { display: none; }

.ops-toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--sp-6) + 64px);
  z-index: 2100;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  max-width: min(520px, calc(100vw - 24px));
  padding: 10px 10px 10px 16px;
  border-radius: var(--radius-pill);
  background: var(--text-primary);
  color: var(--bg-card);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  transform: translateX(-50%);
  animation: opsToastIn 0.28s var(--ease-out);
}
.ops-toast[hidden] { display: none; }
.ops-toast.is-error { background: var(--loss); color: #fff; }
.ops-toast-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ops-toast-undo {
  flex: none;
  min-height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-pill);
  background: color-mix(in oklab, var(--bg-card) 16%, transparent);
  color: var(--accent);
  font-weight: var(--fw-semibold);
  cursor: pointer;
}
.ops-toast-undo[hidden] { display: none; }

@media (max-width: 767.98px) {
  .mobile-header { display: none !important; }
  .content {
    padding: calc(env(safe-area-inset-top) + var(--sp-4)) var(--sp-3) calc(var(--bnav-h) + env(safe-area-inset-bottom) + var(--sp-8));
  }
  .content .page-header { margin-bottom: var(--sp-4); }
  .content .page-title { font-size: 28px; }
  .content .page-subtitle { font-size: var(--fs-sm); }
  /* Lists and feeds run edge to edge on a phone: the screen is the card. */
  .wal-list, .opf, .hist-feed {
    margin-inline: calc(-1 * var(--sp-3));
    border-radius: 0;
    box-shadow: none;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
  }
  .wr-row, .opf-row { padding-inline: var(--sp-4); }
  .ov-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; }
  .ops-fab, .chat-fab { display: none !important; }
  .bnav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 990;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: stretch;
    height: calc(var(--bnav-h) + env(safe-area-inset-bottom));
    padding: 0 4px env(safe-area-inset-bottom);
    background: color-mix(in oklab, var(--bg-card) 90%, transparent);
    -webkit-backdrop-filter: blur(20px) saturate(1.6);
    backdrop-filter: blur(20px) saturate(1.6);
    border-top: 1px solid var(--border);
  }
  .bnav-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    border: 0;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 11px;
    font-weight: var(--fw-semibold);
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    transition: color var(--dur-fast);
  }
  .bnav-link svg { width: 24px; height: 24px; stroke-width: 1.9; transition: transform var(--dur-fast) var(--ease-out); }
  .bnav-link:hover { color: var(--text-primary); }
  .bnav-link:active svg { transform: scale(0.88); }
  .bnav-link.is-active { color: var(--accent-ink); }
  .bnav-link.is-active svg { stroke-width: 2.3; }
  .bnav-add {
    align-self: center;
    justify-self: center;
    width: 52px;
    height: 52px;
    border-radius: 18px;
    border: 0;
    display: grid;
    place-items: center;
    background: var(--fab-bg);
    color: var(--fab-ink);
    box-shadow: 0 6px 16px -6px color-mix(in oklab, var(--fab-bg) 70%, transparent);
    -webkit-tap-highlight-color: transparent;
    transition: transform var(--dur-fast) var(--ease-out);
  }
  .bnav-add svg { width: 28px; height: 28px; stroke-width: 2.4; }
  .bnav-add:active { transform: scale(0.92); }
  body:has(.chatpage) .bnav, body:has(.ops-page) .bnav, body.ops-open .bnav { display: none; }
  /* The chat page keeps its own shell: the header with the menu (the tab
     bar would cover its composer) and the padding its full-bleed layout
     was built against. */
  body:has(.chatpage) .mobile-header { display: flex !important; }
  body:has(.chatpage) .content { padding: 72px var(--sp-4) var(--sp-8); }
  .toast-container { right: var(--sp-3); left: var(--sp-3); bottom: calc(var(--bnav-h) + env(safe-area-inset-bottom) + var(--sp-3)); }
  .ops-toast { bottom: calc(var(--bnav-h) + env(safe-area-inset-bottom) + var(--sp-3)); }
  .budget-savebar.is-dirty { bottom: calc(var(--bnav-h) + env(safe-area-inset-bottom) + var(--sp-4)); }
  .wal-quick--4 .wal-quick-btn { font-size: var(--fs-xs); padding: var(--sp-2) 2px; }
  .wal-quick--4 .wal-quick-btn { justify-content: flex-start; padding-top: 10px; }
  .wal-quick--4 .wal-quick-btn span { white-space: normal; line-height: 1.15; text-align: center; }
  .hist-selects { margin-right: calc(-1 * var(--sp-4)); padding-right: var(--sp-4); }
  .wal-quick-btn { flex-direction: column; gap: 4px; min-height: 64px; font-size: var(--fs-sm); padding: var(--sp-2); }
  .wal-quick-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .ov-sum-cell { padding: var(--sp-3); }
  .ov-sum-value { font-size: var(--fs-lg); }
  .page-header .period-nav { order: -1; }
}

@media (max-width: 640px) {
  .wal-one .dash-hero { grid-template-columns: 1fr; }
}

/* ---------- motion ---------- */

@keyframes opsUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes opsDown { to { transform: translateY(60px); opacity: 0; } }
@keyframes opsSpin { to { transform: rotate(360deg); } }
@keyframes opsShake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@keyframes opsToastIn { from { transform: translate(-50%, 16px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
@keyframes opsFresh { from { background: var(--accent-soft); } to { background: transparent; } }
@media (prefers-reduced-motion: reduce) {
  .ops-dialog-body, .ops-toast, .opf-row.is-fresh { animation: none; }
}

/* /net-worth/edit: the linked wallets' month-end balance under a row. */
.nwe-wallet-hint { display: inline-flex; align-items: center; gap: 4px; margin-top: 4px; font-size: var(--fs-xs); color: var(--accent-ink); white-space: nowrap; }
.nwe-wallet-hint svg { width: 13px; height: 13px; }

/* ---------- sign-in (/login) and «Вход» (/settings/login) ---------- */

.auth-body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(env(safe-area-inset-top) + var(--sp-6)) var(--sp-4) calc(env(safe-area-inset-bottom) + var(--sp-6));
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
}
.auth-card {
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-8) var(--sp-6);
  border-radius: 20px;
  background: var(--bg-card);
  box-shadow: var(--shadow-md);
}
.auth-logo { width: 56px; height: 56px; border-radius: 14px; align-self: center; }
.auth-title { margin: var(--sp-2) 0 0; text-align: center; font-family: var(--font-display); font-size: var(--fs-2xl); font-weight: 400; }
.auth-sub { margin: 0 0 var(--sp-3); text-align: center; color: var(--text-secondary); font-size: var(--fs-sm); }
.auth-passkey { width: 100%; min-height: 52px; display: flex; align-items: center; justify-content: center; gap: var(--sp-2); font-size: var(--fs-lg); border-radius: var(--radius-lg); }
.auth-or { display: flex; align-items: center; gap: var(--sp-3); margin: var(--sp-2) 0; color: var(--text-tertiary); font-size: var(--fs-xs); }
.auth-or::before, .auth-or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.auth-form { display: flex; flex-direction: column; gap: var(--sp-2); }
.auth-form .form-control { font-size: 16px; min-height: 46px; }
.auth-form .form-label { margin: var(--sp-1) 0 0; }
.auth-submit { margin-top: var(--sp-2); min-height: 46px; width: 100%; justify-content: center; }
.auth-status { margin: 0; font-size: var(--fs-sm); color: var(--text-secondary); text-align: center; }
.auth-status.is-error { color: var(--loss); }
.auth-status[hidden] { display: none; }
.auth-foot { margin: var(--sp-3) 0 0; font-size: var(--fs-xs); color: var(--text-tertiary); text-align: center; }
.is-busy { opacity: 0.6; pointer-events: none; }
.auth-keys { display: flex; flex-direction: column; gap: var(--sp-3); }
.auth-key-list { list-style: none; margin: 0; padding: 0; }
.auth-key-list li { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: var(--sp-3); padding: var(--sp-2) 0; border-bottom: 1px solid var(--border); }
.auth-key-list .wt-disc { --size: 36px; }
.auth-key-name { display: flex; flex-direction: column; font-weight: var(--fw-medium); }
.auth-key-name small { font-size: var(--fs-xs); color: var(--text-secondary); font-weight: var(--fw-regular); }
.auth-empty { margin: 0; color: var(--text-secondary); }
.auth-add { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.auth-add .form-control { flex: 1 1 200px; font-size: 16px; }
.auth-add .btn-primary { display: inline-flex; align-items: center; gap: var(--sp-2); }
.auth-logout { margin-top: var(--sp-5); }
.auth-logout .btn-outline { display: inline-flex; align-items: center; gap: var(--sp-2); }

/* The sheet while it loads: its shape, not a spinner. */
.ops-skel { display: flex; flex-direction: column; gap: var(--sp-4); width: 100%; padding: var(--sp-5) var(--sp-4); }
.ops-skel i { display: block; border-radius: var(--radius-md); background: linear-gradient(90deg, var(--bg-secondary) 0%, color-mix(in oklab, var(--bg-secondary) 55%, var(--bg-card)) 50%, var(--bg-secondary) 100%); background-size: 200% 100%; animation: opsShimmer 1.1s linear infinite; }
.ops-skel .s-tabs { height: 38px; border-radius: var(--radius-pill); }
.ops-skel .s-amount { height: 56px; width: 50%; align-self: center; }
.ops-skel .s-bar { height: 52px; border-radius: var(--radius-pill); }
.ops-skel .s-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-3); }
.ops-skel .s-grid i { height: 84px; }
@keyframes opsShimmer { to { background-position: -200% 0; } }
.ops-dialog-body.is-dragging { transition: none; }
.ops-dialog-body.is-settling { transition: transform 0.22s var(--ease-out); }

/* ---- The month-end reconciliation reminder on /wallets ---- */
a.card-panel.rec-reminder {
  display: flex; align-items: center; gap: var(--sp-3);
  margin-bottom: var(--sp-4); padding: var(--sp-3) var(--sp-4);
  color: inherit; text-decoration: none;
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 7%, var(--bg-card));
}
.rec-reminder-icon {
  width: 40px; height: 40px; flex: none; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--text-on-accent, #fff);
}
.rec-reminder-icon svg { width: 20px; height: 20px; }
.rec-reminder-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rec-reminder-text small { color: var(--text-secondary); font-size: var(--fs-sm); }
.rec-reminder-go { color: var(--text-tertiary); }

/* Statistics: investment lines sit under the donut, not inside it. */
.ov-invest { margin-top: var(--sp-5); padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.ov-invest-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-3); margin: 0; font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.ov-invest-head b { font-variant-numeric: tabular-nums; }
.ov-invest-note { margin: var(--sp-1) 0 var(--sp-3); font-size: var(--fs-xs); color: var(--text-secondary); }
.ov-invest-list { list-style: none; margin: 0; padding: 0; }
.ov-invest-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--sp-3); padding: var(--sp-2) 0; color: inherit; text-decoration: none; }
.ov-invest-row .ov-share-name { display: flex; flex-direction: column; }
.ov-invest-row small { font-size: var(--fs-xs); color: var(--text-secondary); }
.ov-invest-row .ov-share-fact { font-variant-numeric: tabular-nums; white-space: nowrap; }
.ov-invest-row > * { grid-area: auto; }

/* Lines with neither plan nor fact fold away until asked for. */
.ov-page:not(.show-empty) .lt.is-empty,
.ov-page:not(.show-empty) .ov-section.is-empty { display: none; }
.ov-add-line { flex-wrap: wrap; gap: var(--sp-2); }

#histResults { transition: opacity .15s ease; }
#histResults.is-loading { opacity: .55; }

.ops-error-action { display: inline-flex; align-items: center; min-height: 32px; margin-top: var(--sp-2); padding: 0 var(--sp-3); border: 0; border-radius: var(--radius-pill); background: var(--loss); color: #fff; font: inherit; font-size: var(--fs-sm); font-weight: var(--fw-semibold); cursor: pointer; }

/* A sheet opened as a page (no script, a shared link) is a page: no grip,
   and the line page already has its way back. */
.ops-page .ops-head::before { display: none; }
.ops-page--line [data-sheet-close] { visibility: hidden; }
/* History filters wrap once there is room; on a phone they scroll, and the
   fade says there is more. */
@media (min-width: 600px) { .hist-selects { flex-wrap: wrap; overflow: visible; } }
@media (max-width: 599px) { .hist-selects { -webkit-mask-image: linear-gradient(to right, #000 85%, transparent); mask-image: linear-gradient(to right, #000 85%, transparent); } }

/* Inside the settings card a status reads as part of the text, not as the
   centred line of the sign-in card. */
.auth-settings .auth-status { text-align: left; }
.auth-settings .auth-status.is-error { padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-md); background: var(--loss-bg); }

/* ---- The line sheet: who the line is, its budget, whether it is active ---- */
.line-scroll { display: flex; flex-direction: column; gap: var(--sp-5); }
.line-id { display: flex; align-items: center; gap: var(--sp-3); }
.line-id-icon { position: relative; padding: 0; border: 0; background: none; cursor: pointer; border-radius: 50%; }
.line-id-icon .lt-disc { width: 60px; height: 60px; }
.line-id-icon .lt-disc svg { width: 26px; height: 26px; color: var(--text-primary); }
.line-id-icon:focus-visible { outline: none; box-shadow: var(--ring-focus); }
.line-id-edit {
  position: absolute; right: -2px; bottom: -2px; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; background: var(--bg-card); color: var(--text-secondary);
  box-shadow: 0 0 0 1px var(--border);
}
.line-id-edit svg { width: 12px; height: 12px; }
.line-id-name {
  flex: 1; min-width: 0; height: 52px; padding: 0 var(--sp-4);
  border: 1px solid transparent; border-radius: var(--radius-md);
  background: var(--bg-secondary); color: var(--text-primary);
  font: inherit; font-size: var(--fs-lg); font-weight: var(--fw-semibold);
}
.line-id-name:focus { outline: none; border-color: var(--accent); background: var(--bg-card); }
.line-icons { margin-top: calc(-1 * var(--sp-2)); }
.line-field { display: flex; flex-direction: column; gap: var(--sp-2); }
.line-field-label { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-secondary); }
.line-field .form-hint { margin: 0; }
.line-switch { padding: 0; }

.wal-feed-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-3); }
.wal-feed-head .wal-section-title { margin: 0; }

/* On a phone a wallet's page leads with its operations: the balance, the
   actions, the month's feed, and the chart after them. */
@media (max-width: 767px) {
  .wal-one { display: flex; flex-direction: column; }
  .wal-one > .dash-hero { display: contents; }
  .wal-one > .dash-hero > .dash-hero-card { margin-bottom: var(--sp-3); }
  .wal-one-chart { order: 10; margin-top: var(--gap-section); }
}

/* ================= The operation sheet, CoinKeeper's way =================
   New: a row of «from» that scrolls sideways, the amount, a grid of «to».
   Once both ends are chosen — and always when editing — it folds into the
   short form: two route chips, the amount, the week, the note. */
/* The sheet scrolls up and down only: the «from» row reaches the screen's
   edges with negative margins, and without the clip the whole sheet could
   be dragged sideways on a phone. */
.ops-sheet .ops-scroll { display: flex; flex-direction: column; gap: var(--sp-4); overflow-x: hidden; overflow-x: clip; touch-action: pan-y; }
.ops-row { touch-action: pan-x pan-y; }
/* Nothing in the sheet may be wider than the sheet. */
.ops-sheet .ops-scroll > * { min-width: 0; max-width: 100%; }
.ops-dialog-body, .ops-sheet { overflow-x: hidden; }
.ops-route { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 6px; }
.ops-route[hidden] { display: none; }
.ops-end {
  display: flex; align-items: center; gap: 10px; min-width: 0; min-height: 64px;
  padding: 8px 10px; border: 1px solid transparent; border-radius: var(--radius-lg);
  background: var(--bg-secondary); color: var(--text-primary); text-align: left; cursor: pointer;
}
.ops-end[aria-expanded="true"] { border-color: var(--accent); background: var(--bg-card); }
.ops-end-glyph { flex: none; display: grid; place-items: center; }
.ops-end-glyph .wt-disc { --size: 34px; }
.ops-end-glyph .lt-disc { width: 44px; height: 44px; }
.ops-end-glyph .lt-disc svg { width: 19px; height: 19px; }
.ops-end-glyph .glyph { --size: 44px; }
.glyph.is-empty { background: transparent; border: 1.5px dashed var(--border-strong); color: var(--text-tertiary); }
.ops-end-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.ops-end-text b { font-size: var(--fs-sm); font-weight: var(--fw-semibold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ops-end-text small { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.ops-route-arrow { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--text-on-accent, #fff); }
.ops-route-arrow svg { width: 16px; height: 16px; stroke-width: 2.5; }
.ops-route-arrow[hidden] { display: none; }

.ops-pick[hidden], .ops-pick [data-slot][hidden] { display: none; }
.ops-pick-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-2); }
.ops-pick-head .ops-panel-title { margin: 0; }
.ops-pick-head [hidden] { display: none; }
/* «From» scrolls sideways under the thumb, tiles at a fixed width. */
.ops-row {
  display: grid; grid-auto-flow: column; grid-auto-columns: 84px; gap: 2px;
  overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x proximity;
  scrollbar-width: none;
}
.ops-row::-webkit-scrollbar { display: none; }
.ops-row > .ops-tile { scroll-snap-align: start; }
.ops-row[hidden] { display: none; }

/* The amounts: one big field, or two equal ones side by side. */

.ops-amt {
  display: flex; align-items: baseline; justify-content: flex-end; gap: 6px; margin: 0;
  min-height: 64px; padding: 8px var(--sp-4); border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-lg); background: var(--bg-card); cursor: text;
}
.ops-amt[hidden] { display: none; }
.ops-amt:focus-within { border-color: var(--accent); box-shadow: var(--ring-focus); }

.ops-amt input {
  flex: 1; min-width: 0; border: 0; outline: 0; padding: 0; background: transparent; color: var(--text-primary);
  font: inherit; font-size: 34px; font-weight: var(--fw-semibold); text-align: right; font-variant-numeric: tabular-nums;
  -webkit-appearance: none; appearance: none;
}

.ops-amt input::placeholder { color: var(--text-tertiary); }
.ops-amt-cur { font-size: 20px; font-weight: var(--fw-semibold); color: var(--text-tertiary); }
.ops-sheet[data-type="income"] .ops-amt input { color: var(--profit); }
.ops-rate { margin: calc(-1 * var(--sp-2)) 0 0; font-size: var(--fs-xs); color: var(--text-secondary); }
.ops-rate[hidden] { display: none; }

.ops-more summary { list-style: none; cursor: pointer; margin-top: var(--sp-2); padding: var(--sp-2) 0; font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--accent-ink); }
.ops-more summary::-webkit-details-marker { display: none; }
.ops-more[open] summary { color: var(--text-secondary); }
.ops-invest { margin-top: var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-2); }
.ops-debt { display: flex; flex-direction: column; gap: var(--sp-3); }
.ops-text {
  width: 100%; min-height: 52px; padding: 0 var(--sp-4); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); background: var(--bg-card); color: var(--text-primary);
  font: inherit; font-size: 16px; -webkit-appearance: none; appearance: none;
}
.ops-text:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring-focus); }
.ops-text.is-invalid { border-color: var(--loss); }

/* The week, today last; the calendar for any other day. */
.ops-days { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 5px; }
.ops-days::-webkit-scrollbar { display: none; }
.ops-day {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  min-height: 56px; padding: 0; margin: 0; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--bg-card); color: var(--text-primary); cursor: pointer;
}
.ops-day b { font-size: var(--fs-md); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.ops-day small { font-size: 11px; color: var(--text-secondary); }
.ops-day[aria-pressed="true"], .ops-day--cal.is-on { background: var(--accent); border-color: var(--accent); color: var(--text-on-accent, #fff); }
.ops-day[aria-pressed="true"] small, .ops-day--cal.is-on small { color: inherit; opacity: .85; }
.ops-day--cal svg { width: 20px; height: 20px; }
/* The calendar is a native date field laid over the button. iOS gives a
   date field a minimum width of its own, wider than the button: it stuck
   out of the sheet and let a finger drag the whole sheet sideways. */
.ops-day--cal { overflow: hidden; }
.ops-day--cal input {
  position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer;
  min-width: 0; max-width: 100%; margin: 0; padding: 0; border: 0;
  -webkit-appearance: none; appearance: none; font-size: 16px;
}
.ops-adjust-sign { margin: 0 var(--sp-4) var(--sp-2); }

/* The amounts: one big field, or two equal ones side by side. */
.ops-amounts { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-2); }
.ops-amounts.is-dual { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.ops-amt {
  display: flex; align-items: baseline; justify-content: flex-end; gap: 6px; margin: 0; min-width: 0;
  min-height: 64px; padding: 8px var(--sp-4); border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-lg); background: var(--bg-card); cursor: text;
}
.ops-amt[hidden] { display: none; }
.ops-amt:focus-within { border-color: var(--accent); box-shadow: var(--ring-focus); }
.ops-amounts.is-invalid .ops-amt { border-color: var(--loss); }
.ops-amt input {
  flex: 1; min-width: 0; border: 0; outline: 0; padding: 0; background: transparent; color: var(--text-primary);
  font: inherit; font-size: 34px; font-weight: var(--fw-semibold); text-align: right; font-variant-numeric: tabular-nums;
  -webkit-appearance: none; appearance: none;
}
.ops-amounts.is-dual .ops-amt { padding-inline: var(--sp-3); }
.ops-amounts.is-dual .ops-amt input { font-size: 24px; }
.ops-amt input::placeholder { color: var(--text-tertiary); }
.ops-amt-cur { font-size: 20px; font-weight: var(--fw-semibold); color: var(--text-tertiary); }
.ops-amounts.is-dual .ops-amt-cur { font-size: 17px; }
.ops-sheet[data-type="income"] .ops-amt input { color: var(--profit); }
.ops-sheet .ops-rate { flex: none; margin: calc(-1 * var(--sp-2)) 0 0; font-size: var(--fs-xs); line-height: 1.4; color: var(--text-secondary); }
.ops-sheet .ops-rate[hidden] { display: none; }

/* Touch sizes for the ledger's small links and switches. */
@media (pointer: coarse) {
  .wal-section-title a { display: inline-flex; align-items: center; min-height: 40px; margin-block: -10px; }
}

/* With the keyboard up the home indicator is hidden under it: no room kept. */
.ops-dialog.kb-open .ops-foot { padding-bottom: var(--sp-2); }
.ops-dialog.kb-open .ops-dialog-body { max-height: var(--vvh, 100dvh); border-radius: 16px 16px 0 0; }

/* ================= The home: month row, card carousel, actions ================= */
.wal-kpis { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(132px, 1fr); gap: var(--sp-2); overflow-x: auto; scrollbar-width: none; margin-bottom: var(--sp-4); }
.wal-kpis::-webkit-scrollbar { display: none; }
.wal-kpi {
  display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: var(--sp-3);
  border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-card);
  color: inherit; text-decoration: none;
}
.wal-kpi small { font-size: var(--fs-xs); color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wal-kpi b { font-size: var(--fs-lg); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; white-space: nowrap; }
.wal-kpi-bar { display: block; height: 4px; margin-top: 6px; border-radius: var(--radius-pill); background: var(--bg-secondary); overflow: hidden; }
.wal-kpi-bar i { display: block; height: 100%; background: var(--profit); border-radius: inherit; }
.wal-kpi-bar i.is-over { background: var(--loss); }

.wal-carousel {
  display: grid; grid-auto-flow: column; grid-auto-columns: min(86%, 360px); gap: var(--sp-3);
  overflow-x: auto; scroll-snap-type: x mandatory; overscroll-behavior-x: contain; scrollbar-width: none;
  margin-bottom: var(--sp-4);
}
.wal-carousel::-webkit-scrollbar { display: none; }
.wal-card {
  scroll-snap-align: start; min-height: 158px; min-width: 0; padding: var(--sp-4) var(--sp-5);
  border-radius: 22px; display: flex; flex-direction: column; gap: 4px;
  background:
    linear-gradient(155deg, rgba(255, 255, 255, 0.18) 0%, rgba(255, 255, 255, 0) 50%),
    linear-gradient(180deg, var(--wc, var(--wallet-slate)), color-mix(in oklab, var(--wc, var(--wallet-slate)), #000 16%));
  color: var(--wci, var(--wallet-ink));
  box-shadow: 0 10px 24px -14px color-mix(in oklab, var(--wc, var(--wallet-slate)), #000 30%);
}
.wal-card--balance { background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.wal-card-top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); min-height: 40px; }
.wal-card-label { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-md); color: var(--text-secondary); }
.wal-card-link { font: inherit; font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--accent-ink); background: none; border: 0; padding: 0; cursor: pointer; display: inline-flex; align-items: center; min-height: 40px; }
.wal-card-glyph { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: rgba(0, 0, 0, 0.16); }
.wal-card-glyph svg { width: 22px; height: 22px; }
.wal-card-edit { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: inherit; opacity: .85; }
.wal-card-edit svg { width: 18px; height: 18px; }
.wal-card-body { display: flex; flex-direction: column; gap: 2px; color: inherit; text-decoration: none; margin-top: auto; }
.wal-card-name { font-size: var(--fs-md); font-weight: var(--fw-semibold); opacity: .92; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wal-card-amount { font-size: clamp(26px, 8vw, 34px); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wal-card--balance .wal-card-amount { margin-top: auto; }
.wal-card-sub { font-size: var(--fs-sm); opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wal-card--balance .wal-card-sub { color: var(--text-secondary); opacity: 1; }

/* The actions act on the card shown and wear its colour. */
.wal-acts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-2); margin-bottom: var(--gap-section); }
.wal-acts.is-balance { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.wal-act {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 0; border: 0; background: none;
  color: var(--text-secondary); font: inherit; font-size: var(--fs-sm); text-decoration: none; cursor: pointer;
}
.wal-act[hidden] { display: none; }
.wal-act-btn {
  width: 100%; height: 56px; border-radius: 16px; display: grid; place-items: center;
  background: var(--wc, var(--accent)); color: var(--wci, var(--text-on-accent, #fff));
  transition: background .2s ease;
}
.wal-act-btn svg { width: 24px; height: 24px; stroke-width: 2; }
.wal-act:active .wal-act-btn { transform: scale(0.97); }
@media (max-width: 767px) {
  .wal-carousel { margin-inline: calc(-1 * var(--sp-3)); padding-inline: var(--sp-3); scroll-padding-inline: var(--sp-3); }
}

/* «Все кошельки»: coloured rows, as CoinKeeper's account picker. */
.wpick { display: flex; flex-direction: column; width: 100%; min-height: 0; color: var(--text-primary); }
.wpick-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 10px; padding: var(--sp-3) var(--sp-4) calc(var(--sp-5) + env(safe-area-inset-bottom)); }
.wpick-row {
  display: flex; align-items: center; min-height: 60px; flex: none; border-radius: 16px; overflow: hidden;
  background:
    linear-gradient(155deg, rgba(255, 255, 255, 0.16) 0%, rgba(255, 255, 255, 0) 55%),
    var(--wc, var(--wallet-slate));
  color: var(--wci, var(--wallet-ink));
}
.wpick-row--balance { background: var(--bg-secondary); color: var(--text-primary); }
button.wpick-row, .wpick-main { border: 0; font: inherit; cursor: pointer; text-align: left; }
button.wpick-row { padding: 0 var(--sp-4); gap: var(--sp-3); }
.wpick-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-2) 0 var(--sp-4); min-height: 60px; background: none; color: inherit; }
.wpick-main svg { width: 22px; height: 22px; flex: none; }
.wpick-name { flex: 1; min-width: 0; font-size: var(--fs-md); font-weight: var(--fw-semibold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wpick-row b { font-size: var(--fs-md); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; white-space: nowrap; }
.wpick-edit { width: 52px; align-self: stretch; display: grid; place-items: center; color: inherit; opacity: .9; }
.wpick-edit svg { width: 20px; height: 20px; }
.wpick-add { display: flex; align-items: center; justify-content: center; gap: var(--sp-2); min-height: 52px; border: 1.5px dashed var(--border-strong); border-radius: 16px; color: var(--text-secondary); text-decoration: none; font-weight: var(--fw-semibold); }
.wpick-add svg { width: 18px; height: 18px; }

/* Pages of eight (4×2) that swipe sideways, with dots, as in CoinKeeper. */
.ops-pages { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; overscroll-behavior-x: contain; scrollbar-width: none; touch-action: pan-x pan-y; }
.ops-pages::-webkit-scrollbar { display: none; }
.ops-pages[hidden], [data-slot][hidden] { display: none; }
.ops-pages:not(.is-paged) { flex-wrap: wrap; }
.ops-pages:not(.is-paged) > .ops-tile { width: 25%; }
.ops-page-p { flex: 0 0 100%; min-width: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); align-content: start; gap: 2px; scroll-snap-align: start; scroll-snap-stop: always; }
.ops-dots { display: flex; justify-content: center; gap: 6px; padding-top: var(--sp-2); }
.ops-dots[hidden] { display: none; }
.ops-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--border-strong); transition: background .2s, transform .2s; }
.ops-dots i.is-on { background: var(--accent); transform: scale(1.15); }

/* In the sheet a tile is compact, so two rows of lines and the page dots
   stay above «Готово» on a phone: the dots are what tells there is more. */
.ops-sheet .ops-tile.lt { padding: 6px 2px 8px; gap: 1px; }
.ops-sheet .ops-tile .lt-disc { width: 46px; height: 46px; margin-bottom: 4px; }
.ops-sheet .ops-tile .lt-disc svg { width: 20px; height: 20px; }
.ops-sheet .ops-tile .lt-name { -webkit-line-clamp: 1; min-height: 0; font-size: 12.5px; }
.ops-sheet .ops-tile .lt-fact { font-size: 13.5px; }
.ops-sheet .ops-dots { padding-top: 6px; }
.ops-sheet .ops-pick--to .ops-panel-title, .ops-sheet .ops-pick--from .ops-panel-title { margin-bottom: 4px; }

/* Overview bands: a title with the total, then pages of tiles. */
.ov-band { padding: var(--sp-3) 0 var(--sp-2); border-bottom: 1px solid var(--border); }
.ov-band:last-child { border-bottom: 0; }
.ov-band-title { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-3); margin: 0 0 var(--sp-2); font-family: var(--font-sans); font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.ov-band-title span { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.ov-band-title small { font-weight: var(--fw-regular); color: var(--text-tertiary); }
.ov-pages .lt { padding: 6px 2px 8px; gap: 1px; }
.ov-pages .lt .lt-disc { width: 50px; height: 50px; margin-bottom: 4px; }
.ov-pages .lt .lt-name, .ov-pages .wt .wt-name { -webkit-line-clamp: 1; min-height: 0; }
.ov-pages .wt .wt-disc { --size: 42px; margin-bottom: 4px; }
@media (min-width: 1024px) {
  .ov-pages.is-wide .ops-page-p { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .ov-band { padding-block: var(--sp-4) var(--sp-3); }
}
@media (min-width: 768px) {
  .wal-acts { max-width: 520px; }
  .wal-act-btn { height: 52px; }
}

/* A feed is read left to right: on a wide screen it keeps a list's width
   instead of putting the amount 1 600px from the name. */
@media (min-width: 1024px) {
  .hist-page, .debt-page { max-width: 880px; }
  .debt-page .wal-columns { grid-template-columns: 1fr; }
}

/* ---- Review fixes ---- */
/* The home on a phone: the carousel and «Все кошельки» already show every
   wallet; the long lists under them pushed the operations to the bottom. */
@media (max-width: 767px) {
  .wal-page .wal-columns > .wal-col:first-child { display: none; }
}
.wal-recent > a.card-panel.wal-debts { margin: 0 0 var(--sp-6); }
.wal-card-split { display: none; }
@media (min-width: 1024px) {
  .wal-page .wal-card--balance .wal-card-amount { margin-top: var(--sp-4); font-size: 40px; }
  .wal-page .wal-card--balance .wal-card-sub { display: none; }
  .wal-card-split { display: flex; gap: var(--sp-6); margin: auto 0 0; padding-top: var(--sp-4); border-top: 1px solid var(--border); }
  .wal-card-split div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
  .wal-card-split dt { font-size: var(--fs-xs); font-weight: var(--fw-normal); color: var(--text-secondary); }
  .wal-card-split dd { margin: 0; font-size: var(--fs-md); font-weight: var(--fw-medium); font-variant-numeric: tabular-nums; white-space: nowrap; }
}
/* On a wide screen the carousel is not a pattern: the balance stands as the
   hero with its actions beside it, the wallets are the list below. */
@media (min-width: 1024px) {
  .wal-page .wal-carousel { display: flex; overflow: visible; }
  .wal-page .wal-carousel > .wal-card:not(.wal-card--balance) { display: none; }
  .wal-page .wal-carousel > .wal-card--balance { flex: 1; }
  .wal-page .wal-top { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: var(--sp-4); align-items: stretch; margin-bottom: var(--gap-section); }
  .wal-page .wal-top .wal-carousel, .wal-page .wal-top .wal-acts { margin: 0; }
  .wal-page .wal-top .wal-acts { max-width: none; align-content: center; }
}
/* On the balance the actions are quiet: the figure is the point. On a
   wallet they wear its colour, as in CoinKeeper. */
.wal-acts.is-balance .wal-act-btn { background: var(--bg-card); color: var(--text-primary); box-shadow: inset 0 0 0 1px var(--border); }
.wal-acts.is-balance .wal-act[data-op-new="expense"] .wal-act-btn svg { color: var(--loss); }
.wal-acts.is-balance .wal-act[data-op-new="income"] .wal-act-btn svg { color: var(--profit); }
.wal-acts.is-balance .wal-act[data-op-new="transfer"] .wal-act-btn svg { color: var(--info); }
/* A save bar stuck to the screen carries the page's background. */
@media (max-width: 767px) {
  .wedit-foot { background: linear-gradient(to top, var(--bg-primary) 70%, transparent); margin-inline: calc(-1 * var(--sp-3)); padding: var(--sp-3) var(--sp-3) var(--sp-2); }
  .rec-form .rec-foot { position: sticky; bottom: calc(var(--bnav-h) + env(safe-area-inset-bottom)); z-index: 5; margin-inline: calc(-1 * var(--sp-4)); padding: var(--sp-3) var(--sp-4); background: linear-gradient(to top, var(--bg-card) 75%, transparent); }
  .rec-form .rec-foot .btn-primary { flex: 1; }
}
/* Desktop: the actions are ordinary buttons — sign and verb on one line,
   stacked beside the balance — not phone tiles floating in a column. */
@media (min-width: 1024px) {
  .wal-page .wal-top { grid-template-columns: minmax(0, 1fr) 240px; }
  .wal-page .wal-top .wal-acts, .wal-page .wal-top .wal-acts.is-balance { display: flex; flex-direction: column; justify-content: center; gap: var(--sp-2); }
  .wal-page .wal-top .wal-act {
    flex-direction: row; justify-content: flex-start; gap: var(--sp-3); height: 52px; padding: 0 var(--sp-4);
    border-radius: var(--radius-md); background: var(--bg-card); box-shadow: inset 0 0 0 1px var(--border);
    color: var(--text-primary); font-size: var(--fs-md); font-weight: var(--fw-medium);
  }
  .wal-page .wal-top .wal-act:hover { background: var(--bg-secondary); }
  .wal-page .wal-top .wal-act-btn, .wal-page .wal-top .wal-acts.is-balance .wal-act-btn { width: auto; height: auto; background: none; box-shadow: none; color: inherit; }
  .wal-page .wal-top .wal-act-btn svg { width: 20px; height: 20px; }
  .wal-page .wal-top .wal-act[data-op-new="expense"] svg { color: var(--loss); }
  .wal-page .wal-top .wal-act[data-op-new="income"] svg { color: var(--profit); }
  .wal-page .wal-top .wal-act[data-op-new="transfer"] svg { color: var(--info); }
}

/* ---- Funds (/funds) on the ledger's components ----
   Accounts are wallet rows, a fund's page is a wallet's page, its settings
   the wallet card form and the transfer form the sheet's tiles. Only what
   funds have and wallets do not is styled here. */
@media (min-width: 1000px) {
  .fund-groups { columns: 2; column-gap: var(--gap-section); }
  .fund-groups > * { break-inside: avoid; }
}
.fund-groups > .wal-section:first-child { margin-top: 0; }
.fund-empty > summary { cursor: pointer; list-style: none; }
.fund-empty > summary::-webkit-details-marker { display: none; }
.fund-empty > summary::after { content: ""; width: 8px; height: 8px; margin-left: var(--sp-2); border: solid var(--text-tertiary); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg) translateY(-3px); }
.fund-empty[open] > summary::after { transform: rotate(-135deg) translateY(-2px); }
.fund-empty > summary span { margin-left: auto; }

.fund-tr { grid-template-columns: 40px minmax(0, 1fr) auto 36px; cursor: default; }
.fund-tr-del { display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: var(--radius-md); background: none; color: var(--text-tertiary); }
.fund-tr-del:hover, .fund-tr-del:focus-visible { color: var(--loss); background: var(--loss-bg); outline: none; }
.fund-tr-del svg { width: 16px; height: 16px; }
.fund-one .wal-quick { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.fund-tr-form { display: flex; flex-direction: column; gap: var(--sp-4); }
.fund-tr-form .choice { align-self: flex-start; }
.fund-tr-pick[hidden] { display: none; }
.fund-tr-pick .ops-panel-title { margin-bottom: var(--sp-2); }
.fund-tr-pick .ops-tile { cursor: pointer; }
.fund-tr-pick .ops-tile input { position: absolute; opacity: 0; pointer-events: none; }
.fund-tr-pick .ops-tile:has(input:checked) { background: var(--accent-soft); }
.fund-tr-pick .ops-tile:has(input:checked) .wt-name { color: var(--text-primary); font-weight: var(--fw-semibold); }
.fund-tr-pick .ops-tile:has(input:focus-visible) { box-shadow: var(--ring-focus); }
.fund-tr-after { margin: calc(-1 * var(--sp-2)) 0 0; min-height: 1.2em; text-align: right; }
.fund-tr-meta { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: var(--sp-3); }
.fund-tr-field > span { display: block; margin-bottom: var(--sp-1); font-size: var(--fs-sm); color: var(--text-secondary); }
.fund-tr-field input[type="date"] { min-width: 0; }
@media (max-width: 480px) { .fund-tr-meta { grid-template-columns: 1fr; } }
.wedit-fixed { margin: 0; font-weight: var(--fw-medium); }
.wedit-fixed small { display: block; margin-top: 2px; font-size: var(--fs-sm); font-weight: var(--fw-normal); color: var(--text-secondary); }
.wedit-danger { margin-top: var(--sp-6); }
a.wal-quick-btn { text-decoration: none; color: inherit; }
.fund-tr-form .choice span { display: inline-flex; align-items: center; gap: 6px; }
.fund-tr-form .choice svg { width: 16px; height: 16px; }
/* A wide screen has room for every account: tiles wrap instead of hiding
   past the right edge of a row that scrolls. */
@media (min-width: 768px) {
  .fund-tr-pick .ops-row { grid-auto-flow: row; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); overflow: visible; }
}
