/* =============================================
   MESSENGER MODULE — Native AngularJS
   ============================================= */

/* === Layout: 2-panel === */
.messenger-container {
    display: flex;
    height: calc(100vh - 64px);
    background: #fff;
    overflow: hidden;
}

/* === Sidebar (Room List) === */
.messenger-sidebar {
    width: 340px;
    min-width: 340px;
    border-right: 1px solid #e8e8e8;
    display: flex;
    flex-direction: column;
    background: #fafafa;
}

.messenger-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px 8px;
    flex-shrink: 0;
}

.messenger-sidebar-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #1a1a1a;
}

.messenger-sidebar-search {
    padding: 8px 16px 12px;
    flex-shrink: 0;
}

.messenger-sidebar-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 13px;
    outline: none;
    background: #fff;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.messenger-sidebar-search input:focus {
    border-color: #08b0a0;
}

.messenger-room-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

/* === Room Item === */
.messenger-room-item {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    cursor: pointer;
    transition: background-color 0.15s;
    border-bottom: 1px solid #f0f0f0;
    gap: 12px;
}

.messenger-room-item:hover {
    background-color: #f0f0f0;
}

.messenger-room-item.active {
    background-color: #e8f5f3;
}

.messenger-room-item.unread {
    background-color: #e8f5f3;
}

.messenger-room-item.unread .room-name {
    font-weight: 600;
}

.messenger-room-item.unread .room-last-message {
    font-weight: 500;
    color: #333;
}

.room-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.room-info-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.room-name {
    font-size: 14px;
    font-weight: 500;
    color: #1a1a1a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.room-time {
    font-size: 11px;
    color: #999;
    white-space: nowrap;
    flex-shrink: 0;
}

.room-last-message {
    font-size: 12px;
    color: #888;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 4px;
}

.room-last-message .material-icons {
    font-size: 14px;
}

/* === Chat Avatar === */
.chat-avatar {
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    background-color: #08b0a0;
    position: relative;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-avatar.small {
    width: 32px;
    height: 32px;
    min-width: 32px;
    font-size: 12px;
}

.chat-avatar.xsmall {
    width: 28px;
    height: 28px;
    min-width: 28px;
    font-size: 11px;
}

.chat-avatar.large {
    width: 64px;
    height: 64px;
    min-width: 64px;
    font-size: 24px;
}

/* === Chat Area (Right Panel) === */
.messenger-chat-area {
    flex: 1;
    display: flex;
    flex-direction: row;
    background: #fff;
    min-width: 0;
    overflow: hidden;
}

.messenger-chat-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.messenger-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #999;
    gap: 12px;
}

.messenger-empty-state .material-icons {
    font-size: 64px;
    color: #ddd;
}

.messenger-empty-state p {
    font-size: 14px;
    margin: 0;
}

/* === Chat Header === */
.chat-header {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid #e8e8e8;
    background: #fff;
    flex-shrink: 0;
    gap: 12px;
    min-height: 56px;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

.chat-header-info h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #1a1a1a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-info span {
    font-size: 12px;
    color: #999;
}

.chat-header-actions {
    display: flex;
    gap: 4px;
}

.chat-header-actions button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    color: #666;
    transition: background-color 0.15s;
}

.chat-header-actions button:hover {
    background-color: #f0f0f0;
}

/* === Messages Area === */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* === Day Separator === */
.chat-day-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 16px 0;
}

.chat-day-separator span {
    font-size: 11px;
    color: #999;
    background: #f5f5f5;
    padding: 4px 12px;
    border-radius: 12px;
}

/* === Message Bubble === */
.message-row {
    display: flex;
    gap: 8px;
    max-width: 70%;
    align-items: flex-end;
    position: relative;
    overflow: visible;
}

.message-row.mine {
    margin-left: auto;
    flex-direction: row-reverse;
}

.message-row.other {
    margin-right: auto;
}

.message-row.system {
    margin-left: auto;
    margin-right: auto;
    max-width: 90%;
}

.message-bubble-wrap {
    position: relative;
    overflow: visible;
}

.message-bubble {
    padding: 8px 12px;
    border-radius: 16px;
    position: relative;
    word-wrap: break-word;
    word-break: break-word;
}

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

.message-row.mine .message-bubble {
    background: #08b0a0;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message-sender-name {
    font-size: 11px;
    font-weight: 600;
    color: #666;
    margin-bottom: 2px;
}

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

