* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    font-family: Arial, sans-serif;
}

body {
    background: #f1f5f9;
}

/* =========================================================
   LOGIN
   ========================================================= */

#loginScreen {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-box {
    width: 90%;
    max-width: 380px;
    background: white;
    padding: 30px;
    border-radius: 16px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.15);
    text-align: center;
}

.login-box h1 {
    margin: 0 0 25px;
}

.login-box input {
    width: 100%;
    padding: 14px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 16px;
    margin-bottom: 12px;
    outline: none;
}

.login-box input:focus {
    border-color: #2563eb;
}

.login-box button {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 8px;
    background: #2563eb;
    color: white;
    font-size: 16px;
    cursor: pointer;
}

.login-box button:hover {
    background: #1d4ed8;
}

#loginError {
    color: #dc2626;
    margin-top: 12px;
}


/* =========================================================
   CHAT SCREEN
   ========================================================= */

#chatScreen {
    width: 100%;
    max-width: 900px;
    height: 100vh;
    height: 100dvh;
    margin: auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: white;
}


/* =========================================================
   NORMAL HEADER
   ========================================================= */

.chat-header {
    flex: 0 0 auto;
    min-height: 68px;
    padding: 10px 18px;
    background: #2563eb;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    z-index: 20;
}

.chat-header h2 {
    margin: 0;
    font-size: 21px;
}

#otherStatus {
    display: block;
    margin-top: 4px;
    font-size: 13px;
    opacity: 0.95;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

#connectionStatus {
    font-size: 13px;
}


/* =========================================================
   CALL BUTTONS
   ========================================================= */

.call-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
}

.call-button {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: white;
    color: #2563eb;
    font-size: 18px;
    cursor: pointer;
}

.call-button:hover {
    background: #dbeafe;
}

.call-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}


/* =========================================================
   MESSAGE SELECTION TOOLBAR
   ========================================================= */

.selection-toolbar {
    position: relative;
    z-index: 50;
    min-height: 68px;
    padding: 10px 14px;
    background: #1d4ed8;
    color: white;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.selection-toolbar #selectionCount {
    font-size: 18px;
    font-weight: bold;
    min-width: 24px;
}

.selection-icon-button,
.selection-actions button {
    border: none;
    cursor: pointer;
    background: transparent;
    color: white;
    font-size: 21px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
}

.selection-icon-button:hover,
.selection-actions button:hover {
    background: rgba(255, 255, 255, 0.15);
}

.selection-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 4px;
}

.selection-actions button:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}


/* =========================================================
   REACTION PICKER
   ========================================================= */

.reaction-picker {
    position: fixed;
    z-index: 100;
    padding: 7px 9px;
    background: white;
    border-radius: 30px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    gap: 2px;
}

.reaction-picker button {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: 50%;
    font-size: 23px;
    cursor: pointer;
    transition: transform 0.1s ease;
}

.reaction-picker button:hover {
    background: #f1f5f9;
    transform: scale(1.15);
}


/* =========================================================
   MESSAGES AREA
   ========================================================= */

#messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 18px 16px;
    background: #f8fafc;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}


/* =========================================================
   MESSAGE ROW
   ========================================================= */

.message-row {
    width: 100%;
    display: flex;
    margin-bottom: 8px;
    position: relative;
}

.message-row.me {
    justify-content: flex-end;
}

.message-row.other {
    justify-content: flex-start;
}


/* =========================================================
   MESSAGE BUBBLE
   ========================================================= */

.message {
    position: relative;
    max-width: 75%;
    min-width: 70px;
    padding: 9px 11px 7px;
    border-radius: 14px;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    user-select: none;
    -webkit-user-select: none;
    touch-action: pan-y;
    cursor: pointer;
    transition:
        transform 0.15s ease,
        box-shadow 0.15s ease,
        background 0.15s ease;
}

.message.me {
    background: #dbeafe;
    border-bottom-right-radius: 4px;
}

.message.other {
    background: #e2e8f0;
    border-bottom-left-radius: 4px;
}

.message-row.selected .message {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.45);
    background: #bfdbfe;
}

