/* Default Theme: Dark (Black) */
:root,
[data-theme="dark"] {
    /* Color Palette - Premium Dark Mode */
    --bg-primary: #0a0a0a;
    --bg-secondary: #121212;
    --bg-card: #1a1a1a;
    --bg-overlay: rgba(0, 0, 0, 0.85);

    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-muted: #555555;

    --accent-color: #6366f1;
    /* Indigo-500 */
    --accent-hover: #4f46e5;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);

    --border-color: rgba(255, 255, 255, 0.1);
    --glass-bg: rgba(20, 20, 20, 0.6);
    --glass-border: rgba(255, 255, 255, 0.08);

    /* Spacing & Layout */
    --sidebar-width: 280px;
    --header-height: 70px;
    --grid-gap: 16px;

    /* Animation */
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* Blue Theme (from Login) */
[data-theme="blue"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #334155;
    --bg-overlay: rgba(15, 23, 42, 0.9);

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --border-color: rgba(255, 255, 255, 0.1);
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
}

/* Light Theme */
[data-theme="light"] {
    --bg-primary: #f8fafc;
    --bg-secondary: #e2e8f0;
    --bg-card: #ffffff;
    --bg-overlay: rgba(255, 255, 255, 0.9);

    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;

    --accent-color: #4f46e5;
    --accent-hover: #4338ca;

    --border-color: rgba(0, 0, 0, 0.1);
    --glass-bg: rgba(255, 255, 255, 0.8);
    --glass-border: rgba(0, 0, 0, 0.08);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    /* fallback */
    background-color: var(--bg-primary);
    color: var(--text-primary);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Typography */
h1,
h2,
h3 {
    font-weight: 600;
    letter-spacing: -0.02em;
}

a {
    text-decoration: none;
    color: inherit;
    transition: var(--transition-fast);
}

/* Layout Controller */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar (Desktop) */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 24px;
    position: fixed;
    height: 100vh;
    z-index: 50;
    transform: translateX(0);
    transition: var(--transition-smooth);
}

.logo-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-bottom: 40px;
    text-align: center;
}

/* Mobile Header Logo - Hidden on desktop */
.mobile-header-logo {
    display: none;
}

.logo-title {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-top: 12px;
    font-weight: 600;
    letter-spacing: 0.05em;
}

.logo-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
    font-weight: 500;
    letter-spacing: 0.02em;
}

.brand-name {
    font-size: 1.25rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 12px;
    color: var(--text-secondary);
    font-size: 0.95rem;
    cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
    background: var(--bg-card);
    color: var(--text-primary);
}

.nav-item i {
    font-size: 1.1rem;
}

/* Main Content Area */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 24px 32px;
    background: var(--bg-primary);
    min-height: 100vh;
}

/* Header / Search Bar */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

.search-container {
    position: relative;
    width: 100%;
    max-width: 600px;
}

.search-input {
    width: 100%;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(168, 85, 247, 0.15));
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 14px 20px 14px 48px;
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    transition: var(--transition-fast);
}

.search-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.search-input:focus {
    border-color: rgba(255, 255, 255, 0.25);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

select.search-input option {
    background: #1a1a1a;
    color: #ffffff;
}

.search-icon {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

/* Gallery Grid */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
    /* Masonry-like flow (CSS Grid is row-based, for true masonry we need JS or specific layout tricks, sticking to grid for now for stability) */
}

.gallery-item {
    position: relative;
    background: var(--bg-card);
    border-radius: 16px;
    overflow: hidden;
    aspect-ratio: 2/3;
    /* Portrait for prompt cards */
    cursor: pointer;
    transition: var(--transition-smooth);
    border: 1px solid transparent;
}

.gallery-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    border-color: var(--border-color);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.6s ease;
}

.gallery-item:hover img {
    transform: scale(1.05);
}

.item-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 16px;
    background: transparent;
    opacity: 1;
    transform: translateY(0);
    transition: var(--transition-fast);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.item-overlay-content {
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 12px;
    padding: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* Hide overlay on hover */
.gallery-item:hover .item-overlay {
    opacity: 0;
    transform: translateY(10px);
}

/* Remove old description overlay rule */

.item-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.item-model-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Swipe FAB (Floating Action Button) - Centered */
.fab-swipe {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    color: white;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: var(--transition-fast);
    font-size: 1.2rem;
    cursor: pointer;
}

.gallery-item:hover .fab-swipe {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.fab-swipe:hover {
    background: var(--accent-color);
    transform: translate(-50%, -50%) scale(1.15);
}

/* Fullscreen Swiper Overlay */
.swiper-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #000;
    z-index: 100;
    display: none;
    /* Toggled by JS */
    opacity: 0;
    transition: opacity 0.4s ease;
}

.swiper-overlay.active {
    display: block;
    opacity: 1;
}

.swiper-close-btn {
    position: absolute;
    top: 24px;
    right: 24px;
    z-index: 102;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.5rem;
    backdrop-filter: blur(10px);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        padding: 16px;
    }

    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
}

/* Swiper Card Ratios */
.swiper-card-container {
    background-size: cover;
    background-position: center;
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    position: relative;
    overflow: hidden;
    transition: width 0.3s ease, height 0.3s ease, aspect-ratio 0.3s ease;
}

