/* assets/css/chat.css */
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;700&display=swap');

:root {
    /* Light Mode Variables */
    --chat-bg: #ffffff;
    --chat-header-bg: #0C2C45;
    --chat-header-text: #ffffff;
    --chat-user-msg-bg: #0C2C45;
    --chat-user-msg-text: #ffffff;
    --chat-bot-msg-bg: #f3f4f6;
    --chat-bot-msg-text: #1f2937;
    --chat-accent: #F6CE0F;
    --chat-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --chat-input-bg: #f1f2f6;
    --chat-border: #e2e8f0;
    --chat-body-pattern-color: #e2e8f0;
}

/* 🌙 Dark Mode Overrides */
html.dark {
    --chat-bg: #0f172a;
    /* Slate 900 */
    --chat-header-bg: #020617;
    /* Slate 950 */
    --chat-header-text: #f8fafc;
    --chat-user-msg-bg: #F6CE0F;
    /* Yellow for user in dark */
    --chat-user-msg-text: #0C2C45;
    /* Navy text */
    --chat-bot-msg-bg: #1e293b;
    /* Slate 800 */
    --chat-bot-msg-text: #e2e8f0;
    --chat-accent: #F6CE0F;
    --chat-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    --chat-input-bg: #1e293b;
    --chat-border: #334155;
    --chat-body-pattern-color: #334155;
}

.chat-widget {
    position: fixed;
    bottom: 30px;
    left: 30px;
    z-index: 999999;
    font-family: 'Vazirmatn', sans-serif;
    direction: rtl;
}

/* Toggle Button */
.chat-toggle-btn {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #0C2C45, #1a4a6e);
    /* Always navy for brand consistency */
    border-radius: 50%;
    color: #F6CE0F;
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    z-index: 20;
}

.chat-toggle-btn:hover {
    transform: scale(1.1) rotate(5deg);
}

.chat-toggle-btn::before {
    content: '';
    position: absolute;
    inset: -5px;
    border-radius: 50%;
    border: 2px solid #F6CE0F;
    opacity: 0;
    animation: chat-pulse 2s infinite;
}

@keyframes chat-pulse {
    0% {
        transform: scale(1);
        opacity: 0.6;
    }

    100% {
        transform: scale(1.4);
        opacity: 0;
    }
}

/* Chat Box */
.chat-box {
    position: absolute;
    bottom: 80px;
    left: 0;
    width: 380px;
    height: 550px;
    background: var(--chat-bg);
    border-radius: 20px;
    box-shadow: var(--chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom left;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid var(--chat-border);
}

.chat-box.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Header */
.chat-header {
    background: var(--chat-header-bg);
    color: var(--chat-header-text);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.chat-info h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
}

.chat-info p {
    margin: 2px 0 0;
    font-size: 11px;
    opacity: 0.8;
    font-weight: 300;
}

.chat-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.operator-avatar {
    width: 42px;
    height: 42px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--chat-accent);
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.status-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background: #10b981;
    border-radius: 50%;
    border: 2px solid var(--chat-header-bg);
}

#closeChat {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    font-size: 18px;
}

#closeChat:hover {
    color: white;
}

/* Body */
.chat-body {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: var(--chat-bg);
    background-image:
        radial-gradient(var(--chat-body-pattern-color) 1.5px, transparent 1.5px),
        radial-gradient(var(--chat-body-pattern-color) 1.5px, transparent 1.5px);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    transition: background 0.3s;
}

.chat-body::-webkit-scrollbar {
    width: 5px;
}

.chat-body::-webkit-scrollbar-track {
    background: transparent;
}

.chat-body::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 10px;
}

/* Messages */
.msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.6;
    position: relative;
    word-wrap: break-word;
    animation: chat-fadeUp 0.3s ease;
}

@keyframes chat-fadeUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

.msg.bot,
.msg.admin {
    background: var(--chat-bot-msg-bg);
    color: var(--chat-bot-msg-text);
    border-bottom-right-radius: 2px;
    align-self: flex-start;
}

.msg.user {
    background: var(--chat-user-msg-bg);
    color: var(--chat-user-msg-text);
    border-bottom-left-radius: 2px;
    align-self: flex-end;
}

.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 4px;
    font-size: 10px;
    opacity: 0.6;
}

.msg.user .msg-meta {
    color: inherit;
    opacity: 0.8;
}

/* Ticks */
.tick {
    width: 14px;
    height: 14px;
    display: inline-block;
    background-size: contain;
    background-repeat: no-repeat;
}

/* تیک تکی (رنگش داینامیک بر اساس تم) */
.msg.user .tick {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");
}

