/* ──────────────────────────────────────────────────────────
   РайАгро — Дизайн-система v2
   ────────────────────────────────────────────────────────── */

:root {
    --navy:     #1e3a5f;
    --accent:   #0078d4;
    --green:    #16a34a;
    --amber:    #f59e0b;
    --red:      #dc2626;
    --gray-600: #4b5563;
    --gray-400: #9ca3af;
    --gray-200: #e2e8f0;
    --gray-100: #f3f4f6;
    --bg:       #f0f2f5;
    --surface:  #ffffff;
    --border:   #e2e8f0;
    --text3:    #999;

    --font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-size-base: 14px;
    --font-size-sm: 12px;
    --font-size-lg: 16px;
    --font-size-xl: 20px;

    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    --shadow-sm: 0 2px 8px rgba(0,0,0,.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,.12);
    --radius: 8px;
}

/* ──────────────────────────────────────────────────────────
   БАЗОВЫЕ СТИЛИ
   ────────────────────────────────────────────────────────── */

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    color: var(--navy);
    background: var(--bg);
}

body {
    overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
    margin: 0;
    font-weight: 600;
}

h1 { font-size: 28px; }
h2 { font-size: 24px; }
h3 { font-size: 20px; }
h4 { font-size: 16px; }

/* ──────────────────────────────────────────────────────────
   КОМПОНЕНТЫ
   ────────────────────────────────────────────────────────── */

.btn {
    padding: var(--spacing-sm) var(--spacing-md);
    border: none;
    border-radius: var(--radius);
    font-size: var(--font-size-base);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn:active {
    transform: translateY(0);
}

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

.btn-primary:hover {
    background: #0066b3;
}

.btn-secondary {
    background: var(--surface);
    color: var(--navy);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--gray-100);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

input.filter-input,
select.filter-select {
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: var(--font-size-base);
    background: white;
    color: var(--navy);
}

select.filter-select[multiple] {
    min-height: 90px;
    padding: 4px;
}

select.filter-select[multiple] option {
    padding: 4px 8px;
}

select.filter-select[multiple] option:checked {
    background: linear-gradient(var(--accent), var(--accent));
    background-color: var(--accent) !important;
    color: white;
}

input.filter-input:focus,
select.filter-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 120, 212, 0.1);
}

/* ──────────────────────────────────────────────────────────
   РАЗМЕТКА СТРАНИЦЫ
   ────────────────────────────────────────────────────────── */

.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: var(--bg);
}

/* ШАПКА */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-lg);
    padding: var(--spacing-md) var(--spacing-lg);
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.header-left h1 {
    color: var(--navy);
    margin: 0;
}

.subtitle {
    color: var(--gray-400);
    font-size: var(--font-size-sm);
}

.header-center {
    flex: 1;
    text-align: center;
}

.last-update {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    justify-content: center;
    font-size: var(--font-size-sm);
    color: var(--gray-600);
}

.update-value {
    font-weight: 600;
    color: var(--navy);
}

.stale-data-badge {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    color: #92400e;
    background: #fef3c7;
    border: 1px solid #fcd34d;
    max-width: 420px;
    line-height: 1.3;
}

.header-right {
    display: flex;
    gap: var(--spacing-sm);
}

.bug-count {
    background: var(--red);
    color: white;
    border-radius: 12px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: bold;
    margin-left: 4px;
}

/* НАВИГАЦИЯ (ВКЛАДКИ) — внутри .header */
.nav-tabs {
    border-top: 1px solid var(--border);
    padding: 0 var(--spacing-lg);
    display: flex;
    gap: var(--spacing-md);
    overflow-x: auto;
}

