/* ===== НОВАЯ LAYOUT-АРХИТЕКТУРА ===== */
/* Левая панель со слоями (как в VSCode/Perplexity) */

:root {
    --sidebar-layers-width: 60px;      /* Узкая левая панель со слоями */
    --sidebar-agents-width: 280px;     /* Боковая панель для выбора агентов */
    --breakpoint-mobile: 768px;
    --breakpoint-tablet: 1024px;
}

/* ===== DESKTOP LAYOUT (1025px и выше) ===== */
@media (min-width: 1025px) {
    .container {
        display: grid;
        grid-template-columns: 
            var(--sidebar-layers-width)  /* Левая панель слоёв */
            1fr                          /* Основной контент */
            var(--sidebar-agents-width); /* Боковая панель агентов (открыта на десктопе) */
        grid-template-rows: 1fr auto;
        gap: 0;
        height: 85vh;
    }

    /* Левая панель слоёв */
    .sidebar-layers {
        grid-column: 1;
        grid-row: 1 / 3;
        display: flex;
        flex-direction: column;
        background: #f8f9fa;
        border-right: 1px solid #e9ecef;
        padding: 12px 0;
        overflow-y: auto;
        z-index: 20;
    }

    /* Основной контент */
    .main {
        grid-column: 2;
        grid-row: 1 / 3;
        display: flex;
        flex-direction: column;
    }

    /* Боковая панель агентов (всегда видна на десктопе) */
    .sidebar-agents {
        grid-column: 3;
        grid-row: 1 / 3;
        display: flex !important;
        flex-direction: column;
        background: #f8f9fa;
        border-left: 1px solid #e9ecef;
        padding: 20px;
        overflow-y: auto;
        z-index: 20;
    }

    /* Input area внизу (если нужна) */
    .sidebar-agents-footer {
        grid-column: 3;
        grid-row: 2;
        padding: 16px 20px;
        border-top: 1px solid #e9ecef;
        background: #f8f9fa;
    }

    /* Мобильные элементы скрыты */
    .mobile-header,
    .mobile-tabs,
    .overlay {
        display: none !important;
    }

    /* Chat area занимает все доступное пространство */
    .chat-area {
        padding: 20px;
    }

    /* Input area стандартная */
    .input-area {
        border-top: 1px solid #e9ecef;
    }
}

/* ===== TABLET LAYOUT (769px - 1024px) ===== */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        display: flex;
        flex-direction: column;
        height: 100vh;
        border-radius: 0;
        padding: 0;
        margin: 0;
    }

    /* Header наверху */
    .mobile-header {
        display: flex !important;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 60px;
        z-index: 100;
    }

    /* Скрыть mobile-tabs (легаси) */
    .mobile-tabs {
        display: none !important;
    }

    /* Левая узкая панель слоёв (вертикально) */
    .sidebar-layers {
        position: fixed;
        left: 0;
        top: 60px;
        width: 60px;
        height: calc(100vh - 60px);
        display: flex;
        flex-direction: column;
        background: #f8f9fa;
        border-right: 1px solid #e9ecef;
        padding: 12px 0;
        overflow-y: auto;
        z-index: 99;
    }

    /* Основной контент (под header, справа от sidebar-layers) */
    .main {
        flex: 1;
        display: flex;
        flex-direction: column;
        margin-top: 60px;
        margin-left: 60px;
        margin-bottom: 0;
        overflow-y: auto;
    }

    /* Боковая панель агентов как drawer (слева) */
    .sidebar-agents {
        position: fixed;
        left: -280px;
        top: 60px;
        width: 280px;
        height: calc(100vh - 60px);
        background: #f8f9fa;
        border-right: 1px solid #e9ecef;
        padding: 20px;
        overflow-y: auto;
        z-index: 200;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        display: flex;
        flex-direction: column;
    }

    .sidebar-agents.open {
        left: 0;
    }

    .sidebar-agents.hidden {
        display: none !important;
    }

    /* Overlay */
    .overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
        z-index: 150;
        pointer-events: none;
    }

    .overlay.visible {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    /* Input area */
    .input-area {
        border-top: 1px solid #e9ecef;
        flex-shrink: 0;
    }
}


