/* MIKU Store — Portal & Sidebar Shared Layout (Dashboard, Admin, Pricelist, Validate) */

.sidebar {
    flex: 0 0 240px;
    min-width: 220px;
    max-width: 260px;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    box-sizing: border-box;
    overflow-y: auto;
    scrollbar-width: thin;
}

@media (min-width: 769px) {
    .sidebar {
        position: sticky;
        top: 73px;
        height: calc(100vh - 85px);
        height: calc(100dvh - 85px);
        max-height: calc(100vh - 85px);
        max-height: calc(100dvh - 85px);
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .sidebar-nav {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        scrollbar-width: thin;
        padding-right: 2px;
    }

    .sidebar-nav a {
        min-height: 38px;
        padding: 6px var(--space-3);
    }

    #menu-toggle-btn,
    .sidebar .menu-toggle-btn {
        display: none !important;
    }
}

@media (pointer: coarse) {
    .sidebar-nav a {
        min-height: 44px;
        padding: var(--space-2) var(--space-3);
    }
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-nav h4 {
    color: var(--text);
    margin: 0 0 var(--space-3);
    font-size: var(--text-sm);
    font-weight: 700;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 44px;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    color: var(--text-muted);
    font-size: var(--text-sm);
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.sidebar-nav a:hover {
    background-color: var(--surface-2);
    color: var(--text);
}

.sidebar-nav a.active {
    background-color: var(--accent);
    border-color: var(--accent);
    color: var(--accent-fg);
    font-weight: 700;
}

#logout-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 44px;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: var(--danger-text);
    font-size: var(--text-sm);
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

#logout-button:hover {
    background-color: var(--danger-soft);
    border-color: var(--danger);
    color: var(--text);
}

.store-link-btn-mobile {
    display: none;
    margin-top: var(--space-4);
    border-top: 1px solid var(--border);
}

.menu-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: var(--space-2);
    background-color: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: var(--text-base);
    cursor: pointer;
    transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.menu-toggle-btn:hover {
    background-color: var(--accent-soft);
    border-color: var(--accent);
}

/* --- Dropdown Game Selector (Compare Prices, Validate & Admin Pages) --- */
#game-selector-dropdown {
    width: 100%;
    max-width: 100%;
    min-height: 44px;
    padding: var(--space-2) var(--space-3);
    background-color: var(--bg);
    background-image: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: max(1rem, 1em);
    cursor: pointer;
    box-sizing: border-box;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

#game-selector-dropdown:hover,
#game-selector-dropdown:focus {
    border-color: var(--accent);
}

@media (min-width: 769px) {
    .sidebar-nav a.sidebar-store-link {
        display: none;
    }

    body.portal-shell header .header-container.container {
        max-width: none;
        width: 100%;
        margin-inline: 0;
        padding-inline: clamp(16px, 2.2vw, 32px);
    }

    body.portal-shell .dashboard-container.container,
    body.portal-shell .admin-page-container.container {
        max-width: none;
        width: 100%;
        margin-inline: 0;
        padding: 0;
        gap: 0;
        align-items: flex-start;
    }

    body.portal-shell .sidebar,
    body.portal-shell #dashboard-sidebar,
    body.portal-shell #admin-sidebar {
        flex: 0 0 252px;
        width: 252px;
        min-width: 252px;
        max-width: 252px;
        position: sticky;
        top: var(--navbar-height, 60px);
        height: calc(100vh - var(--navbar-height, 60px));
        height: calc(100dvh - var(--navbar-height, 60px));
        max-height: calc(100vh - var(--navbar-height, 60px));
        max-height: calc(100dvh - var(--navbar-height, 60px));
        border: none;
        border-right: 1px solid var(--border);
        border-radius: 0;
        padding: var(--space-4);
    }

    body.portal-shell .dashboard-content,
    body.portal-shell .admin-content {
        flex: 1 1 0%;
        max-width: none;
        min-width: 0;
        padding: var(--space-6) clamp(24px, 3vw, 44px) var(--space-12);
    }
}

/* --- Mobile Drawer Behavior (<= 768px) --- */
@media (max-width: 768px) {
    #menu-toggle-btn,
    .sidebar .menu-toggle-btn {
        display: inline-flex !important;
    }

    .store-link-btn,
    .header-right .store-link-btn {
        display: none !important;
    }

    .sidebar .store-link-btn-mobile,
    .sidebar .sidebar-store-link {
        display: flex !important;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        display: flex;
        flex-direction: column;
        width: min(82dvw, 290px);
        max-width: 290px;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        border-radius: 0 var(--radius-md) var(--radius-md) 0;
        z-index: var(--z-dropdown);
        transform: translateX(-100%);
        visibility: hidden;
        pointer-events: none;
        overscroll-behavior: contain;
    }

    .sidebar-nav {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
    }

    .sidebar-nav a {
        min-height: 44px;
        padding: var(--space-2) var(--space-3);
    }

    .sidebar.active {
        transform: translateX(0);
        visibility: visible;
        pointer-events: auto;
    }

    body.menu-open::after {
        content: "";
        position: fixed;
        inset: 0;
        background-color: var(--overlay-backdrop);
        z-index: calc(var(--z-dropdown) - 1);
    }
}

@media (max-width: 768px) and (prefers-reduced-motion: no-preference) {
    .sidebar {
        transition: transform var(--transition-fast), visibility var(--transition-fast);
    }
}
