/* FamFin — мобайл-first тёмная тема */
:root {
  --bg: #0d1b2a;
  --bg2: #15263a;
  --bg3: #1e3349;
  --card: #15263a;
  --border: #26405c;
  --text: #e8eef5;
  --text2: #8aa0b8;
  --accent: #4c7cfa;
  --green: #4caf82;
  --red: #f0556b;
  /* Цвета сумм (настраиваются в «Ещё → Цвета сумм»); по умолчанию = green/red/text */
  --income: #4caf82;
  --expense: #f0556b;
  --balance: #e8eef5;
  --radius: 14px;
  --tabbar-h: 60px;
  --header-h: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* ── Auth ─────────────────────────────────────────────────────────────────── */
.auth-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
  background: radial-gradient(circle at 50% 0%, #1a3354, var(--bg) 70%);
}
.auth-card {
  width: 100%; max-width: 360px; text-align: center;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 20px; padding: 36px 26px;
}
.auth-logo { font-size: 56px; }
.auth-title { font-size: 26px; font-weight: 700; margin-top: 8px; }
.auth-sub { color: var(--text2); font-size: 14px; margin-bottom: 24px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-hint { color: var(--text2); font-size: 12px; margin-top: 16px; }
.alert-err { background: rgba(240,85,107,.15); color: var(--red); padding: 10px; border-radius: 10px; font-size: 14px; margin-bottom: 16px; }

/* ── Inputs / buttons ─────────────────────────────────────────────────────── */
.inp {
  width: 100%; padding: 13px 14px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 11px; color: var(--text); font-size: 16px; outline: none;
  transition: border-color .15s;
}
.inp:focus { border-color: var(--accent); }
.inp::placeholder { color: var(--text2); }
.inp-sm { padding: 9px 11px; font-size: 14px; }
.inp-xs { padding: 6px 8px; font-size: 13px; width: 90px; text-align: right; }
select.inp { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238aa0b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

.btn-primary {
  background: var(--accent); color: #fff; border: none;
  padding: 13px 18px; border-radius: 11px; font-size: 16px; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: opacity .15s;
}
.btn-primary:active { opacity: .8; }
.btn-primary:disabled { opacity: .5; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 14px; border-radius: 9px; }
.btn-ghost {
  background: transparent; color: var(--text2); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 9px; font-size: 14px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}

/* ── App shell ────────────────────────────────────────────────────────────── */
/* position:fixed, а не sticky — на iOS/PWA sticky иногда на один кадр «не прилипает»
   (особенно сразу после location.reload(), которым тут перезагружаются экраны после
   сохранения/удаления операции), и тогда верхний блок экрана заезжает под статус-бар,
   а сама шапка пропадает из виду. fixed не зависит от скролла/времени отрисовки вообще. */
.app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  background: var(--bg); border-bottom: 1px solid var(--border);
  padding-top: var(--safe-t);
}
.app-header-inner {
  height: var(--header-h); display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
}
.app-brand-wrap { display: flex; align-items: baseline; gap: 9px; }
.app-brand { font-weight: 700; font-size: 17px; }
.app-date { font-size: 13px; color: var(--text2); font-weight: 600; }
/* Дата в шапке — прозрачный date-input поверх текста открывает нативный календарь */
.app-date-pick { position: relative; display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.app-date-pick i { color: var(--accent); font-size: 12px; }
.app-date-pick > input[type="date"] { position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; border: 0; padding: 0; margin: 0; cursor: pointer; -webkit-appearance: none; }
.app-date-pick > input[type="date"]::-webkit-calendar-picker-indicator {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.app-user { font-size: 13px; color: var(--text2); display: flex; align-items: center; gap: 5px; }
.app-user i { color: var(--uc, var(--accent)); font-size: 18px; }

.app-main {
  /* Шапка теперь fixed (не в потоке документа) — компенсируем её реальную высоту
     (header-h + safe-t), чтобы контент, как и раньше, начинался сразу под ней. */
  padding-top: calc(var(--header-h) + var(--safe-t));
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px);
  min-height: calc(100vh - var(--header-h));
}
/* ── Tabbar ───────────────────────────────────────────────────────────────── */
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 50;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--bg2); border-top: 1px solid var(--border);
  display: flex;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--text2); text-decoration: none; font-size: 10.5px;
  transition: color .15s;
}
.tab i { font-size: 21px; }
.tab.active { color: var(--accent); }

