/* Дизайн-система из прототипа Mini App: oklch-токены, тёмная тема,
   bottom-sheet модалки, row-карточки. Адаптирована под реальные классы. */

:root {
    --bg: oklch(99% 0.002 240);
    --surface: oklch(100% 0 0);
    --fg: oklch(18% 0.012 250);
    --muted: oklch(54% 0.012 250);
    --border: oklch(92% 0.005 250);
    --accent: oklch(58% 0.18 255);
    --accent-soft: color-mix(in oklch, var(--accent) 14%, transparent);
    --fg-soft: color-mix(in oklch, var(--fg) 6%, transparent);
    --page: oklch(96% 0.004 240);
    --on-accent: oklch(99% 0.001 0);
    --ok: oklch(62% 0.13 155);
    --warn: oklch(70% 0.14 75);
    --danger: oklch(60% 0.19 25);
    --ok-fg: oklch(45% 0.11 150);
    --warn-fg: oklch(48% 0.11 70);
    --danger-fg: oklch(50% 0.19 25);
    /* "Ещё не активен" — не путать с warn (скоро списание/пауза) */
    --scheduled: oklch(55% 0.16 300);
    --scheduled-fg: oklch(48% 0.15 300);
    --font-display: -apple-system, BlinkMacSystemFont, 'SF Pro Display', system-ui, sans-serif;
    --font-body: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
    --font-mono: ui-monospace, 'SF Mono', Menlo, monospace;
    --shadow-color: color-mix(in oklab, var(--fg) 12%, transparent);
    --chart-1: oklch(58% 0.18 255);
    --chart-2: oklch(62% 0.15 155);
    --chart-3: oklch(72% 0.14 75);
    --chart-4: oklch(58% 0.2 25);
    --chart-5: oklch(58% 0.16 300);
    --chart-6: oklch(60% 0.12 210);
    --chart-7: oklch(62% 0.18 350);
}

body.dark-theme {
    --bg: oklch(16% 0.01 250);
    --surface: oklch(21% 0.012 250);
    --fg: oklch(93% 0.004 250);
    --muted: oklch(67% 0.014 250);
    --border: oklch(30% 0.015 250);
    --accent: oklch(70% 0.14 255);
    --accent-soft: color-mix(in oklch, var(--accent) 20%, transparent);
    --fg-soft: color-mix(in oklch, var(--fg) 7%, transparent);
    --page: oklch(12% 0.008 250);
    --ok: oklch(75% 0.12 155);
    --warn: oklch(80% 0.13 80);
    --danger: oklch(70% 0.17 25);
    --ok-fg: oklch(80% 0.11 150);
    --warn-fg: oklch(83% 0.12 80);
    --danger-fg: oklch(74% 0.15 25);
    --scheduled: oklch(78% 0.13 300);
    --scheduled-fg: oklch(83% 0.12 300);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
/* touch-action: manipulation убирает зум по двойному тапу на iOS
   (user-scalable=no Safari в части контекстов игнорирует) */
body {
    margin: 0;
    touch-action: manipulation;
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.5;
    color: var(--fg);
    background: var(--page);
    -webkit-font-smoothing: antialiased;
}
img, svg { display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; padding: 0; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.hidden { display: none !important; }

/* ── Оболочка ─────────────────────────────────────────────────── */
/* Mobile-first: смартфон — во всю ширину, планшет/десктоп — сетки. */

.app-shell {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    width: 100%;
    margin-inline: auto;
    background: var(--bg);
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;   /* даёт .app-main скроллиться внутри, а не растягивать shell */
}

/* ── Шапка ────────────────────────────────────────────────────── */

.app-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px 10px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
    font-weight: 650;
    letter-spacing: -0.01em;
    font-size: 15px;
    /* Клик по бренду ведёт на Сводку */
    cursor: pointer;
}

.brand:hover .brand-mark { background: color-mix(in oklch, var(--fg) 82%, var(--bg)); }

.brand-mark {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: var(--fg);
    color: var(--bg);
    display: grid;
    place-items: center;
    flex: 0 0 auto;
}

.tag {
    display: inline-flex;
    padding: 2px 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--muted);
    white-space: nowrap;
}

/* Тег плана — кнопка: клик открывает окно подписки */
.tag-btn {
    background: none;
    font-family: inherit;
    cursor: pointer;
    transition: border-color .15s, color .15s;
}

.tag-btn:hover {
    border-color: color-mix(in oklch, var(--fg) 30%, var(--border));
    color: var(--fg);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
}

.user-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    flex: none;
    object-fit: cover;
    background: var(--border);
}

.user-avatar-fallback {
    display: grid;
    place-items: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
}

#user-name {
    font-size: 12.5px;
    font-weight: 550;
    color: var(--muted);
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-button {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    color: var(--muted);
    transition: background .15s, color .15s;
    font-size: 15px;
}

.icon-button:hover { background: var(--fg-soft); color: var(--fg); }

/* Переключатель темы: солнце в светлой теме, луна в тёмной (как в прототипе) */

#theme-toggle .ic-moon { display: none; }
body.dark-theme #theme-toggle .ic-sun { display: none; }
body.dark-theme #theme-toggle .ic-moon { display: block; }

/* Выпадающие меню (CSV / помощь) */

.help-menu { position: relative; }

.help-menu summary {
    list-style: none;
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    color: var(--muted);
    cursor: pointer;
    transition: background .15s, color .15s;
}

.help-menu summary::-webkit-details-marker { display: none; }
.help-menu summary:hover { background: var(--fg-soft); color: var(--fg); }

.help-menu.summary-with-label summary {
    width: auto;
    padding: 0 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 550;
}

