/* ============================================================
   Финансы — персональный учёт денег
   ============================================================ */

:root {
  --bg: #080b11;
  --card: #121823;
  --card-2: #182130;
  --text: #eaf0f6;
  --muted: #8a97ab;
  --muted-2: #66728a;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.12);
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.14);
  --red: #fb7185;
  --red-soft: rgba(251, 113, 133, 0.14);
  --blue: #60a5fa;
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  /* iOS в standalone-режиме иногда отдаёт завышенный нижний inset.
     Ограничиваем его высотой home indicator (34px), иначе панель
     вкладок и кнопка «+» уезжают вверх, оставляя пустую полосу снизу. */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-bottom: min(env(safe-area-inset-bottom, 0px), 34px);

  /* Плавность как в iOS: быстрый старт и мягкое затухание. */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-ios: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-page: cubic-bezier(0.35, 0, 0.55, 1);
  --ease-spring: cubic-bezier(0.34, 1.3, 0.64, 1);
  /* Единая скорость открытия и закрытия: без рывка и без «залипания». */
  --ease-sheet: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-sheet: 400ms;
  --dur-period: 400ms;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  background:
    radial-gradient(120% 55% at 50% -10%, #16243a 0%, rgba(8, 11, 17, 0) 60%) no-repeat,
    var(--bg);
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; }

/* Скроллится сам документ, а не внутренний контейнер: так Safari
   сворачивает адресную строку и нижнюю панель при прокрутке, и
   приложение не «уезжает» вверх на высоту браузерного интерфейса. */
#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.view {
  flex: 1;
  padding: calc(var(--safe-top) + 14px) 16px calc(104px + var(--safe-bottom));
  /* Вертикальная прокрутка — браузеру, горизонтальный жест — свайпу периода. */
  touch-action: pan-y;
}

.view.view-soft { animation: view-soft 0.32s ease-out; }

/* Горизонтальное перелистывание периодов: старый и новый месяц
   двигаются одновременно, как страницы. */
.period-swap {
  position: fixed;
  inset: 0;
  z-index: 19;
  overflow: hidden;
  pointer-events: none;
}

.period-swap-pane {
  position: absolute;
  inset: 0;
  overflow: hidden;
  will-change: transform;
}

.period-swap-inner {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
}

/* Верхняя подпись вкладки при перелистывании не двигается:
   в клоне она остаётся прозрачной, чтобы содержимое не смещалось. */
.period-swap .page-head { visibility: hidden; }

.period-swap-pane.is-out-left { animation: period-out-left var(--dur-period) var(--ease-page) both; }
.period-swap-pane.is-out-right { animation: period-out-right var(--dur-period) var(--ease-page) both; }
.period-swap-pane.is-in-right { animation: period-in-right var(--dur-period) var(--ease-page) both; }
.period-swap-pane.is-in-left { animation: period-in-left var(--dur-period) var(--ease-page) both; }

