/*
* Prefixed by https://autoprefixer.github.io
* PostCSS: v8.4.14,
* Autoprefixer: v10.4.7
* Browsers: last 4 version
*/

/* =======================================
    GLOBAL RESPONSIVE IMPROVEMENTS
======================================= */

/* Fluid scaling for fonts & elements */
html {
    font-size: clamp(15px, 1.2vw + 12px, 20px);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
}

/* Performance optimizations for mobile tap */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* =======================================
    UNIVERSAL MOBILE SETTINGS (≤ 768px)
======================================= */
@media (max-width: 768px) {

    /* CRITICAL FIX: KEYBOARD & LAYOUT
       Using 100dvh ensures the window resizes when the keyboard opens.
    */
    .chat-window {
        position: fixed !important;
        inset: 0 !important;
        width: 100vw !important;
        height: 100dvh !important;
        /* Adapts to keyboard height */
        max-height: 100dvh !important;
        border-radius: 0 !important;
        margin: 0 !important;
        z-index: 9999;
        -webkit-box-orient: vertical !important;
        -webkit-box-direction: normal !important;
        -ms-flex-direction: column !important;
        flex-direction: column !important;

        /* GPU Acceleration */
        will-change: transform, opacity;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        -webkit-perspective: 1000px;
        perspective: 1000px;
    }

    /* Enhanced chat header */
    .chat-header {
        padding: 16px clamp(14px, 5vw, 24px);
        min-height: 65px;
        -ms-flex-negative: 0;
        flex-shrink: 0;
        /* Prevents header from squishing */
    }

    .header-left sedo-h2 {
        font-size: clamp(1.3rem, 5vw, 1.5rem);
        line-height: 1.3;
        font-weight: 600;
    }

    .online-status {
        font-size: clamp(0.8rem, 3vw, 0.9rem);
        line-height: 1.4;
    }

    /* Hide chat icon when window is active */
    .chat-window.active~.chat-icon {
        opacity: 0;
        visibility: hidden;
        -webkit-transform: scale(0.6);
        -ms-transform: scale(0.6);
        transform: scale(0.6);
        -webkit-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
        -o-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
        transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* QA Grid System */
    .qa-grid {
        display: -ms-grid;
        display: grid;
        -ms-grid-columns: 1fr clamp(10px, 3.5vw, 18px) 1fr clamp(10px, 3.5vw, 18px) 1fr;
        grid-template-columns: repeat(3, 1fr);
        gap: clamp(10px, 3.5vw, 18px);
        grid-auto-rows: minmax(100px, auto);
    }

    /* Messages Area */
    .chat-messages {
        -webkit-box-flex: 1;
        -ms-flex: 1;
        flex: 1;
        /* Takes up all available space between header and input */
        padding: clamp(14px, 4vw, 22px);
        gap: 14px;
        overflow-y: auto;
    }

    .message {
        max-width: 94%;
        padding: clamp(12px, 2.5vw, 18px);
        font-size: clamp(0.95rem, 3.5vw, 1.1rem);
        line-height: 1.5;
    }

    .message-time {
        font-size: clamp(0.7rem, 2.5vw, 0.85rem);
    }

    .chat-input-container {
        -ms-flex-negative: 0;
        flex-shrink: 0;
        z-index: 10000;
    }

    .chat-input {
        padding: 14px 18px;
        font-size: clamp(0.95rem, 3.5vw, 1.1rem);
        min-height: 50px;
    }

    .send-btn {
        width: 48px;
        height: 48px;
        min-width: 48px;
        min-height: 48px;
        -ms-flex-negative: 0;
        flex-shrink: 0;
    }

    .chat-icon {
        width: 55px !important;
        height: 55px !important;
        right: 20px !important;
        /* Adjusted spacing from edge */
        bottom: 20px !important;
        /* Adjusted spacing from bottom */
    }

    .chat-icon i {
        font-size: 24px !important;
        /* Smaller icon inside the bubble */
    }

    /* Scrollbars */
    .chat-messages::-webkit-scrollbar,
    .qa-grid::-webkit-scrollbar {
        width: 5px;
    }

    .chat-messages::-webkit-scrollbar-thumb,
    .qa-grid::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.25);
        border-radius: 3px;
    }
}

/* =======================================
    MOBILE BREAKDOWN BY WIDTH
======================================= */

/* Medium mobile (481px–768px) */
@media (min-width: 481px) and (max-width: 768px) {
    .qa-grid {
        -ms-grid-columns: 1fr clamp(12px, 3vw, 16px) 1fr clamp(12px, 3vw, 16px) 1fr;
        grid-template-columns: repeat(3, 1fr);
        gap: clamp(12px, 3vw, 16px);
    }
}