.help-icon {
    display: grid;
    place-items: center;
    width: 18px;
    height: 18px;
    border: 1px solid var(--border);
    border-radius: 50%;
    font-size: 11px;
    font-weight: 650;
}

.help-menu-list {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 198px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px;
    box-shadow: 0 12px 32px var(--shadow-color);
    z-index: 40;
}

.help-menu-list button,
.help-menu-list a {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    border-radius: 8px;
    font-size: 13.5px;
    color: var(--fg);
    text-align: left;
}

.help-menu-list button:hover,
.help-menu-list a:hover { background: var(--fg-soft); }

/* Выбранная основная валюта в меню шапки */
.help-menu-list button.active { background: var(--fg-soft); font-weight: 600; }
.help-menu-list button:disabled { opacity: 0.55; }

/* Разделитель секций внутри выпадающего меню («Ещё» в шапке) */
.help-menu-divider {
    height: 1px;
    background: var(--border);
    margin: 6px 4px;
}

/* Вложенное меню (валюта/язык внутри «Ещё»): раскрывается на месте,
   а не плавающей панелью — иначе вылезает за пределы родителя.
   #overflow-menu в селекторе — чтобы гарантированно перебить
   .app-header .help-menu > summary (та же специфичность, но ниже по файлу). */
#overflow-menu .help-menu-list .help-menu > summary {
    width: 100%;
    justify-content: flex-start;
    padding: 9px 10px;
    border-radius: 8px;
    font-size: 13.5px;
    font-weight: 500;
}

#overflow-menu .help-menu-list .help-menu .help-menu-list {
    position: static;
    box-shadow: none;
    border: none;
    background: none;
    padding: 2px 0 2px 10px;
    margin: 0 0 2px 8px;
    border-left: 1px solid var(--border);
    border-radius: 0;
}

/* ── Основная область ─────────────────────────────────────────── */

.app-main {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 28px;
    scrollbar-width: thin;
}

.view { display: none; }
.view.active { display: block; }

.title-section h1 {
    font-family: var(--font-display);
    font-size: 23px;
    line-height: 1.15;
    letter-spacing: -0.02em;
    font-weight: 700;
}

.view-intro {
    font-size: 12.5px;
    color: var(--muted);
    line-height: 1.45;
    margin-bottom: 12px;
    max-width: 52ch;
}

/* Чипы статистики подписок */

.sub-chips, .stats {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin: 9px 0 16px;
}

#totalCount, #activeCount, #pausedCount {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 550;
    background: var(--fg-soft);
    color: var(--muted);
}

#activeCount::before, #pausedCount::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

#activeCount {
    background: color-mix(in oklch, var(--ok) 13%, transparent);
    color: var(--ok-fg);
}

#pausedCount {
    background: color-mix(in oklch, var(--warn) 16%, transparent);
    color: var(--warn-fg);
}

/* ── Виджеты дашборда ─────────────────────────────────────────── */

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

/* Виджет + прикреплённый к нему список (Ближайшие списания):
   одна ячейка сетки, список визуально продолжает кнопку-виджет */
.widget-stack {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.widget {
    text-align: left;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    transition: border-color .15s;
    width: 100%;
}

button.widget:hover { border-color: color-mix(in oklch, var(--fg) 24%, var(--border)); }

/* Кнопка-виджет: шеврон справа как affordance нажатия (вариант B) */
.widget-btn { position: relative; }

.widget-chevron {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 16px;
    height: 16px;
    color: var(--muted);
    transition: transform .15s;
}

/* Список раскрыт — шеврон поворачивается вниз */
.widget-btn[aria-expanded="true"] .widget-chevron { transform: rotate(90deg); }

.widget h3 {
    font-size: 10.5px;
    font-weight: 650;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
}

.widget p {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 19px;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-top: 2px;
}

.widget-hint {
    font-family: var(--font-body) !important;
    font-size: 12px !important;
    font-weight: 400 !important;
    letter-spacing: 0 !important;
    color: var(--muted) !important;
    line-height: 1.35;
}

/* Список ближайших списаний */

.upcoming-list {
    /* -1px накрывает нижнюю границу виджета — список выглядит его продолжением */
    margin: -1px 0 0;
    border: 1px solid var(--border);
    border-radius: 0 0 14px 14px;
    background: var(--surface);
    overflow: hidden;
}

.upcoming-list li {
    display: flex;
    align-items: stretch;
    border-top: 1px solid var(--border);
}

.upcoming-list li:first-child { border-top: 0; }

/* В узкой ячейке (мобайл) имя и срок — двумя строками */
.upcoming-item {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 10px 12px;
    text-align: left;
    min-width: 0;
}

.upcoming-item-name {
    font-size: 13.5px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.upcoming-item-meta {
    font-size: 11.5px;
    color: var(--muted);
    white-space: nowrap;
}

/* ── Диаграмма расходов ───────────────────────────────────────── */

.chart-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    /* Без отступа карточки касались друг друга (0px между ними) — тот же
       промежуток, что уже отделяет .stats-widgets сверху */
    margin-bottom: 12px;
}

.chart-card:last-child { margin-bottom: 0; }

.chart-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    gap: 10px;
    flex-wrap: wrap;
}

.chart-card-header h3 {
    font-size: 10.5px;
    font-weight: 650;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
}

.chart-toggle {
    display: flex;
    background: var(--fg-soft);
    border-radius: 9px;
    padding: 2px;
}

.chart-toggle-btn {
    /* +2px высоты под палец */
    padding: 6px 11px;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 550;
    color: var(--muted);
}

.chart-toggle-btn.active {
    background: var(--surface);
    color: var(--fg);
    box-shadow: 0 1px 3px var(--shadow-color);
}

