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

:root {
    --bg: #f3f4f7;
    --surface: #ffffff;
    --border: #e1e3ea;
    --text: #1f2430;
    --muted: #6a7280;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --danger: #dc2626;
    --success: #16a34a;
    --radius: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* Login */
/* Страница без topbar (layout main.pattern.php): центрирует содержимое. */
.page-fill {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.login-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
    width: 100%;
    max-width: 400px;
}

.login-form h1 {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.login-form .subtitle {
    color: var(--muted);
    margin-bottom: 24px;
    font-size: 0.9rem;
}

/* Forms */
label {
    display: block;
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 4px;
    margin-top: 16px;
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.15s;
}

input:focus {
    border-color: var(--accent);
}

button {
    display: inline-block;
    width: 100%;
    margin-top: 24px;
    padding: 10px 20px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.15s;
}

button:hover {
    background: var(--accent-hover);
}

.login-form button {
    margin-top: 8px;
}

.login-form .remember {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 16px;
    font-size: 0.85rem;
    color: var(--muted);
    cursor: pointer;
}

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

/* Alerts */
.alert:empty {
    display: none;
}

.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.alert-error {
    background: rgba(239, 68, 68, 0.12);
    color: #b91c1c;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.alert-success {
    background: rgba(34, 197, 94, 0.12);
    color: #15803d;
    border: 1px solid rgba(34, 197, 94, 0.3);
}

.alert-warning {
    background: rgba(245, 158, 11, 0.12);
    color: #b45309;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

/* Topbar */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: nowrap;
    min-height: 52px;
    padding: 8px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-sizing: border-box;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1 1 auto;
    min-width: 0;
}

.brand {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    font-weight: 600;
    font-size: 1.05rem;
    line-height: 1.2;
    white-space: nowrap;
}

.brand-link {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
}

.nav-links {
    display: none;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    position: absolute;
    right: 24px;
    top: 56px;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    min-width: 180px;
}

.nav-links.open {
    display: flex;
}

.nav-links a {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.9rem;
    line-height: 1.4;
    padding: 5px 10px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    transition: color 0.15s;
}

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

.nav-links a.active {
    color: var(--accent-hover);
    font-weight: 600;
    border: 1px solid var(--border);
    background: var(--bg);
}

.nav-shop-links {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    border-left: 2px solid var(--border);
    margin-left: 10px;
    padding-left: 10px;
}

.nav-shop-links a {
    font-size: 0.85rem;
}

.shop-sub-block {
    margin-top: 24px;
}

.shop-sub-block h3 {
    margin-bottom: 12px;
}

.own-wh-blocked {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0;
}

.blocked-name {
    text-decoration: line-through;
    opacity: 0.6;
}

.cluster-short-cell {
    color: var(--muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85rem;
    white-space: nowrap;
}

.user {
    color: var(--muted);
    font-size: 0.85rem;
}

.btn-logout {
    color: var(--danger) !important;
}

/* Container */
.container {
    max-width: 800px;
    margin: 32px auto;
    padding: 0 24px;
}

.container h2 {
    margin-bottom: 24px;
    font-size: 1.3rem;
}

/* Card placeholder */
.card-placeholder {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    color: var(--muted);
}

/* Settings form */
.settings-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}

.settings-form h3 {
    margin-bottom: 8px;
    font-size: 1.1rem;
}

.settings-form button {
    max-width: 200px;
}

/* Параметры магазина: компактные поля в одну строку */
.settings-form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
    margin-bottom: 8px;
}
.settings-form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 180px;
}
.settings-form-field input {
    width: auto;
    min-width: 200px;
}
.settings-form-field p {
    margin: 0;
    padding-bottom: 10px;
}

/* Shop list */
.shop-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.shop-list .shop-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    gap: 16px;
}

.shop-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.shop-name {
    font-weight: 600;
    font-size: 1rem;
}

.shop-client {
    color: var(--muted);
    font-size: 0.8rem;
}

.badge {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 10px;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 999px;
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent-hover);
    border: 1px solid rgba(99, 102, 241, 0.3);
    vertical-align: middle;
}

.inline-form {
    margin: 0;
    flex-shrink: 0;
}

.inline-form button {
    width: auto;
    margin: 0;
    padding: 8px 16px;
}

