/* Аренда — учёт доходов и расходов. Тема и компоненты. */

:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --text: #0f172a;
  /* Приглушённый текст: не светлее, иначе на сером фоне страницы падает ниже
     4.5:1 (норма WCAG AA для мелкого текста). Этот оттенок даёт 5.2:1. */
  --muted: #596579;
  --border: #e2e8f0;
  --primary: #4f46e5;
  /* Фон основной кнопки и активного чипа (белая надпись поверх). В светлой
     теме совпадает с --primary; в тёмной — отдельный оттенок: там --primary
     светлеет ради контраста в тексте, и белая надпись на нём не читается. */
  --primary-strong: #4f46e5;
  --primary-soft: #eef2ff;
  --income: #047857;
  --income-soft: #ecfdf5;
  /* Красный расходов: не ярче, иначе на сером фоне страницы и на мягко-красных
     плашках падает ниже 4.5:1. Этот оттенок даёт 5.1:1. */
  --expense: #c81e1e;
  --expense-soft: #fef2f2;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --nav-h: 62px;
}

/* Тёмная тема: по системным настройкам или по ручному выбору (data-theme на <html>) */
:root[data-theme='dark'] {
  --bg: #0b1220;
  --surface: #111a2e;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #1e293b;
  --primary: #818cf8;
  /* белая надпись на этом фоне — 5.4:1; сама кнопка различима на тёмном (3.5:1) */
  --primary-strong: #5b54ea;
  --primary-soft: #1e1b4b;
  --income: #34d399;
  --income-soft: #052e21;
  --expense: #f87171;
  --expense-soft: #2a1215;
  --warn: #fbbf24;
  --warn-soft: #3a2a08;
  --shadow: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0b1220;
    --surface: #111a2e;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #1e293b;
    --primary: #818cf8;
    --primary-soft: #1e1b4b;
    --income: #34d399;
    --income-soft: #052e21;
    --expense: #f87171;
    --expense-soft: #2a1215;
    --warn: #fbbf24;
    --warn-soft: #3a2a08;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

/* Кнопка наследует цвет текста. Без этого кнопка-карточка (например,
   «Бесплатная версия» на «Обзоре») получает чёрный текст браузера по умолчанию
   и в тёмной теме становится нечитаемой. */
button { color: inherit; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- Шапка ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

/* Бейдж плана в шапке: Free / Pro; жёлтый, когда подписка скоро закончится */
.plan-pill {
  height: 36px;
  padding: 0 11px;
  border-radius: 10px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.2px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}

.plan-pill--pro {
  border-color: transparent;
  background: var(--income-soft);
  color: var(--income);
}

.plan-pill--soon {
  background: var(--warn-soft);
  color: var(--warn);
}

/* ---------- Контент ---------- */

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 16px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom));
}

