/* ==========================================================================
   shams-chat.css — دردشة المتجر (شمس AI): واجهة الزائر + صندوق الأدمن
   Store chat (Shams AI): storefront widget + admin inbox — RTL, WhatsApp-like.
   بديل واتساب/n8n بالكامل. | Full replacement for WhatsApp/n8n.
   ========================================================================== */

:root {
    --sc-green: #128c7e;        /* أخضر واتساب الداكن | WhatsApp teal */
    --sc-green-2: #25d366;      /* أخضر فاتح | light green */
    --sc-bg: #efeae2;           /* خلفية المحادثة | chat background */
    --sc-in: #ffffff;           /* فقاعة واردة | inbound bubble */
    --sc-out: #d9fdd3;          /* فقاعة صادرة | outbound bubble */
    --sc-ink: #111b21;
    --sc-muted: #667781;
}

/* ============ زر الإطلاق العائم | floating launcher ============ */
.sc-launcher {
    position: fixed; inset-inline-end: 18px; inset-block-end: 18px; z-index: 1080;
    width: 60px; height: 60px; border-radius: 50%;
    background: linear-gradient(135deg, var(--sc-green-2), var(--sc-green));
    color: #fff; border: none; box-shadow: 0 6px 18px rgba(0,0,0,.25);
    display: flex; align-items: center; justify-content: center; cursor: pointer;
    font-size: 1.7rem; transition: transform .15s ease;
}
.sc-launcher:hover { transform: scale(1.06); }
.sc-launcher .sc-badge {
    position: absolute; top: -4px; inset-inline-start: -4px;
    background: #ef4444; color: #fff; font-size: .7rem; font-weight: 700;
    min-width: 20px; height: 20px; border-radius: 10px;
    display: none; align-items: center; justify-content: center; padding: 0 5px;
}

/* على الموبايل: نرفع الزر فوق الشريط السفلي | lift above mobile tabbar */
@media (max-width: 991.98px) {
    .sc-launcher { inset-block-end: 84px; }
}

/* ============ نافذة الدردشة | chat panel ============ */
.sc-panel {
    position: fixed; inset-inline-end: 18px; inset-block-end: 88px; z-index: 1085;
    width: 370px; max-width: calc(100vw - 24px);
    height: 560px; max-height: calc(100vh - 120px);
    background: #fff; border-radius: 16px; overflow: hidden;
    box-shadow: 0 12px 40px rgba(0,0,0,.28);
    display: none; flex-direction: column;
    font-family: inherit;
}
.sc-panel.open { display: flex; }

@media (max-width: 480px) {
    .sc-panel {
        /* نثبّت الحواف ونستخدم ارتفاعاً يتتبّع المساحة المرئية فعلياً (مع/بدون لوحة المفاتيح)
           anchor edges and use a height that tracks the real visible area (with/without keyboard) */
        inset: 0;
        width: auto;
        height: 100vh;                    /* احتياطي قديم | old fallback */
        height: 100dvh;                   /* الحديثة | modern dynamic viewport height */
        height: -webkit-fill-available;   /* iOS Safari: يتتبّع الشريط ولوحة المفاتيح ويعالج العرض بعد إخفائها */
        max-width: none;
        border-radius: 0;
    }

    /* واجهة أصغر وأخفّ على الجوال | smaller, lighter UI on phones */
    .sc-head { padding: 9px 12px; padding-top: max(9px, env(safe-area-inset-top)); }
    .sc-head .sc-avatar { width: 34px; height: 34px; font-size: 1.1rem; }
    .sc-head .sc-title { font-size: .95rem; }
    .sc-head .sc-sub   { font-size: .68rem; }

    .sc-body { padding: 10px; gap: 6px; }
    .sc-bubble { max-width: 82%; font-size: .88rem; padding: 7px 10px; }

    .sc-foot { padding: 7px 8px; padding-bottom: max(7px, env(safe-area-inset-bottom)); }
    .sc-foot textarea { font-size: .9rem; padding: 8px 12px; }
    .sc-foot .sc-btn { width: 38px; height: 38px; font-size: 1.05rem; }
}

.sc-head {
    background: var(--sc-green); color: #fff;
    padding: 12px 14px; display: flex; align-items: center; gap: 10px;
    flex: 0 0 auto;                 /* لا يتقلّص الرأس | header never shrinks */
}
.sc-head .sc-avatar {
    width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,.2);
    display: flex; align-items: center; justify-content: center; font-size: 1.3rem;
}
.sc-head .sc-title { font-weight: 700; line-height: 1.1; }
.sc-head .sc-sub { font-size: .72rem; opacity: .85; }
.sc-head .sc-close {
    margin-inline-start: auto; background: transparent; border: none; color: #fff;
    font-size: 1.3rem; cursor: pointer; opacity: .9;
}

