:root {
    --color-bg: #f4f5f7;
    --color-surface: #ffffff;
    --color-text: #1f2430;
    --color-muted: #6b7280;
    --color-border: #e5e7eb;
    --color-accent: #2563eb;
    --color-accent-hover: #1d4ed8;
    --color-error: #dc2626;
    --color-error-bg: #fef2f2;
    --color-ok: #16a34a;
    --color-ok-bg: #f0fdf4;
    --color-warn: #d97706;
    --color-warn-bg: #fffbeb;
    --radius: 8px;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

/* ---- Индикатор загрузки при переходе по обычным ссылкам ----
   Обычная навигация браузером не даёт SPA-подобного мгновенного отклика — на
   медленных страницах (напр. ОПиУ считает отчёт по всем магазинам ~2-3с) клик
   по вкладке иначе выглядит как «ничего не произошло». Полоска появляется по
   JS-обработчику в app.js сразу на клик и просто исчезает вместе со старой
   страницей, когда придёт новая — отдельно скрывать её не нужно. */
.nav-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 100%;
    background: var(--color-accent);
    transform: scaleX(0);
    transform-origin: left;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
}
html.is-navigating .nav-progress {
    opacity: 1;
    animation: nav-progress-anim 1.4s ease-in-out infinite;
}
@keyframes nav-progress-anim {
    0% { transform: scaleX(0); }
    50% { transform: scaleX(0.6); }
    100% { transform: scaleX(0.92); }
}

body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

[x-cloak] { display: none !important; }

/* ---- Навигация ---- */
.topnav {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.topnav-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 16px;
    height: 56px;
}

.topnav-brand {
    font-weight: 700;
    color: var(--color-text);
    white-space: nowrap;
}
.topnav-brand:hover { text-decoration: none; }

.topnav-tabs {
    display: flex;
    gap: 4px;
    flex: 1;
    overflow-x: auto;
}

.topnav-tab {
    padding: 8px 12px;
    border-radius: var(--radius);
    color: var(--color-muted);
    white-space: nowrap;
    font-size: 14px;
}
.topnav-tab:hover { background: var(--color-bg); text-decoration: none; }
.topnav-tab.is-active {
    color: var(--color-accent);
    font-weight: 600;
    background: var(--color-bg);
}

.topnav-right {
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
    white-space: nowrap;
}

.topnav-settings { font-size: 14px; color: var(--color-muted); }

.topnav-user { position: relative; }
.topnav-user-btn {
    background: none;
    border: none;
    font-family: inherit;
    font-size: 14px;
    color: var(--color-text);
    cursor: pointer;
    padding: 8px 4px;
}

.topnav-user-menu {
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
    min-width: 160px;
    padding: 6px;
    display: flex;
    flex-direction: column;
}
.topnav-user-menu a, .topnav-user-menu .link-button {
    padding: 8px 10px;
    border-radius: 6px;
    color: var(--color-text);
    text-align: left;
}
.topnav-user-menu a:hover, .topnav-user-menu .link-button:hover {
    background: var(--color-bg);
    text-decoration: none;
}

.link-button {
    background: none;
    border: none;
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    width: 100%;
}

/* ---- Layout ---- */
.page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 16px 64px;
}

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

.page-header { margin-bottom: 20px; }
.page-header h1 { margin: 0; font-size: 22px; }
.page-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
}

.muted { color: var(--color-muted); }
.hint { display: block; font-size: 12px; color: var(--color-muted); margin-top: 4px; }
.inline-result { display: inline-block; margin-left: 10px; vertical-align: middle; }
.inline-result .alert { margin-bottom: 0; padding: 6px 10px; }