.chart-body {
    display: flex;
    gap: 18px;
    align-items: center;
    min-height: 140px;
}

/* ── Тренд / Топ / Календарь ─────────────────────────────────── */

.chart-hint {
    font-size: 11px;
    color: var(--muted);
}

.trend-bars {
    display: flex;
    align-items: stretch;
    gap: 6px;
    min-height: 150px;
}

.trend-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.trend-value {
    height: 12px;
    max-width: 100%;
    overflow: hidden;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 9px;
    color: var(--muted);
    white-space: nowrap;
}

.is-current .trend-value {
    color: var(--fg);
    font-weight: 650;
}

.trend-bar-track {
    position: relative;
    flex: 1;
    width: 100%;
    min-height: 70px;
}

.trend-bar {
    position: absolute;
    bottom: 0;
    left: 15%;
    right: 15%;
    min-height: 2px;
    background: var(--chart-1);
    border-radius: 4px 4px 0 0;
    opacity: .8;
}

.trend-col:hover .trend-bar,
.is-current .trend-bar {
    opacity: 1;
}

.trend-label {
    font-size: 9px;
    letter-spacing: .02em;
    text-transform: uppercase;
    color: var(--muted);
}

.is-current .trend-label {
    color: var(--fg);
    font-weight: 600;
}

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

.top-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.top-rank {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    display: grid;
    place-content: center;
    border-radius: 6px;
    background: var(--fg-soft);
    color: var(--muted);
    font-size: 11px;
    font-weight: 650;
}

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

.top-name {
    font-size: 13px;
    font-weight: 550;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-bar-track {
    display: block;
    height: 5px;
    border-radius: 3px;
    background: var(--fg-soft);
    overflow: hidden;
}

.top-bar {
    display: block;
    height: 100%;
    background: var(--chart-1);
    border-radius: 3px;
}

.top-meta {
    flex: 0 0 auto;
    text-align: right;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.top-amount {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 12.5px;
}

.top-share {
    font-size: 10.5px;
    color: var(--muted);
}

.calendar-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.calendar-nav-btn {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: var(--fg-soft);
    color: var(--fg);
    font-size: 15px;
    line-height: 1;
    display: grid;
    place-content: center;
}

.calendar-label {
    min-width: 110px;
    text-align: center;
    font-size: 12.5px;
    font-weight: 600;
    text-transform: capitalize;
}

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

.calendar-weekdays {
    margin-top: 10px;
    margin-bottom: 2px;
}

.calendar-weekdays span {
    text-align: center;
    font-size: 9.5px;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--muted);
}

.calendar-cell {
    position: relative;
    min-height: 34px;
    border-radius: 8px;
    background: var(--fg-soft);
    border: none;
    padding: 2px 0;
    font: inherit;
    cursor: pointer;
    color: var(--fg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
}

.calendar-cell-icon {
    position: absolute;
    top: 2px;
    right: 2px;
    line-height: 0;
}

.calendar-cell.is-selected {
    box-shadow: 0 0 0 1.5px var(--chart-1);
}

.calendar-details {
    margin-top: 10px;
    border-top: 1px solid var(--border);
    padding-top: 8px;
}

.calendar-details h4 {
    font-size: 11.5px;
    font-weight: 650;
    margin-bottom: 6px;
}

.calendar-details-hint {
    font-size: 11px;
    color: var(--muted);
    margin: 0;
}

.calendar-events {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.calendar-event {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 12px;
    min-width: 0;
}

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

.calendar-event-kind {
    font-size: 10.5px;
    color: var(--muted);
    flex: 0 0 auto;
}

.calendar-event-amount {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    flex: 0 0 auto;
}

/* ── Способы оплаты ──────────────────────────────────────────── */

.pm-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.pm-row select {
    flex: 1;
    min-width: 0;
}

.pm-manage-btn {
    flex: 0 0 auto;
    padding: 6px 10px;
}

.pm-list {
    list-style: none;
    margin: 12px 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.pm-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 9px;
    background: var(--fg-soft);
    font-size: 13px;
}

.pm-empty {
    font-size: 12px;
    color: var(--muted);
    padding: 4px 2px;
}

.calendar-cell.is-empty {
    background: transparent;
}

.calendar-cell.has-events {
    box-shadow: inset 0 0 0 1px var(--border);
}

.calendar-cell.has-draft {
    box-shadow: inset 0 0 0 1px var(--chart-3);
}

.calendar-cell.is-today .calendar-day {
    color: var(--fg);
    font-weight: 700;
    text-decoration: underline;
    text-decoration-color: var(--chart-1);
    text-underline-offset: 2px;
}

.calendar-day {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 11.5px;
    color: var(--fg);
}

.calendar-dots {
    display: flex;
    gap: 2px;
    height: 4px;
}

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

.dot-paid { background: var(--chart-2); }
.dot-draft { background: var(--chart-3); }
.dot-planned { background: var(--muted); }

.calendar-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 10px;
    font-size: 10.5px;
    color: var(--muted);
}

.calendar-legend > span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.pie-wrap {
    position: relative;
    width: 128px;
    height: 128px;
    flex: 0 0 auto;
}

.pie-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--fg-soft);
}

.pie-center {
    position: absolute;
    inset: 16px;
    background: var(--surface);
    border-radius: 50%;
    display: grid;
    place-content: center;
    text-align: center;
    gap: 1px;
    padding: 8px;
}

