/* ==========================================================================
   Mobile Navigation & Mobile-Specific Styles
   ========================================================================== */

/* Mobile Navigation Overlay */
.nav-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-modal-backdrop);
    opacity: 0;
    transition: opacity var(--transition-base);
}

.nav-overlay.active {
    display: block;
    opacity: 1;
}

/* Mobile Navigation Menu */
.mobile-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    max-width: 80%;
    height: 100%;
    background: var(--surface);
    z-index: var(--z-modal);
    transform: translateX(-100%);
    transition: transform var(--transition-base);
    box-shadow: var(--shadow-lg);
    overflow-y: auto;
}

.mobile-nav.active {
    transform: translateX(0);
}

.mobile-nav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border);
    background: var(--primary);
    color: white;
}

.mobile-nav-header h2 {
    margin: 0;
    font-size: 1.25rem;
    color: white;
}

.nav-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: background var(--transition-base);
}

.nav-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

.mobile-nav-menu {
    list-style: none;
    padding: var(--space-md) 0;
}

.mobile-nav-menu li {
    margin: 0;
}

.mobile-nav-menu a {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    color: var(--text);
    font-size: 1rem;
    transition: all var(--transition-base);
}

.mobile-nav-menu a:hover,
.mobile-nav-menu a.active {
    background: var(--light);
    color: var(--primary);
}

.nav-divider {
    height: 1px;
    background: var(--border);
    margin: var(--space-md) 0;
}

/* Floating Action Button */
.fab {
    position: fixed;
    bottom: var(--space-xl);
    right: var(--space-md);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--secondary);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    z-index: var(--z-fixed);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: all var(--transition-base);
}

.fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.fab:active {
    transform: scale(0.95);
}

@media (min-width: 768px) {
    .fab {
        display: none;
    }
}

.fab-menu {
    position: fixed;
    bottom: calc(var(--space-xl) + 70px);
    right: var(--space-md);
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-fixed);
    display: none;
    flex-direction: column;
    gap: var(--space-sm);
    padding: var(--space-md);
    min-width: 200px;
    border: 1px solid var(--border-light);
}

.fab-menu.active {
    display: flex;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fab-menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    border: none;
    background: var(--surface);
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all var(--transition-base);
    text-decoration: none;
    color: var(--text);
}

.fab-menu-item:hover {
    background: var(--light);
}

.fab-menu-icon {
    font-size: 1.5rem;
}

.fab-menu-label {
    font-weight: 500;
}

/* Bottom Tab Bar (Alternative Mobile Navigation) */
.bottom-tabs {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: none; /* Enable if preferred over FAB */
    justify-content: space-around;
    padding: var(--space-sm) 0;
    z-index: var(--z-sticky);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.bottom-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm);
    color: var(--text-light);
    font-size: 0.75rem;
    text-decoration: none;
    transition: color var(--transition-base);
    flex: 1;
    max-width: 80px;
}

.bottom-tab-icon {
    font-size: 1.5rem;
}

.bottom-tab.active,
.bottom-tab:hover {
    color: var(--secondary);
}