/* ---- Настройки: вкладки ---- */
.settings-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 20px;
}
.settings-tab {
    padding: 10px 14px;
    color: var(--color-muted);
    font-size: 14px;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.settings-tab:hover { color: var(--color-text); text-decoration: none; }
.settings-tab.is-active {
    color: var(--color-accent);
    font-weight: 600;
    border-bottom-color: var(--color-accent);
}

select[multiple] { min-width: 220px; }

.btn-danger { color: var(--color-error); }
.btn-danger:hover { background: var(--color-error-bg); }

.icon-btn {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    width: 30px;
    height: 30px;
    font-size: 14px;
    line-height: 1;
    color: var(--color-muted);
    cursor: pointer;
}
.icon-btn:hover { background: var(--color-bg); color: var(--color-text); }
.icon-btn-danger:hover { color: var(--color-error); background: var(--color-error-bg); border-color: var(--color-error-bg); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn:disabled:hover { background: none; color: var(--color-muted); }

.checkbox-inline { flex-direction: row !important; align-items: center; gap: 8px !important; font-size: 14px !important; color: var(--color-text) !important; }

.input-with-btn { display: flex; gap: 8px; }
.input-with-btn input { flex: 1; min-width: 0; }
.input-with-btn .btn { white-space: nowrap; }

/* ---- Cards / forms ---- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}
.card h2 { margin-top: 0; font-size: 16px; }

.auth-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 360px;
}
.auth-card h1 { font-size: 18px; margin-top: 0; }

.form-stack { display: flex; flex-direction: column; gap: 14px; max-width: 420px; }
.form-stack label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--color-muted); }
.inline-form { display: inline-block; }

input[type="text"], input[type="password"], input[type="search"], input[type="date"], select {
    font-family: inherit;
    font-size: 14px;
    padding: 9px 10px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    color: var(--color-text);
    background: var(--color-surface);
}
input:disabled { color: var(--color-muted); background: var(--color-bg); }

.btn {
    display: inline-block;
    border: none;
    border-radius: 6px;
    padding: 9px 16px;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
}
.btn-primary { background: var(--color-accent); color: #fff; }
.btn-primary:hover { background: var(--color-accent-hover); }
.btn-secondary { background: var(--color-bg); color: var(--color-text); border: 1px solid var(--color-border); }
.btn-small { padding: 5px 10px; font-size: 12px; background: var(--color-bg); border: 1px solid var(--color-border); }

.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; }
.alert-error { background: var(--color-error-bg); color: var(--color-error); }
.alert-ok { background: var(--color-ok-bg); color: var(--color-ok); }

/* ---- Tiles ---- */
.tiles {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.tile {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 14px 16px;
}
.tile-warn { background: var(--color-warn-bg); }
.tile-value { font-size: 20px; font-weight: 700; }
.tile-label { font-size: 12px; color: var(--color-muted); margin-top: 2px; }
.tile-link { display: block; color: var(--color-text); }
.tile-link:hover { text-decoration: none; border-color: var(--color-accent); }

/* ---- Table ---- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}
.data-table th, .data-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    font-size: 14px;
}
.data-table th { color: var(--color-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.data-table tr:last-child td { border-bottom: none; }
.actions { display: flex; gap: 6px; }

/* ---- ОПиУ: колонка на месяц, переменное число колонок — не участвует в
   мобильной card-раскладке .data-table (см. .wh-table-scroll), поэтому
   отдельный класс с той же визуальной базой, а не .data-table. ---- */
.pnl-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}
.pnl-table th, .pnl-table td {
    padding: 4px 10px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    font-size: 12.5px;
    line-height: 1.3;
    white-space: nowrap;
}
.pnl-table th { padding-top: 6px; padding-bottom: 6px; color: var(--color-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; }
.pnl-table tr:last-child td { border-bottom: none; }
.pnl-table .chevron-btn { font-size: 12px; padding: 2px 6px; }
.pnl-cell { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.pnl-pct { font-size: 11px; }
.pnl-delta { font-size: 11px; }

/* ---- РНП: "По артикулам" — Артикул/Магазин закреплены при горизонтальном
   скролле (много колонок-метрик, см. templates/rnp_articles.html). Отдельная
   фоновая заливка на каждой sticky-ячейке — иначе прокрученные колонки
   просвечивают сквозь закреплённые. ---- */
.rnp-articles-table th, .rnp-articles-table td { white-space: nowrap; }
.rnp-articles-table .rnp-sticky-1,
.rnp-articles-table .rnp-sticky-2 {
    position: sticky;
    background: var(--color-surface);
    z-index: 1;
}
.rnp-articles-table .rnp-sticky-1 { left: 0; min-width: 220px; max-width: 220px; white-space: normal; }
.rnp-articles-table .rnp-sticky-2 { left: 220px; min-width: 110px; }
.rnp-articles-table thead .rnp-sticky-1,
.rnp-articles-table thead .rnp-sticky-2 { z-index: 2; }
.rnp-total-row td { background: var(--color-bg); }
.rnp-total-row .rnp-sticky-1 { background: var(--color-bg); }

/* компактный размер — 2283 артикула, важно вместить больше строк на экран */
.rnp-articles-table th, .rnp-articles-table td { padding: 1px 6px; font-size: 10px; line-height: 1.15; }
.rnp-articles-table .thumb { width: 22px; height: 22px; border-radius: 3px; }
.rnp-articles-table .muted { font-size: 9px; }
.rnp-articles-table .pnl-delta { font-size: 9px; }
.rnp-articles-table .badge { font-size: 9px; padding: 0 4px; margin-left: 3px; line-height: 1.4; }
.rnp-articles-table .pnl-cell { gap: 4px; }
.rnp-articles-table .rnp-name {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
/* Заголовки метрик переносятся на 2-3 строки вместо растягивания колонки по
   самому длинному названию — значения (td) остаются в одну строку (nowrap
   унаследован от правила выше, тут не трогаем). */
.rnp-articles-table thead th:not(.rnp-sticky-1):not(.rnp-sticky-2) {
    white-space: normal;
    max-width: 62px;
    vertical-align: bottom;
}

.thumb { width: 56px; height: 56px; border-radius: 6px; object-fit: cover; display: block; }
.thumb-empty { background: var(--color-border); }

.empty-state {
    background: var(--color-surface);
    border: 1px dashed var(--color-border);
    border-radius: var(--radius);
    padding: 40px 20px;
    text-align: center;
}

.stub-box { text-align: center; padding: 80px 20px; }
.stub-icon { font-size: 40px; }

/* ---- Себестоимость: фильтры ---- */
.costs-filter-form {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 12px 16px;
}
.costs-search { min-width: 240px; flex: 1 1 240px; }
.filter-tabs { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; }
.filter-tabs label { display: flex; align-items: center; gap: 5px; cursor: pointer; white-space: nowrap; }

/* ---- Себестоимость: строка товара ---- */
.row-no-cost { box-shadow: inset 4px 0 0 0 var(--color-warn); }

.cost-cell { min-width: 160px; }
.cost-display { cursor: pointer; }
.cost-value { font-weight: 600; }

.cost-edit-form {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.cost-input { width: 100px; }
.cost-date { width: 140px; }
.btn-cancel { background: transparent; border-color: transparent; color: var(--color-muted); }
.btn-cancel:hover { color: var(--color-error); }

.chevron-btn {
    background: none;
    border: none;
    font-size: 14px;
    color: var(--color-muted);
    cursor: pointer;
    padding: 4px 8px;
    transition: transform 0.15s ease;
}
.chevron-btn.chevron-open { transform: rotate(180deg); color: var(--color-text); }

.history-row td { background: var(--color-bg); padding: 12px; }
.history-table { width: 100%; border-collapse: collapse; }
.history-table th, .history-table td {
    text-align: left;
    padding: 6px 10px;
    font-size: 13px;
    border-bottom: 1px solid var(--color-border);
}
.history-table tr:last-child td { border-bottom: none; }
.history-current td { font-weight: 600; }
.badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    color: var(--color-ok);
    background: var(--color-ok-bg);
    border-radius: 4px;
    padding: 2px 6px;
    margin-left: 6px;
}
.badge-warn { color: var(--color-warn); background: var(--color-warn-bg); }

/* ---- ОПиУ: дельта к соседнему месяцу ---- */
.pnl-delta-good { color: var(--color-ok); }
.pnl-delta-bad { color: var(--color-error); }

/* ---- Модалка импорта ---- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 40;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 60px 16px;
    overflow-y: auto;
}
.modal {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 640px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.modal-header h2 { margin: 0; font-size: 16px; }
.modal-header .link-button { width: auto; font-size: 18px; padding: 0 4px; }
.modal input[type="file"] { margin: 12px 0; display: block; }
.import-preview { margin-top: 16px; }
.import-summary p { margin: 4px 0; font-size: 13px; }
.import-summary ul { margin: 6px 0 0; padding-left: 20px; font-size: 13px; }

/* ---- Toasts ---- */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    background: var(--color-text);
    color: #fff;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 13px;
    max-width: 320px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

/* ---- Склад ---- */
.wh-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.wh-card {
    display: flex;
    gap: 12px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 12px;
    cursor: pointer;
    text-align: left;
}
.wh-card:hover { border-color: var(--color-accent); }
.wh-card-thumb { width: 64px; height: 64px; flex: none; }
.wh-card-body { min-width: 0; flex: 1; }
.wh-card-body-full { width: 100%; }
.wh-card-title {
    font-weight: 600;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.wh-card-sub { font-size: 12px; margin-top: 2px; }
.wh-card-metrics {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
    font-size: 12px;
    color: var(--color-muted);
    margin-top: 8px;
}
.wh-card-metrics b { color: var(--color-text); }
.wh-warn {
    font-size: 12px;
    color: var(--color-warn);
    background: var(--color-warn-bg);
    border-radius: 4px;
    padding: 3px 6px;
    margin-top: 6px;
    display: inline-block;
}

.wh-collapse {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    padding: 4px 12px 12px;
}
.wh-collapse summary {
    cursor: pointer;
    padding: 10px 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-muted);
}
.wh-collapse[open] summary { color: var(--color-text); }
.wh-collapse .wh-grid { margin-top: 8px; margin-bottom: 0; }

.modal-wide { max-width: 760px; }
.modal-backdrop[data-js-modal] { display: none; }
.modal-backdrop[data-js-modal].is-open { display: flex; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---- Настройка строк (РНП: Сводная) — переключатель ---- */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track {
    position: absolute;
    inset: 0;
    background: var(--color-border);
    border-radius: 999px;
    transition: background 0.15s ease;
    pointer-events: none;
}
.switch-track::before {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    left: 2px;
    top: 2px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.15s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
.switch input:checked + .switch-track { background: var(--color-accent); }
.switch input:checked + .switch-track::before { transform: translateX(18px); }

.rnp-rows-list { list-style: none; margin: 12px 0 0; padding: 0; max-height: 60vh; overflow-y: auto; }
.rnp-rows-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 4px;
    border-bottom: 1px solid var(--color-border);
}
.rnp-rows-item:last-child { border-bottom: none; }
.rnp-rows-item.is-dragging { opacity: 0.4; }
.rnp-rows-handle { cursor: grab; color: var(--color-muted); font-size: 16px; user-select: none; }
.rnp-rows-label { flex: 1; font-size: 14px; }

.wh-modal-header-info { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.wh-modal-thumb { width: 64px; height: 64px; flex: none; }
.wh-modal-tiles { grid-template-columns: repeat(3, 1fr); margin-bottom: 20px; }

.wh-table-scroll { overflow-x: auto; margin-bottom: 12px; }
.wh-bom-table { min-width: 480px; }
.wh-row-limiting { box-shadow: inset 4px 0 0 0 var(--color-warn); background: var(--color-warn-bg); }
.wh-row-limiting td { font-weight: 600; }

.badge-muted { background: var(--color-bg); color: var(--color-muted); }

.wh-link-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}
.wh-link-form select { flex: 1 1 200px; }
.wh-link-form input[type="number"] { width: 70px; }

.wh-used-by { font-size: 13px; padding-left: 18px; margin: 0 0 20px; }
.wh-used-by li { margin-bottom: 4px; }

.wh-batch {
    border: 1px solid var(--color-border);
    border-radius: 6px;
    margin-bottom: 8px;
    overflow: hidden;
}
.wh-batch-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 4px 8px;
}
.wh-batch-spent { opacity: 0.55; }
.wh-batch-main {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 12px;
    background: none;
    border: none;
    font-family: inherit;
    font-size: 13px;
    padding: 8px 0;
    cursor: pointer;
    text-align: left;
    flex: 1;
}
.wh-batch-actions { display: flex; gap: 4px; flex: none; }
.wh-batch-edit-form {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 8px 10px;
}
.wh-batch-edit-form input[type="number"] { width: 70px; }
.wh-batch-edit-form input[type="text"] { width: 110px; }
.wh-batch-edit-form input[type="date"] { width: 130px; }
.wh-batch-detail { background: var(--color-bg); padding: 10px; }

.wh-kind-toggle { display: flex; gap: 16px; font-size: 14px; color: var(--color-text); }
.wh-kind-toggle label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.wh-cost-pair { display: flex; gap: 10px; }
.wh-cost-pair label { flex: 1; }
.wh-parts { display: flex; flex-direction: column; gap: 6px; }
.wh-part-row { display: flex; gap: 6px; align-items: center; }
.wh-part-row input[type="text"]:first-child { flex: 1; }
.wh-part-row input[type="text"]:nth-child(2) { width: 90px; }
.wh-part-row input[type="date"] { width: 130px; }
.wh-move-form { max-width: none; }
.wh-delete-form { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--color-border); }

/* ---- Аналитика РК ---- */
.an-ads-header { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.an-ads-title { font-weight: 600; }

/* ---- Аналитика ---- */
.an-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px 20px;
    margin-bottom: 16px;
}
.an-period-tabs { margin-bottom: 0; border-bottom: none; }
.an-metric-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.an-metric-btn {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 13px;
    font-family: inherit;
    color: var(--color-muted);
    cursor: pointer;
}
.an-metric-btn:hover { color: var(--color-text); }
.an-metric-btn.is-active { background: var(--color-accent); border-color: var(--color-accent); color: #fff; }

.an-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 12px;
}
.an-summary-label { font-size: 12px; color: var(--color-muted); margin-bottom: 4px; }
.an-summary-value { font-size: 28px; font-weight: 700; }
.an-summary-chart { flex: none; }

.an-fixed-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.an-fixed-item {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 10px 14px;
}
.an-fixed-label { font-size: 12px; color: var(--color-muted); }
.an-fixed-value { font-size: 16px; font-weight: 600; }

.an-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}
.an-tile {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex: 1 1 420px;
    min-width: 340px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 14px 16px;
    cursor: pointer;
}
.an-tile:hover { border-color: var(--color-accent); }
.an-tile-no_data { box-shadow: inset 4px 0 0 0 var(--color-warn); }
.an-tile-trap { box-shadow: inset 4px 0 0 0 var(--color-error); }
.an-tile-ok { box-shadow: inset 4px 0 0 0 var(--color-ok); }
.an-tile-main { display: flex; gap: 12px; min-width: 0; }
.an-tile-thumb { width: 48px; height: 48px; flex: none; }
.an-tile-body { min-width: 0; }
.an-tile-title {
    font-weight: 600;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
}
.an-tile-sub { font-size: 12px; margin: 1px 0 6px; }
.an-tile-value { font-size: 20px; font-weight: 700; }
.an-tile-context { font-size: 12px; color: var(--color-muted); margin-top: 4px; }
.an-tile-warn { color: var(--color-error); font-weight: 600; }
.an-tile-cta { font-size: 12px; }
.an-tile-chart { flex: none; }

.an-chart { position: relative; width: 320px; max-width: 100%; }
.an-chart-svg { display: block; width: 100%; }
.an-baseline { stroke: var(--color-border); stroke-width: 1; }
.an-bar { fill: var(--color-accent); }
.an-bar-neg { fill: var(--color-error); }
.an-bar-zero { fill: var(--color-border); }
.an-hit { fill: transparent; cursor: crosshair; }
.an-tooltip {
    position: absolute;
    top: -4px;
    left: 50%;
    transform: translate(-50%, -100%);
    background: var(--color-text);
    color: #fff;
    font-size: 11px;
    white-space: nowrap;
    padding: 4px 8px;
    border-radius: 6px;
    pointer-events: none;
    z-index: 5;
}

.an-modal-header-info { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.an-modal-thumb { width: 56px; height: 56px; flex: none; }
.an-detail-row { margin-bottom: 16px; }
.an-detail-label { font-size: 13px; color: var(--color-muted); margin-bottom: 4px; }
.an-detail-value { font-size: 16px; font-weight: 700; color: var(--color-text); margin-left: 8px; }

/* ---- Настройки: налоговые ставки ---- */
.tax-shop-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 16px;
    margin-bottom: 14px;
}
.tax-shop-header h3 { margin: 0; font-size: 15px; }
.tax-regime { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--color-muted); }
.tax-regime-edit { width: auto; color: var(--color-accent); }
.tax-regime-form { display: flex; align-items: center; gap: 8px; }
.tax-regime-form input[type="text"] { width: 220px; }

.tax-quarters {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}
.tax-quarter {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 10px;
}

/* ---- Пикер периода (диапазон дат) ---- */
.drp { position: relative; display: inline-block; }
.drp-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
}
.drp-trigger:hover { border-color: var(--color-accent); }
.drp-trigger-icon { color: var(--color-muted); }

.drp-panel {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 30;
    display: flex;
    align-items: flex-start;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
    padding: 14px;
    gap: 18px;
}

.drp-presets {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px 6px;
    padding-right: 14px;
    border-right: 1px solid var(--color-border);
    width: 200px;
    flex: none;
    align-content: start;
}
.drp-preset {
    text-align: center;
    padding: 6px 4px;
    border: none;
    border-radius: 12px;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: inherit;
    font-size: 12px;
    line-height: 1.2;
    cursor: pointer;
    white-space: normal;
}
.drp-preset:hover { background: var(--color-border); }

.drp-calendars { display: flex; gap: 20px; }
.drp-calendar { width: 224px; flex: none; }
.drp-cal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.drp-cal-title {
    font-size: 14px;
    font-weight: 600;
}
.drp-nav {
    background: none;
    border: none;
    font-size: 16px;
    color: var(--color-muted);
    cursor: pointer;
    padding: 2px 8px;
    line-height: 1;
}
.drp-nav:hover { color: var(--color-text); }
.drp-nav-spacer { width: 26px; }

/* ---- План/факт (templates/planning_*.html) ---- */

.planning-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
.planning-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.planning-card-actions { display: flex; gap: 4px; flex: none; }

.planning-settings-form {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
    margin-bottom: 16px;
}
.planning-settings-form label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--color-muted);
}