/* ── Add screen — три зоны: верх/низ фиксированы, середина скроллится ───────── */
.add-screen {
  display: flex; flex-direction: column;
  /* высота = вьюпорт минус шапка и таб-бар */
  height: calc(100dvh - var(--header-h) - var(--tabbar-h) - var(--safe-t) - var(--safe-b));
  padding: 10px 16px 0;
}
.add-top    { flex: 1 1 auto; display: flex; flex-direction: column; gap: 12px; justify-content: center; min-height: 0; }
.add-bottom { flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px; padding: 10px 0; }

.seg { display: flex; background: var(--bg3); border-radius: 14px; padding: 4px; }
.seg-btn {
  flex: 1; padding: 18px; border: none; background: transparent; color: var(--text2);
  font-size: 19px; font-weight: 600; border-radius: 11px; cursor: pointer; transition: all .15s;
}
.seg-btn.active { background: var(--red); color: #fff; }
.seg-btn[data-kind="income"].active { background: var(--green); }

.amount-display {
  position: relative;
  display: flex; align-items: baseline; justify-content: center; gap: 6px;
  text-align: center; padding: 10px 62px; color: var(--expense);
}
.amount-display.income { color: var(--income); }
.amount-display.income .amount-input { color: var(--income); }
/* Галочка-сохранить справа в поле, цвета транзакции.
   Скрыта, пока поле суммы не в фокусе (класс .amt-on) */
.amount-save {
  position: absolute; right: 4px; top: 50%;
  width: 50px; height: 50px; flex-shrink: 0; border: none; border-radius: 50%;
  background: var(--red); color: #fff; font-size: 26px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
  opacity: 0; pointer-events: none; transform: translateY(-50%) scale(.4);
  transition: opacity .15s, transform .15s;
}
.amount-display.income .amount-save { background: var(--green); }
.amount-display.amt-on .amount-save { opacity: 1; pointer-events: auto; transform: translateY(-50%) scale(1); }
.amount-display.amt-on .amount-save:active { transform: translateY(-50%) scale(.92); }
.amount-input {
  width: auto; max-width: 100%; min-width: 1ch; text-align: center;
  border: none; background: transparent; outline: none; padding: 0;
  font-family: inherit; font-size: 64px; font-weight: 700; color: var(--expense);
  letter-spacing: -2px; line-height: 1.05;
  field-sizing: content; /* подгон ширины под содержимое (совр. браузеры) */
}
.amount-input::placeholder { color: var(--border); }
.amount-cur { font-size: 22px; color: var(--text2); font-weight: 500; flex-shrink: 0; }

.add-row { display: flex; gap: 10px; }
.add-row > * { flex: 1; min-width: 0; }

/* Крупные элементы блока добавления (категория, счёт, дата, заметка) */
.add-top .inp-sm { padding: 16px 14px; font-size: 17px; }
.add-top .cat-select-btn { font-size: 18px; }
.add-top .cat-btn-icon { width: 30px; height: 30px; }
.add-top .cat-btn-icon i { font-size: 18px; }
.note-inp { font-size: 17px; }

/* Пункты выпадающего списка категорий — крупные (×2) */
.cat-dd-item { padding: 18px 15px; font-size: 26px; gap: 16px; }
.cat-dd-icon { width: 50px; height: 50px; border-radius: 11px; }
.cat-dd-icon i { font-size: 28px; }

.btn-save { width: 100%; padding: 16px; font-size: 18px; }

/* Низкие экраны (iPhone SE ~568px, мало места) — ужимаем */
@media (max-height: 700px) {
  .amount-input { font-size: 48px; }
  .amount-cur { font-size: 18px; }
  .seg-btn { padding: 13px; font-size: 17px; }
}
@media (max-height: 600px) {
  .amount-input { font-size: 40px; }
  .seg-btn { padding: 11px; font-size: 16px; }
}

/* ── Home screen (главная: итоги + операции за сегодня + Добавить) ─────────── */
.home-screen {
  display: flex; flex-direction: column;
  height: calc(100dvh - var(--header-h) - var(--tabbar-h) - var(--safe-t) - var(--safe-b));
  padding: 12px 16px 0;
}
.today-hero {
  flex: 0 0 auto; display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 4px; margin-bottom: 12px;
}
.hero-cell { position: relative; text-align: center; min-width: 0; border-radius: 12px; padding: 12px 44px; transition: background .15s; }
.hero-cell + .hero-cell { border-top: 1px solid var(--border); }
.hero-cell.tappable { cursor: pointer; }
.hero-cell.tappable:active { background: var(--bg3); }
.hero-add {
  position: absolute; top: 12px; right: 12px; width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg3); color: var(--text2); font-size: 14px;
}
.hero-label { font-size: 12px; color: var(--text2); margin-bottom: 4px; }
.hero-val { font-size: 30px; font-weight: 800; letter-spacing: -1px; white-space: nowrap; }
.hero-val.expense { color: var(--expense); }
.hero-val.income  { color: var(--income); }
.hero-cur { font-size: 15px; font-weight: 600; color: var(--text2); }