/* Small mobile (≤ 480px) */
@media (max-width: 480px) {
    .qa-grid {
        -ms-grid-columns: 1fr clamp(10px, 3vw, 14px) 1fr !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: clamp(10px, 3vw, 14px);
    }

    .chat-header {
        padding: 14px clamp(12px, 4vw, 16px);
        min-height: 60px;
    }

    .header-left sedo-h2 {
        font-size: clamp(1.2rem, 4.5vw, 1.4rem);
    }

    .header-btn,
    .close-btn {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
    }
}

/* Extra-small mobile (≤ 432px) */
@media (max-width: 432px) {
    .qa-grid {
        -ms-grid-columns: 1fr !important;
        grid-template-columns: 1fr !important;
        gap: clamp(8px, 2.5vw, 12px);
    }

    .chat-header {
        padding: 12px 14px;
        min-height: 55px;
    }

    .header-left sedo-h2 {
        font-size: 1.25rem;
    }

    .header-btn,
    .close-btn {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }

    .chat-messages {
        padding: 12px 14px;
    }

    .message {
        max-width: 96%;
        padding: 12px 16px;
        font-size: 1rem;
    }

    .chat-input {
        padding: 12px 16px;
        font-size: 1rem;
    }

    .send-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }
}

/* Ultra small mobile (≤ 280px) */
@media (max-width: 280px) {
    .qa-grid {
        gap: 8px;
    }

    .chat-header,
    .chat-messages,
    .chat-input-container {
        padding: 10px 12px;
    }
}

/* =======================================
    LANDSCAPE & SAFE AREA OPTIMIZATIONS
======================================= */
@media (max-width: 768px) and (orientation: landscape),
(max-height: 500px) and (max-width: 768px) {
    .qa-grid {
        -ms-grid-columns: 1fr 10px 1fr 10px 1fr !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 10px;
        grid-auto-rows: minmax(75px, auto);
    }

    .chat-header {
        padding: 8px 14px;
        min-height: 45px;
    }

    .chat-messages {
        padding: 10px 14px;
    }
}

/* Safe Area Support (iPhone Notch/Home Bar) */
@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        .chat-window {
            padding-top: max(0px, env(safe-area-inset-top, 0px));
            padding-left: max(0px, env(safe-area-inset-left, 0px));
            padding-right: max(0px, env(safe-area-inset-right, 0px));
            /* Note: Bottom padding is handled in input-container */
        }
    }
}

/* =======================================
    TOUCH & ANIMATIONS
======================================= */
@media (hover: none) and (pointer: coarse) {

    .action-btn,
    .header-btn,
    .close-btn {
        min-width: 44px;
        min-height: 44px;
        cursor: pointer;
    }

    .action-btn:active,
    .header-btn:active,
    .close-btn:active {
        -webkit-transform: scale(0.95);
        -ms-transform: scale(0.95);
        transform: scale(0.95);
    }
}

@media (max-width: 768px) {
    .chat-window.active {
        -webkit-animation: slideUp 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
        animation: slideUp 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    }

    .chat-window.closing {
        -webkit-animation: slideDown 0.25s cubic-bezier(0.4, 0, 1, 1) forwards;
        animation: slideDown 0.25s cubic-bezier(0.4, 0, 1, 1) forwards;
    }

    @-webkit-keyframes slideUp {
        from {
            -webkit-transform: translateY(100%);
            transform: translateY(100%);
            opacity: 0;
        }

        to {
            -webkit-transform: translateY(0);
            transform: translateY(0);
            opacity: 1;
        }
    }

    @keyframes slideUp {
        from {
            -webkit-transform: translateY(100%);
            transform: translateY(100%);
            opacity: 0;
        }

        to {
            -webkit-transform: translateY(0);
            transform: translateY(0);
            opacity: 1;
        }
    }

    @-webkit-keyframes slideDown {
        from {
            -webkit-transform: translateY(0);
            transform: translateY(0);
            opacity: 1;
        }

        to {
            -webkit-transform: translateY(100%);
            transform: translateY(100%);
            opacity: 0;
        }
    }

    @keyframes slideDown {
        from {
            -webkit-transform: translateY(0);
            transform: translateY(0);
            opacity: 1;
        }

        to {
            -webkit-transform: translateY(100%);
            transform: translateY(100%);
            opacity: 0;
        }
    }
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        -webkit-animation-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        -webkit-transition-duration: 0.01ms !important;
        -o-transition-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}