/* ============================================================
   نافذة الدردشة الذكية — toorela-ai
   ألوان العلامة: البرتقالي #F26B1D، الكحلي #0D1B3E
   ============================================================ */

#toorela-ai-modal, #toorela-ai-modal * { -webkit-tap-highlight-color: transparent; }
#toorela-ai-modal button, #toorela-ai-modal a, #toorela-ai-chat-toggle {
    touch-action: manipulation;
}

/* إلغاء المظهر الافتراضي للزر (خلفية/حدود/حشوة المتصفح) — العنصر
   أصلاً كان <a> ولا يحتاج هذا، لكن <button> يحتاجه صراحة وإلا
   ظهر كصندوق أبيض عادي بدل الدائرة البرتقالية المصمّمة أصلاً
   بواسطة كلاس nav-map-fab في القالب */
#toorela-ai-chat-toggle {
    background: transparent !important; border: none !important;
    padding: 0; margin: 0; font: inherit; color: inherit;
    -webkit-appearance: none; appearance: none; cursor: pointer;
    display: flex !important; flex-direction: column; align-items: center; gap: 3px;
}

/* لا نعتمد على تنسيق nav-map-fab القادم من القالب وحده (قد يختلف
   حسب حالة القالب) — نفرض هنا شكل الدائرة البارزة صراحةً لضمان
   نفس النتيجة دائمًا: دائرة برتقالية مرتفعة بظل وحدّ أبيض واضح */
#toorela-ai-chat-toggle .nav-map-fab {
    width: 52px !important; height: 52px !important;
    background: #F26B1D !important;
    border-radius: 50% !important;
    border: 3px solid #0D1B3E !important;
    box-shadow: 0 6px 16px rgba(242,107,29,.5) !important;
    display: flex !important; align-items: center; justify-content: center;
    margin-top: -26px;
}
#toorela-ai-chat-toggle .nav-map-fab svg {
    width: 22px !important; height: 22px !important;
    fill: #fff !important; stroke: none !important;
}
#toorela-ai-chat-toggle span {
    font-size: 10px !important; color: #F26B1D !important; font-weight: 600;
}

#toorela-ai-overlay {
    position: fixed; inset: 0; background: rgba(13,27,62,.45);
    z-index: 99998; opacity: 0; pointer-events: none;
    transition: opacity .2s ease;
}
#toorela-ai-overlay.open { opacity: 1; pointer-events: auto; }

#toorela-ai-modal {
    position: fixed; left: 0; right: 0; bottom: 0;
    max-width: 480px; margin: 0 auto;
    height: 82vh; height: 82dvh; max-height: 680px;
    background: #fff; border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 30px rgba(0,0,0,.2);
    z-index: 99999; display: flex; flex-direction: column;
    transform: translateY(100%); transition: transform .28s cubic-bezier(.32,.72,0,1);
    direction: inherit; font-family: inherit;
    overscroll-behavior: contain;
}
#toorela-ai-modal.open { transform: translateY(0); }

/* يمنع التمرير الخلفي للصفحة وراء النافذة عند فتحها — بلا هذا،
   تمرير الإصبع داخل الدردشة على الموبايل قد "يسحب" الصفحة خلفها،
   وهو إحساس مواقع الويب لا التطبيقات الحقيقية */
body.toorela-ai-open { overflow: hidden; position: fixed; left: 0; right: 0; width: 100%; }

#toorela-ai-modal .tai-head {
    background: #0D1B3E; color: #fff; padding: 14px 16px;
    display: flex; align-items: center; gap: 10px;
    border-radius: 18px 18px 0 0; flex-shrink: 0;
}
#toorela-ai-modal .tai-head .tai-icon {
    width: 30px; height: 30px; border-radius: 50%; background: #F26B1D;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
#toorela-ai-modal .tai-head .tai-title { font-weight: 600; font-size: 15px; flex: 1; }
#toorela-ai-modal .tai-close {
    background: rgba(255,255,255,.12); border: none; color: #fff;
    width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
    font-size: 16px; line-height: 1; display: flex; align-items: center; justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