/* ---------- header ---------- */

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.page-title {
  font-size: 27px;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

.page-sub {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.head-link {
  background: none;
  border: 0;
  color: var(--green);
  font-size: 14px;
  font-weight: 600;
  padding: 6px 2px;
  transition: opacity 0.2s ease;
}

.head-link:active { opacity: 0.6; }

/* ---------- month nav ---------- */

.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 2px 0 14px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 5px;
}

.month-nav .nav-btn {
  width: 38px;
  height: 34px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 0;
  border-radius: 10px;
  color: var(--muted);
  transition: background 0.2s ease, color 0.2s ease;
}

.month-nav .nav-btn:active { background: rgba(255, 255, 255, 0.07); }
.month-nav .nav-btn:disabled { opacity: 0.28; pointer-events: none; }
.month-nav .nav-btn svg { width: 18px; height: 18px; }

.month-nav .month-label {
  flex: 1;
  background: transparent;
  border: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  padding: 6px 0;
  border-radius: 10px;
  transition: background 0.2s ease;
}

.month-nav .month-label:active { background: rgba(255, 255, 255, 0.05); }
.month-nav .month-label.is-current { color: var(--text); }

.period-jump-note {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -6px 2px 12px;
  padding: 9px 11px;
  border-radius: 12px;
  background: rgba(251, 191, 36, 0.09);
  border: 1px solid rgba(251, 191, 36, 0.2);
  color: #fcd34d;
  font-size: 12.5px;
  line-height: 1.4;
  animation: period-note-in 0.45s var(--ease-out) both;
}

.period-jump-note svg {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  opacity: 0.9;
}

.period-jump-text { flex: 1; min-width: 0; }
.period-jump-note b { color: #fde68a; font-weight: 600; }

.period-jump-add {
  flex: 0 0 auto;
  border: 1px solid rgba(251, 191, 36, 0.28);
  background: rgba(251, 191, 36, 0.1);
  color: #fde68a;
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 600;
  transition: transform 0.18s var(--ease-spring), opacity 0.2s ease;
}

.period-jump-add:active { transform: scale(0.96); opacity: 0.8; }

/* ---------- cards ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card + .card { margin-top: 0; }

.section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin: 18px 2px 8px;
}

.section-label:first-child { margin-top: 0; }

.card-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  text-transform: uppercase;
  margin: 0 0 12px;
}

.balance-card {
  position: relative;
  overflow: hidden;
  background: linear-gradient(150deg, #172030 0%, #101722 65%, #0e141d 100%);
  border: 1px solid var(--line);
  border-radius: 26px;
  padding: 20px 20px 16px;
  margin-bottom: 14px;
}

.balance-card::after {
  content: "";
  position: absolute;
  width: 220px;
  height: 220px;
  right: -90px;
  top: -120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(52, 211, 153, 0.22), rgba(52, 211, 153, 0) 68%);
  pointer-events: none;
}

.balance-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  min-width: 0;
}

.balance-value {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.balance-value.negative { color: var(--red); }

.balance-value-row {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}

.balance-eye {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.07);
  color: var(--muted);
  transition: background 0.22s ease, color 0.22s ease, transform 0.2s var(--ease-spring);
}

.balance-eye.on {
  color: var(--text);
  background: rgba(255, 255, 255, 0.12);
}

.balance-eye:active { transform: scale(0.94); }
.balance-eye:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.period-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  flex: 0 0 auto;
  align-self: flex-end;
  margin-left: auto;
  padding: 4px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  transition: background 0.2s ease, color 0.2s ease, transform 0.18s var(--ease-spring);
}

.period-toggle.is-icon { min-width: 28px; padding: 4px 6px; }
.period-toggle.is-icon .period-toggle-text { display: none; }

@media (max-width: 360px) {
  .period-toggle-text { display: none; }
  .period-toggle { min-width: 28px; min-height: 28px; padding: 4px 6px; }
}

.period-toggle svg { width: 13px; height: 13px; }
.period-toggle:active { transform: scale(0.97); background: rgba(255, 255, 255, 0.08); }
.period-toggle:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.balance-open {
  margin-top: 5px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.balance-split {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 13px;
  color: var(--muted);
  flex-wrap: nowrap;
}

.balance-split .in,
.balance-split .out { min-width: 0; }

.balance-split b {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
  white-space: nowrap;
}

.balance-split.compact { gap: 8px; }
.balance-split.compact b { font-size: clamp(11px, 3.2vw, 13px); }

.balance-split .in b { color: var(--green); }
.balance-split .out b { color: var(--text); }

.stats-only-card::after {
  background: radial-gradient(circle, rgba(96, 165, 250, 0.2), rgba(96, 165, 250, 0) 68%);
}

.stats-only-title {
  position: relative;
  z-index: 1;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stats-only-text {
  position: relative;
  z-index: 1;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--muted);
  margin: 7px 0 0;
  max-width: 310px;
}

.stats-only-action {
  position: relative;
  z-index: 1;
  margin-top: 13px;
  border: 1px solid rgba(96, 165, 250, 0.3);
  background: rgba(96, 165, 250, 0.1);
  color: #93c5fd;
  border-radius: 11px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  transition: transform 0.18s var(--ease-spring), opacity 0.2s ease, background 0.2s ease;
}

.stats-only-action:active { transform: scale(0.97); opacity: 0.82; }

/* ---------- pending ---------- */

.pending-card {
  border-color: rgba(52, 211, 153, 0.22);
  background: linear-gradient(180deg, rgba(52, 211, 153, 0.08), rgba(18, 24, 35, 0.9));
}

.pending-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 0;
}

.pending-row.compact {
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
}

.pending-top {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.pending-actions {
  display: flex;
  justify-content: flex-start;
  gap: 8px;
  padding-left: 50px;
}

.pending-row + .pending-row { border-top: 1px solid var(--line); }

.pending-info { flex: 1; min-width: 0; }

.pending-info .t { font-size: 15px; font-weight: 600; }

.pending-info .s {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pill-btn {
  border: 0;
  background: var(--green);
  color: #06231a;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 13px;
  border-radius: 11px;
  white-space: nowrap;
  transition: transform 0.18s var(--ease-spring), opacity 0.18s ease, background 0.22s ease;
}

.pill-btn.ghost {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-weight: 600;
}

.pill-btn:active { transform: scale(0.955); }

/* ---------- transactions ---------- */

.day-group { margin-bottom: 8px; }

.day-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 12px 4px 7px;
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 500;
}

.day-head .day-sum { font-variant-numeric: tabular-nums; color: var(--muted-2); }

.tx-list {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.tx-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 14px;
  background: transparent;
  border: 0;
  text-align: left;
  min-height: 58px;
  transition: background 0.2s ease;
}

.tx-row + .tx-row { border-top: 1px solid var(--line); }
.tx-row:active { background: rgba(255, 255, 255, 0.04); }

.cat-avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 18px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.tx-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tx-title {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-sub {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-amount {
  font-size: 15.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.tx-amount.income { color: var(--green); }

.empty {
  text-align: center;
  padding: 46px 20px;
  color: var(--muted);
}

.empty .big { font-size: 40px; margin-bottom: 10px; }
.empty .t { color: var(--text); font-weight: 600; margin-bottom: 5px; font-size: 16px; }
.empty .s { font-size: 13.5px; line-height: 1.45; max-width: 270px; margin: 0 auto; }

/* ---------- segmented ---------- */

.segmented {
  display: flex;
  gap: 3px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 13px;
  padding: 3px;
}

.segmented button {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 10px;
  transition: background 0.26s ease, color 0.26s ease;
}

.segmented button.active {
  background: rgba(255, 255, 255, 0.13);
  color: #fff;
}

.segmented.income-expense button[data-kind="expense"].active {
  background: var(--red-soft);
  color: var(--red);
}

.segmented.income-expense button[data-kind="income"].active {
  background: var(--green-soft);
  color: var(--green);
}

/* ---------- reports ---------- */

.reports .donut-wrap {
  display: flex;
  justify-content: center;
  padding: 6px 0 2px;
}

.donut { max-width: 210px; height: auto; }

.donut-total {
  fill: var(--text);
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.donut-cap {
  fill: var(--muted);
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.legend { margin-top: 10px; }

.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 2px;
}

.legend-row + .legend-row { border-top: 1px solid var(--line); }

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 9px;
}

.legend-name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.legend-val {
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.legend-pct {
  width: 42px;
  text-align: right;
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.legend-btn {
  width: 100%;
  border: 0;
  background: none;
  text-align: left;
  color: inherit;
  font: inherit;
  transition: background 0.2s ease;
}

.legend-btn:active { background: rgba(255, 255, 255, 0.05); }

.legend-go {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  margin-left: -2px;
}

/* ---------- report category sheet ---------- */

.sheet-head.report-sheet-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  position: sticky;
  top: 0;
  z-index: 3;
  margin: 0 -16px;
  padding: 8px 16px 10px;
  background: #111823;
}

.report-sheet-head .sheet-title { text-align: center; }
.report-sheet-head .link-btn { justify-self: end; }

.report-cat-summary {
  padding: 2px 0 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.report-cat-sum {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.report-cat-sub {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--muted);
}

.report-tx { padding-left: 14px; padding-right: 14px; }

.report-tx-date {
  flex: 0 0 52px;
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.bars {
  display: flex;
  gap: 8px;
  align-items: stretch;
  height: 148px;
  margin-top: 4px;
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.bar-pair {
  flex: 1;
  display: flex;
  gap: 3px;
  align-items: flex-end;
  padding-bottom: 2px;
}

.bar {
  flex: 1;
  border-radius: 5px 5px 2px 2px;
  min-height: 0;
  transition: height 0.55s var(--ease-ios);
}

.bar.inc { background: linear-gradient(180deg, #4ade80, #22a06b); }
.bar.exp { background: linear-gradient(180deg, #fb7185, #b3455c); }

.bar-label {
  text-align: center;
  font-size: 11px;
  color: var(--muted-2);
  margin-top: 6px;
}

.bar-label.active { color: var(--text); font-weight: 600; }

.chart-legend {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
}

.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 13px 14px;
  min-width: 0;
}

.stat .k {
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat .v {
  font-size: 17px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat .v.small { font-size: 15px; }

/* ---------- recurring ---------- */

.rule-list {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 14px;
}

.rule-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 14px;
  min-height: 62px;
}

.rule-row + .rule-row { border-top: 1px solid var(--line); }

.rule-main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 4px 11px 14px;
  background: transparent;
  border: 0;
  text-align: left;
  min-width: 0;
  transition: background 0.2s ease;
}

.rule-main:active { background: rgba(255, 255, 255, 0.03); }

.rule-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }

.rule-row.inactive .rule-text { opacity: 0.45; }
.rule-row.inactive .cat-avatar { opacity: 0.45; }

.planned-row .rule-text { flex: 1; }

.planned-go {
  color: var(--muted-2);
  font-size: 18px;
  line-height: 1;
  margin-left: auto;
}

.planned-empty .t {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 5px;
}

.planned-empty .s {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}

.pending-info .t {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.switch {
  position: relative;
  width: 46px;
  height: 28px;
  flex: 0 0 46px;
  border: 0;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.14);
  appearance: none;
  -webkit-appearance: none;
  transition: background 0.3s ease;
}

.switch:checked { background: var(--green); }
.switch:checked::after { transform: translateX(18px); }

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.32s var(--ease-spring);
}

.switch.on { background: var(--green); }
.switch.on::after { transform: translateX(18px); }

.due-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  flex: 0 0 7px;
  margin-left: 2px;
}

/* ---------- settings ---------- */

.setting-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 2px;
  background: transparent;
  border: 0;
  text-align: left;
  min-height: 50px;
  transition: opacity 0.2s ease, background 0.2s ease;
}

.setting-row + .setting-row { border-top: 1px solid var(--line); }
.setting-row:active { opacity: 0.7; }

.setting-row .label { flex: 1; font-size: 15px; }
.setting-row .value { color: var(--muted); font-size: 14px; max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.setting-row .chev { color: var(--muted-2); font-size: 18px; line-height: 1; }

.setting-row.danger .label { color: var(--red); }

.backup-warning {
  margin: 10px 0;
  padding: 11px 12px;
  border: 1px solid rgba(251, 191, 36, 0.35);
  border-radius: 14px;
  background: rgba(251, 191, 36, 0.08);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
}

.backup-warning-title {
  margin-bottom: 4px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.backup-warning p { margin: 0; }
.backup-warning p + p { margin-top: 6px; }

.cat-manage-row .cat-avatar { width: 32px; height: 32px; flex-basis: 32px; font-size: 15px; border-radius: 10px; }

.section-gap { height: 20px; }

.hint {
  font-size: 12.5px;
  color: var(--muted-2);
  line-height: 1.45;
  padding: 2px 4px 0;
}

.import-error-list {
  margin: 0 0 14px;
  padding-left: 20px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.45;
}

.import-error-list li + li { margin-top: 5px; }

select.plain {
  appearance: none;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  border-radius: 11px;
  padding: 8px 12px;
  text-align: right;
}

/* ---------- fab ---------- */

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(78px + var(--safe-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 0;
  background: linear-gradient(160deg, #4ade80, #22c58a);
  color: #052a1e;
  display: grid;
  place-items: center;
  box-shadow: 0 10px 26px rgba(34, 197, 138, 0.32), 0 2px 6px rgba(0, 0, 0, 0.35);
  z-index: 20;
  transition: transform 0.28s var(--ease-spring), box-shadow 0.28s ease, opacity 0.22s ease, visibility 0s linear 0s;
}

.fab svg { width: 24px; height: 24px; }
.fab:active { transform: scale(0.9); box-shadow: 0 6px 16px rgba(34, 197, 138, 0.25), 0 2px 4px rgba(0, 0, 0, 0.3); }

body[data-view="settings"] .fab {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(0.82) translateY(8px);
  box-shadow: none;
  transition: transform 0.22s ease, opacity 0.18s ease, visibility 0s linear 0.22s;
}

/* ---------- tabbar ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  display: flex;
  padding: 6px 6px calc(6px + var(--safe-bottom));
  background: rgba(10, 14, 20, 0.86);
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  border-top: 1px solid var(--line);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 0 3px;
  border: 0;
  background: transparent;
  color: var(--muted-2);
  font-size: 10.5px;
  font-weight: 500;
  border-radius: 12px;
  transition: color 0.28s ease, opacity 0.2s ease;
}

.tab svg {
  width: 23px;
  height: 23px;
  transition: transform 0.32s var(--ease-spring);
}

.tab[hidden] { display: none; }
.tab.active { color: var(--green); }
.tab.active svg { transform: translateY(-1px) scale(1.065); }
.tab:active { opacity: 0.7; }

/* ---------- sheet ---------- */

.sheet-wrap {
  position: fixed;
  inset: 0;
  z-index: 60;
}

.sheet-wrap[hidden] { display: none; }

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  animation: backdrop-in var(--dur-sheet) var(--ease-sheet) both;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  background: #111823;
  border-top: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  padding-bottom: var(--safe-bottom);
  transform-origin: bottom center;
  transform: translateY(100%);
  transition: transform var(--dur-sheet) var(--ease-sheet);
  will-change: transform;
}

.sheet-wrap.open .sheet { transform: translateY(0); }

/* Пока лист тянут за «язычок», переход не должен мешать пальцу. */
.sheet-wrap.dragging .sheet { transition: none; }

.sheet-wrap.closing .sheet-backdrop {
  animation: backdrop-out var(--dur-sheet) var(--ease-sheet) both;
}

.sheet-wrap.closing .sheet { transform: translateY(100%); }

.sheet-scroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 8px 16px 18px;
}

.sheet-scroll.sheet-swap {
  animation: sheet-swap 0.26s var(--ease-out);
}

.grabber {
  position: relative;
  width: 44px;
  height: 5px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.18);
  margin: 0 auto 8px;
  cursor: grab;
  touch-action: none;
}

.grabber:active { cursor: grabbing; }

/* У «язычка» маленькая видимая часть — увеличиваем зону захвата. */
.grabber::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 132px;
  height: 34px;
  transform: translate(-50%, -50%);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 0 14px;
}

.sheet-title {
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.link-btn {
  border: 0;
  background: none;
  padding: 6px 2px;
  font-size: 15px;
  color: var(--muted);
  border-radius: 8px;
  transition: opacity 0.2s ease, color 0.2s ease;
}

.link-btn.strong { color: var(--green); font-weight: 650; }
.link-btn:active { opacity: 0.65; }

/* ---------- forms ---------- */

.amount-field {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 0 18px;
}

.amount-field input {
  width: 2ch;
  max-width: 78%;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: none;
  text-align: center;
  font-size: 44px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  padding: 0;
}

@supports (field-sizing: content) {
  .amount-field input {
    field-sizing: content;
    width: auto;
  }
}

.amount-field input::placeholder { color: rgba(255, 255, 255, 0.22); }

.amount-cur {
  font-size: 26px;
  font-weight: 600;
  color: var(--muted-2);
  padding-bottom: 4px;
}

.amount-cur.ghost { visibility: hidden; }

.amount-measure {
  position: absolute;
  visibility: hidden;
  pointer-events: none;
  white-space: pre;
  padding: 0;
  margin: 0;
  border: 0;
}

.amount-field.invalid input { animation: shake 0.3s; color: var(--red); }

.field-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin: 14px 0 8px;
}

.field-label:first-child { margin-top: 0; }

.cat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin-bottom: 4px;
}

.cat-grid[data-kind="expense"] .cat[data-cat-kind="income"],
.cat-grid[data-kind="income"] .cat[data-cat-kind="expense"] { display: none; }

.cat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 9px 3px 7px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.045);
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.15;
  min-width: 0;
  transition: background 0.24s ease, border-color 0.24s ease, color 0.24s ease, transform 0.18s var(--ease-spring);
}

.cat .e { font-size: 19px; line-height: 1.1; }

.cat .n {
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cat.selected {
  background: rgba(52, 211, 153, 0.12);
  border-color: rgba(52, 211, 153, 0.45);
  color: #fff;
}

.cat:active { transform: scale(0.95); }

.form-row { display: flex; gap: 8px; align-items: stretch; }
.form-row > * { flex: 1; min-width: 0; }

.input, .date-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 12px 13px;
  font-size: 16px;
  color: var(--text);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.24s ease, background 0.24s ease;
}

.input::placeholder { color: var(--muted-2); }
.input:focus, .date-input:focus { border-color: rgba(52, 211, 153, 0.5); }

.date-input { min-height: 46px; }
.date-input::-webkit-calendar-picker-indicator { filter: invert(0.65); opacity: 0.8; }

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

.history-intro {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 4px;
}

.period-range-row .range-select { min-width: 0; }

.range-select {
  border-radius: 12px;
  padding-right: 28px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 17px) calc(50% + 1px),
    calc(100% - 12px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.period-range-row .year-select { flex: 0 0 96px; }

.history-range-hint {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.45;
  padding: 10px 2px 0;
}

.history-range-hint b { color: var(--text); font-weight: 600; }
.history-range-hint.error { color: var(--red); }

.history-transfer {
  margin-top: 12px;
  border-top: 1px solid var(--line);
}

.history-transfer[hidden] { display: none; }

.period-empty { padding: 24px 12px 22px; }

.month-picker-list { margin: 0 0 8px; }

.month-picker-year {
  padding: 13px 2px 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.month-picker-year:first-child { padding-top: 0; }

.month-pick-row {
  display: flex;
  align-items: center;
  gap: 2px;
  width: 100%;
  min-height: 46px;
  padding: 0 2px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-size: 15px;
}

.month-pick-main {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  min-height: 46px;
  padding: 9px 0;
  background: transparent;
  border: 0;
  color: inherit;
  text-align: left;
  font-size: 15px;
  transition: opacity 0.18s ease, color 0.18s ease;
}

.month-pick-main:active { opacity: 0.65; }
.month-pick-row.selected .month-pick-main { color: var(--green); }

.month-pick-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.month-pick-del {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted-2);
  transition: background 0.18s ease, color 0.18s ease, transform 0.16s ease;
}

.month-pick-del svg { width: 17px; height: 17px; }
.month-pick-del:active {
  background: rgba(248, 113, 113, 0.14);
  color: #f87171;
  transform: scale(0.94);
}
.month-pick-del:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.month-pick-badge {
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
}

.month-pick-check { color: var(--green); font-size: 16px; }

.quick-dates { display: flex; gap: 7px; margin-top: 8px; }

.chip {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  border-radius: 10px;
  padding: 7px 11px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.22s ease, border-color 0.22s ease, color 0.22s ease, transform 0.16s ease;
}

.chip:active { transform: scale(0.965); }

.chip.active {
  background: rgba(52, 211, 153, 0.13);
  border-color: rgba(52, 211, 153, 0.4);
  color: var(--green);
}

.primary-btn {
  width: 100%;
  border: 0;
  border-radius: 15px;
  padding: 15px;
  font-size: 16px;
  font-weight: 650;
  color: #052a1e;
  background: linear-gradient(160deg, #4ade80, #22c58a);
  margin-top: 16px;
  transition: transform 0.18s var(--ease-spring), opacity 0.18s ease;
}

.primary-btn:active { transform: scale(0.985); opacity: 0.92; }
.primary-btn:disabled { opacity: 0.45; pointer-events: none; }

.primary-btn.danger {
  background: linear-gradient(160deg, #fb7185, #e11d48);
  color: #2a0710;
}

.danger-btn {
  width: 100%;
  border: 1px solid rgba(251, 113, 133, 0.3);
  background: rgba(251, 113, 133, 0.09);
  color: var(--red);
  border-radius: 14px;
  padding: 13px;
  font-size: 15px;
  font-weight: 600;
  margin-top: 18px;
  transition: transform 0.18s var(--ease-spring), opacity 0.18s ease, background 0.22s ease;
}

.danger-btn:active { transform: scale(0.985); opacity: 0.9; }

.secondary-btn {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border-radius: 14px;
  padding: 13px;
  font-size: 15px;
  font-weight: 600;
  margin-top: 10px;
  transition: transform 0.18s var(--ease-spring), opacity 0.18s ease, background 0.22s ease;
}

.secondary-btn:active { transform: scale(0.985); opacity: 0.9; }

.tertiary-btn {
  width: 100%;
  border: 0;
  background: none;
  color: var(--muted);
  padding: 14px;
  font-size: 15px;
  font-weight: 500;
  margin-top: 4px;
  transition: opacity 0.2s ease;
}

.tertiary-btn:active { opacity: 0.65; }

.check-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 2px;
  background: none;
  border: 0;
  text-align: left;
}

.check-row .label { flex: 1; font-size: 15px; }
.check-row .label small { display: block; color: var(--muted-2); font-size: 12px; margin-top: 1px; }

.checkbox {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  border-radius: 8px;
  border: 1.5px solid var(--line-strong);
  display: grid;
  place-items: center;
  color: transparent;
  font-size: 15px;
  font-weight: 700;
  transition: background 0.24s ease, border-color 0.24s ease, color 0.24s ease, transform 0.2s var(--ease-spring);
}

.checkbox.on {
  background: var(--green);
  border-color: var(--green);
  color: #052a1e;
}

.emoji-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 0 8px;
  scrollbar-width: none;
}

.emoji-row::-webkit-scrollbar { display: none; }

.emoji-pick {
  flex: 0 0 40px;
  height: 40px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  font-size: 19px;
  transition: background 0.22s ease, border-color 0.22s ease, transform 0.18s var(--ease-spring);
}

.emoji-pick:active { transform: scale(0.94); }

.emoji-pick.selected { border-color: var(--green); background: var(--green-soft); }

.swatches { display: flex; flex-wrap: wrap; gap: 9px; padding: 2px 0 6px; }

.swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: border-color 0.22s ease, box-shadow 0.22s ease, transform 0.18s var(--ease-spring);
}

.swatch:active { transform: scale(0.92); }

.swatch.selected { border-color: #fff; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.12); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + var(--safe-bottom));
  transform: translate(-50%, 16px) scale(0.97);
  background: #1d283a;
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  padding: 10px 16px;
  border-radius: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease, transform 0.36s var(--ease-ios);
  z-index: 120;
  max-width: calc(100% - 40px);
  text-align: center;
}

.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

/* ---------- storage safety net ---------- */

.storage-banner {
  position: fixed;
  top: calc(10px + var(--safe-top));
  left: 50%;
  width: min(560px, calc(100% - 24px));
  transform: translateX(-50%);
  z-index: 110;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid rgba(251, 113, 133, 0.45);
  border-radius: 16px;
  background: rgba(46, 20, 28, 0.96);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.storage-banner[hidden] { display: none; }

.migration-banner {
  border-color: rgba(251, 191, 36, 0.45);
  background: rgba(41, 33, 15, 0.96);
}

body.has-storage-error .migration-banner { display: none; }

.update-banner {
  position: fixed;
  left: 50%;
  bottom: calc(142px + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(560px, calc(100% - 24px));
  z-index: 105;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(96, 165, 250, 0.45);
  border-radius: 16px;
  background: rgba(18, 30, 48, 0.97);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.update-banner[hidden],
body.sheet-open .update-banner,
body.recovery-mode .update-banner,
body.has-storage-error .update-banner { display: none; }

.update-banner-text {
  flex: 1;
  min-width: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
}

.update-banner-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.update-banner .storage-banner-btn.primary {
  border-color: rgba(52, 211, 153, 0.45);
  background: var(--green-soft);
  color: var(--text);
}

.update-banner .storage-banner-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.storage-banner-text {
  flex: 1;
  min-width: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
}

.storage-banner-actions {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex-shrink: 0;
}

.storage-banner-btn {
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--card-2);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  white-space: nowrap;
  cursor: pointer;
}

.storage-banner-btn:active { transform: scale(0.96); }

.recovery {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 18px calc(24px + var(--safe-bottom));
  overflow-y: auto;
  background:
    radial-gradient(120% 55% at 50% -10%, #2a1720 0%, rgba(8, 11, 17, 0) 60%) no-repeat,
    var(--bg);
}

.recovery[hidden] { display: none; }

.recovery-card {
  width: min(430px, 100%);
  padding: 22px 20px 18px;
  border: 1px solid rgba(251, 113, 133, 0.35);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}

.recovery-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-bottom: 14px;
  border-radius: 14px;
  background: var(--red-soft);
  border: 1px solid rgba(251, 113, 133, 0.45);
  color: var(--red);
  font-size: 24px;
  font-weight: 700;
}

.recovery-title {
  margin: 0 0 8px;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.recovery-text {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.5;
}

.recovery-meta {
  margin: 0 0 16px;
  color: var(--muted-2);
  font-size: 12.5px;
  line-height: 1.45;
}

.recovery-actions {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.recovery-actions .primary-btn,
.recovery-actions .secondary-btn {
  width: 100%;
  margin: 0;
}

.recovery-actions button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.recovery-actions .armed {
  border-color: rgba(251, 113, 133, 0.65);
  color: var(--red);
}

.recovery-hint {
  margin: 13px 0 0;
  color: var(--muted-2);
  font-size: 12.5px;
  line-height: 1.45;
}

.recovery-details {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.recovery-details summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 600;
}

.recovery-details p { margin: 8px 0 0; }

body.recovery-mode { overflow: hidden; }
body.recovery-mode .fab,
body.recovery-mode .tabbar { display: none; }


/* ---------- utility classes (P2-5) ---------- */

.sheet-head-spacer { width: 44px; }
.spacer-6 { height: 6px; }
.spacer-4 { height: 4px; }
.hint-pad { padding: 0 2px 10px; }
.hint-top { padding-top: 8px; }
.hint-planned { margin: -4px 0 12px; }
.hint-subtle { margin: -2px 0 10px; }
.hint-after { margin: 6px 2px 0; }
.hint-version { text-align: center; padding-top: 14px; }
.empty-pad { padding: 28px 10px; }
.segmented-gap { margin-bottom: 14px; }
.segmented-gap-sm { margin-bottom: 12px; }
.legend-gap { margin-bottom: 8px; }
.emoji-input { flex: 0 0 62px; text-align: center; font-size: 21px; padding: 9px 4px; }
.cat .e.currency-emoji { font-size: 21px; }
.cat-grid-4 { grid-template-columns: repeat(4, 1fr); }
.label-green { color: var(--green); }
.value-strong { color: var(--text); font-weight: 600; }
.setting-row .value-strong { color: var(--text); font-weight: 600; }
.text-strong { color: var(--text); }
.dot-income { background: #4ade80; }
.dot-expense { background: #fb7185; }
.amount-income { color: var(--green); }
.sheet-lead { color: var(--muted); font-size: 14.5px; line-height: 1.5; margin: 0 0 10px; }
.sheet-lead-tight { color: var(--muted); font-size: 14.5px; line-height: 1.5; margin: 0 0 6px; }
.sheet-lead-small { color: var(--muted); font-size: 14.5px; line-height: 1.5; margin: 0 0 4px; }
.noscript-note { padding: 24px; text-align: center; }

/* ---------- animations ---------- */

@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes backdrop-out { from { opacity: 1; } to { opacity: 0; } }

@keyframes sheet-swap {
  from { opacity: 0.35; }
  to { opacity: 1; }
}

@keyframes view-soft {
  from { opacity: 0.55; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes period-out-left {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(-100%, 0, 0); }
}

@keyframes period-out-right {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(100%, 0, 0); }
}

@keyframes period-in-right {
  from { transform: translate3d(100%, 0, 0); }
  to { transform: translate3d(0, 0, 0); }
}

@keyframes period-in-left {
  from { transform: translate3d(-100%, 0, 0); }
  to { transform: translate3d(0, 0, 0); }
}

@keyframes period-note-in {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0s !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- wider screens ---------- */

@media (min-width: 620px) {
  .view { padding-left: max(16px, calc(50vw - 290px)); padding-right: max(16px, calc(50vw - 290px)); }
  .tabbar { padding-left: max(6px, calc(50vw - 320px)); padding-right: max(6px, calc(50vw - 320px)); }
  .sheet { left: 0; right: 0; width: 560px; margin: 0 auto; border-radius: 24px 24px 0 0; }
  .fab { right: max(18px, calc(50vw - 320px)); }
  .pending-row:not(.compact) {
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 9px 0;
  }
  .pending-row:not(.compact) .pending-top { flex: 1; min-width: 0; }
  .pending-row:not(.compact) .pending-actions {
    margin-left: auto;
    padding-left: 0;
    justify-content: flex-end;
  }
}

/* ---------- debts ---------- */

.debt-toggle-row {
  margin-top: 10px;
  cursor: pointer;
}
.debt-fields { margin-top: 2px; }
.debt-fields[hidden],
.tx-category-block[hidden] { display: none; }

.debt-summary-card { padding: 16px; }
.debt-summary-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.debt-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 8px;
}
.debt-summary-grid > div {
  font-size: 12px;
  color: var(--muted);
}
.debt-summary-grid b {
  display: block;
  margin-top: 2px;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.debt-summary-grid .in b { color: var(--green); }
.debt-summary-grid .out b { color: var(--red); }
.debt-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}
.debt-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.debt-list-compact { margin-top: 10px; }
.debt-list-closed { opacity: 0.72; }
.debt-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
}
.debt-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}
.debt-avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 10px;
  font-size: 17px;
  font-weight: 700;
}
.debt-avatar.lent { color: var(--green); background: var(--green-soft); }
.debt-avatar.borrowed { color: var(--red); background: var(--red-soft); }
.debt-avatar-inline { font-size: 17px; }
.debt-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.debt-text .tx-title,
.debt-text .tx-sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.debt-amount {
  flex: 0 0 auto;
  font-size: 13.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.debt-amount.lent { color: var(--green); }
.debt-amount.borrowed { color: var(--red); }
.debt-pay {
  flex: 0 0 auto;
  padding: 7px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.debt-pay:active { transform: scale(0.97); }
.debt-badge {
  display: inline-block;
  margin-left: 3px;
  padding: 1px 5px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 9px;
  font-weight: 600;
  vertical-align: 1px;
}
.debt-empty {
  padding: 16px;
  text-align: center;
}
.debt-empty .t { font-size: 14px; font-weight: 600; }
.debt-empty .s { margin-top: 3px; font-size: 12px; color: var(--muted); }
.debt-report-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
  margin-top: 10px;
}
.debt-report-grid > div { font-size: 12px; color: var(--muted); }
.debt-report-grid b {
  display: block;
  margin-top: 2px;
  font-size: 15px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.debt-detail {
  text-align: center;
  padding: 8px 0 4px;
}
.debt-detail-direction { font-size: 12px; color: var(--muted); }
.debt-detail-amount {
  margin-top: 3px;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.debt-detail-meta {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.debt-history { margin-top: 2px; }
.debt-history-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.debt-history-row > span:first-child {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.debt-history-row small { color: var(--muted); font-size: 11.5px; }
.debt-history-amount {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  color: var(--red);
  white-space: nowrap;
}
.debt-history-amount.income { color: var(--green); }
