/* CSS Variables */
:root {
    --primary: #075E54;
    --primary-dark: #054D44;
    --secondary: #25D366;
    --accent: #34B7F1;
    --background: #0B141A;
    --surface: #111B21;
    --surface-light: #1F2C34;
    --surface-lighter: #2A3942;
    --text-primary: #E9EDEF;
    --text-secondary: #8696A0;
    --text-muted: #667781;
    --sent-bubble: #005C4B;
    --received-bubble: #1F2C34;
    --border: #222D34;
    --danger: #F15C6D;
    --white: #FFFFFF;
}

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

html, body {
    height: 100%;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    overflow: hidden;
}

/* Chat Container */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 500px;
    margin: 0 auto;
    background: var(--surface);
    position: relative;
}

/* Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    min-height: 60px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white);
    font-weight: 600;
    font-size: 18px;
}

.header-info h1 {
    font-size: 17px;
    font-weight: 500;
    color: var(--text-primary);
}

.header-info .status {
    font-size: 13px;
    color: var(--secondary);
}

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

.icon-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: var(--surface-light);
}

.icon-btn:active {
    background: var(--surface-lighter);
}

/* Messages Area */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--background);
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.02'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

/* Welcome Message */
.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    margin: 20px 0;
    background: var(--surface);
    border-radius: 16px;
}

.welcome-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    color: var(--white);
}

.welcome-message h2 {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.welcome-message p {
    font-size: 15px;
    color: var(--text-secondary);
}

/* Message Bubbles */
.message {
    display: flex;
    margin-bottom: 4px;
    animation: fadeIn 0.3s ease;
}

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

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

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

.message-bubble {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 8px;
    position: relative;
    word-wrap: break-word;
}

.message.sent .message-bubble {
    background: var(--sent-bubble);
    border-top-right-radius: 0;
}

.message.received .message-bubble {
    background: var(--received-bubble);
    border-top-left-radius: 0;
}

.message-text {
    font-size: 15px;
    line-height: 1.4;
    color: var(--text-primary);
}

.message-image {
    max-width: 100%;
    border-radius: 8px;
    margin-bottom: 4px;
    cursor: pointer;
    display: block;
}

.message-time {
    font-size: 11px;
    color: var(--text-muted);
    text-align: right;
    margin-top: 4px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
}

.message.sent .message-time {
    color: rgba(255, 255, 255, 0.6);
}

/* Date Separator */
.date-separator {
    display: flex;
    justify-content: center;
    margin: 16px 0;
}

.date-separator span {
    background: var(--surface-light);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

/* Input Area */
.input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.input-wrapper {
    flex: 1;
    background: var(--surface-light);
    border-radius: 24px;
    overflow: hidden;
}

.input-wrapper input {
    width: 100%;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 16px;
    outline: none;
}

.input-wrapper input::placeholder {
    color: var(--text-muted);
}

.attach-btn {
    color: var(--text-secondary);
}

.send-btn {
    width: 48px;
    height: 48px;
    border: none;
    background: var(--secondary);
    color: var(--white);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background 0.2s;
}

.send-btn:hover {
    background: #20c35c;
}

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

/* Image Preview Modal */
.image-preview-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.image-preview-modal.active {
    display: flex;
}

.modal-content {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.modal-content img {
    max-width: 100%;
    max-height: 60vh;
    border-radius: 8px;
    object-fit: contain;
}

.close-modal {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    border: none;
    background: var(--surface-light);
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-actions {
    width: 100%;
    display: flex;
    gap: 12px;
}

.modal-actions input {
    flex: 1;
    padding: 12px 16px;
    border: none;
    background: var(--surface-light);
    color: var(--text-primary);
    font-size: 16px;
    border-radius: 24px;
    outline: none;
}

.send-image-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    background: var(--secondary);
    color: var(--white);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 24px;
    transition: background 0.2s;
}

.send-image-btn:hover {
    background: #20c35c;
}

/* Loading Overlay */
.loading-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 16px;
}

.loading-overlay.active {
    display: flex;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--surface-light);
    border-top-color: var(--secondary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-overlay p {
    color: var(--text-primary);
    font-size: 15px;
}

/* ===== ADMIN STYLES ===== */

/* Admin Login */
.admin-login {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: var(--background);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    padding: 40px 32px;
    border-radius: 16px;
    text-align: center;
}

.login-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
    color: var(--white);
}

.login-card h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.login-card > p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border);
    background: var(--surface-light);
    color: var(--text-primary);
    font-size: 16px;
    border-radius: 12px;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: var(--primary);
}

