/* ==================== MOBILE-FIRST OPTIMIZATIONS ==================== */
/* Advanced Mobile UX Enhancements for CopilotX */
/* Includes: Touch Gestures, Mobile Navigation, Performance, PWA Support */

/* ==================== MOBILE VIEWPORT FIXES ==================== */
/* Fix for 100vh on mobile browsers */
:root {
    --vh: 1vh;
}

.full-height-mobile {
    height: 100vh; /* Fallback */
    height: calc(var(--vh, 1vh) * 100);
}

/* Prevent zoom on double-tap for iOS */
* {
    touch-action: manipulation;
}

/* Prevent overscroll bounce on iOS */
html,
body {
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

/* ==================== SAFE AREA INSETS FOR NOTCHES ==================== */
.safe-area-padding {
    padding-top: env(safe-area-inset-top);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
}

.safe-area-top {
    padding-top: max(16px, env(safe-area-inset-top));
}

.safe-area-bottom {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
}

/* ==================== TOUCH-OPTIMIZED COMPONENTS ==================== */
/* Minimum touch target size (44x44px for iOS, 48x48px for Android) */
.touch-target {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
}

.touch-target-lg {
    min-width: 48px;
    min-height: 48px;
    padding: 12px;
}

/* Remove tap highlight */
.no-tap-highlight {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
}

/* ==================== MOBILE BOTTOM NAVIGATION ==================== */
.mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(60px + env(safe-area-inset-bottom));
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    padding-top: 8px;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
    z-index: 100;
    transform: translateZ(0);
}

.mobile-nav-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 12px;
    min-width: 60px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 12px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.mobile-nav-button i {
    font-size: 22px;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-nav-button span {
    font-size: 11px;
    font-weight: 500;
    transition: color 0.2s ease;
}

.mobile-nav-button:active {
    background: var(--bg-hover);
    transform: scale(0.95);
}

.mobile-nav-button.active {
    color: var(--primary);
}

.mobile-nav-button.active i {
    transform: translateY(-2px);
}

/* Badge for notifications */
.mobile-nav-badge {
    position: absolute;
    top: 4px;
    right: 8px;
    min-width: 18px;
    height: 18px;
    background: var(--danger);
    color: white;
    font-size: 10px;
    font-weight: 700;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid var(--bg-primary);
}

/* Hide on desktop */
@media (min-width: 768px) {
    .mobile-bottom-nav {
        display: none;
    }
}

/* ==================== MOBILE HEADER ==================== */
.mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(56px + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 16px;
    padding-right: 16px;
    z-index: 90;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.mobile-header-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin: 0 8px;
}

.mobile-header-button {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    color: var(--text-primary);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.2s ease;
}

.mobile-header-button:active {
    background: var(--bg-hover);
    transform: scale(0.95);
}

.mobile-header-button i {
    font-size: 20px;
}

/* ==================== PULL-TO-REFRESH ==================== */
.pull-to-refresh {
    position: relative;
}

.pull-to-refresh-indicator {
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: top 0.3s ease;
}

.pull-to-refresh.pulling .pull-to-refresh-indicator {
    top: 20px;
}

.pull-to-refresh-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* ==================== MOBILE MODALS & SHEETS ==================== */
.mobile-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border-top-left-radius: 24px;
    border-top-right-radius: 24px;
    padding: 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 200;
}

.mobile-sheet.open {
    transform: translateY(0);
}

.mobile-sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--border-dark);
    border-radius: 2px;
    margin: 0 auto 20px;
}

.mobile-sheet-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.mobile-sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 199;
}

.mobile-sheet-backdrop.open {
    opacity: 1;
    visibility: visible;
}

/* ==================== SWIPE GESTURES ==================== */
.swipeable {
    position: relative;
    overflow: hidden;
    touch-action: pan-y;
}

.swipeable-item {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.swipeable-actions {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
}

.swipe-action {
    min-width: 60px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
    border-radius: 8px;
    cursor: pointer;
}

.swipe-action.delete {
    background: var(--danger);
}

.swipe-action.archive {
    background: var(--warning);
}

/* ==================== MOBILE FAB (Floating Action Button) ==================== */
.mobile-fab {
    position: fixed;
    bottom: calc(76px + env(safe-area-inset-bottom));
    right: 16px;
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 
        0 8px 24px rgba(0, 132, 255, 0.4),
        0 4px 8px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 80;
    border: none;
}

.mobile-fab:active {
    transform: scale(0.9);
}

.mobile-fab:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 12px 32px rgba(0, 132, 255, 0.5),
        0 6px 12px rgba(0, 0, 0, 0.2);
}

.mobile-fab i {
    font-size: 24px;
}

/* Extended FAB with text */
.mobile-fab-extended {
    width: auto;
    padding: 0 20px;
    gap: 8px;
}

.mobile-fab-extended span {
    font-size: 15px;
    font-weight: 600;
}

/* ==================== MOBILE CHIPS & TAGS ==================== */
.mobile-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.mobile-chip:active {
    transform: scale(0.95);
    background: var(--bg-tertiary);
}

