/* ============================================
   TAILORD — Макет и сетка
   Шапка, сайдбар, основной контент
   ============================================ */

/* ============================================
   КОНТЕЙНЕР
   ============================================ */
.container {
    display: flex;
    min-height: calc(100vh - var(--header-height));
    margin-top: var(--header-height);
}

/* ============================================
   ШАПКА (HEADER)
   ============================================ */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--white);
    border-bottom: 1px solid var(--gray-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    z-index: 1000;
    box-shadow: var(--shadow);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Логотип */
.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--main-color);
}

.logo-icon {
    font-size: 2rem;
}

.logo-text {
    color: var(--main-color);
}

/* Информация о пользователе */
.user-info {
    color: var(--gray-dark);
    font-size: var(--font-size-sm);
}

/* ============================================
   БОКОВОЕ МЕНЮ (SIDEBAR)
   ============================================ */
.sidebar {
    position: fixed;
    left: 0;
    top: var(--header-height);
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    background: var(--main-color);
    padding: 1.5rem 0;
    overflow-y: auto;
    z-index: 999;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.5rem;
    color: var(--white);
    text-decoration: none;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--second-color);
}

.nav-item.active {
    background: rgba(255, 174, 66, 0.15);
    color: var(--second-color);
    border-left-color: var(--second-color);
}

.nav-icon {
    font-size: 1.25rem;
    width: 1.5rem;
    text-align: center;
}

.nav-text {
    font-size: var(--font-size-sm);
    font-weight: 500;
}

/* ============================================
   ОСНОВНОЙ КОНТЕНТ (MAIN)
   ============================================ */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 2rem;
    background: var(--white);
    min-height: calc(100vh - var(--header-height));
}

/* Заголовок страницы */
.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: var(--font-size-2xl);
    margin-bottom: 0.5rem;
}

.page-header .subtitle {
    color: var(--gray-medium);
    font-size: var(--font-size-base);
    margin: 0;
}

/* ============================================
   КАРТОЧКИ СТАТИСТИКИ (STATS GRID)
   ============================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--white);
    border: 1px solid var(--gray-light);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    font-size: 2.5rem;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-light);
    border-radius: var(--border-radius);
}

.stat-info {
    flex: 1;
}

.stat-value {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    color: var(--main-color);
    line-height: 1.2;
}

.stat-label {
    font-size: var(--font-size-sm);
    color: var(--gray-medium);
    margin-top: 0.25rem;
}

/* ============================================
   СЕКЦИИ КОНТЕНТА
   ============================================ */
.content-section {
    background: var(--white);
    border: 1px solid var(--gray-light);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.section-header h2 {
    font-size: var(--font-size-lg);
    margin: 0;
}

.btn-link {
    color: var(--second-color);
    font-size: var(--font-size-sm);
    font-weight: 500;
    transition: color 0.2s ease;
}

.btn-link:hover {
    color: var(--main-color);
}

/* ============================================
   ТАБЛИЦЫ (КОНТЕЙНЕР)
   ============================================ */
.table-container {
    overflow-x: auto;
    border: 1px solid var(--gray-light);
    border-radius: var(--border-radius);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    background: var(--gray-light);
    color: var(--gray-dark);
    font-weight: 600;
    text-transform: uppercase;
    font-size: var(--font-size-xs);
    letter-spacing: 0.05em;
    padding: 1rem;
    border-bottom: 2px solid var(--gray-dark);
    text-align: center;
}

.data-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--gray-light);
    color: var(--main-color);
    text-align: center;
}

.data-table tbody tr:hover {
    background: var(--gray-light);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* ============================================
   АДАПТИВНОСТЬ (БАЗОВАЯ)
   ============================================ */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .header {
        padding: 0 1rem;
    }
    
    .main-content {
        padding: 1rem;
    }
    
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
}

/* ============================================
   МОБИЛЬНОЕ МЕНЮ (БУРГЕР)
   ============================================ */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--main-color);
}

@media (max-width: 768px) {
    .menu-toggle {
        display: block;
    }
}

/* ============================================
   OVERLAY (ЗАТЕМНЕНИЕ ФОНА)
   ============================================ */
.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(38, 37, 45, 0.5);
    z-index: 998;
}

.overlay.active {
    display: block;
}

/* ============================================
   ЭКРАН ВХОДА (LOGIN SCREEN)
   ============================================ */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--gray-light) 0%, var(--white) 100%);
}

.login-screen.hidden {
    display: none !important;
}

.login-card {
    background: var(--white);
    padding: 2.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
}

