/* ============================================================
   ai-assistant.css — المساعدة الذكية (الأفاتار المتحركة الناطقة)
   ============================================================ */

:root {
    --ai-gold: #c9a24b;
    --ai-gold-light: #e6c97a;
    --ai-dark: #16283f;
    --ai-darker: #0e1a2a;
    --ai-panel-bg: #101f33;
}

/* ---------- الزر العائم — دائماً أسفل اليسار (واتساب دائماً أسفل اليمين) ---------- */
.ai-widget {
    position: fixed;
    bottom: 24px;
    left: 24px;
    right: auto;
    z-index: 1050;
    font-family: inherit;
}

.ai-fab {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 2px solid var(--ai-gold);
    background: var(--ai-dark);
    cursor: pointer;
    padding: 0;
    box-shadow: 0 6px 22px rgba(0, 0, 0, .45);
    transition: transform .25s ease, box-shadow .25s ease;
    overflow: visible;
}
.ai-fab:hover { transform: scale(1.08); box-shadow: 0 8px 28px rgba(201, 162, 75, .4); }
.ai-fab-avatar { display: block; width: 100%; height: 100%; border-radius: 50%; overflow: hidden; }
.ai-svg { width: 100%; height: 100%; display: block; }

.ai-fab-pulse {
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    border: 2px solid var(--ai-gold);
    animation: aiPulse 2.4s ease-out infinite;
    pointer-events: none;
}
.ai-widget.open .ai-fab-pulse { animation: none; opacity: 0; }
@keyframes aiPulse {
    0%   { transform: scale(1);    opacity: .8; }
    70%  { transform: scale(1.45); opacity: 0; }
    100% { transform: scale(1.45); opacity: 0; }
}

/* ---------- نافذة المحادثة ---------- */
.ai-panel {
    position: absolute;
    bottom: 76px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 500px;
    max-height: calc(100vh - 140px);
    background: var(--ai-panel-bg);
    border: 1px solid rgba(201, 162, 75, .35);
    border-radius: 18px;
    box-shadow: 0 18px 60px rgba(0, 0, 0, .55);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: aiSlideUp .28s cubic-bezier(.21, 1.02, .73, 1);
}
.ai-panel { left: 0; right: auto; }
.ai-panel[hidden] { display: none; }
@keyframes aiSlideUp {
    from { opacity: 0; transform: translateY(18px) scale(.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- الرأس ---------- */
.ai-panel-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: linear-gradient(135deg, var(--ai-darker), var(--ai-dark));
    border-bottom: 1px solid rgba(201, 162, 75, .3);
}
.ai-head-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--ai-gold);
    flex-shrink: 0;
    background: var(--ai-dark);
}
.ai-head-info { flex: 1; min-width: 0; color: #f2ead8; line-height: 1.25; }
.ai-head-info strong { display: block; font-size: .95rem; }
.ai-head-info small { color: #9fb2c8; font-size: .72rem; display: flex; align-items: center; gap: 5px; }
.ai-online-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: #4ade80; display: inline-block;
    box-shadow: 0 0 6px #4ade80;
    animation: aiOnlineBlink 2s ease-in-out infinite;
}
@keyframes aiOnlineBlink { 50% { opacity: .45; } }

.ai-head-actions { display: flex; gap: 6px; }
.ai-icon-btn {
    width: 32px; height: 32px;
    border-radius: 8px;
    border: 1px solid rgba(201, 162, 75, .35);
    background: transparent;
    color: var(--ai-gold-light);
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background .2s;
}
.ai-icon-btn:hover { background: rgba(201, 162, 75, .15); }
.ai-icon-btn.muted { color: #7c8ea3; border-color: rgba(255, 255, 255, .15); }

/* ---------- الرسائل ---------- */
.ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background:
        radial-gradient(ellipse at 20% 0%, rgba(201, 162, 75, .06), transparent 55%),
        var(--ai-panel-bg);
}
.ai-messages::-webkit-scrollbar { width: 6px; }
.ai-messages::-webkit-scrollbar-thumb { background: rgba(201, 162, 75, .3); border-radius: 3px; }

.ai-msg {
    max-width: 84%;
    padding: 9px 13px;
    border-radius: 14px;
    font-size: .88rem;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
    animation: aiMsgIn .22s ease-out;
}
@keyframes aiMsgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.ai-msg-bot {
    align-self: flex-start;
    background: rgba(255, 255, 255, .07);
    border: 1px solid rgba(201, 162, 75, .2);
    color: #eef2f7;
    border-start-start-radius: 4px;
}
.ai-msg-user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--ai-gold), #a8842f);
    color: #14100a;
    font-weight: 500;
    border-start-end-radius: 4px;
}

/* مؤشر الكتابة */
.ai-typing { display: inline-flex; gap: 5px; align-items: center; padding: 12px 16px; }
.ai-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--ai-gold-light);
    animation: aiDotBounce 1.2s ease-in-out infinite;
}
.ai-dot:nth-child(2) { animation-delay: .18s; }
.ai-dot:nth-child(3) { animation-delay: .36s; }
@keyframes aiDotBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .5; }
    30%           { transform: translateY(-5px); opacity: 1; }
}