.pie-center strong {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 13.5px;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.pie-center span {
    font-size: 9.5px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .07em;
}

.pie-legend {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-width: 0;
}

.pie-legend li {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    min-width: 0;
}

.pie-swatch {
    width: 9px;
    height: 9px;
    border-radius: 3px;
    flex: 0 0 auto;
}

.pie-legend-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pie-legend-amount {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    font-size: 11.5px;
    white-space: nowrap;
}

.pie-legend-pct {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    font-size: 11.5px;
    min-width: 38px;
    text-align: right;
    white-space: nowrap;
}

.chart-empty { color: var(--muted); font-size: 13px; }

/* ── Контролы и кнопки ────────────────────────────────────────── */

.controls {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.controls .filter-sort {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-left: auto;
}

/* Полноширинная строка поиска: своя строка над фильтрами, чтобы не сжимать
   их на узком экране (360px) до горизонтального переполнения */
.controls .services-search {
    flex: 1 1 100%;
    height: 38px;
    order: 3;
}

.btn,
.primary-btn,
.secondary-btn,
.danger-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 40px;
    padding: 0 16px;
    border-radius: 11px;
    font-size: 13.5px;
    font-weight: 600;
    border: 1px solid transparent;
    transition: background .15s, border-color .15s, color .15s, transform .05s;
    white-space: nowrap;
}

.primary-btn:active, .secondary-btn:active, .danger-btn:active { transform: translateY(1px); }

.primary-btn { background: var(--accent); color: var(--on-accent); }

/* "+" перед текстом — как в прототипе; ::before, а не реальный child-узел,
   потому что data-i18n перезаписывает textContent кнопки при смене языка */
#add-service-btn::before {
    content: '+';
    margin-right: 2px;
    font-weight: 700;
}
.primary-btn:hover { background: color-mix(in oklch, var(--accent) 90%, black); }

.secondary-btn { border-color: var(--border); color: var(--fg); background: var(--surface); }
.secondary-btn:hover { border-color: color-mix(in oklch, var(--fg) 30%, var(--border)); }

.danger-btn { background: var(--danger); color: var(--on-accent); }
.danger-btn:hover { background: color-mix(in oklch, var(--danger) 88%, black); }

.filter-sort select,
select.filter {
    height: 38px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    padding: 0 8px;
    font-size: 12.5px;
    color: var(--fg);
    max-width: 46vw;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    height: 30px;
    padding: 0 11px;
    border-radius: 9px;
    font-size: 12.5px;
    font-weight: 550;
    transition: background .15s;
}

.edit-btn { background: var(--accent-soft); color: var(--accent); }
.edit-btn:hover { background: color-mix(in oklch, var(--accent) 24%, transparent); }

.confirm-btn {
    background: color-mix(in oklch, var(--ok) 12%, transparent);
    color: var(--ok-fg);
}
.confirm-btn:hover {
    background: color-mix(in oklch, var(--ok) 22%, transparent);
}

.form-toggle {
    display: block;
    background: none;
    border: none;
    color: var(--accent);
    font-size: 0.9em;
    padding: 4px 0;
    margin: -4px 0 8px;
    cursor: pointer;
}

/* Конструктор полей: форма становится flex-контейнером, чтобы CSS `order`
   (расставляется в JS по личной раскладке пользователя) двигал поля, не
   трогая их DOM-положение. .form-actions всегда прижат к концу, вне
   зависимости от того, что происходит с порядком полей выше. */
.form-constructible {
    display: flex;
    flex-direction: column;
}
.form-constructible > .form-actions {
    order: 999;
}

.ios-install-hint {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 14px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 12.5px;
    font-weight: 550;
}
.ios-install-hint .close-btn {
    width: 24px;
    height: 24px;
    font-size: 15px;
    flex-shrink: 0;
    background: none;
    color: inherit;
}

.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}
.modal-header-actions .icon-button {
    width: 32px;
    height: 32px;
    font-size: 14px;
}

.field-layout-list {
    list-style: none;
    margin: 8px 0 16px;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.field-layout-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    cursor: grab;
    user-select: none;
}
.field-layout-row.dragging {
    opacity: 0.4;
}
.field-layout-row .drag-handle {
    color: var(--muted);
}
.field-layout-divider {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}
.field-layout-divider::before,
.field-layout-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}
.field-layout-row.drag-over-before {
    border-top: 2px solid var(--accent);
}
.field-layout-row.drag-over-after {
    border-bottom: 2px solid var(--accent);
}
.link-btn {
    background: var(--accent-soft);
    color: var(--accent);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}

/* ── Row-карточки ─────────────────────────────────────────────── */

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

.row-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px;
    transition: border-color .15s;
    width: 100%;
    text-align: left;
    /* Мягкое выравнивание высоты: единый базовый размер, карточки с бóльшим
       контентом (прогресс, чипы) могут быть выше */
    min-height: 64px;
}

button.row-card:hover,
div.row-card:hover { border-color: color-mix(in oklch, var(--fg) 24%, var(--border)); }

.rc-main {
    flex: 1;
    min-width: 0;
    display: block;
}

button.rc-main {
    text-align: left;
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    cursor: pointer;
    border-radius: 8px;
}

.rc-title {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 7px;
    flex-wrap: wrap;
}

