/* =========================
   CHAT PAGE
========================= */

.chat-page {
    width: 100%;
    height: calc(100vh - 40px);
    min-height: 550px;
    padding: 15px;
}

.chat-layout {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    height: 100%;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 16px;
    overflow: hidden;
}

/* CHAT SIDEBAR */

.chat-sidebar {
    display: flex;
    flex-direction: column;
    border-right: 1px solid #eee;
    min-width: 0;
}

.chat-sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 22px 18px;
}

.chat-sidebar-header h1 {
    font-size: 24px;
    font-weight: 700;
}

.chat-sidebar-header button,
.active-chat-header > button {
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 9px;
    border-radius: 50%;
}

.chat-sidebar-header button:hover,
.active-chat-header > button:hover {
    background: #f4f4f5;
}

.chat-search {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 15px 15px;
    padding: 11px 13px;
    background: #f5f5f7;
    border-radius: 10px;
}

.chat-search input {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-size: 14px;
}

.chat-conversation-list {
    flex: 1;
    overflow-y: auto;
}

/* EMPTY STATE */

.chat-empty-state,
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 30px;
    color: #888;
}

.chat-empty-state i,
.chat-welcome i {
    width: 45px;
    height: 45px;
    margin-bottom: 15px;
    color: #d94675;
}

.chat-empty-state h3,
.chat-welcome h2 {
    color: #333;
    margin-bottom: 8px;
}

.chat-empty-state p,
.chat-welcome p {
    font-size: 13px;
}

/* CONVERSATION ITEM */

.chat-conversation {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    cursor: pointer;
    transition: background 0.2s;
}

.chat-conversation:hover {
    background: #faf5f7;
}

.chat-conversation.active {
    background: #fff0f5;
}

.chat-avatar {
    width: 46px;
    height: 46px;
    min-width: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #fce7f3;
    color: #be185d;
    font-weight: 700;
    font-size: 17px;
}

.chat-conversation-info {
    flex: 1;
    min-width: 0;
}

.chat-conversation-info h4 {
    font-size: 14px;
    margin-bottom: 5px;
    color: #222;
}

.chat-conversation-info p {
    font-size: 12px;
    color: #888;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* MAIN CHAT */

.chat-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #fff;
}

.chat-welcome {
    flex: 1;
}

.active-chat {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.active-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
}

.active-chat-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.active-chat-user h3 {
    font-size: 15px;
    margin-bottom: 4px;
}

.active-chat-user span {
    font-size: 12px;
    color: #999;
}

/* MESSAGES */

.chat-messages {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 22px;
    overflow-y: auto;
    background: #fafafa;
}

.chat-message {
    display: flex;
    max-width: 75%;
}

.chat-message.sent {
    align-self: flex-end;
}

.chat-message.received {
    align-self: flex-start;
}

