/*
 * آریاز چت‌ویجت — ariaz-chat.css
 * Floating bubble + Drawer — گوشه پایین-چپ
 * سازگار با light/dark mode از طریق CSS variables
 */

/* ══ Root & Reset ═══════════════════════════════════════════════════════════ */
#az-chat-root *,
#az-chat-root *::before,
#az-chat-root *::after {
    box-sizing: border-box;
    font-family: var(--az-font, 'Vazirmatn', Tahoma, sans-serif);
}

/* ══ Bubble ══════════════════════════════════════════════════════════════════ */
.az-chat-bubble {
    position: fixed;
    bottom: 80px;
    left: 24px;
    z-index: 9990;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: var(--az-brand);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(11,79,108,0.40);
    transition: transform 0.25s cubic-bezier(.34,1.56,.64,1), box-shadow 0.25s;
    outline: none;
}

.az-chat-bubble:hover {
    transform: scale(1.10);
    box-shadow: 0 8px 28px rgba(11,79,108,0.50);
}

.az-chat-bubble:focus-visible {
    outline: 3px solid var(--az-accent);
    outline-offset: 3px;
}

.az-bubble--active {
    background: var(--az-accent);
}

.az-bubble-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s;
}

/* Badge */
.az-bubble-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    background: var(--az-accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

/* ══ Drawer ══════════════════════════════════════════════════════════════════ */
.az-chat-drawer {
    position: fixed;
    bottom: 142px;
    left: 24px;
    z-index: 9989;
    width: 340px;
    max-height: 520px;
    border-radius: 18px;
    background: var(--az-bg-panel);
    border: 1.5px solid var(--az-border);
    box-shadow: 0 16px 48px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.97);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(.34,1.3,.64,1);
    transform-origin: bottom left;
}

.az-chat-drawer--open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ── Header ── */
.az-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: var(--az-brand);
    color: #fff;
    flex-shrink: 0;
    gap: 8px;
}

.az-chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.az-chat-avatar-sm {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    opacity: 0.9;
}

.az-chat-title {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.az-chat-subtitle {
    display: block;
    font-size: 11px;
    color: rgba(255,255,255,0.75);
}

.az-chat-header-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.az-chat-icon-btn {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: none;
    background: rgba(255,255,255,0.12);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.18s;
    padding: 0;
}

.az-chat-icon-btn:hover {
    background: rgba(255,255,255,0.25);
}

/* ── Messages ── */
.az-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 12px 4px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.az-chat-messages::-webkit-scrollbar { width: 4px; }
.az-chat-messages::-webkit-scrollbar-track { background: transparent; }
.az-chat-messages::-webkit-scrollbar-thumb { background: var(--az-border); border-radius: 2px; }

/* ── Message bubbles ── */
.az-msg {
    display: flex;
    max-width: 88%;
    animation: az-msg-in 0.22s ease;
}

@keyframes az-msg-in {
    from { opacity:0; transform: translateY(6px); }
    to   { opacity:1; transform: translateY(0); }
}

.az-msg--user {
    align-self: flex-start;
    flex-direction: row-reverse;
}

.az-msg--bot {
    align-self: flex-end;
}

.az-msg-bubble {
    padding: 8px 12px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.65;
    word-break: break-word;
}

.az-msg--user .az-msg-bubble {
    background: var(--az-brand);
    color: #fff;
    border-bottom-left-radius: 4px;
}

.az-msg--bot .az-msg-bubble {
    background: var(--az-bg-deep);
    color: var(--az-text);
    border-bottom-right-radius: 4px;
    border: 1px solid var(--az-border);
}

.az-msg--error .az-msg-bubble {
    background: #fff0f0;
    color: #721c24;
    border-color: #f5c6cb;
}

.az-msg-bubble--sources {
    font-size: 11px;
    padding: 6px 10px;
    background: var(--az-accent-dim) !important;
    border: none !important;
    color: var(--az-text-muted) !important;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}

.az-sources-label { font-weight: 600; }

.az-source-chip {
    background: var(--az-bg-panel);
    border: 1px solid var(--az-border);
    padding: 1px 7px;
    border-radius: 8px;
    font-size: 10px;
    color: var(--az-text-sec);
}

/* ── Typing indicator ── */
.az-chat-typing {
    padding: 6px 14px;
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
}

.az-chat-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--az-brand);
    opacity: 0.4;
    animation: az-typing 1.2s infinite;
}

.az-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.az-chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes az-typing {
    0%, 60%, 100% { opacity:0.3; transform: scale(1); }
    30%            { opacity:1;   transform: scale(1.25); }
}

/* ── Suggestions ── */
.az-chat-suggestions {
    display: flex;
    gap: 6px;
    padding: 6px 12px 0;
    overflow-x: auto;
    flex-shrink: 0;
    scrollbar-width: none;
}

.az-chat-suggestions::-webkit-scrollbar { display: none; }

.az-suggestion {
    white-space: nowrap;
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 12px;
    border: 1.5px solid var(--az-brand);
    background: transparent;
    color: var(--az-brand);
    cursor: pointer;
    transition: background 0.18s, color 0.18s;
    font-family: var(--az-font, 'Vazirmatn', Tahoma, sans-serif);
    flex-shrink: 0;
}

.az-suggestion:hover {
    background: var(--az-brand);
    color: #fff;
}

/* ── Input row ── */
.az-chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 10px 12px;
    border-top: 1px solid var(--az-border);
    background: var(--az-bg-panel);
    flex-shrink: 0;
}

.az-chat-input {
    flex: 1;
    resize: none;
    border: 1.5px solid var(--az-border);
    border-radius: 12px;
    padding: 8px 12px;
    font-size: 13px;
    line-height: 1.5;
    min-height: 40px;
    max-height: 120px;
    outline: none;
    background: var(--az-bg-deep);
    color: var(--az-text);
    font-family: var(--az-font, 'Vazirmatn', Tahoma, sans-serif);
    direction: rtl;
    overflow-y: auto;
    transition: border-color 0.2s;
}

.az-chat-input:focus {
    border-color: var(--az-brand);
}

.az-chat-input::placeholder {
    color: var(--az-text-muted);
    font-size: 12px;
}

.az-chat-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.az-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: none;
    background: var(--az-brand);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.18s, transform 0.15s;
}

.az-chat-send:hover:not(:disabled) {
    background: var(--az-accent);
    transform: scale(1.06);
}

.az-chat-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

/* ── Dark mode ── */
[data-theme="dark"] .az-chat-drawer {
    box-shadow: 0 16px 48px rgba(0,0,0,0.45), 0 2px 8px rgba(0,0,0,0.3);
}

[data-theme="dark"] .az-msg--bot .az-msg-bubble {
    background: #1e2633;
}

[data-theme="dark"] .az-msg--error .az-msg-bubble {
    background: #3b1519;
    color: #f8d7da;
    border-color: #721c24;
}

/* ── Mobile ── */
@media (max-width: 480px) {
    .az-chat-drawer {
        left: 8px;
        right: 8px;
        width: auto;
        bottom: 128px;
        max-height: 65vh;
    }

    .az-chat-bubble {
        left: 16px;
        bottom: 76px;
    }
}