/* در حالت دارک مود که پس زمینه یوزر زرده، تیک باید تیره باشه */
html.dark .msg.user .tick {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230C2C45' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");
}

.tick.read {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234ade80' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 6L7 17l-5-5'%3E%3C/path%3E%3Cpath d='M22 6l-11 11'%3E%3C/path%3E%3C/svg%3E") !important;
}

/* Footer & Input */
.chat-footer {
    padding: 12px 16px;
    background: var(--chat-bg);
    border-top: 1px solid var(--chat-border);
    flex-shrink: 0;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.chat-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--chat-input-bg);
    border-radius: 24px;
    padding: 6px 12px;
    border: 1px solid transparent;
    transition: all 0.3s;
}

.chat-input-area:focus-within {
    background: var(--chat-bg);
    border-color: var(--chat-header-bg);
}

.chat-input-area input {
    flex-grow: 1;
    border: none;
    background: transparent;
    padding: 8px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    height: 36px;
    color: var(--chat-bot-msg-text);
}

.send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--chat-header-bg);
    color: var(--chat-accent);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    transition: transform 0.2s;
}

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

/* Auth Form */
.auth-form {
    background: var(--chat-bg);
    padding: 20px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    margin: auto 0;
    border: 1px solid var(--chat-border);
}

.auth-form p {
    color: var(--chat-bot-msg-text);
}

.auth-form input {
    width: 100%;
    padding: 12px;
    background: var(--chat-input-bg);
    border: 2px solid var(--chat-border);
    border-radius: 12px;
    margin: 10px 0;
    text-align: center;
    font-size: 16px;
    font-family: inherit;
    outline: none;
    color: var(--chat-bot-msg-text);
}

.auth-form input:focus {
    border-color: var(--chat-accent);
}

/* FAQ Buttons */
.menu-container {
    width: 100%;
    display: flex;
    flexDirection: column;
    gap: 8px;
}

.faq-btn {
    background: var(--chat-bg);
    border: 1px solid var(--chat-border);
    color: var(--chat-bot-msg-text);
    padding: 12px;
    border-radius: 12px;
    font-size: 13px;
    cursor: pointer;
    text-align: right;
    transition: all 0.2s;
}

.faq-btn:hover {
    background: var(--chat-input-bg);
    border-color: var(--chat-header-bg);
}

.faq-btn.special {
    background: var(--chat-header-bg);
    color: var(--chat-accent);
    border: none;
    font-weight: bold;
    text-align: center;
}

/* Mobile */
@media (max-width: 768px) {
    .chat-widget {
        bottom: 20px;
        left: 20px;
        z-index: 2147483647;
    }

    .chat-box {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100% !important;
        height: 100dvh !important;
        max-height: none;
        border-radius: 0;
        transform: translateY(100%);
        box-shadow: none;
        border: none;
        z-index: 2147483647;
    }

    .chat-box.open {
        transform: translateY(0);
    }

    .chat-header {
        padding-top: max(16px, env(safe-area-inset-top));
        border-radius: 0;
    }

    .chat-body {
        font-size: 14px;
    }

    .chat-footer {
        padding: 10px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .chat-box.open+.chat-toggle-btn {
        display: none;
    }
}
/* Typing Animation */
.msg.typing {
    padding: 15px 20px;
    display: flex;
    gap: 4px;
    align-items: center;
    width: fit-content;
}

.dot {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.dot:nth-child(1) {
    animation-delay: -0.32s;
}

.dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

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

    40% {
        transform: scale(1);
    }
}

/* استایل مخصوص هوش مصنوعی */
.msg.bot_ai {
    background: #e0f2fe;
    /* آبی خیلی کمرنگ */
    color: #0f172a;
    border-left: 3px solid #0ea5e9;
}

html.dark .msg.bot_ai {
    background: #1e293b;
    color: #e2e8f0;
    border-left: 3px solid #38bdf8;
}

/* نشانگر ربات */
.ai-badge {
    font-size: 9px;
    background: #0ea5e9;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    margin-bottom: 5px;
    display: inline-block;
    font-weight: bold;
}

/* دکمه لینک هوشمند */
.smart-link-btn {
    display: block;
    margin-top: 10px;
    background: #0C2C45;
    color: white !important;
    text-align: center;
    padding: 8px;
    border-radius: 8px;
    font-size: 12px;
    text-decoration: none;
    transition: background 0.2s;
}

.smart-link-btn:hover {
    background: #1a4a6e;
}

html.dark .smart-link-btn {
    background: #F6CE0F;
    color: #0C2C45 !important;
}