.message strong {
    display: block;
    margin-bottom: 5px;
    font-size: 13px;
    color: #334155;
}

.message-text {
    font-size: 15px;
    line-height: 1.4;
    white-space: pre-wrap;
}

.message.deleted .message-text {
    color: #64748b;
    font-style: italic;
}

.message img {
    display: block;
    max-width: min(330px, 100%);
    max-height: 420px;
    height: auto;
    border-radius: 10px;
    object-fit: contain;
}


/* =========================================================
   REPLY INSIDE MESSAGE
   ========================================================= */

.message-reply {
    margin-bottom: 7px;
    padding: 6px 8px;
    border-left: 4px solid #2563eb;
    background: rgba(255, 255, 255, 0.55);
    border-radius: 7px;
    cursor: pointer;
    overflow: hidden;
}

.message-reply strong {
    margin: 0 0 2px;
    font-size: 11px;
    color: #2563eb;
}

.message-reply-text {
    font-size: 12px;
    color: #475569;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* =========================================================
   MESSAGE META
   ========================================================= */

.message-meta {
    margin-top: 5px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
    min-height: 14px;
}

.message-time {
    color: #64748b;
    font-size: 10px;
    white-space: nowrap;
}

.message-edited {
    color: #64748b;
    font-size: 10px;
    font-style: italic;
}

.message-status {
    font-size: 13px;
    line-height: 1;
    letter-spacing: -3px;
    padding-right: 2px;
    color: #64748b;
}

.message-status.seen {
    color: #2563eb;
}


/* =========================================================
   REACTIONS
   ========================================================= */

.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 5px;
}

.reaction-chip {
    border: 1px solid #cbd5e1;
    background: white;
    border-radius: 12px;
    padding: 2px 6px;
    font-size: 12px;
    line-height: 18px;
    cursor: pointer;
}

.reaction-chip.mine {
    border-color: #2563eb;
    background: #eff6ff;
}


/* =========================================================
   REPLY / EDIT COMPOSER PREVIEW
   ========================================================= */

.composer-preview {
    flex: 0 0 auto;
    background: white;
    border-top: 1px solid #e2e8f0;
    padding: 8px 12px;
}

.composer-preview-line {
    display: flex;
    align-items: center;
    gap: 10px;
    border-left: 4px solid #2563eb;
    padding-left: 9px;
}

#composerPreviewTitle {
    display: block;
    color: #2563eb;
    font-size: 13px;
    margin-bottom: 2px;
}

#composerPreviewText {
    color: #64748b;
    font-size: 12px;
    max-width: 700px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#composerPreviewClose {
    margin-left: auto;
    flex: 0 0 auto;
    border: none;
    background: transparent;
    color: #64748b;
    font-size: 20px;
    cursor: pointer;
    width: 35px;
    height: 35px;
    border-radius: 50%;
}

#composerPreviewClose:hover {
    background: #f1f5f9;
}


/* =========================================================
   INPUT AREA
   ========================================================= */

.chat-input-area {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #ddd;
    background: white;
    position: relative;
    z-index: 20;
}

.chat-input-area input[type="text"] {
    flex: 1;
    min-width: 0;
    padding: 12px 16px;
    border: 1px solid #cbd5e1;
    border-radius: 22px;
    outline: none;
    font-size: 15px;
    background: white;
}

.chat-input-area input[type="text"]:focus {
    border-color: #2563eb;
}

.chat-input-area button {
    flex: 0 0 auto;
    width: 46px;
    height: 46px;
    border: none;
    border-radius: 50%;
    background: #2563eb;
    color: white;
    font-size: 20px;
    cursor: pointer;
}

.chat-input-area button:hover {
    background: #1d4ed8;
}

.chat-input-area button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.chat-input-area .image-button {
    background: #e2e8f0;
    color: #334155;
}

.chat-input-area .image-button:hover {
    background: #cbd5e1;
}


/* =========================================================
   CALL POPUP
   ========================================================= */

