/* ai_chat.css — floating "אלייה" support chat widget.
   Positioned on the OPPOSITE corner from the accessibility widget
   (accessibility uses inset-inline-start; we use inset-inline-end).
   Mirrors automatically in RTL because everything uses inset-inline-*. */

:root {
    --aic-brand:        #4f46e5;   /* indigo — same as footer accent */
    --aic-brand-dark:   #4338ca;
    --aic-brand-light:  #6366f1;
    --aic-bg:           #ffffff;
    --aic-bg-soft:      #f9fafb;
    --aic-text:         #1f2937;
    --aic-text-muted:   #6b7280;
    --aic-border:       #e5e7eb;
    --aic-bubble-user:  #eef2ff;
    --aic-bubble-bot:   #f3f4f6;
    --aic-shadow:       0 10px 30px rgba(17, 24, 39, .18);
}

/* ───── Launcher ───── */
.ai-chat-launcher {
    position: fixed;
    bottom: 20px;
    inset-inline-end: 20px;
    z-index: 10000;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--aic-brand) 0%, var(--aic-brand-light) 100%);
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    box-shadow: var(--aic-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .18s ease, box-shadow .18s ease;
}
.ai-chat-launcher:hover,
.ai-chat-launcher:focus-visible {
    transform: scale(1.06);
    box-shadow: 0 12px 36px rgba(79, 70, 229, .35);
    outline: 3px solid #fbbf24;
    outline-offset: 2px;
}
.ai-chat-launcher.is-open { transform: scale(0.92); opacity: .8; }

/* Pulsing dot to draw attention on first paint */
.ai-chat-launcher-pulse {
    position: absolute;
    top: 4px;
    inset-inline-end: 4px;
    width: 12px;
    height: 12px;
    background: #10b981;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 0 rgba(16, 185, 129, .6);
    animation: aic-pulse 2.2s infinite;
}
@keyframes aic-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(16, 185, 129, .6); }
    70%  { box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}
.ai-chat-launcher.is-open .ai-chat-launcher-pulse { display: none; }

/* ───── Panel ───── */
.ai-chat-panel {
    position: fixed;
    bottom: 90px;
    inset-inline-end: 20px;
    z-index: 10000;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 120px);
    background: var(--aic-bg);
    border-radius: 16px;
    box-shadow: var(--aic-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.96);
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
    font-family: 'Heebo', 'Inter', system-ui, -apple-system, Segoe UI, Arial, sans-serif;
    color: var(--aic-text);
}
.ai-chat-panel.is-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ───── Header ───── */
.ai-chat-head {
    background: linear-gradient(135deg, var(--aic-brand) 0%, var(--aic-brand-light) 100%);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.ai-chat-head-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.ai-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .22);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.ai-chat-head-text { min-width: 0; }
.ai-chat-name {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
}
.ai-chat-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    opacity: .92;
    margin-top: 2px;
}
.ai-chat-status-dot {
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(74, 222, 128, .6);
    animation: aic-pulse 2.2s infinite;
}
.ai-chat-close {
    background: rgba(255, 255, 255, .15);
    color: #fff;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s;
}
.ai-chat-close:hover, .ai-chat-close:focus-visible {
    background: rgba(255, 255, 255, .3);
    outline: none;
}

/* ───── Messages ───── */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--aic-bg-soft);
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}
.ai-chat-msg { display: flex; }
.ai-chat-msg-bot  { justify-content: flex-start; }
.ai-chat-msg-user { justify-content: flex-end; }
.ai-chat-bubble {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.ai-chat-msg-bot .ai-chat-bubble {
    background: var(--aic-bubble-bot);
    color: var(--aic-text);
    border-end-start-radius: 4px;
}
.ai-chat-msg-user .ai-chat-bubble {
    background: var(--aic-bubble-user);
    color: var(--aic-text);
    border-end-end-radius: 4px;
}
.ai-chat-msg-error .ai-chat-bubble {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

/* Typing indicator */
.ai-chat-typing {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    padding: 4px 0;
}
.ai-chat-typing span {
    width: 6px;
    height: 6px;
    background: var(--aic-text-muted);
    border-radius: 50%;
    animation: aic-bounce 1.2s infinite ease-in-out both;
}
.ai-chat-typing span:nth-child(2) { animation-delay: .15s; }
.ai-chat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes aic-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: .4; }
    40%           { transform: scale(1);   opacity: 1;  }
}

/* ───── Suggestions ───── */
.ai-chat-suggestions {
    padding: 8px 12px;
    border-top: 1px solid var(--aic-border);
    background: var(--aic-bg);
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.ai-chat-suggestions.is-hidden { display: none; }
.ai-chat-chip {
    background: var(--aic-bg-soft);
    border: 1px solid var(--aic-border);
    color: var(--aic-text);
    padding: 6px 12px;
    border-radius: 100px;
    font-size: 12px;
    cursor: pointer;
    transition: all .15s;
    font-family: inherit;
}
.ai-chat-chip:hover {
    background: var(--aic-brand);
    color: #fff;
    border-color: var(--aic-brand);
}

/* ───── Form ───── */
.ai-chat-form {
    border-top: 1px solid var(--aic-border);
    background: var(--aic-bg);
    padding: 10px 12px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.ai-chat-form textarea {
    flex: 1;
    border: 1px solid var(--aic-border);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    max-height: 100px;
    font-family: inherit;
    color: var(--aic-text);
    background: var(--aic-bg);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.ai-chat-form textarea:focus {
    border-color: var(--aic-brand);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}
.ai-chat-send {
    background: var(--aic-brand);
    color: #fff;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background .15s, transform .15s;
}
.ai-chat-send:hover  { background: var(--aic-brand-dark); }
.ai-chat-send:active { transform: scale(0.92); }
.ai-chat-send:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
    transform: none;
}

/* In RTL the paper-plane icon needs to flip so it points the right way */
[dir="rtl"] .ai-chat-send i { transform: scaleX(-1); }

/* ───── Footer disclaimer ───── */
.ai-chat-foot {
    background: var(--aic-bg-soft);
    color: var(--aic-text-muted);
    font-size: 10.5px;
    padding: 6px 14px;
    text-align: center;
    border-top: 1px solid var(--aic-border);
    line-height: 1.4;
}

/* ───── Mobile ───── */
@media (max-width: 480px) {
    .ai-chat-launcher {
        bottom: 14px;
        inset-inline-end: 14px;
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
    .ai-chat-panel {
        bottom: 0;
        inset-inline-end: 0;
        inset-inline-start: 0;
        width: 100%;
        max-width: 100%;
        height: 92vh;
        max-height: 92vh;
        border-radius: 16px 16px 0 0;
    }
}

/* ───── Accessibility-widget compatibility ─────
   If the user activates the a11y dark mode, mirror it for our chat. */
body.a11y-dark .ai-chat-panel,
body.a11y-dark .ai-chat-bubble,
body.a11y-dark .ai-chat-form textarea {
    background: #1f2937;
    color: #f9fafb;
    border-color: #374151;
}
body.a11y-dark .ai-chat-messages,
body.a11y-dark .ai-chat-suggestions,
body.a11y-dark .ai-chat-form,
body.a11y-dark .ai-chat-foot { background: #111827; color: #d1d5db; }
body.a11y-dark .ai-chat-msg-bot  .ai-chat-bubble { background: #374151; color: #f9fafb; }
body.a11y-dark .ai-chat-msg-user .ai-chat-bubble { background: #4f46e5; color: #fff; }
body.a11y-dark .ai-chat-chip { background: #1f2937; color: #e5e7eb; border-color: #374151; }