.today-list {
  flex: 1 1 auto; overflow-y: auto; min-height: 0;
  overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch;
}
.today-head { font-size: 12px; color: var(--text2); font-weight: 600; margin: 2px 2px 9px; }

.home-foot { flex: 0 0 auto; padding: 10px 0 6px; }
.btn-add-home { width: 100%; padding: 16px; font-size: 18px; font-weight: 700; }

@media (max-height: 700px) { .hero-val { font-size: 25px; } }

/* ── Полноэкранная модалка ввода ──────────────────────────────────────────── */
.modal-full {
  position: fixed; inset: 0; z-index: 150; background: var(--bg);
  display: flex; flex-direction: column; animation: slideUp .22s;
}
.mf-head {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 14px 10px; border-bottom: 1px solid var(--border);
}
.mf-x {
  width: 34px; height: 34px; flex-shrink: 0; border: none; border-radius: 9px;
  background: var(--bg3); color: var(--text); font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.mf-title { font-weight: 700; font-size: 16px; }
.mf-kind { text-align: center; font-size: 24px; font-weight: 800; letter-spacing: 2px; }
.mf-kind.expense { color: var(--expense); }
.mf-kind.income  { color: var(--income); }
.mf-date { display: flex; flex-direction: column; gap: 6px; }
.mf-date-cap { font-size: 12px; color: var(--text2); font-weight: 600; }
.mf-body {
  flex: 1 1 auto; overflow-y: auto; padding: 18px 16px;
  display: flex; flex-direction: column; gap: 16px;
}
.mf-foot { flex: 0 0 auto; padding: 12px 16px calc(12px + var(--safe-b)); border-top: 1px solid var(--border); }

/* Локальное распознавание чека */
.receipt-scan { display: flex; flex-direction: column; gap: 10px; }
.receipt-scan-btn {
  min-height: 44px; width: 100%; display: flex; align-items: center; justify-content: center; gap: 9px;
  padding: 10px 14px; border: 1px dashed color-mix(in srgb, var(--expense) 68%, var(--border));
  border-radius: 11px; background: color-mix(in srgb, var(--expense) 8%, var(--bg3));
  color: var(--expense); font: inherit; font-weight: 700; cursor: pointer;
}
.receipt-scan-btn i { font-size: 19px; }
.receipt-scan-btn:disabled { opacity: .55; cursor: wait; }
.receipt-status {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 11px;
  background: var(--bg3); color: var(--text2); font-size: 12px;
}
.receipt-status.ok { border-color: color-mix(in srgb, var(--green) 55%, var(--border)); }
.receipt-status.error { border-color: color-mix(in srgb, var(--red) 60%, var(--border)); color: var(--red); }
.receipt-status-line { display: flex; align-items: center; gap: 7px; }
.receipt-status-line > span { flex: 1; min-width: 0; }
.receipt-status-line > strong { color: var(--text); font-variant-numeric: tabular-nums; }
.receipt-progress { height: 3px; margin-top: 9px; overflow: hidden; border-radius: 3px; background: var(--border); }
.receipt-progress > span { display: block; width: 0; height: 100%; background: var(--accent); transition: width .18s; }
.receipt-result { margin-top: 8px; color: var(--text); font-weight: 600; line-height: 1.45; }

/* ── Разметка чека по продавцу (receipt_rules) ───────────────────────────────── */
.receipt-markup-toggle {
  margin-top: 8px; width: 100%; text-align: left; background: none; border: none;
  color: var(--accent); font-size: 12px; font-weight: 600; padding: 4px 0; cursor: pointer;
}
.receipt-markup { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.receipt-markup-hint { font-size: 11.5px; color: var(--text2); margin-bottom: 8px; line-height: 1.4; }
.rm-line {
  display: flex; align-items: center; gap: 6px; padding: 6px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}
.rm-line:last-child { border-bottom: none; }
.rm-line-text {
  flex: 1; min-width: 0; font-size: 12px; color: var(--text); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; font-family: ui-monospace, monospace;
}
.rm-btn {
  flex-shrink: 0; width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg3); color: var(--text2); font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.rm-btn:active { opacity: .7; }
.rm-btn.rm-amount:active, .rm-btn.rm-amount:hover { color: var(--income); border-color: var(--income); }
.rm-btn.rm-date:active, .rm-btn.rm-date:hover { color: var(--accent); border-color: var(--accent); }

/* Выбор валюты */
.cur-seg { display: flex; gap: 8px; }
.cur-btn {
  flex: 1; padding: 11px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 11px; color: var(--text2); font-size: 17px; font-weight: 700; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.cur-btn small { font-size: 11px; font-weight: 500; color: var(--text2); }
.cur-btn.active {
  border-color: var(--accent); color: var(--text);
  background: color-mix(in srgb, var(--accent) 14%, var(--bg3));
}

/* Заметка с подсказками */
.note-field { position: relative; }
.note-suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 5px); z-index: 5;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; max-height: 44vh; overflow-y: auto;
  box-shadow: 0 12px 34px rgba(0,0,0,.45);
}
.ns-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%;
  padding: 12px 13px; background: transparent; border: none; border-bottom: 1px solid var(--border);
  color: var(--text); font-size: 14px; cursor: pointer; text-align: left;
}
.ns-item:last-child { border-bottom: none; }
.ns-item:active { background: var(--bg3); }
.ns-note { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ns-cat { display: inline-flex; align-items: center; gap: 5px; flex-shrink: 0; font-size: 12px; color: var(--cc); }

/* Определённая категория */
.cat-detected { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text2); }
.cd-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 20px;
  background: color-mix(in srgb, var(--cc) 18%, transparent); color: var(--cc); font-weight: 600; font-size: 13px;
}

