/* 1. Global Overrides - RESTORED APP SHELL */
html {
    margin: 0;
    padding: 0;
    height: 100%;
}

body.chat-page {
    height: 100vh;
    width: 100%;
    margin: 0;
    overflow: hidden !important;
    padding-top: 0 !important;
}

@media (max-width: 1024px) {
    body.chat-page {
        padding-top: 0 !important;
        /* Force override style.css media query */
    }
}

body.chat-page header {
    display: none !important;
}

body.chat-page .bg-orb,
body.chat-page #toast-container {
    display: block !important;
}

/* Restore Container — full width */
.chat-page-container {
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 100vh !important;
    margin: 0 !important;
    display: flex;
    justify-content: stretch;
    align-items: stretch !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
}

/* Override any .container class if it exists on chat page */
body.chat-page .container {
    max-width: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* 2. Chat Layout Container - full width, header bhi same */
body.chat-page .chat-container,
.chat-container {
    /* Full width: header aur input edge-to-edge, padding nahi */
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    height: 100%;
    display: flex;
    flex-direction: column;
    background-color: #efeae2;
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
    background-repeat: repeat;
    background-size: 400px;
    position: relative;
    z-index: 1;
    border-radius: 0 0 20px 20px;
    /* Flat top */
    overflow: hidden !important;
    /* Ensure internal scroll */
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-top: none;
    /* No top border */
    max-height: none !important;
    height: 100% !important;
    border-radius: 0 !important;
    box-sizing: border-box;


    /* Overlay to tint the doodle background properly */
    .chat-container::before {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(229, 221, 213, 0.9);
        /* Beige tint strength */
        z-index: -1;
    }

    /* 3. Header Styling */
    .wa-chat-header {
        height: 60px;
        background-color: #008069;
        /* WhatsApp Teal Green */
        display: flex;
        align-items: center;
        padding: 10px 16px;
        color: white;
        flex-shrink: 0;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
        z-index: 100;
    }

    .wa-back-btn {
        background: none;
        border: none;
        color: white;
        cursor: pointer;
        margin-right: 8px;
        padding: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        transition: background-color 0.2s ease;
        min-width: 40px;
        min-height: 40px;
    }

    .wa-back-btn:hover {
        background-color: rgba(255, 255, 255, 0.1);
    }

    .wa-back-btn:active {
        background-color: rgba(255, 255, 255, 0.15);
    }

    .wa-back-btn svg {
        width: 24px;
        height: 24px;
    }

    .wa-avatar-circle {
        width: 42px;
        height: 42px;
        border-radius: 50%;
        margin-right: 12px;
        overflow: hidden;
        background: #ccc;
        cursor: pointer;
        border: 2px solid rgba(255, 255, 255, 0.2);
        transition: transform 0.2s ease, border-color 0.2s ease;
        flex-shrink: 0;
    }

    .wa-avatar-circle:hover {
        transform: scale(1.05);
        border-color: rgba(255, 255, 255, 0.3);
    }

    .wa-avatar-circle img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .wa-header-left {
        display: flex;
        align-items: center;
        flex: 1;
        cursor: pointer;
    }

    .wa-header-text {
        display: flex;
        flex-direction: column;
    }

    .wa-contact-name {
        font-size: 16px;
        font-weight: 500;
        line-height: 1.2;
    }

    .wa-contact-status {
        font-size: 13px;
        opacity: 0.8;
        line-height: 1.2;
    }

    .wa-header-actions {
        display: flex;
        gap: 4px;
        align-items: center;
        flex-shrink: 0;
    }

    .wa-action-btn {
        background: none;
        border: none;
        color: white;
        cursor: pointer;
        padding: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        transition: background-color 0.2s ease, transform 0.1s ease;
        min-width: 44px;
        min-height: 44px;
        opacity: 1;
    }

    .wa-action-btn:hover {
        background-color: rgba(255, 255, 255, 0.15);
        opacity: 1;
    }

    .wa-action-btn:active {
        background-color: rgba(255, 255, 255, 0.2);
        transform: scale(0.95);
    }

    .wa-action-btn svg {
        width: 22px;
        height: 22px;
        flex-shrink: 0;
        transition: transform 0.2s ease;
    }

    .wa-action-btn:hover svg {
        transform: scale(1.05);
    }

    /* 4. Messages Area */
    #chat-messages {
        flex: 1;
        overflow-y: auto;
        padding: 20px 5% 80px;
        /* Increased bottom padding to prevent content from being hidden behind input */
        display: flex;
        flex-direction: column;
        gap: 8px;
        /* Gap between messages */
        scroll-behavior: smooth;
        /* Custom Scrollbar for messages */
        scrollbar-width: thin;
        scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
    }

    #chat-messages::-webkit-scrollbar {
        width: 6px;
    }

    #chat-messages::-webkit-scrollbar-thumb {
        background-color: rgba(0, 0, 0, 0.2);
    }

    /* 5. Date Divider */
    .wa-date-divider {
        text-align: center;
        margin: 10px 0;
        display: flex;
        justify-content: center;
    }

    .wa-date-divider span {
        background: #dcf8c6;
        /* Light green tint or white */
        background: rgba(255, 255, 255, 0.9);
        color: #555;
        padding: 5px 12px;
        border-radius: 8px;
        font-size: 12.5px;
        box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
    }

    /* 6. Encryption Msg */
    .wa-encryption-msg {
        text-align: center;
        font-size: 12.5px;
        color: #555;
        background: rgba(254, 229, 114, 0.9);
        /* Yellowish system msg */
        padding: 5px 12px;
        border-radius: 8px;
        margin: 10px auto;
        max-width: 90%;
        box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
        align-self: center;
    }

    /* 7. Message Bubbles */
    .chat-message {
        max-width: 75%;
        /* Limit width */
        padding: 6px 7px 8px 9px;
        border-radius: 8px;
        font-size: 14.2px;
        line-height: 19px;
        color: #111b21;
        position: relative;
        box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
        word-wrap: break-word;
        display: flex;
        flex-direction: column;
    }

    /* Incoming (AI) */
    .chat-message.ai {
        align-self: flex-start;
        background: #ffffff;
        border-top-left-radius: 0;
        margin-left: 10px;
        /* For tail */
    }

    /* Incoming Tail */
    .chat-message.ai::before {
        content: "";
        position: absolute;
        top: 0;
        left: -8px;
        width: 0;
        height: 0;
        border: 8px solid transparent;
        border-top-color: #ffffff;
        border-right-color: #ffffff;
        border-bottom: none;
        transform: skew(-15deg);
    }

    /* Outgoing (User) */
    .chat-message.user {
        align-self: flex-end;
        background: #d9fdd3;
        /* WhatsApp Green */
        border-top-right-radius: 0;
        margin-right: 10px;
        /* For tail */
    }

    /* Outgoing Tail */
    .chat-message.user::before {
        content: "";
        position: absolute;
        top: 0;
        right: -8px;
        width: 0;
        height: 0;
        border: 8px solid transparent;
        border-top-color: #d9fdd3;
        border-left-color: #d9fdd3;
        border-bottom: none;
        transform: skew(15deg);
    }

    .msg-text {
        margin-bottom: 0px;
        /* Adjusted to fit time next to it if short, or below */
        padding-right: 10px;
        /* Space for time if inline potentially, but block is safer */
    }

    .msg-meta {
        font-size: 11px;
        color: #667781;
        text-align: right;
        margin-top: -4px;
        /* Pull up closer */
        margin-bottom: -2px;
        align-self: flex-end;
        display: flex;
        align-items: center;
        gap: 3px;
        float: right;
        /* Use float for wrapping text effect like WA */
        margin-left: 8px;
        height: 15px;
    }

    /* Checkmarks (ticks) */
    .msg-ticks {
        width: 16px;
        height: 16px;
        display: inline-block;
        background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 15" width="16" height="15"><path fill="%234FC3F7" d="M15.01 3.316l-.478-.372a.365.365 0 0 0-.51.063L8.666 9.879a.32.32 0 0 1-.484.033l-.358-.325a.319.319 0 0 0-.484.032l-.378.483a.418.418 0 0 0 .036.541l1.32 1.283a.419.419 0 0 0 .575-.035l6.232-7.538a.418.418 0 0 0-.117-.638v.001z"/><path fill="%234FC3F7" d="M6.154 3.316l-.478-.372a.365.365 0 0 0-.51.063L.666 9.879a.32.32 0 0 1-.484.033l-.358-.325a.319.319 0 0 0-.484.032l-.378.483a.418.418 0 0 0 .036.541l1.32 1.283a.419.419 0 0 0 .575-.035l6.232-7.538a.418.418 0 0 0-.117-.638v.001z"/></svg>');
        /* Blue double tick SVG data URI */
        background-repeat: no-repeat;
        background-position: center;
    }

    /* Hide user avatar in chat as WhatsApp doesn't show it next to message bubbles */
    .chat-avatar-icon {
        display: none !important;
    }

    /* Dark background for chat area as per screenshot */
    .chat-container {
        background-color: #0b141a;
        /* WhatsApp Dark Mode Background */
        background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
        background-blend-mode: overlay;
    }

    .chat-container::before {
        background-color: rgba(11, 20, 26, 0.9);
        /* Dark tint */
    }

    /* Message bar — header jaisa: same green, same design */
    .chat-input-area {
        flex-shrink: 0;
        position: relative;
        bottom: auto;
        left: auto;
        transform: none;
        width: 100%;
        max-width: 100%;
        background-color: #008069;
        padding: 10px 16px;
        border-radius: 0;
        box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.2);
        z-index: 100;
        min-height: 60px;
        border: none;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        display: flex !important;
        align-items: center !important;
        justify-content: center;
        margin: 0;
        color: white;
    }

    /* Adjust Message Area to compensate for docked footer */
    /* Adjust Message Area to compensate for docked footer */
    #chat-messages {
        flex: 1 1 0;
        /* Grow, shrink, base 0 */
        min-height: 0;
        /* Enable scrolling */
        overflow-y: auto;
        /* Internal Scroll */
        padding: 20px 5% 80px;
        /* Increased bottom padding to prevent content from being hidden */
        display: flex;
        flex-direction: column;
        gap: 8px;
        scroll-behavior: smooth;
        height: auto;
    }

    .wa-input-container {
        display: flex !important;
        /* Force flex */
        flex-direction: row !important;
        /* Force row */
        align-items: center !important;
        width: 100%;
        gap: 8px;
        /* Clean gap */
        background: transparent;
        padding: 0;
        margin: 0;
    }

    /* Mobile: Adjust icon sizes and spacing */
    @media (max-width: 768px) {
        .wa-icon-btn,
        .wa-mic-btn,
        .wa-send-btn {
            width: 40px;
            height: 40px;
            min-width: 40px;
            min-height: 40px;
        }

        .wa-icon-btn svg,
        .wa-mic-btn svg,
        .wa-send-btn svg {
            width: 20px;
            height: 20px;
        }

        .wa-input-container {
            gap: 6px;
        }

        .wa-back-btn {
            min-width: 36px;
            min-height: 36px;
            padding: 6px;
        }

        .wa-action-btn {
            min-width: 36px;
            min-height: 36px;
            padding: 6px;
        }

        .wa-action-btn svg {
            width: 20px;
            height: 20px;
        }
    }

    /* Icons styling */
    /* Icons — header jaisa white */
    .wa-icon-btn,
    .wa-mic-btn,
    .wa-send-btn {
        flex-shrink: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 42px;
        height: 42px;
        min-width: 42px;
        min-height: 42px;
        border-radius: 50%;
        background: transparent;
        color: white;
        border: none;
        padding: 0;
        margin: 0;
        cursor: pointer;
        transition: all 0.2s ease;
        position: relative;
    }

    .wa-icon-btn:hover,
    .wa-mic-btn:hover,
    .wa-send-btn:hover {
        background: rgba(255, 255, 255, 0.1);
        transform: scale(1.05);
    }

    .wa-icon-btn:active,
    .wa-mic-btn:active,
    .wa-send-btn:active {
        background: rgba(255, 255, 255, 0.15);
        transform: scale(0.95);
    }

    .wa-icon-btn svg,
    .wa-mic-btn svg,
    .wa-send-btn svg {
        width: 22px;
        height: 22px;
        transition: transform 0.2s ease;
    }

    /* Input field — header ke saath match, light box on green */
    .wa-input-wrapper {
        flex: 1;
        background: rgba(255, 255, 255, 0.2);
        border-radius: 24px;
        padding: 0 16px;
        display: flex;
        align-items: center;
        height: 42px;
        margin: 0;
        border: none;
        transition: background-color 0.2s ease, box-shadow 0.2s ease;
    }

    .wa-input-wrapper:focus-within {
        background: rgba(255, 255, 255, 0.25);
        box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
    }

    .wa-input-wrapper input {
        width: 100%;
        background: transparent;
        border: none;
        color: white;
        font-size: 15px;
        outline: none;
        padding: 0;
        margin: 0;
        height: 100%;
    }

    .wa-input-wrapper input::placeholder {
        color: rgba(255, 255, 255, 0.75);
    }

    /* Hide specific icons if needed or adjust layout */
    .emoji-btn svg,
    .attach-btn svg,
    .camera-btn svg {
        pointer-events: none;
        /* Let click pass to button */
    }

    /* Adjust messages padding for floating input */
    /* Adjust messages padding for floating input - REMOVED */
    #chat-messages {
        /* Padding handled in main block */
        scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
    }

    /* Update ticks for dark mode */
    .msg-meta {
        color: rgba(255, 255, 255, 0.6);
    }

    .chat-message.ai {
        background: #202c33;
        color: white;
    }

    .chat-message.ai::before {
        border-top-color: #202c33;
        border-right-color: #202c33;
    }

    .chat-message.user {
        background: #005c4b;
        /* Dark Green */
        color: white;
    }

    .chat-message.user::before {
        border-top-color: #005c4b;
        border-left-color: #005c4b;
    }

    /* Date divider dark mode */
    .wa-date-divider span {
        background: #182229;
        color: #8696a0;
        box-shadow: none;
        border: 1px solid rgba(255, 255, 255, 0.05);
    }

    /* Encryption msg dark mode */
    .wa-encryption-msg {
        background: #182229;
        color: #FFD279;
        box-shadow: none;
        border: 1px solid rgba(255, 255, 255, 0.05);
    }

    /* Header Text Color */
    .wa-contact-name {
        color: white !important;
    }

    .wa-contact-status {
        color: rgba(255, 255, 255, 0.7) !important;
    }

    /* Desktop: full width — header aur container dono viewport bhar */
    @media (min-width: 1025px) {
        .chat-page-container {
            max-width: 100% !important;
            margin: 0 !important;
            padding: 0 !important;
            justify-content: stretch !important;
        }
        
        .chat-container {
            max-width: 100% !important;
            width: 100% !important;
            margin: 0 !important;
        }
    }
    
    /* Tablet: Full Width */
    @media (max-width: 1024px) and (min-width: 769px) {
        .chat-page-container {
            width: 100% !important;
            max-width: 100% !important;
            padding: 0 !important;
        }
        
        .chat-container {
            max-width: 100% !important;
            width: 100% !important;
            margin: 0 !important;
        }
    }

    /* NUCLEAR MOBILE FIX - Force everything to full width and height */
    @media (max-width: 768px) {

        html,
        html body,
        html body.chat-page {
            width: 100vw !important;
            max-width: 100vw !important;
            min-width: 100vw !important;
            height: 100vh !important;
            max-height: 100vh !important;
            min-height: 100vh !important;
            padding: 0 !important;
            margin: 0 !important;
            overflow-x: hidden !important;
            overflow-y: hidden !important;
            position: fixed !important;
            top: 0 !important;
            left: 0 !important;
            right: 0 !important;
            bottom: 0 !important;
        }

        /* Target all variations to be bulletproof */
        .chat-page-container,
        body.chat-page .chat-page-container,
        body.chat-page .container,
        body.chat-page .container.chat-page-container {
            padding: 0 !important;
            margin: 0 !important;
            height: 100vh !important;
            max-height: 100vh !important;
            min-height: 100vh !important;
            width: 100vw !important;
            max-width: 100vw !important;
            min-width: 100vw !important;
            left: 0 !important;
            right: 0 !important;
            top: 0 !important;
            bottom: 0 !important;
            position: fixed !important;
            box-sizing: border-box !important;
        }
        
        .chat-container {
            max-width: 100vw !important;
            width: 100vw !important;
            height: 100vh !important;
            max-height: 100vh !important;
            min-height: 100vh !important;
            margin: 0 !important;
            padding: 0 !important;
            border-radius: 0 !important;
            position: fixed !important;
            top: 0 !important;
            left: 0 !important;
            right: 0 !important;
            bottom: 0 !important;
            box-sizing: border-box !important;
        }

        .chat-input-area {
            border-radius: 0 !important;
            width: 100vw !important;
            max-width: 100vw !important;
            position: fixed !important;
            bottom: 0 !important;
            left: 0 !important;
            right: 0 !important;
            box-sizing: border-box !important;
        }

                #chat-messages {
                    height: calc(100vh - 60px - 70px) !important;
                    /* Full height minus header and input area */
                    max-height: calc(100vh - 60px - 70px) !important;
                    overflow-y: auto !important;
                    padding-bottom: 80px !important;
                    /* Increased bottom padding to prevent last lines from being hidden */
                    padding-top: 20px !important;
                    box-sizing: border-box !important;
                }
    }

    /* NUCLEAR OPTION: FORCE RESET EVERYTHING FOR CHAT PAGE */
    /* We use high specificity to override style.css and any media queries */

    html body.chat-page {
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
        height: 100% !important;
        width: 100% !important;
    }

    /* Force Header Gone */
    html body.chat-page header,
    html body.chat-page .header-content,
    html body.chat-page #header-actions {
        display: none !important;
        height: 0 !important;
        width: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
        position: absolute !important;
        top: -9999px !important;
        left: -9999px !important;
        opacity: 0 !important;
        visibility: hidden !important;
        z-index: -1 !important;
        animation: none !important;
    }

    /* Force Container to Top */
    html body.chat-page .chat-page-container {
        padding-top: 0 !important;
        margin-top: 0 !important;
        top: 0 !important;
    }

    /* Ensure no pseudo-elements creating space */
    html body.chat-page::before,
    html body.chat-page::after {
        display: none !important;
        content: none !important;
    }
}

