
/* =========================================================
   IQRANIX MESSAGES
   Clean white messaging interface
========================================================= */

:root {
    --msg-green: #168653;
    --msg-green-dark: #0d6840;
    --msg-green-light: #e9f6ee;
    --msg-text: #17231c;
    --msg-muted: #89938d;
    --msg-border: #edf0ed;
    --msg-background: #ffffff;
    --msg-soft: #f6f8f6;
    --msg-danger: #d94343;
    --keyboard-height: 0px;
    --visual-height: 100dvh;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0;
    background: var(--msg-background);
    color: var(--msg-text);
    font-family: Arial, Helvetica, sans-serif;
}

body {
    overflow-x: hidden;
}

button,
input,
textarea {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

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

.hidden {
    display: none !important;
}

/* =========================================================
   MAIN VIEWS
========================================================= */

#inboxView,
#chatView,
#newMessageView,
#blockedUsersScreen {
    width: 100%;
    min-height: 100dvh;
    background: #fff;
}

#inboxView {
    padding-bottom: 85px;
}

#newMessageView,
#blockedUsersScreen {
    padding-bottom: 25px;
}

/* =========================================================
   INBOX HEADER
========================================================= */

.messages-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 66px;
    padding: 10px 17px;
    background: rgba(255, 255, 255, .97);
    border-bottom: 1px solid var(--msg-border);
}

.messages-header h1 {
    margin: 0;
    font-size: 23px;
    font-weight: 750;
    letter-spacing: -.7px;
}

.messages-header-actions {
    display: flex;
    align-items: center;
    gap: 17px;
}

.messages-header button,
.header-icon-button {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    color: var(--msg-text);
    background: transparent;
    border: 0;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
}

.messages-header button:active,
.header-icon-button:active {
    background: var(--msg-soft);
}

/* =========================================================
   SEARCH
========================================================= */

.messages-search-wrap {
    padding: 12px 16px;
}

.messages-search,
.people-search {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 43px;
    padding: 0 14px;
    background: #f2f4f2;
    border: 1px solid transparent;
    border-radius: 12px;
}

.messages-search:focus-within,
.people-search:focus-within {
    border-color: #b9ddc7;
    background: #fff;
}

.messages-search i,
.people-search i {
    color: var(--msg-muted);
    font-size: 15px;
}

.messages-search input,
.people-search input {
    width: 100%;
    min-width: 0;
    height: 42px;
    padding: 0;
    color: var(--msg-text);
    background: transparent;
    border: 0;
    outline: 0;
    font-size: 14px;
}

.messages-search input::placeholder,
.people-search input::placeholder {
    color: #929b95;
}

/* =========================================================
   CONVERSATION LIST
========================================================= */

#conversationList {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 13px;
    width: 100%;
    min-height: 79px;
    padding: 11px 16px;
    text-align: left;
    color: var(--msg-text);
    background: #fff;
    border: 0;
    border-bottom: 1px solid #f1f2f1;
    cursor: pointer;
}

.conversation-item:active {
    background: #f8faf8;
}

.conversation-avatar {
    flex: 0 0 52px;
    width: 52px;
    height: 52px;
    object-fit: cover;
    border-radius: 50%;
    background: var(--msg-soft);
}

.conversation-details {
    flex: 1;
    min-width: 0;
}

.conversation-topline,
.conversation-bottomline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 9px;
}

.conversation-name {
    overflow: hidden;
    color: #17231c;
    font-size: 15px;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-time {
    flex-shrink: 0;
    color: var(--msg-muted);
    font-size: 11px;
}

.conversation-preview {
    display: block;
    overflow: hidden;
    max-width: 90%;
    margin-top: 6px;
    color: #89928c;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-item.unread .conversation-name {
    font-weight: 800;
}

.conversation-item.unread .conversation-preview {
    color: #26372d;
    font-weight: 650;
}

.conversation-unread-dot {
    flex: 0 0 9px;
    width: 9px;
    height: 9px;
    background: var(--msg-green);
    border-radius: 50%;
}

/* =========================================================
   EMPTY STATES
========================================================= */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 55vh;
    padding: 30px;
    text-align: center;
}

.empty-icon {
    display: grid;
    place-items: center;
    width: 76px;
    height: 76px;
    margin-bottom: 17px;
    color: var(--msg-green);
    border: 2px solid #cfe8d8;
    border-radius: 50%;
    font-size: 29px;
}

.empty-state h3 {
    margin: 0 0 8px;
    font-size: 20px;
}

.empty-state p,
.subtle-message {
    color: var(--msg-muted);
    font-size: 14px;
    line-height: 1.6;
}