/* ── List screen ──────────────────────────────────────────────────────────── */
.list-screen {
  height: calc(100dvh - var(--header-h) - var(--tabbar-h) - var(--safe-t) - var(--safe-b));
  padding: 14px 16px 0;
  display: flex; flex-direction: column; min-height: 0;
}
.list-top { flex: 0 0 auto; }
.list-scroll {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding-bottom: 12px; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.page-pad { padding: 14px 16px; }
.page-title { font-size: 22px; font-weight: 700; margin-bottom: 14px; }
.page-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.page-title-row .page-title { margin-bottom: 0; }
.report-step {
  flex: 0 0 auto; border-radius: 10px; padding: 3px;
}
.report-step .seg-btn {
  padding: 6px 9px; border-radius: 8px; font-size: 12px; line-height: 1.1;
}

/* Панель возврата: список операций открыт из «Бюджета» (?from=budget) */
.ctx-back { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; padding: 9px 12px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  color: var(--text2); text-decoration: none; font-size: 14px; }
.ctx-back > i { font-size: 15px; }
.ctx-back b { margin-left: auto; display: flex; align-items: center; gap: 6px;
  color: var(--text); font-weight: 600; min-width: 0; }
.ctx-back b span, .ctx-back b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctx-back:active { transform: scale(.99); }

.month-nav { position: relative; display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
/* Скрытый date-input под заголовком — по клику открывает нативный календарь рядом */
.date-hidden { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%);
  width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; margin: 0; pointer-events: none; }
.month-arrow {
  width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  background: var(--bg3); border-radius: 10px; color: var(--text); text-decoration: none; font-size: 18px;
}
.month-label { font-weight: 600; font-size: 16px; color: var(--text); }
.month-label.is-date { color: var(--accent); }

.summary-row { display: flex; gap: 9px; margin-bottom: 16px; }
.sum-card { flex: 1; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 11px 12px; }
.sum-label { font-size: 11px; color: var(--text2); margin-bottom: 3px; }
.sum-val { font-size: 15px; font-weight: 700; }
.sum-card.income .sum-val { color: var(--income); }
.sum-card.expense .sum-val { color: var(--expense); }
.sum-card.balance .sum-val { color: var(--balance); }
/* плашки-фильтры (ссылки) */
a.sum-card { text-decoration: none; color: inherit; cursor: pointer; transition: border-color .12s, background .12s; }
a.sum-card:active { transform: scale(.98); }
.sum-card.income.active  { border-color: var(--green); background: rgba(81,207,102,.10); }
.sum-card.expense.active { border-color: var(--red);   background: rgba(240,85,107,.10); }

/* строка поиска + фильтр категории */
.list-filter { display: flex; align-items: stretch; gap: 8px; margin-bottom: 14px; }
.lf-search { flex: 1 1 0; min-width: 0; display: flex; align-items: center; gap: 7px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 0 11px; }
.lf-search i { color: var(--text2); font-size: 14px; flex: 0 0 auto; }
.lf-search input { flex: 1; background: none; border: 0; outline: none; color: var(--text);
  font-size: 14px; padding: 10px 0; min-width: 0; }
.lf-cat { flex: 1 1 auto; min-width: 0; height: 42px; background-color: var(--card); border: 1px solid var(--border);
  border-radius: 12px; color: var(--text); font-size: 14px; padding: 0 32px 0 11px; outline: none;
  text-overflow: ellipsis; -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238aa0b8' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'><path d='M4 6l4 4 4-4'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 14px; }
/* Кнопка-лупа: открывает модалку поиска */
.lf-icon { flex: 0 0 auto; width: 44px; height: 42px; display: flex; align-items: center; justify-content: center;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  color: var(--text2); font-size: 16px; cursor: pointer; }
.lf-icon.active { color: var(--accent); border-color: var(--accent); }
.lf-icon:active { transform: scale(.96); }
/* Выбор даты — слева от категорий, шириной чётко под дату; со словом «Дата», когда пусто */
.lf-date { flex: 0 0 auto; width: 10.4em; height: 42px; position: relative;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; }
.lf-date input { width: 100%; height: 100%; background: transparent; border: 0; outline: none;
  color: var(--text); font-family: inherit; font-size: 14px; padding: 0 10px; text-align: left; }
.lf-date input::-webkit-datetime-edit { text-align: left; }
/* Нативный индикатор скрыт, но прозрачно кликабелен по правому краю (открывает пикер) */
.lf-date input::-webkit-calendar-picker-indicator { position: absolute; right: 0; top: 0;
  width: 34px; height: 100%; margin: 0; padding: 0; opacity: 0; cursor: pointer; }
/* Иконка календаря приложения — только в пустом состоянии, рядом со словом «Дата» */
.lf-date-ic { display: none; position: absolute; right: 11px; top: 50%; transform: translateY(-50%);
  color: var(--text2); font-size: 15px; pointer-events: none; }
.lf-date.is-empty .lf-date-ic { display: block; }
.lf-date.is-empty input::-webkit-datetime-edit { display: none; }   /* убираем дд.мм.гггг под «Дата» */
.lf-date-ph { display: none; }
.lf-date.is-empty .lf-date-ph { display: block; position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%); color: var(--text); font-size: 14px; font-family: inherit; pointer-events: none; }
.lf-clear { flex: 0 0 auto; display: flex; align-items: center; justify-content: center; width: 40px; height: 42px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; color: var(--text2);
  text-decoration: none; font-size: 13px; }