.login-btn {
    width: 100%;
    padding: 14px;
    border: none;
    background: var(--primary);
    color: var(--white);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 12px;
    transition: background 0.2s;
}

.login-btn:hover {
    background: var(--primary-dark);
}

.error-msg {
    color: var(--danger);
    font-size: 14px;
    margin-top: 16px;
}

/* Admin Dashboard */
.admin-dashboard {
    display: flex;
    height: 100vh;
    height: 100dvh;
    background: var(--background);
}

/* Users Sidebar */
.users-sidebar {
    width: 360px;
    min-width: 360px;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar-header .icon-btn {
    display: none;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    margin: 8px 12px;
    background: var(--surface-light);
    border-radius: 8px;
}

.search-box svg {
    color: var(--text-muted);
    flex-shrink: 0;
}

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

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

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

.user-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid var(--border);
}

.user-item:hover {
    background: var(--surface-light);
}

.user-item.active {
    background: var(--surface-lighter);
}

.user-item .avatar {
    width: 50px;
    height: 50px;
    font-size: 20px;
    position: relative;
}

.user-item .unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 22px;
    height: 22px;
    background: var(--secondary);
    color: var(--white);
    font-size: 12px;
    font-weight: 600;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.user-info .user-name {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.user-info .last-message {
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-meta {
    text-align: right;
}

.user-meta .time {
    font-size: 12px;
    color: var(--text-muted);
}

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

.empty-state svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

.logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px;
    margin: 12px;
    border: none;
    background: transparent;
    color: var(--danger);
    font-size: 15px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
}

.logout-btn:hover {
    background: rgba(241, 92, 109, 0.1);
}

/* Admin Chat Area */
.admin-chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--background);
}

.no-chat-selected {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    text-align: center;
    padding: 40px;
}

.no-chat-selected svg {
    margin-bottom: 24px;
    opacity: 0.3;
}

.no-chat-selected h2 {
    font-size: 22px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.active-chat {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.admin-header {
    background: var(--surface);
}

.back-btn {
    display: none;
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
}

.admin-messages {
    flex: 1;
}

.delete-chat-btn {
    color: var(--danger);
}

/* Full Image Modal */
.full-image-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 3000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    cursor: zoom-out;
}

.full-image-modal.active {
    display: flex;
}

.full-image-modal img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Mobile Overlay */
.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

/* Responsive Styles */
@media (max-width: 768px) {
    .users-sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        width: 85%;
        max-width: 360px;
        z-index: 100;
        transition: left 0.3s ease;
    }

    .users-sidebar.active {
        left: 0;
    }

    .mobile-overlay.active {
        display: block;
    }

    .sidebar-header .icon-btn {
        display: flex;
    }

    .back-btn {
        display: flex;
    }

    .no-chat-selected {
        display: none;
        overflow: hidden;
        margin-top: -55%;
    }

    .active-chat {
        display: flex !important;
    }

    #activeChat {
        display: flex !important;
    }

    #noChatSelected {
        display: flex !important;
    }

    .admin-chat-area {
        position: relative;
    }

    .admin-chat-area::before {
        content: '';
        position: absolute;
        top: 16px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 5px;
        background: var(--surface-light);
        border-radius: 3px;
        z-index: 10;
        display: none;
    }
}

