/* Responsive CSS Improvements for Kontexto Chat and Service Center */

/* ========================================
   Mobile First Approach - Base Styles
   ======================================== */

/* General Improvements */
* {
    -webkit-tap-highlight-color: transparent;
}

/* Prevent horizontal scroll on mobile */
html, body {
    overflow-x: hidden;
    max-width: 100%;
}

/* Better touch targets for mobile */
.btn {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.dropdown-item {
    min-height: 44px;
    padding: 0.5rem 1rem;
}

/* ========================================
   Chat Page Responsive Improvements
   ======================================== */

/* Mobile Navigation Toggle */
.mobile-nav-toggle {
    display: none;
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 1001;
    background: var(--whatsapp-header-green);
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* Sidebar Improvements */
.sidebar {
    transition: transform 0.3s ease-in-out;
    will-change: transform;
}

/* Chat Area Improvements */
.chat-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--whatsapp-panel-header);
}

.messages-container {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Message Input Area */
.message-input-container {
    position: sticky;
    bottom: 0;
    background: var(--whatsapp-panel-header);
    padding: 0.5rem;
}

/* Input buttons alignment */
.input-group button.btn {
    padding: 0.375rem 0.5rem;
    border: none;
    background: transparent;
    color: #54656F;
}

.input-group button.btn:hover {
    color: var(--whatsapp-teal);
}

/* Voice button specific styling */
#voiceButton {
    transition: color 0.2s ease;
}

#voiceButton:hover {
    color: var(--whatsapp-green);
}

/* File Upload Buttons */
.file-upload-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* ========================================
   Service Page Responsive Improvements
   ======================================== */

.service-sidebar {
    transition: transform 0.3s ease-in-out;
}

.channel-item {
    cursor: pointer;
    transition: all 0.2s ease;
}

.channel-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* ========================================
   Tablet Styles (768px - 991px)
   ======================================== */
@media (min-width: 768px) and (max-width: 991px) {
    /* Chat Sidebar */
    .sidebar {
        width: 350px;
        flex: 0 0 350px;
    }
    
    /* Adjust font sizes */
    body {
        font-size: 15px;
    }
    
    .chat-message {
        max-width: 80%;
    }
}

/* ========================================
   Mobile Styles (max-width: 767px)
   ======================================== */
@media (max-width: 767px) {
    /* Show mobile navigation toggle */
    .mobile-nav-toggle {
        display: flex;
    }
    
    /* Chat Page Mobile Layout */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        transform: translateX(-100%);
        z-index: 1000;
    }
    
    .sidebar.mobile-open {
        transform: translateX(0);
    }
    
    /* Overlay for sidebar */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 999;
    }
    
    .sidebar-overlay.show {
        display: block;
    }
    
    /* Chat area takes full width on mobile */
    .chat-area {
        width: 100%;
        padding-left: 0 !important;
    }
    
    /* Adjust chat header for mobile */
    .chat-header {
        padding: 0.5rem;
        padding-left: 0.5rem;
    }

    /* Mobile back button */
    .mobile-back-btn {
        color: var(--whatsapp-teal, #128C7E);
        font-size: 1.2rem;
        min-width: 36px !important;
        min-height: 36px !important;
        padding: 0;
    }
    
    .chat-header .user-info h6 {
        font-size: 1rem;
    }
    
    /* Message improvements */
    .chat-message {
        max-width: 85%;
        font-size: 0.9rem;
    }
    
    .message-time {
        font-size: 0.7rem;
    }
    
    /* Input area adjustments */
    .message-input-container {
        padding: 0.5rem;
    }
    
    #messageInput {
        font-size: 16px; /* Prevent zoom on iOS */
    }

    /* Make buttons slightly smaller on mobile */
    .chat-input-group .chat-input-btn {
        padding: 4px 8px;
        font-size: 0.9rem;
    }
    
    /* Dropdown menus */
    .dropdown-menu {
        max-height: 70vh;
        overflow-y: auto;
    }
    
    /* Modal improvements */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        max-height: calc(100vh - 1rem);
        overflow-y: auto;
    }
    
    /* Service Page Mobile Layout */
    #serviceChannels {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        transform: translateX(-100%);
        z-index: 1000;
        background: white;
        transition: transform 0.3s ease-in-out;
    }
    
    #serviceChannels.mobile-open {
        transform: translateX(0);
    }
    
    .service-sidebar {
        height: 100%;
        background: var(--whatsapp-sidebar-bg);
    }
    
    .service-content {
        width: 100%;
        padding: 1rem;
    }
    
    /* Service header adjustments */
    .service-header {
        position: sticky;
        top: 0;
        background: white;
        z-index: 100;
    }
    
    .service-header h5 {
        font-size: 1.1rem;
    }
    
    /* Channel items */
    .channel-item {
        padding: 0.75rem !important;
    }
    
    .channel-item h6 {
        font-size: 0.95rem;
    }
    
    /* Active requests */
    .request-item {
        font-size: 0.9rem;
    }
    
    /* Buttons in service page */
    .request-service {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }
}