.btn-delete {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.btn-delete:hover {
    background: rgba(239, 68, 68, 0.15);
}

.link {
    color: var(--accent-hover);
    text-decoration: none;
}

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

.sku-filter {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin: 10px 0 0;
    padding: 8px 14px;
    background: var(--bg, #f8fafc);
    border: 1px solid var(--border, #cbd5e1);
    border-radius: 8px;
    font-size: 0.92rem;
}
.sku-filter .mono {
    font-weight: 600;
}

/* Панель действий журнала: «+ Добавить запись» и «Пересчитать остатки» (при SKU-фильтре) */
.own-wh-crud .crud-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 10px 0 16px;
}
.own-wh-crud .crud-toolbar .btn-add-shop,
.own-wh-crud .crud-toolbar form.sku-recalc {
    margin: 0;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 24px;
    flex-shrink: 0;
    white-space: nowrap;
    position: relative;
}

/* Кнопка-гамбургер правого меню: видна только на узких экранах */
.menu-toggle {
    display: flex;
    width: 34px;
    height: 34px;
    margin: 0;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: none;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

.menu-toggle .tb-icon {
    width: 16px;
    height: 16px;
    position: relative;
    background: none;
}

.menu-toggle .tb-icon::before,
.menu-toggle .tb-icon::after {
    content: "";
    position: absolute;
    left: 0;
    width: 16px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    top: 4px;
}

.menu-toggle .tb-icon::after {
    top: 10px;
}

.shop-menu {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}

.shop-menu::-webkit-scrollbar {
    display: none;
}

.topbar .shop-item {
    flex-wrap: nowrap;
    flex-shrink: 0;
}

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

.shop-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: none;
    border: none;
    color: var(--text);
    font-size: 0.9rem;
    border-radius: var(--radius);
    text-decoration: none;
}

.shop-link:hover {
    background: var(--bg);
}

/* Выбранный магазин — жирный текст */
.shop-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text);
    padding: 5px 10px;
    white-space: nowrap;
}

.shop-submenu {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    white-space: nowrap;
    gap: 2px;
    padding: 2px;
}

.shop-submenu a {
    display: inline-block;
    padding: 6px 10px;
    color: var(--muted);
    text-decoration: none;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 0.9rem;
    white-space: nowrap;
    line-height: 1.4;
}

.shop-submenu a:hover {
    color: var(--accent-hover);
    background: var(--bg);
}

.shop-submenu a.active {
    color: var(--accent-hover);
    font-weight: 600;
    border: 1px solid var(--border);
    background: var(--bg);
}

.shop-trigger.empty {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.9rem;
}

/* Дропдаун выбора магазина вместо логотипа */
.shop-select {
    position: relative;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
}

.shop-select-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 12px;
    margin: 0;
    width: auto;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    white-space: nowrap;
}

.shop-select-btn:hover {
    border-color: var(--accent);
}

.shop-select-caret {
    flex: 0 0 auto;
    opacity: 0.6;
    transition: transform 0.15s;
}

.shop-select-btn[aria-expanded="true"] .shop-select-caret {
    transform: rotate(180deg);
}

.shop-select-menu {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 200px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    z-index: 200;
}

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

.shop-select-item {
    display: block;
    padding: 8px 12px;
    color: var(--text);
    text-decoration: none;
    border-radius: var(--radius);
    white-space: nowrap;
    font-size: 0.9rem;
}

.shop-select-item:hover {
    background: var(--bg);
}

.shop-select-item.active {
    color: var(--accent-hover);
    font-weight: 600;
    background: var(--bg);
}

/* Подменю активного магазина: занимает остаток строки, при нехватке места скроллится внутри */
.topbar-submenu {
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}

.topbar-submenu::-webkit-scrollbar {
    display: none;
}

.topbar-submenu a {
    height: 36px;
    padding: 0 10px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
}

/* Магазины в строчку (десктоп): имя магазина + его подменю рядом.
   На мобильных блок скрыт — там работает дропдаун .shop-select. */
.shops-inline {
    display: none;
    align-items: center;
    gap: 20px;
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}

.shops-inline::-webkit-scrollbar {
    display: none;
}

.shop-group {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.shop-name-inline {
    display: inline-flex;
    align-items: center;
    height: 36px;
    padding: 0 10px;
    color: var(--text);
    font-weight: 700;
    font-size: 0.95rem;
    white-space: nowrap;
    text-decoration: none;
    border: 1px solid transparent;
    border-radius: var(--radius);
}

.shop-name-inline:hover {
    background: var(--bg);
}

.shop-name-inline.active {
    color: var(--accent-hover);
}

/* Десктоп (≥801px — порог из основного @media (max-width: 800px)):
   магазины в строчку; дропдаун и «плавающее» подменю скрыты */
@media (min-width: 801px) {
    .shops-inline {
        display: flex;
    }

    .shop-select,
    .topbar-submenu {
        display: none;
    }
}

/* Page head */
.page-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
}