.lf-clear:active { transform: scale(.96); }

.day-group { margin-bottom: 16px; }
.day-head { font-size: 12px; color: var(--text2); margin-bottom: 7px; font-weight: 600;
    display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.day-tot { display: flex; gap: 10px; font-weight: 700; white-space: nowrap; }
.day-tot .dt-exp { color: var(--expense); }
.day-tot .dt-inc { color: var(--income); }

.tx-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px;
  background: var(--card); border-radius: 12px; margin-bottom: 7px; cursor: pointer;
  transition: opacity .25s, height .25s, margin .25s, padding .25s;
}
.tx-item.removing { opacity: 0; height: 0 !important; margin: 0; padding: 0 12px; overflow: hidden; }
.tx-icon { width: 40px; height: 40px; flex-shrink: 0; border-radius: 11px; display: flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--cc) 20%, transparent); }
.tx-icon i { font-size: 19px; color: var(--cc); }
.tx-body { flex: 1; min-width: 0; }
.tx-cat { font-size: 14.5px; font-weight: 600; }
.tx-meta { font-size: 12px; color: var(--text2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-author { color: var(--uc); margin-left: 4px; }
.tx-amount { font-size: 15px; font-weight: 700; white-space: nowrap; }
.tx-amount.income { color: var(--income); }
.tx-amount.expense { color: var(--expense); }
.tx-cur { font-size: 11px; color: var(--text2); font-weight: 500; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--text2); }
.empty-state i { font-size: 48px; opacity: .4; }
.empty-state p { margin: 12px 0; }

/* ── Soon card ────────────────────────────────────────────────────────────── */
.soon-card { text-align: center; padding: 40px 20px; color: var(--text2); background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); margin-top: 16px; }
.soon-card i { font-size: 44px; color: var(--accent); opacity: .6; }
.soon-card h3 { margin: 12px 0 8px; color: var(--text); font-size: 17px; }
.soon-card p { font-size: 13px; line-height: 1.5; }