.message-row.mine .message-text a {
    color: #e0f7fa;
}

.message-row.other .message-text a {
    color: #08b0a0;
}

.message-time {
    font-size: 10px;
    color: #aaa;
    margin-top: 4px;
    text-align: right;
}

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

/* === System Message === */
.message-system {
    font-size: 12px;
    color: #999;
    font-style: italic;
    text-align: center;
    padding: 4px 12px;
    background: #f5f5f5;
    border-radius: 12px;
}

/* === Image Message === */
.message-image {
    max-width: 250px;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    margin: 4px 0;
}

.message-image img {
    width: 100%;
    display: block;
    border-radius: 8px;
}

/* === File Message === */
.message-file {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    cursor: pointer;
    min-width: 180px;
    transition: background-color 0.15s;
}

.message-file:hover {
    background: rgba(0, 0, 0, 0.08);
}

.message-row.mine .message-file {
    background: rgba(255, 255, 255, 0.15);
}

.message-row.mine .message-file:hover {
    background: rgba(255, 255, 255, 0.25);
}

.message-file .material-icons {
    font-size: 28px;
}

.message-file-name {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

/* === Reactions === */
.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.reaction-badge {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px 6px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.15s;
}

.reaction-badge:hover {
    background: #f0f0f0;
}

.reaction-badge .count {
    font-size: 11px;
    color: #666;
}

/* === Reaction Picker === */
.reaction-picker {
    display: none;
    position: absolute;
    top: -36px;
    left: 0;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    padding: 4px 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    z-index: 100;
    gap: 2px;
    white-space: nowrap;
}

.message-bubble-wrap:hover .reaction-picker {
    display: flex;
}

.reaction-picker button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 2px 4px;
    border-radius: 50%;
    transition: transform 0.15s;
}

.reaction-picker button:hover {
    transform: scale(1.3);
}

/* === Message Input Area === */
.chat-input-area {
    display: flex;
    align-items: flex-end;
    padding: 10px 16px;
    border-top: 1px solid #e8e8e8;
    background: #fff;
    gap: 8px;
    flex-shrink: 0;
}

.chat-input-area .attach-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    color: #666;
    border-radius: 50%;
    transition: background-color 0.15s;
    flex-shrink: 0;
}

.chat-input-area .attach-btn:hover {
    background-color: #f0f0f0;
}

.chat-input-area textarea {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    resize: none;
    max-height: 120px;
    min-height: 36px;
    line-height: 1.4;
    transition: border-color 0.2s;
}

.chat-input-area textarea:focus {
    border-color: #08b0a0;
}

.chat-input-area .send-btn {
    background: #08b0a0;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: #fff;
    border-radius: 50%;
    transition: background-color 0.15s;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-input-area .send-btn:hover {
    background-color: #069b8c;
}

.chat-input-area .send-btn:disabled {
    background: #ccc;
    cursor: default;
}

/* === Upload Overlay === */
.upload-overlay {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    padding: 6px 16px;
    border-radius: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    font-size: 13px;
    color: #666;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* === File Input Hidden === */
.chat-file-input {
    display: none;
}

/* === Image Viewer Modal === */
.image-viewer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}

.image-viewer-overlay img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
}

.image-viewer-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    color: #fff;
    font-size: 32px;
    cursor: pointer;
    padding: 8px;
}

/* === New Chat Button === */
.new-chat-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    color: #08b0a0;
    border-radius: 50%;
    transition: background-color 0.15s;
}

.new-chat-btn:hover {
    background-color: #e8f5f3;
}

/* === Dropdown Menu === */
.messenger-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    z-index: 100;
    min-width: 180px;
    overflow: hidden;
}

.messenger-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    font-size: 13px;
    color: #333;
    transition: background-color 0.15s;
}

.messenger-dropdown-item:hover {
    background-color: #f5f5f5;
}

.messenger-dropdown-item .ms-Icon {
    color: #666;
}

.messenger-dropdown-item.danger {
    color: #e74c3c;
}

.messenger-dropdown-item.danger .material-icons {
    color: #e74c3c;
}

/* === Contact List (in Modal) === */
.contact-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.contact-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    cursor: pointer;
    transition: background-color 0.15s;
}

.contact-item:hover {
    background-color: #f5f5f5;
}