.login-card .logo {
    justify-content: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--gray-light);
}

.login-card h2 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--main-color);
}

/* ============================================
   КОНТЕНТ ПРИЛОЖЕНИЯ (APP CONTENT)
   ============================================ */
#appContent.hidden {
    display: none !important;
}

/* ============================================
   ПАНЕЛЬ ПОЛЬЗОВАТЕЛЯ В ШАПКЕ
   ============================================ */
.user-panel {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-right: 1rem;
}

.user-login {
    font-weight: 600;
    color: var(--main-color);
    font-size: var(--font-size-sm);
}

.user-role {
    font-size: var(--font-size-xs);
    color: var(--gray-medium);
    background: var(--gray-light);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

/* layout.css (добавить в конец файла) */

/* ============================================
   АДАПТАЦИЯ ПОД МОБИЛЬНЫЕ УСТРОЙСТВА
   ============================================ */

@media (max-width: 768px) {
    /* --- ШАПКА (HEADER) --- */
    .header {
        padding: 0 1rem; /* Уменьшаем боковые отступы */
        height: var(--header-height, 60px); /* Используем переменную или значение по умолчанию */
    }

    .header-left {
        gap: 1rem; /* Уменьшаем расстояние */
    }

    .logo-icon {
        font-size: 1.75rem; /* Уменьшаем иконку */
    }

    .logo-text {
        font-size: 1.2rem; /* Уменьшаем текст логотипа */
    }

    /* Прячем часть информации о пользователе, оставляем только логин или иконку */
    .user-info {
        display: none;
    }
    .user-panel .user-role {
        display: none;
    }
    .user-panel .user-login {
        font-size: 0.9rem;
    }

    /* --- БОКОВОЕ МЕНЮ (SIDEBAR) --- */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        width: 80%; /* Сайдбар занимает 80% экрана */
        max-width: 300px; /* Но не больше 300px */
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        z-index: 1001; /* Выше, чем overlay */
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .nav-item {
        padding: 0.875rem 1rem; /* Уменьшаем паддинг */
    }

    /* --- ОСНОВНОЙ КОНТЕНТ (MAIN) --- */
    .main-content {
        margin-left: 0; /* Убираем отступ под сайдбар */
        padding: 1.5rem 1rem; /* Уменьшаем паддинг */
        width: 100%;
    }

    /* --- КАРТОЧКИ СТАТИСТИКИ (STATS GRID) --- */
    .stats-grid {
        grid-template-columns: 1fr; /* Одна колонка */
        gap: 1rem;
    }

    .stat-card {
        padding: 1rem; /* Уменьшаем внутренние отступы */
    }

    .stat-icon {
        width: 50px;
        height: 50px;
        font-size: 2rem;
    }

    .stat-value {
        font-size: var(--font-size-xl); /* Используем переменную */
    }

    /* --- СЕКЦИИ КОНТЕНТА --- */
    .content-section {
        padding: 1rem; /* Уменьшаем отступы */
        margin-bottom: 1.5rem;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    /* --- ТАБЛИЦЫ (КОНТЕЙНЕР) --- */
    .table-container {
        /* Убираем фиксированную ширину, добавляем скролл */
        overflow-x: auto;
        -webkit-overflow-scrolling: touch; /* Плавный скролл на iOS */
    }

    .data-table th,
    .data-table td {
        padding: 0.75rem 0.5rem; /* Уменьшаем паддинг в ячейках */
        font-size: 0.9rem; /* Немного уменьшаем шрифт */
        white-space: nowrap; /* Запрещаем перенос строк, чтобы включился горизонтальный скролл */
    }

    /* --- МОБИЛЬНОЕ МЕНЮ (БУРГЕР) --- */
    .menu-toggle {
        display: block; /* Показываем кнопку бургера */
        order: -1; /* Можно переместить в начало */
    }

    /* --- OVERLAY (ЗАТЕМНЕНИЕ ФОНА) --- */
    .overlay.active {
        display: block;
        z-index: 1000;
    }

    /* --- ЭКРАН ВХОДА (LOGIN SCREEN) --- */
    .login-card {
        padding: 1.5rem;
        max-width: 90%; /* Карточка занимает 90% ширины */
    }
}

/* --- Стили для горизонтальной ориентации телефонов и маленьких планшетов --- */
@media (min-width: 769px) and (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr); /* Две колонки */
    }

    .main-content {
        padding: 2rem 1.5rem;
    }

    /* Сайдбар показываем как обычно, если нужно его скрывать на планшетах, добавьте аналогичную логику с бургером */
}