/* Mobile-Specific Adjustments */
@media (max-width: 767px) {
    /* Reduce padding on mobile */
    .container {
        padding: 0 var(--space-md);
    }
    
    /* Stack buttons vertically on mobile */
    .cta-buttons,
    .prompt-actions,
    .collection-actions {
        flex-direction: column;
    }
    
    .cta-buttons .btn,
    .prompt-actions .btn {
        width: 100%;
    }
    
    /* Full-width cards on mobile */
    .feature-grid,
    .stats-grid,
    .collections-grid {
        grid-template-columns: 1fr;
    }
    
    /* Adjust modals for mobile */
    .modal {
        padding: 0;
    }
    
    .modal-content {
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
    }
    
    /* Mobile header adjustments */
    .main-header {
        position: fixed;
        width: 100%;
        top: 0;
        left: 0;
    }
    
    body {
        padding-top: 60px;
    }
    
    /* Hide desktop elements */
    .desktop-nav {
        display: none !important;
    }
    
    /* Mobile-friendly forms */
    .form-row {
        grid-template-columns: 1fr;
    }
    
    /* Mobile tables */
    .calendar-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: var(--space-sm);
    }
    
    .calendar-day {
        padding: var(--space-sm);
    }
    
    .day-number {
        font-size: 0.9rem;
    }
    
    .day-prompt {
        font-size: 0.65rem;
    }
    
    /* Mobile tabs */
    .tabs {
        gap: var(--space-sm);
        padding-bottom: 0;
    }
    
    .tab {
        padding: var(--space-sm) var(--space-md);
        font-size: 0.9rem;
    }
    
    /* Mobile filter panel */
    .filter-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: var(--z-modal);
        max-height: 100vh;
        overflow-y: auto;
        display: none;
        border-radius: 0;
    }
    
    .filter-panel.mobile-active {
        display: block;
        animation: slideUp 0.3s ease;
    }
    
    /* Mobile browse layout */
    .browse-container {
        grid-template-columns: 1fr;
        padding: var(--space-md);
    }
    
    /* Mobile write interface */
    .write-container {
        grid-template-columns: 1fr;
        padding: var(--space-md);
    }
    
    .prompt-display {
        padding: var(--space-md);
    }
    
    .prompt-text {
        font-size: 1.1rem;
    }
    
    .editor {
        min-height: 300px;
        padding: var(--space-md);
        font-size: 1rem;
    }
    
    .writing-sidebar {
        position: relative;
        top: auto;
        margin-top: var(--space-md);
    }
}

/* Tablet adjustments */
@media (min-width: 768px) and (max-width: 1023px) {
    .feature-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .calendar-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

/* Touch-friendly adjustments */
@media (hover: none) and (pointer: coarse) {
    /* Increase tap target sizes */
    .btn,
    .icon-btn,
    .toolbar-btn,
    .filter-option,
    .tab {
        min-height: 44px;
    }
    
    /* Remove hover effects on touch devices */
    .feature-card:hover,
    .card:hover,
    .btn:hover {
        transform: none;
    }
    
    /* Larger form inputs for touch */
    .form-group input,
    .form-group textarea,
    .form-group select {
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 44px;
    }
}

/* Landscape mobile adjustments */
@media (max-width: 767px) and (orientation: landscape) {
    .hero {
        min-height: auto;
        padding: var(--space-xl) var(--space-md);
    }
    
    .hero-stats {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .write-header {
        position: relative;
    }
    
    .editor {
        min-height: 50vh;
    }
}

/* Small mobile devices */
@media (max-width: 374px) {
    html {
        font-size: 14px;
    }
    
    .hero-title {
        font-size: 2rem;
    }
    
    .section-title {
        font-size: 1.75rem;
    }
    
    .btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }
    
    .mobile-nav {
        width: 100%;
        max-width: 100%;
    }
}

/* Large mobile devices / Small tablets */
@media (min-width: 375px) and (max-width: 767px) {
    .hero-stats {
        gap: var(--space-md);
    }
    
    .stat-number {
        font-size: 2.5rem;
    }
}

/* Pull to refresh indicator (optional enhancement) */
.pull-to-refresh {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    padding: var(--space-md);
    background: var(--secondary);
    color: white;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    opacity: 0;
    transition: all var(--transition-base);
}

.pull-to-refresh.visible {
    opacity: 1;
    top: var(--space-md);
}

/* Mobile-specific save status and editor optimizations */
@media (max-width: 768px) {
    .save-status {
        font-size: 0.8rem;
        flex-direction: column;
        align-items: flex-start;
    }
    
    #editor {
        font-size: 16px; /* Prevent zoom on iOS */
        min-height: 200px;
        -webkit-overflow-scrolling: touch;
    }
    
    .char-count.warning,
    .char-count.caution {
        font-size: 0.9rem;
        padding: 0.25rem 0.5rem;
        border-radius: var(--radius-sm);
        display: inline-block;
    }
    
    .char-count.warning {
        background: rgba(231, 76, 60, 0.1);
    }
    
    .char-count.caution {
        background: rgba(243, 156, 18, 0.1);
    }
}

/* Safe area insets for notched devices */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    
    .main-header,
    .write-header,
    .bottom-tabs {
        padding-left: max(var(--space-md), env(safe-area-inset-left));
        padding-right: max(var(--space-md), env(safe-area-inset-right));
    }
    
    .fab {
        right: max(var(--space-md), env(safe-area-inset-right));
        bottom: max(var(--space-xl), env(safe-area-inset-bottom));
    }
}

