/* =========================================
   ABR Chat Widget – Frontend Styles v1.1
   abrbaranidc.ir  |  RTL Persian
   ========================================= */

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

:root {
    --abr-primary:    #0055a5;
    --abr-accent:     #00b4d8;
    --abr-primary-dk: #003d7a;
    --abr-bg:         #f0f4f8;
    --abr-white:      #ffffff;
    --abr-text:       #1e293b;
    --abr-border:     #e2e8f0;
    --abr-shadow:     0 20px 60px rgba(0,0,0,.18), 0 4px 16px rgba(0,0,0,.08);
    --abr-font:       'Vazirmatn', Tahoma, 'Segoe UI', sans-serif;
    --abr-z:          99999;
    --abr-width:      360px;
    --abr-height:     520px;
}

/* ── Root ── */
#abr-chat-root {
    position: fixed;
    bottom: 24px;
    z-index: var(--abr-z);
    direction: rtl;
    font-family: var(--abr-font);
}
#abr-chat-root.abr-pos-left  { left: 24px; }
#abr-chat-root.abr-pos-right { right: 24px; }

/* ── Bubble ── */
.abr-bubble {
    width: 58px; height: 58px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--abr-primary), var(--abr-accent));
    color: #fff;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 18px rgba(0,85,165,.45);
    transition: transform .25s cubic-bezier(.34,1.56,.64,1), box-shadow .25s;
    position: relative;
    outline: none;
}
.abr-bubble:hover  { transform: scale(1.1); box-shadow: 0 8px 28px rgba(0,85,165,.55); }
.abr-bubble:active { transform: scale(.95); }

/* Icons – CSS-only transition, NO hidden attribute */
.abr-bubble-icon {
    position: absolute;
    width: 26px; height: 26px;
    display: flex; align-items: center; justify-content: center;
    transition: opacity .22s ease, transform .22s ease;
    pointer-events: none;
}
.abr-icon-chat  { opacity: 1; transform: scale(1) rotate(0deg); }
.abr-icon-close { opacity: 0; transform: scale(.6) rotate(-60deg); }

.abr-bubble.abr-open .abr-icon-chat  { opacity: 0; transform: scale(.6) rotate(60deg); }
.abr-bubble.abr-open .abr-icon-close { opacity: 1; transform: scale(1) rotate(0deg); }

/* Badge */
.abr-badge {
    position: absolute;
    top: -4px; right: -4px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    width: 20px; height: 20px;
    font-size: 11px; font-weight: 700;
    display: none;
    align-items: center; justify-content: center;
    border: 2px solid white;
    animation: abr-pulse 1.8s infinite;
}
@keyframes abr-pulse {
    0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,.5); }
    50%      { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}

/* ── Chat window ── */
.abr-window {
    position: absolute;
    bottom: 72px;
    width: var(--abr-width);
    height: var(--abr-height);
    background: var(--abr-white);
    border-radius: 16px;
    box-shadow: var(--abr-shadow);
    display: none;          /* JS switches to flex */
    flex-direction: column;
    overflow: hidden;
    transform: scale(.88) translateY(16px);
    opacity: 0;
    transform-origin: bottom center;
    transition: transform .28s cubic-bezier(.34,1.2,.64,1), opacity .22s ease;
}
#abr-chat-root.abr-pos-left  .abr-window { left: 0; }
#abr-chat-root.abr-pos-right .abr-window { right: 0; }

.abr-window.abr-visible {
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* ── Header ── */
.abr-header {
    background: linear-gradient(135deg, var(--abr-primary) 0%, var(--abr-primary-dk) 100%);
    padding: 14px 16px;
    display: flex; align-items: center; gap: 12px;
    flex-shrink: 0;
}
.abr-header-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: rgba(255,255,255,.15);
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.abr-header-avatar svg { width: 26px; height: 26px; }
.abr-header-info { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.abr-header-name { color: white; font-size: 14px; font-weight: 700; }
.abr-header-status { color: rgba(255,255,255,.8); font-size: 11px; display: flex; align-items: center; gap: 5px; }
.abr-dot { width: 7px; height: 7px; background: #4ade80; border-radius: 50%; display: inline-block; animation: abr-blink 2s infinite; }
@keyframes abr-blink { 0%,100%{opacity:1} 50%{opacity:.4} }

/* Header close button */
.abr-close-btn {
    background: rgba(255,255,255,.15);
    border: none; color: white;
    width: 32px; height: 32px; border-radius: 50%;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .2s;
    flex-shrink: 0;
    z-index: 2;
}
.abr-close-btn svg { width: 16px; height: 16px; pointer-events: none; }
.abr-close-btn:hover { background: rgba(255,255,255,.3); }

/* ── Messages
   CRITICAL: keep direction RTL so Persian text renders correctly.
   Use align-self to position bot(right) vs user(left).
   In RTL flex-column: flex-start = RIGHT side, flex-end = LEFT side.
─── */
.abr-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--abr-bg);
    scroll-behavior: smooth;
    /* direction inherits RTL from parent – DO NOT override */
}
.abr-messages::-webkit-scrollbar { width: 4px; }
.abr-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* Base row */
.abr-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 82%;
    animation: abr-msg-in .28s ease both;
}
@keyframes abr-msg-in {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Bot: right side in RTL, avatar on far right */
.abr-msg.abr-bot {
    align-self: flex-start;   /* = RIGHT in RTL column */
    flex-direction: row;      /* RTL row: first child goes to right */
}

/* User: left side in RTL, no avatar */
.abr-msg.abr-user {
    align-self: flex-end;     /* = LEFT in RTL column */
    flex-direction: row;
}

/* Avatar */
.abr-msg-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: linear-gradient(135deg, var(--abr-primary), var(--abr-accent));
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.abr-msg-avatar svg { width: 18px; height: 18px; fill: white; }

/* Bubble */
.abr-msg-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.75;
    word-break: break-word;
    /* text direction inherits RTL – Persian renders correctly */
}

