/**
 * Critical CSS - Above-the-fold styles for instant rendering
 * 
 * PERFORMANCE: This file contains only the essential styles needed
 * for the initial page render (navbar, basic layout, loading states).
 * The main style.css is loaded asynchronously after this.
 * 
 * Target: < 14KB for optimal first render
 */

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* CSS Variables - Essential only (fallbacks until style.css loads) */
:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --body-bg: linear-gradient(135deg, #0f1429 0%, #1e2544 25%, #252d4a 50%, #1a2240 75%, #0a0e1f 100%);
    --body-bg-solid: #0f1429;
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.95);
    --nav-bg: rgba(15, 23, 42, 0.95);
    --nav-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    --nav-border: rgba(255, 255, 255, 0.1);
    --elevated-bg: rgba(15, 23, 42, 0.85);
    --elevated-bg-solid: rgba(15, 23, 42, 0.95);
    --elevated-bg-hover: rgba(15, 23, 42, 0.98);
    --card-bg: rgba(30, 41, 59, 0.8);
    --border-light: rgba(255, 255, 255, 0.1);
    --border-color: rgba(255, 255, 255, 0.2);
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-bg-light: rgba(255, 255, 255, 0.15);
    --glass-border: rgba(255, 255, 255, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.15);
    --text-on-surface: #ffffff;
    --text-on-surface-secondary: rgba(255, 255, 255, 0.85);
    --text-on-surface-muted: rgba(255, 255, 255, 0.6);
}

/* Body base */
html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--body-bg);
    background-attachment: fixed;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    color: var(--text-primary);
    line-height: 1.5;
    overflow-x: hidden;
}

/* iOS Safe Area - Extend theme color to top/bottom */
html {
    background-color: var(--body-bg-solid);
    background: var(--body-bg);
    background-attachment: fixed;
}

/* iOS PWA Safe Area Support */
@supports (padding-top: env(safe-area-inset-top)) {
    body {
        padding-top: 0;
    }
}

/* iOS Status Bar Cover - Provides solid background behind dynamic island/status bar */
.ios-status-bar-cover {
    display: none;
}

@supports (padding-top: env(safe-area-inset-top)) {
    @media all and (display-mode: standalone) {
        .ios-status-bar-cover {
            display: block;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            height: env(safe-area-inset-top);
            background: linear-gradient(180deg, var(--body-bg-solid) 0%, var(--elevated-bg-solid) 100%);
            z-index: 999;
            pointer-events: none;
        }
    }
}

/* Navbar - Critical for above-the-fold */
.navbar {
    background: var(--elevated-bg-hover);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-light);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    padding: 0.5rem 0.75rem;
    box-shadow: var(--nav-shadow);
    /* iOS Safe Area Support - navbar includes status bar area */
    padding-top: calc(0.5rem + env(safe-area-inset-top, 0px));
    padding-left: calc(0.75rem + env(safe-area-inset-left, 0px));
    padding-right: calc(0.75rem + env(safe-area-inset-right, 0px));
}


.nav-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 0.5rem;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
}

.nav-brand i {
    font-size: 1.25rem;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-menu {
    display: flex;
    list-style: none;
    align-items: center;
    gap: 0;
}

.nav-link {
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.75rem;
    padding: 0.375rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.nav-link i {
    font-size: 0.875rem;
}

/* Main content area */
.main-content {
    padding: 1rem;
    padding-top: 70px; /* Account for fixed navbar */
    min-height: calc(100vh - 70px);
    /* iOS Safe Area Support */
    padding-top: calc(70px + env(safe-area-inset-top, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    min-height: calc(100vh - 70px - env(safe-area-inset-top, 0px));
}

/* Loading skeleton */
.loading-skeleton {
    background: linear-gradient(90deg, var(--border-light) 25%, var(--glass-bg-light) 50%, var(--border-light) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 8px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Basic card structure */
.card-3d {
    background: var(--elevated-bg);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 1rem;
}

/* Button basics */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, #4f46e5 100%);
    color: white;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .main-content {
        padding: 0.75rem;
        padding-top: 60px;
        /* iOS Safe Area Support for mobile */
        padding-top: calc(60px + env(safe-area-inset-top, 0px));
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
        padding-left: calc(0.75rem + env(safe-area-inset-left, 0px));
        padding-right: calc(0.75rem + env(safe-area-inset-right, 0px));
    }
    
    .nav-menu {
        display: none;
    }
    
    .hamburger-menu-btn {
        display: flex;
    }
}

/* Hide hamburger on desktop */
.hamburger-menu-btn {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
}

.hamburger-menu-btn span {
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
}

/* ============================================
   ANTI-FOUC: Hide overlay elements immediately
   These must be hidden BEFORE main CSS loads
   to prevent visual glitches on page navigation
   
   NOTE: Do NOT use pointer-events: none here!
   It will break click handlers. visibility: hidden
   already prevents interactions.
   ============================================ */

/* Quick Action FAB Overlay - hidden by default */
.quick-action-overlay {
    opacity: 0;
    visibility: hidden;
}

/* Mobile Menu - hidden by default (desktop) */
/* On mobile, style.css will override with display: block */
.mobile-menu,
.mobile-menu-overlay {
    opacity: 0;
    visibility: hidden;
}

/* User Dropdown - hidden by default */
.user-dropdown {
    opacity: 0;
    visibility: hidden;
}

/* Modals - hidden by default */
.modal {
    display: none;
}

/* Voice Command Modal */
#voiceCommandModal {
    display: none;
}

/* Settings page - hide mobile elements on desktop */
.settings-mobile-menu-btn,
.settings-mobile-toggle {
    display: none;
}

/* Show settings mobile elements only on mobile */
@media (max-width: 768px) {
    .settings-mobile-menu-btn {
        display: flex;
    }
    
    .settings-mobile-toggle {
        display: flex;
    }
}

/* Page loading state */
.page-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 50vh;
}

.page-loading::after {
    content: '';
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
