/* ==========================================================================
   MySubs — visual world: "Схема" (transit map)
   Paper field, ink type, line-colour data, hairline rules, dense grid.
   Light = paper (primary). Dark = night map.
   ========================================================================== */

:root {
    --paper: #f4f2ec;
    --panel: #fbfaf6;
    --panel-2: #ece9e0;
    --ink: #14161a;
    --ink-soft: #4a4f57;
    --muted: #666c74;
    --rule: #d8d3c6;
    --rule-strong: #c2bcac;
    --field: #ffffff;

    --line-red: #d33a2c;
    --line-blue: #2f5fd0;
    --line-green: #12915b;
    --line-amber: #e6a100;
    --line-violet: #6a4fd0;
    --line-teal: #0f8a8a;

    --danger: #c0392b;
    --warn: #8a6508;
    --ok: #0f7a4c;

    --shadow: 0 1px 2px rgba(20, 22, 26, 0.05), 0 8px 24px rgba(20, 22, 26, 0.06);
    --shadow-lift: 0 2px 4px rgba(20, 22, 26, 0.08), 0 18px 48px rgba(20, 22, 26, 0.14);

    --radius: 14px;
    --radius-sm: 8px;
    --control-h: 34px;

    --font: 'Golos Text', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

[data-theme="dark"] {
    --paper: #12141a;
    --panel: #171a21;
    --panel-2: #1e222b;
    --ink: #f1efe8;
    --ink-soft: #b9bec7;
    --muted: #7d838d;
    --rule: #2a2f39;
    --rule-strong: #3a404c;
    --field: #1b1f27;

    --line-red: #ef5a48;
    --line-blue: #5b81e8;
    --line-green: #2fb377;
    --line-amber: #f0b429;
    --line-violet: #8a72e0;
    --line-teal: #2aa3a3;

    --danger: #ef5a48;
    --warn: #f0b429;
    --ok: #2fb377;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.4);
    --shadow-lift: 0 2px 6px rgba(0, 0, 0, 0.5), 0 24px 60px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
    font-family: var(--font);
    background: var(--paper);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.45;
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

.bg-glow { display: none; }

.app-container {
    max-width: 1180px;
    margin: 0 auto;
    padding: 20px 24px 96px;
}

/* ---------- Micro labels ---------- */
.stat-label,
.form-label,
.chart-subtitle,
.rates-status,
.group-badge,
.unused-badge,
.tbl-badge,
.subscription-category,
.ana-hint,
.bulk-count,
.calendar-weekdays,
.section-cap {
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
}

/* ---------- Header ---------- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 0 16px;
    border-bottom: 1px solid var(--rule);
    margin-bottom: 0;
}

.logo-wrap { display: flex; align-items: center; gap: 10px; }

.logo-icon {
    display: grid;
    place-items: center;
    color: var(--ink);
}

.logo-svg { display: block; height: 22px; width: auto; color: var(--ink); }
.logo-svg .logo-cut { fill: var(--paper); }
.logo-svg .logo-check { fill: none; stroke: var(--paper); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }

.app-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.header-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- Buttons ---------- */
.btn {
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
    background: var(--panel);
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius-sm);
    padding: 8px 13px;
    height: var(--control-h);
    white-space: nowrap;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    transition: background .12s ease, border-color .12s ease, color .12s ease, transform .05s ease;
}
.btn:hover { border-color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--line-blue); outline-offset: 1px; }

.btn-glass { background: transparent; border-color: var(--rule); color: var(--ink-soft); }
.btn-glass:hover { color: var(--ink); border-color: var(--ink); }

