/* ============================================ */
/* CHAT SYSTEM - IMPROVED UI STYLES */
/* ============================================ */

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2196F3;
    --primary-dark: #1976D2;
    --primary-light: #BBDEFB;
    --success-color: #4CAF50;
    --danger-color: #F44336;
    --text-primary: #212121;
    --text-secondary: #757575;
    --bg-primary: #FFFFFF;
    --bg-secondary: #F5F5F5;
    --bg-hover: #E3F2FD;
    --border-color: #E0E0E0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 20px rgba(0,0,0,0.15);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

/* ============================================ */
/* ADMIN CHAT CONTAINER */
/* ============================================ */

.admin-chat-container {
    width: 100%;
    height: 100vh;
    background: var(--bg-secondary);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    overflow: hidden;
}

.admin-chat-wrapper {
    display: flex;
    height: 100%;
    max-width: 1600px;
    margin: 0 auto;
    background: var(--bg-primary);
    box-shadow: var(--shadow-lg);
}

/* ============================================ */
/* LEFT PANEL - CONVERSATIONS */
/* ============================================ */

.chat-left-panel {
    width: 380px;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Panel Header */
.panel-header {
    padding: 16px 20px;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    min-height: 72px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.user-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
    overflow: hidden;
}

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

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

.user-details h4 {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 4px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.online-status {
    font-size: 13px;
    opacity: 0.9;
    display: block;
}

.panel-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.btn-refresh,
.btn-search {
    width: 38px;
    height: 38px;
    border: none;
    background: rgba(255,255,255,0.15);
    color: white;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.btn-refresh:hover,
.btn-search:hover {
    background: rgba(255,255,255,0.25);
    transform: scale(1.05);
}

.btn-refresh:active,
.btn-search:active {
    transform: scale(0.95);
}

.btn-refresh:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-search.active {
    background: rgba(255,255,255,0.3);
}

/* Search Box - Initially Hidden */
.search-box {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    overflow: hidden;
    flex-shrink: 0;
}

.search-input-wrapper {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-icon {
    color: var(--text-secondary);
    font-size: 16px;
    flex-shrink: 0;
}

.search-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 14px;
    color: var(--text-primary);
    background: transparent;
    min-width: 0;
}

.search-input::placeholder {
    color: var(--text-secondary);
}

.btn-close-search {
    width: 28px;
    height: 28px;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.btn-close-search:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

/* Conversation List */
.conversation-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.conversation-list::-webkit-scrollbar {
    width: 6px;
}

.conversation-list::-webkit-scrollbar-track {
    background: transparent;
}

.conversation-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.conversation-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Conversation Item */
.conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid var(--bg-secondary);
}

.conversation-item:hover {
    background: var(--bg-hover);
}

.conversation-item.active {
    background: var(--primary-light);
    border-left: 4px solid var(--primary-color);
}

.conversation-avatar {
    position: relative;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
    color: var(--primary-color);
    flex-shrink: 0;
    overflow: hidden;
}

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

.online-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: var(--success-color);
    border: 2px solid var(--bg-primary);
    border-radius: 50%;
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

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

.conversation-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.conversation-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-time {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    flex-shrink: 0;
}

.conversation-preview {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.last-message {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.unread-badge {
    background: var(--primary-color);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.conversation-details {
    display: flex;
    align-items: center;
    gap: 8px;
}

.room-info {
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
}

/* Empty States */
.loading-conversations,
.empty-conversations {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.empty-conversations i {
    font-size: 48px;
    color: var(--border-color);
    margin-bottom: 12px;
}

/* ============================================ */
/* RIGHT PANEL - CHAT AREA */
/* ============================================ */

.chat-right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    overflow: hidden;
}

/* Empty State */
.empty-chat-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

.empty-icon i {
    font-size: 80px;
    color: var(--border-color);
    margin-bottom: 20px;
}

.empty-chat-state h3 {
    font-size: 22px;
    color: var(--text-primary);
    margin: 0 0 8px 0;
}

.empty-chat-state p {
    font-size: 15px;
    margin: 0;
}

/* Active Chat */
.active-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    overflow: hidden;
}

/* Chat Header */
.chat-header {
    padding: 16px 20px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    min-height: 72px;
}

.chat-user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.chat-user-avatar {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    color: var(--primary-color);
    flex-shrink: 0;
    overflow: hidden;
}

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

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

.chat-user-details h4 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 4px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-status {
    font-size: 13px;
    display: block;
}

.user-status.online {
    color: var(--success-color);
}

.user-status.offline {
    color: var(--text-secondary);
}

.chat-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.btn-action {
    width: 38px;
    height: 38px;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s ease;
}

.btn-action:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

/* Messages Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    background: #F0F2F5;
}

.messages-container::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Messages */
.message {
    display: flex;
    margin-bottom: 12px;
    animation: fadeInMessage 0.3s ease;
}

@keyframes fadeInMessage {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-received {
    justify-content: flex-start;
}

.message-sent {
    justify-content: flex-end;
}

.message-content {
    max-width: 65%;
    min-width: 100px;
}

.message-received .message-content {
    background: var(--bg-primary);
    border-radius: 8px 8px 8px 2px;
    box-shadow: var(--shadow-sm);
}

.message-sent .message-content {
    background: var(--primary-color);
    color: white;
    border-radius: 8px 8px 2px 8px;
}

.message-text {
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message-meta {
    padding: 4px 14px 8px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    font-size: 11px;
}

.message-received .message-meta {
    color: var(--text-secondary);
}

.message-sent .message-meta {
    color: rgba(255,255,255,0.8);
}

.message-time {
    white-space: nowrap;
}

.message-status {
    display: flex;
    align-items: center;
}

.loading-messages,
.empty-messages {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: var(--text-secondary);
}

.empty-messages i {
    font-size: 56px;
    color: var(--border-color);
    margin-bottom: 16px;
}

.empty-messages p {
    margin: 4px 0;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    font-size: 13px;
    color: var(--text-secondary);
}

.typing-dots {
    display: flex;
    gap: 3px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-8px);
    }
}

/* Message Input */
.message-input-container {
    padding: 16px 20px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 8px 12px;
}

.message-input {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: transparent;
    max-height: 100px;
    padding: 6px;
}

.message-input::placeholder {
    color: var(--text-secondary);
}

.btn-send {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.btn-send:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.btn-send:active {
    transform: scale(0.95);
}

/* ============================================ */
/* USER CHAT (Floating) */
/* ============================================ */

.chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    transition: all 0.3s ease;
    z-index: 999;
}

.chat-fab:hover {
    background: var(--primary-dark);
    transform: scale(1.1);
}

.chat-fab .unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 24px;
    height: 24px;
    background: var(--danger-color);
    color: white;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    padding: 0 6px;
}

.chat-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    height: 550px;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 998;
    transform-origin: bottom right;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.chat-window.active {
    display: flex;
}

.chat-window.minimized {
    height: 72px;
}

.chat-window.minimized .messages-container,
.chat-window.minimized .typing-indicator,
.chat-window.minimized .message-input-container {
    display: none;
}

.chat-window .btn-minimize,
.chat-window .btn-close {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255,255,255,0.15);
    color: white;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.2s ease;
}

.chat-window .btn-minimize:hover,
.chat-window .btn-close:hover {
    background: rgba(255,255,255,0.25);
}

/* ============================================ */
/* RESPONSIVE */
/* ============================================ */

@media (max-width: 768px) {
    .chat-left-panel {
        width: 100%;
        border-right: none;
    }
    
    .chat-right-panel {
        display: none;
    }
    
    .chat-right-panel.active {
        display: flex;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 10;
    }
    
    .chat-window {
        width: calc(100% - 32px);
        right: 16px;
        bottom: 80px;
    }
}

/* ============================================ */
/* UTILITY CLASSES */
/* ============================================ */

.pulse {
    animation: pulse 1s ease-in-out;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

/* Accessibility */
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}