/* === БАЗОВЫЕ СТИЛИ LAMODA PRO === */
:root {
    --bg-app: #f4f7fe;
    --bg-sidebar: #111827; 
    --bg-sidebar-hover: #1f2937;
    --text-sidebar: #9ca3af;
    --text-sidebar-active: #ffffff;
    --primary: #3b82f6; 
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg-panel: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    
    --sidebar-collapsed: 70px;
    --sidebar-expanded: 260px;
}

body {
    margin: 0; font-family: 'Inter', 'Segoe UI', sans-serif;
    background: var(--bg-app); color: var(--text-main);
    height: 100vh; overflow: hidden; display: flex; font-size: 13px;
}

.sidebar { position: fixed; top: 0; left: 0; height: 100vh; width: var(--sidebar-collapsed); background: var(--bg-sidebar); color: var(--text-sidebar); transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1); z-index: 1000; overflow-x: hidden; white-space: nowrap; box-shadow: 4px 0 15px rgba(0,0,0,0.1); display: flex; flex-direction: column; }
.sidebar:hover { width: var(--sidebar-expanded); }
.sidebar-logo { height: 60px; display: flex; align-items: center; padding: 0 22px; font-size: 1.1rem; font-weight: 800; color: white; border-bottom: 1px solid rgba(255,255,255,0.05); background: #0f141f; flex-shrink: 0; letter-spacing: 0.5px; }
.sidebar-logo i { color: var(--primary); min-width: 26px; text-align: center; font-size: 1.4rem;}
.sidebar-logo span { margin-left: 15px; opacity: 0; transition: opacity 0.3s; }
.sidebar:hover .sidebar-logo span { opacity: 1; }
.nav-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; padding-bottom: 20px;}
.nav-scroll::-webkit-scrollbar { width: 4px; }
.nav-scroll::-webkit-scrollbar-thumb { background: #374151; border-radius: 4px; }
.nav-title { font-size: 0.7rem; text-transform: uppercase; font-weight: 700; padding: 15px 22px 5px 22px; opacity: 0; color: #4b5563; transition: opacity 0.3s; }
.sidebar:hover .nav-title { opacity: 1; }
.nav-item { display: flex; align-items: center; padding: 10px 22px; color: var(--text-sidebar); text-decoration: none; transition: all 0.2s; cursor: pointer; border-left: 3px solid transparent; }
.nav-item i { font-size: 1.1rem; min-width: 26px; text-align: center; }
.nav-item span { margin-left: 15px; font-weight: 500; font-size: 0.9rem; opacity: 0; transition: opacity 0.3s;}
.sidebar:hover .nav-item span { opacity: 1; }
.nav-item:hover { background: var(--bg-sidebar-hover); color: var(--text-sidebar-active); }
.nav-item.active { background: rgba(59, 130, 246, 0.15); color: var(--text-sidebar-active); border-left-color: var(--primary); }
.nav-item.active i { color: var(--primary); }

.main-wrapper { margin-left: var(--sidebar-collapsed); flex: 1; display: flex; flex-direction: column; height: 100vh; background: var(--bg-app); padding: 15px 25px; box-sizing: border-box; overflow-y: auto; }
.view-section { display: none; animation: fadeIn 0.2s ease; flex-direction: column; height: 100%;}
.view-section.active { display: flex; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }

/* === МОБИЛЬНЫЕ ЭЛЕМЕНТЫ (шапка, нижняя навигация, оверлей меню) ===
   По умолчанию (десктоп) полностью скрыты. Видимыми становятся только
   внутри медиа-запроса max-width:900px ниже. Без этого базового правила
   браузер показывает их прямо в потоке документа на любом экране. */
.mobile-topbar,
.mobile-bottom-nav,
.mobile-overlay {
    display: none;
}

/* === СТИЛИ ТАБЛИЦ И ЭЛЕМЕНТОВ ИЗ INDEX.HTML === */
.panel { flex: 1; background: #fff; border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.05); display: flex; flex-direction: column; overflow: hidden; }
table { border-collapse: collapse; font-size: 13px; width: 100%; }
th, td { padding: 10px 15px; border-bottom: 1px solid #eee; text-align: left; }
th { background: #f8f9fa; position: sticky; top: 0; color: #495057; z-index: 10; cursor: pointer; user-select: none; border-bottom: 1px solid #dee2e6;}
.col-border { border-left: 2px solid #dee2e6; }
.td-center { text-align: center; }
.th-sub { font-size: 12px; padding: 6px 10px; text-align: center; background: #e9ecef; top: 41px; cursor: default;}

.badge { padding: 4px 8px; border-radius: 12px; font-weight: bold; font-size: 0.8rem; color: #fff; display: inline-block; text-align: center; min-width: 20px;}
.b-blue { background: #007bff; }
.b-green { background: #28a745; }
.b-red { background: #dc3545; }
.b-gray { background: #6c757d; }

.footer-totals { padding: 8px 10px; background: #f8f9fa; border-top: 1px solid #eee; display: flex; gap: 6px; flex-wrap: nowrap; justify-content: center; align-items: center; overflow: hidden; }
.total-item { background: #fff; padding: 4px 8px; border-radius: 6px; border: 1px solid #ddd; font-weight: bold; font-size: 0.8rem; color: #333; white-space: nowrap; flex-shrink: 1;}
.total-item span { color: #007bff; font-size: 0.85rem; margin-left: 3px;}

.top-controls { padding: 10px 20px; background: #f8f9fa; display: flex; align-items: center; justify-content: flex-end; gap: 15px; border-bottom: 1px solid #dee2e6; }

.context-menu { display: none; position: absolute; background: white; border: 1px solid #ced4da; box-shadow: 0 5px 15px rgba(0,0,0,0.15); border-radius: 8px; z-index: 3000; min-width: 280px; padding: 5px 0; }
.context-menu.show { display: block; }
.context-header { padding: 8px 15px; font-size: 12px; color: #adb5bd; font-weight: bold; border-bottom: 1px solid #eee; margin-bottom: 5px; text-transform: uppercase;}
.context-item { padding: 10px 15px; cursor: pointer; display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; color: #495057; }
.context-item:hover { background: #f8f9fa; color: #007bff; }
.context-item.danger { color: #dc3545; border-top: 1px solid #eee; margin-top: 5px; }

.modal { display: none; position: fixed; z-index: 4000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5); align-items: center; justify-content: center; }
.modal.show { display: flex; }
.modal-content { background-color: #fff; padding: 25px; border-radius: 8px; width: 380px; max-width: 90%; position: relative; box-shadow: 0 10px 25px rgba(0,0,0,0.2); }
.close-btn { position: absolute; top: 15px; right: 15px; font-size: 24px; cursor: pointer; color: #888; transition: 0.2s; line-height: 1; z-index: 10;}
.close-btn:hover { color: #dc3545; }

.car-row { padding: 10px 0; border-bottom: 1px solid #eee; display: flex; justify-content: space-between; align-items: center;}
.car-row:last-child { border-bottom: none; }
.car-label { color: #6c757d; font-weight: bold; font-size: 0.95rem;}
.car-val { font-weight: bold; color: #333; text-align: right; max-width: 60%; word-break: break-word;}

.edit-input { width: 100%; padding: 8px; margin-bottom: 10px; border: 1px solid #ced4da; border-radius: 4px; box-sizing: border-box; font-family: monospace;}
.action-btn { display: block; width: 100%; padding: 12px; margin-bottom: 10px; border: 1px solid #ced4da; border-radius: 6px; background: #fff; font-weight: bold; cursor: pointer; text-align: center;}
.action-btn.primary { color: #fff; background: #007bff; border-color: #007bff; }

.loading-container { position: absolute; bottom: -8px; left: 0; width: 100%; height: 3px; background: #e9ecef; border-radius: 2px; overflow: hidden; opacity: 0; }
.loading-container.active { opacity: 1; }
.loading-bar { height: 100%; width: 30%; background: #007bff; animation: loadingSlide 1s infinite linear; }
@keyframes loadingSlide { 0% { transform: translateX(-100%); } 100% { transform: translateX(350%); } }

.sort-icon { font-size: 0.9rem; color: #adb5bd; margin-left: 4px; }
.clickable-row { cursor: pointer; transition: background-color 0.2s, opacity 0.2s; }
.clickable-row:hover { background: #fdfdfe; }
.updating-row { opacity: 0.4; pointer-events: none; background: #e9ecef !important; filter: grayscale(80%); }

#global-loader { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(255, 255, 255, 0.85); z-index: 9999; align-items: center; justify-content: center; flex-direction: column; }
#global-loader.active { display: flex; }
.spinner { border: 4px solid #f3f3f3; border-top: 4px solid #007bff; border-radius: 50%; width: 50px; height: 50px; animation: spin 1s linear infinite; margin-bottom: 15px; }
.loader-text { font-size: 1.2rem; font-weight: bold; color: #343a40; }

.column-filter-menu { display: none; position: absolute; background: white; border: 1px solid #ced4da; box-shadow: 0 5px 15px rgba(0,0,0,0.15); border-radius: 8px; z-index: 4000; max-height: 300px; overflow-y: auto; min-width: 180px; padding: 10px; }
.column-filter-menu.show { display: block; }
.filter-option { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; cursor: pointer; font-size: 13px; color: #495057; font-weight: normal; }
.filter-actions { display: flex; justify-content: space-between; margin-bottom: 10px; border-bottom: 1px solid #eee; padding-bottom: 8px; }
.filter-btn { background: none; border: none; color: #007bff; cursor: pointer; font-size: 13px; font-weight: bold; padding: 0; }
.filter-btn:hover { text-decoration: underline; }
.filter-icon { margin-left: 5px; cursor: pointer; color: #adb5bd; transition: color 0.2s; vertical-align: middle; }
.filter-icon:hover { color: #495057; }
.filter-icon.active { color: #007bff; }

.related-shipments-list { max-height: 220px; overflow-y: auto; border: 1px solid #ced4da; padding: 10px; border-radius: 6px; margin: 10px 0; background: #f8f9fa; }
.related-shipment-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid #eee; font-size: 14px; color: #495057; cursor: pointer;}
.related-shipment-item:last-child { border-bottom: none; }
.manual-add-row { display: flex; gap: 8px; margin-top: 10px; }
.manual-add-row input { flex: 1; margin: 0; padding: 8px; border: 1px solid #ced4da; border-radius: 4px; }
.manual-add-row button { background: #6c757d; color: white; border: none; border-radius: 4px; padding: 0 15px; font-weight: bold; cursor: pointer; font-size: 1.2rem;}
.manual-add-row button:hover { background: #5a6268; }

.no-copy { user-select: none; -webkit-user-select: none; }
.hidden { display: none !important; }


/* ======================================================== */
/* ТОЧНАЯ СЕТКА ДАШБОРДА (ДЛЯ ПК)                           */
/* ======================================================== */

#v-dashboards { 
    padding: 0; 
    box-sizing: border-box;
} 

#dash-scale-viewport {
    width: 100%;
    height: 100%;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}
#dash-scale-inner {
    width: 1600px;  
    height: 900px;  
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transform-origin: center center;
}

/* Топбар */
.dash-topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.dash-top-summary { display: flex; gap: 20px; font-size: 14px; font-weight: 600; color: #6c757d; align-items: center;}
.dash-top-summary b { margin-left: 6px; font-size: 16px; color: #212529; }
.dash-trucks-title { font-size: 24px; font-weight: 900; color: #212529; }

.dash-grid-master {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr)); 
    grid-template-rows: 1.3fr 0.7fr 0.7fr 1.3fr; 
    gap: 15px;
    flex: 1; 
    min-height: 0; 
    padding-bottom: 0;
}

.d-col-span-2 { grid-column: span 2; }
.d-col-span-3 { grid-column: span 3; }
.d-row-span-2 { grid-row: span 2; } 

/* Подсетка для EXP1, EXP2, STP */
.exp-stp-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    height: 100%; 
}

/* Карточки */
.dash-grid-master .dash-card {
    background: #ffffff;
    border-radius: 12px;
    padding: 16px 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    display: flex;
    flex-direction: column;
}
.dash-grid-master .card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; border:none; padding:0; }
.dash-grid-master .header-title { font-size: 18px; font-weight: 800; color: #2c3e50; display: flex; align-items: center; gap: 8px; }
.dash-grid-master .time-lbl { font-size: 11px; font-weight: 600; color: #9ca3af; }

/* Таблицы */
.dash-grid-master .min-table { width: 100%; border-collapse: collapse; }
.dash-grid-master .min-table th { font-size: 11px; color: #9ca3af; text-transform: uppercase; font-weight: 700; padding-bottom: 8px; border-bottom: 2px solid #f0f0f0; text-align: center; }
.dash-grid-master .min-table th:first-child { text-align: left; }
.dash-grid-master .min-table td { padding: 8px 0; border-bottom: 1px solid #f8f9fa; font-size: 14px; text-align: center; font-weight: 800; color: #212529;}
.dash-grid-master .min-table td:first-child { text-align: left; font-weight: 600; color: #495057; }
.dash-grid-master .min-table tr:last-child td { border-bottom: none; }
.dash-grid-master .val-plan { color: #6c757d; font-weight: 600; }
.dash-grid-master .val-rem { color: #dc3545; }

/* Консолидация */
.dash-grid-master .cons-numbers-row { display: flex; justify-content: space-between; align-items: flex-end; margin-top: auto; padding-top: 10px; }
.dash-grid-master .cons-num-item { display: flex; flex-direction: column; align-items: center; }
.dash-grid-master .cons-num-item b { font-size: 36px; font-weight: 900; color: #212529; line-height: 1; }
.dash-grid-master .cons-num-item span { font-size: 11px; font-weight: 800; color: #9ca3af; text-transform: uppercase; margin-top: 6px; letter-spacing: 0.5px;}
.dash-grid-master .cons-num-item .strike { text-decoration: line-through; opacity: 0.5; }

/* Контейнер Express */
.dash-grid-master .express-2col-layout { 
    display: grid; 
    grid-template-columns: 1fr 1fr; 
    gap: 20px; 
    margin-top: 10px; 
}

.dash-grid-master .express-col { 
    display: flex; 
    flex-direction: column; 
    gap: 12px;           
    justify-content: flex-start; 
}

.dash-grid-master .express-2col-layout .express-col:first-child {
    justify-content: center;
    gap: 12px; 
}

.dash-card.d-row-span-2 > .express-col {
    margin-top: 10px;
}

.dash-grid-master .express-row { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    font-size: 13px; 
    font-weight: 600; 
    color: #6c757d; 
    text-transform: uppercase; 
    padding-bottom: 5px;
    border-bottom: 1px dashed #f0f0f0; 
}

.dash-grid-master .express-row span:last-child { color: #212529; font-size: 16px; font-weight: 800; }
.dash-grid-master .express-row:last-child { border-bottom: none; }

/* Потери */
.dash-grid-master .losses-grid { display: grid; grid-template-columns: repeat(4, 1fr); align-items: center; height: 100%; gap: 10px; text-align: center;}
.dash-grid-master .loss-item { display: flex; flex-direction: column; align-items: center; }
.dash-grid-master .loss-item b { font-size: 34px; font-weight: 900; line-height: 1; margin-bottom: 5px; color: #dc3545; }
.dash-grid-master .loss-item span { font-size: 11px; font-weight: 800; color: #212529; text-transform: uppercase; }

/* Отгрузки */
.dash-grid-master .waves-table { width: 100%; border-collapse: collapse; font-size: 13px; text-align: center; }
.dash-grid-master .waves-table th { padding: 6px; color: #6c757d; font-weight: 600; border-bottom: 2px solid #f0f0f0; }
.dash-grid-master .waves-table td { padding: 8px 6px; font-weight: 700; color: #212529; border-bottom: 1px solid #f8f9fa; }
.dash-grid-master .wave-row-label { text-align: left; color: #6c757d !important; font-weight: 600 !important; text-transform: lowercase; }

/* ========================================================= */
/* ИДЕАЛЬНАЯ МОБИЛЬНАЯ ВЕРСИЯ (ЕДИНЫЙ БЛОК БЕЗ КОНФЛИКТОВ)   */
/* ========================================================= */

@media (max-width: 900px) {
    /* 1. НА МОБИЛЬНОМ ПОКАЗЫВАЕМ мобильную шапку и нижнюю навигацию.
       Десктопный сайдбар и верхнюю панель управления таблиц — прячем. */
    .mobile-topbar {
        display: flex !important;
    }
    .mobile-bottom-nav {
        display: flex !important;
    }
    .sidebar,
    .top-controls,
    .nav-tabs,
    .menu-container,
    .header {
        display: none !important;
    }
    .mobile-overlay.show {
        display: block !important;
    }

    /* 2. РАЗБЛОКИРУЕМ ПРОКРУТКУ, УБИРАЕМ ПУСТОТЫ */
    html, body {
        overflow-y: auto !important;
        overflow-x: hidden !important;
        height: auto !important;
        min-height: 100vh !important;
        background: var(--bg-app) !important;
    }

    /* 3. КОНТЕЙНЕР ДАШБОРДА НА ВЕСЬ ЭКРАН */
    .main-wrapper {
        margin: 0 !important;
        padding: 10px !important; /* Легкие отступы от краев телефона */
        width: 100% !important;
        height: auto !important;
        min-height: 100vh !important;
        overflow: visible !important;
        box-sizing: border-box !important;
    }

    /* 4. ВЫКЛЮЧАЕМ ЛОМАЮЩИЕ ВЫСОТЫ СЕКЦИЙ */
    .view-section {
        height: auto !important;
    }
    /* Скрытые на мобильном разделы полностью исключаются из расчёта layout/paint
       браузером (content-visibility). Там много крупных таблиц с данными,
       которые на телефоне не видны, но раньше всё равно отрисовывались в фоне
       и замедляли первую загрузку страницы. */
    .view-section:not(#v-dashboards) {
        display: none !important; /* Прячем все кроме дашборда */
        content-visibility: hidden !important;
    }
    #v-dashboards, #v-dashboards.active {
        display: block !important;
        height: auto !important;
        padding: 0 !important;
    }

    /* 5. УБИВАЕМ ЦЕНТРИРОВАНИЕ И МАСШТАБ (ИМЕННО ЭТО ВЫЗЫВАЛО ПУСТОТЫ!) */
    #dash-scale-viewport {
        display: block !important; /* Было flex с align-items: center */
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
    }
    #dash-scale-inner {
        display: block !important; /* Было flex с высотой 900px */
        width: 100% !important;
        height: auto !important;
        transform: none !important;
        transform-origin: initial !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* 6. ПЕРЕВОДИМ СЕТКУ КАРТОЧЕК В ВЕРТИКАЛЬНЫЙ СТОЛБЕЦ */
    .dash-grid-master {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
        height: auto !important;
        padding: 0 !important;
        padding-bottom: 20px !important;
    }

    /* 7. ВНУТРЕННИЕ ПОДСЕТКИ ДЕЛАЕМ УДОБНЫМИ */
    .exp-stp-row, .express-2col-layout {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
        height: auto !important;
    }
    .cons-numbers-row, .losses-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important; /* По 2 цифры в ряд */
        gap: 15px !important;
        height: auto !important;
        margin-top: 10px !important;
    }

    /* 8. САМИ КАРТОЧКИ - НА ВСЮ ШИРИНУ ТЕЛЕФОНА */
    .dash-grid-master .dash-card {
        width: 100% !important;
        height: auto !important;
        padding: 15px !important;
        box-sizing: border-box !important;
        margin: 0 !important;
        border: 1px solid #e5e7eb !important;
    }
    .dash-grid-master > .dash-card:nth-child(7) { display: none !important; } /* Скрываем пустые блоки, если есть */

    /* 9. ФИКС ТАБЛИЦ - СКРОЛЛ ТОЛЬКО ВНУТРИ НИХ */
    .min-table, .waves-table {
        display: block !important;
        width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* 10. ТОПБАР - СТОЛБИКОМ */
    .dash-topbar {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
        align-items: stretch !important;
        margin-bottom: 15px !important;
    }
    .dash-trucks-title { text-align: left !important; font-size: 18px !important; }
}