/* ========================================
   Small Mobile Styles (max-width: 575px)
   ======================================== */
@media (max-width: 575px) {
    /* Further reduce padding and margins */
    .container-fluid {
        padding: 0;
    }
    
    /* Chat bubbles */
    .chat-message {
        max-width: 90%;
        padding: 0.5rem 0.75rem;
    }
    
    /* User profile section */
    .user-profile-section {
        padding: 0.5rem;
    }
    
    .user-profile-section h6 {
        font-size: 0.9rem;
    }
    
    /* Search input */
    #searchInput {
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    /* File upload preview */
    .file-preview {
        max-width: 150px;
        max-height: 150px;
    }
    
    /* Emoji picker */
    .emoji-picker {
        width: 100%;
        max-width: 300px;
        left: 50% !important;
        transform: translateX(-50%);
    }
}

/* ========================================
   Landscape Mobile Styles
   ======================================== */
@media (max-width: 767px) and (orientation: landscape) {
    /* Reduce vertical space usage */
    .chat-header {
        padding: 0.25rem 0.5rem;
    }
    
    .message-input-container {
        padding: 0.25rem 0.5rem;
    }
    
    /* Hide less important elements */
    .user-profile-section small {
        display: none;
    }
    
    /* Reduce message container height */
    .messages-container {
        max-height: calc(100vh - 100px);
    }
}

/* ========================================
   Touch Device Improvements
   ======================================== */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .chat-item, .channel-item {
        min-height: 60px;
    }
    
    /* Remove hover effects on touch devices */
    .chat-item:hover, .channel-item:hover {
        transform: none;
        box-shadow: none;
    }
    
    /* Add active states instead */
    .chat-item:active, .channel-item:active {
        background-color: var(--whatsapp-hover);
    }
    
    /* Scrollbar improvements for touch */
    ::-webkit-scrollbar {
        width: 3px;
    }
}

/* ========================================
   Dark Theme Responsive Adjustments
   ======================================== */
body.dark-theme .mobile-nav-toggle,
body.dark .mobile-nav-toggle {
    background: var(--whatsapp-dark-header);
}

body.dark-theme .sidebar-overlay,
body.dark .sidebar-overlay {
    background: rgba(0,0,0,0.7);
}

body.dark-theme .service-sidebar,
body.dark .service-sidebar {
    background: var(--whatsapp-dark-sidebar);
}

body.dark-theme .service-header,
body.dark .service-header {
    background: var(--whatsapp-dark-header);
}

/* ========================================
   Form and Input Improvements
   ======================================== */
@media (max-width: 767px) {
    /* Prevent zoom on input focus in iOS */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="tel"],
    input[type="url"],
    textarea,
    select {
        font-size: 16px !important;
    }
    
    /* Better form spacing */
    .form-group, .mb-3 {
        margin-bottom: 1rem !important;
    }
    
    /* Modal form improvements */
    .modal-body {
        padding: 1rem;
    }
    
    .modal-footer {
        padding: 0.75rem;
    }
    
    /* Button spacing in forms */
    .modal-footer .btn {
        margin: 0.25rem;
    }
}

/* ========================================
   Scroll Improvements
   ======================================== */
@supports (-webkit-overflow-scrolling: touch) {
    .messages-container,
    .chat-list,
    .channels-list,
    .modal-body {
        -webkit-overflow-scrolling: touch;
    }
}

/* ========================================
   Accessibility Improvements
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ========================================
   Performance Optimizations
   ======================================== */
@media (max-width: 767px) {
    /* Disable animations on mobile for better performance */
    *, *::before, *::after {
        animation-duration: 0.3s !important;
        transition-duration: 0.3s !important;
    }
    
    /* Use GPU acceleration for transforms */
    .sidebar, #serviceChannels {
        transform: translateX(-100%) translateZ(0);
        -webkit-transform: translateX(-100%) translateZ(0);
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
    }
    
    .sidebar.mobile-open, #serviceChannels.mobile-open {
        transform: translateX(0) translateZ(0);
        -webkit-transform: translateX(0) translateZ(0);
    }
    
    /* Optimize repaints */
    .chat-message {
        will-change: transform;
    }
    
    /* Reduce shadow complexity on mobile */
    .card, .modal-content, .dropdown-menu {
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
}