/* Voice call overlay – Live style: dark + blue gradient, bottom control bar */
.voice-call-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 0;
    box-sizing: border-box;
    overflow: hidden;
}

.voice-call-bg {
    position: absolute;
    inset: 0;
    background: #0d0d0f;
    pointer-events: none;
}

.voice-call-bg::after {
    content: '';
    position: absolute;
    left: -20%;
    right: -20%;
    bottom: -30%;
    height: 70%;
    background: radial-gradient(ellipse at center bottom, rgba(59, 130, 246, 0.35) 0%, rgba(37, 99, 235, 0.15) 40%, transparent 70%);
    filter: blur(60px);
    pointer-events: none;
}

.voice-call-content {
    position: relative;
    z-index: 1;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 20px 100px;
    text-align: center;
}

.voice-call-live {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 24px;
}

.voice-call-live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 12px rgba(34, 197, 94, 0.8);
    animation: voice-call-pulse 1.5s ease-in-out infinite;
}

@keyframes voice-call-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.2); }
}

.voice-call-live-text {
    font-size: 1rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.95);
    letter-spacing: 0.05em;
}

.voice-call-timer {
    font-variant-numeric: tabular-nums;
    font-size: 2rem;
    font-weight: 600;
    color: white;
    margin-bottom: 8px;
}

