/* ==========================================
   LIVE CHAT WIDGET
   ========================================== */

/* ─── Chat Bubble ─── */
.chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    transition: transform 0.2s ease, background 0.2s ease;
}
.chat-bubble:hover {
    transform: scale(1.08);
    background: var(--accent-hover);
}
.chat-bubble svg {
    width: 26px;
    height: 26px;
    fill: #fff;
}
.chat-bubble .chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: var(--error);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    line-height: 1;
}
.chat-bubble.has-unread {
    animation: chat-pulse 2s ease-in-out infinite;
}
@keyframes chat-pulse {
    0%, 100% { box-shadow: var(--shadow-md); }
    50% { box-shadow: 0 4px 20px rgba(90, 158, 62, 0.5); }
}

/* ─── Chat Window ─── */
.chat-window {
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: 360px;
    height: 480px;
    background: var(--bg-card);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    z-index: 9000;
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border-color);
}
.chat-window.open {
    display: flex;
}

/* ─── Header ─── */
.chat-header {
    background: var(--accent);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.chat-header-title {
    font-size: 0.95rem;
    font-weight: 600;
}
.chat-header-actions {
    display: flex;
    gap: 8px;
}
.chat-header-actions button {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    opacity: 0.8;
    font-size: 1.1rem;
    padding: 2px;
    line-height: 1;
    transition: opacity 0.2s;
}
.chat-header-actions button:hover {
    opacity: 1;
}

/* ─── Body (wraps messages + input) ─── */
.chat-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* ─── Messages Area ─── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg-primary);
}
.chat-messages::-webkit-scrollbar {
    width: 5px;
}
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

/* ─── Message Bubbles ─── */
.chat-msg {
    max-width: 80%;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 8px;
}
.chat-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.chat-msg.admin {
    align-self: flex-start;
}
.chat-msg-content {
    display: flex;
    flex-direction: column;
}
.chat-avatar {
    width: 37px;
    height: 37px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    margin-top: 2px;
}
.chat-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.88rem;
    line-height: 1.45;
    word-wrap: break-word;
}
.chat-msg.user .chat-msg-bubble {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-msg.admin .chat-msg-bubble {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}
.chat-msg-sender {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 0 4px;
    margin-bottom: 2px;
}
.chat-msg.user .chat-msg-sender {
    text-align: right;
}
.chat-msg-meta {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 3px;
    padding: 0 4px;
}
.chat-msg.user .chat-msg-meta {
    text-align: right;
}

/* ─── Start Form ─── */
.chat-start-form {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    gap: 12px;
}
.chat-start-form p {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.5;
}
.chat-start-form input,
.chat-start-form textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: var(--font-primary);
    font-size: 0.88rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    resize: none;
    transition: border-color 0.2s;
}
.chat-start-form input:focus,
.chat-start-form textarea:focus {
    outline: none;
    border-color: var(--accent);
}
.chat-start-form textarea {
    flex: 1;
    min-height: 80px;
}
.chat-start-form button {
    padding: 10px 20px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-family: var(--font-primary);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.chat-start-form button:hover {
    background: var(--accent-hover);
}

/* ─── Input Bar ─── */
.chat-input-bar {
    display: flex;
    align-items: flex-end;
    padding: 10px 12px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-card);
    gap: 8px;
    flex-shrink: 0;
}
.chat-input-bar textarea {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-family: var(--font-primary);
    font-size: 0.85rem;
    resize: none;
    max-height: 100px;
    line-height: 1.4;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color 0.2s;
}
.chat-input-bar textarea:focus {
    outline: none;
    border-color: var(--accent);
}
.chat-input-bar button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}
.chat-input-bar button:hover {
    background: var(--accent-hover);
}
.chat-input-bar button svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* ─── Status Notices ─── */
.chat-notice {
    text-align: center;
    padding: 10px 16px;
    font-size: 0.82rem;
    color: var(--text-muted);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

/* ─── Loading ─── */
.chat-loading {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.88rem;
}

/* ─── System Messages ─── */
.chat-system-msg {
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-muted);
    padding: 6px 12px;
    font-style: italic;
}

/* ─── Mobile ─── */
@media (max-width: 480px) {
    .chat-window {
        right: 12px;
        left: 12px;
        bottom: 88px;
        width: auto;
        height: calc(100vh - 120px);
        max-height: 520px;
    }
    .chat-bubble {
        bottom: 16px;
        right: 16px;
    }
}

/* ==========================================
   ADMIN LIVE CHAT
   ========================================== */

/* ─── Session List ─── */
.chat-filter-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
}
.chat-filter-tab {
    padding: 8px 20px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    font-family: var(--font-primary);
    font-size: 0.85rem;
    font-weight: 500;
    transition: var(--transition);
}
.chat-filter-tab:hover {
    background: var(--bg-secondary);
}
.chat-filter-tab.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.chat-session-row {
    cursor: pointer;
    transition: background 0.15s;
}
.chat-session-row:hover {
    background: var(--accent-light) !important;
}
.chat-session-row.unread td {
    font-weight: 600;
}
.chat-session-row .unread-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    margin-right: 6px;
    vertical-align: middle;
}
.chat-session-preview {
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.chat-status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.chat-status-badge.active {
    background: var(--accent-light);
    color: var(--accent);
}
.chat-status-badge.closed {
    background: var(--bg-secondary);
    color: var(--text-muted);
}

/* ─── Conversation View ─── */
.admin-chat-thread {
    max-width: 800px;
    margin: 0 auto;
    background: var(--bg-primary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    min-height: 400px;
    max-height: 600px;
    overflow: hidden;
}
.admin-chat-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 12px 12px 0 0;
}
.admin-chat-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}
.admin-chat-header .chat-user-info {
    font-size: 0.82rem;
    color: var(--text-muted);
}
.admin-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.admin-chat-messages::-webkit-scrollbar {
    width: 5px;
}
.admin-chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

/* Reuse bubble styles */
.admin-chat-messages .chat-msg {
    max-width: 70%;
}

.admin-chat-input {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-card);
    display: flex;
    gap: 10px;
    align-items: flex-end;
    border-radius: 0 0 12px 12px;
}
.admin-chat-input textarea {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: var(--font-primary);
    font-size: 0.88rem;
    resize: none;
    max-height: 100px;
    line-height: 1.4;
    background: var(--bg-primary);
    color: var(--text-primary);
}
.admin-chat-input textarea:focus {
    outline: none;
    border-color: var(--accent);
}
.admin-chat-input button {
    padding: 10px 20px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-family: var(--font-primary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}
.admin-chat-input button:hover {
    background: var(--accent-hover);
}
.admin-chat-closed-bar {
    padding: 12px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 0 0 12px 12px;
}

/* ─── Auto-refresh indicator ─── */
.chat-refresh-indicator {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-align: right;
    margin-bottom: 10px;
}