.planning-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}

.planning-picker-list {
    max-height: 360px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.planning-picker-row {
    display: flex !important;
    gap: 10px;
    padding: 6px 4px;
    border-bottom: 1px solid var(--color-border);
}

.planning-grid-scroll, .planning-detail-scroll {
    overflow-x: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
}
.planning-grid, .planning-detail-table { width: 100%; border-collapse: collapse; white-space: nowrap; }
.planning-target-input {
    width: 100px;
    padding: 6px 8px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-bg);
}
.planning-total-row td { background: var(--color-bg); font-weight: 600; }
.planning-val-neg { color: var(--color-error); }

.planning-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}
.planning-tile {
    display: block;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 14px 16px;
    color: var(--color-text);
}
.planning-tile:hover { border-color: var(--color-accent); text-decoration: none; }
.planning-tile.is-active { border-color: var(--color-accent); box-shadow: 0 0 0 1px var(--color-accent); }
.planning-tile-label { font-size: 12px; color: var(--color-muted); margin-bottom: 8px; }
.planning-tile-row { display: flex; align-items: center; gap: 10px; }
.planning-tile-fact { font-weight: 700; font-size: 14px; flex: none; }
.planning-tile-target { font-size: 12px; color: var(--color-muted); flex: none; }

.planning-progress-bar {
    position: relative;
    flex: 1;
    height: 20px;
    border-radius: 10px;
    background: var(--color-bg);
    overflow: hidden;
}
.planning-progress-fill { height: 100%; border-radius: 10px; }
.planning-progress-pct {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--color-text);
}
.planning-progress-ahead .planning-progress-fill { background: var(--color-ok-bg); border: 1px solid var(--color-ok); }
.planning-progress-behind .planning-progress-fill { background: var(--color-error-bg); border: 1px solid var(--color-error); }
.planning-progress-unknown .planning-progress-fill { background: var(--color-border); }

