/* ====================== GENERAL & AUTH ====================== */
body { 
    background-color: #f0f2f5; 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
    margin: 0;
}

.auth-card { 
    width: 100%;
    max-width: 400px;
    margin-top: 100px; 
    border: none; 
    border-radius: 15px; 
    box-shadow: 0 4px 12px rgba(0,0,0,0.1); 
}

.hidden { display: none !important; }

/* ====================== MAIN LAYOUT ====================== */
.main-container { 
    height: 100vh; 
    display: flex; 
    overflow: hidden; 
}

.sidebar { 
    width: 350px; 
    background: white; 
    border-right: 1px solid #ddd; 
    display: flex; 
    flex-direction: column; 
}

.chat-area { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    background: #e5ddd5; /* Classic WhatsApp Background */
    position: relative; 
}

/* ====================== USER LIST (SIDEBAR) ====================== */
.user-item { 
    padding: 15px; 
    border-bottom: 1px solid #eee; 
    cursor: pointer; 
    display: flex; 
    justify-content: space-between;
    align-items: center;
    transition: 0.2s;
}

.user-item:hover { background: #f8f9fa; }

.active-user { 
    background: #e7f3ff !important; 
    border-left: 5px solid #0084ff; 
}

.unread-badge {
    background-color: #25d366; 
    color: white; 
    font-size: 12px; 
    font-weight: bold; 
    padding: 2px 8px;  
    border-radius: 50%; 
    min-width: 24px; 
    text-align: center; 
}

#user-search {
    border-radius: 20px;
    background-color: #f0f2f5;
    border: 1px solid transparent;
    padding: 8px 15px;
    font-size: 14px;
    transition: all 0.2s;
}

#user-search:focus {
    background-color: #fff;
    border-color: #0084ff;
    box-shadow: none;
    outline: none;
}

/* Add a little padding to the search container */
.sidebar .p-2.border-bottom.bg-light {
    padding: 10px 15px !important;
}

/* ====================== MESSAGE PANE ====================== */
.message-pane { 
    flex: 1; 
    overflow-y: auto; 
    padding: 20px 40px; /* Extra horizontal padding for floating buttons */
    display: flex; 
    flex-direction: column; 
    gap: 10px;
}

/* The Message Bubble */
.msg {
    position: relative;
    padding: 10px 15px;
    border-radius: 12px;
    font-size: 15px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
    margin-bottom: 12px;
    max-width: 70%;            
    width: fit-content;         
    word-wrap: break-word;      
    overflow-wrap: anywhere;    
    word-break: break-all;      
    white-space: pre-wrap;      
}

.msg-sent { 
    align-self: flex-end; 
    background-color: #dcf8c6; 
    margin-right: 50px; /* Room for your floating icons */
}

.msg-received { 
    align-self: flex-start; 
    background-color: #ffffff; 
    margin-left: 50px; /* Room for your floating icons */
}

/* ====================== FLOATING ACTION MENU ====================== */
.msg-menu {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 12px;
    background: white;
    padding: 8px 15px;
    border-radius: 25px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 100;
}

.msg-menu::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30px; /* Size of the gap */
}

/* Position for SENT messages (Menu on the LEFT) */
.msg-sent .msg-menu {
    right: 102%; /* Very close to the bubble */
}

.msg-sent .msg-menu::before {
    right: -25px; /* Bridge to the right towards the bubble */
}

/* Position for RECEIVED messages (Menu on the RIGHT) */
.msg-received .msg-menu {
    left: 102%; /* Very close to the bubble */
}

.msg-received .msg-menu::before {
    left: -25px; /* Bridge to the left towards the bubble */
}

.msg:hover .msg-menu,
.msg-menu:hover {
    opacity: 1;
    visibility: visible;
}

/* Icon Styles */
.msg-menu span {
    font-size: 22px; /* Bigger icons as requested */
    cursor: pointer;
    padding: 5px;
    display: inline-block;
    transition: transform 0.1s;
    line-height: 1;
}

.msg-menu span:hover {
    transform: scale(1.4);
    filter: drop-shadow(0 0 2px rgba(0,0,0,0.2));
}

/* ====================== MEDIA CONSTRAINTS ====================== */
.msg img, .msg video {
    width: 100%;       
    max-width: 300px;  
    height: auto;      
    max-height: 300px; 
    object-fit: contain; 
    border-radius: 10px;
    display: block;
    margin-top: 5px;
}

.msg img {
    cursor: zoom-in;
    transition: 0.2s;
}

/* When clicked, it becomes this: */
.msg img.img-big {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    max-width: 100vw; /* Overrides chat bubble lock */
    max-height: 100vh;
    object-fit: contain; /* Keeps image shape perfect */
    background: rgba(0,0,0,0.9); /* Dark background */
    z-index: 9999;
    cursor: zoom-out;
    margin: 0;
    border-radius: 0;
}

.msg audio {
    max-width: 100%;
    margin-top: 5px;
    display: block;
}

.msg:has(audio) { min-width: 250px; }