/* Scrollbar Styles */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--surface-lighter);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--surface-light);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 4000;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.toast.active {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.error {
    background: var(--danger);
    color: var(--white);
}

.toast.success {
    background: var(--secondary);
    color: var(--white);
}

/* Unread Message Styles */
.user-item.unread {
    background: rgba(37, 211, 102, 0.08);
}

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

.user-item.unread .last-message {
    color: var(--text-primary);
    font-weight: 500;
}

.new-msg-dot {
    width: 10px;
    height: 10px;
    background: var(--secondary);
    border-radius: 50%;
    margin-top: 4px;
}

/* Notification badge pulse */
.unread-badge {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(37, 211, 102, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(37, 211, 102, 0);
    }
}

/* User Item with Delete Button */
.user-item {
    display: flex;
    align-items: center;
    padding: 0;
    border-bottom: 1px solid var(--border);
}

.user-item-main {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 8px 12px 16px;
    flex: 1;
    cursor: pointer;
    transition: background 0.2s;
}

.user-item-main:hover {
    background: var(--surface-light);
}

.user-delete-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
    margin-right: 8px;
    border-radius: 50%;
}

.user-delete-btn:hover {
    color: var(--danger);
    background: rgba(241, 92, 109, 0.1);
}

/* Select Mode Bar */
.select-mode-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.cancel-select-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 15px;
    cursor: pointer;
}

.delete-selected-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border: none;
    background: var(--danger);
    color: var(--white);
    font-size: 15px;
    cursor: pointer;
    border-radius: 8px;
}

#selectedCount {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Selectable Messages */
.message.selectable {
    cursor: pointer;
}

.message.selectable.selected .message-bubble {
    outline: 2px solid var(--secondary);
    outline-offset: 2px;
}

.message-checkbox {
    display: none;
}

.message.selectable .message-checkbox {
    display: block;
    margin-right: 8px;
}

.message.selectable .message-checkbox input {
    width: 20px;
    height: 20px;
    accent-color: var(--secondary);
}

/* Quick Reply List Dropdown */
.quick-reply-list {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 8px;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    z-index: 100;
}

.quick-reply-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
}

.quick-reply-item:last-child {
    border-bottom: none;
}

.quick-reply-item:hover {
    background: var(--surface-light);
}

.quick-reply-text {
    font-size: 14px;
    color: var(--text-primary);
}

/* Quick Reply Button */
.quick-reply-btn {
    color: var(--secondary);
}

/* Quick Reply Manager Modal */
.quick-reply-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.quick-reply-modal.active {
    display: flex;
}

.qr-modal-content {
    width: 100%;
    max-width: 500px;
    background: var(--surface);
    border-radius: 16px;
    overflow: hidden;
}

.qr-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--primary);
    color: var(--white);
}

.qr-modal-header h3 {
    font-size: 18px;
    font-weight: 500;
}

.qr-modal-header .close-modal {
    background: transparent;
    border: none;
    color: var(--white);
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.qr-modal-header .close-modal:hover {
    background: rgba(255, 255, 255, 0.1);
}

.qr-modal-body {
    padding: 20px;
    max-height: 60vh;
    overflow-y: auto;
}

.qr-hint {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
    text-align: center;
}

.qr-add-form {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.qr-add-form input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border);
    background: var(--surface-light);
    color: var(--text-primary);
    font-size: 15px;
    border-radius: 8px;
    outline: none;
}

.qr-add-form input:focus {
    border-color: var(--primary);
}

.qr-add-form button {
    padding: 12px 20px;
    border: none;
    background: var(--secondary);
    color: var(--white);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
}

.qr-add-form button:hover {
    background: #20c35c;
}

.qr-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.quick-reply-manager-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--surface-light);
    border-radius: 8px;
}

.qr-text {
    font-size: 14px;
    color: var(--text-primary);
    flex: 1;
    margin-right: 12px;
}

.qr-delete-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: color 0.2s, background 0.2s;
}

.qr-delete-btn:hover {
    color: var(--danger);
    background: rgba(241, 92, 109, 0.1);
}
