/* =============================================================
   مساعد مودة — ويدجت الشات بوت
   الهيكل: resources/views/front/partials/chatbot.blade.php
   السلوك: public/assets/js/chatbot.js
   المحادثة: config/chatbot.php + App\Services\ChatbotService
   ============================================================= */

.mwd-chat {
    --chat-primary: #f68962;
    --chat-primary-dark: #e5734a;
    --chat-soft: #fdeee7;
    --chat-border: #f8cdb8;
    --chat-text: #4b4b4b;
    --chat-muted: #8f8f8f;
    --chat-radius: 18px;

    position: fixed;
    bottom: 30px;
    /* أقل من نوافذ بوتستراب (1040+) حتى لا يغطّي المودالات */
    z-index: 1030;
    line-height: 1.7;
    font-family: 'Cairo', 'Tajawal', sans-serif;
}

/* الزاوية المقابلة لزر "تبرع سريع" حتى لا يتراكبا */
html[dir="rtl"] .mwd-chat {
    right: 24px;
    left: auto;
}

html[dir="ltr"] .mwd-chat {
    left: 24px;
    right: auto;
}

/* ------------------------------------------------------- الزر العائم */

.mwd-chat__launcher {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 18px 8px 8px;
    border: none;
    border-radius: 999px;
    background: var(--chat-primary);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(246, 137, 98, 0.35);
    transition: transform 0.2s ease, background-color 0.2s ease;
    /* حاوية اللمعة (::after) */
    position: relative;
    overflow: hidden;
    isolation: isolate;
}

html[dir="ltr"] .mwd-chat__launcher {
    padding: 8px 8px 8px 18px;
    flex-direction: row-reverse;
}

.mwd-chat__launcher:hover,
.mwd-chat__launcher:focus-visible {
    background: var(--chat-primary-dark);
    transform: translateY(-2px);
    color: #fff;
}

/* لمعة زجاجية: شريط أبيض مائل ضيّق يعبر الزر من طرف إلى طرف كل خمس ثوانٍ،
   أربع مرات بعد تحميل الصفحة ثم يهدأ. تتوقف فور فتح المحادثة، وتُلغى لمن
   يطلب تقليل الحركة في إعدادات نظامه. */
.mwd-chat__launcher::after {
    content: "";
    position: absolute;
    top: -70%;
    bottom: -70%;
    width: 26%;
    inset-inline-start: -40%;
    background: linear-gradient(90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.18) 28%,
        rgba(255, 255, 255, 1) 50%,
        rgba(255, 255, 255, 0.18) 72%,
        rgba(255, 255, 255, 0) 100%);
    transform: skewX(-20deg);
    filter: blur(3px);
    opacity: 0;
    pointer-events: none;
}

.mwd-chat--attention .mwd-chat__launcher {
    animation: mwd-chat-pulse 5s ease-in-out 4;
}

.mwd-chat--attention .mwd-chat__launcher::after {
    animation: mwd-chat-shine 5s ease-in-out 4;
}

.mwd-chat.is-open .mwd-chat__launcher,
.mwd-chat.is-open .mwd-chat__launcher::after {
    animation: none;
}

/* الشريط يعبر الزر في أول ثانية ونصف من الدورة، ثم يستريح حتى الدورة التالية. */
@keyframes mwd-chat-shine {
    0% {
        inset-inline-start: -40%;
        opacity: 0;
    }

    5% {
        opacity: 1;
    }

    30% {
        inset-inline-start: 115%;
        opacity: 1;
    }

    34%,
    100% {
        inset-inline-start: 115%;
        opacity: 0;
    }
}

@keyframes mwd-chat-pulse {
    0%,
    40%,
    100% {
        box-shadow: 0 10px 24px rgba(246, 137, 98, 0.35);
    }

    10% {
        box-shadow: 0 10px 24px rgba(246, 137, 98, 0.45), 0 0 0 10px rgba(246, 137, 98, 0.18);
    }

    26% {
        box-shadow: 0 10px 24px rgba(246, 137, 98, 0.35), 0 0 0 20px rgba(246, 137, 98, 0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .mwd-chat--attention .mwd-chat__launcher,
    .mwd-chat--attention .mwd-chat__launcher::after {
        animation: none;
    }
}

.mwd-chat__launcher-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #fff;
    color: var(--chat-primary);
    font-size: 18px;
    flex: 0 0 auto;
}

/* ---------------------------------------------------------- البطاقة */

.mwd-chat__panel {
    position: absolute;
    bottom: calc(100% + 14px);
    width: 370px;
    max-width: calc(100vw - 32px);
    max-height: min(78vh, 640px);
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid var(--chat-border);
    border-radius: 24px;
    box-shadow: 0 18px 50px rgba(72, 44, 33, 0.18);
    overflow: hidden;
    opacity: 0;
    transform: translateY(12px) scale(0.98);
    transition: opacity 0.18s ease, transform 0.18s ease;
}

html[dir="rtl"] .mwd-chat__panel {
    right: 0;
    transform-origin: bottom right;
}

html[dir="ltr"] .mwd-chat__panel {
    left: 0;
    transform-origin: bottom left;
}

.mwd-chat.is-open .mwd-chat__panel {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.mwd-chat__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--chat-soft);
    background: #fff;
    flex: 0 0 auto;
}