.section-title {
  margin: 6px 2px -4px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Заголовок раздела с кнопкой действия справа (например, «Залоги» + «+ Залог») */
.section-title--row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Сумма в заголовке раздела платежей («Просрочено · 4 500 ₽») */
.section-title__sum {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: normal;
  text-transform: none;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Кнопка «✎ Изменить» в правом верхнем углу карточки объекта */
.prop-card__toolbar {
  display: flex;
  justify-content: flex-end;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.footnote {
  margin: 2px 2px 0;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Кнопки ---------- */

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn--primary {
  background: var(--primary-strong);
  border-color: var(--primary-strong);
  color: #fff;
}

.btn--ghost {
  background: var(--primary-soft);
  border-color: transparent;
  color: var(--primary);
}

.btn--danger {
  background: var(--expense-soft);
  border-color: transparent;
  color: var(--expense);
}

.btn--block { width: 100%; }

.btn--sm { padding: 7px 11px; font-size: 13px; }

.icon-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ---------- Переключение месяцев ---------- */

.month-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 10px;
}

.month-nav__label {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: 16px;
}

/* ---------- Показатели ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 12px 10px;
  min-width: 0;
}

.stat__label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 4px;
}

.stat__value {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.is-income { color: var(--income); }
.is-expense { color: var(--expense); }

/* ---------- Разбивка по объектам ---------- */

.break-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 11px 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.card > :last-child,
.tx-row--last { border-bottom: 0 !important; }

.break-row__name { font-weight: 600; font-size: 15px; }

.break-row__sub {
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--muted);
}

.break-row__net { font-weight: 700; white-space: nowrap; }

/* ---------- Операции ---------- */

.tx-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.tx-row__main { flex: 1; min-width: 0; }

.tx-row__title { font-weight: 600; font-size: 15px; }

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

.tx-row__amount {
  font-weight: 700;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.date-head {
  margin: 4px 2px -6px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
}

/* ---------- Фильтры ---------- */

.filters {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 15px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.chip.is-active {
  background: var(--primary-strong);
  border-color: var(--primary-strong);
  color: #fff;
}

/* Счётчик внутри чипа-фильтра (например, «К оплате 3») */
.chip__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 19px;
  height: 19px;
  margin-left: 7px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 11.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Есть просрочки — счётчик «К оплате» красный, чтобы долг был виден сразу */
.chip__count--alert {
  background: var(--expense);
  color: #fff;
}

.chip.is-active .chip__count {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.chip.is-active .chip__count--alert {
  background: var(--expense);
  color: #fff;
}

.filter-select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

/* ---------- Объекты ---------- */

.prop-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.prop-card {
  display: block;
  width: 100%;
  border: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.prop-card__name { font-size: 16px; font-weight: 700; }

.prop-card__address {
  margin-top: 2px;
  font-size: 13px;
  color: var(--muted);
}

.prop-card__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 10px;
  font-size: 13.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.prop-card__net { color: var(--text); font-weight: 700; }

.prop-card__dep {
  margin-top: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
}

.prop-card__note {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  font-size: 13px;
  color: var(--muted);
}

/* Объект за лимитом бесплатной версии: виден с замком, но закрыт */
.prop-card--locked {
  opacity: 0.72;
}

.prop-card__locked {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  font-size: 12.5px;
  color: var(--warn);
}

/* ---------- Пустые состояния ---------- */

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

.empty__icon { font-size: 30px; margin-bottom: 8px; }

.empty__title {
  color: var(--text);
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 4px;
}

.empty__text { font-size: 14px; margin-bottom: 14px; }

/* ---------- Нижняя навигация ---------- */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 640px;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  z-index: 20;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 7px 0 5px;
  min-width: 0;
}

.nav-btn svg { width: 21px; height: 21px; }

.nav-btn.is-active { color: var(--primary); }

/* ---------- Модальные окна ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
}

.modal {
  background: var(--surface);
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  border-radius: 18px 18px 0 0;
  animation: sheet-up 0.18s ease;
}

@media (min-width: 640px) {
  .modal { border-radius: 18px; }
}

@keyframes sheet-up {
  from { transform: translateY(14px); opacity: 0.6; }
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 18px 8px;
}

.modal__head h2 {
  margin: 0;
  font-size: 18px;
}

.modal__body {
  padding: 6px 18px calc(18px + env(safe-area-inset-bottom));
  overflow-y: auto;
}

/* ---------- Формы ---------- */

.form-row { margin-bottom: 14px; }

.form-row label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.form input,
.form select,
.form textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
}

.form textarea { resize: vertical; }

.form-grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--bg);
  border-radius: 12px;
  padding: 4px;
}

.seg-btn {
  border: 0;
  background: transparent;
  border-radius: 9px;
  padding: 9px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}

.seg-btn.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.form-actions .btn--block { flex: 1; }

/* ---------- Тост ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%) translateY(8px);
  background: #111827;
  color: #f9fafb;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
  max-width: 90vw;
}

.toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.error-card { color: var(--expense); font-size: 14px; }

/* ---------- Импорт ---------- */

.import-info { margin-bottom: 14px; }

.import-info__row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.import-info__row:last-child { border-bottom: 0; }

.import-info__label { color: var(--muted); flex-shrink: 0; }

.import-info__value { text-align: right; word-break: break-word; }

.import-warning {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--expense-soft);
  color: var(--expense);
  font-size: 13.5px;
}

.form-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
  font-size: 13.5px;
  color: var(--muted);
  cursor: pointer;
}

