/* Reset and Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #e0e0e0;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* Chat Container */
.chat-container {
    width: 100%;
    max-width: 450px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 20px;
    background: rgba(30, 35, 50, 0.9);
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    position: relative;
}

/* Header */
h2 {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 20px;
    color: #fff;
    text-align: center;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

h2::before {
    content: "💬";
    font-size: 24px;
}

/* Join Section */
.join-section {
    margin-bottom: 20px;
}

.join-section label {
    display: block;
    margin: 10px 0 5px;
    font-size: 14px;
    font-weight: 500;
    color: #a0a0a0;
    letter-spacing: 0.3px;
}

.join-section input[type="text"] {
    padding: 12px;
    font-size: 15px;
    border: none;
    border-radius: 15px;
    background: #2a2f40;
    color: #e0e0e0;
    width: 100%;
    outline: none;
    transition: all 0.3s ease;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.2);
}

.join-section input[type="text"]:focus {
    background: #32384a;
    box-shadow: 0 0 10px rgba(124, 97, 255, 0.3);
}

.join-section button {
    margin-top: 10px;
    padding: 8px 15px;
    cursor: pointer;
    background: linear-gradient(135deg, #7c61ff 0%, #5a4bff 100%);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.join-section button:hover {
    background: linear-gradient(135deg, #5a4bff 0%, #7c61ff 100%);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

/* Horizontal Line */
hr {
    border: 0;
    border-top: 1px solid #3a3f50;
    margin: 20px 0;
    opacity: 0.5;
}

/* User List */
#userList {
    font-size: 14px;
    color: #a0a0a0;
    margin-bottom: 10px;
}

/* Messages List */
#messages {
    list-style: none;
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px 0;
    scrollbar-width: thin;
    scrollbar-color: #7c61ff #2a2f40;
}

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

#messages::-webkit-scrollbar-track {
    background: #2a2f40;
    border-radius: 10px;
}

#messages::-webkit-scrollbar-thumb {
    background: #7c61ff;
    border-radius: 10px;
}

#messages li {
    display: flex;
    align-items: flex-start;
    margin: 15px 0;
    position: relative;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#messages li.sent {
    justify-content: flex-end;
}

#messages li.sent .message-bubble {
    background: linear-gradient(135deg, #7c61ff 0%, #5a4bff 100%);
    color: #fff;
    border-radius: 20px 20px 0 20px;
    padding: 12px 18px;
    max-width: 70%;
    word-wrap: break-word;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease;
}

#messages li.sent .message-bubble:hover {
    transform: translateY(-2px);
}

#messages li.sent .initial {
    background: linear-gradient(135deg, #ff6b6b 0%, #ff8787 100%);
    order: 1;
    margin-left: 10px;
}

#messages li.received {
    justify-content: flex-start;
}

#messages li.received .message-bubble {
    background: linear-gradient(135deg, #3a3f50 0%, #4a4f60 100%);
    color: #e0e0e0;
    border-radius: 20px 20px 20px 0;
    padding: 12px 18px;
    max-width: 70%;
    word-wrap: break-word;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease;
}

#messages li.received .message-bubble:hover {
    transform: translateY(-2px);
}

#messages li.received .initial {
    background: linear-gradient(135deg, #ff6b6b 0%, #ff8787 100%);
    margin-right: 10px;
}

#messages li.typing {
    color: #888;
    font-style: italic;
    margin: 5px 0;
    display: flex;
    align-items: center;
    gap: 5px;
}

#messages li.typing::before {
    content: "• • •";
    animation: typing 1s infinite;
}

@keyframes typing {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

/* Initial Circle */
.initial {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* Timestamp */
.timestamp {
    position: absolute;
    bottom: -18px;
    font-size: 11px;
    color: #888;
    width: 100%;
    text-align: center;
    opacity: 0.7;
}

/* Input Section */
.input-section {
    margin-top: auto;
    padding: 10px 0;
}

.input-section label {
    display: block;
    margin: 10px 0 5px;
    font-size: 14px;
    font-weight: 500;
    color: #a0a0a0;
    letter-spacing: 0.3px;
}

.input-section input[type="text"] {
    padding: 12px;
    font-size: 15px;
    border: none;
    border-radius: 15px;
    background: #2a2f40;
    color: #e0e0e0;
    width: 100%;
    outline: none;
    transition: all 0.3s ease;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.2);
    margin-bottom: 10px;
}

.input-section input[type="text"]:focus {
    background: #32384a;
    box-shadow: 0 0 10px rgba(124, 97, 255, 0.3);
}

.message-input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(40, 45, 60, 0.9);
    padding: 10px;
    border-radius: 25px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(5px);
    transition: all 0.3s ease;
}

.message-input-wrapper:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

#messageInput {
    flex-grow: 1;
    padding: 10px 15px;
    font-size: 15px;
    border: none;
    border-radius: 20px;
    background: transparent;
    color: #e0e0e0;
    outline: none;
    resize: none;
    min-height: 40px;
    line-height: 1.5;
    overflow-y: auto;
    max-height: 120px;
}

#messageInput::placeholder {
    color: #888;
    font-style: italic;
}