.mwd-chat__avatar,
.mwd-chat__intro-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid var(--chat-border);
    background: #fff;
    overflow: hidden;
}

.mwd-chat__avatar img,
.mwd-chat__intro-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 4px;
}

.mwd-chat__avatar {
    width: 40px;
    height: 40px;
}

.mwd-chat__header-actions {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.mwd-chat__icon-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--chat-muted);
    font-size: 16px;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.mwd-chat__icon-btn:hover,
.mwd-chat__icon-btn:focus-visible {
    background: var(--chat-soft);
    color: var(--chat-primary);
}

/* ----------------------------------------------------- جسم المحادثة */

.mwd-chat__body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 18px 16px 8px;
    background: #fff;
}

.mwd-chat__body::-webkit-scrollbar {
    width: 6px;
}

.mwd-chat__body::-webkit-scrollbar-thumb {
    background: var(--chat-border);
    border-radius: 999px;
}

.mwd-chat__intro {
    text-align: center;
    margin-bottom: 18px;
}

.mwd-chat__intro-avatar {
    width: 74px;
    height: 74px;
    margin: 0 auto 10px;
}

.mwd-chat__intro-title {
    margin: 0 0 6px;
    font-size: 19px;
    font-weight: 700;
    color: var(--chat-primary);
}

.mwd-chat__intro-text {
    margin: 0;
    font-size: 13px;
    color: var(--chat-muted);
}

.mwd-chat__stream {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.mwd-chat__msg {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 100%;
}

.mwd-chat__msg--user {
    max-width: 85%;
    padding: 9px 14px;
    border-radius: 16px;
    background: var(--chat-primary);
    color: #fff;
    font-size: 13px;
}

html[dir="rtl"] .mwd-chat__msg--user {
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

html[dir="ltr"] .mwd-chat__msg--user {
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.mwd-chat__text {
    padding: 11px 14px;
    border-radius: 16px;
    background: var(--chat-soft);
    color: var(--chat-text);
    font-size: 13px;
}

.mwd-chat__text strong {
    color: #3d3d3d;
}

.mwd-chat__text--success {
    background: #eef8f0;
    border: 1px solid #cfe9d5;
}

.mwd-chat__text--warning {
    background: #fdf3ec;
    border: 1px solid var(--chat-border);
}

/* -------------------------------------------------- نقاط "يكتب الآن" */

.mwd-chat__typing {
    flex-direction: row;
    align-items: center;
    gap: 4px;
    align-self: flex-start;
    padding: 12px 16px;
    border-radius: 16px;
    background: var(--chat-soft);
}

.mwd-chat__typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chat-primary);
    animation: mwd-chat-bounce 1.2s infinite ease-in-out;
}

.mwd-chat__typing span:nth-child(2) {
    animation-delay: 0.15s;
}

.mwd-chat__typing span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes mwd-chat-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.45;
    }

    30% {
        transform: translateY(-5px);
        opacity: 1;
    }
}

/* ---------------------------------------------- بطاقة "اختر موضوعك" */

.mwd-chat__card {
    padding: 14px 12px;
    border: 1px solid var(--chat-border);
    border-radius: var(--chat-radius);
}

.mwd-chat__card-title {
    margin-bottom: 10px;
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    color: #3d3d3d;
}

.mwd-chat__grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.mwd-chat__chip,
.mwd-chat__option {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--chat-border);
    border-radius: 12px;
    background: #fff;
    color: var(--chat-text);
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    text-align: start;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.mwd-chat__chip i,
.mwd-chat__option i {
    color: var(--chat-primary);
    font-size: 15px;
    flex: 0 0 auto;
}

.mwd-chat__chip:hover,
.mwd-chat__chip:focus-visible,
.mwd-chat__option:hover,
.mwd-chat__option:focus-visible {
    background: var(--chat-primary);
    border-color: var(--chat-primary);
    color: #fff;
}

.mwd-chat__chip:hover i,
.mwd-chat__chip:focus-visible i,
.mwd-chat__option:hover i,
.mwd-chat__option:focus-visible i {
    color: #fff;
}

.mwd-chat__options {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.mwd-chat__option {
    justify-content: center;
    text-align: center;
    padding: 9px 4px;
}

/* ------------------------------------------------------ قوائم الروابط */

.mwd-chat__list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mwd-chat__row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--chat-border);
    border-radius: 12px;
    background: #fff;
    color: var(--chat-text);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    text-align: start;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.mwd-chat__row > i:first-child {
    color: var(--chat-primary);
    flex: 0 0 auto;
}