/* ============================================
   МОБИЛЬНАЯ КНОПКА МЕНЮ (бургер)
   ============================================ */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--main-color);
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius);
    transition: background-color 0.2s ease;
    margin-right: 8px;
}

.menu-toggle:hover {
    background-color: var(--gray-light);
}

.menu-toggle:focus {
    outline: 2px solid var(--second-color);
    outline-offset: 2px;
}

.menu-toggle-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.menu-toggle-icon {
    display: block;
    width: 24px;
    height: 18px;
    position: relative;
}

.menu-toggle-icon span,
.menu-toggle-icon::before,
.menu-toggle-icon::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 2px;
    background-color: var(--main-color);
    left: 0;
    transition: transform 0.3s ease, top 0.3s ease, opacity 0.3s ease;
}

.menu-toggle-icon span {
    top: 8px;
}

.menu-toggle-icon::before {
    top: 0;
}

.menu-toggle-icon::after {
    top: 16px;
}

.menu-toggle.active .menu-toggle-icon span {
    opacity: 0;
}

.menu-toggle.active .menu-toggle-icon::before {
    transform: rotate(45deg);
    top: 8px;
}

.menu-toggle.active .menu-toggle-icon::after {
    transform: rotate(-45deg);
    top: 8px;
}

/* ============================================
   OVERLAY ДЛЯ МОБИЛЬНОГО МЕНЮ
   ============================================ */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(38, 37, 45, 0.6);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* ============================================
   МОБИЛЬНАЯ АДАПТАЦИЯ (до 1024px)
   ============================================ */
@media (max-width: 1024px) {
    /* Кнопка меню */
    .menu-toggle {
        display: flex;
    }

    /* Шапка */
    .header-left {
        display: flex;
        align-items: center;
    }

    .header-left .logo {
        margin-left: 0;
    }

    .header-left .logo-text {
        font-size: 1.1rem;
    }

    .header-right {
        gap: 0.5rem;
    }

    .user-panel {
        margin-right: 0;
    }

    .user-login {
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .user-role {
        display: none;
    }

    /* Сайдбар */
    .sidebar {
        position: fixed;
        left: 0;
        top: var(--header-height);
        width: 85%;
        max-width: 320px;
        height: calc(100vh - var(--header-height));
        background: var(--main-color);
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
        z-index: 999;
        overflow-y: auto;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Пункты меню */
    .nav-item {
        padding: 1rem 1.25rem;
        min-height: 48px;
    }

    .nav-dropdown-content {
        padding-left: 2.5rem;
    }

    .nav-subitem {
        padding: 0.75rem 1rem;
        margin: 0.25rem 0;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .nav-dropdown-toggle {
        min-height: 48px;
        display: flex;
        align-items: center;
    }

    /* Основной контент */
    .main-content {
        padding: 1rem;
    }
}

/* ============================================
   ГОРИЗОНТАЛЬНАЯ ОРИЕНТАЦИЯ (для телефонов)
   ============================================ */
@media (max-width: 1024px) and (orientation: landscape) {
    .sidebar {
        width: 60%;
        max-width: 380px;
    }

    .nav-item {
        padding: 0.75rem 1rem;
    }

    .nav-dropdown-content {
        max-height: 300px;
        overflow-y: auto;
    }

    .user-role {
        display: inline-block;
    }

    .user-login {
        max-width: 150px;
    }
}

/* ============================================
   ПЛАНШЕТЫ (вертикальная ориентация)
   ============================================ */
@media (min-width: 769px) and (max-width: 1024px) and (orientation: portrait) {
    .sidebar {
        width: 70%;
        max-width: 350px;
    }

    .main-content {
        padding: 1.5rem;
    }
}

/* ============================================
   ДЕСКТОП (больше 1024px)
   ============================================ */
@media (min-width: 1025px) {
    .menu-toggle {
        display: none !important;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: var(--header-height);
        width: var(--sidebar-width);
        height: calc(100vh - var(--header-height));
        transform: none !important;
        box-shadow: none;
    }

    .sidebar-overlay {
        display: none !important;
    }

    .user-login {
        max-width: 200px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .user-role {
        display: inline-block;
    }
}

/* ============================================
   ОЧЕНЬ МАЛЕНЬКИЕ ТЕЛЕФОНЫ (до 375px)
   ============================================ */
@media (max-width: 375px) {
    .sidebar {
        width: 90%;
        max-width: 280px;
    }

    .header-left .logo-text {
        font-size: 1rem;
    }

    .user-login {
        max-width: 80px;
        font-size: 0.9rem;
    }

    .btn-sm {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }
}