* {
    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 */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.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"],
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 {
    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);
}

/* Topbar */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand {
    font-weight: 600;
    font-size: 1.05rem;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 16px;
}

.nav-links a {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 5px 10px;
    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);
}

.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;
}

/* 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;
}

/* Topbar: shops + dropdown */
.topbar {
    gap: 16px;
}

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

.topbar-right {
    display: flex;
    align-items: center;
    gap: 24px;
}

/* Кнопка-гамбургер правого меню: видна только на узких экранах */
.menu-toggle {
    display: none;
    width: 34px;
    height: 34px;
    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;
}

.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;
    gap: 2px;
    padding: 2px;
}

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

.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-trigger.empty {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.9rem;
}

/* 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 thead th {
    color: var(--muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--bg);
}

.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-den {
    border-top: 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 .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;
}

/* Пометка простоя по последней продаже (артикул в остатках) */
.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 {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 170px;
    width: 100%;
    min-width: 0;
}

.chart-grid {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 160px;
    z-index: 0;
    pointer-events: none;
}

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

.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;
}

.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;
}

.chart-day {
    text-align: center;
    font-size: 0.62rem;
    color: var(--muted);
    margin-top: 4px;
    white-space: nowrap;
}

/* На узких экранах в подписи дней показываем только число */
@media (max-width: 520px) {
    .chart-day-month {
        display: none;
    }

    /* Без отступов по краям экрана */
    .container,
    .container.full,
    .container.wide {
        padding-left: 0;
        padding-right: 0;
        margin-left: 0;
        margin-right: 0;
    }

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

    /* Заказы: номер заказа скрыт, год в дате скрыт */
    .ord-num {
        display: none;
    }
    .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;
    }
}

/* Правую часть верхнего меню на узких экранах прячем в кнопку-гамбургер,
   чтобы она не перекрывала пункты меню магазинов. Раскрывается по тапу. */
@media (max-width: 760px) {
    .menu-toggle {
        display: flex;
    }
    .topbar-right {
        position: relative;
    }
    .topbar-right .nav-links {
        display: none;
    }
    .topbar-right .nav-links.open {
        display: flex;
        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);
    }
}

