/* ============================================
   layout.css - Grid System & Responsive Layout
   ============================================ */

/* Main Layout Container */
.layout {
    display: grid;
    min-height: 100vh;
    max-width: var(--max-width);
    margin: 0 auto;
    width: 100%;
    overflow-x: hidden;
}

/* Desktop: 3-column layout (nav + content + aside) */
@media (min-width: 1120px) {
    .layout.has-nav.has-aside {
        grid-template-columns: var(--nav-width) 1fr var(--aside-width);
        grid-template-areas: "nav main aside";
    }

    .layout.has-nav {
        grid-template-columns: var(--nav-width) 1fr;
        grid-template-areas: "nav main";
    }

    .layout.has-aside {
        grid-template-columns: 1fr var(--aside-width);
        grid-template-areas: "main aside";
    }

    .layout {
        grid-template-columns: 1fr;
        grid-template-areas: "main";
    }
}

/* Tablet: 2-column or single */
@media (min-width: 768px) and (max-width: 1119px) {
    .layout.has-nav {
        grid-template-columns: 200px 1fr;
        grid-template-areas: "nav main";
    }

    .layout {
        grid-template-columns: 1fr;
        grid-template-areas: "main";
    }

    .layout aside {
        display: none;
        /* Hide aside on tablet */
    }
}

/* Mobile: single column, nav becomes header */
@media (max-width: 767px) {
    .layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        grid-template-areas:
            "nav"
            "main";
        width: 100vw;
        max-width: 100vw;
        overflow-x: hidden;
    }

    .layout aside {
        display: none;
    }

    .layout-main {
        padding: var(--space-md);
        width: 100%;
        box-sizing: border-box;
    }

    .layout-nav {
        padding: var(--space-sm) var(--space-md);
    }
}

/* Layout Areas */
.layout-nav {
    grid-area: nav;
    border-right: var(--border);
    padding: var(--content-padding);
}

.layout-main {
    grid-area: main;
    padding: var(--content-padding);
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
    max-width: 100%;
}

.layout-aside {
    grid-area: aside;
    border-left: var(--border);
    padding: var(--content-padding);
    position: sticky;
    top: var(--content-padding);
    align-self: start;
    max-height: calc(100vh - var(--content-padding) * 2);
    overflow-y: auto;
}

/* Content area should grow to push footer down */
#content-area {
    flex: 1;
}

/* Mobile nav becomes horizontal header */
@media (max-width: 767px) {
    .layout-nav {
        border-right: none;
        border-bottom: var(--border);
        padding: var(--space-md);
    }

    .layout-aside {
        position: static;
        max-height: none;
    }
}

/* Container utilities */
.container {
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 var(--content-padding);
}

.container-narrow {
    max-width: 800px;
}

.container-wide {
    max-width: 1200px;
}

/* Flex utilities */
.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

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

.items-center {
    align-items: center;
}

.justify-center {
    justify-content: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-sm {
    gap: var(--space-sm);
}

.gap-md {
    gap: var(--space-md);
}

.gap-lg {
    gap: var(--space-lg);
}

/* Grid utilities */
.grid {
    display: grid;
}

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

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

@media (max-width: 767px) {

    .grid-cols-2,
    .grid-cols-3 {
        grid-template-columns: 1fr;
    }
}