.nav-tab {
    background: none;
    border: none;
    padding: var(--spacing-md) var(--spacing-lg);
    cursor: pointer;
    font-size: var(--font-size-base);
    color: var(--gray-600);
    border-bottom: 3px solid transparent;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.nav-tab:hover {
    color: var(--navy);
}

.nav-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* ОСНОВНОЙ КОНТЕНТ */
.main-content {
    flex: 1;
    padding: var(--spacing-lg);
    overflow-y: auto;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ПАНЕЛЬ ФИЛЬТРОВ */
.filters-panel {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.filters-panel > * {
    flex: 0 0 auto;
}

.filter-search-main {
    flex: 0 0 160px !important;
    min-width: 0 !important;
}

.fdrop {
    flex: 0 0 105px;
    min-width: 0;
    max-width: 105px;
}

.filter-dates {
    display: flex;
    gap: 4px;
    flex: 0 0 auto;
}

.filter-dates input {
    width: 100px;
    min-width: 0;
}

.filter-hide-closed {
    flex: 0 0 auto;
    white-space: nowrap;
    margin-left: 0;
}

/* ──────────────────────────────────────────────────────────
   КАСТОМНЫЕ DROPDOWN ФИЛЬТРЫ
   ────────────────────────────────────────────────────────── */

.fdrop {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 180px;
}

.fdrop-trigger {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 5px 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    background: white;
    min-height: 30px;
    font-size: 11px;
    color: var(--navy);
    transition: all 0.2s ease;
    overflow: hidden;
    white-space: nowrap;
}

.fdrop-trigger:hover {
    border-color: #999;
    background: #fafafa;
}

.fdrop.open .fdrop-trigger {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(0, 120, 212, 0.1);
    background: white;
}

.fdrop-label {
    color: var(--gray-400);
    font-size: 11px;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}

.fdrop-label.filled {
    color: var(--navy);
    font-weight: 500;
    max-width: 100px;
}

.fdrop-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    flex: 1;
}

.fdrop-tag {
    background: var(--accent);
    color: white;
    border-radius: 3px;
    padding: 2px 4px;
    font-size: 10px;
    display: flex;
    align-items: center;
    gap: 2px;
    white-space: nowrap;
}

.fdrop-tag-x {
    cursor: pointer;
    opacity: 0.9;
    font-weight: bold;
    line-height: 1;
}

.fdrop-tag-x:hover {
    opacity: 1;
}

.fdrop-arrow {
    font-size: 9px;
    color: var(--gray-400);
    flex-shrink: 0;
    transition: transform 0.2s;
    margin-left: auto;
}

.fdrop.open .fdrop-arrow {
    transform: scaleY(-1);
}

.fdrop-panel {
    position: absolute;
    z-index: 999;
    top: calc(100% + 2px);
    left: 0;
    width: 220px;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: none;
    overflow: hidden;
    flex-direction: column;
}

.fdrop.open .fdrop-panel {
    display: flex;
}

.fdrop-search {
    width: 100%;
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 8px 10px;
    font-size: 12px;
    outline: none;
    font-family: inherit;
    background: white;
}

.fdrop-search:focus {
    background: #f9f9f9;
    border-bottom-color: var(--accent);
}

.fdrop-list {
    max-height: 200px;
    overflow-y: auto;
    flex: 1;
}

.fdrop-item {
    padding: 7px 10px;
    cursor: pointer;
    font-size: 12px;
    color: var(--navy);
    white-space: nowrap;
    transition: background 0.1s;
    border-left: 3px solid transparent;
}

.fdrop-item:hover {
    background: #f0f0f0;
}

.fdrop-item.selected {
    background: #e3f2fd;
    color: var(--accent);
    font-weight: 500;
    border-left-color: var(--accent);
}

.fdrop-item.hidden {
    display: none;
}

/* Группы фильтров */
.filter-hide-closed {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    white-space: nowrap;
}

.filter-hide-closed input {
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.filter-hide-closed span {
    font-size: 11px;
    color: var(--navy);
}

#tableOrders {
    flex: 1;
    overflow: hidden;
}

/* ДАШБОРД КАРТОЧКИ */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
}

.dashboard-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-sm);
}

.dashboard-card h3 {
    margin-bottom: var(--spacing-md);
    color: var(--navy);
}

.dashboard-card canvas {
    max-width: 100%;
    height: auto;
}

/* KPI КАРТОЧКИ */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
}

.kpi-card {
    background: linear-gradient(135deg, var(--accent) 0%, #0066b3 100%);
    color: white;
    border-radius: var(--radius);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-md);
    text-align: center;
}

.kpi-value {
    font-size: 32px;
    font-weight: bold;
    margin-bottom: var(--spacing-sm);
}

.kpi-label {
    font-size: var(--font-size-sm);
    opacity: 0.9;
}

/* ТАБЛИЦА МЕНЕДЖЕРОВ */
.managers-table-container {
    background: var(--surface);
    border-radius: var(--radius);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-sm);
    margin-top: var(--spacing-lg);
}

/* КАРТА */
.map-content {
    background: var(--surface);
    border-radius: var(--radius);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-sm);
}

.map-controls {
    display: flex;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

#map {
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: #f5f5f5;
}

/* ПАНЕЛЬ БАГОВ (боковая) */
.bugs-panel {
    position: fixed;
    right: -400px;
    top: 0;
    width: 400px;
    height: 100vh;
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    transition: right 0.3s ease;
    overflow-y: auto;
    z-index: 1000;
}

.bugs-panel.open {
    right: 0;
}

