/**
 * Core Layout System
 * ==================
 * Defines the main application grid and responsive behavior.
 * Dependencies: tokens.css
 */

/* ========================================
   BASE GRID
   ======================================== */

/* Base body styles */
body {
    min-height: 100vh;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-body);
    display: flex;
    flex-direction: column;
}

/* Main Layout Grid */
main {
    display: grid;
    grid-template-areas: "sidebar content";
    grid-template-columns: var(--sidebar-width) 1fr;
    flex: 1;
    /* Ensure main takes available space */
    width: 100%;
    margin: 0 auto;
}

/* ========================================
   AREAS
   ======================================== */

#sidebar {
    grid-area: sidebar;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    background: var(--color-bg-elevated);
    border-right: 1px solid var(--color-border);
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    z-index: var(--z-fixed);
}

#content {
    grid-area: content;
    padding: var(--space-6) var(--space-8);
    max-width: var(--max-content-width);
    margin: 0 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
    position: relative;
    /* Ensure content establishes a stacking context */
    isolation: isolate;
}

/* Narrative Container */
#narrative-container {
    max-width: var(--narrative-max-width);
    margin: 0 auto;
    width: 100%;
}

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

/* Tablet & Mobile (≤ 1024px) */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 280px;
    }

    #content {
        padding: var(--space-5);
    }
}

/* Mobile (≤ 768px) */
@media (max-width: 768px) {
    main {
        grid-template-areas:
            "content"
            "sidebar";
        /* Sidebar moves below or is handled by mobile.css overlays */
        grid-template-columns: 1fr;
    }

    #sidebar {
        /* Mobile specific sidebar handling is usually done via mobile.css 
           translating it off-screen or making it an accordion list at bottom */
        height: auto;
        position: relative;
        border-right: none;
        border-top: 1px solid var(--color-border);
        background: var(--color-bg);
        /* Match bg to blend in */
    }

    #content {
        padding: var(--space-4);
        max-width: 100%;
    }
}

/* ========================================
   UTILITY LAYOUTS
   ======================================== */

/* Flex row for button groups */
.btn-group {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}

/* Panel Containers */
.panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
}

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