.btn-primary {
    background: var(--ink);
    color: var(--paper);
    border-color: var(--ink);
}
.btn-primary:hover { background: #000; border-color: #000; }
[data-theme="dark"] .btn-primary:hover { background: #fff; border-color: #fff; color: #12141a; }

.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-success { color: var(--ok); border-color: var(--ok); background: transparent; }
.btn-success:hover { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn-sm { padding: 5px 10px; font-size: 12px; height: auto; }
.btn-lg { padding: 12px 20px; height: auto; font-size: 15px; font-weight: 600; }
.btn-block { width: 100%; justify-content: center; }
body.modal-open { overflow: hidden; }

.btn-shimmer { position: relative; overflow: hidden; }

.icon-btn {
    width: var(--control-h);
    height: var(--control-h);
    display: inline-grid;
    place-items: center;
    background: transparent;
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
    color: var(--ink-soft);
    cursor: pointer;
    transition: color .12s, border-color .12s, background .12s;
}
.icon-btn:hover { color: var(--ink); border-color: var(--ink); background: var(--panel-2); }
.icon-btn-danger:hover { color: var(--danger); border-color: var(--danger); }

.currency-switch { display: inline-flex; }
.currency-select {
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
    background: var(--panel);
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
    padding: 7px 9px;
    height: var(--control-h);
    cursor: pointer;
}

.theme-icon { display: none; line-height: 1; }
[data-theme="dark"] .dark-icon { display: inline; }
[data-theme="light"] .light-icon { display: inline; }

.notify-status { font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.notify-on .notify-status { color: var(--ok); }

/* ---------- Tabs (line-colour rail) ---------- */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--rule);
    margin-bottom: 22px;
}
.tab {
    position: relative;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 12px 14px;
    margin-bottom: -1px;
    cursor: pointer;
    transition: color .12s, border-color .12s;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--line-red); }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Summary strip (replaces neon stat cards) ---------- */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--panel);
    margin-bottom: 18px;
    overflow: hidden;
}
.stat-card {
    position: relative;
    padding: 13px 16px;
    border-right: 1px solid var(--rule);
}
.stat-card:last-child { border-right: none; }
.stat-bg, .stat-icon { display: none; }
.stat-value {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--ink);
}
.stat-card-warning .stat-value { color: var(--warn); }
.stat-card-danger .stat-value { color: var(--danger); }
.stat-label { display: block; margin-top: 3px; }

/* ---------- The map (signature) ---------- */
.map-panel {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
    gap: 0;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--panel);
    margin-bottom: 18px;
    overflow: hidden;
}
.map-main { padding: 16px 18px 18px; border-right: 1px solid var(--rule); min-width: 0; }
.map-side { padding: 16px 18px 18px; min-width: 0; background: var(--panel); }