.bugs-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border);
    background: var(--gray-100);
}

.bugs-header h3 {
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--gray-600);
}

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

.bugs-list {
    padding: var(--spacing-md);
}

.bug-item {
    background: var(--gray-100);
    border-left: 3px solid var(--red);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-md);
    border-radius: var(--radius);
}

.bug-type {
    font-weight: 600;
    color: var(--red);
    font-size: var(--font-size-sm);
}

.bug-description {
    margin: var(--spacing-sm) 0 0 0;
    color: var(--gray-600);
}

/* ИНДИКАТОР ЗАГРУЗКИ */
.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.3);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: var(--spacing-lg);
}

.loading-overlay.active {
    display: flex;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay p {
    color: white;
    font-size: var(--font-size-lg);
}

/* ──────────────────────────────────────────────────────────
   АДАПТИВНОСТЬ
   ────────────────────────────────────────────────────────── */

@media (max-width: 1024px) {
    .header-top {
        flex-wrap: wrap;
        gap: var(--spacing-md);
    }

    .nav-tabs {
        gap: var(--spacing-sm);
        padding: 0 var(--spacing-md);
    }

    .nav-tab {
        padding: var(--spacing-sm) var(--spacing-md);
        font-size: 12px;
    }

    .filters-panel > * {
        min-width: 120px;
        flex: 1;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

/* ══════════════════════════════════════════════════════════
   МОБИЛЬНЫЕ ЭЛЕМЕНТЫ — скрыты на десктопе
   ══════════════════════════════════════════════════════════ */

.mob-search-row   { display: none; }
.bottom-nav       { display: none; }
.mob-grp-section  { display: none; }

/* ══════════════════════════════════════════════════════════
   МОБИЛЬНАЯ АДАПТАЦИЯ (≤ 768px)
   ══════════════════════════════════════════════════════════ */

@media (max-width: 768px) {

    /* ── ШАПКА ── */
    .header-top {
        padding: 10px 14px;
        gap: 8px;
        flex-wrap: nowrap;
        align-items: center;
    }

    .header-left h1 { font-size: 20px; }
    .subtitle        { display: none; }

    .header-center { display: none; }   /* "Обновлено" скрыть */

    .header-right .btn {
        padding: 7px 11px;
        font-size: 13px;
    }

    /* ── ВКЛАДКИ ШАПКИ — скрыть, будет нижняя навигация ── */
    .nav-tabs { display: none; }

    /* ── ОСНОВНОЙ КОНТЕНТ ── */
    .main-content {
        padding: 10px 10px 70px; /* отступ снизу под нижнюю панель */
    }

    /* ── МОБИЛЬНАЯ СТРОКА ПОИСКА + ФИЛЬТРЫ ── */
    .mob-search-row {
        display: flex;
        gap: 8px;
        align-items: center;
        margin-bottom: 10px;
    }

    .mob-search-input {
        flex: 1;
        height: 38px;
        padding: 0 12px;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        font-size: 14px;
        font-family: inherit;
        color: var(--navy);
        background: white;
        outline: none;
    }

    .mob-search-input:focus {
        border-color: var(--accent);
        box-shadow: 0 0 0 3px rgba(0,120,212,.1);
    }

    .mob-filter-btn {
        display: flex;
        align-items: center;
        gap: 6px;
        height: 38px;
        padding: 0 14px;
        background: white;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        font-size: 13px;
        font-family: inherit;
        color: var(--navy);
        cursor: pointer;
        white-space: nowrap;
        transition: all .2s;
        flex-shrink: 0;
    }

    .mob-filter-btn:active {
        background: var(--gray-100);
        transform: scale(.97);
    }

    .mob-filter-btn.has-filters {
        border-color: var(--accent);
        background: #ebf4ff;
        color: var(--accent);
    }

    .mob-fcount {
        background: var(--accent);
        color: white;
        border-radius: 10px;
        padding: 1px 6px;
        font-size: 11px;
        font-weight: 700;
        display: none;
    }

    .mob-fcount.visible { display: inline-block; }

    /* ── ТУЛБАР ГРУППИРОВКИ — скрыть на мобильном ── */
    .orders-toolbar { display: none !important; }

    /* ── ГРУППИРОВКА И СОРТИРОВКА ВНУТРИ ДРОВЕРА ФИЛЬТРОВ ── */
    .mob-grp-section {
        display: flex;
        flex-direction: column;
        gap: 6px;
        padding-bottom: 14px;
        border-bottom: 1px solid var(--border);
        width: 100% !important;
    }

    .mob-grp-label {
        font-size: 11px;
        font-weight: 700;
        color: var(--gray-600);
        text-transform: uppercase;
        letter-spacing: .4px;
    }

    .mob-grp-section .grp-toggle,
    .mob-grp-section .sort-btns {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
    }

    .mob-grp-section .gt-btn {
        flex: 1 1 auto;
        min-width: 60px;
        padding: 7px 10px;
        font-size: 12px;
        text-align: center;
        border-radius: 6px;
    }

    /* ── ФИЛЬТРЫ — выдвижная панель снизу ──
       ВАЖНО: анимация только через bottom (не transform!),
       иначе position:fixed у дочерних fdrop-panel ломается  */
    .filters-panel {
        position: fixed;
        left: 0; right: 0;
        bottom: -80vh;           /* скрыта за экраном */
        z-index: 800;
        background: white;
        border-top: 1px solid var(--border);
        box-shadow: 0 -6px 24px rgba(0,0,0,.16);
        border-radius: 16px 16px 0 0;
        padding: 16px;
        flex-direction: column;
        gap: 10px;
        flex-wrap: nowrap;
        max-height: 70vh;
        overflow-y: auto;
        opacity: 0;
        pointer-events: none;
        transition: bottom .3s ease, opacity .25s ease;
        display: flex;
    }

    .filters-panel.mob-open {
        bottom: 56px;
        opacity: 1;
        pointer-events: auto;
    }

    /* Ручка-индикатор сверху */
    .filters-panel::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        background: var(--gray-200);
        border-radius: 2px;
        margin: 0 auto 8px;
        flex-shrink: 0;
    }

    /* Все элементы фильтров — полная ширина */
    .filters-panel > * {
        flex: 0 0 auto !important;
        min-width: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    .filter-search-main {
        width: 100% !important;
        height: 40px;
        font-size: 14px;
    }

    .fdrop {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 auto !important;
    }

    .fdrop-trigger {
        min-height: 40px;
        font-size: 13px;
        padding: 8px 12px;
    }

    /* Выпадающий список fdrop — фиксированный, появляется в верхней части экрана */
    .fdrop-panel {
        position: fixed !important;
        top: 70px;
        left: 10px;
        right: 10px;
        bottom: auto;
        width: auto !important;
        max-height: 45vh;
        z-index: 1100;
    }

    .fdrop-list { max-height: 38vh; }

    .fdrop-item { padding: 12px 14px; font-size: 14px; }

    .filter-dates {
        width: 100% !important;
        display: flex;
        gap: 8px;
    }

    .filter-dates input {
        flex: 1;
        height: 40px;
        font-size: 13px;
    }

    .filter-hide-closed {
        width: 100% !important;
        padding: 4px 0;
    }

    .filter-hide-closed input {
        width: 18px;
        height: 18px;
    }

    .filter-hide-closed span {
        font-size: 13px;
    }

    #btnClearFilters {
        width: 100% !important;
        height: 40px;
        font-size: 13px;
        justify-content: center;
    }

    /* Оверлей за панелью фильтров */
    .filters-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.35);
        z-index: 799;
    }

    .filters-overlay.visible { display: block; }

    /* ── ТАБЛИЦА ── */
    .tbl-wrap {
        overflow-x: auto;
        overflow-y: auto;
        max-height: calc(100vh - 240px);
        -webkit-overflow-scrolling: touch;
        border-radius: var(--radius);
    }

    #ordersTable {
        font-size: 12px;
        min-width: 680px;
    }

    #ordersTable th,
    #ordersTable td {
        padding: 8px 10px;
    }

    /* Первые 2 колонки — sticky */
    #ordersTable td:nth-child(1),
    #ordersTable th:nth-child(1) {
        position: sticky;
        left: 0;
        background: white;
        z-index: 2;
    }
    #ordersTable thead th:nth-child(1) {
        background: var(--gray-100);
        z-index: 12;
    }
    #ordersTable tr.sel-row td:nth-child(1) { background: #e3f2fd; }
    #ordersTable tr.grp-hdr td:nth-child(1) { background: #f0f4f8; }

    /* ── SEL-BAR ── */
    .sel-bar {
        flex-wrap: wrap;
        gap: 6px;
        padding: 8px 10px;
        font-size: 12px;
    }

    /* ── ПАНЕЛЬ БАГОВ ── */
    .bugs-panel {
        width: 100%;
        right: -100%;
    }

    /* ── СКЛАД ── */
    .stk-two-col   { grid-template-columns: 1fr; }
    .stk-kpi-row   { gap: 8px; }
    .stk-kpi       { min-width: 140px; }

    /* ── РАЙОНЫ ── */
    #districtPivotContent { overflow-x: auto; }
    .dp-toolbar { gap: 8px; padding: 8px 0; }

    /* ── НИЖНЯЯ НАВИГАЦИЯ ── */
    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        height: 56px;
        background: white;
        border-top: 1px solid var(--border);
        box-shadow: 0 -2px 12px rgba(0,0,0,.08);
        z-index: 1000;
        align-items: stretch;
    }

    .bnav-tab {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        background: none;
        border: none;
        cursor: pointer;
        color: var(--gray-400);
        padding: 6px 4px;
        transition: color .2s;
        -webkit-tap-highlight-color: transparent;
        position: relative;
    }

    .bnav-tab::after {
        content: '';
        position: absolute;
        top: 0; left: 20%; right: 20%;
        height: 2px;
        background: var(--accent);
        border-radius: 0 0 2px 2px;
        opacity: 0;
        transition: opacity .2s;
    }

    .bnav-tab.active {
        color: var(--accent);
    }

    .bnav-tab.active::after { opacity: 1; }

    .bnav-icon  { font-size: 20px; line-height: 1; }
    .bnav-label { font-size: 10px; font-weight: 500; white-space: nowrap; }
}