.chat-message-bubble {
    padding: 11px 15px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.chat-message.sent .chat-message-bubble {
    background: #e83e70;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-message.received .chat-message-bubble {
    background: #fff;
    color: #333;
    border: 1px solid #eee;
    border-bottom-left-radius: 4px;
}

.chat-message-time {
    display: block;
    margin-top: 5px;
    font-size: 10px;
    font-weight: bold;
    opacity: 0.7;
    text-align: right;
}

/* MESSAGE INPUT */

.chat-message-form {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px 20px;
    border-top: 1px solid #eee;
}

.chat-message-form input {
    flex: 1;
    min-width: 0;
    padding: 13px 16px;
    border: 1px solid #eee;
    border-radius: 25px;
    outline: none;
    font-size: 14px;
}

.chat-message-form input:focus {
    border-color: #e83e70;
}

.chat-message-form button {
    width: 43px;
    height: 43px;
    border: none;
    border-radius: 50%;
    background: #e83e70;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.chat-message-form button:hover {
    background: #cc285b;
}

.chat-message-form button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-message-placeholder {
    text-align: center;
    color: #999;
    margin: auto;
    font-size: 13px;
}

/* RESPONSIVE */

@media (max-width: 768px) {

    .chat-page {
        height: calc(100dvh - 130px);
        min-height: 450px;
        padding: 0;
    }

    .chat-layout {
        grid-template-columns: 1fr;
        border-radius: 0;
    }

    .chat-sidebar {
        border-right: none;
    }

    .chat-main {
        display: none;
    }

    .chat-layout.chat-open .chat-sidebar {
        display: none;
    }

    .chat-layout.chat-open .chat-main {
        display: flex;
    }

    .chat-message {
        max-width: 88%;
    }

}

/* NEW CHAT STUDENT SEARCH */

.new-chat-search {
    padding: 12px;
    width: 100%;
}

.new-chat-search input {
    width: 100%;
    padding: 13px 16px;
    border: 1px solid var(--border-color, #ddd);
    border-radius: 12px;
    outline: none;
    font-size: 14px;
    background: var(--card-bg, #fff);
    color: var(--text-color, #222);
    margin-bottom: 12px;
    box-sizing: border-box;
}

.new-chat-search input:focus {
    border-color: var(--primary-color, #7c3aed);
}

#newChatSearchResults {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#newChatSearchResults > p {
    padding: 15px;
    text-align: center;
    color: var(--text-secondary, #888);
    font-size: 13px;
}

#newChatSearchResults .chat-conversation {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: none;
    border-radius: 12px;
    background: transparent;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s ease;
}

#newChatSearchResults .chat-conversation:hover {
    background: var(--hover-bg, #f3f3f3);
}

#newChatSearchResults .chat-avatar {
    width: 46px;
    height: 46px;
    min-width: 46px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-color, #7c3aed);
    color: white;
    font-size: 18px;
    font-weight: 600;
}

#newChatSearchResults .chat-conversation-info {
    min-width: 0;
    flex: 1;
}

#newChatSearchResults .chat-conversation-info h4 {
    margin: 0 0 5px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-color, #222);
}

#newChatSearchResults .chat-conversation-info p {
    margin: 0;
    font-size: 12px;
    color: var(--text-secondary, #888);
}

/* FIX CONVERSATION BUTTONS */

.chat-conversation {
    width: 100%;
    border: none;
    background: transparent;
    text-align: left;
    font-family: inherit;
    box-sizing: border-box;
}

.chat-conversation.active {
    background: #fff0f5;
}

/* FIX MESSAGE BUBBLES */

.chat-message-content {
    padding: 11px 15px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.chat-message.sent .chat-message-content {
    background: #e83e70;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-message.received .chat-message-content {
    background: #fff;
    color: #333;
    border: 1px solid #eee;
    border-bottom-left-radius: 4px;
}

/* Back button */
.back-to-chats {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #333;
    cursor: pointer;
    flex-shrink: 0;
}

.back-to-chats:hover {
    background: #f3f3f3;
    color: #e83e70;
}

.back-to-chats i,
.back-to-chats svg {
    width: 22px;
    height: 22px;
}

.active-chat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.back-from-student-search {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 15px;
    border: none;
    border-bottom: 1px solid #eee;
    background: #fff;
    color: #333;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
}

.back-from-student-search:hover {
    background: #fff0f5;
    color: #e83e70;
}

.back-from-student-search i,
.back-from-student-search svg {
    width: 20px;
    height: 20px;
}

/* Individual message options */
.chat-message {
    position: relative;
}



.message-options-btn:hover {
    background: #fff;
    color: #e83e70;
}

/* INSTAGRAM-STYLE MESSAGE OPTIONS */

.chat-message {
    position: relative;
    display: flex;
    align-items: center;
    gap: 5px;
    width: fit-content;
    max-width: 75%;
}

.chat-message.sent {
    flex-direction: row-reverse;
    align-self: flex-end;
}

.chat-message.received {
    flex-direction: row;
    align-self: flex-start;
}

.chat-message-content {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
}

.message-options {
    position: relative;
    flex-shrink: 0;
}

.message-options-btn {
    width: 25px;
    height: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #777;
    cursor: pointer;
    opacity: 0;
    transition: background 0.2s, opacity 0.2s;
}

.chat-message:hover .message-options-btn,
.message-options-btn:focus,
.message-options-btn[aria-expanded="true"] {
    opacity: 1;
}

.message-options-btn:hover {
    background: #eee;
    color: #e83e70;
}

.message-options-btn svg {
    width: 17px;
    height: 17px;
}

.message-options-menu {
    display: none;
    position: absolute;
    top: 28px;
    right: 0;
    z-index: 100;
    min-width: 175px;
    padding: 5px;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
}

.message-options-menu.show {
    display: flex;
    flex-direction: column;
}

.message-options-menu button {
    width: 100%;
    padding: 10px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #333;
    font-size: 13px;
    text-align: left;
    white-space: nowrap;
    cursor: pointer;
}

.message-options-menu button:hover {
    background: #f5f5f5;
}

.message-options-menu .delete-message-everyone {
    color: #d93025;
}

@media (max-width: 768px) {
    .chat-message {
        max-width: 88%;
    }

    .message-options-btn {
        opacity: 1;
    }
}

.chat-message-time {
    display: block;
    margin-top: 4px;
    font-size: 10px;
    color: #000;
    text-align: right;
}


.message-options-menu button {
    padding: 10px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #333;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.message-options-menu button:hover {
    background: #fff0f5;
    color: #e83e70;
}

.delete-message-everyone {
    color: #d93025 !important;
}

.delete-message-everyone:hover {
    background: #fff0ef !important;
}

/* =========================
   CHAT MESSAGE LAYOUT FIX
========================= */

.chat-messages {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    min-width: 0;
}

.chat-message {
    position: relative;
    display: flex;
    width: fit-content;
    max-width: 75%;
    min-width: 0;
}

.chat-message.sent {
    align-self: flex-end;
}

.chat-message.received {
    align-self: flex-start;
}

.chat-message-content {
    box-sizing: border-box;
    max-width: 100%;
    padding: 11px 32px 11px 15px;
    overflow-wrap: anywhere;
}

/* Instagram-style message dropdown */

.message-options {
    position: absolute;
    top: 5px;
    right: 5px;
    z-index: 10;
}

.message-options-btn {
    width: 22px;
    height: 22px;
    min-width: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.85);
    color: #555;
    font-size: 17px;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
}

.message-options-btn:hover {
    background: #fff;
    color: #e83e70;
}

.message-options-menu {
    display: none;
    position: absolute;
    top: 25px;
    right: 0;
    z-index: 20;
    min-width: 165px;
    padding: 5px;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 9px;
    box-shadow: 0 5px 18px rgba(0, 0, 0, 0.15);
}

.message-options-menu.show {
    display: flex;
    flex-direction: column;
}

@media (max-width: 768px) {
    .chat-message {
        max-width: 88%;
    }

    .chat-messages {
        padding: 15px;
    }
}

/* Keep the chat layout within the available screen height */
.chat-layout {
    height: 100%;
    min-height: 0;
}

.chat-main {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.active-chat {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Only the messages area should scroll */
.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Keep the message input and button visible */
.chat-message-form {
    flex-shrink: 0;
}

.chat-message-status {
    display: block;
    margin-top: 3px;
    font-size: 10px;
    font-weight: 500;
    line-height: 1;
    text-align: right;
}

.chat-message-status.sent {
    color: #9ca3af;
}

.chat-message-status.delivered {
    color: #60a5fa;
}

.chat-message-status.read {
    color: #22c55e;
}

.public-profile-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.public-profile-actions button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

/* SOCIETY CHAT CATEGORY TABS */

.chat-category-tabs {
    display: flex;
    gap: 8px;
    padding: 0 15px 15px;
    border-bottom: 1px solid #eee;
}

.chat-category-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 11px 8px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #fff;
    color: #64748b;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chat-category-tab svg {
    width: 16px;
    height: 16px;
}

.chat-category-tab:hover {
    background: #f5f3ff;
    border-color: #c4b5fd;
    color: #6c4cf1;
}

.chat-category-tab.active {
    background: #6c4cf1;
    border-color: #6c4cf1;
    color: #fff;
    box-shadow: 0 3px 10px rgba(108, 76, 241, 0.2);
}

.society-conversation-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

@media (max-width: 480px) {
    .chat-category-tabs {
        gap: 6px;
        padding-left: 10px;
        padding-right: 10px;
    }

    .chat-category-tab {
        font-size: 11px;
        padding: 10px 5px;
    }
}

/* =================================
   SOCIETY CHAT CONVERSATION LIST
================================= */

.society-conversation-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 12px;
}

.society-conversation-item {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 15px 16px;
    margin-bottom: 9px;
    border: 1px solid #e8eaf2;
    border-radius: 12px;
    background: #ffffff;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
}

.society-conversation-item:hover {
    background: #f5f3ff;
    border-color: #c4b5fd;
    transform: translateX(3px);
}

.society-conversation-item.active {
    background: #f0edff;
    border-color: #8b75f5;
}

.society-conversation-name {
    color: #243b70;
    font-size: 14px;
    font-weight: 700;
    text-transform: capitalize;
}

.society-conversation-role {
    display: inline-block;
    padding: 4px 9px;
    border-radius: 20px;
    background: #eeeaff;
    color: #6c4cf1;
    font-size: 10px;
    font-weight: 700;
    text-transform: capitalize;
    letter-spacing: 0.3px;
}

.society-conversation-item.active .society-conversation-role {
    background: #6c4cf1;
    color: #ffffff;
}

/* Empty state */
.society-conversation-list .chat-empty-state {
    padding: 35px 15px;
    text-align: center;
    color: #64748b;
}

.society-conversation-list .chat-empty-state svg {
    width: 35px;
    height: 35px;
    color: #8b75f5;
    margin-bottom: 12px;
}

/* =========================
   SHARED REEL IN CHAT
========================= */

.shared-reel-card {
    display: block;
    width: 240px;
    max-width: 100%;
    padding: 0;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 12px;
    background: #111;
    color: #fff;
    text-align: left;
    cursor: pointer;
}

.shared-reel-card video {
    display: block;
    width: 100%;
    max-height: 320px;
    aspect-ratio: 9 / 16;
    object-fit: cover;
    background: #111;
}

.shared-reel-label {
    display: block;
    padding: 9px 11px 2px;
    font-size: 12px;
    font-weight: 700;
}

.shared-reel-caption {
    display: -webkit-box;
    padding: 3px 11px 10px;
    overflow: hidden;
    color: #ddd;
    font-size: 12px;
    line-height: 1.4;
    overflow-wrap: anywhere;
    -webkit-box-orient: vertical;
}

.shared-reel-card:hover {
    opacity: 0.92;
}

.chat-message-content:has(.shared-reel-card) {
    padding: 6px;
}

.chat-message-content:has(.shared-reel-card) .chat-message-time {
    padding: 0 5px;
}

@media (max-width: 480px) {
    .shared-reel-card {
        width: 210px;
    }

    .shared-reel-card video {
        max-height: 280px;
    }
}

/* Shared photo post in chat */
.shared-post-card {
    display: block;
    width: 240px;
    max-width: 100%;
    padding: 0;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 12px;
    background: #111;
    color: #fff;
    text-align: left;
    cursor: pointer;
}

.shared-post-card img {
    display: block;
    width: 100%;
    max-height: 280px;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    background: #111;
}

.shared-post-card:hover {
    opacity: 0.92;
}

.chat-message-content:has(.shared-post-card) {
    padding: 6px;
}

.chat-message-content:has(.shared-post-card) .chat-message-time {
    padding: 0 5px;
}

@media (max-width: 480px) {
    .shared-post-card {
        width: 210px;
    }

    .shared-post-card img {
        max-height: 240px;
    }
}

/* Content Share Modal */
.content-share-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.65);
}

