/* CodeCaps Chatbot */
.cb-root {
    --cb-green: #01e16b;
    --cb-green-dark: #00a84f;
    --cb-navy: #021d3c;
    --cb-bg: var(--color-bg-primary, #ffffff);
    --cb-surface: var(--color-bg-secondary, #f4f7fa);
    --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, #3b4f66);
    --cb-muted: var(--color-text-muted, #72849a);
    --cb-bot-bubble: #ffffff;
    --cb-user-bubble: #d9fbe8;
    --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: #0b2d55;
    --cb-user-bubble: #0f4a3a;
}

.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: calc(var(--cb-gap) - 4px);
    width: 64px;
    height: 64px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    padding: 0;
    cursor: pointer;
    z-index: 290;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s ease;
}
/* الأيقونة كما هي بدون خلفية، مع ظل خفيف حول شكلها فقط */
.cb-launcher img { width: 64px; height: 64px; display: block; filter: drop-shadow(0 6px 12px rgba(2, 29, 60, 0.28)); }
.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; }
.cb-avatar img { width: 44px; height: 44px; display: block; }
.cb-head-text { flex: 1; min-width: 0; }
.cb-head-text h2 { margin: 0; font-size: 1.02rem; font-weight: 800; color: #fff; line-height: 1.3; font-family: 'Plus Jakarta Sans', inherit; }
.cb-head-text p { margin: 0; font-size: .78rem; color: #a9c0da; display: flex; align-items: center; gap: .35rem; }
.cb-head-text p::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--cb-green); flex-shrink: 0; }
.cb-icon-btn {
    width: 38px; height: 38px; border-radius: 10px; 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-start-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: 700;
    line-height: 1.45;
    padding: .6rem .8rem;
    border-radius: 12px;
    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: 700; 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: 700;
    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: 58px; height: 58px; bottom: calc(2rem + 56px + 10px); inset-inline-start: calc(2rem - 1px); }
    .cb-launcher img { width: 58px; height: 58px; }
    .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; } }