.aspect-9-16 {
    aspect-ratio: 9/16;
    height: 85vh;
    max-height: 800px;
    width: auto;
}

.aspect-16-9 {
    aspect-ratio: 16/9;
    width: 90vw;
    max-width: 1200px;
    height: auto;
}

/* Description Text */
.prompt-description {
    font-size: 0.95rem;
    opacity: 0.9;
    margin-bottom: 12px;
    color: #e2e8f0;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Ratio Toggle Button */
.ratio-toggle-btn {
    position: absolute;
    top: 24px;
    right: 80px;
    /* Left of close button */
    z-index: 102;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.ratio-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

/* Media Query Adjustments */
@media (max-width: 768px) {
    .aspect-16-9 {
        width: 100vw;
        aspect-ratio: 16/9;
        height: auto;
    }

    .aspect-9-16 {
        width: 100vw;
        height: 80vh;
        border-radius: 0;
    }

    .swiper-card-container {
        border-radius: 12px;
    }
}

/* ==============================
   MOBILE-SPECIFIC STYLES
   ============================== */

/* Hamburger Menu Button - Only visible on mobile */
.hamburger-btn {
    display: none;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 200;
    width: 44px;
    height: 44px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    font-size: 1.2rem;
    transition: all 0.2s ease;
}

.hamburger-btn:hover {
    background: var(--bg-card);
}

/* Mobile Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    opacity: 1;
}

/* Mobile Styles */
@media (max-width: 768px) {

    /* Show hamburger */
    .hamburger-btn {
        display: flex;
    }

    /* Show overlay when needed */
    .sidebar-overlay {
        display: block;
        pointer-events: none;
    }

    .sidebar-overlay.active {
        pointer-events: auto;
    }

    /* Sidebar becomes sliding drawer */
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
        z-index: 100;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Main content takes full width */
    .main-content {
        margin-left: 0;
        padding: 70px 12px 24px 12px;
    }

    /* Top bar adjustments */
    .top-bar {
        flex-wrap: wrap;
        gap: 12px;
        margin-bottom: 16px;
        padding-left: 0;
        justify-content: center;
        width: 100%;
    }

    /* Hide tagline on mobile */
    .tagline-box {
        display: none !important;
    }

    /* Show mobile header logo */
    .mobile-header-logo {
        display: flex;
        justify-content: center;
        align-items: center;
        margin-bottom: 16px;
        padding-top: 8px;
    }

    /* Hide sidebar logo on mobile */
    .sidebar .logo-area {
        display: none;
    }

    /* Single column grid */
    .gallery-grid {
        grid-template-columns: 1fr !important;
        gap: 16px;
        padding: 0 4px;
    }

    /* Larger cards on mobile for better visibility */
    .gallery-item {
        aspect-ratio: 3/4;
        border-radius: 16px;
    }

    /* Search container full width */
    .search-container {
        max-width: 100%;
        flex: 1;
    }

    /* Type filter smaller */
    #typeFilter {
        min-width: auto;
        padding: 10px 12px;
    }

    /* Auth buttons compact */
    .auth-buttons {
        gap: 6px;
    }

    .auth-buttons .btn-secondary {
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    /* Close button for sidebar */
    .sidebar-close-btn {
        display: block;
        position: absolute;
        top: 16px;
        right: 16px;
        width: 36px;
        height: 36px;
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        color: var(--text-primary);
        cursor: pointer;
        font-size: 1rem;
    }

    /* Push nav menu down so it doesn't overlap with close button */
    .sidebar .nav-menu {
        margin-top: 60px;
    }

    /* Mobile Swiper Fullscreen */
    .swiper-overlay {
        padding: 0;
    }

    #swiperContent {
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Swiper buttons smaller on mobile */
    .ratio-toggle-btn,
    .swiper-close-btn {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }

    .swiper-close-btn {
        top: 16px;
        right: 16px;
    }

    .ratio-toggle-btn {
        top: 16px;
        right: 64px;
    }

    /* Mobile swiper card full width */
    .swiper-card-container {
        border-radius: 0;
        max-height: 100vh;
        max-width: 100vw;
    }

    /* Mobile 9:16 fullscreen */
    .aspect-9-16 {
        width: 100vw;
        height: 100vh;
        max-height: none;
        border-radius: 0;
    }

    /* Mobile 16:9 */
    .aspect-16-9 {
        width: 100vw;
        max-width: none;
        border-radius: 0;
    }

    /* Hide some desktop elements on mobile */
    .sidebar .logo-text {
        font-size: 0.7rem;
    }

    /* Footer adjustments */
    #siteFooter {
        padding: 20px 16px !important;
        font-size: 0.8rem !important;
    }

    /* Pagination adjustments */
    .page-btn {
        padding: 8px 10px !important;
        font-size: 0.8rem !important;
    }

    .page-info {
        width: 100%;
        text-align: center;
        margin-top: 8px;
        margin-left: 0 !important;
    }

    /* Hide theme toggle button on mobile */
    #theme-toggle-btn {
        display: none !important;
    }

    /* Hide hamburger button when swiper is active */
    body:has(.swiper-overlay.active) .hamburger-btn {
        display: none !important;
    }
}

/* Landscape mode on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .aspect-9-16 {
        height: 100vh;
        width: auto;
        aspect-ratio: 9/16;
    }

    .swiper-card-container {
        max-height: 100vh;
    }
}