/* =========================================================
   CHAT HEADER
========================================================= */

#chatView {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
}

.chat-header {
    position: relative;
    z-index: 15;
    display: flex;
    flex: 0 0 64px;
    align-items: center;
    gap: 11px;
    min-height: 64px;
    padding: 7px 12px;
    background: #fff;
    border-bottom: 1px solid var(--msg-border);
}

.chat-back-button {
    display: grid;
    flex: 0 0 36px;
    place-items: center;
    width: 36px;
    height: 40px;
    color: var(--msg-text);
    background: transparent;
    border: 0;
    font-size: 21px;
    cursor: pointer;
}

.chat-header-avatar {
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    object-fit: cover;
    border-radius: 50%;
}

.chat-header-details {
    flex: 1;
    min-width: 0;
}

.chat-header-details h2 {
    overflow: hidden;
    margin: 0 0 3px;
    font-size: 15px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-header-details span {
    color: var(--msg-muted);
    font-size: 11px;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 13px;
}

.chat-header-actions button {
    display: grid;
    place-items: center;
    width: 37px;
    height: 40px;
    padding: 0;
    color: var(--msg-green);
    background: transparent;
    border: 0;
    border-radius: 50%;
    font-size: 19px;
    cursor: pointer;
}

.chat-header-actions button:active {
    background: var(--msg-green-light);
}

/* =========================================================
   MESSAGE HISTORY
========================================================= */

#messageList {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 9px;
    min-height: 0;
    padding: 18px 13px 15px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: #fff;
    scroll-behavior: smooth;
}

.message-row {
    display: flex;
    width: 100%;
}

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

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

.message-bubble {
    position: relative;
    max-width: min(78%, 340px);
    min-width: 45px;
    padding: 10px 13px 7px;
    overflow-wrap: anywhere;
    color: #25352b;
    background: #f0f2f0;
    border-radius: 18px 18px 18px 5px;
    font-size: 14px;
    line-height: 1.45;
}

.message-row.mine .message-bubble {
    color: #fff;
    background: var(--msg-green);
    border-radius: 18px 18px 5px 18px;
}

.message-time {
    margin-top: 5px;
    color: rgba(80, 95, 85, .7);
    font-size: 9px;
    text-align: right;
}

.message-row.mine .message-time {
    color: rgba(255, 255, 255, .72);
}

.unsent-message {
    color: #89938d !important;
    background: #f0f1f0 !important;
    font-style: italic;
}

.chat-start-note {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-height: 200px;
    color: var(--msg-muted);
    text-align: center;
}

.chat-start-note i {
    margin-bottom: 12px;
    color: #9acbaa;
    font-size: 36px;
}

.chat-start-note p {
    font-size: 13px;
}

/* =========================================================
   IMAGE MESSAGES
========================================================= */

.message-image {
    display: block;
    width: 100%;
    max-width: 260px;
    max-height: 340px;
    object-fit: cover;
    border-radius: 12px;
    cursor: pointer;
}

/* =========================================================
   VOICE MESSAGES
========================================================= */

.voice-message {
    min-width: 190px;
    max-width: 250px;
}

.voice-message audio {
    display: block;
    width: 100%;
    max-width: 240px;
    height: 38px;
}

.message-row.mine .voice-message audio {
    filter: invert(1);
}

/* =========================================================
   UNSEND
========================================================= */

.unsend-message-button {
    display: block;
    margin: 5px 0 0 auto;
    padding: 2px 0;
    color: inherit;
    background: transparent;
    border: 0;
    font-size: 10px;
    opacity: .8;
    cursor: pointer;
}

/* =========================================================
   MESSAGE COMPOSER
========================================================= */

#messageForm {
    position: relative;
    z-index: 12;
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 64px;
    padding: 9px 11px;
    padding-bottom: max(9px, env(safe-area-inset-bottom));
    background: #fff;
    border-top: 1px solid var(--msg-border);
}

#messageInput {
    flex: 1;
    min-width: 0;
    height: 43px;
    padding: 0 15px;
    color: var(--msg-text);
    background: #f2f4f2;
    border: 1px solid transparent;
    border-radius: 25px;
    outline: none;
    font-size: 14px;
}

#messageInput:focus {
    background: #fff;
    border-color: #b7dbc4;
}

#messageInput::placeholder {
    color: #929b95;
}

#messageForm button {
    display: grid;
    flex: 0 0 39px;
    place-items: center;
    width: 39px;
    height: 41px;
    padding: 0;
    color: var(--msg-green);
    background: transparent;
    border: 0;
    border-radius: 50%;
    font-size: 19px;
    cursor: pointer;
}

