/**
 * 🎛️ BUSINESS1 LAYOUT SYSTEM v2.0
 * Центральная система управления layout'ом для исключения конфликтов
 * Все размеры, отступы, z-index в одном месте
 */

/* ===== LAYOUT CORE VARIABLES ===== */
:root {
    /* 📏 ОСНОВНЫЕ РАЗМЕРЫ */
    --layout-header-height: 60px;
    --layout-sidebar-width-desktop: 280px;
    --layout-sidebar-width-mobile: 240px;
    --layout-sidebar-width-compact: 64px;
    
    /* 📱 RESPONSIVE BREAKPOINTS */
    --layout-breakpoint-desktop: 1024px;
    --layout-breakpoint-tablet: 768px;
    --layout-breakpoint-mobile: 480px;
    
    /* 🎚️ Z-INDEX LAYERS (централизованная система) */
    --z-header: 1000;
    --z-sidebar: 999;
    --z-dropdown: 1001;
    --z-modal-backdrop: 1050;
    --z-modal-content: 1051;
    --z-tooltip: 1070;
    --z-notification: 1080;
    --z-loading-overlay: 9999;
    
    /* 🎨 LAYOUT SPACING SYSTEM */
    --layout-padding-desktop: 1.5rem;
    --layout-padding-mobile: 1rem;
    --layout-gap-small: 0.75rem;
    --layout-gap-medium: 1rem;
    --layout-gap-large: 1.5rem;
    
    /* 📐 COMPUTED VALUES - автоматические расчеты */
    --layout-content-margin-desktop: var(--layout-sidebar-width-desktop);
    --layout-content-margin-mobile: var(--layout-sidebar-width-mobile);
    --layout-content-top: var(--layout-header-height);
    --layout-sidebar-top: var(--layout-header-height);
}

/* ===== GLOBAL LAYOUT FOUNDATION ===== */

/* 🏗️ Основные layout контейнеры */
#main-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--layout-header-height);
    z-index: var(--z-header);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
}

/* 🎨 Базовые стили для header content */
#main-header .header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1.5rem;
    height: 100%;
}

#main-header h1 {
    color: var(--text-primary);
    margin: 0;
}

#main-header .header-stats {
    color: var(--text-secondary);
}

#sidebar {
    position: fixed;
    top: var(--layout-sidebar-top);
    left: 0;
    width: var(--layout-sidebar-width-desktop);
    height: calc(100vh - var(--layout-header-height));
    z-index: var(--z-sidebar);
    overflow-y: auto;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* 🎨 БАЗОВЫЕ СТИЛИ - нужны для работы sidebar-premium.css */
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-light);
}

/* 🧭 Базовые стили для навигации sidebar */
#sidebar .nav-menu {
    list-style: none;
    margin: 0;
    padding: 0;
}

#sidebar .nav-link {
    display: block;
    text-decoration: none;
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    transition: all 0.3s ease;
}

#sidebar .nav-link:hover {
    background: rgba(255, 255, 255, 0.05);
}

#main-content {
    margin-left: var(--layout-content-margin-desktop);
    margin-top: var(--layout-content-top);
    min-height: calc(100vh - var(--layout-header-height));
    padding: 0; /* Убираем огромный padding - модули сами управляют отступами */
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#content-area {
    width: 100%;
    min-height: 400px;
    background: var(--bg-primary);
    border-radius: 8px;
    padding: 0; /* Убираем padding - модули сами управляют */
    margin: 0; /* Убираем margin */
}

/* ===== RESPONSIVE LAYOUT SYSTEM ===== */

/* 📱 TABLET/MOBILE LAYOUT (≤1024px) */
@media (max-width: 1024px) {
    #sidebar {
        width: var(--layout-sidebar-width-mobile);
    }
    
    #main-content {
        margin-left: var(--layout-content-margin-mobile);
        padding: 0; /* Убираем padding */
    }
}

/* 📱 MOBILE COMPACT (≤768px) */
@media (max-width: 768px) {
    #main-content {
        padding: 0; /* Убираем padding */
    }
}

/* ===== LOADING & MODAL OVERLAYS ===== */

/* 🔄 Loading overlay с правильным z-index */
#loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-primary);
    padding: var(--layout-gap-large);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    z-index: var(--z-loading-overlay);
    display: none;
}

/* 🗂️ Modal system */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal-backdrop);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    z-index: var(--z-modal-content);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal.active .modal-content {
    transform: scale(1);
}

/* ===== UTILITY CLASSES ===== */

/* 📐 Layout utilities */
.layout-full-width {
    width: 100%;
}

.layout-center {
    max-width: 1400px;
    margin: 0 auto;
}

.layout-no-sidebar {
    margin-left: 0 !important;
}

.layout-compact-sidebar #sidebar {
    width: var(--layout-sidebar-width-compact);
}

.layout-compact-sidebar #main-content {
    margin-left: var(--layout-sidebar-width-compact);
}

/* 🎯 Focus management */
.layout-sidebar-hidden #sidebar {
    transform: translateX(-100%);
}

.layout-sidebar-hidden #main-content {
    margin-left: 0;
}

/* ===== DEBUG MODE ===== */
.layout-debug * {
    outline: 1px solid rgba(255, 0, 0, 0.2);
}

.layout-debug #sidebar {
    background: rgba(0, 255, 0, 0.1);
}

.layout-debug #main-content {
    background: rgba(0, 0, 255, 0.1);
}

/* ===== ANIMATIONS ===== */
@keyframes slideInFromLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

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

.layout-animate-in {
    animation: fadeIn 0.3s ease-out;
}

.layout-slide-in {
    animation: slideInFromLeft 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