/* ══════════════════════════════════════════════════════════
   МАЛЕНЬКИЙ ТЕЛЕФОН (≤ 480px)
   ══════════════════════════════════════════════════════════ */

@media (max-width: 480px) {

    .header-left h1 { font-size: 18px; }

    .main-content { padding: 8px 8px 70px; }

    #ordersTable { font-size: 11px; min-width: 600px; }
    #ordersTable th, #ordersTable td { padding: 6px 8px; }

    .tbl-wrap { max-height: calc(100vh - 230px); }

    .bnav-icon  { font-size: 18px; }
    .bnav-label { font-size: 9px; }
}

/* ──────────────────────────────────────────────────────────
   TABULATOR ПЕРЕОПРЕДЕЛЕНИЯ
   ────────────────────────────────────────────────────────── */

.tabulator {
    background: var(--surface);
    border: 1px solid var(--border);
}

.tabulator .tabulator-header {
    background: var(--gray-100);
    border-bottom: 1px solid var(--border);
}

.tabulator .tabulator-row {
    border-bottom: 1px solid var(--gray-100);
}

.tabulator .tabulator-row:hover {
    background: var(--gray-100);
}

.tabulator .tabulator-cell {
    padding: var(--spacing-sm) var(--spacing-md);
}

/* НЕ ДОБАВЛЯТЬ display:flex К .tab-panel! Вкладки скрываются через display:none/block */