/* ============ جسم المحادثة | messages body ============ */
.sc-body {
    flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 14px;
    background-color: var(--sc-bg);
    background-image: radial-gradient(rgba(0,0,0,.035) 1px, transparent 1px);
    background-size: 18px 18px;
    display: flex; flex-direction: column; gap: 8px;
}

.sc-row { display: flex; }
.sc-row.in  { justify-content: flex-start; }
.sc-row.out { justify-content: flex-end; }

.sc-bubble {
    max-width: 78%; padding: 8px 11px; border-radius: 12px;
    font-size: .92rem; line-height: 1.5; color: var(--sc-ink);
    box-shadow: 0 1px 1px rgba(0,0,0,.08); word-wrap: break-word; white-space: pre-wrap;
    position: relative;
}
.sc-row.in  .sc-bubble { background: var(--sc-in);  border-top-right-radius: 3px; }
.sc-row.out .sc-bubble { background: var(--sc-out); border-top-left-radius: 3px; }
.sc-bubble .sc-meta {
    display: block; font-size: .66rem; color: var(--sc-muted);
    margin-top: 3px; text-align: end;
}
.sc-link, .wa-chat-body .sc-link { color: #0b57d0; text-decoration: underline; word-break: break-all; }
.sc-bubble.audio audio { width: 210px; max-width: 60vw; display: block; }
.sc-bubble.image img { max-width: 210px; border-radius: 8px; display: block; }
.sc-bubble .sc-sender-tag {
    font-size: .64rem; font-weight: 700; color: var(--sc-green);
    display: block; margin-bottom: 2px;
}

/* مؤشّر الكتابة | typing indicator */
.sc-typing { display: flex; gap: 4px; align-items: center; padding: 6px 4px; }
.sc-typing span {
    width: 7px; height: 7px; border-radius: 50%; background: #9aa5ab;
    animation: sc-blink 1.2s infinite both;
}
.sc-typing span:nth-child(2) { animation-delay: .2s; }
.sc-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes sc-blink { 0%,80%,100%{opacity:.25} 40%{opacity:1} }

/* ============ شريط الإدخال | composer ============ */
.sc-foot {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 10px; background: #f0f2f5; border-top: 1px solid #e3e6ea;
    flex: 0 0 auto;                 /* لا يتقلّص شريط الإدخال | composer never shrinks */
}
.sc-foot textarea {
    flex: 1; resize: none; border: none; outline: none; border-radius: 20px;
    padding: 9px 14px; font-size: .92rem; max-height: 90px; line-height: 1.4;
    background: #fff;
}
.sc-foot .sc-btn {
    width: 42px; height: 42px; border-radius: 50%; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center; font-size: 1.15rem;
    background: var(--sc-green); color: #fff; flex: 0 0 auto;
}
.sc-foot .sc-btn.mic { background: #fff; color: var(--sc-green); border: 1px solid #d5dbdf; }
.sc-foot .sc-btn.mic.recording { background: #ef4444; color: #fff; border-color: #ef4444; animation: sc-pulse 1s infinite; }
@keyframes sc-pulse { 0%,100%{box-shadow:0 0 0 0 rgba(239,68,68,.5)} 50%{box-shadow:0 0 0 6px rgba(239,68,68,0)} }

.sc-rechint {
    font-size: .74rem; color: #ef4444; padding: 0 12px 6px; display: none;
    background: #f0f2f5;
}
.sc-rechint.show { display: block; }

/* ==========================================================================
   أزرار «اسأل الذكاء الاصطناعي» (بديل زر واتساب) على البطاقات وصفحة المنتج
   "Ask AI" buttons (replacing the WhatsApp button) on cards & product page
   ========================================================================== */
.card-ic.js-ai-ask { color: var(--sc-green); }
.pd-ai { color: var(--sc-green); border-color: #bfe3dd; }
.pd-ask .pd-ask-cap { color: var(--sc-green); }

/* ==========================================================================
   صندوق الأدمن (واتساب ويب) | Admin inbox (WhatsApp-Web style)
   ========================================================================== */
.wa-inbox {
    display: flex; height: calc(100vh - 150px); min-height: 460px;
    border: 1px solid #e3e6ea; border-radius: 12px; overflow: hidden; background: #fff;
}

/* قائمة المحادثات | conversations list */
.wa-list { width: 320px; border-inline-end: 1px solid #e9edef; display: flex; flex-direction: column; background: #fff; }
.wa-list .wa-search { padding: 10px; border-bottom: 1px solid #f0f2f5; }
.wa-list .wa-search input { width: 100%; border: 1px solid #e3e6ea; border-radius: 20px; padding: 8px 14px; font-size: .88rem; }
.wa-convs { overflow-y: auto; flex: 1; }
.wa-conv {
    display: flex; align-items: center; gap: 10px; padding: 11px 12px;
    cursor: pointer; border-bottom: 1px solid #f4f6f7;
}
.wa-conv:hover { background: #f5f6f6; }
.wa-conv.active { background: #e9f3f1; }
.wa-conv .wa-ava {
    width: 44px; height: 44px; border-radius: 50%; background: var(--sc-green);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; flex: 0 0 auto;
}
.wa-conv .wa-info { flex: 1; min-width: 0; }
.wa-conv .wa-name { font-weight: 700; font-size: .9rem; display: flex; justify-content: space-between; gap: 6px; }
.wa-conv .wa-name .wa-time { font-weight: 400; font-size: .68rem; color: var(--sc-muted); flex: 0 0 auto; }
.wa-conv .wa-prev { font-size: .8rem; color: var(--sc-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-conv .wa-badge {
    background: var(--sc-green-2); color: #fff; font-size: .7rem; font-weight: 700;
    min-width: 20px; height: 20px; border-radius: 10px; padding: 0 6px;
    display: inline-flex; align-items: center; justify-content: center; margin-inline-start: 6px;
}

/* لوحة المحادثة | conversation panel */
.wa-chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.wa-chat-head {
    padding: 11px 14px; background: #f0f2f5; border-bottom: 1px solid #e9edef;
    display: flex; align-items: center; gap: 10px;
}
.wa-chat-head .wa-ava { width: 38px; height: 38px; }
.wa-chat-body {
    flex: 1; overflow-y: auto; padding: 16px;
    background-color: var(--sc-bg);
    background-image: radial-gradient(rgba(0,0,0,.035) 1px, transparent 1px);
    background-size: 18px 18px;
    display: flex; flex-direction: column; gap: 8px;
}
.wa-empty { margin: auto; color: var(--sc-muted); text-align: center; }
.wa-chat-foot { display: flex; gap: 8px; padding: 10px; background: #f0f2f5; border-top: 1px solid #e9edef; }
.wa-chat-foot input {
    flex: 1; border: 1px solid #e3e6ea; border-radius: 20px; padding: 9px 14px; font-size: .92rem;
}
.wa-chat-foot button {
    width: 42px; height: 42px; border-radius: 50%; border: none; background: var(--sc-green);
    color: #fff; font-size: 1.1rem; cursor: pointer;
}

/* نعيد استخدام فقاعات الزائر داخل الأدمن | reuse bubbles inside admin */
.wa-chat-body .sc-row { display: flex; }
.wa-chat-body .sc-row.in  { justify-content: flex-start; }
.wa-chat-body .sc-row.out { justify-content: flex-end; }
.wa-chat-body .sc-bubble { max-width: 66%; padding: 8px 11px; border-radius: 12px; font-size: .92rem; line-height: 1.5; box-shadow: 0 1px 1px rgba(0,0,0,.08); white-space: pre-wrap; }
.wa-chat-body .sc-row.in  .sc-bubble { background: var(--sc-in); }
.wa-chat-body .sc-row.out .sc-bubble { background: var(--sc-out); }
.wa-chat-body .sc-bubble .sc-meta { display:block; font-size:.66rem; color:var(--sc-muted); margin-top:3px; text-align:end; }
.wa-chat-body .sc-bubble .sc-sender-tag { font-size:.64rem; font-weight:700; display:block; margin-bottom:2px; }
.wa-chat-body .sc-bubble .sc-sender-tag.ai    { color: var(--sc-green); }
.wa-chat-body .sc-bubble .sc-sender-tag.admin { color: #7c3aed; }
.wa-chat-body .sc-bubble.audio audio { width: 240px; max-width: 50vw; }
.wa-chat-body .sc-bubble.image img { max-width: 240px; border-radius: 8px; }

@media (max-width: 767.98px) {
    .wa-inbox { flex-direction: column; height: auto; }
    .wa-list { width: 100%; max-height: 40vh; border-inline-end: none; border-bottom: 1px solid #e9edef; }
    .wa-chat { min-height: 55vh; }
}