/* ---------- حقل الإدخال ---------- */
.ai-input-row {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    background: var(--ai-darker);
    border-top: 1px solid rgba(201, 162, 75, .25);
}
.ai-input-row input {
    flex: 1;
    background: rgba(255, 255, 255, .06);
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 22px;
    color: #f2ead8;
    padding: 9px 16px;
    font-size: .88rem;
    outline: none;
    transition: border-color .2s;
    font-family: inherit;
}
.ai-input-row input:focus { border-color: var(--ai-gold); }
.ai-input-row input::placeholder { color: #7c8ea3; }
.ai-send {
    width: 40px; height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--ai-gold), #a8842f);
    color: #14100a;
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1rem;
    transition: transform .15s;
    flex-shrink: 0;
}
.ai-send:hover { transform: scale(1.1); }
html[dir="rtl"] .ai-send i { transform: scaleX(-1); display: inline-block; }

/* ============================================================
   حركات الأفاتار (صورة ريم الرسمية)
   ============================================================ */

.ai-photo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    user-select: none;
}

/* تنفّس خفيف في وضع الخمول */
.ai-head-avatar .ai-photo { animation: aiBreath 4.5s ease-in-out infinite; }
@keyframes aiBreath {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.035); }
}

/* أثناء الكلام: اهتزاز لطيف + توهج ذهبي */
.ai-head-avatar.talking .ai-photo { animation: aiTalkBob .42s ease-in-out infinite alternate; }
/* الزر العائم ينبض بنعومة أثناء الكلام */
.ai-fab-avatar.talking { animation: aiFabTalk 1.1s ease-in-out infinite; box-shadow: 0 0 16px rgba(201, 162, 75, .6); }
@keyframes aiFabTalk {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.06); }
}
@keyframes aiTalkBob {
    from { transform: scale(1.02) translateY(0); }
    to   { transform: scale(1.07) translateY(-1.5px); }
}
.ai-head-avatar.talking {
    border-color: var(--ai-gold-light);
    box-shadow: 0 0 14px rgba(201, 162, 75, .55);
}

/* أشرطة صوت متحركة أسفل الأفاتار أثناء الكلام */
.ai-speaking-bars {
    position: absolute;
    bottom: 2px;
    inset-inline-end: 2px;
    display: none;
    align-items: flex-end;
    gap: 2px;
    background: rgba(14, 26, 42, .85);
    border: 1px solid var(--ai-gold);
    border-radius: 8px;
    padding: 3px 4px;
}
.ai-head-avatar.talking .ai-speaking-bars { display: flex; }
.ai-speaking-bars i {
    width: 3px;
    background: var(--ai-gold-light);
    border-radius: 2px;
    animation: aiBar .7s ease-in-out infinite;
}
.ai-speaking-bars i:nth-child(1) { height: 6px; }
.ai-speaking-bars i:nth-child(2) { height: 10px; animation-delay: .18s; }
.ai-speaking-bars i:nth-child(3) { height: 7px; animation-delay: .36s; }
@keyframes aiBar {
    0%, 100% { transform: scaleY(.5); }
    50%      { transform: scaleY(1.4); }
}
.ai-head-avatar { position: relative; }

/* ---------- مبدّل طريقة إخراج الرد (كتابي/صوتي) ---------- */
.ai-output-toggle { display: inline-flex; border: 1px solid rgba(201,162,75,.35); border-radius: 8px; overflow: hidden; align-self: stretch; }
.ai-output-toggle button { border: 0; background: transparent; padding: 0 8px; font-size: 1rem; cursor: pointer; opacity: .45; transition: opacity .2s, background .2s; display: inline-flex; align-items: center; }
.ai-output-toggle button.active { opacity: 1; background: rgba(201,162,75,.18); }
.ai-output-toggle button + button { border-inline-start: 1px solid rgba(201,162,75,.25); }

/* ---------- زر الإدخال الصوتي (staff فقط) ---------- */
.ai-mic { border: 1px solid rgba(201,162,75,.35); border-radius: 8px; background: transparent; color: var(--ai-gold-light); width: 40px; align-self: stretch; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: background .25s; }
.ai-mic:hover { background: rgba(201,162,75,.12); }
.ai-mic.recording { color: #f87171; border-color: #f87171; animation: aiRecPulse 1.1s ease-in-out infinite; }
@keyframes aiRecPulse { 50% { box-shadow: 0 0 10px rgba(248,113,113,.7); } }

/* ---------- تجاوب الجوال ---------- */
@media (max-width: 480px) {
    .ai-widget { bottom: 16px; left: 16px; right: auto; }
    .ai-fab { width: 54px; height: 54px; }
    .ai-panel {
        position: fixed;
        bottom: 84px;
        left: 12px !important;
        right: 12px !important;
        width: auto;
        height: 62vh;
    }
}