#messageForm button[type="submit"] {
    color: #fff;
    background: var(--msg-green);
    font-size: 16px;
}

#messageForm button:active {
    transform: scale(.94);
}

.blocked-composer {
    opacity: .5;
}

/* =========================================================
   KEYBOARD OPEN
========================================================= */

body.chat-keyboard-open #chatView {
    height: var(--visual-height);
    min-height: 0;
}

body.chat-keyboard-open #messageForm {
    padding-bottom: 8px;
}

body.chat-keyboard-open #messageList {
    min-height: 0;
}

/* =========================================================
   BLOCKED CHAT NOTICE
========================================================= */

.blocked-chat-notice {
    flex: 0 0 auto;
    padding: 12px 15px;
    color: #9b3434;
    background: #fff0f0;
    border-top: 1px solid #f5dada;
    font-size: 12px;
    text-align: center;
}

/* =========================================================
   RECORDING NOTICE
========================================================= */

#recordingNotice {
    position: absolute;
    right: 12px;
    bottom: 75px;
    left: 12px;
    z-index: 25;
    padding: 12px;
    color: #9e3434;
    background: #fff0f0;
    border: 1px solid #f3d4d4;
    border-radius: 12px;
    font-size: 13px;
    text-align: center;
}

#recordingNotice button {
    margin-left: 10px;
    color: #b33c3c;
    background: transparent;
    border: 0;
    font-weight: 700;
}

/* =========================================================
   NEW MESSAGE SCREEN
========================================================= */

.new-message-header,
.blocked-users-header {
    display: flex;
    align-items: center;
    gap: 15px;
    min-height: 64px;
    padding: 10px 15px;
    background: #fff;
    border-bottom: 1px solid var(--msg-border);
}

.new-message-header h2,
.blocked-users-header h2 {
    margin: 0;
    font-size: 19px;
}

.new-message-header button,
.blocked-users-header button {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    color: var(--msg-text);
    background: transparent;
    border: 0;
    font-size: 19px;
}

.people-search {
    margin: 15px 15px 10px;
    width: calc(100% - 30px);
}

#peopleResults {
    display: flex;
    flex-direction: column;
}

.person-result {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 70px;
    padding: 10px 16px;
    color: var(--msg-text);
    background: #fff;
    border: 0;
    border-bottom: 1px solid var(--msg-border);
    text-align: left;
    cursor: pointer;
}

.person-result img {
    width: 46px;
    height: 46px;
    object-fit: cover;
    border-radius: 50%;
}

.person-result div {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.person-result strong {
    font-size: 14px;
}

.person-result span {
    color: var(--msg-muted);
    font-size: 12px;
}

/* =========================================================
   CONVERSATION ACTION MENU
========================================================= */

.conversation-action-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 15px;
    background: rgba(0, 0, 0, .4);
}

.conversation-action-panel {
    width: 100%;
    max-width: 480px;
    padding: 9px;
    background: #fff;
    border-radius: 19px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .15);
    animation: menuSlideUp .18s ease-out;
}

@keyframes menuSlideUp {
    from {
        opacity: 0;
        transform: translateY(18px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.conversation-action-button,
.conversation-action-cancel {
    display: flex;
    align-items: center;
    gap: 13px;
    width: 100%;
    min-height: 51px;
    padding: 0 13px;
    color: var(--msg-text);
    background: #fff;
    border: 0;
    border-bottom: 1px solid #f1f2f1;
    border-radius: 9px;
    text-align: left;
    font-size: 14px;
    cursor: pointer;
}

.conversation-action-button i {
    width: 21px;
    color: var(--msg-green);
    text-align: center;
}

.conversation-action-button.danger,
.conversation-action-button.danger i {
    color: var(--msg-danger);
}

.conversation-action-cancel {
    justify-content: center;
    margin-top: 7px;
    color: var(--msg-green-dark);
    border: 0;
    font-weight: 700;
}

/* =========================================================
   BLOCKED USERS
========================================================= */

#blockedUsersList {
    display: flex;
    flex-direction: column;
}

.blocked-user-row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 72px;
    padding: 10px 15px;
    border-bottom: 1px solid var(--msg-border);
}

.blocked-user-row img {
    width: 45px;
    height: 45px;
    object-fit: cover;
    border-radius: 50%;
}

.blocked-user-row strong {
    flex: 1;
    font-size: 14px;
}

.blocked-user-row button {
    padding: 8px 14px;
    color: var(--msg-green-dark);
    background: var(--msg-green-light);
    border: 0;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
}

/* =========================================================
   CALL PREPARATION SCREEN
========================================================= */

#callPreparingScreen,
#incomingCallScreen,
#activeCallScreen {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 25px;
    color: #fff;
    background: #071a14;
    text-align: center;
}