.rc-sub {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.rc-side {
    display: flex;
    flex-direction: column;
    gap: 3px;
    align-items: flex-end;
    flex: 0 0 auto;
}

.rc-amt {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

.rc-note {
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
}

.rc-actions {
    display: flex;
    gap: 2px;
    flex: 0 0 auto;
}

/* Тач-таргеты под палец: 40×40 (HIG — 44, но три кнопки по 44 с суммой
   справа не влезают в узкий экран; 40 + gap 2 — компромисс) */
.rc-actions .icon-button {
    width: 40px;
    height: 40px;
    border-radius: 10px;
}

/* Карточка сервиса/подписки: вертикальные ряды (имя+цена → тег проекта →
   статус → действия) вместо одной плотной строки — сущности не наезжают
   друг на друга на узком экране и читаются по отдельности */
.service-card {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
}

.service-card .sc-head {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.service-card .sc-head .rc-name { flex: 1 1 auto; }

.service-card .sc-period {
    font-family: var(--font-body);
    font-size: 11px;
    font-weight: 500;
    color: var(--muted);
}

.service-card .sc-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    padding-left: 46px; /* под иконку в шапке: выравнивание по имени */
    font-size: 12px;
    color: var(--muted);
}

.service-card .sc-status {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding-left: 46px;
}

.service-card > .rc-actions { align-self: flex-end; }

/* Чип отсчёта — кнопка: клик/тап раскрывает точную дату строкой ниже
   (hover-title недоступен на тач-экране) */
button.chip {
    border: none;
    cursor: pointer;
    appearance: none;
}

.sc-due-wrap {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
}

.sc-date-detail {
    /* max-height, не grid-template-rows: 0fr/1fr резолвятся в одну и ту же
       content-based высоту, когда у контейнера нет своего внешнего
       ограничения по высоте (auto) — здесь его нет */
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height .25s cubic-bezier(.16, 1, .3, 1), opacity .2s ease;
    font-size: 11px;
    color: var(--muted);
}

.sc-due-wrap.open .sc-date-detail { max-height: 40px; opacity: 1; margin-top: 4px; }

@media (prefers-reduced-motion: reduce) {
    .sc-date-detail { transition: none; }
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 550;
    background: var(--fg-soft);
    color: var(--muted);
    white-space: nowrap;
}

.chip::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

.chip.no-dot::before { display: none; }

.chip.ok { background: color-mix(in oklch, var(--ok) 13%, transparent); color: var(--ok-fg); }
.chip.warn { background: color-mix(in oklch, var(--warn) 16%, transparent); color: var(--warn-fg); }
.chip.danger { background: color-mix(in oklch, var(--danger) 13%, transparent); color: var(--danger-fg); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.inactive { background: var(--fg-soft); color: var(--muted); }
.chip.scheduled { background: color-mix(in oklch, var(--scheduled) 15%, transparent); color: var(--scheduled-fg); }

.proj-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--pd, var(--accent));
    display: inline-block;
    flex: 0 0 auto;
}

/* Прогресс запаса расходника */

.progress {
    height: 5px;
    border-radius: 999px;
    background: var(--fg-soft);
    overflow: hidden;
    margin-top: 8px;
    max-width: 220px;
}

.progress i {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: var(--ok);
}

.progress.warn i { background: var(--warn); }
.progress.danger i { background: var(--danger); }

/* ── Платежи: ленты по месяцам ────────────────────────────────── */

.lane {
    margin-bottom: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.lane-head {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 8px;
}

.lane-head h3 {
    font-size: 11.5px;
    font-weight: 650;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--muted);
}

.lane-head::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
    align-self: center;
}

.lane-sum {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 11.5px;
    color: var(--muted);
    white-space: nowrap;
}

.lane.is-focus .row-card {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

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

.empty-state {
    border: 1px dashed var(--border);
    border-radius: 14px;
    padding: 22px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
}

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

.app-nav {
    flex: 0 0 auto;
    display: flex;
    border-top: 1px solid var(--border);
    background: color-mix(in oklch, var(--surface) 88%, transparent);
    backdrop-filter: blur(14px);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    /* 6 кнопок не помещаются в ряд на телефоне — трек скроллится по
       горизонтали. Скроллбар скрыт: на тач-экранах он не нужен, край
       обрезанной кнопки сам подсказывает, что есть продолжение. */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.app-nav::-webkit-scrollbar { display: none; }

.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 52px;
    padding: 6px 2px 4px;
    border-radius: 10px;
    /* Неактивные табы чуть бледнее — активный читается первым */
    color: color-mix(in oklch, var(--muted) 82%, transparent);
    font-size: 10.5px;
    font-weight: 550;
    transition: color .15s, background .15s;
}

.nav-btn svg { width: 21px; height: 21px; }
.nav-btn:hover { color: var(--fg); background: var(--fg-soft); }

/* Активный таб: пилюля-индикатор вокруг иконки+подписи (вариант B) */
.nav-btn.active {
    color: var(--accent);
    background: var(--accent-soft);
}

/* Пружинка иконки при переключении вкладок (в стиле iOS tab bar) */
@keyframes navIconPop {
    0% { transform: scale(1); }
    35% { transform: scale(1.22); }
    62% { transform: scale(0.92); }
    100% { transform: scale(1); }
}

.nav-btn.nav-pop svg {
    animation: navIconPop .42s cubic-bezier(.34, 1.56, .64, 1);
}

@media (prefers-reduced-motion: reduce) {
    .nav-btn.nav-pop svg { animation: none; }
}

/* ── Модалки: нижние шторки ───────────────────────────────────── */

.modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: none;
    align-items: flex-end;
    justify-content: center;
}

.modal.open { display: block; }

/* Модалка способов оплаты и конструктор полей открываются поверх уже
   открытой модалки (сервиса/проекта/платежа/расходника) — выше базового z-index */
#payment-method-modal,
#field-layout-modal {
    z-index: 70;
}


.modal::before {
    content: '';
    position: absolute;
    inset: 0;
    background: color-mix(in oklab, var(--fg) 34%, transparent);
    opacity: 0;
    transition: opacity .2s;
}

.modal.open::before { opacity: 1; }

.modal-content,
.sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    margin-inline: auto;
    max-width: 430px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom: 0;
    border-radius: 20px 20px 0 0;
    padding: 14px 16px calc(18px + env(safe-area-inset-bottom, 0px));
    max-height: 88%;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform .25s cubic-bezier(.32, .72, .24, 1);
}