.chart-container {
    background: var(--surface);
    border-radius: var(--radius);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--spacing-lg);
}

.shipment-summary {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--spacing-md);
}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md);
    background: var(--gray-100);
    border-radius: var(--radius);
}

.summary-row strong {
    font-size: var(--font-size-lg);
    color: var(--accent);
}

/* ТАБЛИЦА ЗАКАЗОВ */
.orders-toolbar {
    display: flex;
    gap: 6px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.grp-toggle {
    display: flex;
    gap: 8px;
}

.gt-btn {
    padding: 4px 10px;
    border: 1px solid var(--border);
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    transition: all 0.2s;
    white-space: nowrap;
}

.gt-btn:hover {
    background: var(--gray-100);
}

.gt-btn.on {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.sort-btns {
    display: flex;
    gap: 8px;
    align-items: center;
}

.sel-bar {
    background: #e3f2fd;
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: #1565c0;
}

.tbl-wrap {
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow-y: auto;
    max-height: calc(100vh - 230px);
}

#ordersTable {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

#ordersTable thead {
    background: var(--gray-100);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

#ordersTable th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--gray-600);
    border-right: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
}

#ordersTable th:last-child {
    border-right: none;
}

#ordersTable th.r {
    text-align: right;
}

#ordersTable td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--gray-100);
    border-right: 1px solid var(--gray-100);
}

#ordersTable td:last-child {
    border-right: none;
}

#ordersTable tr.orow:hover {
    background: #f9fafb;
}

#ordersTable tr.orow.sel-row {
    background: #e3f2fd;
}

#ordersTable tr.grp-hdr {
    background: #f0f4f8;
    font-weight: 600;
    color: var(--navy);
    border-bottom: 2px solid var(--border);
}

#ordersTable tr.grp-hdr td {
    padding: 12px;
    border-right: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#ordersTable tr.tfoot {
    background: var(--gray-100);
    font-weight: 600;
    border-top: 2px solid var(--border);
}

