/* ========================================
   FACEBOOK MESSENGER-STYLE FULL-SCREEN LAYOUT
   ======================================== */

/*
 * Fixed positioning removes the layout from normal document flow, so the
 * Bootstrap container wrapper and the page footer have no effect on its height.
 * The navbar is fixed-top at 52px; we start directly below it.
 */
.chat-messenger-layout {
    position: fixed;
    top: 52px; /* .topFiller height — matches the fixed navbar */
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    overflow: hidden;
    background: #f0f2f5;
    z-index: 10; /* above page content, below Bootstrap modals (z-index 1050) */
}

/* Left conversations panel — reuses .conversation-* classes from messenger.css */
.conversations-panel {
    width: 260px;
    flex-shrink: 0;
    background: #fff;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.conversations-panel .conversations-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid #e0e0e0;
    background: #f8f9fa;
    flex-shrink: 0;
}

.conversations-panel .conversations-header h2 {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
    color: #2d3748;
}

.conversations-panel .conversations-search {
    padding: 10px 12px;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.conversations-panel .conversations-search input {
    width: 100%;
    padding: 8px 14px;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    font-size: 13px;
    background: #f0f2f5;
    outline: none;
}

.conversations-panel .conversations-list {
    flex: 1;
    overflow-y: auto;
}

/* Right chatroom panel fills remaining space */
.chatroom-panel {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Override .chatroomWrapper to fill the panel instead of using fixed sizes */
.chatroom-panel .chatroomWrapper {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    min-width: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
    margin: 0;
    background: #fff;
    /* overflow:hidden removed — it would clip the footer when inner content overflows */
}

.chatroom-panel .chatroomHeader {
    flex-shrink: 0;
    border-radius: 0;
    margin-bottom: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.chatroom-panel .chatroomHeader span {
    font-size: 16px;
    font-weight: 700;
    flex: 1;
}

.chatroom-panel .chatroomTable {
    flex: 1;
    min-height: 0;
    display: flex;
    overflow: hidden;
}

.chatroom-panel .chatroomContainer {
    flex: 1;
    min-height: 0;
    display: flex;
    overflow: hidden;
}

/* Chat messages area fills remaining space — override the fixed 400px height */
.chatroom-panel .chatroomContent {
    flex: 1;
    min-height: 0;
    height: auto !important;
    overflow-y: auto;
    border-radius: 0;
    box-shadow: none;
    background: #f8f9fa;
}

/* Participants sidebar inside the chat panel */
.chatroom-panel .chatroomUsers {
    width: 220px;
    min-height: 0;
    height: auto !important;
    flex-shrink: 0;
    overflow-y: auto;
    border-right: 1px solid #e0e0e0;
    border-radius: 0;
    background: #fafafa;
    float: none;
}

.chatroom-panel .chatroomFooter {
    flex-shrink: 0;
    margin-top: 0;
    border-top: 1px solid #e0e0e0;
    padding: 12px 16px;
    background: #fff;
}

/* ========================================
   MODERN CHATROOM STYLING
   ======================================== */

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Modern Chat Container */
.chatroomWrapper {
    border: none;
    min-width: 990px;
    padding: 20px;
    margin: 4px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.1);
}

.chatroomContainer {
    width: 100%;
}

/* Modern Chat Content Area */
.chatroomContainer .chatroomContent {
    height: 400px;
    min-width: 500px;
    overflow-y: auto;
    overflow-x: hidden;
    border: none;
    padding: 15px;
    border-radius: 15px;
    background: #ffffff;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.05);
}

/* Facebook Messenger-Style Chat Messages */
.chatroomContainer .chatroomContent .chatMessage {
    margin-bottom: 8px;
    clear: both;
    animation: fadeIn 0.3s ease-out;
}

.chatroomContainer .chatroomContent .chatMessage .messageWrapper {
    display: flex;
    align-items: flex-end;
    max-width: 70%;
    margin-top: 4px;
}

.chatroomContainer .chatroomContent .chatMessage .messageAvatar {
    width: 32px;
    height: 32px;
    margin-right: 8px;
    flex-shrink: 0;
}

.chatroomContainer .chatroomContent .chatMessage .messageAvatar .avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.chatroomContainer .chatroomContent .chatMessage .messageBubble {
    display: flex;
    flex-direction: column;
    padding: 8px 12px;
    border-radius: 18px;
    max-width: 100%;
    word-wrap: break-word;
}

.chatroomContainer .chatroomContent .chatMessage .messageHeader {
    font-size: 11px;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chatroomContainer .chatroomContent .chatMessage .messageAuthor {
    font-weight: 600;
    color: #65676b;
}

.chatroomContainer .chatroomContent .chatMessage .messageTime {
    font-size: 10px;
    color: #8a8d91;
}

.chatroomContainer .chatroomContent .chatMessage .messageContent {
    line-height: 1.4;
    font-size: 14px;
}

/* Other user's messages (left-aligned) */
.chatroomContainer .chatroomContent .chatMessageOther .messageWrapper {
    float: left;
}

.chatroomContainer .chatroomContent .chatMessageOther .messageBubble {
    background: #e4e6eb;
    color: #050505;
}

/* Own messages (right-aligned, like Facebook Messenger) */
.chatroomContainer .chatroomContent .chatMessageOwn .messageWrapper {
    float: right;
    flex-direction: row-reverse;
}

.chatroomContainer .chatroomContent .chatMessageOwn .messageAvatar {
    margin-right: 0;
    margin-left: 8px;
}

.chatroomContainer .chatroomContent .chatMessageOwn .messageBubble {
    background: linear-gradient(135deg, #0084ff, #0066cc);
    color: white;
}

.chatroomContainer .chatroomContent .chatMessageOwn .messageAuthor,
.chatroomContainer .chatroomContent .chatMessageOwn .messageTime {
    color: rgba(255, 255, 255, 0.8);
}

.chatroomContainer .chatroomContent .chatMessage img {
    vertical-align: middle;
    border-radius: 8px;
}

/* Modern Chat Users Sidebar */
.chatroomUsers {
    margin-right: 15px;
    overflow-y: auto;
    overflow-x: hidden;
    width: 200px;
    height: 400px;
    float: left;
    padding: 10px;
    white-space: nowrap;
    vertical-align: top;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.05), rgba(118, 75, 162, 0.05));
    border-radius: 15px;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.05);
}

.chatroomUsers .chatroomUser {
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 12px;
    padding: 10px;
    margin-bottom: 8px;
    background: white;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.chatroomUsers .chatroomUser:hover {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
    border-color: #667eea;
    transform: translateX(5px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.chatroomUsers .guestUser {
    border: 2px solid #e8eaf6;
    padding: 8px 8px 8px 35px;
    border-radius: 12px;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #f8f9fa, #ffffff);
    background-image: url("/resources/gfx/chatroom/guest.png");
    background-repeat: no-repeat;
    background-position: 8px center;
    background-size: 20px;
}

.chatroomUsers .chatroomUser .userProfilePicture {
    float: left;
    margin-right: 8px;
    border-radius: 8px;
    overflow: hidden;
}

.chatroomUsers .chatroomUser .info {
    float: left;
}

.chatroomUsers .chatroomUser .info .username {
    font-weight: 700;
    color: #2c3e50;
    font-size: 13px;
}

.chatroomUsers .chatroomUser .info .profile {
    font-size: 11px;
    color: #888;
}

.chatroomUsers .chatroomUser .info .geo {
    font-size: 11px;
    color: #888;
}

/* Modern Chat Header */
.chatroomHeader {
    padding: 15px;
    font-size: 18px;
    font-weight: 700;
    color: #2c3e50;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
    border-radius: 12px;
    margin-bottom: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* Modern Chat Footer/Input */
.chatroomFooter {
    margin-top: 15px;
}

.chatroomMessage {
    display: flex;
    gap: 10px;
    align-items: center;
}

.chatroomFooter #line {
    flex: 1;
    border-radius: 20px;
    border: 1px solid #ccd0d5;
    padding: 10px 15px;
    font-size: 14px;
    transition: all 0.3s ease;
}

.chatroomFooter #line:focus {
    border-color: #0084ff;
    box-shadow: 0 0 0 2px rgba(0, 132, 255, 0.1);
    outline: none;
}

.chatroomFooter #btnSend {
    background: linear-gradient(135deg, #0084ff, #0066cc);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 10px 20px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.chatroomFooter #btnSend:hover {
    background: linear-gradient(135deg, #0066cc, #0052a3);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 132, 255, 0.3);
}

.chatroomFooter #btnSend:active {
    transform: translateY(0);
}

.chatroomFooter .chatMessage .chatroomNickname {
    float: left;
    color: #667eea;
    padding: 8px 12px;
    font-weight: 600;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 8px;
    margin-right: 8px;
}

/* Load Older Messages Button */
#loadOlder {
    width: 100%;
    margin-bottom: 10px;
    background: #f0f2f5;
    color: #65676b;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

#loadOlder:hover {
    background: #e4e6eb;
}

/* Modern Color Picker */
#colorpicker {
    float: left;
    padding: 4px;
}

.jPicker {
    border: 2px solid #667eea;
    width: 20px;
    height: 20px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.jPicker:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

/* Scrollbar Styling */
.chatroomUsers::-webkit-scrollbar,
.chatroomContent::-webkit-scrollbar {
    width: 8px;
}

.chatroomUsers::-webkit-scrollbar-track,
.chatroomContent::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.chatroomUsers::-webkit-scrollbar-thumb,
.chatroomContent::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-radius: 10px;
}

.chatroomUsers::-webkit-scrollbar-thumb:hover,
.chatroomContent::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #7689f0, #8659b0);
}