#toorela-ai-modal .tai-body {
    flex: 1; overflow-y: auto; padding: 14px; display: flex;
    flex-direction: column; gap: 12px; background: #f7f8fa;
    -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
    min-height: 0; /* ضروري ليعمل التمرير داخل حاوية flex ذات ارتفاع محدود */
}
/* السبب الجذري لاختفاء البطاقات: عناصر flex التي تحمل overflow
   (مثل صف البطاقات) ينكمش حدها الأدنى تلقائيًا إلى 0، فيضغطها
   المتصفح لخط رفيع بدل أن يتيح التمرير عندما تتراكم الرسائل.
   flex-shrink:0 يمنع هذا نهائيًا: كل عنصر يحتفظ بحجمه الكامل،
   والزيادة تصبح تمريرًا عاديًا. */
#toorela-ai-modal .tai-body > * { flex-shrink: 0; }

@keyframes tai-pop-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.tai-msg, .tai-quick, .tai-cards, .tai-date-strip, .tai-anim-block {
    animation: tai-pop-in .22s ease both;
}
@media (prefers-reduced-motion: reduce) {
    .tai-msg, .tai-quick, .tai-cards, .tai-date-strip, .tai-anim-block { animation: none; }
}

.tai-step-label {
    align-self: center; font-size: 10px; color: #999; background: #fff;
    padding: 3px 11px; border-radius: 10px; border: 1px solid #eee; margin: 2px 0;
}