.drp-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    font-size: 11px;
    color: var(--color-muted);
    text-align: center;
    margin-bottom: 4px;
}
.drp-week { display: grid; grid-template-columns: repeat(7, 1fr); }
.drp-day {
    border: none;
    background: none;
    font-family: inherit;
    font-size: 13px;
    color: var(--color-text);
    padding: 7px 0;
    cursor: pointer;
    border-radius: 999px;
}
.drp-day:hover { background: var(--color-border); }
.drp-day-out { color: var(--color-border); }
.drp-day-in-range { background: var(--color-bg); border-radius: 0; }
.drp-day-selected { background: var(--color-accent); color: #fff; }
.tax-quarter-title { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.tax-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
    align-items: center;
    margin-bottom: 4px;
}
.tax-row-labels { font-size: 11px; color: var(--color-muted); }
.tax-col-label { text-align: left; }
.tax-row-quarter { margin-bottom: 8px; }
.tax-row-quarter .tax-input { font-weight: 600; }
.tax-row-label { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tax-input { width: 100%; padding: 6px 8px; font-size: 13px; }

@media (max-width: 900px) {
    .tax-quarters { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
    .tax-quarters { grid-template-columns: 1fr; }
}

/* ---- Mobile ---- */
@media (max-width: 720px) {
    .topnav-inner { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
    .topnav-tabs { order: 3; width: 100%; }
    .tiles { grid-template-columns: repeat(2, 1fr); }
    .an-fixed-row { grid-template-columns: 1fr; }
    .an-tile { flex-direction: column; align-items: stretch; min-width: 0; }
    .an-summary { flex-direction: column; align-items: stretch; }

    .data-table thead { display: none; }
    .data-table, .data-table tbody, .data-table tr { display: block; }
    .data-table tr {
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius);
        margin-bottom: 10px;
        padding: 10px;
    }
    .data-table td {
        display: block;
        border-bottom: none;
        padding: 6px 4px;
    }
    .data-table td[data-label]::before {
        content: attr(data-label);
        display: block;
        font-size: 11px;
        text-transform: uppercase;
        font-weight: 600;
        color: var(--color-muted);
        margin-bottom: 2px;
    }
    .costs-table tbody { margin-bottom: 10px; }
    .costs-table .history-row td { background: transparent; padding: 6px 4px 0; }
}
