/* =============================================================================
   RESPONSIVE 3-ZONE LAYOUT SYSTEM
   Sidebar | Center Content | AI Panel
   ============================================================================= */

/* =============================================================================
   LAYOUT VARIABLES
   ============================================================================= */

:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 0px;
    --ai-panel-width: 360px;
    --ai-panel-collapsed-width: 0px;
    --header-height: 64px;
    --layout-transition: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* =============================================================================
   MAIN LAYOUT CONTAINER
   ============================================================================= */

.app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* =============================================================================
   HEADER
   ============================================================================= */

.app-header {
    height: var(--header-height);
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-6);
    position: relative;
    z-index: var(--z-sticky);
    transition: all var(--transition-base);
}

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

.header-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.logo {
    font-size: var(--text-xl);
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
}

/* Theme Switcher */
.theme-switcher {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background-color: var(--bg-tertiary);
    border-radius: var(--radius-full);
    padding: var(--space-1);
}

.theme-switcher button {
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-full);
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
}

.theme-switcher button.active {
    background-color: var(--primary);
    color: white;
}

.theme-switcher button:hover:not(.active) {
    color: var(--text-primary);
}

/* =============================================================================
   BODY LAYOUT (3 ZONES)
   ============================================================================= */

.app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* =============================================================================
   SIDEBAR (LEFT)
   ============================================================================= */

.app-sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: all var(--layout-transition);
    position: relative;
    z-index: var(--z-fixed);
}

.app-sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
    border-right: none;
}

.sidebar-header {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: var(--text-sm);
    font-weight: 500;
}

.sidebar-nav-item:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.sidebar-nav-item.active {
    background-color: var(--primary);
    color: white;
}

.sidebar-nav-icon {
    font-size: var(--text-lg);
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-toggle {
    position: absolute;
    top: 50%;
    right: -12px;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    border-radius: var(--radius-full);
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    z-index: 10;
}

.sidebar-toggle:hover {
    background-color: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* =============================================================================
   CENTER CONTENT
   ============================================================================= */

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--bg-main);
    transition: all var(--layout-transition);
}

.main-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-6);
}

/* Content Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.container-fluid {
    width: 100%;
    padding: 0 var(--space-6);
}

/* =============================================================================
   AI PANEL (RIGHT)
   ============================================================================= */

.ai-panel {
    width: var(--ai-panel-width);
    background-color: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: all var(--layout-transition);
    position: relative;
    z-index: var(--z-fixed);
}

.ai-panel.collapsed {
    width: var(--ai-panel-collapsed-width);
    border-left: none;
}

.ai-panel-header {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ai-panel-title {
    font-size: var(--text-lg);
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.ai-panel-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.ai-toggle {
    position: absolute;
    top: 50%;
    left: -12px;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    border-radius: var(--radius-full);
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    z-index: 10;
}

.ai-toggle:hover {
    background-color: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* =============================================================================
   GRID SYSTEMS
   ============================================================================= */

.grid {
    display: grid;
    gap: var(--space-6);
}

.grid-cols-1 {
    grid-template-columns: repeat(1, minmax(0, 1fr));
}

.grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-cols-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* =============================================================================
   RESPONSIVE BREAKPOINTS
   ============================================================================= */

/* Tablet (768px - 1024px) */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 220px;
        --ai-panel-width: 320px;
    }

    .grid-cols-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .grid-cols-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .main-content {
        padding: var(--space-4);
    }
}

/* Mobile (< 768px) */
@media (max-width: 768px) {
    :root {
        --header-height: 56px;
    }

    .app-header {
        padding: 0 var(--space-4);
    }

    .header-center {
        display: none;
    }

    /* Sidebar becomes overlay on mobile */
    .app-sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: 0;
        z-index: var(--z-modal);
        box-shadow: var(--shadow-xl);
    }

    .app-sidebar.collapsed {
        transform: translateX(-100%);
    }

    .app-sidebar:not(.collapsed) {
        transform: translateX(0);
    }

    /* AI Panel becomes overlay on mobile */
    .ai-panel {
        position: fixed;
        top: var(--header-height);
        right: 0;
        bottom: 0;
        z-index: var(--z-modal);
        box-shadow: var(--shadow-xl);
    }

    .ai-panel.collapsed {
        transform: translateX(100%);
    }

    .ai-panel:not(.collapsed) {
        transform: translateX(0);
    }

    /* Main content takes full width on mobile */
    .app-main {
        width: 100%;
    }

    .main-content {
        padding: var(--space-3);
    }

    /* Grid adjustments */
    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4 {
        grid-template-columns: repeat(1, minmax(0, 1fr));
    }

    /* Backdrop for overlays */
    .overlay-backdrop {
        position: fixed;
        top: var(--header-height);
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: calc(var(--z-modal) - 1);
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--transition-base);
    }

    .overlay-backdrop.active {
        opacity: 1;
        pointer-events: all;
    }
}

/* Small Mobile (< 480px) */
@media (max-width: 480px) {
    .app-sidebar {
        width: 280px;
    }

    .ai-panel {
        width: 100%;
    }

    .main-content {
        padding: var(--space-2);
    }

    .logo {
        font-size: var(--text-lg);
    }
}

/* =============================================================================
   SECTION LAYOUTS
   ============================================================================= */

.section {
    margin-bottom: var(--space-8);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-6);
}

.section-title {
    font-size: var(--text-2xl);
    font-weight: 700;
    color: var(--text-primary);
}

.section-subtitle {
    font-size: var(--text-sm);
    color: var(--text-muted);
    margin-top: var(--space-2);
}

/* =============================================================================
   UTILITIES FOR LAYOUT
   ============================================================================= */

.w-full {
    width: 100%;
}

.h-full {
    height: 100%;
}

.min-h-screen {
    min-height: 100vh;
}

.relative {
    position: relative;
}

.absolute {
    position: absolute;
}

.fixed {
    position: fixed;
}

.sticky {
    position: sticky;
}

.top-0 {
    top: 0;
}

.right-0 {
    right: 0;
}

.bottom-0 {
    bottom: 0;
}

.left-0 {
    left: 0;
}

.z-10 {
    z-index: 10;
}

.z-20 {
    z-index: 20;
}

.z-30 {
    z-index: 30;
}

.z-40 {
    z-index: 40;
}

.z-50 {
    z-index: 50;
}

.flex-1 {
    flex: 1;
}

.flex-shrink-0 {
    flex-shrink: 0;
}

.flex-wrap {
    flex-wrap: wrap;
}

.space-y-2>*+* {
    margin-top: var(--space-2);
}

.space-y-3>*+* {
    margin-top: var(--space-3);
}

.space-y-4>*+* {
    margin-top: var(--space-4);
}

.space-y-6>*+* {
    margin-top: var(--space-6);
}

.divide-y>*+* {
    border-top: 1px solid var(--border-color);
}