/**
 * Responsive Layout - Prime Factors Pro
 * Adaptive layout system for mobile, tablet, and desktop viewports.
 * Requirements: 8.1, 8.2, 8.3, 8.4, 8.5, 8.6, 8.7
 *
 * Breakpoints:
 *   - Mobile:  < 576px
 *   - Small:   576px - 767px
 *   - Tablet:  768px - 1023px
 *   - Desktop: 1024px - 1279px
 *   - Wide:    1280px+
 */

/* ========================================
   Global: Prevent Horizontal Scroll (8.6)
   ======================================== */

html,
body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* ========================================
   Base Layout Structure
   ======================================== */

.layout-pfp {
    display: flex;
    min-height: 100vh;
    width: 100%;
    max-width: 100vw;
}

.layout-pfp__sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    background: var(--color-bg-primary);
    border-right: 1px solid var(--color-border);
    transition: transform var(--transition-base),
                width var(--transition-base);
    overflow-y: auto;
    overflow-x: hidden;
}

.layout-pfp__main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
}

.layout-pfp__content {
    display: grid;
    gap: var(--space-6);
    padding: var(--space-6);
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* ========================================
   Sidebar Overlay Backdrop
   ======================================== */

.layout-pfp__overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99;
    background: var(--color-bg-dark);
    opacity: 0.5;
}

.layout-pfp__overlay--visible {
    display: block;
}

/* ========================================
   Mobile: Below 576px (8.2)
   Single column, collapsed sidebar, hamburger nav
   ======================================== */

@media (max-width: 575.98px) {
    .layout-pfp__sidebar {
        width: 260px;
        transform: translateX(-100%);
    }

    .layout-pfp__sidebar--open {
        transform: translateX(0);
    }

    .layout-pfp__main {
        margin-left: 0;
    }

    .layout-pfp__content {
        grid-template-columns: 1fr;
        padding: var(--space-4);
    }

    /* Hamburger toggle visible */
    .layout-pfp__toggle {
        display: flex;
    }

    /* Touch targets: 44x44px minimum (8.7) */
    .layout-pfp a,
    .layout-pfp button,
    .layout-pfp [role="button"],
    .layout-pfp input[type="submit"],
    .layout-pfp input[type="button"],
    .layout-pfp select,
    .layout-pfp summary {
        min-height: 44px;
        min-width: 44px;
    }
}

/* ========================================
   Small: 576px - 767px (8.3)
   Single column, collapsed sidebar, hamburger nav
   ======================================== */

@media (min-width: 576px) and (max-width: 767.98px) {
    .layout-pfp__sidebar {
        width: 260px;
        transform: translateX(-100%);
    }

    .layout-pfp__sidebar--open {
        transform: translateX(0);
    }

    .layout-pfp__main {
        margin-left: 0;
    }

    .layout-pfp__content {
        grid-template-columns: 1fr;
        padding: var(--space-6);
    }

    /* Hamburger toggle visible */
    .layout-pfp__toggle {
        display: flex;
    }

    /* Touch targets: 44x44px minimum (8.7) */
    .layout-pfp a,
    .layout-pfp button,
    .layout-pfp [role="button"],
    .layout-pfp input[type="submit"],
    .layout-pfp input[type="button"],
    .layout-pfp select,
    .layout-pfp summary {
        min-height: 44px;
        min-width: 44px;
    }
}

/* ========================================
   Tablet: 768px - 1023px (8.4)
   Compact sidebar (icons only), two-column grid
   ======================================== */

@media (min-width: 768px) and (max-width: 1023.98px) {
    .layout-pfp__sidebar {
        width: 72px;
        transform: translateX(0);
    }

    /* Hide sidebar text, show icons only */
    .layout-pfp__sidebar .sidebar-pfp__brand-text,
    .layout-pfp__sidebar .sidebar-pfp__link span,
    .layout-pfp__sidebar .sidebar-pfp__balance-label,
    .layout-pfp__sidebar .sidebar-pfp__balance-value {
        display: none;
    }

    .layout-pfp__main {
        margin-left: 72px;
    }

    .layout-pfp__content {
        grid-template-columns: repeat(2, 1fr);
        padding: var(--space-6);
    }

    /* Hamburger toggle hidden */
    .layout-pfp__toggle {
        display: none;
    }

    /* Touch targets: 44x44px minimum (8.7) */
    .layout-pfp a,
    .layout-pfp button,
    .layout-pfp [role="button"],
    .layout-pfp input[type="submit"],
    .layout-pfp input[type="button"],
    .layout-pfp select,
    .layout-pfp summary {
        min-height: 44px;
        min-width: 44px;
    }
}

/* ========================================
   Desktop: 1024px+ (8.5)
   Full sidebar (icons + text), 3-column grid
   ======================================== */

@media (min-width: 1024px) {
    .layout-pfp__sidebar {
        width: 260px;
        transform: translateX(0);
    }

    /* Show full sidebar text */
    .layout-pfp__sidebar .sidebar-pfp__brand-text,
    .layout-pfp__sidebar .sidebar-pfp__link span,
    .layout-pfp__sidebar .sidebar-pfp__balance-label,
    .layout-pfp__sidebar .sidebar-pfp__balance-value {
        display: inline;
    }

    .layout-pfp__main {
        margin-left: 260px;
    }

    .layout-pfp__content {
        grid-template-columns: repeat(3, 1fr);
        padding: var(--space-8);
    }

    /* Hamburger toggle hidden */
    .layout-pfp__toggle {
        display: none;
    }

    /* Compact sidebar variant (icon-only on desktop) */
    .sidebar-pfp--compact {
        width: 72px;
    }

    .sidebar-pfp--compact .sidebar-pfp__brand-text,
    .sidebar-pfp--compact .sidebar-pfp__link span,
    .sidebar-pfp--compact .sidebar-pfp__balance-label,
    .sidebar-pfp--compact .sidebar-pfp__balance-value {
        display: none;
    }

    .sidebar-pfp--compact ~ .layout-pfp__main,
    .layout-pfp:has(.sidebar-pfp--compact) .layout-pfp__main {
        margin-left: 72px;
    }
}

/* ========================================
   Wide: 1280px+ (8.5 extension)
   Wider content area
   ======================================== */

@media (min-width: 1280px) {
    .layout-pfp__content {
        max-width: 1440px;
        margin-left: auto;
        margin-right: auto;
        padding: var(--space-8) var(--space-12);
    }
}

/* ========================================
   Hamburger Toggle Button
   ======================================== */

.layout-pfp__toggle {
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: var(--space-2);
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--color-text-primary);
    transition: background-color var(--transition-fast);
}

.layout-pfp__toggle:hover {
    background-color: var(--color-bg-tertiary);
}

.layout-pfp__toggle:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* ========================================
   Content Grid Utilities
   ======================================== */

/* Full-width item spanning all columns */
.layout-pfp__content--full {
    grid-column: 1 / -1;
}

/* Two-column span */
.layout-pfp__content--span-2 {
    grid-column: span 2;
}

/* Ensure full-width items stack on mobile */
@media (max-width: 767.98px) {
    .layout-pfp__content--span-2 {
        grid-column: 1 / -1;
    }
}