.modal.open .modal-content,
.modal.open .sheet { transform: translateY(0); }

@media (min-width: 640px) {
    .modal-content, .sheet {
        left: 50%;
        right: auto;
        transform: translate(-50%, 100%);
        width: 100%;
        max-width: 460px;
        border-radius: 20px;
        border-bottom: 1px solid var(--border);
        margin-bottom: 14px;
    }
    .modal.open .modal-content,
    .modal.open .sheet { transform: translate(-50%, 0); }
}

@media (min-width: 1024px) {
    .modal-content, .sheet {
        top: 50%;
        bottom: auto;
        transform: translate(-50%, calc(-50% + 24px));
        opacity: 0;
        transition: transform .22s cubic-bezier(.32,.72,.24,1), opacity .22s;
        border-radius: 18px;
        border-bottom: 1px solid var(--border);
        margin-bottom: 0;
        max-width: 500px;
    }
    .modal.open .modal-content,
    .modal.open .sheet {
        transform: translate(-50%, -50%);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.modal-header h2 {
    font-family: var(--font-display);
    font-size: 17px;
    letter-spacing: -0.01em;
    font-weight: 700;
}

.close-btn {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    display: grid;
    place-items: center;
    color: var(--muted);
    background: var(--fg-soft);
    font-size: 18px;
    line-height: 1;
}

.close-btn:hover { color: var(--fg); }

/* ── Формы ────────────────────────────────────────────────────── */

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 12px;
}

.form-group > label {
    font-size: 12px;
    font-weight: 550;
    color: var(--muted);
}

input.input,
select.input,
textarea.input,
.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    font-size: 14px;
}

/* iOS Safari: нативный input[type=date] рисует собственный внутренний блок
   со своей высотой и вертикальным выравниванием — без фикса дата уезжает
   вверх/обрезается, а поле выше соседних инпутов в form-row. */

input[type="date"] {
    -webkit-appearance: none;
    appearance: none;
    min-height: 44px;
}

input[type="date"]::-webkit-date-and-time-value {
    /* выравнивает текст даты по центру строки, как в обычных инпутах */
    min-height: 1.45em;
    text-align: left;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea { min-height: 60px; resize: vertical; }

.form-row {
    display: flex;
    gap: 8px;
}

.form-row > * { flex: 1; min-width: 0; }

/* Пара полей в одну строку (форма расходника): на очень узких экранах — в столбик */

@media (max-width: 360px) {
    .modal-content .form-row { flex-direction: column; gap: 0; }
}

.form-hint {
    font-size: 11.5px;
    color: var(--muted);
    line-height: 1.4;
}

.form-group label:has(input[type="checkbox"]) {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 13.5px;
    color: var(--fg);
}

.form-group input[type="checkbox"] {
    width: 17px;
    height: 17px;
    accent-color: var(--accent);
}

.form-actions {
    display: flex;
    /* Кнопки, не влезающие в ряд (напр. 4 кнопки в модалке «Пространство»
       на телефоне), переносятся на следующую строку — вместо горизонтального
       скролла всей шторки. */
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}

.form-actions .btn,
.form-actions .primary-btn,
.form-actions .secondary-btn,
.form-actions .danger-btn { flex: 1 1 auto; }

.premium-stub {
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 13.5px;
    color: var(--muted);
    line-height: 1.5;
}

.premium-stub strong { color: var(--fg); }
.premium-stub .primary-btn {
    align-self: stretch;
    text-align: center;
    text-decoration: none;
}

.confirm-text {
    font-size: 13.5px;
    color: var(--muted);
    line-height: 1.5;
    margin-bottom: 14px;
}

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

/* ── Иконки сущностей и пикер ─────────────────────────────────── */

.entity-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    overflow: hidden;
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 650;
    font-size: 14px;
}

.entity-icon img,
.entity-icon svg {
    width: 20px;
    height: 20px;
}

.entity-icon-letter { line-height: 1; }

.entity-icon-sm {
    width: 22px;
    height: 22px;
    border-radius: 7px;
    font-size: 11px;
}

.entity-icon-sm img,
.entity-icon-sm svg { width: 12px; height: 12px; }

.entity-icon-xs {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    font-size: 7.5px;
}

.entity-icon-xs img,
.entity-icon-xs svg { width: 9px; height: 9px; }

.entity-title {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.entity-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.subscription-name {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Имя расходника внутри .rc-title: длинные названия обрезаются многоточием
   (перенос по буквам выглядит хуже, а карточка остаётся компактной) */
.rc-name {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.icon-picker { margin-top: 8px; }

.icon-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    gap: 6px;
    max-height: 196px;
    overflow-y: auto;
    padding: 2px;
}

.icon-pick {
    width: 44px;
    height: 44px;
    min-height: 44px;
    border: 2px solid transparent;
    border-radius: 10px;
    background: var(--bg);
    cursor: pointer;
    display: grid;
    place-items: center;
    padding: 0;
    color: var(--fg);
}

.icon-pick .entity-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
}

.icon-pick:hover { border-color: var(--accent); }
.icon-pick.selected {
    border-color: var(--fg);
    background: var(--accent-soft);
}

.icon-pick-logo {
    border-style: dashed;
    border-color: var(--border);
}

.icon-pick-logo.selected { border-style: solid; }

/* ── Логин-оверлей ────────────────────────────────────────────── */

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

.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 22px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: 0 24px 60px var(--shadow-color);
}

.login-card h2 {
    font-family: var(--font-display);
    font-size: 19px;
    letter-spacing: -0.01em;
}

.login-card p {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.55;
}