/* ── Графики (отчёты) ─────────────────────────────────────────────────────── */
.seg-accent .seg-btn.active { background: var(--accent); color: #fff; }
.chart-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 12px 6px; margin-bottom: 12px; }
.chart-head { display: flex; align-items: center; gap: 7px; font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.chart-head .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.chart-toggle {
  border: 1px solid rgba(138,160,184,.45); background: transparent; color: rgba(138,160,184,.65);
  border-radius: 8px; padding: 3px 8px; font-size: 11px; font-weight: 700;
  cursor: pointer; line-height: 1.2;
}
.chart-toggle.active {
  border-color: #ff5a36; color: #ff5a36; background: transparent;
}
.chart-total { margin-left: auto; font-size: 13px; font-weight: 600; color: var(--text2); }
svg.chart { width: 100%; height: auto; display: block; }

/* ── Budget ───────────────────────────────────────────────────────────────── */
.budget-total { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 16px; }
.bt-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; }
.bt-row b.over { color: var(--expense); }
.bt-row b.good { color: var(--income); }
.budget-item { position: relative; background: var(--card); border-radius: 12px; padding: 12px 38px 12px 12px; margin-bottom: 8px; cursor: pointer; }
.budget-item.dragging { opacity: .6; transform: scale(1.03); box-shadow: 0 4px 14px rgba(0,0,0,.4); }
.drag-handle { position: absolute; right: 4px; top: 0; bottom: 0; width: 32px;
  display: flex; align-items: center; justify-content: center; color: var(--text2);
  font-size: 18px; cursor: grab; touch-action: none;
  user-select: none; -webkit-user-select: none; }
/* touch-action не наследуется: если палец попадёт по иконке, браузер начнёт
   прокрутку и отменит перетаскивание — гасим у иконки указательные события */