#ordersTable tbody input[type="checkbox"],
#ordersTable thead input[type="checkbox"] {
    cursor: pointer;
    width: 18px;
    height: 18px;
}

.cb-col {
    width: 40px;
    text-align: center;
}

.r {
    text-align: right;
}

/* БЭДЖИ СТАТУСОВ */
.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.badge.b-ready {
    background: #d4edda;
    color: #155724;
}

.badge.b-proc {
    background: #cfe2ff;
    color: #084298;
}

.badge.b-pay {
    background: #fff3cd;
    color: #664d03;
}

.badge.b-res {
    background: #f8d7da;
    color: #842029;
}

.badge.b-done {
    background: #d1ecf1;
    color: #0c5460;
}

.badge.b-prepay {
    background: #ffe5b4;
    color: #7a4400;
}

.badge.b-nopay {
    background: #f8d7da;
    color: #842029;
    font-weight: 700;
}

/* ФИЛЬТР НОМЕНКЛАТУРЫ (Заявка / Ведомость) */
.nom-filter-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 12px;
}
.nom-filter-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.nom-filter-title { font-size: 12px; font-weight: 600; color: var(--gray-600); }
.nf-btn-all, .nf-btn-none {
    border: 1px solid var(--border);
    background: white;
    border-radius: 10px;
    padding: 2px 10px;
    font-size: 11px;
    cursor: pointer;
    color: var(--gray-600);
}
.nf-btn-all:hover  { background: #d4edda; color: #155724; border-color: #b8dfc6; }
.nf-btn-none:hover { background: #f8d7da; color: #842029; border-color: #f5c2c7; }
.nom-filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: center;
}
.nf-culture-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--navy);
    margin-right: 2px;
    margin-top: 2px;
}
.nf-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    cursor: pointer;
    border: 1px solid #ccc;
    background: #e9ecef;
    color: #6c757d;
    transition: all 0.15s;
    user-select: none;
}
.nf-chip.nf-active {
    background: #d4edda;
    color: #155724;
    border-color: #b8dfc6;
    font-weight: 500;
}
.nf-chip:hover { opacity: 0.8; }
.nf-qty { font-weight: 700; font-size: 10px; }

.badge.b-def {
    background: #e2e3e5;
    color: #383d41;
}

.badge.b-refused {
    background: #f3e8ff;
    color: #7c3aed;
    font-weight: 700;
}

/* Строка отказа — приглушённый вид */
#ordersTable tr.refused-row td {
    opacity: .55;
}

#ordersTable tr.refused-row:hover td {
    opacity: .75;
    background: #fdf4ff;
}

.refused-nom {
    font-style: italic;
    color: #9ca3af;
    font-size: 11px;
}

/* ТЕГИ ДОЛГА */
.debt-tag {
    display: inline-block;
    padding: 3px 6px;
    margin-left: 6px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.debt-tag.dt-ship-done {
    background: #28a745;
    color: white;
}

.debt-tag.dt-paid {
    background: #20c997;
    color: white;
}

.debt-tag.dt-credit {
    background: #ffc107;
    color: #333;
}

.debt-tag.dt-debt {
    background: #fd7e14;
    color: white;
}
.debt-tag.dt-noship {
    background: #dc2626;
    color: white;
    font-weight: 700;
    letter-spacing: -.2px;
}
.debt-tag.dt-debt-shipped {
    background: #f59e0b;
    color: white;
    font-weight: 700;
    letter-spacing: -.2px;
}

/* ПРОЦЕНТНАЯ ПОЛОСКА */
.pct-bar {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
}

.pct-bar-track {
    display: inline-block;
    width: 60px;
    height: 6px;
    background: #e0e0e0;
    border-radius: 3px;
    overflow: hidden;
}

.pct-bar-fill {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #4CAF50, #8BC34A);
    transition: width 0.3s;
}

.grp-note {
    font-size: 11px;
    color: var(--text3);
    margin-left: 12px;
}

/* KPI ВАРИАНТЫ */
.kpi-card {
    background: linear-gradient(135deg, var(--accent) 0%, #0066b3 100%);
    color: white;
    border-radius: var(--radius);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-md);
    min-width: 160px;
}

.kpi-card.kpi-danger {
    background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);
}