.map-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.map-head h2 { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.map-legend { display: flex; flex-wrap: wrap; gap: 10px 14px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.legend-swatch { width: 14px; height: 3px; border-radius: 2px; }

.map-tools { display: flex; gap: 8px; align-items: center; }
.cal-nav {
    width: 26px; height: 26px; flex: none;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--rule); border-radius: 50%;
    background: var(--panel-2); color: var(--ink-soft);
    font-family: inherit; font-size: 15px; line-height: 1; padding: 0;
    cursor: pointer; transition: border-color .12s, color .12s;
}
.cal-nav:hover { border-color: var(--ink); color: var(--ink); }
.cal-label {
    min-width: 116px; padding: 0;
    background: none; border: none; cursor: pointer;
    font-family: inherit; font-size: 12px; font-weight: 700; color: var(--ink-soft);
    text-align: center; text-transform: capitalize;
}
.cal-label:hover { color: var(--ink); }

.cal { margin-top: 2px; }
.cal-head { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 6px; }
.cal-wd { text-align: center; font-size: 11px; font-weight: 600; color: var(--muted); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-cell {
    position: relative;
    min-height: 52px;
    display: flex; flex-direction: column; justify-content: space-between;
    padding: 6px 7px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--panel-2);
    color: var(--ink);
}
.cal-blank { background: transparent; border-color: transparent; }
.cal-cell.today { border-color: var(--ink); }
.cal-num { font-size: 12px; font-weight: 700; line-height: 1; }
.cal-val { font-size: 11px; font-weight: 700; align-self: flex-end; font-variant-numeric: tabular-nums; }
.cal-cell.l3, .cal-cell.l4 { color: #fff; }

.heat-legend { display: inline-flex; align-items: center; gap: 3px; }
.heat-legend-label { color: var(--muted); font-size: 11px; font-weight: 600; }
.heat-legend-swatch { width: 11px; height: 11px; border-radius: 2px; display: inline-block; }
.heat-legend-metric { color: var(--muted); font-size: 11px; font-weight: 700; margin-left: 8px; text-transform: uppercase; letter-spacing: .05em; }

/* ---------- Next charges panel ---------- */
.next-list { display: flex; flex-direction: column; }
.next-row {
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr) auto;
    align-items: baseline;
    gap: 10px;
    padding: 9px 0;
    border-bottom: 1px solid var(--rule);
    cursor: default;
}
.next-row:last-child,
.next-list .next-row:nth-last-child(2) { border-bottom: none; }
.next-date { font-size: 12px; font-weight: 700; color: var(--ink); }
.next-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.next-price { font-size: 12px; font-weight: 600; color: var(--ink-soft); text-align: right; }
.next-tag { font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.next-tag.soon { color: var(--warn); }
.next-tag.expired { color: var(--danger); }
.next-summary { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--rule); font-size: 12px; color: var(--ink-soft); }

/* ---------- Map side segments ---------- */
.side-seg { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; }
.seg-btn {
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-soft);
    background: var(--panel-2);
    border: 1px solid var(--rule);
    border-radius: 999px;
    padding: 4px 11px;
    cursor: pointer;
    transition: border-color .12s, color .12s, background .12s;
}
.seg-btn:hover { border-color: var(--ink); color: var(--ink); }
.seg-btn.active { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.seg-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.side-metric { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.side-metric-value { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.side-metric-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.side-note { font-size: 12px; color: var(--ink-soft); margin-bottom: 12px; }
.side-more { font-size: 12px; color: var(--muted); padding: 8px 0 2px; }

.forecast-strip { display: flex; align-items: flex-end; gap: 2px; height: 46px; margin: 2px 0 14px; }
.fs-bar { flex: 1; min-width: 0; background: var(--panel-2); border-radius: 2px 2px 0 0; }

.side-stats { display: flex; flex-direction: column; }
.side-stat {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px solid var(--rule);
    font-size: 13px;
}
.side-stat:last-child { border-bottom: none; }
.side-stat span { color: var(--ink-soft); }
.side-stat strong { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- Charts ---------- */
.charts-section { margin-bottom: 20px; }
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-card {
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--panel);
    padding: 14px 16px 16px;
}
.chart-header { margin-bottom: 8px; }
.chart-title { font-size: 14px; font-weight: 700; letter-spacing: -0.01em; }
.chart-subtitle { letter-spacing: .06em; }
.chart-wrapper { position: relative; height: 210px; }

/* ---------- Filters ---------- */
.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 12px 0;
    border-top: 1px solid var(--rule);
    border-bottom: 1px solid var(--rule);
    margin-bottom: 0;
}
.filter-group { display: flex; flex-wrap: wrap; gap: 6px; }
.filter-btn {
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-soft);
    background: transparent;
    border: 1px solid var(--rule);
    border-radius: 100px;
    padding: 6px 12px;
    cursor: pointer;
    transition: all .12s;
}
.filter-btn:hover { border-color: var(--ink); color: var(--ink); }
.filter-btn.active { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.search-group { flex: 1 1 200px; min-width: 160px; }
.search-input {
    width: 100%;
    font-family: inherit;
    font-size: 13px;
    color: var(--ink);
    background: var(--field);
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
    padding: 8px 11px;
    height: var(--control-h);
}
.search-input::placeholder { color: var(--muted); }
.search-input:focus { outline: none; border-color: var(--ink); }

.view-toggle { display: inline-flex; height: var(--control-h); border: 1px solid var(--rule); border-radius: var(--radius-sm); overflow: hidden; }
.view-btn {
    width: 34px;
    display: grid; place-items: center;
    background: var(--panel);
    border: none;
    color: var(--muted);
    cursor: pointer;
}
.view-btn:first-child { border-right: 1px solid var(--rule); }
.view-btn.active { background: var(--panel-2); color: var(--ink); }

.group-filter {
    font-family: inherit; font-size: 12px; font-weight: 600; color: var(--ink);
    background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-sm);
    padding: 7px 9px; height: var(--control-h); cursor: pointer; max-width: 180px;
}

/* ---------- Rates bar ---------- */
.rates-bar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 9px 0 14px;
}
.rates-status { letter-spacing: .04em; }
.rates-status.error { color: var(--danger); }
.rates-status.stale { color: var(--warn); }