.drag-handle i { pointer-events: none; }
.drag-handle:active { cursor: grabbing; }
.bi-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 14px; }
.bi-cat { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.bi-nums-wrap { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex-shrink: 0; }
.bi-nums { font-size: 13px; color: var(--text2); }
.bi-avg { font-size: 11px; color: var(--text2); font-weight: 500; opacity: .75; }
.bi-bar { height: 7px; background: var(--bg3); border-radius: 4px; overflow: hidden; }
.bi-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width .3s; }
.bi-fill.over { background: var(--red); }
.bi-fill.income { background: var(--green); }
.bi-nums.over { color: var(--expense); }
.bi-nums.good { color: var(--income); }
.budget-section { margin-bottom: 22px; }
.budget-sec-head { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 700; color: var(--text); margin: 6px 0 10px; }
.budget-sec-head i { font-size: 18px; color: var(--text2); }

/* ── Settings ─────────────────────────────────────────────────────────────── */
.set-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.set-card-head { font-weight: 600; font-size: 14px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; color: var(--text); }
.set-card-head i { color: var(--accent); }
/* привязка категории FamFin → bxapp (Финансы) в модалке категории */
.bx-map-lbl { display: block; margin-bottom: 14px; }
.bx-map-cap { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text2); font-weight: 600; margin: 0 2px 5px; }
.bx-map-cap i { color: var(--accent); }
.bx-map-lbl .inp { margin-bottom: 0; }
.set-card .inp { margin-bottom: 9px; }
.set-card .btn-primary, .set-card .btn-ghost { margin-right: 8px; }
.set-field { display: block; margin-bottom: 10px; }
.set-field-label { display: block; color: var(--text2); font-size: 12px; font-weight: 600; margin: 0 2px 5px; }
.set-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.set-row:last-of-type { border-bottom: none; }
.set-row small { color: var(--text2); }
/* Строка выбора цвета сумм */
.color-row { display: flex; justify-content: space-between; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.color-row:last-of-type { border-bottom: none; }
.color-row .cr-name { display: flex; align-items: center; gap: 8px; }
.color-row .cr-dot { width: 14px; height: 14px; border-radius: 50%; }
.color-row input[type="color"] {
  width: 46px; height: 30px; padding: 0; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg3); cursor: pointer;
}
.color-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 3px; }
.color-row input[type="color"]::-webkit-color-swatch { border: none; border-radius: 5px; }
.x-btn { background: transparent; border: none; color: var(--text2); font-size: 18px; cursor: pointer; padding: 2px 6px; }
.set-add { display: flex; gap: 8px; margin-top: 10px; }
.set-add .inp { margin-bottom: 0; }
.set-add-col { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.cat-mini-grid { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 4px; }
.cat-mini { display: inline-flex; align-items: center; gap: 5px; background: var(--bg3); border-radius: 8px; padding: 5px 9px; font-size: 12.5px; }
.cat-mini i { color: var(--cc); }
.cat-count { background: var(--bg2); color: var(--text2); border-radius: 20px; padding: 1px 7px; font-size: 11px; font-weight: 600; min-width: 18px; text-align: center; }
.cat-mini.cat-empty { opacity: .55; }
.cat-mini.cat-empty .cat-count { background: rgba(240,85,107,.18); color: var(--red); }
.cat-mini-grid .cat-mini { touch-action: none; user-select: none; -webkit-user-select: none; }
.cat-mini.dragging { opacity: .6; transform: scale(1.08); box-shadow: 0 4px 14px rgba(0,0,0,.4); }
.x-btn-mini { background: transparent; border: none; color: var(--text2); cursor: pointer; font-size: 15px; line-height: 1; padding: 0 0 0 2px; }
.rate-edit { display: flex; align-items: center; }
.text-muted { color: var(--text2); }

/* ── Modal sheet ──────────────────────────────────────────────────────────── */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 100; display: flex; align-items: flex-end; }
.modal-sheet {
  width: 100%; background: var(--bg2); border-radius: 20px 20px 0 0;
  padding: 22px 18px calc(22px + var(--safe-b)); animation: slideUp .25s;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-sheet h3 { font-size: 17px; margin-bottom: 14px; }
.modal-sheet .inp { margin-bottom: 14px; }
.modal-sheet .seg { margin-bottom: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; align-items: center; }
.modal-actions .danger { margin-right: auto; color: var(--red); font-size: 18px; padding: 8px 12px; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); left: 50%;
  transform: translateX(-50%) translateY(20px); z-index: 200;
  background: var(--bg3); color: var(--text); padding: 11px 20px; border-radius: 24px;
  font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,.4); white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.ok { border-color: var(--green); color: var(--green); }