.form-check input {
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
  padding: 0;
  flex-shrink: 0;
  accent-color: var(--primary);
}

/* ---------- Кнопка темы ---------- */

.theme-btn { font-size: 16px; line-height: 1; }

/* ---------- Платежи ---------- */

.pay-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Grid, а не flex-строка: у просроченной карточки между «main» и «side»
   есть ещё строка «Не оплачено: …» — она должна занимать всю ширину,
   а не сжиматься в третью колонку (иначе выдавливает заголовок в ноль). */
.pay-card {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 4px 12px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.pay-card--overdue { border-left: 4px solid var(--expense); }

.pay-card__main {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  padding: 0;
}

.pay-card__title { font-weight: 600; font-size: 15px; }

/* Имя объекта над заголовком карточки — чтобы платёж находился глазами,
   когда на экране объекты вперемешку (фильтр «Все объекты») */
.pay-card__prop {
  margin-bottom: 3px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pay-card__meta {
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--muted);
}

.pay-card__side {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.pay-card__amount {
  font-weight: 700;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.overdue-note {
  grid-column: 1 / -1;
  grid-row: 2;
  font-size: 12.5px;
  color: var(--expense);
}

.status-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-chip--paid { background: var(--primary-soft); color: var(--primary); }
.status-chip--upcoming { background: var(--bg); color: var(--text); }
.status-chip--overdue { background: var(--expense-soft); color: var(--expense); }
.status-chip--paused { background: var(--bg); color: var(--muted); }

.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  /* Зона нажатия — вся подпись («оплачено», «передано»). Расширяем её по
     вертикали до 36px; отрицательные поля держат строку на месте. */
  min-height: 36px;
  padding: 9px 0;
  margin: -9px 0;
}

.check__input {
  width: 20px;
  height: 20px;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--primary-strong);
}

.check__input:disabled { cursor: not-allowed; }
.check__input:disabled ~ * { cursor: default; }

/* Сводка платежей на дашборде */

.pay-summary {
  display: block;
  width: 100%;
  border: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.pay-summary__row { font-size: 14px; font-weight: 600; }

.pay-summary__overdue {
  margin-top: 4px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--expense);
}

/* ---------- Аналитика ---------- */

.chart svg {
  width: 100%;
  height: auto;
  display: block;
}

.chart-label { fill: var(--muted); }

.chart-legend {
  display: flex;
  gap: 16px;
  margin: 0 2px 8px;
  font-size: 12.5px;
  color: var(--muted);
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
}

.legend-dot--income { background: #10b981; }
.legend-dot--expense { background: #f87171; }

.bar-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bar-row__top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
  font-size: 13.5px;
}

.bar-row__name { font-weight: 600; }

.bar-row__value {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.bar-row__track {
  height: 6px;
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
}

.bar-row__fill {
  height: 100%;
  border-radius: 999px;
  background: var(--expense);
}

/* ---------- Счётчики ---------- */

.meter-card { display: flex; flex-direction: column; }

/* Счётчик, чьи показания ещё не переданы — красная полоса, как у просрочки */
.meter-card--attention { border-left: 4px solid var(--expense); }

/* Статус в шапке карточки счётчика не сжимается и не давит название */
.meter-card__head .status-chip {
  flex-shrink: 0;
  margin-left: 8px;
}

/* Ряд кнопок под шапкой карточки счётчика («✓ Передано», «+ Показание», «Изменить») */
.meter-card__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin: 10px 0 2px;
}

.meter-card__head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.meter-icon { font-size: 20px; flex-shrink: 0; }

.meter-card__title { flex: 1; min-width: 0; }

.meter-meta {
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--muted);
}

/* Строка показания. В узкой карточке — в две линии, чтобы на телефоне ничего
   не переезжало:
       дата                                       галочка «передано»
       показание            расход и стоимость   удалить
   Раньше строка шла в одну линию с переносом: кнопка удаления падала на
   отдельную строку слева, оторвавшись от показания. В широкой карточке
   (правило ниже, по ширине самой карточки) — по-прежнему одна строка. */
.reading-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas:
    'date date toggle'
    'value delta delete';
  align-items: center;
  column-gap: 8px;
  row-gap: 2px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}

