/* Общие стили приложения. */

:root {
  /* Тёмная тема с красным акцентом */
  color-scheme: dark; /* календарь, списки и полосы прокрутки браузера тоже тёмные */
  --bg: #0b0b0b;
  --card: #1c1c1e;
  --card-2: #2a2a2d;      /* подложка переключателей, наведение */
  --input: #121214;       /* фон полей ввода */
  --text: #ffffff;
  --muted: #8e8e93;
  --border: #2a2a2d;
  --accent: #ef4b3f;
  --accent-light: #f56e62;
  --accent-tint: #3b1916; /* тёмно-красная подложка выбранного пункта */
  --gradient: linear-gradient(90deg, #e8433a, #f2614f);
  --danger: #ff6b5e;
  --warn: #ffcc4d;
  --ok: #34c759;
  --radius: 24px;
  /* Тени: на тёмном фоне глубже и темнее */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);
  /* Плавность всех анимаций */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  /* «Пружинка» для переезжающей плашки: чуть проскакивает и возвращается */
  --spring: cubic-bezier(0.34, 1.36, 0.64, 1);
}

/* Светлая тема (выбор в настройках): цвета прежнего синего оформления.
   Меняются только цвета, расположение и анимации общие для обеих тем */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f7;
  --card: #ffffff;
  --card-2: #eceef2;
  --input: #ffffff;
  --text: #1d1d1f;
  --muted: #6b6f76;
  --border: #d9dce1;
  --accent: #2f6fed;
  --accent-light: #2f6fed;
  --accent-tint: #e6eefd;
  --gradient: linear-gradient(90deg, #2f6fed, #4a84f5);
  --danger: #d93025;
  --warn: #e0a100;
  --ok: #1e9e5a;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-md: 0 6px 16px rgba(16, 24, 40, 0.10), 0 2px 6px rgba(16, 24, 40, 0.06);
}

/* Скрытое атрибутом hidden прячем всегда, даже если у элемента свой display */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

/* Обычные ссылки в тексте — светло-красные, как акцент */
a { color: var(--accent-light); }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button {
  font: inherit;
  padding: 10px 18px;
  border: none;
  border-radius: 999px;
  background: var(--gradient);
  color: #fff;
  font-weight: 500;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s var(--ease), background 0.15s;
}

/* Кнопки чуть темнеют при наведении и «нажимаются» при клике */
button:hover:not(:disabled),
.button:hover { filter: brightness(1.1); }
button:active:not(:disabled),
.button:active { transform: scale(0.97); }
button:disabled { opacity: 0.5; cursor: default; }

/* Ссылка, которая выглядит как кнопка */
.button {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--gradient);
  color: #fff;
  font-weight: 500;
  text-decoration: none;
  text-align: center;
  transition: filter 0.15s, transform 0.1s var(--ease);
}

input,
select,
textarea {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--input);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

/* Поле, в котором стоит курсор, подсвечивается мягким кольцом */
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(239, 75, 63, 0.25);
}

textarea { resize: vertical; }

[aria-invalid="true"] { border-color: var(--danger); }