.d-none { display: none !important; }
.btn-block { width: 100%; }
.mt-2 { margin-top: 10px; }

/* ── Кастомный select категории (с иконкой) ───────────────────────────────── */
.cat-select-btn {
  display: flex; align-items: center; justify-content: space-between;
  text-align: left; cursor: pointer; font-size: 16px;
}
.cat-btn-placeholder { color: var(--text2); }
.cat-btn-picked { display: flex; align-items: center; gap: 8px; color: var(--text); }
.cat-btn-icon, .cat-dd-icon {
  width: 26px; height: 26px; flex-shrink: 0; border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--cc) 20%, transparent);
}
.cat-btn-icon i, .cat-dd-icon i { color: var(--cc); font-size: 15px; }

.cat-dd-list { display: flex; flex-direction: column; gap: 4px; max-height: 60vh; overflow-y: auto; }
.cat-dd-item {
  display: flex; align-items: center; gap: 11px; padding: 11px 10px;
  background: var(--bg3); border: none; border-radius: 11px; color: var(--text);
  font-size: 15px; cursor: pointer; text-align: left; width: 100%;
}
.cat-dd-item:active { background: var(--bg); }

/* ── Пикер иконок ─────────────────────────────────────────────────────────── */
.icon-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px;
  max-height: 55vh; overflow-y: auto;
}
.icon-opt {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  background: var(--bg3); border: 1.5px solid transparent; border-radius: 11px;
  color: inherit; cursor: pointer; font-size: 20px;
}
.icon-opt.sel { border-color: currentColor; background: color-mix(in srgb, currentColor 18%, var(--bg3)); }
/* Палитра цветов */
.color-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; justify-content: center; }
.color-opt {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; padding: 0; flex-shrink: 0;
}
.color-opt.sel { border-color: #fff; box-shadow: 0 0 0 2px var(--bg2); }
.icon-pick-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 11px 14px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 11px; color: var(--text2); cursor: pointer; font-size: 14px; margin-bottom: 9px;
}
.icon-pick-btn i { font-size: 22px; color: var(--accent); }

/* ── Счета/категории в настройках ─────────────────────────────────────────── */
.acc-row { gap: 8px; }
.star-btn { background: transparent; border: none; color: var(--text2); font-size: 18px; cursor: pointer; padding: 2px 4px; flex-shrink: 0; }
.star-btn.on { color: #f5b50a; }
.acc-tap { flex: 1; min-width: 0; cursor: pointer; display: flex; align-items: center; gap: 7px; overflow: hidden; }
.acc-tap small { color: var(--text2); white-space: nowrap; }

/* Шаблон чека: имени продавца недостаточно места в одну строку (признаки
   суммы/даты + заметка + чип категории) — раскладываем в колонку, с переносом. */
.rr-tap { flex: 1; min-width: 0; cursor: pointer; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; }
.rr-tap-head { display: flex; align-items: center; gap: 7px; }
.rr-tap small { color: var(--text2); white-space: normal; line-height: 1.4; }
.cat-kind-label { font-size: 11px; color: var(--text2); margin: 8px 0 6px; text-transform: uppercase; letter-spacing: .04em; }
.cat-mini { cursor: pointer; }

/* ── Desktop adaptation ───────────────────────────────────────────────────── */
@media (min-width: 768px) {
  .app-main { max-width: 560px; margin: 0 auto; }
  .app-header-inner { max-width: 560px; margin: 0 auto; }
  .tabbar { max-width: 560px; left: 50%; transform: translateX(-50%); border-radius: 16px 16px 0 0; }
  .modal-sheet { max-width: 440px; margin: 0 auto; border-radius: 18px; }
  .modal-back { align-items: center; }
  .modal-full { max-width: 480px; left: 50%; right: auto; transform: translateX(-50%); animation: none; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