/* ====================== INPUT AREA & RECORDING ====================== */
#input-area { 
    position: relative; 
    overflow: visible !important;
}

.dropdown-menu { 
    z-index: 1050; 
    bottom: 100%;  
    margin-bottom: 10px;
}

#voice-btn.recording {
    background-color: #ff4d4d;
    color: white;
    border-color: #ff4d4d;
    animation: pulse-red 1.5s infinite;
}

/* Animations */
@keyframes pulse-red {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 77, 77, 0.7); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(255, 77, 77, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 77, 77, 0); }
}

.animate-flicker {
    animation: flicker 1s infinite;
}

@keyframes flicker {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Empty State image */
.empty-chat { 
    position: absolute; 
    top: 0; left: 0; width: 100%; height: 100%; 
    background: #f8f9fa; 
    display: flex; flex-direction: column; 
    align-items: center; justify-content: center; 
    z-index: 10; 
}

/* ====================== MOBILE ONLY ====================== */
@media (max-width: 768px) {

    html, body {
        width: 100%;
        height: 100%;
        overflow: hidden;
    }

    #page-chat.main-container {
        width: 100vw;
        height: 100dvh;
        display: flex;
        overflow: hidden;
    }

    /* LEFT SIDEBAR */
    .sidebar {
        width: 34%;
        min-width: 115px;
        max-width: 140px;
        height: 100dvh;
        flex-shrink: 0;
        overflow: hidden;
        background: #ffffff;
    }

    .sidebar .p-3.bg-primary {
        padding: 12px 8px !important;
        text-align: center;
    }

    #display-my-username {
        font-size: 16px;
        font-weight: 700;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .sidebar .p-2.border-bottom.bg-light {
        padding: 8px !important;
    }

    #user-search {
        font-size: 13px;
        padding: 8px 10px;
        border-radius: 18px;
    }

    #user-list {
        height: calc(100dvh - 155px);
        overflow-y: auto;
    }

    .user-item {
        padding: 12px 8px;
        font-size: 14px;
        display: block;
        word-break: normal;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .active-user {
        border-left: 4px solid #0084ff;
    }

    .sidebar .p-2.border-top {
        height: 58px;
        padding: 6px !important;
        gap: 5px !important;
    }

    .sidebar .btn {
        font-size: 12px;
        padding: 6px 4px;
    }

    /* RIGHT CHAT AREA */

        #mobile-back-btn {
        display: none !important;
        flex-shrink: 0;
    }

    .chat-area {
        width: 66%;
        height: 100dvh;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        background: #e5ddd5;
    }

    #chat-header {
        height: 58px;
        flex-shrink: 0;
        padding: 12px 10px !important;
        font-size: 15px;
        background: #ffffff !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #chat-header span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #empty-state img {
        width: 190px !important;
    }

    #empty-state p {
        font-size: 13px;
        text-align: center;
        padding: 0 15px;
    }

    /* ONLY MESSAGE AREA CAN SCROLL */
    #message-pane.message-pane {
        flex: 1;
        height: auto;
        overflow-y: auto;
        padding: 12px 10px;
        gap: 8px;
    }

    .msg {
        max-width: 88%;
        font-size: 14px;
        padding: 9px 12px;
        margin-bottom: 10px;
        word-break: break-word;
        overflow-wrap: anywhere;
        white-space: pre-wrap;
    }

    .msg-sent {
        align-self: flex-end;
        margin-right: 0 !important;
    }

    .msg-received {
        align-self: flex-start;
        margin-left: 0 !important;
    }

    .msg-menu {
        display: none;
    }

    .msg img,
    .msg video {
        max-width: 160px;
        max-height: 160px;
    }

    .msg audio {
        width: 150px;
    }

    .msg:has(audio) {
        min-width: 170px;
    }

    /* INPUT ALWAYS FIXED AT BOTTOM INSIDE CHAT AREA */
    #input-area {
        height: 62px;
        flex-shrink: 0;
        padding: 7px !important;
        gap: 5px !important;
        background: #f8f9fa !important;
        border-top: 1px solid #ddd;
        align-items: center;
        overflow: visible !important;
    }

    #input-area .btn {
        width: 38px;
        height: 38px;
        padding: 0;
        font-size: 16px;
        flex-shrink: 0;
    }

    #msg-input {
        min-width: 0;
        height: 38px;
        font-size: 15px;
        padding: 6px 8px;
    }

    #send-btn {
        width: 52px !important;
        border-radius: 8px;
        font-size: 14px !important;
    }

    #recording-status {
        font-size: 11px;
        white-space: nowrap;
    }

    .dropdown-menu {
        min-width: 130px;
        font-size: 14px;
    }

    .mobile-chat-open .sidebar {
        display: none !important;
    }

    .mobile-chat-open .chat-area {
        width: 100vw !important;
        flex: 1 !important;
    }

    .mobile-chat-open #mobile-back-btn {
        display: inline-block !important;
    }

    .msg.show-menu .msg-menu {
    display: flex !important;
    opacity: 1 !important;
    visibility: visible !important;
    gap: 10px;
    }
}