.page-head h2 {
    margin-bottom: 0;
}

.page-count {
    color: var(--muted);
    font-size: 0.9rem;
}

/* Container wide */
.container.wide {
    max-width: 1100px;
}

/* Container full — во всю ширину экрана */
.container.full {
    max-width: 100%;
    padding-left: 24px;
    padding-right: 24px;
}

/* Data table */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.data-table th,
.data-table td {
    text-align: left;
    padding: 10px 14px;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
}

.data-table .avg-col {
    border-right: 2px solid var(--border);
}

/* Вертикальная линия между групповыми шапками (Цена|Ozon). */
.data-table thead th.th-sep {
    border-left: 2px solid var(--border);
}

.data-table thead th {
    color: var(--muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--bg);
}

/* Групповые шапки верхней строки (Цена/Ozon) — по центру над своими колонками. */
.data-table thead th.th-center {
    text-align: center;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover {
    background: var(--bg);
}

.data-table .num {
    text-align: right;
    white-space: nowrap;
}

.data-table .muted {
    color: var(--muted);
}

/* Группа строк с новой датой: утолщённая граница сверху */
.data-table tr.date-break td {
    border-top: 2px solid var(--border);
}

.data-table .mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.8rem;
}

.data-table .sub {
    color: var(--muted);
    font-size: 0.75rem;
}

/* Сводная таблица остатков по кластерам */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.table-wrap .data-table {
    border: none;
    margin: 0;
}

.stock-pivot th.rot {
    writing-mode: horizontal-tb;
    text-align: center;
    white-space: nowrap;
    padding: 10px 14px;
    max-height: none;
    min-width: 60px;
}

.stock-pivot th.num {
    text-align: center;
}

/* Вторая строка в заголовке кластера: стоимость в кластере / ежемесячная доставка, тыс ₽ */
.stock-pivot th .th-stats {
    display: block;
    margin-top: 2px;
    font-size: 0.72em;
    font-weight: 500;
    color: var(--muted);
    white-space: nowrap;
}

.stock-pivot td {
    text-align: center;
    white-space: nowrap;
}

.stock-pivot td.num {
    text-align: center;
}

.stock-pivot td.mono {
    text-align: left;
}

.stock-pivot .strong {
    font-weight: 700;
}

/* Простая дробь: числитель над знаменателем с чертой */
.fraction {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    line-height: 1.15;
    font-size: 0.68em;
}
.fraction .fr-num,
.fraction .fr-den {
    display: block;
    padding: 0 3px;
}
.fraction .fr-num {
    border-bottom: 1px solid currentColor;
}

/* Товары в пути: «+ N» в ячейке остатков */
.in-transit {
    color: var(--muted);
    font-weight: 700;
    font-size: 0.9em;
}

/* Подсветка достаточности остатка в ячейке */
.stock-pivot .cell-ok {
    background: #dcf0e1;
}

/* Ярко-зелёный: остатка хватает более чем на 6 месяцев */
.stock-pivot .cell-ok-bright {
    background: #6fe08a;
}

/* Красный: остатка хватает менее чем на месяц (0.5–1 мес) */
.stock-pivot .cell-out {
    background: #fbdfdd;
}

/* Тёмно-красный: остатка хватает менее чем на полмесяца */
.stock-pivot .cell-out-dark {
    background: #efb3ae;
}

.stock-pivot .cell-low {
    background: #fbf0d2;
}

/* Серый: склад (кластер) заблокирован */
.stock-pivot .cell-blocked {
    background: #ececec;
}

/* Колонка избранного (звёздочка) */
.stock-pivot .fav-col {
    width: 46px;
    text-align: center;
    vertical-align: middle;
    padding: 4px 2px;
    white-space: nowrap;
}

.star {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 0;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.7rem;
    line-height: 1;
    color: #a9aeb8;
    padding: 0 4px;
    transition: color 0.15s ease, transform 0.1s ease;
}

.star:hover {
    background: none;
    color: #d4a017;
    transform: scale(1.15);
}

.star.on,
.star.active {
    color: #d4a017;
}

/* Звёздочка-переключатель в заголовке колонки «избранные» */
.fav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #d4a017;
    text-decoration: none;
    font-size: 16px;
    cursor: pointer;
}
.fav-toggle:hover {
    transform: scale(1.15);
    opacity: 0.8;
}

