/* Dashboard Styles - Final Fixes [v95] */

#dashboard-view {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg);
    overflow-y: auto;
    z-index: 50;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

#dashboard-view.active {
    display: block;
}

#editor-view {
    display: none;
}

#editor-view.active {
    display: block;
}

/* ============================================
   HEADER - NO COLLISION LAYOUT
   ============================================ */

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    padding-top: max(env(safe-area-inset-top, 0px), 12px);
    border-bottom: 1px solid var(--border);
    background: var(--primary);
    position: sticky;
    top: 0;
    z-index: 100;
    height: 72px;
    box-sizing: border-box;
    gap: 12px;
    flex-wrap: nowrap;
    /* CRITICAL: Prevents wrapping bugs */
}

/* Updated logo to match sidebar style */
.dashboard-header .logo-container {
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
}

/* Right side actions container */
.dashboard-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex: 1;
    justify-content: flex-end;
    min-width: 0;
    /* Prevents flexbox overflow */
}

/* ============================================
   SEARCH & INPUT OVERRIDES
   ============================================ */

#dashboard-view input[type="text"],
#dashboard-view select {
    width: auto;
    max-width: 100%;
}

.search-container {
    position: relative;
    display: flex;
    align-items: center;
    width: 240px;
    max-width: 100%;
    transition: width 0.3s ease;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.search-box .material-symbols-outlined {
    position: absolute;
    left: 10px;
    color: #666;
    pointer-events: none;
    font-size: 20px;
}

.search-box input#dashboard-search {
    padding: 0 16px 0 40px;
    background: #111;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    color: var(--text);
    width: 100%;
    outline: none;
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    font-size: 0.9rem;
    height: 40px;
    font-family: var(--font-main);
}

.search-box input#dashboard-search:focus {
    border-color: var(--accent);
    background: #1a1a1a;
}

/* Sort Dropdown - Compact for Mobile */
#dashboard-view .sort-select {
    padding: 0 8px;
    background: #111;
    border: 1px solid #444;
    border-radius: 8px;
    color: var(--text);
    outline: none;
    cursor: pointer;
    height: 38px;
    width: auto;
    min-width: 80px;
    /* Small enough for mobile, big enough for "Recent" */
    font-size: 0.85rem;
    flex-shrink: 0;
}

/* Mobile Buttons (Hidden on Desktop) */
.search-icon-btn,
.search-back-btn,
.search-close-btn {
    display: none;
}

/* ============================================
   SYNC BAR & REFRESH BUTTON
   ============================================ */

.sync-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: #0a0a0a;
    border-bottom: 1px solid var(--border);
    font-size: 0.75rem;
    color: #888;
    height: 40px;
}

.sync-status-bar.loading {
    color: #4285f4;
}

.sync-status-bar.synced {
    color: #34a853;
}

.sync-status-bar.error {
    color: var(--red-accent);
}

/* Refresh Button - Clean Style */
#refresh-btn {
    background: transparent;
    border: none;
    color: #34a853;
    /* Match 'Synced' green */
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    border-radius: 50%;
}

#refresh-btn:hover {
    background: rgba(52, 168, 83, 0.1);
}

#refresh-btn .material-symbols-outlined {
    font-size: 20px;
}

.dashboard-body {
    padding: 16px;
    max-width: 1200px;
    margin: 0 auto;
    padding-bottom: 100px;
    /* Space for FAB */
}

/* ============================================
   DRIVE STATE & BUTTON FIX
   ============================================ */

.drive-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    color: var(--text-sec);
    /* FIX: Removed animation to prevent flickering */
    animation: none;
    position: relative;
    z-index: 1;
}

.btn-drive-sleek {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #ffffff;
    /* Clean white button */
    color: #000000;
    border: none;
    padding: 12px 28px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.95rem;
    /* FIX: Force cursor and pointer events */
    cursor: pointer !important;
    z-index: 100;
    pointer-events: auto !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    font-family: var(--font-main);
    user-select: none;
}

.btn-drive-sleek:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(255, 255, 255, 0.15);
    background: #f5f5f5;
}

.btn-drive-sleek:active {
    transform: translateY(0) scale(0.98);
}

.btn-drive-sleek .material-symbols-outlined {
    font-size: 20px;
    color: #4285F4;
    /* Google Blue */
}

/* Add a subtle animation to the icon */
.drive-state .material-symbols-outlined:first-child {
    font-size: 64px;
    margin-bottom: 16px;
    background: linear-gradient(135deg, #333, #111);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    opacity: 0.8;
}

/* ============================================
   TABS & GRIDS
   ============================================ */

.source-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-bottom: 1px solid #333;
    overflow-x: auto;
}

.source-tab {
    flex: 1;
    background: transparent;
    border: none;
    color: #666;
    padding: 12px 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
}

.source-tab:hover {
    color: #ccc;
}

.source-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
}

@media (min-width: 600px) {
    .projects-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
        gap: 20px;
    }
}

/* ============================================
   CARDS
   ============================================ */

.project-card {
    background: #0F0F0F;
    border: 1px solid #222;
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.project-card:hover {
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-6px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7);
}

.card-thumbnail {
    position: relative;
    width: 100%;
    padding-top: 56.25%;
    /* 16:9 Aspect Ratio */
    background: #0a0a0a;
    border-bottom: 1px solid #222;
}

.card-thumbnail img,
.thumbnail-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: flex;
    align-items: center;
    justify-content: center;
}

.thumbnail-placeholder .material-symbols-outlined {
    font-size: 48px;
    color: #333;
}

.image-count-badge {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: bold;
}

