/* CodeCaps Chatbot */
.cb-root {
    --cb-green: #01e16b;
    --cb-green-dark: #008541;
    --cb-navy: #021d3c;
    --cb-bg: var(--color-bg-primary, #ffffff);
    --cb-surface: var(--color-bg-secondary, #f1f5f9);
    --cb-border: var(--color-border, rgba(2, 29, 60, 0.1));
    --cb-text: var(--color-text-primary, #021d3c);
    --cb-text-2: var(--color-text-secondary, #3a4f67);
    --cb-muted: var(--color-text-muted, #627386);
    --cb-bot-bubble: #ffffff;
    --cb-user-bubble: #d1fae4;
    --cb-gap: 2rem;
    --cb-vh: 100dvh;
    font-family: inherit;
    line-height: 1.6;
}
body.theme-dark .cb-root, [data-theme="dark"] .cb-root {
    --cb-bot-bubble: #1b3450;
    --cb-user-bubble: #006532;
}

.cb-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* زر الفتح: فوق زر واتساب العائم وفي نفس الجهة */
.cb-launcher {
    position: fixed;
    bottom: calc(var(--cb-gap) + 56px + 12px);
    inset-inline-start: var(--cb-gap);
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 50%;
    background: var(--cb-navy);   /* حالة «Active» في الهوية: أيقونة خضراء على كحلي */
    color: var(--cb-green);
    box-shadow: 0 6px 16px rgba(2, 29, 60, 0.22);
    padding: 0;
    cursor: pointer;
    z-index: 290;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s ease;
}
.cb-launcher:hover { transform: translateY(-2px); }
.cb-launcher:focus-visible, .cb-root button:focus-visible, .cb-root a:focus-visible, .cb-root input:focus-visible {
    outline: 3px solid var(--cb-green);
    outline-offset: 2px;
}
body.cb-open .cb-launcher, body.nav-open .cb-launcher { display: none; }

/* النافذة */
.cb-panel {
    position: fixed;
    bottom: var(--cb-gap);
    inset-inline-start: var(--cb-gap);
    width: 380px;
    max-width: calc(100vw - 2 * var(--cb-gap));
    height: min(640px, calc(var(--cb-vh) - var(--cb-gap) - 90px));
    display: flex;
    flex-direction: column;
    background: var(--cb-bg);
    color: var(--cb-text);
    border: 1px solid var(--cb-border);
    border-radius: 20px;
    box-shadow: 0 24px 60px rgba(2, 29, 60, 0.25);
    overflow: hidden;
    z-index: 300;
    animation: cbIn .22s ease-out;
}
.cb-panel[hidden] { display: none; }
@keyframes cbIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.cb-head {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .8rem .9rem;
    background: var(--cb-navy);
    color: #fff;
    flex-shrink: 0;
}
.cb-avatar { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: var(--cb-green); border-radius: 50%; background: rgba(1, 225, 107, .12); }
.cb-head-text { flex: 1; min-width: 0; }
.cb-head-text h2 { margin: 0; font-size: 1.02rem; font-weight: 600; color: #fff; line-height: 1.3; }
.cb-head-text p { margin: 0; font-size: .78rem; color: #bdc4cc; display: flex; align-items: center; gap: .35rem; }
.cb-head-text p::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--cb-green); flex-shrink: 0; box-shadow: -8px 0 0 var(--cb-green), -16px 0 0 var(--cb-green); margin-inline-end: 16px; } /* ثلاث نقاط (Dot rhythm) */
.cb-icon-btn {
    width: 38px; height: 38px; border-radius: 8px; border: 0;
    background: rgba(255, 255, 255, .08); color: #fff; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.cb-icon-btn:hover { background: rgba(255, 255, 255, .16); }

/* المحادثة */
.cb-log {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1rem .9rem .5rem;
    background: var(--cb-surface);
    display: flex;
    flex-direction: column;
    gap: .55rem;
    scroll-behavior: smooth;
}
.cb-msg {
    max-width: 86%;
    padding: .6rem .85rem;
    border-radius: 16px;
    font-size: .92rem;
    white-space: pre-line;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    box-shadow: 0 1px 2px rgba(2, 29, 60, .06);
}
.cb-msg.bot { align-self: flex-start; background: var(--cb-bot-bubble); color: var(--cb-text); border-start-start-radius: 4px; border: 1px solid var(--cb-border); }
.cb-msg.user { align-self: flex-end; background: var(--cb-user-bubble); color: var(--cb-text); border-end-end-radius: 4px; } /* الذيل لأسفل يسار كما في الهوية */
.cb-msg.notice { background: #fff7e6; border-color: #f5d9a3; color: #6b4a07; }
body.theme-dark .cb-msg.notice { background: #3a2d0e; color: #f5d9a3; border-color: #5a4614; }

.cb-options { display: flex; flex-direction: column; gap: .4rem; align-self: stretch; margin: .1rem 0 .25rem; }
.cb-options.grid { display: grid; grid-template-columns: 1fr 1fr; }
.cb-opt {
    text-align: start;
    font-family: inherit;
    font-size: .88rem;
    font-weight: 600;
    line-height: 1.45;
    padding: .6rem .8rem;
    border-radius: 16px;
    border: 1px solid var(--cb-border);
    background: var(--cb-bg);
    color: var(--cb-text);
    cursor: pointer;
    transition: border-color .15s, background-color .15s;
}
.cb-opt:hover { border-color: var(--cb-green); background: rgba(1, 225, 107, .07); }
.cb-opt.secondary { font-weight: 600; color: var(--cb-text-2); background: transparent; }
.cb-options.used .cb-opt { opacity: .55; pointer-events: none; }
.cb-options.used .cb-opt.chosen { opacity: 1; border-color: var(--cb-green); }

.cb-contacts { display: flex; flex-wrap: wrap; gap: .4rem; align-self: stretch; }
.cb-contact {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .45rem .8rem; border-radius: 999px;
    font-size: .84rem; font-weight: 600; text-decoration: none;
    border: 1px solid var(--cb-border); background: var(--cb-bg); color: var(--cb-text);
}
.cb-contact:hover { border-color: var(--cb-green); }
.cb-contact.whatsapp { background: #25d366; border-color: #25d366; color: #fff; }

.cb-typing { align-self: flex-start; display: inline-flex; gap: 4px; padding: .75rem .9rem; border-radius: 16px; background: var(--cb-bot-bubble); border: 1px solid var(--cb-border); }
.cb-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--cb-muted); animation: cbDot 1s infinite ease-in-out; }
.cb-typing span:nth-child(2) { animation-delay: .15s; }
.cb-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes cbDot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* أسفل النافذة */
.cb-bar { padding: .45rem .9rem 0; background: var(--cb-bg); border-top: 1px solid var(--cb-border); flex-shrink: 0; }
.cb-home-btn {
    display: inline-flex; align-items: center; gap: .35rem;
    font-family: inherit; font-size: .8rem; font-weight: 600;
    color: var(--cb-text-2); background: transparent; border: 0; padding: .25rem .1rem; cursor: pointer;
}
.cb-home-btn:hover { color: var(--cb-green-dark); }
.cb-form { display: flex; gap: .5rem; padding: .5rem .9rem .35rem; background: var(--cb-bg); flex-shrink: 0; }
.cb-form input {
    flex: 1; min-width: 0;
    font-family: inherit; font-size: 16px; /* 16px يمنع تكبير الصفحة في iPhone */
    padding: .65rem .95rem;
    border-radius: 999px;
    border: 1px solid var(--cb-border);
    background: var(--cb-surface);
    color: var(--cb-text);
}
.cb-form input:focus { outline: none; border-color: var(--cb-green); box-shadow: 0 0 0 3px rgba(1, 225, 107, .18); }
.cb-send {
    width: 44px; height: 44px; border-radius: 50%; border: 0; flex-shrink: 0;
    background: var(--cb-green); color: var(--cb-navy); cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
}
.cb-send:hover { background: var(--cb-green-dark); color: #fff; }
.cb-send:disabled { opacity: .5; cursor: default; }
[dir="rtl"] .cb-send svg { transform: scaleX(-1); }
.cb-foot { margin: 0; padding: 0 .9rem .6rem; font-size: .7rem; color: var(--cb-muted); text-align: center; background: var(--cb-bg); flex-shrink: 0; }

/* الموبايل: النافذة تملأ الشاشة وتتكيف مع لوحة المفاتيح */
@media (max-width: 576px) {
    .cb-root { --cb-gap: 1rem; }
    .cb-launcher { width: 52px; height: 52px; bottom: calc(2rem + 56px + 10px); inset-inline-start: calc(2rem + 2px); }
    .cb-panel {
        inset: 0;
        top: var(--cb-top, 0px);
        bottom: auto;
        width: 100%;
        max-width: none;
        height: var(--cb-vh);
        border-radius: 0;
        border: 0;
    }
    body.cb-open { overflow: hidden; }
    body.cb-open .whatsapp-floating-bubble, body.cb-open .scroll-top-trigger { display: none; }
    .cb-options.grid { grid-template-columns: 1fr; }
    .cb-msg { max-width: 90%; }
}

@media (prefers-reduced-motion: reduce) {
    .cb-panel, .cb-typing span { animation: none; }
    .cb-launcher, .cb-launcher:hover { transition: none; transform: none; }
    .cb-log { scroll-behavior: auto; }
}

@media print { .cb-root { display: none; } }

/* أيقونات الهوية: زر الفتح (فقاعة + النقاط الثلاث) وأزرار النافذة */
.cb-root .cc-icon { display: block; width: 20px; height: 20px; }
.cb-root .cb-avatar .cc-icon { width: 26px; height: 26px; }
.cb-root .cb-launcher .cc-icon { width: 30px; height: 30px; }
.cb-root .cb-home-btn .cc-icon { width: 16px; height: 16px; }
[data-theme="dark"] .cb-launcher, body.theme-dark .cb-launcher { background: #1b3450; }

/* زر الفتح: النقاط الثلاث تتحرك بالتتابع 120ms (اتصال: «جاهزين نرد عليك») — مرتين بعد التحميل، وعند المرور */
@media (prefers-reduced-motion: no-preference) {
    .cb-launcher .cc-icon circle { transform-box: fill-box; transform-origin: center; animation: cbHop 1.1s cubic-bezier(.2, .8, .2, 1) 3s 2 both; }
    .cb-launcher .cc-icon circle:nth-of-type(2) { animation-delay: 3.12s; }
    .cb-launcher .cc-icon circle:nth-of-type(3) { animation-delay: 3.24s; }
    .cb-launcher:hover .cc-icon circle { animation: cbHopHover .9s cubic-bezier(.2, .8, .2, 1) infinite; }
    .cb-launcher:hover .cc-icon circle:nth-of-type(2) { animation-delay: .12s; }
    .cb-launcher:hover .cc-icon circle:nth-of-type(3) { animation-delay: .24s; }
}
@keyframes cbHop { 0%, 50%, 100% { transform: none; opacity: 1; } 25% { transform: translateY(-2px); opacity: .45; } }
@keyframes cbHopHover { 0%, 50%, 100% { transform: none; opacity: 1; } 25% { transform: translateY(-2px); opacity: .45; } }
