/**
 * ETM Mobile Bar - Chat Styles (Complete)
 * استایل کامل چت‌بات هوشمند — نسخه نهایی 2.1.0
 *
 * @package ETM_MobileBar
 * @version 2.1.0
 */

/* ═══════════════════════════════════════════════════
   🎯 Wrapper اصلی
   ═══════════════════════════════════════════════════ */

.etm-mbu-chat {
    position: fixed;
    inset: 0;
    z-index: 99997;
    font-family: 'Vazirmatn', Tahoma, sans-serif;
    direction: rtl;
    display: none;
    box-sizing: border-box;
}

.etm-mbu-chat *,
.etm-mbu-chat *::before,
.etm-mbu-chat *::after {
    box-sizing: border-box;
}

.etm-mbu-chat[hidden] {
    display: none !important;
}

.etm-mbu-chat.is-open {
    display: block;
}

/* ─── Overlay ─── */
.etm-mbu-chat-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0);
    backdrop-filter: blur(0);
    -webkit-backdrop-filter: blur(0);
    transition: background 0.35s ease, backdrop-filter 0.35s ease;
    cursor: pointer;
}

.etm-mbu-chat.is-open .etm-mbu-chat-overlay {
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

/* ═══════════════════════════════════════════════════
   📦 Panel
   ═══════════════════════════════════════════════════ */

.etm-mbu-chat-panel {
    position: absolute;
    bottom: 0;
    right: 0;
    left: 0;
    max-width: 480px;
    margin: 0 auto;
    height: 90vh;
    max-height: 700px;
    background: #f8fafc;
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -15px 50px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1;
}

.etm-mbu-chat.is-open .etm-mbu-chat-panel {
    transform: translateY(0);
}

/* ─── Desktop: Panel میانی ─── */
@media (min-width: 1025px) {
    .etm-mbu-chat-panel {
        top: auto;
        bottom: 24px;
        right: 24px;
        left: auto;
        max-width: 420px;
        height: 640px;
        border-radius: 20px;
        box-shadow: 0 25px 60px rgba(0, 0, 0, 0.3);
        transform: translateY(20px) scale(0.9);
        opacity: 0;
    }

    .etm-mbu-chat.is-open .etm-mbu-chat-panel {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

/* ═══════════════════════════════════════════════════
   📱 Header
   ═══════════════════════════════════════════════════ */

.etm-mbu-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--etm-primary, #7c3aed), var(--etm-secondary, #2563eb));
    color: #fff;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

.etm-mbu-chat-header::before {
    content: '';
    position: absolute;
    top: -50px;
    right: -50px;
    width: 200px;
    height: 200px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.15), transparent 70%);
    border-radius: 50%;
    pointer-events: none;
}

.etm-mbu-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
    position: relative;
    z-index: 1;
}

.etm-mbu-chat-avatar {
    position: relative;
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.etm-mbu-chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.etm-mbu-chat-avatar-emoji {
    font-size: 22px;
    line-height: 1;
}

.etm-mbu-chat-status-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: #22c55e;
    border: 2px solid var(--etm-primary, #7c3aed);
    border-radius: 50%;
    animation: etm-chat-status-pulse 2s ease-in-out infinite;
}

@keyframes etm-chat-status-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.15); opacity: 0.85; }
}

.etm-mbu-chat-header-text {
    flex: 1;
    min-width: 0;
}

.etm-mbu-chat-header-title {
    font-size: 14.5px;
    font-weight: 900;
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.etm-mbu-chat-header-subtitle {
    font-size: 11.5px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.etm-mbu-chat-online-dot {
    width: 6px;
    height: 6px;
    background: #22c55e;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 6px #22c55e;
}

.etm-mbu-chat-header-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.etm-mbu-chat-header-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    padding: 0;
    font-size: 15px;
    line-height: 1;
}

.etm-mbu-chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.08);
}

.etm-mbu-chat-header-btn:active {
    transform: scale(0.95);
}

.etm-mbu-chat-header-btn svg {
    width: 18px;
    height: 18px;
}

/* ═══════════════════════════════════════════════════
   📜 Body (Messages Area)
   ═══════════════════════════════════════════════════ */

.etm-mbu-chat-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 16px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
    position: relative;
}

.etm-mbu-chat-body::-webkit-scrollbar {
    width: 6px;
}

.etm-mbu-chat-body::-webkit-scrollbar-track {
    background: transparent;
}

.etm-mbu-chat-body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.etm-mbu-chat-body::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.etm-mbu-chat-messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
}

/* ═══════════════════════════════════════════════════
   💬 Messages
   ═══════════════════════════════════════════════════ */

.etm-mbu-chat-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 88%;
    opacity: 0;
    transform: translateY(15px) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.etm-mbu-chat-msg-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.etm-mbu-chat-msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.etm-mbu-chat-msg-bot {
    align-self: flex-start;
}

.etm-mbu-chat-msg-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: #fff;
    border-radius: 50%;
    flex-shrink: 0;
    font-size: 16px;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    border: 1.5px solid #e2e8f0;
}