/* ========================================
   EXISTING STYLES
   ======================================== */

#header { color: #555 }

.chatroomTable { }

.rounded { border-radius: 10px  }

.list { margin-bottom: 16px}
.loginBox { width: 400px; float: right }

#profileSearchForm { border: 1px solid #888; border-radius: 15px; float: left; }
#profileSearchForm .field { float: left;  clear: none }

#filterBox .filterOptionBox .filterOptionSelectionsBox #username { width: 200px; }
#filterBox .filterOptionBox .filterOptionSelectionsBox #Labelcity { width: 200px; }

.box.medium { cursor: pointer }

/* ========================================
   RESPONSIVE CHATROOM STYLES
   ======================================== */

/* Tablet devices */
@media (max-width: 991.98px) {
    .chatroomWrapper {
        min-width: auto;
        padding: 15px;
        border-radius: 15px;
    }

    .chatroomContainer .chatroomContent {
        min-width: auto;
        height: 350px;
    }

    .chatroomUsers {
        max-height: 250px;
    }

    .chatMessage .messageWrapper {
        max-width: 80%;
    }
}

/* Mobile devices */
@media (max-width: 767.98px) {
    /* On mobile the navbar grows to 56px */
    .chat-messenger-layout {
        top: 56px;
        flex-direction: column;
    }

    /* Conversations panel fills full width on mobile */
    .conversations-panel {
        width: 100%;
        flex: 1;
        min-height: 0;
    }

    /* Chatroom panel hidden until a conversation is opened */
    .chatroom-panel {
        display: none;
        position: fixed;
        top: 56px;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 100;
    }

    /* chatroom-active: show chat, hide conversations list */
    .chat-messenger-layout.chatroom-active .conversations-panel {
        display: none;
    }

    .chat-messenger-layout.chatroom-active .chatroom-panel {
        display: flex;
    }

    /* Full-height chatroom on mobile */
    .chatroom-panel .chatroomWrapper {
        border-radius: 0;
        padding: 0;
        margin: 0;
    }

    .chatroom-panel .chatroomHeader {
        border-radius: 0;
        padding: 12px 15px;
        flex-shrink: 0;
    }

    /* Toggle button for participants */
    .participants-toggle {
        background: linear-gradient(135deg, #667eea, #764ba2);
        color: white;
        border: none;
        border-radius: 8px;
        padding: 8px 12px;
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        display: flex;
        align-items: center;
        gap: 6px;
        transition: all 0.3s ease;
        box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    }

    .participants-toggle:active {
        transform: scale(0.95);
    }

    .participants-toggle i {
        font-size: 16px;
    }

    .chatroom-panel .chatroomTable {
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .chatroom-panel .chatroomContainer {
        flex: 1;
        display: flex;
        flex-direction: column;
        position: relative;
        overflow: hidden;
    }

    .chatroom-panel .chatroomContent {
        flex: 1;
        min-width: auto;
        height: auto !important;
        padding: 10px;
        border-radius: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Participants list — collapsible overlay on mobile */
    .chatroom-panel .chatroomUsers {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1001;
        width: auto;
        height: auto;
        float: none;
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(10px);
        border-radius: 0;
        padding: 15px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .chatroom-panel .chatroomUsers.show {
        transform: translateX(0);
        box-shadow: 2px 0 20px rgba(0, 0, 0, 0.3);
    }

    /* Participants header with close button */
    .participants-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 15px;
        margin: -15px -15px 15px -15px;
        background: linear-gradient(135deg, #667eea, #764ba2);
        color: white;
        font-size: 18px;
        font-weight: 700;
        position: sticky;
        top: -15px;
        z-index: 10;
    }

    .participants-close {
        background: rgba(255, 255, 255, 0.2);
        border: none;
        color: white;
        border-radius: 50%;
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.3s ease;
        font-size: 20px;
    }

    .participants-close:active {
        background: rgba(255, 255, 255, 0.3);
        transform: scale(0.95);
    }

    .chatroomUser {
        padding: 12px;
        font-size: 14px;
        margin-bottom: 10px;
    }

    /* Footer - fixed at bottom */
    .chatroom-panel .chatroomFooter {
        margin-top: 0;
        padding: 10px 15px;
        flex-shrink: 0;
    }

    .chatroomMessage {
        flex-wrap: wrap;
    }

    .chatroomFooter #line {
        padding: 12px 15px;
        font-size: 16px;
    }

    .chatroomFooter #btnSend {
        padding: 12px 20px;
        font-size: 16px;
    }

    #colorpicker {
        float: none;
        display: inline-block;
        margin-right: 10px;
    }

    /* Stack chat layout vertically on mobile */
    .chatMessage .messageWrapper {
        max-width: 85%;
    }

    /* Hide body scroll when chat is open on mobile */
    body.chat-open-mobile {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }
}

/* Small mobile devices */
@media (max-width: 575.98px) {
    .chatroomWrapper {
        padding: 0;
        border-radius: 0;
    }

    .chatroomContainer .chatroomContent {
        padding: 8px;
    }

    .chatroomUsers {
        padding: 12px;
    }

    .chatMessage .messageWrapper {
        max-width: 90%;
    }

    .chatMessage .messageAvatar {
        width: 24px;
        height: 24px;
        margin-right: 4px;
    }

    .chatMessage .messageBubble {
        padding: 5px 8px;
        border-radius: 12px;
        font-size: 13px;
    }

    .chatroomHeader {
        font-size: 16px;
        padding: 10px 12px;
    }

    .participants-toggle {
        padding: 6px 10px;
        font-size: 13px;
    }

    .participants-toggle i {
        font-size: 14px;
    }

    /* Private message modal responsive */
    #privateMessageModal .modal-dialog {
        margin: 0.5rem;
    }

    #privateMessageModal .modal-body {
        padding: 15px;
    }

    #privateMessageModal #privateMessageText {
        min-height: 80px;
        font-size: 14px;
    }
}

/* Landscape orientation adjustments */
@media (max-width: 767.98px) and (orientation: landscape) {
    .chatroomHeader {
        padding: 8px 15px;
        font-size: 16px;
    }

    .participants-toggle {
        padding: 6px 10px;
        font-size: 13px;
    }

    .chatroomFooter {
        padding: 8px 15px;
    }

    .chatroomFooter #line,
    .chatroomFooter #btnSend {
        padding: 8px 15px;
        font-size: 14px;
    }
}

/* Ensure chat content is always scrollable */
@media (max-width: 991.98px) {
    .chatroomContainer .chatroomContent {
        overflow-y: scroll;
        -webkit-overflow-scrolling: touch;
    }
}

/* Touch-friendly buttons on mobile */
@media (max-width: 767.98px) {
    button, .btn, .chatroomInputWrapper button {
        min-height: 44px;
        padding: 12px 20px;
        font-size: 16px;
    }

    .chatroomUser,
    .guestUser {
        min-height: 44px;
        padding: 10px 8px;
    }
}