.content-share-dialog {
    width: 100%;
    max-width: 420px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    padding: 20px;
    border-radius: 18px;
    background: #fff;
    color: #171717;
}

.content-share-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.content-share-header h3 {
    margin: 0;
    font-size: 19px;
}

.content-share-header button {
    border: 0;
    background: transparent;
    font-size: 27px;
    cursor: pointer;
}

#contentShareSearch {
    width: 100%;
    padding: 12px 14px;
    margin-bottom: 14px;
    border: 1px solid #ddd;
    border-radius: 10px;
    outline: none;
}

#contentShareContacts {
    min-height: 100px;
    overflow-y: auto;
}

.content-share-contact {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 4px;
    cursor: pointer;
}

.content-share-avatar {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 50%;
    background: #eee;
}

.content-share-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.content-share-user {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.content-share-user small {
    color: #777;
}

.content-share-contact input {
    width: 18px;
    height: 18px;
    accent-color: #7654e8;
}

#sendSharedContent {
    width: 100%;
    padding: 12px;
    margin-top: 14px;
    border: 0;
    border-radius: 10px;
    background: #7654e8;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

#sendSharedContent:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.content-share-extra {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}

.content-share-extra button {
    flex: 1;
    padding: 11px;
    border: 1px solid #ddd;
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
}

@media (max-width: 480px) {
    .content-share-dialog {
        max-height: 90vh;
        padding: 16px;
    }
}

/* =========================
   UNREAD CHAT BADGES
========================= */

.unread-chat-badge,
.conversation-unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 50px;
    background: #e83e70;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    flex-shrink: 0;
}

.conversation-unread-badge {
    margin-left: auto;
}

/* Navbar badges */
.nav-link,
.mobile-nav-link {
    position: relative;
}

.unread-chat-badge {
    margin-left: auto;
}