.etm-mbu-chat-msg-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.etm-mbu-chat-msg-user .etm-mbu-chat-msg-content {
    align-items: flex-end;
}

.etm-mbu-chat-msg-bot .etm-mbu-chat-msg-content {
    align-items: flex-start;
}

.etm-mbu-chat-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.75;
    font-weight: 600;
    color: #1e293b;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
    position: relative;
}

.etm-mbu-chat-msg-user .etm-mbu-chat-msg-bubble {
    background: linear-gradient(135deg, var(--etm-primary, #7c3aed), var(--etm-secondary, #2563eb));
    color: #fff;
    border-bottom-left-radius: 4px;
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.25);
}

.etm-mbu-chat-msg-bot .etm-mbu-chat-msg-bubble {
    background: #fff;
    border: 1.5px solid #e2e8f0;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.etm-mbu-chat-msg-bubble a {
    color: inherit;
    font-weight: 800;
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-thickness: 1.5px;
}

.etm-mbu-chat-msg-bot .etm-mbu-chat-msg-bubble a {
    color: var(--etm-primary, #7c3aed);
}

.etm-mbu-chat-msg-bubble a:hover {
    opacity: 0.85;
}

.etm-mbu-chat-msg-bubble strong {
    font-weight: 900;
}

.etm-mbu-chat-msg-bubble br {
    line-height: 1.6;
}

.etm-mbu-chat-msg-time {
    font-size: 10.5px;
    color: #94a3b8;
    font-weight: 600;
    padding: 0 6px;
}

.etm-mbu-chat-msg-user .etm-mbu-chat-msg-time {
    text-align: left;
}

/* ─── Error Message ─── */
.etm-mbu-chat-msg-error .etm-mbu-chat-msg-bubble {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}

/* ─── Welcome Message ─── */
.etm-mbu-chat-msg-bot:first-child {
    margin-top: 8px;
}

/* ═══════════════════════════════════════════════════
   ⏳ Typing Indicator
   ═══════════════════════════════════════════════════ */

.etm-mbu-chat-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 16px;
    background: #fff;
    border: 1.5px solid #e2e8f0;
    border-radius: 16px 16px 16px 4px;
    width: fit-content;
    align-self: flex-start;
    margin-right: 40px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.etm-mbu-chat-typing[hidden] {
    display: none;
}

.etm-mbu-chat-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--etm-primary, #7c3aed);
    border-radius: 50%;
    animation: etm-chat-typing-anim 1.4s ease-in-out infinite;
    opacity: 0.6;
}

.etm-mbu-chat-typing-dot:nth-child(1) { animation-delay: 0s; }
.etm-mbu-chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.etm-mbu-chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes etm-chat-typing-anim {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.6;
    }
    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* ═══════════════════════════════════════════════════
   ⚡ Quick Actions
   ═══════════════════════════════════════════════════ */

.etm-mbu-chat-quick-actions {
    display: flex;
    gap: 6px;
    padding: 10px 16px;
    background: #fff;
    border-top: 1.5px solid #f1f5f9;
    overflow-x: auto;
    flex-shrink: 0;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.etm-mbu-chat-quick-actions::-webkit-scrollbar {
    display: none;
}

.etm-mbu-chat-quick-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: #f5f3ff;
    border: 1.5px solid #c4b5fd;
    border-radius: 20px;
    font-family: inherit;
    font-size: 12px;
    font-weight: 800;
    color: var(--etm-primary, #7c3aed);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 0.2s;
    line-height: 1;
}

.etm-mbu-chat-quick-btn:hover {
    background: var(--etm-primary, #7c3aed);
    color: #fff;
    border-color: var(--etm-primary, #7c3aed);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.25);
}

.etm-mbu-chat-quick-btn:active {
    transform: translateY(0);
}

.etm-mbu-chat-quick-icon {
    font-size: 14px;
    line-height: 1;
}

/* ═══════════════════════════════════════════════════
   📝 Input Area
   ═══════════════════════════════════════════════════ */

.etm-mbu-chat-input-wrap {
    padding: 12px 16px;
    background: #fff;
    border-top: 1.5px solid #f1f5f9;
    flex-shrink: 0;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
}

.etm-mbu-chat-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.etm-mbu-chat-input {
    flex: 1;
    padding: 11px 16px;
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 22px;
    font-family: inherit;
    font-size: 13.5px;
    line-height: 1.6;
    color: #1e293b;
    resize: none;
    outline: none;
    transition: all 0.2s;
    max-height: 120px;
    min-height: 44px;
    overflow-y: auto;
    box-sizing: border-box;
    scrollbar-width: thin;
}

.etm-mbu-chat-input::placeholder {
    color: #94a3b8;
    font-weight: 600;
}

.etm-mbu-chat-input:focus {
    border-color: var(--etm-primary, #7c3aed);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

.etm-mbu-chat-input::-webkit-scrollbar {
    width: 4px;
}

.etm-mbu-chat-input::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 2px;
}

.etm-mbu-chat-send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--etm-primary, #7c3aed), var(--etm-secondary, #2563eb));
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
    padding: 0;
}

.etm-mbu-chat-send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(124, 58, 237, 0.4);
}

.etm-mbu-chat-send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.etm-mbu-chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

.etm-mbu-chat-send-btn svg {
    width: 20px;
    height: 20px;
}

/* ═══════════════════════════════════════════════════
   🔻 Footer
   ═══════════════════════════════════════════════════ */

.etm-mbu-chat-footer {
    padding: 8px 16px 12px;
    background: #f8fafc;
    text-align: center;
    flex-shrink: 0;
    border-top: 1px solid #f1f5f9;
}

.etm-mbu-chat-powered {
    font-size: 10.5px;
    color: #94a3b8;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.etm-mbu-chat-powered strong {
    color: var(--etm-primary, #7c3aed);
    font-weight: 900;
}

/* ═══════════════════════════════════════════════════
   📱 Responsive
   ═══════════════════════════════════════════════════ */

@media (max-width: 480px) {
    .etm-mbu-chat-panel {
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    .etm-mbu-chat-msg {
        max-width: 92%;
    }

    .etm-mbu-chat-header {
        padding: 14px 16px;
    }

    .etm-mbu-chat-body {
        padding: 16px 12px;
    }

    .etm-mbu-chat-typing {
        margin-right: 34px;
    }
}

/* ═══════════════════════════════════════════════════
   🌙 Dark Mode
   ═══════════════════════════════════════════════════ */

@media (prefers-color-scheme: dark) {
    .etm-mbu-chat-panel {
        background: #1a1625;
    }

    .etm-mbu-chat-body {
        background: #1a1625;
    }

    .etm-mbu-chat-msg-bot .etm-mbu-chat-msg-bubble {
        background: #231d2f;
        border-color: #2d2640;
        color: #f1f5f9;
    }

    .etm-mbu-chat-msg-avatar {
        background: #231d2f;
        border-color: #2d2640;
        color: #f1f5f9;
    }

    .etm-mbu-chat-typing {
        background: #231d2f;
        border-color: #2d2640;
    }

    .etm-mbu-chat-input {
        background: #231d2f;
        border-color: #2d2640;
        color: #f1f5f9;
    }

    .etm-mbu-chat-input:focus {
        background: #1a1625;
    }

    .etm-mbu-chat-quick-actions,
    .etm-mbu-chat-input-wrap {
        background: #231d2f;
        border-color: #2d2640;
    }

    .etm-mbu-chat-quick-btn {
        background: #2d2640;
        border-color: #3f3568;
        color: #c4b5fd;
    }

    .etm-mbu-chat-footer {
        background: #231d2f;
        border-color: #2d2640;
    }
}

/* ═══════════════════════════════════════════════════
   🖨️ Print
   ═══════════════════════════════════════════════════ */

@media print {
    .etm-mbu-chat {
        display: none !important;
    }
}

/* ═══════════════════════════════════════════════════
   ♿ Accessibility
   ═══════════════════════════════════════════════════ */

.etm-mbu-chat-header-btn:focus-visible,
.etm-mbu-chat-send-btn:focus-visible,
.etm-mbu-chat-quick-btn:focus-visible {
    outline: 2px solid var(--etm-primary, #7c3aed);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .etm-mbu-chat-panel,
    .etm-mbu-chat-msg,
    .etm-mbu-chat-typing-dot,
    .etm-mbu-chat-status-indicator {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ═══════════════════════════════════════════════════
   📌 Body Lock
   ═══════════════════════════════════════════════════ */

body.etm-mbu-chat-open {
    overflow: hidden;
    touch-action: none;
}

/* ═══════════════════════════════════════════════════
   🎯 Loading State
   ═══════════════════════════════════════════════════ */

.etm-mbu-chat.is-loading .etm-mbu-chat-send-btn {
    pointer-events: none;
    opacity: 0.6;
}

.etm-mbu-chat.is-loading .etm-mbu-chat-send-btn::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: etm-chat-spinner 0.7s linear infinite;
}

@keyframes etm-chat-spinner {
    to { transform: rotate(360deg); }
}

/* ═══════════════════════════════════════════════════
   💬 Message Bubble Enhancements
   ═══════════════════════════════════════════════════ */

/* ─── Mark (highlight) ─── */
.etm-mbu-chat-msg-bubble mark {
    background: #fde68a;
    color: #92400e;
    padding: 1px 4px;
    border-radius: 4px;
    font-weight: 900;
}

/* ─── Code ─── */
.etm-mbu-chat-msg-bubble code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    direction: ltr;
    display: inline-block;
    color: #7c3aed;
}

.etm-mbu-chat-msg-user .etm-mbu-chat-msg-bubble code {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

/* ─── Lists ─── */
.etm-mbu-chat-msg-bubble ul,
.etm-mbu-chat-msg-bubble ol {
    margin: 6px 0;
    padding-right: 20px;
}

.etm-mbu-chat-msg-bubble li {
    margin-bottom: 4px;
}

/* ─── Emojis ─── */
.etm-mbu-chat-msg-bubble .emoji {
    font-size: 16px;
    line-height: 1;
    vertical-align: middle;
}