.abr-msg.abr-bot .abr-msg-bubble {
    background: var(--abr-white);
    color: var(--abr-text);
    border-radius: 4px 14px 14px 14px;
    box-shadow: 0 1px 4px rgba(0,0,0,.07);
}

.abr-msg.abr-user .abr-msg-bubble {
    background: linear-gradient(135deg, var(--abr-primary), var(--abr-accent));
    color: white;
    border-radius: 14px 14px 14px 4px;
}

/* Typing dots */
.abr-typing .abr-msg-bubble {
    background: var(--abr-white);
    box-shadow: 0 1px 4px rgba(0,0,0,.07);
    border-radius: 4px 14px 14px 14px;
    padding: 12px 16px;
}
.abr-dots { display: flex; gap: 4px; align-items: center; height: 16px; }
.abr-dots span {
    width: 6px; height: 6px; background: #94a3b8; border-radius: 50%;
    animation: abr-dot-bounce .9s infinite;
}
.abr-dots span:nth-child(2) { animation-delay: .15s; }
.abr-dots span:nth-child(3) { animation-delay: .30s; }
@keyframes abr-dot-bounce {
    0%,80%,100% { transform: translateY(0); }
    40%         { transform: translateY(-6px); }
}

/* ── Quick buttons ── */
.abr-quick-wrap {
    padding: 6px 12px 8px;
    display: flex; flex-wrap: wrap; gap: 6px;
    background: var(--abr-bg);
    border-top: 1px solid var(--abr-border);
    max-height: 90px; overflow-y: auto;
}
.abr-quick-btn {
    background: white;
    border: 1px solid var(--abr-primary);
    color: var(--abr-primary);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 12px; cursor: pointer;
    font-family: var(--abr-font);
    transition: all .2s; white-space: nowrap;
}
.abr-quick-btn:hover { background: var(--abr-primary); color: white; }

/* ── Input area ── */
.abr-input-area {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 12px;
    background: white;
    border-top: 1px solid var(--abr-border);
    flex-shrink: 0;
}
.abr-input {
    flex: 1;
    border: 1.5px solid var(--abr-border);
    border-radius: 22px;
    padding: 9px 16px;
    font-size: 13.5px;
    font-family: var(--abr-font);
    outline: none; color: var(--abr-text);
    background: #f8fafc;
    transition: border-color .2s, box-shadow .2s;
    direction: rtl; text-align: right;
}
.abr-input:focus {
    border-color: var(--abr-accent);
    box-shadow: 0 0 0 3px rgba(0,180,216,.12);
    background: white;
}
.abr-input::placeholder { color: #a0aec0; }

.abr-send-btn {
    width: 38px; height: 38px;
    border-radius: 50%; border: none;
    background: linear-gradient(135deg, var(--abr-primary), var(--abr-accent));
    color: white; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: transform .2s, box-shadow .2s;
    box-shadow: 0 2px 8px rgba(0,85,165,.3);
}
.abr-send-btn svg { width: 17px; height: 17px; transform: rotate(180deg); }
.abr-send-btn:hover  { transform: scale(1.08); box-shadow: 0 4px 14px rgba(0,85,165,.4); }
.abr-send-btn:active { transform: scale(.95); }

/* ── Branding ── */
.abr-branding {
    text-align: center; padding: 5px;
    font-size: 10px; color: #a0aec0;
    background: white;
    border-top: 1px solid var(--abr-border);
    flex-shrink: 0;
}
.abr-branding a { color: #a0aec0; text-decoration: none; }
.abr-branding a:hover { color: var(--abr-primary); }

/* ── Mobile ── */
@media (max-width: 480px) {
    :root { --abr-width: calc(100vw - 32px); --abr-height: 480px; }
    #abr-chat-root.abr-pos-left,
    #abr-chat-root.abr-pos-right { left: 16px; right: 16px; bottom: 16px; }
    .abr-window { left: 0 !important; right: 0 !important; width: 100% !important; }
}
@media (max-width: 768px) {
    #abr-chat-root.abr-hide-mobile { display: none !important; }
}

/* ── Page link buttons (inside bot bubble) ── */
.abr-page-links {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(0,0,0,.08);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.abr-page-links-label {
    font-size: 11px;
    color: #94a3b8;
    font-weight: 600;
    letter-spacing: .3px;
}

.abr-page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 7px 12px;
    background: linear-gradient(135deg, #f0f7ff, #e8f4fd);
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    color: #1d4ed8;
    font-size: 12.5px;
    font-family: var(--abr-font);
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background .18s, border-color .18s, transform .15s;
    direction: rtl;
    line-height: 1.4;
}

.abr-page-btn:hover {
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
    border-color: #93c5fd;
    transform: translateY(-1px);
    color: #1e40af;
    text-decoration: none;
}

.abr-page-btn:active {
    transform: translateY(0);
}

.abr-btn-arrow {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: .7;
}
