/* ============================================
   LAYOUT
   Main app structure, containers, and panels
   ============================================ */

/* App Container */
.app-container {
    width: 100%;
    display: grid;
    grid-template-rows: auto 1fr auto;
    height: 100%;
    overflow: hidden;
    margin: 0;
    padding: 20px;
    box-sizing: border-box;
}

/* Main Two-Column Layout */
.main-layout {
    display: grid;
    grid-template-columns: auto 12px 1fr;
    gap: 20px;
    min-height: 0;
    overflow: hidden;
    height: 100%;
    transition: all 0.3s ease;
}

.main-layout.resizing {
    cursor: col-resize;
    user-select: none;
    transition: none;
}

/* Left Panel: Search */
.search-panel {
    min-width: 0;
    overflow: hidden;
    transition: width 0.2s ease;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.search-panel.collapsed {
    width: 0 !important;
    overflow: hidden;
    padding: 0;
}

.search-panel.collapsed * {
    visibility: hidden;
}

/* Panel Divider */
.panel-divider {
    width: 8px;
    background: transparent;
    border-right: 1px solid var(--divider-border);
    cursor: col-resize;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 60px;
    position: relative;
    height: 100%;
    transition: background 0.2s ease;
}

.panel-divider:hover {
    border-right-color: var(--accent-color);
    background: transparent;
}

.panel-divider:active {
    border-right-color: var(--accent-color);
    box-shadow: 1px 0 8px var(--accent-glow);
    background: transparent;
}

/* Collapse Button */
.collapse-btn {
    width: 20px;
    height: 40px;
    border: none;
    background: var(--divider-btn-bg);
    color: var(--divider-btn-text);
    border-radius: 4px;
    cursor: pointer;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
}

.collapse-btn:hover {
    background: var(--accent-color);
    color: #fff;
}

.mobile-text {
    display: none;
}

/* Right Panel */
.right-panel {
    min-width: 320px;
    height: 100%;
    overflow: hidden;
    background: var(--panel-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* Panel Content */
.panel-content {
    display: grid;
    grid-template-rows: 1fr;
    overflow: hidden;
    padding: 16px;
    flex: 1;
}

.panel-content>* {
    min-width: 0;
    min-height: 0;
}

/* Common panel styles */
.deck-panel,
.stats-panel,
.genome-panel,
.library-panel,
.evolution-panel,
.home-panel {
    position: relative;
    /* Anchor for internal overlays/modals */
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: auto !important;
    /* Enable single main scrollbar */
    overflow-x: hidden;
    border: none !important;
    box-sizing: border-box !important;
    /* Ensure padding doesn't break height */
}

/* Main content container (wraps list or empty message) */
.deck-list-container {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
    overflow: visible !important;
}

@media (max-width: 768px) {
    .deck-panel,
    .library-panel,
    .evolution-panel,
    .stats-panel,
    .genome-panel,
    .home-panel {
        height: auto !important;
        min-height: 100%;
        overflow-y: visible !important;
        display: flex;
        flex-direction: column;
        flex: 1;
    }
}

/* Stats Panel Override */
.stats-panel {
    overflow-y: auto !important;
    padding-right: 6px;
    box-sizing: border-box;
}

/* ============================================
   MEDIA QUERIES
   ============================================ */

/* Mobile Layout Override */
@media (max-width: 768px) {
    html,
    body {
        overflow-y: auto !important;
        overflow-x: hidden !important;
        height: auto !important;
        min-height: 100vh !important;
        margin: 0;
        padding: 0;
    }

    .app-container {
        display: block !important;
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
        padding: 10px !important;
        width: 100%;
    }

    .main-layout {
        display: block !important;
        /* Single column, no grid/flex split */
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
        position: relative;
        width: 100%;
        /* Anchor for absolute positioned search overlay */
    }

    /* Hide the panel divider on mobile - replaced by FAB */
    .panel-divider {
        display: none !important;
    }

    /* Search Panel: Hidden by default, becomes slide-over overlay */
    .search-panel {
        display: none;
        /* Hidden by default on mobile */
    }

    /* When explicitly shown via mobile overlay, use mobile_fab.css styles */
    .search-panel.mobile-overlay {
        display: flex;
    }

    /* Right Panel: Grow with content */
    .right-panel {
        width: 100%;
        max-width: 100vw;
        height: auto !important;
        min-height: 100vh;
        overflow-x: hidden !important;
        overflow-y: visible !important;
        display: flex;
        flex-direction: column;
        border-radius: 12px 12px 0 0;
        border-left: none;
        border-top: none;
        /* Disable all blurs on mobile - causes rendering artifacts */
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background: var(--widget-bg) !important;
    }

    .mobile-search-backdrop {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background: rgba(0, 0, 0, 0.8) !important;
    }

    .panel-content {
        flex: 1;
        min-height: 0;
        overflow: visible !important;
        display: flex;
        flex-direction: column;
        height: auto !important;
        padding: 0 !important;
    }

    /* Internal panels handle their own scrolling - Handled at top of file now */
    .library-content {
        flex: 1;
        min-height: 0;
        box-sizing: border-box !important;
    }

    /* Hide desktop-only elements */
    .desktop-icon {
        display: none;
    }

    .mobile-text {
        display: inline-block;
    }

    .collapse-btn {
        display: none;
    }
}

/* Ultrawide Layout Override */
@media (min-width: 1921px) {
    .main-layout {
        max-width: none;
        margin: 0;
        border: none;
        box-shadow: none;
        /* Ensure gap handles sidebar correctly */
        gap: 24px;
        padding-right: 24px;
    }
}

/* App Footer */
.app-footer {
    padding: 8px 12px;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.6;
    transition: opacity 0.3s ease;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-top: auto;
}

.app-footer p {
    margin: 0;
    line-height: 1.4;
}

.app-footer:hover {
    opacity: 1;
}