.login-card code {
    font-family: var(--font-mono);
    background: var(--fg-soft);
    border-radius: 5px;
    padding: 1px 5px;
    color: var(--fg);
}

.bot-link { color: var(--accent); font-weight: 550; }
.bot-link:hover { text-decoration: underline; }

.login-card .primary-btn,
.login-card .secondary-btn {
    align-self: stretch;
    text-align: center;
    text-decoration: none;
}

.login-divider {
    color: var(--fg-soft);
    font-size: 0.85em;
    text-align: center;
    margin: 4px 0;
}

.login-error {
    color: var(--danger-fg) !important;
    font-weight: 500;
}

html.login-open .app-shell {
    visibility: hidden;
}

.help-menu-login summary {
    width: auto !important;
    padding: 0 10px !important;
    display: flex !important;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 550;
    border: 1px solid var(--border);
    border-radius: 10px;
    height: 36px;
    align-self: flex-start;
}

/* ── Админка: курсы валют ─────────────────────────────────────── */

.table-wrap {
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow-x: auto;
    background: var(--surface);
}

.rates-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
}

.rates-table caption {
    caption-side: top;
    text-align: left;
    padding: 12px 14px 4px;
    font-size: 10.5px;
    font-weight: 650;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
}

.rates-table th, .rates-table td {
    padding: 9px 14px;
    text-align: left;
    border-top: 1px solid var(--border);
    white-space: nowrap;
}

.rates-table thead th {
    border-top: 0;
    font-size: 11px;
    color: var(--muted);
    font-weight: 600;
}

.rate-name {
    display: block;
    font-weight: 400;
    font-size: 11px;
    color: var(--muted);
}

/* ── Админка: разделы (Курсы валют / Каталог сервисов) ────────────────── */

.admin-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.admin-nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 4px 12px;
    border: none;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 600;
    font-size: 13.5px;
    cursor: pointer;
}

.admin-nav-btn:hover { color: var(--fg); }

.admin-nav-btn.active {
    color: var(--fg);
    border-bottom-color: var(--accent);
}

.admin-panel { display: none; }
.admin-panel.active { display: block; }

.admin-section-title {
    margin: 18px 0 8px;
    font-size: 14px;
    font-weight: 650;
}

/* ── Каталог сервисов (админ-раздел + пикер в форме сервиса) ─────────── */

.catalog-admin-tab.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
}

.badge {
    display: inline-flex;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--danger);
    color: var(--on-accent);
    font-size: 10px;
    font-weight: 700;
    align-items: center;
    justify-content: center;
}

.catalog-table-icon { width: 26px; height: 26px; border-radius: 7px; }
.catalog-table-prices { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.catalog-pick-results {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 6px;
    max-height: 176px;
    overflow-y: auto;
}

.catalog-pick-results:empty { display: none; }

.catalog-pick-result {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 9px;
    border: none;
    border-radius: 9px;
    background: var(--fg-soft);
    color: var(--fg);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.catalog-pick-result:hover { background: var(--accent-soft); }

.catalog-pick-result .entity-icon { flex-shrink: 0; }

.catalog-pick-result-name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
}

.catalog-price-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.catalog-price-row select { flex: 0 0 auto; width: 92px; }
.catalog-price-row input { flex: 1; min-width: 0; }

/* ── Пользователи (админ-раздел) ──────────────────────────────────── */

.users-table-user {
    display: flex;
    align-items: center;
    gap: 8px;
}

.users-table-name {
    font-weight: 600;
    white-space: nowrap;
}

.users-table-handle {
    display: block;
    font-size: 11px;
    color: var(--muted);
    font-weight: 400;
}

.users-table-counts {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 11.5px;
    color: var(--muted);
}

.premium-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 650;
    background: var(--fg-soft);
    color: var(--muted);
}

.premium-badge.is-active {
    background: color-mix(in oklch, var(--chart-3) 22%, transparent);
    color: color-mix(in oklch, var(--chart-3) 70%, var(--fg));
}

.user-detail-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.user-detail-head .entity-icon { width: 48px; height: 48px; font-size: 18px; }
.user-detail-head .entity-icon img { width: 48px; height: 48px; border-radius: inherit; }

.user-detail-head-text { min-width: 0; }
.user-detail-name { font-size: 16px; font-weight: 650; }
.user-detail-handle { font-size: 12.5px; color: var(--muted); }

.user-detail-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px 12px;
    margin: 0 0 4px;
    font-size: 12.5px;
}

.user-detail-grid dt { color: var(--muted); }
.user-detail-grid dd { margin: 0; text-align: right; }

.user-detail-premium-status {
    font-size: 13px;
    margin: 0 0 10px;
}

.user-detail-days-input { width: 90px; }

.premium-timeline {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 220px;
    overflow-y: auto;
}

.premium-timeline-empty {
    font-size: 12px;
    color: var(--muted);
    margin: 0;
}

.premium-timeline-item {
    display: flex;
    gap: 8px;
    align-items: baseline;
    font-size: 12.5px;
    padding: 6px 0;
    border-top: 1px solid var(--border);
}

.premium-timeline-item:first-child { border-top: none; }

.premium-timeline-date {
    flex: 0 0 auto;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
}

.premium-timeline-text { min-width: 0; }
.premium-timeline-text b { font-weight: 650; }

/* ── Тосты ────────────────────────────────────────────────────── */

#toast {
    position: fixed;
    left: 50%;
    bottom: 84px;
    transform: translateX(-50%);
    z-index: 80;
    background: var(--fg);
    color: var(--bg);
    padding: 9px 15px;
    border-radius: 11px;
    font-size: 12.5px;
    font-weight: 550;
    max-width: min(85vw, 360px);
    text-align: center;
    pointer-events: none;
    animation: toast-in .2s ease;
}

