/* 
 * Mobile-First Responsive Styles
 * Optimized for touch devices and modern responsive design
 */

/* Mobile Menu Toggle Button */
.mobile-menu-toggle {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1001;
    background: #007bff;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
}

.mobile-menu-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: white;
    margin: 2px 0;
    transition: all 0.3s ease;
}

.mobile-menu-toggle:hover {
    background: #0056b3;
    transform: scale(1.05);
}

/* Mobile Menu Animation */
.menu-open .mobile-menu-toggle span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.menu-open .mobile-menu-toggle span:nth-child(2) {
    opacity: 0;
}

.menu-open .mobile-menu-toggle span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -6px);
}

/* Mobile Breakpoints */
@media (max-width: 768px) {
    .mobile-menu-toggle {
        display: flex;
    }
    
    /* Enhanced mobile layout */
    .chitchat-container {
        padding: 0;
    }
    
    /* Safe area for iOS devices */
    @supports (padding: max(0px)) {
        .chitchat-main {
            padding-top: max(20px, env(safe-area-inset-top));
            padding-bottom: max(20px, env(safe-area-inset-bottom));
        }
        
        .message-input {
            padding-bottom: max(10px, env(safe-area-inset-bottom));
        }
    }
    
    /* Improved touch targets */
    .messages .message-main {
        min-height: 44px;
        touch-action: manipulation;
    }
    
    /* Virtual keyboard handling */
    .keyboard-open .chitchat-main {
        height: 50vh;
    }
    
    .keyboard-open .messages {
        max-height: calc(50vh - 100px);
    }
}

/* Tablet Breakpoints */
@media (min-width: 769px) and (max-width: 1024px) {
    .chitchat-main .messages {
        padding: 20px;
    }
    
    .message-input {
        padding: 15px 20px;
    }
}

/* High-DPI Display Optimizations */
@media (-webkit-min-device-pixel-ratio: 2),
       (min-resolution: 192dpi),
       (min-resolution: 2dppx) {
    .mobile-menu-toggle {
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    }
}

/* Landscape Orientation */
@media (orientation: landscape) and (max-height: 500px) {
    .chitchat-main .messages {
        max-height: calc(100vh - 120px);
    }
    
    .message-input {
        padding: 8px 15px;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .mobile-menu-toggle,
    .mobile-menu-toggle span,
    .main-nav {
        transition: none;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .mobile-menu-toggle {
        background: #1a1a1a;
        color: white;
    }
    
    .mobile-menu-toggle:hover {
        background: #333;
    }
    
    .mobile-overlay {
        background: rgba(0, 0, 0, 0.8);
    }
}

/* Large Touch Targets */
@media (pointer: coarse) {
    .btn, 
    .form-control, 
    .message-input button,
    .messages .message-main {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Increase spacing for easier touch */
    .form-group {
        margin-bottom: 20px;
    }
}

/* Print Styles */
@media print {
    .mobile-menu-toggle,
    .mobile-overlay,
    .message-input {
        display: none !important;
    }
    
    .messages .message-main {
        page-break-inside: avoid;
        margin-bottom: 10px;
    }
}

/* Custom Scrollbar for Mobile */
@media (max-width: 768px) {
    .messages::-webkit-scrollbar {
        width: 6px;
    }
    
    .messages::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 10px;
    }
    
    .messages::-webkit-scrollbar-thumb {
        background: #888;
        border-radius: 10px;
    }
    
    .messages::-webkit-scrollbar-thumb:hover {
        background: #555;
    }
}

/* Accessibility Improvements */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus indicators */
.mobile-menu-toggle:focus,
.message-input input:focus,
.btn:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* Loading states */
.chitchat-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.chitchat-loader img {
    max-width: 100px;
    height: auto;
}

/* Mobile-specific animations */
@keyframes slideInFromLeft {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.main-nav.on {
    animation: slideInFromLeft 0.3s ease-out;
}

.mobile-overlay.active {
    animation: fadeIn 0.3s ease-out;
}