/* ---------- Subscription list / cards ---------- */
.subscriptions-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding-top: 16px; }
.subscriptions-list.view-table { display: block; padding-top: 16px; }

.subscription-card {
    position: relative;
    background: var(--panel);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    padding: 13px 14px;
    cursor: pointer;
    transition: border-color .12s, box-shadow .12s, transform .05s;
}
.subscription-card:hover { box-shadow: var(--shadow); }
.subscription-card:active { transform: translateY(1px); }
.subscription-card.expiring-soon { border-color: var(--warn); }
.subscription-card.expired { border-color: var(--danger); opacity: .72; }
.subscription-card.card-unused { opacity: .6; }

.subscription-card-header { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }
.select-wrap { display: inline-flex; }
.card-check { width: 15px; height: 15px; accent-color: var(--ink); cursor: pointer; }
.sub-icon {
    width: 30px; height: 30px; flex: none;
    display: grid; place-items: center;
    font-size: 15px;
    border: 1px solid var(--rule);
    border-radius: var(--radius-sm);
    background: var(--panel-2) !important;
}
.subscription-name { font-size: 14px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; letter-spacing: -0.01em; }
.subscription-price-wrap { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.subscription-price { font-size: 14px; font-weight: 700; white-space: nowrap; }
.card-price-converted { font-size: 12px; color: var(--muted); white-space: nowrap; }

.subscription-card-body { display: flex; flex-direction: column; gap: 6px; }
.subscription-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 2px; }
.subscription-category { color: var(--ink-soft); }
.group-badge { color: var(--ink-soft); padding: 1px 6px; border: 1px solid var(--rule); border-radius: 100px; letter-spacing: .05em; }
.unused-badge { color: var(--warn); letter-spacing: .05em; }
.subscription-autorenew { font-size: 12px; font-weight: 600; color: var(--muted); }

.subscription-info-row { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; border-top: 1px solid var(--rule); padding-top: 6px; }
.subscription-info-label { color: var(--muted); font-size: 11px; letter-spacing: .04em; text-transform: uppercase; font-weight: 600; }
.subscription-info-value { color: var(--ink); font-weight: 600; }
.subscription-days-left { font-weight: 700; }
.days-normal { color: var(--ok); }
.days-warning { color: var(--warn); }
.days-danger { color: var(--danger); }
.subscription-cancel-remind { font-size: 12px; font-weight: 700; color: var(--warn); letter-spacing: .03em; }
.sub-notes { font-size: 12px; color: var(--ink-soft); border-top: 1px solid var(--rule); padding-top: 6px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--panel); }
.subs-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.subs-table th, .subs-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.subs-table th {
    font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
    background: var(--panel-2); position: sticky; top: 0;
}
.subs-table th.sortable { cursor: pointer; user-select: none; }
.subs-table th.sortable:hover { color: var(--ink); }
.subs-table th.sorted { color: var(--ink); }
.subs-table tbody tr { transition: background .1s; }
.subs-table tbody tr:hover { background: var(--panel-2); }
.subs-table tbody tr:last-child td { border-bottom: none; }
.th-select, .th-actions { width: 40px; }
.row-check { width: 15px; height: 15px; accent-color: var(--ink); }
.row-expired { opacity: .6; }
.row-expiring { background: color-mix(in srgb, var(--warn) 8%, transparent); }
.row-unused { opacity: .55; }
.tbl-name { display: flex; align-items: center; gap: 9px; }
.tbl-icon { width: 26px; height: 26px; flex: none; display: grid; place-items: center; font-size: 13px; border: 1px solid var(--rule); border-radius: var(--radius-sm); }
.tbl-title { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tbl-title strong { font-weight: 700; }
.tbl-muted { color: var(--muted); }
.tbl-badge { font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-soft); border: 1px solid var(--rule); border-radius: 100px; padding: 1px 6px; }
.tbl-badge-warn { color: var(--warn); border-color: var(--warn); }
.td-num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.td-date { color: var(--ink-soft); }
.td-actions { display: flex; gap: 5px; }

