/**
 * Live Chat Widget - User Side CSS
 */

:root {
    --chat-primary: #6366f1;
    --chat-primary-dark: #4f46e5;
    --chat-success: #10b981;
    --chat-warning: #f59e0b;
    --chat-danger: #ef4444;
    --chat-bg: #ffffff;
    --chat-text: #1f2937;
    --chat-text-muted: #6b7280;
    --chat-border: #e5e7eb;
    --chat-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

[data-theme="dark"] {
    --chat-bg: #1f2937;
    --chat-text: #f9fafb;
    --chat-text-muted: #9ca3af;
    --chat-border: #374151;
    --chat-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.live-chat-widget {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 10000;
    font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, sans-serif;
    direction: rtl;
}

/* Toggle Button */
.chat-widget-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: var(--chat-primary);
    color: white;
    cursor: pointer;
    box-shadow: var(--chat-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.chat-widget-toggle:hover {
    transform: scale(1.05);
    background: var(--chat-primary-dark);
}

.chat-widget-toggle.online .status-indicator {
    background: var(--chat-success);
}

.chat-widget-toggle.offline .status-indicator {
    background: var(--chat-text-muted);
}

.status-indicator {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 3px solid white;
}

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

.chat-widget-toggle.is-open .close-icon {
    display: block !important;
}

/* Chat Panel */
.chat-widget-panel {
    position: absolute;
    bottom: 75px;
    left: 0;
    width: 360px;
    max-width: calc(100vw - 40px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: var(--chat-bg);
    border-radius: 16px;
    box-shadow: var(--chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease-out;
}

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

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Header */
.chat-widget-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: var(--chat-primary);
    color: white;
}

.header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.status-dot.online {
    background: var(--chat-success);
    animation: pulse 2s infinite;
}

.status-dot.offline {
    background: #9ca3af;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.header-title {
    font-weight: 600;
    font-size: 1rem;
}

.chat-close-btn {
    padding: 6px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: white;
    cursor: pointer;
    transition: background 0.2s;
}

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

/* Pre-chat Form */
.chat-prechat {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.prechat-content {
    text-align: center;
}

.prechat-icon {
    margin-bottom: 16px;
}

.prechat-title {
    margin: 0 0 8px;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--chat-text);
}

.prechat-desc {
    margin: 0 0 24px;
    color: var(--chat-text-muted);
    font-size: 0.9rem;
}

.prechat-form {
    text-align: right;
}

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

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--chat-text);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--chat-border);
    border-radius: 10px;
    font-size: 0.9rem;
    background: var(--chat-bg);
    color: var(--chat-text);
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--chat-primary);
}