.kpi-card.kpi-warn {
    background: linear-gradient(135deg, #f59e0b 0%, #b45309 100%);
}

.kpi-card .kpi-label {
    font-size: 12px;
    opacity: 0.9;
    margin-bottom: 6px;
}

.kpi-card .kpi-value {
    font-size: 24px;
    font-weight: 700;
}

/* КАРТОЧКА-КОНТЕЙНЕР */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-title {
    padding: 12px 16px;
    background: var(--gray-100);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

/* КНОПКИ РАЗМЕРА SM */
.btn-sm {
    padding: 5px 12px;
    font-size: 12px;
}

.btn-ghost {
    background: transparent;
    color: var(--gray-600);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--gray-100);
}

/* ── СВОДНАЯ ТАБЛИЦА ПО РАЙОНАМ ─────────────────────────── */
#districtPivotContent { padding: 0; }

/* Основная сводная таблица */
.dp-tbl { width: 100%; border-collapse: collapse; font-size: 13px; }

.dp-th {
    padding: 7px 10px;
    text-align: left;
    background: var(--gray-100);
    border-bottom: 2px solid var(--border);
    font-size: 11px;
    color: var(--gray-600);
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}
.dp-th:hover { background: #dde3ea; }
.dp-th.r { text-align: right; }

.dp-sarr { margin-left: 3px; opacity: .4; font-size: 10px; }
.dp-sarr.active { opacity: 1; color: var(--accent); }

.dp-row { cursor: pointer; }
.dp-row:hover td { background: var(--gray-50); }
.dp-row-open td { background: #ebf4ff; }
.dp-row td { padding: 6px 10px; border-top: 1px solid var(--border); vertical-align: middle; font-size: 13px; }
.dp-row td.r { text-align: right; }

.dp-tog {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 10px;
    color: var(--gray-400);
    padding: 0 4px 0 0;
    line-height: 1;
}

.dp-total { font-weight: 700; color: var(--navy); }
.dp-zero  { color: var(--gray-300); }

/* Строка деталей */
.dp-detail { display: none; }
.dp-detail td { padding: 0 !important; border-top: none !important; }

/* Таблица деталей внутри */
.dp-det { width: 100%; border-collapse: collapse; font-size: 12px; background: #fafcff; }
.dp-det thead tr { background: var(--gray-50); }
.dp-det th { padding: 5px 12px; text-align: left; font-size: 11px; color: var(--gray-500); font-weight: 600; border-bottom: 1px solid var(--border); }
.dp-det th.r { text-align: right; }
.dp-det td { padding: 4px 12px; border-top: 1px solid #f0f0f0; vertical-align: top; }
.dp-det td.r { text-align: right; }
.dp-det-cl   { font-weight: 600; max-width: 200px; }
.dp-det-loc  { font-size: 11px; color: var(--gray-500); max-width: 120px; }
.dp-det-date { font-size: 11px; color: var(--gray-600); white-space: nowrap; }

/* Итоговая строка */
.dp-foot td {
    padding: 7px 10px;
    border-top: 2px solid var(--border);
    background: var(--gray-100);
    font-size: 13px;
}
.dp-foot td.r { text-align: right; }

.dp-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0 12px;
    flex-wrap: wrap;
}
.dp-bold { font-weight: 600; color: var(--navy); }

.dp-multi-drop { position: relative; }
.dp-multi-btn {
    cursor: pointer; background: white; border: 1px solid var(--border);
    border-radius: var(--radius); padding: 7px 12px; font-size: 13px;
    white-space: nowrap; text-align: left;
}
.dp-multi-btn.active { border-color: var(--accent); color: var(--accent); background: #ebf4ff; }
.dp-multi-panel {
    display: none; position: absolute; z-index: 999; top: calc(100% + 4px); left: 0;
    min-width: 200px; max-height: 260px; overflow-y: auto;
    background: white; border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-md); padding: 6px 0;
}
.dp-multi-drop:focus-within .dp-multi-panel,
.dp-multi-drop.open .dp-multi-panel { display: block; }
.dp-chk-item {
    display: flex; align-items: center; gap: 8px; padding: 5px 12px;
    font-size: 13px; cursor: pointer; user-select: none;
}
.dp-chk-item:hover { background: var(--gray-50); }
.dp-chk-item.checked { background: #ebf4ff; color: var(--accent); font-weight: 500; }

/* ══════════════════════════════════════════════════════════════
   СКЛАД — визуальный дашборд с графиками
══════════════════════════════════════════════════════════════ */

.stk-empty  { padding: 40px; text-align: center; color: var(--gray-400); font-size: 15px; }
.stk-dim    { color: #9ca3af; font-size: 11px; }
.stk-red    { color: #dc2626; font-weight: 700; }
.stk-orange { color: #d97706; font-weight: 600; }
.stk-green  { color: #16a34a; font-weight: 700; }

/* Тулбар */
.stk-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px;
    background: white; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }

/* ── СЕКЦИЯ КУЛЬТУРЫ (Подсолнечник / Кукуруза / склад СЗР) ─── */
.stk-cult-section {
    background: #fff; border: 1px solid #e5e7eb; border-radius: 12px;
    margin-bottom: 16px; overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.stk-cult-hdr {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 10px 16px; background: var(--navy); color: #fff;
}
.stk-cult-title   { font-size: 14px; font-weight: 700; white-space: nowrap; }
.stk-cult-summary { font-size: 12px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stk-cult-summary .stk-dim    { color: #cbd5e1; }
.stk-cult-summary .stk-orange { color: #fcd34d; font-weight: 600; }

/* ── СТРОКА ГИБРИДА ──────────────────────────────────────────── */
.stk-hyb-row {
    border-bottom: 1px solid #f0f4f8;
    padding: 10px 16px 6px;
}
.stk-hyb-row:last-child { border-bottom: none; }
.stk-hyb-def { background: #fff8f8; border-left: 3px solid #dc2626; }

.stk-hyb-head {
    display: flex; align-items: baseline; gap: 10px;
    flex-wrap: wrap; margin-bottom: 5px;
}
.stk-hyb-name  { font-size: 13px; font-weight: 700; flex-shrink: 0; min-width: 120px; }
.stk-hyb-right { font-size: 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.stk-hyb-bar   { margin-bottom: 6px; }

/* ── БЕЙДЖИ ДЕФИЦИТ / ИЗБЫТОК ───────────────────────────────── */
.stk-badge-def {
    display: inline-flex; align-items: center;
    background: #dc2626; color: #fff;
    font-size: 11px; font-weight: 800;
    border-radius: 5px; padding: 2px 8px;
    white-space: nowrap; letter-spacing: .3px;
}
.stk-badge-ok {
    display: inline-flex; align-items: center;
    background: #16a34a; color: #fff;
    font-size: 11px; font-weight: 800;
    border-radius: 5px; padding: 2px 8px;
    white-space: nowrap; letter-spacing: .3px;
}
.stk-badge-zero {
    display: inline-flex; align-items: center;
    background: #6b7280; color: #fff;
    font-size: 11px; font-weight: 700;
    border-radius: 5px; padding: 2px 8px;
    white-space: nowrap;
}

/* ── ПАРТИИ ─────────────────────────────────────────────────── */
.stk-batches {
    background: #f8fafc; border-top: 1px dashed #e2e8f0;
    padding: 4px 0 4px 12px; margin: 0 -16px -6px; padding-left: 24px;
}
.stk-batch-row {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 4px 16px 4px 0; border-bottom: 1px solid #edf2f7; font-size: 12px;
}
.stk-batch-row:last-child { border-bottom: none; }
.stk-batch-def { background: #fff5f5; }
.stk-batch-id  { color: #6b7280; font-weight: 600; min-width: 90px; }
.stk-batch-wh  { color: #9ca3af; font-size: 11px; min-width: 80px; }
.stk-batch-nums { margin-left: auto; display: flex; align-items: center; gap: 4px; white-space: nowrap; }

/* ── САФАРИ — специальный блок ──────────────────────────────── */
.stk-safari-wrap { border-top: 1px solid #f0f4f8; }
.stk-safari-hdr {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 8px 16px; background: #fffbf0; border-bottom: 1px solid #fde68a;
}
.stk-safari-title  { font-size: 13px; font-weight: 800; color: #92400e; }
.stk-safari-sum    { font-size: 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stk-nobatch-warn  {
    display: inline-flex; align-items: center;
    background: #7c3aed; color: #fff;
    font-size: 11px; font-weight: 700;
    border-radius: 5px; padding: 2px 8px; white-space: nowrap;
}
.stk-hyb-nobatch   { background: #faf5ff !important; border-left: 3px solid #7c3aed !important; }

/* ── ГОРИЗОНТАЛЬНЫЙ БАР ─────────────────────────────────────── */
.stk-hbar {
    display: flex; border-radius: 5px; overflow: hidden;
    background: #e5e7eb; width: 100%;
}
.stk-hbar-rsv  { background: #f59e0b; flex-shrink: 0; transition: width .3s; }
.stk-hbar-free { background: #22c55e; flex-shrink: 0; transition: width .3s; }
.stk-hbar-def  { background: #dc2626; flex-shrink: 0; transition: width .3s; opacity: .85; }

@media (max-width: 900px) {
    .stk-hyb-right { margin-left: 0; }
    .stk-cult-hdr  { flex-direction: column; align-items: flex-start; }
}