.button-secondary {
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.error { color: var(--danger); }
.muted { color: var(--muted); }

/* Сообщение после действия («Папка удалена» и т.п.) */
.flash {
  padding: 12px 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
}

/* Круглая кнопка «+» */
.round-button {
  width: 40px;
  height: 40px;
  padding: 0;
  flex-shrink: 0;
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
}

/* Кнопка, похожая на красную ссылку (для удаления) */
.link-danger {
  padding: 0;
  background: none;
  color: var(--danger);
  font-size: 14px;
}

.link-danger:hover { text-decoration: underline; }

/* --- Полоса папок --- */

.folders {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  margin-bottom: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.folder-tabs {
  position: relative; /* внутри едет красная плашка, см. slide.js */
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 6px;
  /* на компьютере много папок переносятся на следующую строку */
  flex-wrap: wrap;
}

/* на телефоне полоса листается пальцем вбок, чтобы не занимать пол-экрана */
@media (max-width: 767px) {
  .folder-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
}

.folder-tab {
  flex-shrink: 0;
  padding: 8px 16px;
  border-radius: 999px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  color: var(--muted);
  font-weight: 500;
  position: relative;
  z-index: 1; /* текст поверх плашки */
  transition: color 0.25s;
}

.folder-tab:hover { color: var(--text); }

.folder-tab.active { color: #fff; }

/* Без JS плашки нет: выбранная папка просто красная */
.folder-tabs:not(.has-pill) .folder-tab.active { background: var(--gradient); }

/* На телефоне долгое нажатие не должно выделять текст и открывать меню ссылки iOS */
.folder-tab[data-folder-id] {
  -webkit-touch-callout: none;
  user-select: none;
}

.folders-hint { margin: 0 0 12px 8px; }

/* Меню папки (правый клик / долгое нажатие) */
.context-menu {
  position: fixed;
  z-index: 30;
  min-width: 180px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
}

.context-menu[hidden] { display: none; }

.context-menu button {
  padding: 10px 12px;
  text-align: left;
  background: none;
  color: var(--text);
  border-radius: 8px;
}

.context-menu button:hover,
.context-menu button:focus-visible { background: var(--card-2); }

.context-menu button.danger { color: var(--danger); }

/* --- Карточки подписок --- */

.cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Компьютер: иконка | название | цена | ссылка — в одну строку, как на наброске */
.card {
  position: relative;
  display: grid;
  /* Под кнопку «ссылка» место есть всегда, даже если ссылки нет:
     так цены у всех карточек стоят ровной колонкой */
  grid-template-columns: 44px minmax(100px, 1fr) auto auto 96px;
  grid-template-areas: "icon title alerts price link";
  align-items: center;
  gap: 4px 14px;
  padding: 14px 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  /* Скругление обрезает полоску «на сколько хватит денег» снизу */
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), border-color 0.2s;
}

/* Наведение: карточка приподнимается и отбрасывает тень */
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: #3a3a3e;
}

.card-icon {
  grid-area: icon;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Свой оттенок у каждой подписки, см. --hue в home.html */
  background: hsl(var(--hue, 220) 40% 20%);
  color: hsl(var(--hue, 220) 85% 75%);
  font-size: 20px;
  font-weight: 600;
  transition: transform 0.2s var(--ease);
}

.card:hover .card-icon { transform: scale(1.06); }

/* Кружок с картинкой: белый фон, чтобы прозрачные логотипы не сливались */
.card-icon-img {
  background: #fff;
  border: 1px solid var(--border);
  overflow: hidden;
}

.card-icon-img img {
  width: 70%;
  height: 70%;
  object-fit: contain;
}

/* Поле «Картинка» в форме: превью слева от выбора файла */
.icon-field {
  display: flex;
  align-items: center;
  gap: 12px;
}

.icon-field label { flex: 1; }
.icon-field .card-icon { flex-shrink: 0; }

input[type="file"] { padding: 8px; background: var(--input); }

/* Кнопка «Выбрать файл» внутри поля — тёмная таблетка */
input[type="file"]::file-selector-button {
  margin-right: 12px;
  padding: 6px 14px;
  border: none;
  border-radius: 999px;
  background: var(--card-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.icon-fetch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 12px;
}

/* Полоска внизу карточки: ширина = на сколько дней хватит денег */
.days-bar {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: var(--fill);
  min-width: 6px;
  border-radius: 0 3px 3px 0;
}

.days-bar-ok { background: var(--ok); }
.days-bar-mid { background: var(--warn); }
.days-bar-low { background: var(--danger); }

.card-title {
  grid-area: title;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}

/* Растягиваем ссылку названия на всю карточку: клик в любом месте открывает подписку */
.card-title::after {
  content: "";
  position: absolute;
  inset: 0;
}

.card-price {
  grid-area: price;
  white-space: nowrap;
}

/* Кнопка «ссылка» лежит поверх растянутой ссылки и кликается отдельно */
.card-link {
  grid-area: link;
  position: relative;
  z-index: 1;
  padding: 8px 0;
}

.empty { margin-top: 24px; }

/* Предупреждения: красные и мягкие (серые). Мелкая приписка — отдельной строкой. */
.card-alerts {
  grid-area: alerts;
  text-align: right;
}

.alert { margin: 0; line-height: 1.3; }
.alert small { display: block; font-size: 12px; }
.alert-danger { color: var(--danger); }
.alert-soft { color: var(--muted); font-size: 14px; }

.sub-alerts {
  max-width: 720px;
  margin: 8px 0 0;
}

/* Телефон: цена уходит под название, чтобы всё влезло */
@media (max-width: 767px) {
  .card {
    grid-template-columns: 44px 1fr 88px;
    grid-template-areas:
      "icon title link"
      "icon price link"
      "icon alerts link";
    padding: 10px 12px;
  }

  .card-alerts { text-align: left; font-size: 14px; }

  .card-price { color: var(--muted); font-size: 14px; }
}

/* --- Плавающая кнопка «+» --- */

.fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 5;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient);
  color: #fff;
  font-size: 32px;
  line-height: 1;
  text-decoration: none;
  box-shadow: 0 6px 20px rgba(239, 75, 63, 0.45);
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.fab:hover {
  transform: scale(1.08) rotate(90deg);
  box-shadow: 0 10px 28px rgba(239, 75, 63, 0.55);
}

@media (max-width: 767px) {
  .fab { right: 16px; bottom: 16px; }
}

/* --- Форма подписки --- */

.sub-form {
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sub-form fieldset {
  margin: 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.sub-form legend {
  padding: 0 6px;
  font-weight: 600;
  color: var(--muted);
}

.sub-form label { display: block; }

/* Переключатель из нескольких вариантов (валюта в настройках) */
.radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
}

.sub-form label.radio {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

/* Общий стиль полей растягивает их на всю ширину, кружку это не нужно */
.radio input {
  width: auto;
  margin: 0;
  accent-color: var(--accent);
}

/* Несколько полей в ряд; на узком экране переносятся друг под друга */
.row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.hint {
  display: block;
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.field-error {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  color: var(--danger);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.sub-delete {
  max-width: 720px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* --- Страница подписки --- */

.back-link {
  display: inline-block;
  margin-bottom: 12px;
  color: var(--muted);
  text-decoration: none;
}

.back-link:hover { color: var(--text); }

/* Шапка с названием в рамке, как на наброске */
.sub-header {
  max-width: 720px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.sub-header h2 {
  margin: 0;
  font-size: 22px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.sub-actions {
  display: flex;
  gap: 8px;
  margin: 12px 0 16px;
}

.info-block {
  max-width: 720px;
  margin-bottom: 12px;
  padding: 16px 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.info-block h3 { margin: 0 0 10px; font-size: 16px; }
.info-block dl { margin: 0; }
.info-block p { margin: 0; }

/* Строка «название — значение»; на телефоне значение уходит под название */
.info-row {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 4px 16px;
  padding: 6px 0;
}

.info-row + .info-row { border-top: 1px solid var(--border); }
.info-row dt { color: var(--muted); }
.info-row dd {
  margin: 0;
  overflow-wrap: anywhere; /* длинная ссылка не растянет страницу */
  white-space: pre-line;   /* переносы строк из заметок сохраняются */
}

@media (max-width: 767px) {
  .info-row { grid-template-columns: 1fr; }
}

.topups {
  list-style: none;
  margin: 0;
  padding: 0;
}

.topups li {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  padding: 6px 0;
}

/* --- Чат с Claude --- */

.chat-intro { max-width: 720px; }

.chat { max-width: 720px; margin-bottom: 16px; }

.chat summary {
  list-style: none; /* убираем стандартный треугольник */
  cursor: pointer;
}

.chat summary::-webkit-details-marker { display: none; }

.chat[open] > summary { display: none; }

.chat-window {
  display: flex;
  flex-direction: column;
  height: min(560px, 70vh);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-bubble {
  max-width: 85%;
  margin: 0;
  padding: 10px 14px;
  border-radius: 14px;
  white-space: pre-wrap;    /* переносы строк из ответа сохраняются */
  overflow-wrap: anywhere;
}

/* Claude слева, свои сообщения справа, как в мессенджерах */
.chat-claude { align-self: flex-start; background: var(--card-2); border-bottom-left-radius: 4px; }
.chat-user { align-self: flex-end; background: var(--gradient); color: #fff; border-bottom-right-radius: 4px; }
.chat-error { color: var(--danger); }

.chat-input {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
}

.chat-input textarea { margin: 0; resize: none; }
.chat-input button { white-space: nowrap; }

.chat-off code,
.chat-summary code { font-size: 14px; }

.chat-summary-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-summary-head h3 { margin: 0; }
.chat-summary summary { cursor: pointer; margin-top: 8px; color: var(--accent); }

.chat-summary pre {
  margin: 8px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: inherit;
  font-size: 14px;
}

button:disabled,
input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.dialog {
  width: min(400px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
}

.dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

.dialog h2 { margin: 0 0 16px; font-size: 20px; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* --- Каркас: боковое меню + содержимое --- */

:root { --sidebar-width: 240px; }

.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 20px 14px;
  background: #111113;
  border-right: 1px solid var(--border);
  /* меню остаётся на месте при прокрутке длинной страницы */
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
}

.avatar {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient);
  color: #fff;
  font-weight: 600;
}

.username {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-nav {
  position: relative; /* внутри едет плашка, см. slide.js */
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-nav a {
  position: relative;
  z-index: 1;
  padding: 11px 14px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 500;
  text-decoration: none;
  transition: color 0.25s;
}

.sidebar-nav a:hover { color: var(--text); }

.sidebar-nav a.active { color: var(--accent); }

/* Без JS плашки нет: выбранный пункт просто на красной подложке */
.sidebar-nav:not(.has-pill) a.active { background: var(--accent-tint); }

/* Кнопка «Выйти» прижата к низу меню */
.sidebar-logout { margin-top: auto; }
.sidebar-logout button { width: 100%; }

.content {
  flex: 1;
  min-width: 0; /* без этого длинный текст растягивает колонку */
  padding: 16px 24px 96px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.topbar h1 { margin: 0; font-size: 28px; font-weight: 700; }

.menu-toggle {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 50%;
}

.backdrop { display: none; }

/* Компьютер: свёрнутое меню просто скрывается, содержимое занимает всю ширину */
@media (min-width: 768px) {
  .menu-collapsed .sidebar { display: none; }
}

/* Телефон: меню выезжает поверх страницы и по умолчанию спрятано */
@media (max-width: 767px) {
  .sidebar {
    position: fixed;
    left: 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .menu-open .sidebar { transform: none; }

  .menu-open .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 10;
    background: rgba(0, 0, 0, 0.35);
  }

  .content { padding: 12px 16px 96px; }
}

/* --- Страница входа --- */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  padding: 28px 24px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card h1 { margin: 0 0 4px; font-size: 22px; text-align: center; }
.login-card .error { margin: 0; }

/* --- Курсы валют --- */

/* Поле курса между подписями: «1 € = [ 1.08 ] $» */
.rate-input {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 320px;
  margin-top: 4px;
}

.rate-input span { white-space: nowrap; }
.rate-input input { flex: 1; min-width: 0; margin-top: 0; }

/* --- Статистика --- */

.stats-warning { max-width: 720px; margin-bottom: 12px; }

.stats-totals {
  max-width: 720px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 20px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.stat-label { color: var(--muted); }
.stat-value { font-size: 30px; font-weight: 300; }

.stats-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 8px;
}

.stats-table th,
.stats-table td {
  padding: 8px 0;
  text-align: left;
  border-top: 1px solid var(--border);
}

.stats-table th { color: var(--muted); font-weight: 400; border-top: none; }

/* Суммы выровнены по правому краю, чтобы разряды стояли друг под другом */
.stats-table th + th,
.stats-table td + td { text-align: right; white-space: nowrap; padding-left: 12px; }

@media (max-width: 767px) {
  .stat-value { font-size: 22px; }
}

/* Вторая форма на странице настроек — с отступом от первой */
.settings-password { margin-top: 24px; }

/* Курс евро из ЕЦБ: не поле ввода, а строка с числом */
.rates-auto { margin-top: 24px; }
.rate-auto { margin: 0; }

/* --- График пополнений по месяцам (статистика) --- */

.bars {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 6px;
  align-items: end;
  height: 180px;
  /* Место сверху под подпись суммы над самым высоким столбиком */
  margin: 28px 0 8px;
}

.bar-col {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

/* Дорожка забирает всю высоту колонки, кроме подписи месяца.
   Проценты высоты столбика считаются от неё */
.bar-track {
  flex: 1;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-end;
}

.bar {
  position: relative;
  width: 100%;
  max-width: 36px;
  /* Пустой месяц — тонкая полоска, чтобы было видно, что он есть */
  height: max(var(--h), 2px);
  border-radius: 8px 8px 3px 3px;
  background: linear-gradient(180deg, #f2614f, #c9352c);
  opacity: 0.85;
  transform-origin: bottom;
  animation: grow 0.5s var(--ease) backwards;
  transition: opacity 0.15s;
}

.bar-col:hover .bar { opacity: 1; }

/* Подпись суммы над столбиком, мелко. На телефоне скрыта: не влезает */
.bar-value {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.bar-label { font-size: 12px; color: var(--muted); }
.bar-label-now { color: var(--text); font-weight: 600; }

@keyframes grow {
  from { transform: scaleY(0); }
  to { transform: scaleY(1); }
}

@media (max-width: 767px) {
  .bars { gap: 3px; height: 150px; }
  .bar-value { display: none; }
  .bar-label { font-size: 10px; }
}

/* --- Страница «Таблица» --- */

.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 12px;
}

.table-who,
.table-search { flex: 1; min-width: 160px; }
.table-toolbar label { display: block; color: var(--muted); font-size: 14px; }

/* Таблица шире экрана телефона: листается вбок внутри своей рамки */
.table-wrap {
  overflow-x: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--card-2); }
.data-table .num { text-align: right; }

.data-table th {
  position: sticky;
  top: 0;
  background: var(--card);
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}

.data-table th:hover { color: var(--text); }
.data-table th[aria-sort="ascending"]::after { content: " ▲"; font-size: 10px; }
.data-table th[aria-sort="descending"]::after { content: " ▼"; font-size: 10px; }

/* Название прилипает слева, когда таблицу листают вбок */
.data-table .table-name {
  position: sticky;
  left: 0;
  background: var(--card);
  z-index: 1;
}

.data-table th.table-name { z-index: 2; }
.data-table tbody tr:hover .table-name { background: var(--card-2); }
.data-table .table-name a { color: var(--text); font-weight: 600; text-decoration: none; }
.data-table .table-name a:hover { color: var(--accent); }
.table-alerts { color: var(--danger); }

/* Пометка в настройках: кто ещё видит подписки */
.notice {
  max-width: 720px;
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: 18px;
  background: var(--accent-tint);
  color: #ffb3ab;
  font-size: 14px;
}

/* --- Калькулятор стоимости в форме подписки --- */

.calc summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 500;
}

.calc[open] summary { margin-bottom: 8px; }

.calc-rows { display: flex; flex-direction: column; gap: 8px; }

.calc-row {
  display: grid;
  grid-template-columns: 1fr auto 72px 120px 40px;
  align-items: center;
  gap: 8px;
}

.calc-row input,
.calc-row select { margin-top: 0; }

.calc-remove { padding: 8px 0; }

.calc-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 10px;
}

.calc-total { flex: 1; font-weight: 600; }

@media (max-width: 767px) {
  /* На телефоне «за что» и кнопка «убрать» переносятся на вторую строку */
  .calc-row { grid-template-columns: 1fr auto 64px; }
  .calc-row select { grid-column: 1 / 3; }
}

/* --- Появление карточек --- */

/* Карточки при загрузке страницы мягко выезжают снизу одна за другой */
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.cards .card { animation: rise 0.35s var(--ease) backwards; }
.cards .card:nth-child(2) { animation-delay: 0.03s; }
.cards .card:nth-child(3) { animation-delay: 0.06s; }
.cards .card:nth-child(4) { animation-delay: 0.09s; }
.cards .card:nth-child(n+5) { animation-delay: 0.12s; }

.stat { transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease); }
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

/* --- Переезжающая плашка (static/js/slide.js) --- */

/* Плашка лежит под пунктами меню и плавно переезжает к нажатому, как на iPhone */
.slide-pill {
  position: absolute;
  z-index: 0;
  top: 0;
  left: 0;
  border-radius: 999px;
  pointer-events: none;
  transition:
    transform 0.42s var(--spring),
    width 0.42s var(--spring),
    height 0.42s var(--spring);
}

/* Первая расстановка при загрузке страницы — без анимации */
.slide-pill.no-anim { transition: none; }

.folder-tabs .slide-pill { background: var(--gradient); }
.sidebar-nav .slide-pill,
.tabbar .slide-pill { background: var(--accent-tint); }

/* --- Переключатель-«таблетка» вместо радиокнопок --- */

/* Радиокнопки спрятаны, видны только подписи. Красная плашка (::before)
   стоит под выбранным вариантом; номер варианта выбирает :has() ниже */
.segmented {
  --count: 2;
  --index: 0;
  position: relative;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 0;
  padding: 4px;
  /* Не полный круг: длинные подписи переносятся на вторую строку */
  border-radius: 22px;
  background: var(--card-2);
}

.segmented::before {
  content: "";
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: calc((100% - 8px) / var(--count));
  border-radius: 18px;
  background: var(--gradient);
  transform: translateX(calc(100% * var(--index)));
  transition: transform 0.42s var(--spring);
}

.segmented:has(label:nth-child(2) input:checked) { --index: 1; }
.segmented:has(label:nth-child(3) input:checked) { --index: 2; }
.segmented:has(label:nth-child(3)) { --count: 3; }

.sub-form .segmented label.radio,
.segmented label.radio {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 6px 10px;
  border-radius: 18px;
  color: var(--muted);
  font-weight: 500;
  text-align: center;
  line-height: 1.2;
  cursor: pointer;
  transition: color 0.25s;
}

.segmented label.radio:has(input:checked) { color: #fff; }

@media (max-width: 767px) {
  .sub-form .segmented label.radio,
  .segmented label.radio { font-size: 14px; }
}

/* Сам кружок прячем, но он остаётся в форме и доступен с клавиатуры */
.segmented .radio input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented label.radio:has(input:focus-visible) { outline: 2px solid var(--accent-light); outline-offset: -2px; }

/* --- Нижняя панель на телефоне --- */

.tabbar,
.more-sheet { display: none; }

@media (max-width: 767px) {
  /* На телефоне боковое меню и кнопка ☰ не нужны: их заменяет панель снизу */
  .sidebar,
  .menu-toggle { display: none; }

  .content { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }

  .tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 15;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
    background: rgba(11, 11, 11, 0.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
  }

  .tab {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
    border: none;
    border-radius: 0;
    background: none;
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.25s;
  }

  .tab:hover:not(:disabled) { filter: none; }
  .tab.active { color: var(--accent); }

  .tab-icon {
    position: relative;
    z-index: 1;
    width: 56px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .tab-icon svg { width: 22px; height: 22px; fill: currentColor; }

  .tabbar:not(.has-pill) .tab.active .tab-icon { background: var(--accent-tint); border-radius: 999px; }

  /* Плавающая «+» поднимается над панелью */
  .fab { bottom: calc(84px + env(safe-area-inset-bottom)); }

  /* Меню «Ещё»: выезжает снизу над панелью */
  .more-sheet {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(80px + env(safe-area-inset-bottom));
    z-index: 16;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    opacity: 0;
    transform: translateY(16px) scale(0.98);
    pointer-events: none;
    transition: opacity 0.2s, transform 0.3s var(--spring);
  }

  .more-open .more-sheet { opacity: 1; transform: none; pointer-events: auto; }

  .more-open .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 14;
    background: rgba(0, 0, 0, 0.5);
  }

  .more-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px 12px;
    font-weight: 600;
  }

  .more-sheet a,
  .more-sheet button {
    width: 100%;
    padding: 13px 14px;
    border-radius: 14px;
    background: none;
    color: var(--text);
    text-align: left;
    text-decoration: none;
    font-weight: 400;
  }

  .more-sheet a.active { color: var(--accent); }
  .more-sheet a:hover,
  .more-sheet button:hover { background: var(--card-2); filter: none; }
  .more-sheet .more-logout { color: var(--danger); }
}

/* Кто отключил анимации в системе, тому их не показываем */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* --- Светлая тема: места, где у тёмной цвет задан прямо, а не через переменные --- */

:root[data-theme="light"] input:focus,
:root[data-theme="light"] select:focus,
:root[data-theme="light"] textarea:focus { box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.18); }

:root[data-theme="light"] .card:hover { border-color: transparent; }

/* Кружки с иконками светлые, буква тёмная — как было в синей теме */
:root[data-theme="light"] .card-icon {
  background: hsl(var(--hue, 220) 85% 94%);
  color: hsl(var(--hue, 220) 55% 35%);
}

:root[data-theme="light"] .card-icon-img { background: #fff; }
:root[data-theme="light"] .sidebar { background: var(--card); }

:root[data-theme="light"] .fab { box-shadow: 0 4px 14px rgba(47, 111, 237, 0.4); }
:root[data-theme="light"] .fab:hover { box-shadow: 0 8px 22px rgba(47, 111, 237, 0.45); }

:root[data-theme="light"] .bar { background: linear-gradient(180deg, #4a84f5, #2f6fed); }
:root[data-theme="light"] .notice { color: hsl(220 50% 30%); }

@media (max-width: 767px) {
  :root[data-theme="light"] .tabbar { background: rgba(255, 255, 255, 0.92); }
  :root[data-theme="light"] .menu-open .backdrop,
  :root[data-theme="light"] .more-open .backdrop { background: rgba(0, 0, 0, 0.25); }
}