.mwd-chat__row:hover,
.mwd-chat__row:focus-visible {
    background: var(--chat-soft);
    border-color: var(--chat-primary);
    color: var(--chat-text);
}

.mwd-chat__row-label {
    flex: 1 1 auto;
}

.mwd-chat__row-chevron {
    color: var(--chat-primary);
    font-size: 12px;
    flex: 0 0 auto;
}

html[dir="ltr"] .mwd-chat__row-chevron {
    transform: scaleX(-1);
}

/* --------------------------------------------------------- زر الإجراء */

.mwd-chat__cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 16px;
    border: 1px solid var(--chat-primary);
    border-radius: 12px;
    background: var(--chat-primary);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.mwd-chat__cta:hover,
.mwd-chat__cta:focus-visible {
    background: var(--chat-primary-dark);
    border-color: var(--chat-primary-dark);
    color: #fff;
}

.mwd-chat__cta--ghost {
    background: #fff;
    color: var(--chat-primary);
}

.mwd-chat__cta--ghost:hover,
.mwd-chat__cta--ghost:focus-visible {
    background: var(--chat-soft);
    color: var(--chat-primary-dark);
}

.mwd-chat__back {
    align-self: center;
    padding: 6px 14px;
    border: 1px dashed var(--chat-border);
    border-radius: 999px;
    background: transparent;
    color: var(--chat-muted);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
}

.mwd-chat__back:hover,
.mwd-chat__back:focus-visible {
    color: var(--chat-primary);
    border-color: var(--chat-primary);
}

/* ---------------------------------------------- تفاصيل العضوية والصور */

.mwd-chat__details {
    padding: 14px;
    border: 1px solid var(--chat-border);
    border-radius: var(--chat-radius);
    background: #fff;
    font-size: 13px;
}

.mwd-chat__details-title {
    font-weight: 700;
    color: var(--chat-primary);
    margin-bottom: 4px;
}

.mwd-chat__details-summary {
    color: var(--chat-muted);
    margin-bottom: 10px;
}

.mwd-chat__details-groups {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.mwd-chat__details-group-title {
    font-weight: 700;
    margin-bottom: 4px;
    color: #3d3d3d;
}

.mwd-chat__details-item {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: 12px;
    margin-bottom: 3px;
}

.mwd-chat__details-check {
    color: #4caf7d;
    font-size: 11px;
    margin-top: 5px;
    flex: 0 0 auto;
}

.mwd-chat__details-note {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed var(--chat-border);
    font-weight: 700;
    color: var(--chat-primary);
}

.mwd-chat__image {
    text-align: center;
}

.mwd-chat__image img {
    max-width: 190px;
    width: 100%;
    border: 1px solid var(--chat-border);
    border-radius: 12px;
    padding: 8px;
    background: #fff;
}

/* ------------------------------------------------ حقل الكتابة والتذييل */

.mwd-chat__composer {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 6px 14px 0;
    padding: 6px 6px 6px 14px;
    border: 1px solid var(--chat-border);
    border-radius: 999px;
    flex: 0 0 auto;
}

html[dir="ltr"] .mwd-chat__composer {
    padding: 6px 14px 6px 6px;
    flex-direction: row-reverse;
}

.mwd-chat__composer.is-busy {
    opacity: 0.6;
    pointer-events: none;
}

.mwd-chat__input {
    flex: 1 1 auto;
    min-width: 0;
    border: none;
    background: transparent;
    font-size: 13px;
    font-family: inherit;
    color: var(--chat-text);
    outline: none;
}

.mwd-chat__input::placeholder {
    color: #c0b4ae;
}

.mwd-chat__send {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--chat-soft);
    color: var(--chat-primary);
    font-size: 15px;
    cursor: pointer;
    flex: 0 0 auto;
    transition: background-color 0.2s ease, color 0.2s ease;
}

html[dir="rtl"] .mwd-chat__send i {
    display: inline-block;
    transform: scaleX(-1);
}

.mwd-chat__send:hover,
.mwd-chat__send:focus-visible {
    background: var(--chat-primary);
    color: #fff;
}

.mwd-chat__footer {
    margin: 8px 0 12px;
    text-align: center;
    font-size: 12px;
    color: var(--chat-muted);
    flex: 0 0 auto;
}

.mwd-chat__footer i {
    color: var(--chat-primary);
}

/* ------------------------------------------------------------ الجوال */

@media (max-width: 575.98px) {
    .mwd-chat {
        bottom: 18px;
    }

    html[dir="rtl"] .mwd-chat {
        right: 16px;
    }

    html[dir="ltr"] .mwd-chat {
        left: 16px;
    }

    .mwd-chat__launcher-text {
        display: none;
    }

    .mwd-chat__launcher,
    html[dir="ltr"] .mwd-chat__launcher {
        padding: 6px;
    }

    .mwd-chat__panel {
        width: calc(100vw - 32px);
        max-height: 72vh;
    }

    .mwd-chat__options {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