.reading-row__date {
  grid-area: date;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.reading-row__val {
  grid-area: value;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.reading-row__delta {
  grid-area: delta;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.reading-row .check {
  grid-area: toggle;
  justify-self: end;
}

.reading-row__del { grid-area: delete; justify-self: end; }

/* Ширина карточки — то, от чего зависит, влезает ли строка в одну линию
   (не ширина окна): карточка счётчика и есть контейнер. */
.meter-card { container: meter-card / inline-size; }

@container meter-card (min-width: 400px) {
  .reading-row {
    grid-template-columns: auto auto 1fr auto auto;
    grid-template-areas: 'date value delta toggle delete';
    row-gap: 0;
  }
}

.link-btn {
  border: 0;
  background: none;
  color: var(--primary);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  /* Зона нажатия не меньше 32×32: крестик «удалить» размером 18px легко
     промахнуть мимо на телефоне — а рядом стоит галочка «передано».
     Отрицательные поля не раздвигают строку. */
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  min-height: 32px;
  padding: 0;
  margin: -7px -6px;
}

.link-btn--danger { color: var(--expense); }

/* ---------- Залоги ---------- */

.dep-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 11px 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

/* Левая часть строки платежа — кнопка (клик открывает форму). Сброс стиля
   браузера обязателен: без него строка рисовалась серой плашкой с рамкой,
   а в тёмной теме её светлый текст на этой плашке пропадал. */
.dep-row__main {
  flex: 1;
  min-width: 0;
  border: 0;
  padding: 0;
  margin: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.dep-row__title { font-weight: 600; font-size: 15px; }

.dep-row__meta {
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--muted);
}

.dep-row__right {
  text-align: right;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.dep-row__right-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.dep-row__amount {
  font-weight: 700;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---------- Сроки договоров и контакты ---------- */

.status-chip--soon { background: var(--warn-soft); color: var(--warn); }

.contract-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.contract-row__label {
  color: var(--muted);
  font-weight: 600;
  font-size: 13.5px;
}

.contract-warning {
  margin: 0 0 6px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 13.5px;
  font-weight: 600;
}

.contract-warning:last-child { margin-bottom: 0; }

.contract-summary {
  display: block;
  width: 100%;
  border: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.prop-card__dep--warn { color: var(--warn); }

.prop-contacts {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

.prop-contacts__title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.prop-contacts__item {
  display: inline-block;
  margin: 0 8px 6px 0;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  word-break: break-word;
}

a.prop-contacts__item:hover { text-decoration: underline; }

/* ---------- Меню «⋯» (доп. действия) ---------- */

.menu-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.menu-list .btn {
  width: 100%;
  text-align: left;
  justify-content: flex-start;
}

/* ---------- Синхронизация ---------- */

.sync-status {
  margin: 0 0 14px;
  font-size: 14px;
}

/* Строки «Это устройство: … · отпечаток …» и вердикт сравнения */
.sync-meta {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--muted);
}

.sync-verdict {
  margin: 0 0 14px;
  font-size: 14px;
}

.sync-verdict--ok { color: var(--income); }
.sync-verdict--warn { color: var(--warn); }
.sync-verdict--bad { color: var(--expense); }

/* Строка подписки в окне синхронизации (js/sub.js) */
.sync-sub {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--muted);
}

.sync-sub--soon { color: var(--warn); }

.sync-sub--expired { color: var(--expense); }

/* Строка об автосинхронизации в окне синхронизации */
.sync-auto {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--income);
}

/* Баннер подписки наверху «Обзора»: истекает / истекла */
.sub-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  border-left: 4px solid var(--warn);
}

.sub-banner--expired {
  border-left-color: var(--expense);
}

.sub-banner__text {
  flex: 1 1 240px;
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
}

/* ---------- План Free/Pro: карточка-предложение и экран полной версии ---------- */

.upsell-card {
  display: block;
  width: 100%;
  text-align: left;
  cursor: pointer;
  border: 1px dashed var(--border);
}

.upsell-card__row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.upsell-card__text {
  flex: 1;
}

.upsell-card__title {
  font-size: 14px;
  font-weight: 600;
}

.upsell-card__hint {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
}

.upsell-card__btn {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
}

/* Строка инструкции «как купить» (когда кнопки оплаты ещё не подключены) */
.plan-how__step {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text);
  padding: 3px 0;
}

/* Блок покупки в окне «Полная версия»: кнопки оплаты или инструкция.
   Заглушка держит высоту, чтобы окно не прыгало, пока идёт запрос. */
.plan-pay {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 2px 0 14px;
  min-height: 96px;
}

.plan-pay__holder {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.plan-pay__holder .btn {
  text-decoration: none;  /* почта-ссылка выглядит как кнопка */
  text-align: center;
}

/* «Уже есть ключ? Ввести» — свёрнуто: нужно только тем, кто купил */
.plan-key {
  margin-top: 14px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

.plan-key summary {
  cursor: pointer;
  padding: 6px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  list-style: none;
}

.plan-key summary::-webkit-details-marker { display: none; }
.plan-key summary::before { content: '+ '; }

.plan-key[open] summary {
  color: var(--muted);
  font-weight: 500;
  list-style: none;
}

.plan-key[open] summary::before { content: '− '; }

.plan-key .sync-key { margin-bottom: 0; }

/* ---------- Мастер первого запуска (js/onboarding.js) ---------- */

.onboarding__progress {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.onboarding__step {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
}

.onboarding__bar {
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.onboarding__fill {
  height: 100%;
  border-radius: 999px;
  background: var(--primary-strong);
  transition: width 0.25s ease;
}

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

.onboarding__results {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.onboarding__done {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--income);
}

.onboarding__next {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 0 16px;
  padding-left: 20px;
  font-size: 14px;
  color: var(--muted);
}

.onboarding__next b { color: var(--text); }

/* ---------- Напоминание о резервной копии (Free) ---------- */

.backup-hint {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  border-left: 4px solid var(--warn);
}

.backup-hint__text {
  flex: 1 1 220px;
  margin: 0;
  font-size: 13.5px;
  line-height: 1.45;
}

/* Бейдж текущего плана и подпись в окне «Полная версия» */
.plan-badge {
  display: inline-block;
  font-size: 12.5px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  margin-bottom: 12px;
}

.plan-badge--pro {
  background: var(--income-soft);
  color: var(--income);
}

.plan-caption {
  margin: 4px 0 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

/* Список выгод в окне «Полная версия» */
.plan-feature {
  font-size: 14px;
  line-height: 1.5;
  padding: 2px 0;
}

.plan-trial {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}

.sync-version {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/* Блок «Ключ доступа» в окнах синхронизации и ключа */
.sync-key {
  margin: 0 0 16px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sync-key__title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.sync-key__status {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.sync-key__status.is-error { color: var(--expense); }

.sync-key input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
}

.sync-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.sync-note {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--muted);
}

.sync-note.sync-last { margin-bottom: 0; }

/* ---------- Версия ---------- */

.app-version {
  margin-top: 18px;
  user-select: all;
}

.menu-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

.menu-version {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  user-select: all;
}

/* ---------- Вход по ключу ---------- */

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-form {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 22px;
  text-align: center;
}

.auth-logo { font-size: 34px; margin-bottom: 8px; }

.auth-title { margin: 0 0 6px; font-size: 18px; }

.auth-text {
  margin: 0 0 16px;
  font-size: 13.5px;
  color: var(--muted);
}

.auth-input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  margin-bottom: 10px;
  text-align: center;
  letter-spacing: 0.08em;
}

.auth-input:focus {
  outline: none;
  border-color: var(--primary);
}

.auth-error {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--expense);
  font-weight: 600;
}

/* ---------- История платежей и итоги года ---------- */

.pay-card__history {
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
}

.section-title--sub {
  margin-top: 12px;
}

.rec-history {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
}

.rec-history__title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 4px;
}

.rec-history__row {
  display: flex;
  gap: 10px;
  font-size: 13px;
  padding: 2px 0;
  font-variant-numeric: tabular-nums;
}

.rec-history__row span:first-child { flex: 1; }
.rec-history__row span:nth-child(2) { color: var(--muted); }

.year-summary {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.year-summary__title { font-weight: 700; }

.year-summary__row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.year-summary__label { flex: 1; color: var(--muted); font-size: 13px; }
.year-summary__value { font-weight: 700; font-variant-numeric: tabular-nums; }
.year-summary__delta { color: var(--muted); font-size: 12px; min-width: 92px; text-align: right; }
.year-summary__prev {
  border-top: 1px solid var(--border);
  padding-top: 6px;
  font-size: 12.5px;
  color: var(--muted);
}

.install-steps {
  font-size: 14px;
  line-height: 1.5;
  background: var(--surface-2, rgba(127, 127, 127, 0.08));
  border-radius: 10px;
  padding: 10px 12px;
}

/* ---------- Название приложения в боковой панели (только широкий экран) ---------- */

.nav-brand {
  display: none;
}

/* ---------- Широкий экран (компьютер) ----------
   Порог 1024px — тот же, что DESKTOP_QUERY в js/ui.js.
   На телефоне навигация снизу и контент в одну колонку до 640px. На
   компьютере так приложение выглядит «растянутым телефоном»: навигация
   уходит боковой панелью влево, контент занимает остальную ширину. */
@media (min-width: 1024px) {
  #app {
    max-width: 1180px;
    display: grid;
    grid-template-columns: 232px minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    grid-template-areas:
      'nav header'
      'nav screen';
  }

  .bottom-nav {
    position: sticky;
    top: 0;
    grid-area: nav;
    left: auto;
    transform: none;
    width: auto;
    max-width: none;
    height: 100dvh;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    gap: 4px;
    padding: 18px 12px;
    border-top: 0;
    border-right: 1px solid var(--border);
    z-index: 10;
  }

  .nav-brand {
    display: block;
    padding: 4px 14px 18px;
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
  }

  .nav-btn {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 12px;
    font-size: 14.5px;
  }

  .nav-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
  }

  .nav-btn.is-active { background: var(--primary-soft); }

  .app-header { grid-area: header; }

  /* Контент — колонкой читаемой ширины: карточка в 950px с пустотой
     посередине утомляет. Экран, которому нужна вся ширина (два столбца
     «Объектов»), снимает ограничение классом screen--wide. */
  .screen {
    grid-area: screen;
    align-self: start;
    justify-self: center;
    width: 100%;
    max-width: 760px;
    padding: 20px 28px 48px;
  }

  .screen--wide { max-width: none; }

  /* снизу больше нет панели навигации */
  .toast { bottom: 24px; }
}

/* ---------- «Объекты» в два столбца: список и карточка ---------- */

.split {
  display: grid;
  grid-template-columns: minmax(0, 300px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.split__list .prop-list { gap: 10px; }

/* подсказка «нажмите на объект…» не нужна: карточка и так открыта рядом */
.split__list .footnote { display: none; }

.split__detail {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

/* выбранный объект в списке */
.prop-card.is-active {
  border: 1px solid var(--primary);
  background: var(--primary-soft);
}

.prop-card.is-active .prop-card__name { color: var(--primary); }