.icon-button {
    background: none;
    border: none;
    color: #a0a0a0;
    font-size: 22px;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.icon-button:hover {
    color: #7c61ff;
    transform: scale(1.1);
}

.plus-button {
    background: linear-gradient(135deg, #7c61ff 0%, #5a4bff 100%);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 24px;
}

.plus-button:hover {
    background: linear-gradient(135deg, #5a4bff 0%, #7c61ff 100%);
}

.camera-button {
    color: #a0a0a0;
}

.send-button {
    background: linear-gradient(135deg, #7c61ff 0%, #5a4bff 100%);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 20px;
}

.send-button:hover {
    background: linear-gradient(135deg, #5a4bff 0%, #7c61ff 100%);
}

/* Video Call Section */
#videoContainer {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
    position: relative;
}

#localVideo, #remoteVideo {
    border: 2px solid #3a3f50;
    background: #000;
    border-radius: 10px;
    width: 45%;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}

#callButton, #endCallButton {
    margin: 5px;
    padding: 8px 15px;
    cursor: pointer;
    background: linear-gradient(135deg, #7c61ff 0%, #5a4bff 100%);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
}

#callButton:hover, #endCallButton:hover {
    background: linear-gradient(135deg, #5a4bff 0%, #7c61ff 100%);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

#callButton:disabled {
    background: #555;
    cursor: not-allowed;
}

#callButton:disabled:hover {
    transform: none;
    box-shadow: none;
}

/* Full-Screen Video Call in Mobile View */
@media (max-width: 400px) {
    .chat-container {
        padding: 15px;
        border-radius: 0;
    }

    .join-section input[type="text"],
    .input-section input[type="text"],
    .icon-button {
        font-size: 14px;
    }

    #messageInput {
        font-size: 14px;
    }

    /* Default Video Container Adjustments for Mobile (Before Call) */
    #videoContainer {
        flex-direction: column;
        align-items: center;
        gap: 15px;
    }

    #localVideo {
        width: 100%;
        max-width: 300px;
        height: 200px;
        object-fit: cover; /* Ensure video fits without distortion */
    }

    #remoteVideo {
        width: 100%;
        max-width: 300px;
        height: 200px;
        object-fit: cover; /* Ensure video fits without distortion */
    }

    #callButton, #endCallButton {
        width: 120px;
        margin: 5px 0;
    }

    /* Full-Screen Video Call When Video Container is Visible (During Call) */
    #videoContainer[style*="display: flex"] {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        margin: 0;
        flex-direction: column;
        justify-content: space-between;
        align-items: center;
        background: #000;
        z-index: 1000;
        padding-bottom: 80px; /* Add padding to ensure space for the End Call button */
    }

    #videoContainer[style*="display: flex"] ~ h2,
    #videoContainer[style*="display: flex"] ~ .join-section,
    #videoContainer[style*="display: flex"] ~ hr,
    #videoContainer[style*="display: flex"] ~ #userList,
    #videoContainer[style*="display: flex"] ~ #messages,
    #videoContainer[style*="display: flex"] ~ .input-section {
        display: none; /* Hide all other elements during the call */
    }

    #videoContainer[style*="display: flex"] #localVideo {
        width: 100%;
        height: 40%; /* Adjusted to fit both videos and leave space for the button */
        max-width: none;
        border: none;
        border-radius: 0;
        box-shadow: none;
        object-fit: cover; /* Maintain aspect ratio */
    }

    #videoContainer[style*="display: flex"] #remoteVideo {
        display: block; /* Ensure remote video is visible during full-screen call */
        width: 100%;
        height: 40%; /* Adjusted to fit both videos and leave space for the button */
        max-width: none;
        border: none;
        border-radius: 0;
        box-shadow: none;
        object-fit: cover; /* Maintain aspect ratio */
    }

    #videoContainer[style*="display: flex"] #callButton {
        display: none; /* Hide Start Call button during the call */
    }

    #videoContainer[style*="display: flex"] #endCallButton {
        display: block !important; /* Ensure End Call button is visible */
        position: fixed;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%); /* Center the button horizontally */
        width: 150px;
        padding: 12px 20px; /* Make the button larger for better touch interaction */
        background: linear-gradient(135deg, #ff6b6b 0%, #ff8787 100%); /* Red gradient for End Call */
        z-index: 1001; /* Ensure it appears above the videos */
        font-size: 16px;
        font-weight: 600;
        border-radius: 15px;
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    }

    #videoContainer[style*="display: flex"] #endCallButton:hover {
        background: linear-gradient(135deg, #ff8787 0%, #ff6b6b 100%);
        transform: translateX(-50%) translateY(-2px); /* Adjust hover effect to account for centering */
    }

    /* Additional End Call Icon in Full-Screen Mode (Moved to Bottom-Right) */
    #videoContainer[style*="display: flex"]::after {
        content: "📞"; /* Phone hang-up icon (you can replace with a custom SVG or emoji) */
        position: fixed;
        bottom: 20px; /* Moved to bottom */
        right: 20px; /* Positioned on the right */
        width: 50px;
        height: 50px;
        background: linear-gradient(135deg, #ff6b6b 0%, #ff8787 100%);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 24px;
        color: #fff;
        cursor: pointer;
        z-index: 1002; /* Ensure it appears above everything */
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
        transition: all 0.3s ease;
    }

    #videoContainer[style*="display: flex"]::after:hover {
        background: linear-gradient(135deg, #ff8787 0%, #ff6b6b 100%);
        transform: scale(1.1);
    }
}

/* Adjust for 4:3 Aspect Ratio (if needed) */
@media (max-width: 400px) and (min-aspect-ratio: 4/3) {
    #videoContainer[style*="display: flex"] #localVideo,
    #videoContainer[style*="display: flex"] #remoteVideo {
        height: 35%; /* Slightly reduce height to fit 4:3 aspect ratio better */
    }
}