.mobile-chip.selected {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.mobile-chip-remove {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    margin-left: 4px;
    font-size: 12px;
}

/* ==================== MOBILE TOAST NOTIFICATIONS ==================== */
.mobile-toast {
    position: fixed;
    bottom: calc(76px + env(safe-area-inset-bottom));
    left: 16px;
    right: 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    transform: translateY(calc(100% + 100px));
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 250;
}

.mobile-toast.show {
    transform: translateY(0);
}

.mobile-toast-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    font-size: 20px;
}

.mobile-toast.success .mobile-toast-icon {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.mobile-toast.error .mobile-toast-icon {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.mobile-toast.info .mobile-toast-icon {
    background: rgba(0, 132, 255, 0.15);
    color: var(--primary);
}

.mobile-toast-content {
    flex: 1;
}

.mobile-toast-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.mobile-toast-message {
    font-size: 13px;
    color: var(--text-secondary);
}

.mobile-toast-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.2s ease;
}

.mobile-toast-close:active {
    background: var(--bg-hover);
}

/* ==================== MOBILE SEARCH BAR ==================== */
.mobile-search-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-radius: 16px;
    border: 1px solid var(--border);
    transition: all 0.2s ease;
}

.mobile-search-bar:focus-within {
    background: var(--bg-primary);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 132, 255, 0.1);
}

.mobile-search-icon {
    font-size: 18px;
    color: var(--text-secondary);
}

.mobile-search-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 16px;
    color: var(--text-primary);
    outline: none;
}

.mobile-search-input::placeholder {
    color: var(--text-tertiary);
}

.mobile-search-clear {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.mobile-search-clear:active {
    transform: scale(0.9);
    background: var(--bg-hover);
}

/* ==================== MOBILE ACCORDION ==================== */
.mobile-accordion-item {
    border-bottom: 1px solid var(--border);
}

.mobile-accordion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.2s ease;
}

.mobile-accordion-header:active {
    background: var(--bg-hover);
}

.mobile-accordion-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.mobile-accordion-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border-radius: 8px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-accordion-item.open .mobile-accordion-icon {
    transform: rotate(180deg);
}

.mobile-accordion-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-accordion-item.open .mobile-accordion-content {
    max-height: 1000px;
}

.mobile-accordion-body {
    padding: 0 16px 16px;
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* ==================== MOBILE LIST ITEMS ==================== */
.mobile-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.mobile-list-item:active {
    background: var(--bg-hover);
}

.mobile-list-avatar {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.mobile-list-content {
    flex: 1;
    min-width: 0;
}

.mobile-list-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mobile-list-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mobile-list-action {
    flex-shrink: 0;
    color: var(--text-tertiary);
}

/* ==================== MOBILE PERFORMANCE OPTIMIZATIONS ==================== */
/* Enable GPU acceleration for smooth scrolling */
.smooth-scroll {
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
    transform: translateZ(0);
}

/* Optimize images for mobile */
.mobile-optimized-image {
    max-width: 100%;
    height: auto;
    display: block;
    image-rendering: -webkit-optimize-contrast;
}

/* Lazy loading placeholder */
.lazy-loading {
    background: linear-gradient(
        90deg,
        var(--bg-secondary) 25%,
        var(--bg-tertiary) 50%,
        var(--bg-secondary) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
}

/* ==================== MOBILE FORM ENHANCEMENTS ==================== */
.mobile-input-group {
    margin-bottom: 20px;
}

.mobile-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.mobile-input {
    width: 100%;
    min-height: 48px;
    padding: 12px 16px;
    font-size: 16px; /* Prevents zoom on iOS */
    background: var(--bg-primary);
    border: 2px solid var(--border);
    border-radius: 12px;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.mobile-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 132, 255, 0.1);
}

.mobile-textarea {
    min-height: 120px;
    resize: vertical;
    font-family: inherit;
}

/* ==================== MOBILE SWITCH/TOGGLE ==================== */
.mobile-switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 30px;
}

.mobile-switch-input {
    opacity: 0;
    width: 0;
    height: 0;
}

.mobile-switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-tertiary);
    border-radius: 30px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-switch-slider::before {
    content: '';
    position: absolute;
    height: 24px;
    width: 24px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.mobile-switch-input:checked + .mobile-switch-slider {
    background: var(--primary);
}

.mobile-switch-input:checked + .mobile-switch-slider::before {
    transform: translateX(22px);
}

/* ==================== RESPONSIVE BREAKPOINTS ==================== */
/* Only show on mobile */
.mobile-only {
    display: block;
}

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

/* Hide on mobile */
.desktop-only {
    display: none;
}

@media (min-width: 768px) {
    .desktop-only {
        display: block;
    }
}

/* ==================== ORIENTATION SPECIFIC ==================== */
@media (orientation: landscape) and (max-height: 500px) {
    .mobile-sheet {
        max-height: 85vh;
    }
    
    .mobile-header {
        height: calc(48px + env(safe-area-inset-top));
    }
    
    .mobile-bottom-nav {
        height: calc(52px + env(safe-area-inset-bottom));
    }
}

/* ==================== ACCESSIBILITY FOR MOBILE ==================== */
.mobile-focus-visible:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
    border-radius: 8px;
}

/* Increase touch targets for small screens */
@media (max-width: 374px) {
    .touch-target {
        min-width: 48px;
        min-height: 48px;
    }
}