.call-popup {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.call-popup-box {
    width: 90%;
    max-width: 360px;
    background: white;
    border-radius: 20px;
    padding: 30px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.call-icon {
    font-size: 55px;
    margin-bottom: 15px;
}

.call-popup-box h2 {
    margin: 0 0 8px;
}

.call-popup-box p {
    color: #64748b;
    margin-bottom: 25px;
}

.incoming-call-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.incoming-call-buttons button {
    border: none;
    padding: 12px 18px;
    border-radius: 10px;
    color: white;
    font-size: 15px;
    cursor: pointer;
}

.accept-call {
    background: #16a34a;
}

.accept-call:hover {
    background: #15803d;
}

.reject-call {
    background: #dc2626;
}

.reject-call:hover {
    background: #b91c1c;
}


/* =========================================================
   ACTIVE CALL
   ========================================================= */

.active-call-screen {
    position: fixed;
    inset: 0;
    background: #0f172a;
    z-index: 2000;
    display: flex;
    flex-direction: column;
}

.active-call-header {
    padding: 18px;
    color: white;
    display: flex;
    justify-content: space-between;
    background: #111827;
}

#activeCallUser {
    font-size: 18px;
    font-weight: bold;
}

#activeCallStatus {
    font-size: 14px;
    color: #94a3b8;
}


/* =========================================================
   VIDEO
   ========================================================= */

.video-area {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#remoteVideo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

#localVideo {
    position: absolute;
    right: 20px;
    bottom: 20px;
    width: 180px;
    height: 130px;
    object-fit: cover;
    background: #000;
    border-radius: 12px;
    border: 2px solid white;
}


/* =========================================================
   CALL CONTROLS
   ========================================================= */

.call-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 20px;
    background: #111827;
}

.call-controls button {
    border: none;
    border-radius: 25px;
    padding: 12px 18px;
    background: white;
    color: #111827;
    font-size: 14px;
    cursor: pointer;
}

.call-controls button:hover {
    background: #e2e8f0;
}

.call-controls .end-call {
    background: #dc2626;
    color: white;
}

.call-controls .end-call:hover {
    background: #b91c1c;
}


/* =========================================================
   STATUS
   ========================================================= */

.online {
    color: #22c55e;
}

.offline {
    color: #cbd5e1;
}


/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 600px) {

    .chat-header {
        min-height: 60px;
        padding: 8px 10px;
    }

    .chat-header h2 {
        font-size: 18px;
    }

    .header-right {
        gap: 5px;
    }

    #connectionStatus {
        display: none;
    }

    .call-button {
        width: 38px;
        height: 38px;
        font-size: 16px;
    }

    #messages {
        padding: 12px 8px;
    }

    .message {
        max-width: 88%;
        padding: 8px 10px 6px;
    }

    .message-text {
        font-size: 15px;
    }

    .message img {
        max-height: 350px;
    }

    .selection-toolbar {
        min-height: 60px;
        padding: 7px 8px;
    }

    .selection-actions button,
    .selection-icon-button {
        width: 38px;
        height: 38px;
        font-size: 19px;
    }

    .reaction-picker {
        max-width: calc(100vw - 20px);
        padding: 5px 6px;
    }

    .reaction-picker button {
        width: 38px;
        height: 38px;
        font-size: 21px;
    }

    .chat-input-area {
        padding: 8px;
        gap: 6px;
    }

    .chat-input-area input[type="text"] {
        padding: 11px 14px;
        font-size: 15px;
    }

    .chat-input-area button {
        width: 44px;
        height: 44px;
    }

    #localVideo {
        width: 120px;
        height: 90px;
        right: 10px;
        bottom: 10px;
    }

    .call-controls {
        padding: 12px 8px;
        gap: 6px;
    }

    .call-controls button {
        padding: 10px 12px;
        font-size: 12px;
    }
}


/* =========================================================
   SMALL MOBILE
   ========================================================= */

@media (max-width: 380px) {

    .message {
        max-width: 92%;
    }

    .reaction-picker button {
        width: 34px;
        height: 34px;
        font-size: 19px;
    }

    .chat-input-area {
        gap: 4px;
    }

    .chat-input-area button {
        width: 42px;
        height: 42px;
    }
}