@keyframes toast-in {
    from { opacity: 0; transform: translate(-50%, 8px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* ── Прочее ───────────────────────────────────────────────────── */

/* Карточка расходника: вертикальная раскладка рядами (шапка → мета →
   прогресс → футер). Одна и та же на мобиле и десктопе — не ломается
   при сужении и читается как референс. */
.cons-card {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
}

.cons-head {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

/* Кнопка-шапка: вся зона имени кликабельна (открывает редактирование) */
.cons-open {
    display: flex;
    flex: 1;
    min-width: 0;
    align-items: center;
    gap: 10px;
    text-align: left;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.cons-open .rc-name { flex: 1 1 auto; }

.cons-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    padding-left: 46px; /* под иконку в шапке: выравнивание по имени */
    font-size: 12px;
    color: var(--muted);
}

/* Статусный чип — у правого края своей строки, категория и прогноз слева */
.cons-meta .chip { margin-left: auto; }

.cons-meta.muted-line { opacity: .85; }

/* Прогресс запаса — во всю ширину карточки */
.cons-card .progress { max-width: 100%; }

.cons-foot {
    display: flex;
    align-items: center;
    gap: 10px;
}

.cons-foot .rc-actions {
    margin-left: auto;
    padding-left: 8px;
    /* страховка ≤360px: цена + ссылка + «Заказано» + удаление по 40px */
    flex-wrap: wrap;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    clip: rect(0 0 0 0);
    overflow: hidden;
}

body.tg-webapp { line-height: 1.45; }

@media (max-width: 480px) {
    .controls { gap: 8px; }
    .chart-body { flex-direction: row; }
    /* 12 подписей месяца в ряд слипаются на узком экране — оставляем
       каждую вторую (плюс текущий месяц всегда), полное значение всё
       ещё доступно в title-тултипе на самом столбце. */
    .trend-col:nth-child(odd):not(.is-current) .trend-label { visibility: hidden; }
}

/* Трек навигации: 6 разделов в ряд */

.app-nav-track {
    display: flex;
    gap: 2px;
    /* Не сжимаемся ниже контента: на узком экране трек уходит под
       горизонтальный скролл .app-nav, а кнопки не сплющиваются.
       На десктопе (≥1024px) трек влезает целиком — скролл не появляется. */
    flex: 1 0 auto;
    min-width: max-content;
}

.nav-btn {
    font-size: 10px;
    white-space: nowrap;
}

/* Шапка на узких экранах: помощь — только иконка, имя скрыто */

.app-header .help-menu > summary {
    width: auto;
    min-width: 38px;
    padding: 0 9px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 550;
}

@media (max-width: 519px) {
    .app-header .help-menu > summary span:not(.help-icon) { display: none; }
    #user-name { display: none; }
    .brand { flex-shrink: 0; }
}

/* ── Responsive: планшет ≥640px ───────────────────────────────── */

@media (min-width: 640px) {
    .app-header {
        padding-inline: max(20px, calc((100% - 720px) / 2));
    }

    .app-nav {
        padding-inline: max(12px, calc((100% - 720px) / 2));
    }

    .app-main {
        padding: 20px 24px 32px;
    }

    .view,
    .title-section {
        max-width: 720px;
        margin-inline: auto;
        width: 100%;
    }

    .stats-widgets { gap: 12px; }
}

/* ── Responsive: десктоп ≥1024px ──────────────────────────────── */

@media (min-width: 1024px) {
    /* Шапка и нижняя панель держат контент в той же колонке 1000px, что и
       основная сетка: кнопки навигации растягиваются равномерно */
    .app-header,
    .app-nav {
        padding-inline: max(24px, calc((100% - 1000px) / 2));
    }

    .app-nav-track {
        flex: 1;
        max-width: 1000px;
        margin-inline: auto;
    }

    .app-nav .nav-btn {
        flex-direction: row;
        gap: 8px;
        min-height: 52px;
        font-size: 12.5px;
    }

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

    .app-main { padding: 26px 28px 36px; }

    /* Контент тянется шире, но не бесконечно */
    .view,
    .title-section {
        max-width: 1000px;
        margin-inline: auto;
    }

    .title-section h1 { font-size: 27px; }

    .stats-widgets {
        grid-template-columns: repeat(4, 1fr);
        margin-bottom: 16px;
    }

    /* Списки карточек — в несколько колонок, карточки в ряду одной высоты */
    .card-list {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
        gap: 12px;
    }

    .card-list .row-card { height: 100%; }

    /* Ленты платежей: заголовок на всю ширину, строки сеткой */
    .lane {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
        gap: 12px;
    }

    .lane-head { grid-column: 1 / -1; }

    .lane .row-card { height: 100%; }

    /* Список прикреплён к виджету «Ближайшие списания»: одна колонка в ячейке,
       длинный список скроллится, а не растягивает сетку */
    #upcoming-list {
        max-height: 264px;
        overflow-y: auto;
    }

    .upcoming-item {
        flex-direction: row;
        align-items: baseline;
        justify-content: space-between;
        gap: 10px;
    }

    .chart-body {
        align-items: center;
        padding-block: 6px;
    }
}


/* === Spaces UI (Task 7) === */
.member-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.member-row:last-child {
    border-bottom: none;
}

.member-chip {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--fg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    flex-shrink: 0;
}

.member-name {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
}

.history-amount {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    flex-shrink: 0;
    text-align: right;
}

.invite-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.invite-row input[readonly] {
    flex: 1;
    min-width: 0;
}

.muted {
    color: var(--muted, var(--fg));
    opacity: 0.7;
}
