/* ==============================================================
   AI Assistant widget — زر عائم + نافذة محادثة
   الألوان: #1A365D (كحلي) / #C59D5F (ذهبي) / #F9FAFB / #FFFFFF
   ============================================================== */

.aiw-btn {
    position: fixed;
    bottom: 22px;
    right: 22px;
    z-index: 990;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: linear-gradient(145deg, #1A365D, #122844);
    color: #C59D5F;
    font-size: 1.45rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 18px rgba(26, 54, 93, .35);
    transition: transform .2s, box-shadow .2s;
}
.aiw-btn:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 10px 24px rgba(26, 54, 93, .45);
}
.aiw-btn:focus-visible {
    outline: 3px solid #C59D5F;
    outline-offset: 2px;
}

/* ---------- نافذة المحادثة ---------- */
.aiw-panel {
    position: fixed;
    bottom: 92px;
    right: 22px;
    z-index: 991;
    width: 360px;
    max-width: calc(100vw - 24px);
    height: 480px;
    max-height: calc(100vh - 120px);
    background: #FFFFFF;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    box-shadow: 0 18px 48px rgba(0, 0, 0, .22);
    display: none;
    flex-direction: column;
    overflow: hidden;
    direction: rtl;
}
.aiw-panel.aiw-open { display: flex; }

.aiw-head {
    background: linear-gradient(145deg, #1A365D, #14305a);
    color: #FFFFFF;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.aiw-head i.aiw-head-icon { color: #C59D5F; font-size: 1.15rem; }
.aiw-head-title { font-weight: 700; font-size: .95rem; flex: 1; line-height: 1.3; }
.aiw-head-sub   { display: block; font-weight: 400; font-size: .7rem; color: rgba(255,255,255,.65); }
.aiw-close {
    background: none;
    border: none;
    color: rgba(255,255,255,.8);
    cursor: pointer;
    font-size: 1rem;
    padding: 4px 6px;
    border-radius: 6px;
}
.aiw-close:hover { color: #fff; background: rgba(255,255,255,.12); }

/* ---------- ملاحظة الخصوصية ---------- */
.aiw-privacy {
    font-size: .68rem;
    color: #6b7280;
    background: #F9FAFB;
    border-bottom: 1px solid #eef0f3;
    padding: 6px 12px;
    flex-shrink: 0;
    line-height: 1.5;
}
.aiw-privacy i { color: #C59D5F; margin-left: 4px; }

/* ---------- الرسائل ---------- */
.aiw-msgs {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    background: #F9FAFB;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scrollbar-width: thin;
}
.aiw-msg {
    max-width: 85%;
    padding: 9px 12px;
    border-radius: 14px;
    font-size: .86rem;
    line-height: 1.65;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.aiw-msg-user {
    align-self: flex-start;          /* RTL: يسار = جهة المستخدم */
    background: #1A365D;
    color: #fff;
    border-bottom-left-radius: 4px;
}
.aiw-msg-bot {
    align-self: flex-end;
    background: #FFFFFF;
    color: #1f2937;
    border: 1px solid #e5e7eb;
    border-bottom-right-radius: 4px;
}

/* روابط المكتبة المقترحة */
.aiw-links {
    align-self: flex-end;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-width: 90%;
}
.aiw-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: .74rem;
    font-weight: 600;
    color: #1A365D;
    background: #fff;
    border: 1px solid #C59D5F;
    border-radius: 999px;
    padding: 4px 11px;
    text-decoration: none;
    transition: .15s;
}
.aiw-link:hover { background: #C59D5F; color: #fff; }
.aiw-link i { color: #C59D5F; }
.aiw-link:hover i { color: #fff; }

/* مؤشر الكتابة */
.aiw-typing {
    align-self: flex-end;
    background: #FFFFFF;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    padding: 10px 14px;
    display: flex;
    gap: 5px;
}
.aiw-typing span {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #C59D5F;
    animation: aiwBlink 1.2s infinite ease-in-out;
}
.aiw-typing span:nth-child(2) { animation-delay: .18s; }
.aiw-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes aiwBlink {
    0%, 80%, 100% { opacity: .25; transform: translateY(0); }
    40%           { opacity: 1;   transform: translateY(-3px); }
}

/* ---------- الإدخال ---------- */
.aiw-form {
    display: flex;
    gap: 8px;
    padding: 10px;
    background: #FFFFFF;
    border-top: 1px solid #eef0f3;
    flex-shrink: 0;
}
.aiw-input {
    flex: 1;
    border: 1px solid #e5e7eb;
    border-radius: 999px;
    padding: 9px 14px;
    font-size: .86rem;
    font-family: inherit;
    background: #F9FAFB;
    color: #111827;
}
.aiw-input:focus {
    outline: none;
    border-color: #C59D5F;
    box-shadow: 0 0 0 3px rgba(197, 157, 95, .18);
    background: #fff;
}
.aiw-send {
    width: 40px; height: 40px;
    flex-shrink: 0;
    border: none;
    border-radius: 50%;
    background: #C59D5F;
    color: #fff;
    cursor: pointer;
    font-size: .95rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: .15s;
}
.aiw-send:hover:not(:disabled) { background: #a88343; }
.aiw-send:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- موبايل ---------- */
@media (max-width: 480px) {
    .aiw-btn   { bottom: 16px; right: 16px; width: 52px; height: 52px; font-size: 1.3rem; }
    .aiw-panel {
        bottom: 80px;
        right: 12px;
        left: 12px;
        width: auto;
        height: 70vh;
    }
}

@media print {
    .aiw-btn, .aiw-panel { display: none !important; }
}
