/**
 * 📱 Mobile Enhancement Styles
 * Optimized mobile experience with touch-friendly UI and gestures
 */

/* ===== MOBILE ENHANCED BASE ===== */
.mobile-enhanced {
    --mobile-touch-target: 44px;
    --mobile-padding: 16px;
    --mobile-border-radius: 12px;
    --mobile-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Prevent text selection on UI elements */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Allow text selection in content areas */
.mobile-enhanced .message,
.mobile-enhanced input,
.mobile-enhanced textarea {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* ===== MOBILE TOOLBAR ===== */
.mobile-toolbar {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 1000;
    opacity: 0.9;
    transition: opacity 0.3s ease;
}

.mobile-toolbar:hover {
    opacity: 1;
}

.mobile-tool-btn {
    width: var(--mobile-touch-target);
    height: var(--mobile-touch-target);
    background: rgba(0, 0, 0, 0.8);
    border: none;
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--mobile-transition);
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.mobile-tool-btn:hover {
    background: rgba(0, 0, 0, 0.9);
    transform: scale(1.1);
}

.mobile-tool-btn:active {
    transform: scale(0.95);
    background: rgba(0, 0, 0, 1);
}

/* ===== PULL TO REFRESH ===== */
.pull-indicator {
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 100;
}

.pull-indicator.ready .pull-icon {
    transform: rotate(180deg);
    color: #4285f4;
}

.pull-icon {
    font-size: 24px;
    transition: transform 0.3s ease, color 0.3s ease;
    color: #666;
}

.pull-text {
    font-size: 12px;
    color: #666;
    text-align: center;
}

/* ===== MOBILE TOAST NOTIFICATIONS ===== */
.mobile-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 12px 20px;
    border-radius: 25px;
    font-size: 14px;
    z-index: 10000;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
    max-width: 80vw;
    text-align: center;
}

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

/* ===== TOUCH-FRIENDLY INPUTS ===== */
.mobile-enhanced input,
.mobile-enhanced textarea {
    min-height: var(--mobile-touch-target);
    padding: 12px 16px;
    border-radius: var(--mobile-border-radius);
    font-size: 16px; /* Prevent zoom on iOS */
    border: 2px solid #e0e0e0;
    transition: var(--mobile-transition);
}

.mobile-enhanced input:focus,
.mobile-enhanced textarea:focus {
    border-color: #4285f4;
    box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.1);
    outline: none;
}

.mobile-enhanced input.mobile-focused,
.mobile-enhanced textarea.mobile-focused {
    transform: scale(1.02);
    box-shadow: 0 4px 16px rgba(66, 133, 244, 0.2);
}

/* ===== TOUCH-FRIENDLY BUTTONS ===== */
.mobile-enhanced button {
    min-height: var(--mobile-touch-target);
    min-width: var(--mobile-touch-target);
    padding: 12px 20px;
    border-radius: var(--mobile-border-radius);
    font-size: 16px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: var(--mobile-transition);
    position: relative;
    overflow: hidden;
}

.mobile-enhanced button:active {
    transform: scale(0.98);
}

/* Touch ripple effect */
.mobile-enhanced button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.3s ease, height 0.3s ease;
    pointer-events: none;
}

.mobile-enhanced button:active::before {
    width: 200px;
    height: 200px;
}

/* ===== SWIPEABLE MESSAGES ===== */
.mobile-enhanced .message {
    position: relative;
    transition: transform 0.3s ease;
    border-radius: var(--mobile-border-radius);
    margin: 8px 0;
    padding: 16px;
}

.mobile-enhanced .message.swipe-left {
    transform: translateX(-60px);
}

.mobile-enhanced .message.swipe-right {
    transform: translateX(60px);
}

.message-actions {
    position: absolute;
    right: -60px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.message.swipe-left .message-actions {
    opacity: 1;
}

.message-action-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.message-action-btn.copy {
    background: #4285f4;
}

.message-action-btn.share {
    background: #34a853;
}

.message-action-btn.delete {
    background: #ea4335;
}

/* ===== KEYBOARD ADJUSTMENTS ===== */
.keyboard-open {
    --keyboard-offset: 0px;
}

.keyboard-open #chat-container {
    padding-bottom: var(--keyboard-offset);
    transition: padding-bottom 0.3s ease;
}

.keyboard-open .mobile-toolbar {
    bottom: calc(20px + var(--keyboard-offset));
    transition: bottom 0.3s ease;
}

/* ===== MOBILE MENU PANEL ===== */
.mobile-menu-panel {
    position: fixed;
    top: 0;
    left: -100%;
    width: 280px;
    height: 100vh;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    z-index: 9999;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 2px 0 20px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
}

.mobile-menu-panel.open {
    left: 0;
}

.mobile-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.mobile-menu-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.mobile-menu-header {
    padding: 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.mobile-menu-content {
    padding: 20px;
}

.mobile-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    cursor: pointer;
    transition: background 0.2s ease;
}

.mobile-menu-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* ===== BOTTOM SHEET ===== */
.bottom-sheet {
    position: fixed;
    bottom: -100%;
    left: 0;
    right: 0;
    background: white;
    border-radius: 20px 20px 0 0;
    z-index: 10000;
    transition: bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    max-height: 80vh;
    overflow-y: auto;
}

.bottom-sheet.open {
    bottom: 0;
}