.voice-call-status {
    font-size: 1.1rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.85);
    min-height: 1.4em;
    margin-bottom: 8px;
}

.voice-call-hint {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.55);
    line-height: 1.4;
    max-width: 280px;
}

.voice-call-bar {
    position: relative;
    z-index: 1;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    padding: 20px 24px 28px;
    padding-bottom: max(28px, env(safe-area-inset-bottom));
    background: linear-gradient(to top, rgba(15, 15, 20, 0.95) 0%, rgba(15, 15, 20, 0.6) 70%, transparent 100%);
}

.voice-call-ctrl-btn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.12);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: default;
    transition: background 0.2s, transform 0.1s;
}

.voice-call-ctrl-btn:not(:disabled) {
    cursor: pointer;
}

.voice-call-ctrl-btn:not(:disabled):hover {
    background: rgba(255, 255, 255, 0.2);
}

.voice-call-ctrl-btn:not(:disabled):active {
    transform: scale(0.95);
}

.voice-call-ctrl-btn svg {
    width: 24px;
    height: 24px;
}

.voice-call-ctrl-btn:disabled {
    opacity: 0.4;
}

.voice-call-mic-btn {
    background: rgba(255, 255, 255, 0.15);
}

.voice-call-end-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: #ef4444;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.4);
}

.voice-call-end-btn:hover {
    background: #dc2626;
}

.voice-call-end-btn:active {
    transform: scale(0.95);
}

.voice-call-end-btn svg {
    width: 26px;
    height: 26px;
}