/* ---------- Empty states ---------- */
.empty-state { grid-column: 1 / -1; text-align: center; padding: 56px 20px; color: var(--muted); border: 1px dashed var(--rule-strong); border-radius: var(--radius); }
.empty-state-icon { font-size: 26px; margin-bottom: 8px; }
.empty-state-text { font-size: 14px; }
.empty-note { color: var(--muted); font-size: 13px; padding: 8px 0; }

/* ---------- Calendar ---------- */
.calendar-card { border: 1px solid var(--rule); border-radius: var(--radius); background: var(--panel); padding: 16px 18px 18px; }
.calendar-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.calendar-nav { display: flex; align-items: center; gap: 10px; }
.calendar-month { font-size: 15px; font-weight: 700; min-width: 150px; text-align: center; letter-spacing: -0.01em; text-transform: capitalize; }
.calendar-summary { font-size: 12px; color: var(--ink-soft); }
.calendar-summary strong { color: var(--ink); }
.calendar-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; padding-bottom: 8px; }
.calendar-weekdays span { text-align: center; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: var(--radius-sm); overflow: hidden; }
.cal-day { background: var(--panel); min-height: 78px; padding: 7px 8px; display: flex; flex-direction: column; gap: 3px; cursor: pointer; transition: background .1s; }
.cal-day:hover { background: var(--panel-2); }
.cal-day.other-month { background: var(--paper); color: var(--muted); }
.cal-day.other-month .cal-day-num { color: var(--muted); }
.cal-day.today { box-shadow: inset 0 0 0 2px var(--ink); }
.cal-day.selected { background: var(--panel-2); box-shadow: inset 0 0 0 2px var(--line-blue); }
.cal-day.has-charges .cal-day-num { font-weight: 700; }
.cal-day-num { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.cal-day-total { font-size: 10px; font-weight: 700; color: var(--line-red); }
.cal-day-chips { display: flex; flex-wrap: wrap; gap: 2px; margin-top: auto; }
.cal-chip { font-size: 12px; line-height: 1; }
.calendar-detail { margin-top: 16px; border-top: 1px solid var(--rule); padding-top: 14px; }
.cal-detail-empty { color: var(--muted); font-size: 13px; }
.cal-detail-date { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.cal-detail-item { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--rule); }
.cal-detail-item:last-child { border-bottom: none; }
.cdi-name { flex: 1; font-weight: 600; }
.cdi-price { font-weight: 700; }

/* ---------- Analytics ---------- */
.analytics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.ana-card { border: 1px solid var(--rule); border-radius: var(--radius); background: var(--panel); padding: 15px 17px; }
.ana-card-wide { grid-column: 1 / -1; }
.ana-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.ana-head h2 { font-size: 14px; font-weight: 700; letter-spacing: -0.01em; }
.ana-metric { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.ana-savings { color: var(--ok); }
.ana-bar { height: 6px; background: var(--panel-2); border-radius: 100px; overflow: hidden; margin: 10px 0; }
.ana-bar-fill { height: 100%; background: var(--line-blue); border-radius: 100px; transition: width .3s; }
.ana-bar-fill.warn { background: var(--warn); }
.ana-bar-fill.danger { background: var(--danger); }
.ana-sub { font-size: 12px; color: var(--ink-soft); }
.ana-sub .up { color: var(--danger); font-weight: 700; }
.ana-sub .down { color: var(--ok); font-weight: 700; }

.groups-breakdown { display: flex; flex-direction: column; gap: 12px; }
.group-row-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 5px; }
.gr-name { font-size: 12px; color: var(--ink); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.gr-sum { font-size: 12px; font-weight: 700; color: var(--ink-soft); }
.group-row-bar { height: 6px; background: var(--panel-2); border-radius: 100px; overflow: hidden; }
.group-row-fill { height: 100%; background: var(--line-blue); border-radius: 100px; }
.group-row:nth-child(1) .group-row-fill { background: var(--line-red); }
.group-row:nth-child(2) .group-row-fill { background: var(--line-blue); }
.group-row:nth-child(3) .group-row-fill { background: var(--line-green); }
.group-row:nth-child(4) .group-row-fill { background: var(--line-amber); }
.group-row:nth-child(5) .group-row-fill { background: var(--line-violet); }

.issues-list { display: flex; flex-direction: column; gap: 8px; }
.issue-item { display: flex; gap: 10px; padding: 11px 13px; border: 1px solid var(--rule); border-radius: var(--radius-sm); background: var(--paper); }
.issue-warn { border-color: var(--warn); }
.issue-info { border-color: var(--line-blue); }
.issue-ok { border-color: var(--ok); }
.issue-icon { font-size: 16px; line-height: 1.4; }
.issue-title { font-size: 13px; font-weight: 700; }
.issue-desc { font-size: 12px; color: var(--ink-soft); }

/* ---------- Templates ---------- */
.templates-body { padding: 16px 18px 18px; }
.templates-hint { margin-bottom: 12px; }
.templates-search { margin-bottom: 14px; }
.templates-grid { display: block; max-height: 60vh; overflow-y: auto; }
.templates-empty { padding: 20px 4px; color: var(--muted); font-size: 13px; text-align: center; }
.template-group { margin-bottom: 16px; }
.template-group:last-child { margin-bottom: 0; }
.template-group-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.template-group-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.template-add {
    font-family: inherit; font-size: 11px; font-weight: 700; color: var(--ink-soft);
    background: none; border: 1px solid var(--rule); border-radius: var(--radius-sm);
    padding: 3px 8px; cursor: pointer; white-space: nowrap;
    transition: border-color .12s, color .12s, background .12s;
}
.template-add:hover { border-color: var(--ink); color: var(--ink); background: var(--panel-2); }
.template-group-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.template-item { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-sm); padding: 6px 8px 6px 10px; transition: border-color .12s, background .12s; }
.template-item:hover { border-color: var(--ink); background: var(--panel-2); }
.template-main { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; text-align: left; font-family: inherit; font-size: inherit; color: inherit; background: none; border: none; padding: 4px 0; cursor: pointer; }
.template-icon { font-size: 18px; }
.template-info { display: flex; flex-direction: column; min-width: 0; }
.template-name { font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.template-price { font-size: 11px; color: var(--muted); }
.template-actions { display: flex; gap: 2px; flex: none; transition: opacity .12s; }
@media (hover: hover) {
    .template-item-custom .template-actions { opacity: 0; }
    .template-item-custom:hover .template-actions,
    .template-item-custom:focus-within .template-actions { opacity: 1; }
}
.template-act {
    font-family: inherit; font-size: 13px; line-height: 1; color: var(--muted);
    background: none; border: none; padding: 4px 5px; border-radius: var(--radius-sm); cursor: pointer;
    transition: color .12s, background .12s;
}
.template-act:hover { color: var(--ink); background: var(--panel-2); }

/* ---------- Bulk bar ---------- */
.bulk-bar {
    position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 200%);
    display: flex; align-items: center; gap: 14px;
    background: var(--ink); color: var(--paper);
    border-radius: var(--radius); padding: 10px 14px;
    box-shadow: var(--shadow-lift);
    transition: transform .2s ease, opacity .2s ease, visibility .2s;
    opacity: 0; visibility: hidden; pointer-events: none;
    z-index: 60;
}
.bulk-bar.active { transform: translate(-50%, 0); opacity: 1; visibility: visible; pointer-events: auto; }
.bulk-count { color: var(--paper); }
.bulk-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.bulk-bar .btn { background: transparent; border-color: rgba(255,255,255,.35); color: var(--paper); }
.bulk-bar .btn:hover { border-color: var(--paper); }
.bulk-bar .btn-danger { color: #ffb4aa; border-color: #ffb4aa; }
.bulk-bar .btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 100; }
.modal.active { display: flex; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 22, 26, .5); backdrop-filter: blur(2px); }
[data-theme="dark"] .modal-backdrop { background: rgba(0,0,0,.65); }
.modal-content {
    position: relative;
    width: 100%; max-width: 620px;
    background: var(--panel);
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lift);
    animation: pop .16s ease;
}
.modal-sm { max-width: 440px; }
.modal-lg { max-width: 900px; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--rule); }
.modal-title { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.modal-close { font-size: 22px; line-height: 1; background: none; border: none; color: var(--muted); cursor: pointer; padding: 0 4px; }
.modal-close:hover { color: var(--ink); }

.subscription-form { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { grid-template-columns: 1.3fr 1fr 1fr; }
.form-row-icon { grid-template-columns: 84px 1fr; }
.form-label { letter-spacing: .05em; }
.form-input {
    font-family: inherit; font-size: 13px; color: var(--ink); background: var(--field);
    border: 1px solid var(--rule); border-radius: var(--radius-sm); padding: 9px 11px;
    width: 100%; min-width: 0; max-width: 100%;
}
.form-input:focus { outline: none; border-color: var(--ink); }
select.form-input { text-overflow: ellipsis; cursor: pointer; }
.form-textarea { resize: vertical; min-height: 54px; }
.form-hint { font-size: 12px; color: var(--muted); }

.toggle { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 13px; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-slider { position: relative; width: 38px; height: 22px; background: var(--panel-2); border: 1px solid var(--rule); border-radius: 100px; transition: background .15s, border-color .15s; flex: none; }
.toggle-slider::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: var(--ink); border-radius: 50%; transition: transform .15s; }
.toggle input:checked + .toggle-slider { background: var(--ink); border-color: var(--ink); }
.toggle input:checked + .toggle-slider::after { transform: translateX(16px); background: var(--paper); }
.toggle-label { font-size: 13px; color: var(--ink-soft); }

.color-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.color-option { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; box-shadow: 0 0 0 1px var(--rule); cursor: pointer; padding: 0; }
.color-option.active { border-color: var(--ink); }
.color-custom { position: relative; overflow: hidden; background: conic-gradient(from 210deg, #d33a2c, #e6a100, #12915b, #0f8a8a, #2f5fd0, #6a4fd0, #d33a2c); }
.color-custom input[type="color"] { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; margin: 0; border: 0; opacity: 0; background: transparent; cursor: pointer; -webkit-appearance: none; appearance: none; }
.color-custom input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-custom input[type="color"]::-webkit-color-swatch { border: 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* ---------- Toast ---------- */
.toast {
    position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 140%);
    background: var(--ink); color: var(--paper);
    padding: 11px 16px; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 600;
    box-shadow: var(--shadow-lift);
    z-index: 200; transition: transform .2s ease; max-width: 90vw;
}
.toast.show { transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
    .subscriptions-list { grid-template-columns: repeat(2, 1fr); }
    .map-panel { grid-template-columns: 1fr; }
    .map-main { border-right: none; border-bottom: 1px solid var(--rule); }
    .analytics-grid { grid-template-columns: 1fr; }
    .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
    .app-container { padding: 16px 14px 96px; }
    .app-header { flex-wrap: wrap; }
    .header-actions { width: 100%; flex-wrap: wrap; }
    .header-actions .btn-primary { flex: 1 1 100%; justify-content: center; margin-left: 0; }
    .stats-bar { grid-template-columns: repeat(2, 1fr); }
    .stat-card { border-bottom: 1px solid var(--rule); }
    .stat-card:nth-child(odd) { border-right: 1px solid var(--rule); }
    .subscriptions-list { grid-template-columns: 1fr; }
    .template-group-grid { grid-template-columns: repeat(2, 1fr); }
    .form-row, .form-row-3 { grid-template-columns: 1fr; }
    .filters { gap: 8px; }
    .search-group { flex-basis: 100%; }
    .cal-cell { min-height: 44px; padding: 5px 6px; }
    .cal-val { font-size: 10px; }
}

@media (max-width: 520px) {
    .template-group-grid { grid-template-columns: 1fr; }
    .cal-cell { min-height: 38px; }
    .cal-num, .cal-val { font-size: 10px; }
    .cal-head { gap: 3px; }
    .cal-grid { gap: 3px; }
    .cal-label { min-width: 96px; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