#callPreparingScreen img,
#incomingCallScreen img,
#activeCallScreen img {
    width: 112px;
    height: 112px;
    margin-bottom: 23px;
    object-fit: cover;
    border: 3px solid rgba(255, 255, 255, .22);
    border-radius: 50%;
}

#callPreparingScreen h2,
#incomingCallScreen h2,
#activeCallScreen h2 {
    margin: 0 0 10px;
    font-size: 23px;
}

#callPreparingScreen p,
#incomingCallScreen p,
#activeCallScreen p {
    margin: 0;
    color: rgba(255, 255, 255, .7);
    font-size: 14px;
}

#preparingCallStatus {
    margin-top: 12px !important;
}

#cancelPreparingCallButton {
    min-width: 125px;
    min-height: 45px;
    margin-top: 45px;
    color: #fff;
    background: #b83b3b;
    border: 0;
    border-radius: 25px;
    font-weight: 700;
}

/* =========================================================
   INCOMING CALL
========================================================= */

.incoming-call-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 45px;
    margin-top: 55px;
}

.incoming-call-actions button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 9px;
    color: #fff;
    background: transparent;
    border: 0;
    font-size: 12px;
}

.incoming-call-actions button i {
    display: grid;
    place-items: center;
    width: 61px;
    height: 61px;
    border-radius: 50%;
    font-size: 22px;
}

#acceptCallButton i {
    background: #1e9c61;
}

#declineCallButton i {
    background: #d94343;
}

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

#activeCallScreen {
    justify-content: flex-start;
    padding-top: max(70px, env(safe-area-inset-top));
    overflow: hidden;
}

#activeCallScreen > img {
    width: 92px;
    height: 92px;
    margin-top: 30px;
}

#remoteVideo {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #071a14;
}

#localVideo {
    position: absolute;
    top: 22px;
    right: 17px;
    z-index: 3;
    width: 105px;
    height: 145px;
    object-fit: cover;
    background: #26372d;
    border: 2px solid rgba(255, 255, 255, .8);
    border-radius: 15px;
}

#activeCallScreen > img,
#activeCallScreen > h2,
#activeCallScreen > p {
    position: relative;
    z-index: 2;
}

#activeCallStatus {
    margin-top: 8px !important;
}

.active-call-controls {
    position: absolute;
    right: 0;
    bottom: max(35px, env(safe-area-inset-bottom));
    left: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 17px;
}

.active-call-controls button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 63px;
    min-height: 65px;
    padding: 8px;
    color: #fff;
    background: rgba(255, 255, 255, .16);
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 18px;
    font-size: 10px;
}

.active-call-controls button i {
    font-size: 19px;
}

#endCallButton {
    background: #d94343;
    border-color: #d94343;
}

/* =========================================================
   TOAST
========================================================= */

#messagesToast {
    position: fixed;
    right: 18px;
    bottom: calc(85px + env(safe-area-inset-bottom));
    left: 18px;
    z-index: 500;
    width: fit-content;
    max-width: calc(100% - 36px);
    margin: 0 auto;
    padding: 12px 18px;
    color: #fff;
    background: #24372c;
    border-radius: 25px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, .16);
    font-size: 13px;
    line-height: 1.4;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
    transition: opacity .2s ease, transform .2s ease;
}

#messagesToast.show {
    opacity: 1;
    transform: translateY(0);
}

/* =========================================================
   COMMUNITY NAVIGATION
========================================================= */

#communityNavMount {
    position: relative;
    z-index: 30;
}

/* =========================================================
   SMALL SCREENS
========================================================= */

@media (max-width: 380px) {
    .chat-header-actions {
        gap: 5px;
    }

    .chat-header-actions button {
        width: 33px;
        font-size: 17px;
    }

    .message-bubble {
        max-width: 84%;
    }

    .active-call-controls {
        gap: 9px;
    }

    .active-call-controls button {
        min-width: 57px;
    }
}

@media (min-width: 700px) {
    #inboxView,
    #newMessageView,
    #blockedUsersScreen {
        max-width: 650px;
        margin: 0 auto;
        border-right: 1px solid var(--msg-border);
        border-left: 1px solid var(--msg-border);
    }

    #chatView {
        max-width: 850px;
        margin: 0 auto;
        border-right: 1px solid var(--msg-border);
        border-left: 1px solid var(--msg-border);
    }
}