.tai-field-error { color: #dc3232; font-size: 11px; margin-top: -4px; }
.tai-input-err { border-color: #dc3232 !important; }

.tai-msg { max-width: 82%; font-size: 13px; line-height: 1.7; padding: 9px 13px; border-radius: 14px; }
.tai-msg.user { align-self: flex-end; background: #0D1B3E; color: #fff; border-radius: 14px 14px 2px 14px; }
.tai-msg.bot  { align-self: flex-start; background: #fff; border: 1px solid #eee; border-radius: 14px 14px 14px 2px; }

.tai-quick { display: flex; gap: 8px; flex-wrap: wrap; align-self: flex-start; max-width: 100%; }
.tai-quick button {
    background: #fff; border: 1px solid #0D1B3E; color: #0D1B3E;
    font-size: 12px; padding: 7px 12px; border-radius: 20px; cursor: pointer;
}
.tai-quick button:hover { background: #f5f6f8; }
/* استثناء: زر "تأكيد الحجز" يبقى برتقاليًا — هو الفعل الحاسم فتدفق الحجز */
.tai-quick button.tai-quick-primary {
    background: #F26B1D; border-color: #F26B1D; color: #fff;
}
.tai-quick button.tai-quick-primary:hover { background: #e05f16; }

.tai-cards { display: flex; gap: 10px; overflow-x: auto; align-self: flex-start; max-width: 100%; padding-bottom: 4px; }
.tai-card {
    min-width: 148px; background: #fff; border: 1px solid #eee; border-radius: 12px;
    overflow: hidden; flex-shrink: 0; text-decoration: none; color: inherit;
    display: flex; flex-direction: column;
}
/* الجزء العلوي (صورة + نص) يتمدد ليدفع زر "احجز" لأسفل البطاقة دائمًا،
   فتبقى الأزرار متحاذية بين بطاقات الصف الواحد مهما اختلف محتواها
   (مثلًا بطاقة فيها سطر سعر وأخرى بلا سعر) */
.tai-card > a { flex: 1 1 auto; }
.tai-card img { width: 100%; height: 80px; object-fit: cover; background: #eee; display: block; }
.tai-card .tai-card-body { padding: 8px; }
.tai-card .tai-card-title { font-size: 12px; font-weight: 600; margin: 0 0 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tai-card .tai-card-meta { font-size: 10.5px; color: #888; display: flex; justify-content: space-between; align-items: center; }
.tai-card .tai-card-discount { color: #F26B1D; font-weight: 700; }
.tai-card .tai-card-slot { font-size: 9.5px; font-weight: 700; color: #0D1B3E; background: #eef0f4; display: inline-block; padding: 2px 7px; border-radius: 8px; margin-bottom: 4px; }
.tai-card .tai-card-price { font-size: 10.5px; color: #555; margin-top: 3px; }
.tai-card .tai-card-cta {
    display: block; width: 100%; margin-top: 6px;
    background: #0D1B3E; color: #fff; text-align: center;
    font-size: 11px; padding: 7px; border-radius: 7px;
    border: none; font: inherit; cursor: pointer; -webkit-appearance: none;
}

/* شريط التواريخ الأفقي — نمط تطبيقات الحجز الحديثة (Calendly/Fresha) */
.tai-date-strip {
    align-self: flex-start; max-width: 100%; display: flex; gap: 8px;
    overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch;
}
.tai-date-chip {
    flex-shrink: 0; min-width: 56px; background: #fff; border: 1.5px solid #0D1B3E;
    border-radius: 14px; padding: 8px 6px; cursor: pointer; display: flex;
    flex-direction: column; align-items: center; gap: 1px; color: #0D1B3E;
    font: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.tai-date-chip:active { background: #f5f6f8; }
.tai-date-chip-dow { font-size: 10px; color: #0D1B3E; font-weight: 600; }
.tai-date-chip-num { font-size: 16px; font-weight: 700; }
.tai-date-chip-mon { font-size: 9px; color: #888; }

/* تبويبات فترات الوقت (صباحًا/بعد الظهر/مساءً) */
.tai-period-tabs { display: flex; gap: 6px; align-self: flex-start; }
.tai-period-tab {
    background: #f0f0f0; border: none; border-radius: 16px; padding: 6px 12px;
    font-size: 11.5px; color: #555; cursor: pointer; font: inherit;
    touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.tai-period-tab.active { background: #0D1B3E; color: #fff; font-weight: 600; }

.tai-typing { align-self: flex-start; display: flex; gap: 4px; padding: 10px 14px; }
.tai-typing span { width: 6px; height: 6px; border-radius: 50%; background: #ccc; animation: tai-blink 1.2s infinite; }
.tai-typing span:nth-child(2) { animation-delay: .2s; }
.tai-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes tai-blink { 0%,80%,100%{opacity:.3;} 40%{opacity:1;} }

#toorela-ai-modal .tai-foot {
    display: flex; align-items: center; gap: 8px; padding: 10px 12px;
    border-top: 1px solid #eee; background: #fff; flex-shrink: 0;
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
}
#toorela-ai-modal .tai-input {
    flex: 1; border: 1px solid #ddd; border-radius: 20px; height: 40px;
    padding: 0 14px; font-size: 16px; outline: none;
}
#toorela-ai-modal .tai-input:focus { border-color: #F26B1D; }
#toorela-ai-modal .tai-send {
    width: 38px; height: 38px; border-radius: 50%; background: #F26B1D;
    border: none; color: #fff; cursor: pointer; display: flex;
    align-items: center; justify-content: center; flex-shrink: 0;
}
#toorela-ai-modal .tai-send:disabled { opacity: .5; cursor: default; }

@media (min-width: 481px) {
    #toorela-ai-modal { border-radius: 18px; bottom: 90px; height: 600px; }
}

/* مشغّل سطح المكتب: مخفي على الموبايل (هناك الزر في الشريط السفلي) */
#toorela-ai-launcher {
    display: none; position: fixed; left: 24px; bottom: 24px; z-index: 99997;
    width: 58px; height: 58px; border-radius: 50%; border: 3px solid #0D1B3E;
    background: #F26B1D; cursor: pointer; align-items: center; justify-content: center;
    box-shadow: 0 8px 22px rgba(242,107,29,.45); padding: 0;
    transition: transform .15s ease; -webkit-appearance: none; appearance: none;
}
#toorela-ai-launcher svg { fill: #fff; }
#toorela-ai-launcher:hover { transform: scale(1.06); }
@media (min-width: 769px) {
    #toorela-ai-launcher { display: flex; }
    #toorela-ai-modal { left: 24px; right: auto; margin: 0; width: 400px; bottom: 96px; }
}