/* Пометка простоя по последней продаже (артикул в остатках) */
.sku-cell {
    display: table-cell;
    white-space: nowrap;
}
.sku-inner {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.sku-cell a {
    text-decoration: none;
    border-bottom: 1px dashed var(--border, #cbd5e1);
    color: var(--text, #0f172a);
}
.sku-cell a:hover {
    color: var(--accent, #2563eb);
    border-bottom-color: currentColor;
}
.stale {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.4;
    vertical-align: middle;
    white-space: nowrap;
    cursor: help;
}
.stale-none {
    background: rgba(148, 163, 184, 0.18);
    color: #64748b;
    border: 1px solid rgba(148, 163, 184, 0.5);
}
.stale-1m {
    background: rgba(255, 213, 79, 0.18);
    color: #997f16;
    border: 1px solid rgba(217, 175, 34, 0.55);
}
.stale-3m {
    background: rgba(248, 113, 113, 0.16);
    color: #c0392b;
    border: 1px solid rgba(220, 38, 38, 0.45);
}

.tag {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.25);
    color: var(--text);
    border-radius: 5px;
    font-size: 0.75rem;
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 24px;
    flex-wrap: wrap;
}

.page-link,
.page-current,
.page-ellipsis {
    min-width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    text-decoration: none;
}

.page-link {
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
}

.page-link:hover {
    border-color: var(--accent);
    color: var(--accent-hover);
}

.page-current {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

.page-ellipsis {
    color: var(--muted);
}

.shop-actions {
    display: flex;
    gap: 12px;
    flex-shrink: 0;
}

/* Filter bar */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.filter-bar label {
    margin: 0;
    font-size: 0.85rem;
    color: var(--muted);
}

.filter-bar select {
    width: 320px;
    max-width: 100%;
}

/* Order statuses */
.status {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.status-delivered {
    background: rgba(34, 197, 94, 0.14);
    color: #15803d;
    border: 1px solid rgba(34, 197, 94, 0.4);
}

.status-delivering {
    background: rgba(234, 179, 8, 0.15);
    color: #a16207;
    border: 1px solid rgba(234, 179, 8, 0.4);
}

.status-cancelled {
    background: rgba(239, 68, 68, 0.13);
    color: #b91c1c;
    border: 1px solid rgba(239, 68, 68, 0.4);
}

.status-pending {
    background: rgba(113, 113, 122, 0.13);
    color: #52525b;
    border: 1px solid rgba(113, 113, 122, 0.4);
}

.status-awaiting {
    background: rgba(113, 113, 122, 0.20);
    color: #374151;
    border: 1px solid rgba(113, 113, 122, 0.5);
}

.status-unknown {
    background: rgba(113, 113, 122, 0.13);
    color: #52525b;
    border: 1px solid rgba(113, 113, 122, 0.4);
}

/* График «сумма заказов по дням» */
.chart-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 24px;
    overflow-x: auto;
}

.chart-title {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.chart-legend {
    display: flex;
    gap: 16px;
    margin-bottom: 10px;
    font-size: 0.75rem;
    color: var(--muted);
}

.chart-legend .dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    margin-right: 5px;
    vertical-align: middle;
}

/* Свотч средней линии (линия, а не точка) в легенде */
.chart-legend .ln {
    display: inline-block;
    width: 16px;
    height: 3px;
    border-radius: 2px;
    margin-right: 5px;
    vertical-align: middle;
}

.chart {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 170px;
    width: 100%;
    min-width: 0;
    padding-right: 45px;
}

/* Сетка и подписи оси Y — поверх баров: столбцы .chart-col на z-index 1,
   иначе на узком экране последние бары перекрывают подписи.
   Сетка лежит ровно на зоне баров (0..160px): .chart 170px = 160px графика
   + 10px полоса подписей дней (см. .chart-day ниже). Иначе ноль-линия
   и линии сетки смещаются вниз относительно основания баров. */
.chart-grid {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 10px;
    z-index: 2;
    pointer-events: none;
}

.chart-gridline {
    position: absolute;
    left: 0;
    right: 0;
    border-top: 1px dashed var(--border);
    height: 0;
}

/* Средняя линия (напр. по неделям) поверх баров: та же зона, что и бары
   (правый отступ = padding-right .chart под подписи оси Y, нижний — полоса
   подписей дней, иначе крайние точки съедут относительно бара/низа).
   Штрих не искажается растяжением viewBox (non-scaling-stroke). */
.chart-line {
    position: absolute;
    left: 0;
    top: 0;
    width: calc(100% - 45px);
    height: calc(100% - 10px);
    z-index: 2;
    pointer-events: none;
    overflow: visible;
}

/* Нулевая линия шкалы (при отрицательных значениях, напр. минус на «Деньгах») */
.chart-gridline.zero {
    border-top-style: solid;
    border-color: var(--muted);
}

.chart-gridlabel {
    position: absolute;
    right: 0;
    top: -8px;
    font-size: 0.6rem;
    color: var(--muted);
    background: var(--surface);
    padding: 0 3px;
    white-space: nowrap;
}

.chart-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1 1 0;
    min-width: 0;
    z-index: 1;
    position: relative;
}

/* Граница недели: вертикальная серая линия перед понедельником */
.chart-col.mon::before {
    content: '';
    position: absolute;
    left: -1px;
    top: 0;
    height: 160px;
    width: 0;
    border-left: 1px solid var(--border);
    z-index: -1;
}

.chart-bars {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    height: 160px;
    width: 100%;
    max-width: 14px;
}

.seg {
    width: 100%;
}

.seg-delivered {
    background: #7ee08a;
}

.seg-delivering {
    background: #f7d154;
}

.seg-grey {
    background: #9ca3af;
}

.seg-cancelled {
    background: #f0888d;
}

.seg-neg {
    background: #dc2626;
}

.chart-day {
    text-align: center;
    font-size: 0.62rem;
    color: var(--muted);
    /* Фиксированная полоса 10px внизу .chart (170px = 160px графика + 10px
       подписей): дневная подпись не должна выталкивать .chart-bars вверх,
       иначе сетка (0..160px) и бары расходятся по вертикали. */
    height: 10px;
    line-height: 10px;
    overflow: hidden;
    white-space: nowrap;
}

/* Плотный график (длинная ось, напр. заказы по дням за 6 месяцев):
   на широком экране — базовый отступ между столбцами (2px);
   на узком (≤800px) — бары вплотную и до 2px, без прокрутки
   (см. media max-width 800px ниже). */

/* На широком экране на оси Y показываем полное число, а не сокращённое */
.chart-gridlabel .gl-short {
    display: none;
}

/* Заказы: на широком экране — полный номер, на узком — dd-dddd */
.ord-num .orth-short,
.ord-num-h .orth-short,
.ord-status-h .orh-short {
    display: none;
}
.ord-num {
    white-space: nowrap;
}

/* Цены: на широком экране — полная сумма, на узком — 123 кР / 123 МР */
.pp .pp-short {
    display: none;
}

/* На узких экранах (до 800px) — сайт без боковых отступов и с компактными
   подписями; правила именно графика (бары, подписи дней, ось Y) —
   в отдельном media (max-width: 800px) ниже. */
@media (max-width: 800px) {
    /* Без отступов по краям экрана */
    .container,
    .container.full,
    .container.wide {
        padding-left: 0;
        padding-right: 0;
        margin-left: 0;
        margin-right: 0;
    }

    /* Скрываем логотип — магазины с подменю идут с начала строки */
    .brand {
        display: none;
    }

    /* Заказы: на узком экране — короткие подписи и номера */
    .ord-num .orth-full,
    .ord-num-h .orth-full,
    .ord-status-h .orh-full {
        display: none;
    }
    .ord-num .orth-short,
    .ord-num-h .orth-short {
        display: inline;
    }

    /* Цены: на узком экране — сокращённые тыс./млн, по наведению полное число */
    .pp .pp-full {
        display: none;
    }
    .pp .pp-short {
        display: inline;
    }

    .d-year {
        display: none;
    }

    /* Заказы: слово «В месяц» на узком экране скрыто (числа остаются) */
    .month-label {
        display: none;
    }

    /* Заказы: статус схлопывается до цветного кружочка */
    .ord-status .status {
        display: inline-block;
        width: 12px;
        height: 12px;
        padding: 0;
        font-size: 0;
        border-radius: 50%;
        text-indent: -9999px;
        overflow: hidden;
        white-space: nowrap;
        vertical-align: middle;
    }
}

/* Узкий экран (≤800px) для графика: бары вплотную (без прокрутки, минимум 2px),
   подписи дней прорежены, месяц в подписи не показываем, ось Y — коротко. */
@media (max-width: 800px) {
    .chart-day-month {
        display: none;
    }

    /* Плотный график: без отступов между барами, столбцы до 2px,
       подписи дней — каждый второй подписанный день */
    .chart.dense {
        gap: 0;
    }
    .chart.dense .chart-col {
        min-width: 2px;
    }
    .chart.dense .chart-col.lb-e .chart-day {
        visibility: hidden;
    }

    /* Ось Y: сокращённое число (тысячи), вплотную к краю */
    .chart-gridlabel .gl-full {
        display: none;
    }
    .chart-gridlabel .gl-short {
        display: inline;
    }
    .chart {
        padding-right: 20px;
    }
    .chart-line {
        width: calc(100% - 20px);
    }
}

/* ===== Мои склады (own-warehouses.php) ===== */
.own-wh-block {
    margin: 10px 0;
    padding: 10px 12px;
    border: 1px solid var(--border, #e0e0e0);
    border-radius: 8px;
    background: var(--bg-soft, #fafafa);
}

.own-wh-block h4 {
    margin: 0 0 8px;
    font-size: 14px;
}

.own-wh-block .data-table {
    width: auto;
    margin-bottom: 8px;
}

/* ===== Закупки (own-purchases.php) ===== */
.nowrap {
    white-space: nowrap;
}

.odoc-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px 16px;
    margin-bottom: 16px;
}

.odoc-fields label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.85rem;
    color: var(--muted);
}

.odoc-fields input,
.odoc-fields select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    color: var(--text);
    background: var(--surface);
}

.odoc-add-item {
    display: flex;
    flex-wrap: nowrap;
    align-items: flex-end;
    gap: 10px;
    margin: 0 0 14px;
}

.odoc-add-item label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.85rem;
    color: var(--muted);
}

.odoc-add-item .odoc-add-btn-lbl .odoc-ghost {
    color: transparent;
    line-height: 1.22;
}

.odoc-add-item select,
.odoc-add-item input {
    height: 36px;
    box-sizing: border-box;
    padding: 0 10px;
    line-height: normal;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    background: var(--surface);
}

.odoc-add-item button[type="submit"]:hover {
    background: var(--accent-hover);
}

.odoc-add-item .odoc-prod {
    width: 340px;
    max-width: 340px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.odoc-add-item .odoc-qty {
    width: 72px;
}

.odoc-add-item .odoc-price {
    width: 100px;
}

.odoc-add-item button[type="submit"] {
    margin: 0;
    width: auto;
    height: 36px;
    padding: 0 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: #fff;
    flex-shrink: 0;
    box-sizing: border-box;
}

.odoc-search-wrap .odoc-search {
    width: 68px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    background: var(--surface);
}

.odoc-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.odoc-grid .own-wh-block {
    max-width: 900px;
}

.odoc-grid .own-wh-block:last-child {
    max-width: 100%;
}

.odoc-grid .own-wh-block .data-table {
    width: 100%;
}

@media (max-width: 800px) {
    .data-table .col-name {
        display: none;
    }
}

.btn-danger {
    margin: 0 0 0 8px;
    width: auto;
    background: #dc2626;
}

.btn-danger:hover {
    background: #b91c1c;
}

.own-wh-add {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.own-wh-add input[type="text"] {
    flex: 1 1 180px;
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 6px;
}

.own-wh-add button {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    background: #2563eb;
    color: #fff;
    cursor: pointer;
}

.own-wh-kart {
    margin: 16px 0;
    padding: 16px;
    border: 1px solid var(--border, #e0e0e0);
    border-radius: 8px;
}

.own-wh-kart h3,
.own-wh-move h3,
.own-wh-log h3 {
    margin: 0 0 8px;
}

.own-wh-totals {
    margin: 4px 0 0;
    font-size: 14px;
}

.own-wh-move,
.own-wh-log {
    margin: 24px 0;
}

.own-move-head {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 12px;
}

.own-move-head label {
    display: flex;
    flex-direction: column;
    font-size: 13px;
    gap: 4px;
}

.own-move-head input,
.own-move-head select {
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 6px;
}

.own-move-items td input,
.own-move-items td select {
    width: 100%;
    min-width: 120px;
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 6px;
}

.own-move-items td:first-child input,
.own-move-items td:first-child select {
    min-width: 260px;
}

.own-log-item {
    margin: 12px 0;
    border: 1px solid var(--border, #e0e0e0);
    border-radius: 8px;
    padding: 10px 12px;
}

.own-log-head {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: baseline;
    margin-bottom: 6px;
    font-size: 14px;
}

.own-log-type {
    font-weight: 700;
}

.own-log-date,
.own-log-route,
.own-log-comment {
    color: #666;
}

.own-log-comment {
    font-style: italic;
}

.own-log-items {
    width: 100%;
}

.own-log-items td {
    padding: 3px 8px;
}

.form-msg {
    margin: 10px 0;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
}

.form-msg.ok {
    background: #d1fae5;
    color: #065f46;
}

.form-msg.err {
    background: #fee2e2;
    color: #991b1b;
}

.own-wh-inactive td {
    opacity: 0.55;
}

/* ===== Настройки складов (own-wh-settings.php) ===== */
.own-wh-edit-block {
    margin-top: 12px;
    padding: 16px;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 10px;
    background: var(--bg-card, #fff);
}
.own-wh-edit-block h3 {
    margin: 0 0 12px;
    font-size: 1.05rem;
}
.own-wh-crud {
    margin-top: 8px;
}
.own-wh-crud .btn-add-wh {
    margin-bottom: 12px;
}
.own-wh-actions-th,
.own-wh-actions {
    width: 176px;
    text-align: right;
    white-space: nowrap;
}
.own-wh-actions {
    white-space: nowrap;
    vertical-align: middle;
    font-size: 0;
    line-height: 0;
}
.own-wh-actions form {
    display: inline-block;
    margin: 0 0 0 4px;
    vertical-align: middle;
}
.own-wh-actions .icon-btn {
    margin: 0;
    vertical-align: middle;
    flex-shrink: 0;
}
.own-wh-edit-form {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}
.own-wh-edit-form button {
    width: auto;
    margin: 16px 8px 0 0;
    padding: 8px 16px;
}
.own-item-edit-form {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}
.own-item-edit-form label {
    margin: 0;
}
.own-item-edit-form input {
    width: auto;
}
.own-item-edit-form input[type="number"] {
    width: 90px;
}
.own-item-edit-form button {
    margin: 0;
}
.own-wh-add-form button {
    width: auto;
}
.own-wh-add {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 16px;
    padding: 12px;
    border: 1px dashed var(--border, #cbd5e1);
    border-radius: 10px;
}
.own-wh-add input[type="text"] {
    padding: 6px 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 14px;
}
.own-wh-add button {
    padding: 6px 14px;
    border: 1px solid #2563eb;
    border-radius: 6px;
    background: #2563eb;
    color: #fff;
    cursor: pointer;
}
.own-wh-edit {
    display: flex;
    gap: 6px;
    align-items: center;
    margin: 0;
}

.own-wh-edit input[type="text"] {
    padding: 4px 8px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 14px;
    width: 100%;
    box-sizing: border-box;
}

.own-wh-edit .own-wh-name {
    min-width: 180px;
}

.own-wh-edit .own-wh-addr {
    min-width: 220px;
}

.own-wh-edit button {
    padding: 4px 10px;
    border: 1px solid #2563eb;
    border-radius: 6px;
    background: #2563eb;
    color: #fff;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

.own-wh-edit button:hover {
    background: #1d4ed8;
}

/* ===== Настройки: кнопка «+ Добавить», иконки, форма редактирования ===== */
.settings-title {
    margin: 28px 0 0;
    font-size: 1.1rem;
}

.btn-add-shop {
    width: auto;
    margin: 10px 0 16px;
    padding: 6px 14px;
    background: var(--accent, #2563eb);
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1.4;
    transition: background 0.15s;
}

.btn-add-shop:hover {
    background: var(--accent-hover, #1d4ed8);
}

.shop-item {
    flex-wrap: wrap;
}

.shop-edit-form {
    width: 100%;
    margin-top: 12px;
}

.icon-btn {
    width: 32px;
    height: 32px;
    margin: 0;
    padding: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--muted, #6b7280);
    border: 1px solid var(--border, #d1d5db);
    border-radius: 6px;
    cursor: pointer;
    flex-shrink: 0;
    box-sizing: border-box;
}

.icon-btn svg {
    width: 16px;
    height: 16px;
    display: block;
}

.icon-btn:hover {
    color: var(--text, #111827);
    background: var(--bg, #f3f4f6);
}

.icon-btn:disabled {
    opacity: .35;
    cursor: default;
}

.icon-btn:disabled:hover {
    color: var(--muted, #6b7280);
    background: transparent;
}

form.inline-form .icon-btn {
    width: 32px;
    height: 32px;
    padding: 6px;
    margin: 0;
}

.btn-cancel {
    background: transparent;
    color: var(--muted, #6b7280);
    border: 1px solid var(--border, #d1d5db);
}

.btn-cancel:hover {
    background: var(--bg, #f3f4f6);
}

/* API: токен магазина */
.own-wh-api {
    margin: 0 0 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border, #e5e7eb);
}
.own-wh-api > label {
    display: block;
    margin-bottom: 6px;
}
.api-token-val {
    width: 100%;
    max-width: 480px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    background: var(--bg, #f3f4f6);
}
.api-token-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 4px;
}
.btn-revoke {
    background: transparent;
    color: var(--accent, #0a7cff);
    border: 1px solid var(--accent, #0a7cff);
    border-radius: 6px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
}
.btn-revoke:hover {
    background: rgba(10, 124, 255, 0.08);
}

/* ===== Деньги (money) ===== */
/* Журнал финансов: отрицательная сумма (расход) — красным */
.money-neg {
    color: var(--danger);
}
.money-hint {
    font-size: 0.85rem;
    margin: 8px 0 0;
}

/* Статистика по типам в заголовке секции (h3.mrk-title); «Остаток на сегодня»
   — тоже элемент этого списка (первым), поэтому mrk-title-balance не нужен */
.mrk-title .mrk-title-stats {
    color: var(--muted);
    font-weight: 400;
    font-size: 0.85rem;
}

/* Компактная однострочная форма добавления/редактирования */
.money-form-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px 14px;
}
.money-form-row label {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 0.8rem;
    color: var(--muted);
}
.money-form-row input {
    width: 100%;
    padding: 6px 9px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.92rem;
    color: var(--text);
    background: var(--surface);
}
.money-form-row .money-date {
    width: 150px;
}
.money-form-row .money-amount {
    width: 115px;
}
.money-form-row .money-balance {
    width: 120px;
}
.money-form-row .money-comment {
    flex: 1 1 200px;
    min-width: 150px;
}
.money-form-row .money-type {
    width: 135px;
}
.money-form-row .money-form-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.money-form-row .money-form-actions button {
    margin: 0;
}

/* Постоянные платежи: поля формы (строки переиспользуют .money-form-row).
   Первая строка — Начало|Конец|Сумма|Периодичность|День, суммарно ~726px,
   чтобы не переноситься при окнах от ~820px (мобильный вид — media 800px). */
.money-form-row .mrk-date {
    width: 140px;
}
.money-form-row .mrk-amount {
    width: 100px;
}
.money-form-row .mrk-period {
    width: 150px;
}
.money-form-row .mrk-day {
    width: 140px;
}
.money-form-row .mrk-comment {
    flex: 1 1 200px;
    min-width: 150px;
}
.money-form-row .mrk-type {
    width: 135px;
}
/* selects в форме платежей — те же стили, что у inputs */
.money-form-row select {
    width: 100%;
    padding: 6px 9px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.92rem;
    color: var(--text);
    background: var(--surface);
}
/* скрытие «неактивного» поля дня (label — flex, атрибут hidden сам не победит) */
.money-form-row label[hidden] {
    display: none;
}
/* Заголовок и таблица постоянных платежей */
.mrk-title {
    margin: 22px 0 10px;
    font-size: 1rem;
}
.mrk-table th.mrk-col-date,
.mrk-table td.mrk-col-date {
    text-align: center;
    width: 1%;
    white-space: nowrap;
}

/* Таблица журнала: дата по центру, колонки суммы/остатка — по контенту,
   комментарий растянут на всю ширину */
.money-table th.money-col-date,
.money-table td.money-col-date {
    text-align: center;
    width: 1%;
}
.money-table th.money-col-date,
.money-table td.money-col-date,
.money-table th.num,
.money-table td.num,
.money-table th.own-wh-actions-th,
.money-table td.own-wh-actions {
    white-space: nowrap;
    width: 1%;
}
.money-table th.money-col-comment,
.money-table td.money-col-comment {
    width: auto;
    white-space: normal;
}
/* Тип записи/платежа — узкая колонка перед «Комментарием» */
.money-table th.money-col-type,
.money-table td.money-col-type {
    white-space: nowrap;
    width: 1%;
}

/* Money: отступ снизу таблиц — кнопка добавления («+») теперь в шапке,
   панель действий убрана, поэтому воздух после таблицы компенсируем снизу */
.money-table-wrap {
    margin-bottom: 24px;
}

/* Кнопка «+» добавления в шапке таблиц денег:
   белый фон (как у кнопок редактирования в строках) и выравнена вправо —
   на одной оси с кнопками редактирования ниже. Перекрывает text-align: left
   из .data-table th */
.money-table thead th.own-wh-actions-th {
    text-align: right;
}
.money-table thead th.own-wh-actions-th .icon-btn {
    background: var(--surface, #fff);
}
