/**
 * Live Chat Widget Styles
 * Human-operated customer support chat
 * Compatible with light and dark themes
 */

/* ============================================================
   Variables - Integrated with Design System
   ============================================================ */
:root {
    --livechat-primary: var(--color-primary-500);
    --livechat-primary-hover: var(--color-primary-600);
    --livechat-bg: var(--bg-primary);
    --livechat-bg-secondary: var(--bg-secondary);
    --livechat-text: var(--text-primary);
    --livechat-text-muted: var(--text-muted);
    --livechat-border: var(--border-default);
    --livechat-shadow: var(--shadow-lg);
    --livechat-visitor-bg: var(--color-primary-500);
    --livechat-visitor-text: var(--color-neutral-0);
    --livechat-operator-bg: var(--bg-tertiary);
    --livechat-operator-text: var(--text-primary);
    --livechat-system-text: var(--text-muted);
    --livechat-radius: var(--radius-xl);
    --livechat-header-bg: var(--color-primary-500);
    --livechat-header-text: var(--color-neutral-0);
    --livechat-online-color: #22c55e;
    --livechat-offline-color: #94a3b8;
}

[data-theme="dark"] {
    --livechat-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --livechat-header-bg: var(--color-primary-600);
}

/* ============================================================
   Floating Widget - Positioning
   ============================================================ */
.livechat-floating {
    position: fixed;
    z-index: 9999;
}

.livechat-floating.livechat-position-bottom-right {
    bottom: 20px;
    right: 20px;
}

.livechat-floating.livechat-position-bottom-left {
    bottom: 20px;
    left: 20px;
}

/* ============================================================
   Toggle Button
   ============================================================ */
.livechat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--livechat-primary);
    color: var(--livechat-header-text);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    position: relative;
    font-size: 1.25rem;
}

.livechat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
    background: var(--livechat-primary-hover);
}

.livechat-toggle .livechat-icon-close {
    display: none;
    font-size: 1.2rem;
}

.livechat-widget.livechat-open .livechat-toggle .livechat-icon-open {
    display: none;
}

.livechat-widget.livechat-open .livechat-toggle .livechat-icon-close {
    display: block;
}

/* Status dot */
.livechat-status-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--livechat-offline-color);
    border: 2px solid var(--livechat-primary);
    transition: background-color 0.3s ease;
}

.livechat-widget[data-online="1"] .livechat-status-dot {
    background: var(--livechat-online-color);
}

/* ============================================================
   Chat Container
   ============================================================ */
.livechat-container {
    display: none;
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 370px;
    max-height: 520px;
    background: var(--livechat-bg);
    border-radius: var(--livechat-radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    flex-direction: column;
    border: 1px solid var(--livechat-border);
}

.livechat-widget.livechat-open .livechat-container {
    display: flex;
}

.livechat-position-bottom-left .livechat-container {
    right: auto;
    left: 0;
}

/* ============================================================
   Header
   ============================================================ */
.livechat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--livechat-header-bg);
    color: var(--livechat-header-text);
    flex-shrink: 0;
}

.livechat-header-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.livechat-title {
    font-weight: 600;
    font-size: 0.95rem;
}

.livechat-header-status {
    font-size: 0.75rem;
    opacity: 0.85;
}

.livechat-close {
    opacity: 0.8;
    filter: none;
}

.livechat-close:hover {
    opacity: 1;
}

/* ============================================================
   Body / Panels
   ============================================================ */
.livechat-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 350px;
}

.livechat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px;
    overflow-y: auto;
}

.livechat-chat-panel {
    padding: 0;
}

/* ============================================================
   Pre-chat Form
   ============================================================ */
.livechat-welcome-msg {
    text-align: center;
    color: var(--livechat-text);
    margin-bottom: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
}

.livechat-form .form-control {
    font-size: 0.875rem;
}

/* ============================================================
   Waiting State
   ============================================================ */
.livechat-waiting-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 12px;
    color: var(--livechat-text-muted);
}

.livechat-waiting-spinner {
    font-size: 1.5rem;
}

.livechat-waiting-text {
    font-size: 0.9rem;
}

/* ============================================================
   Active Chat - Messages
   ============================================================ */
.livechat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.livechat-msg {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.875rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.livechat-msg-visitor {
    align-self: flex-end;
    background: var(--livechat-visitor-bg);
    color: var(--livechat-visitor-text);
    border-bottom-right-radius: 4px;
}

.livechat-msg-operator {
    align-self: flex-start;
    background: var(--livechat-operator-bg);
    color: var(--livechat-operator-text);
    border-bottom-left-radius: 4px;
}

.livechat-msg-system {
    align-self: center;
    text-align: center;
    color: var(--livechat-system-text);
    font-size: 0.8rem;
    font-style: italic;
    padding: 4px 8px;
    background: none;
    max-width: 90%;
}

.livechat-msg-sender {
    font-size: 0.7rem;
    font-weight: 600;
    margin-bottom: 2px;
    opacity: 0.7;
}

.livechat-msg-time {
    font-size: 0.65rem;
    opacity: 0.6;
    margin-top: 4px;
    text-align: right;
}

/* ============================================================
   Input Area
   ============================================================ */
.livechat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--livechat-border);
    background: var(--livechat-bg);
    flex-shrink: 0;
}

.livechat-input {
    flex: 1;
    resize: none;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 0.875rem;
    max-height: 80px;
    line-height: 1.4;
}

.livechat-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
    font-size: 0.85rem;
}

/* ============================================================
   Rating Panel
   ============================================================ */
.livechat-rating-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 8px;
    text-align: center;
}

.livechat-rating-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--livechat-text);
}

.livechat-rating-subtitle {
    font-size: 0.9rem;
    color: var(--livechat-text-muted);
    margin-bottom: 8px;
}

.livechat-stars {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.livechat-star {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.5rem;
    color: #d1d5db;
    transition: color 0.2s ease, transform 0.2s ease;
    padding: 0;
}

.livechat-star:hover,
.livechat-star.active {
    color: #f59e0b;
    transform: scale(1.15);
}

.livechat-rating-content .form-control {
    font-size: 0.875rem;
    width: 100%;
}

/* ============================================================
   Offline Form
   ============================================================ */
.livechat-offline-msg {
    text-align: center;
    color: var(--livechat-text-muted);
    margin-bottom: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
}

/* ============================================================
   Success State
   ============================================================ */
.livechat-success-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 8px;
    text-align: center;
}

.livechat-success-icon {
    font-size: 3rem;
    color: var(--livechat-online-color);
}

.livechat-success-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--livechat-text);
}

.livechat-success-subtitle {
    font-size: 0.9rem;
    color: var(--livechat-text-muted);
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 480px) {
    .livechat-container {
        width: calc(100vw - 24px);
        max-height: calc(100vh - 100px);
        bottom: 70px;
        right: -8px;
    }

    .livechat-position-bottom-left .livechat-container {
        left: -8px;
    }
}

/* ============================================================
   Animations
   ============================================================ */
.livechat-widget.livechat-open .livechat-container {
    animation: livechatSlideUp 0.3s ease;
}

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

.livechat-msg {
    animation: livechatFadeIn 0.2s ease;
}

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