.bottom-sheet-handle {
    width: 40px;
    height: 4px;
    background: #ccc;
    border-radius: 2px;
    margin: 12px auto 20px;
}

.bottom-sheet-content {
    padding: 0 20px 20px;
}

/* ===== MOBILE OPTIMIZED CHAT ===== */
.mobile-enhanced #chat-container {
    padding: var(--mobile-padding);
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.mobile-enhanced .message {
    font-size: 16px;
    line-height: 1.5;
    word-wrap: break-word;
    hyphens: auto;
}

.mobile-enhanced .message img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    cursor: pointer;
}

/* ===== MOBILE BRAIN PORTAL ===== */
.mobile-enhanced #brainPortal {
    margin: var(--mobile-padding);
    border-radius: var(--mobile-border-radius);
    max-height: 80vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.mobile-enhanced .brain-content {
    padding: var(--mobile-padding);
    font-size: 16px;
    line-height: 1.6;
}

/* ===== ACCESSIBILITY ENHANCEMENTS ===== */
.mobile-enhanced [role="button"],
.mobile-enhanced button {
    position: relative;
}

.mobile-enhanced [role="button"]:focus,
.mobile-enhanced button:focus {
    outline: 3px solid #4285f4;
    outline-offset: 2px;
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .mobile-enhanced button {
        border: 2px solid currentColor;
    }
    
    .mobile-tool-btn {
        border: 2px solid white;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .mobile-enhanced * {
        transition: none !important;
        animation: none !important;
    }
}

/* ===== LANDSCAPE ORIENTATION ===== */
@media (orientation: landscape) and (max-height: 500px) {
    .mobile-toolbar {
        flex-direction: row;
        bottom: 10px;
        right: 10px;
    }
    
    .mobile-enhanced #chat-container {
        max-height: calc(100vh - 120px);
    }
    
    .mobile-enhanced .input-container {
        padding: 8px var(--mobile-padding);
    }
}

/* ===== DEVICE-SPECIFIC OPTIMIZATIONS ===== */
/* iOS specific */
.platform-ios.mobile-enhanced {
    --mobile-border-radius: 10px;
}

.platform-ios .mobile-tool-btn {
    backdrop-filter: blur(20px);
    background: rgba(0, 0, 0, 0.7);
}

.platform-ios input,
.platform-ios textarea {
    -webkit-appearance: none;
    appearance: none;
    border-radius: 10px;
}

/* Android specific */
.platform-android.mobile-enhanced {
    --mobile-border-radius: 8px;
}

.platform-android .mobile-tool-btn {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.platform-android button {
    text-transform: uppercase;
    font-weight: 500;
    letter-spacing: 0.5px;
}

/* ===== DARK MODE SUPPORT ===== */
@media (prefers-color-scheme: dark) {
    .mobile-enhanced {
        color: #fff;
    }
    
    .mobile-enhanced input,
    .mobile-enhanced textarea {
        background: #2d2d2d;
        border-color: #444;
        color: #fff;
    }
    
    .mobile-enhanced input:focus,
    .mobile-enhanced textarea:focus {
        border-color: #4285f4;
        background: #333;
    }
    
    .mobile-menu-panel {
        background: rgba(30, 30, 30, 0.95);
        color: #fff;
    }
    
    .mobile-menu-item {
        border-bottom-color: rgba(255, 255, 255, 0.1);
    }
    
    .mobile-menu-item:hover {
        background: rgba(255, 255, 255, 0.1);
    }
    
    .bottom-sheet {
        background: #2d2d2d;
        color: #fff;
    }
    
    .mobile-toast {
        background: rgba(255, 255, 255, 0.9);
        color: #000;
    }
}

/* ===== RESPONSIVE BREAKPOINTS ===== */
@media (max-width: 480px) {
    .mobile-enhanced {
        --mobile-padding: 12px;
    }
    
    .mobile-toolbar {
        bottom: 15px;
        right: 15px;
        gap: 8px;
    }
    
    .mobile-tool-btn {
        width: 40px;
        height: 40px;
    }
}

@media (max-width: 360px) {
    .mobile-enhanced {
        --mobile-padding: 8px;
    }
    
    .mobile-enhanced .message {
        font-size: 14px;
        padding: 12px;
    }
    
    .mobile-menu-panel {
        width: 100%;
    }
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */
.mobile-enhanced * {
    /* Hardware acceleration for smooth animations */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Optimize scrolling performance */
.mobile-enhanced #chat-container,
.mobile-enhanced #brainPortal {
    contain: layout style paint;
    will-change: scroll-position;
}

/* Optimize touch interactions */
.mobile-enhanced button,
.mobile-enhanced [role="button"] {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* ===== LOADING STATES ===== */
.mobile-loading {
    position: relative;
    overflow: hidden;
}

.mobile-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* ===== SAFE AREA SUPPORT ===== */
@supports (padding: max(0px)) {
    .mobile-enhanced {
        padding-left: max(var(--mobile-padding), env(safe-area-inset-left));
        padding-right: max(var(--mobile-padding), env(safe-area-inset-right));
        padding-bottom: max(var(--mobile-padding), env(safe-area-inset-bottom));
    }
    
    .mobile-toolbar {
        bottom: max(20px, env(safe-area-inset-bottom));
        right: max(20px, env(safe-area-inset-right));
    }
}