.card-body {
    padding: 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.card-title {
    margin: 0;
    font-size: 0.95rem;
    color: var(--accent);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-meta {
    font-size: 0.75rem;
    color: #888;
}

.card-actions {
    padding: 10px 12px;
    border-top: 1px solid #222;
    display: flex;
    gap: 8px;
}

.btn-primary {
    flex: 1;
    padding: 10px;
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: var(--font-main);
    transition: all 0.2s;
}

.btn-icon {
    width: 34px;
    height: 34px;
    min-width: 34px;
    background: transparent;
    border: 1px solid #333;
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   FAB
   ============================================ */

.dashboard-fab {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 90;
}

.fab-btn {
    width: 56px;
    height: 56px;
    background: var(--accent);
    border: none;
    border-radius: 50%;
    color: #000;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 30px rgba(255, 255, 255, 0.2);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.fab-btn:hover {
    transform: scale(1.1) rotate(90deg);
    box-shadow: 0 12px 40px rgba(255, 255, 255, 0.3);
}

.fab-btn .material-symbols-outlined {
    font-size: 28px;
}

/* ============================================
   CONTEXT MENU
   ============================================ */
.context-menu {
    position: fixed;
    background: var(--secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.8);
    padding: 6px;
    z-index: 1000;
    min-width: 180px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text);
    font-size: 0.9rem;
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.menu-item.danger {
    color: #ff5555;
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */

@media (max-width: 600px) {
    /* FIX: Force context menu to be visible and reachable above FAB */
    .context-menu {
        bottom: calc(env(safe-area-inset-bottom, 0px) + 110px) !important; /* Increased to clear FAB */
        right: 20px !important;
        left: auto !important;
        top: auto !important;
        position: fixed !important;
        z-index: 9999 !important;
        pointer-events: auto !important; /* Force clicks to work */
    }

    .dashboard-header {
        padding: 0 12px;
        padding-top: max(env(safe-area-inset-top, 0px), 12px);
    }

    .dashboard-logo {
        font-size: 20px;
    }

    /* Hide standard input on mobile default state */
    .search-container {
        display: none;
    }

    /* Show sort dropdown but keep it compact */
    #dashboard-view .sort-select {
        width: auto;
        min-width: 0;
        padding: 0 4px;
        font-size: 0.8rem;
    }

    /* Mobile Buttons */
    .search-icon-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 38px;
        height: 38px;
        border-radius: 50%;
        background: transparent;
        border: none;
        color: white;
    }

    /* Expanded Search State */
    .dashboard-header.search-active .logo-container,
    .dashboard-header.search-active .sort-select,
    .dashboard-header.search-active .search-icon-btn {
        display: none;
    }

    .dashboard-header.search-active .search-container {
        display: flex;
        flex: 1;
        width: 100%;
    }

    .dashboard-header.search-active .search-box input {
        padding-left: 12px;
        /* Remove icon padding for more space */
    }

    .dashboard-header.search-active .search-box .material-symbols-outlined {
        display: none;
    }

    .search-back-btn,
    .search-close-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        background: transparent;
        border: none;
        color: white;
    }

    /* Adjust grid for mobile */
    .projects-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .card-thumbnail {
        padding-top: 100%;
        /* Square thumbnails on mobile */
    }

    .card-body {
        padding: 10px;
    }
}

/* =========================================
   ONBOARDING GUIDE (Fixed & Paginated)
   ========================================= */

#onboarding-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}

#onboarding-overlay.active {
    display: flex !important;
}

.onboarding-card {
    background: var(--card-bg, #1e1e1e);
    /* Fallback to dark grey if var missing */
    border: 1px solid var(--border, #333);
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.9);

    max-width: 450px !important;
    width: 90% !important;
    padding: 25px;
    text-align: left;

    display: flex;
    flex-direction: column;
    min-height: 450px;
    /* Ensure consistent height for slides */
}

.onboarding-slides-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

/* Hide all slides by default */
.onboarding-slide {
    display: none;
    animation: fadeIn 0.4s ease;
    text-align: center;
    padding-bottom: 10px;
}

.onboarding-slide.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Icons and Visuals */
.slide-icon-large .material-symbols-outlined {
    font-size: 64px;
    color: var(--accent);
    margin-bottom: 24px;
    background: #252525;
    padding: 20px;
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.slide-image-placeholder .material-symbols-outlined {
    font-size: 48px;
    color: #555;
    margin-bottom: 24px;
    padding: 20px;
}

/* Typography */
.onboarding-slide h3 {
    font-size: 1.6rem;
    margin-bottom: 16px;
    color: white;
}

.onboarding-slide p {
    font-size: 1rem;
    line-height: 1.6;
    color: #ccc;
    margin-bottom: 16px;
}

.onboarding-list {
    text-align: left;
    background: #222;
    padding: 15px 20px 15px 35px;
    border-radius: 12px;
    margin-top: 15px;
    color: #ddd;
    font-size: 0.9rem;
    border: 1px solid #333;
}

.onboarding-list li {
    margin-bottom: 8px;
}

/* Footer & Navigation */
.onboarding-footer {
    margin-top: auto;
    padding-top: 20px;
    border-top: 1px solid #333;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.onboarding-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 5px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #444;
    transition: all 0.3s;
}

.dot.active {
    background: var(--accent);
    transform: scale(1.3);
}

.onboarding-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
}

.btn-text {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 8px;
    font-weight: 600;
}

.btn-text:hover {
    color: #fff;
}

.btn-success {
    background-color: #4CAF50 !important;
}

/* Mobile Optimizations */
@media (max-width: 600px) {
    .onboarding-card {
        padding: 20px !important;
        min-height: 400px;
    }

    .slide-icon-large .material-symbols-outlined {
        font-size: 48px;
        padding: 16px;
        margin-bottom: 16px;
    }

    .onboarding-slide h3 {
        font-size: 1.3rem;
    }

    .onboarding-slide p {
        font-size: 0.9rem;
    }
}