/* ===== MOBILE LAYOUT (до 768px) ===== */
@media (max-width: 768px) {
    .container {
        display: flex;
        flex-direction: column;
        height: 100dvh;
        border-radius: 0;
        padding: 0;
        margin: 0;
    }

    body {
        padding: 0;
        margin: 0;
    }

    /* Header наверху */
    .mobile-header {
        display: flex !important;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 60px;
        z-index: 100;
        background: #fff;
        border-bottom: 1px solid #e9ecef;
    }

    /* Скрыть mobile-tabs (легаси) */
    .mobile-tabs {
        display: none !important;
    }

    /* Левая узкая панель слоёв (вертикально) */
    .sidebar-layers {
        position: fixed;
        left: 0;
        top: 60px;
        width: 60px;
        height: calc(100vh - 60px);
        display: flex;
        flex-direction: column;
        background: #f8f9fa;
        border-right: 1px solid #e9ecef;
        padding: 12px 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        z-index: 99;
    }

    /* Основной контент (под header, справа от sidebar-layers) */
    .main {
        flex: 1;
        display: flex;
        flex-direction: column;
        margin-top: 60px;
        margin-left: 60px;
        margin-bottom: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Input area */
    .input-area {
        flex-shrink: 0;
        border-top: 1px solid #e9ecef;
    }

    /* Боковая панель агентов как drawer (слева) */
    .sidebar-agents {
        position: fixed;
        left: -280px;
        top: 60px;
        width: 280px;
        height: calc(100vh - 60px);
        background: #f8f9fa;
        border-right: 1px solid #e9ecef;
        padding: 20px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        z-index: 200;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        display: flex;
        flex-direction: column;
    }

    .sidebar-agents.open {
        left: 0;
    }

    .sidebar-agents.hidden {
        display: none !important;
    }

    /* Overlay */
    .overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
        z-index: 150;
        pointer-events: none;
    }

    .overlay.visible {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    /* Chat area */
    .chat-area {
        padding: 16px;
    }
}

    }
}

/* ===== MOBILE LANDSCAPE (max-width: 768px and landscape) ===== */
@media (max-width: 768px) and (orientation: landscape) {
    .container {
        height: 100dvh;
    }

    .mobile-header {
        height: 50px;
    }

    .sidebar-layers {
        top: 50px;
        height: 40px;
    }

    .main {
        margin-top: 90px;  /* 50px header + 40px tabs */
    }

    .sidebar-agents {
        max-height: 50vh; /* Меньше на альбомной ориентации */
    }

    .chat-area {
        padding: 12px;
    }

    .input-area {
        padding: 8px;
    }
}

/* ===== LAYER ITEMS STYLING (слои в левой панели) ===== */

.layer-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    padding: 8px;
    cursor: pointer;
    color: #999;
    background: transparent;
    border: none;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
    position: relative;
    font-size: 0;
}

.layer-item:hover {
    background: rgba(102, 126, 234, 0.08);
    color: #667eea;
}

.layer-item.active {
    background: rgba(102, 126, 234, 0.15);
    color: #764ba2;
    border-left-color: #764ba2;
}

.layer-icon {
    font-size: 24px;
    display: block;
    margin-bottom: 4px;
    line-height: 1;
}

.layer-item-label {
    font-size: 10px;
    text-align: center;
    max-width: 50px;
    word-break: break-word;
    opacity: 0.8;
}

/* На мобилке и планшете — горизонтальный layout */
@media (max-width: 1024px) {
    .layer-item {
        width: auto;
        height: 50px;
        flex-direction: row;
        padding: 12px 16px;
        border-left: none;
        border-bottom: 3px solid transparent;
        gap: 6px;
    }

    .layer-item:hover {
        background: rgba(102, 126, 234, 0.1);
    }

    .layer-item.active {
        background: rgba(102, 126, 234, 0.15);
        border-left: none;
        border-bottom-color: #764ba2;
    }

    .layer-icon {
        margin-bottom: 0;
        font-size: 20px;
    }

    .layer-item-label {
        font-size: 12px;
        display: block;
        opacity: 1;
    }
}