.contact-item.selected {
    background-color: #e8f5f3;
}

.contact-item-info {
    flex: 1;
    min-width: 0;
}

.contact-item-name {
    font-size: 14px;
    font-weight: 500;
    color: #1a1a1a;
}

.contact-item-group {
    font-size: 12px;
    color: #999;
}

.contact-item .material-icons.check-icon {
    color: #08b0a0;
    font-size: 20px;
}

/* === Selected Members Chips === */
.selected-members {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 16px;
}

.member-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    background: #e8f5f3;
    border-radius: 16px;
    padding: 4px 10px;
    font-size: 12px;
    color: #08b0a0;
}

.member-chip .remove-chip {
    cursor: pointer;
    font-size: 14px;
    margin-left: 2px;
}

/* === Members List (in Chat Detail) === */
.members-panel {
    width: 280px;
    min-width: 280px;
    height: 100%;
    border-left: 1px solid #e8e8e8;
    display: flex;
    flex-direction: column;
    background: #fafafa;
    overflow: hidden;
}

.members-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid #e8e8e8;
}

.members-panel-header h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

.members-panel-add {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    color: #666;
    margin-left: auto;
    margin-right: 4px;
    transition: background-color 0.15s, color 0.15s;
}

.members-panel-add:hover {
    background-color: #f0f0f0;
    color: #08b0a0;
}

.members-panel-close {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    color: #666;
    transition: background-color 0.15s;
}

.members-panel-close:hover {
    background-color: #f0f0f0;
}

.members-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.member-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
}

.member-item-name {
    font-size: 13px;
    font-weight: 500;
}

.member-remove-btn {
    margin-left: auto;
    border: none;
    background: none;
    padding: 4px 6px;
    border-radius: 4px;
    color: #999;
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s, color .15s, background-color .15s;
}

.member-item:hover .member-remove-btn {
    opacity: 1;
}

.member-remove-btn:hover {
    color: #d93025;
    background-color: rgba(217, 48, 37, .08);
}

.members-panel-footer {
    margin-top: auto;
    padding: 12px 16px;
    border-top: 1px solid #eee;
}

.leave-group-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: none;
    background: none;
    padding: 8px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    color: #d93025;
    cursor: pointer;
}

.leave-group-btn:hover {
    background-color: rgba(217, 48, 37, .08);
}

/* === Loading State === */
.messenger-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: #999;
}

.room-skeleton {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    gap: 12px;
}

.skeleton-circle {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

.skeleton-lines {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.skeleton-line {
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

.skeleton-line.short {
    width: 60%;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* === Attach Menu === */
.attach-menu {
    position: absolute;
    bottom: 100%;
    left: 0;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
    margin-bottom: 8px;
    overflow: hidden;
    z-index: 10;
}

.attach-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    font-size: 13px;
    color: #333;
    white-space: nowrap;
    transition: background-color 0.15s;
}

.attach-menu-item:hover {
    background-color: #f5f5f5;
}

.attach-menu-item .material-icons {
    font-size: 18px;
    color: #08b0a0;
}

/* === Responsive === */
@media (max-width: 768px) {
    .messenger-sidebar {
        width: 100%;
        min-width: 100%;
    }

    .messenger-chat-area {
        display: none;
    }

    .messenger-container.chat-open .messenger-sidebar {
        display: none;
    }

    .messenger-container.chat-open .messenger-chat-area {
        display: flex;
    }

    .members-panel {
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        z-index: 50;
        box-shadow: -4px 0 12px rgba(0, 0, 0, 0.1);
    }

    .message-row {
        max-width: 85%;
    }
}

/* === Scrollbar === */
.messenger-room-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar,
.contact-list::-webkit-scrollbar,
.members-list::-webkit-scrollbar {
    width: 6px;
}

.messenger-room-list::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track,
.contact-list::-webkit-scrollbar-track,
.members-list::-webkit-scrollbar-track {
    background: transparent;
}

.messenger-room-list::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb,
.contact-list::-webkit-scrollbar-thumb,
.members-list::-webkit-scrollbar-thumb {
    background-color: #d0d0d0;
    border-radius: 3px;
}

.messenger-room-list::-webkit-scrollbar-thumb:hover,
.chat-messages::-webkit-scrollbar-thumb:hover {
    background-color: #bbb;
}