.btn-start-chat {
    width: 100%;
    padding: 14px 20px;
    border: none;
    border-radius: 10px;
    background: var(--chat-primary);
    color: white;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-start-chat:hover {
    background: var(--chat-primary-dark);
    transform: translateY(-1px);
}

.btn-start-chat:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Queue View */
.chat-queue {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.queue-content {
    text-align: center;
}

.queue-animation {
    margin-bottom: 20px;
}

.queue-circle {
    width: 60px;
    height: 60px;
    border: 4px solid var(--chat-border);
    border-top-color: var(--chat-primary);
    border-radius: 50%;
    margin: 0 auto;
    animation: spin 1s linear infinite;
}

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

.queue-title {
    margin: 0 0 16px;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--chat-text);
}

.queue-position,
.queue-wait {
    margin: 0 0 8px;
    color: var(--chat-text-muted);
    font-size: 0.9rem;
}

.queue-position strong,
.queue-wait strong {
    color: var(--chat-primary);
}

.queue-actions {
    margin-top: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-secondary {
    padding: 12px 16px;
    border: 1px solid var(--chat-border);
    border-radius: 10px;
    background: transparent;
    color: var(--chat-text);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: var(--chat-border);
}

.btn-text {
    padding: 8px;
    border: none;
    background: transparent;
    color: var(--chat-text-muted);
    font-size: 0.85rem;
    cursor: pointer;
}

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

/* Offline View */
.chat-offline {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.offline-content {
    text-align: center;
}

.offline-icon {
    margin-bottom: 16px;
}

.offline-title {
    margin: 0 0 8px;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--chat-text);
}

.offline-desc {
    margin: 0 0 24px;
    color: var(--chat-text-muted);
    font-size: 0.9rem;
}

.btn-create-ticket {
    padding: 14px 24px;
    border: none;
    border-radius: 10px;
    background: var(--chat-primary);
    color: white;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    transition: all 0.2s;
}

.btn-create-ticket:hover {
    background: var(--chat-primary-dark);
    transform: translateY(-1px);
}

/* Chat Active */
.chat-active {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-active-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: #f1f5f9;
    border-bottom: 1px solid var(--chat-border);
    font-size: 0.85rem;
    color: var(--chat-text-muted);
}

[data-theme="dark"] .chat-active-header {
    background: #374151;
}

.btn-end-chat {
    width: 28px;
    height: 28px;
    border: none;
    background: #fee2e2;
    color: #dc2626;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-end-chat:hover {
    background: #fecaca;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    animation: fadeIn 0.2s ease-out;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.user {
    align-self: flex-start;
    /* Right in RTL */
    background: var(--chat-primary);
    color: white;
    border-bottom-left-radius: 4px;
}

.chat-message.admin {
    align-self: flex-end;
    /* Left in RTL */
    background: #f3f4f6;
    color: var(--chat-text);
    border-bottom-right-radius: 4px;
}

[data-theme="dark"] .chat-message.admin {
    background: #374151;
}

.chat-message.system {
    align-self: center;
    background: transparent;
    color: var(--chat-text-muted);
    font-size: 0.8rem;
    font-style: italic;
    padding: 8px;
}

.message-time {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-top: 4px;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    color: var(--chat-text-muted);
    font-size: 0.8rem;
}

.typing-indicator .dot {
    width: 6px;
    height: 6px;
    background: var(--chat-text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-indicator .dot:nth-child(1) {
    animation-delay: 0s;
}

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

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

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-6px);
    }
}

/* Send Form */
.chat-send-form {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--chat-border);
    background: var(--chat-bg);
}

.chat-send-form input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--chat-border);
    border-radius: 24px;
    font-size: 0.9rem;
    background: var(--chat-bg);
    color: var(--chat-text);
}

.chat-send-form input:focus {
    outline: none;
    border-color: var(--chat-primary);
}

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

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

/* Chat Ended */
.chat-ended {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.ended-content {
    text-align: center;
}

.ended-content h3 {
    margin: 16px 0 8px;
    font-size: 1.1rem;
    color: var(--chat-text);
}

.ended-content p {
    margin: 0 0 16px;
    color: var(--chat-text-muted);
}

/* Rating Form */
.rating-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 16px;
}

.star-rating {
    display: flex;
    justify-content: center;
    gap: 8px;
}

.star-rating .star {
    font-size: 2rem;
    background: none;
    border: none;
    color: #d1d5db;
    cursor: pointer;
    transition: all 0.15s;
    padding: 0;
}

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

.rating-form textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--chat-border);
    border-radius: 10px;
    font-size: 0.9rem;
    resize: none;
    background: var(--chat-bg);
    color: var(--chat-text);
}

.rating-form textarea:focus {
    outline: none;
    border-color: var(--chat-primary);
}

.btn-submit-rating {
    padding: 12px 20px;
    border: none;
    border-radius: 10px;
    background: var(--chat-success);
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-submit-rating:hover {
    background: #059669;
}

.btn-submit-rating:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .live-chat-widget {
        bottom: 10px;
        left: 10px;
        right: 10px;
    }

    .chat-widget-toggle {
        width: 56px;
        height: 56px;
    }

    .chat-widget-panel {
        width: 100%;
        max-width: none;
        left: 0;
        right: 0;
        bottom: 70px;
        height: calc(100vh - 90px);
        max-height: none;
        border-radius: 16px 16px 0 0;
    }
}