/* =============================================================
   CodecIT Chatbot — Frontend Widget Styles
   ============================================================= */

/* ── CSS Variables (overridden inline by PHP) ──────────────── */
:root {
    --ccbot-primary: #147A96;
    --ccbot-primary-dk: #0e5f76;
    --ccbot-white: #ffffff;
    --ccbot-bg: #f4f7f9;
    --ccbot-bubble-bot: #eef4f7;
    --ccbot-bubble-user: var(--ccbot-primary);
    --ccbot-text-dark: #1a2d3d;
    --ccbot-text-mid: #5a7080;
    --ccbot-border: rgba(0, 0, 0, .08);
    --ccbot-shadow: 0 12px 48px rgba(14, 56, 76, .18);
    --ccbot-radius: 20px;
    --ccbot-panel-w: 370px;
    --ccbot-panel-h: 530px;
    --ccbot-z: 2147483640;
    --ccbot-font: 'Poppins', 'Inter', system-ui, sans-serif;
    --ccbot-transition: 0.3s cubic-bezier(.4, 0, .2, 1);
}

/* ── Required font (fallback only; theme already loads Poppins) */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap');

/* ── Widget wrapper ────────────────────────────────────────── */
#ccbot-wrap {
    position: fixed;
    z-index: var(--ccbot-z);
    font-family: var(--ccbot-font);
}

#ccbot-wrap.ccbot-pos-bottom-right {
    bottom: 12px !important;
    /* Stack above WhatsApp button (bottom:96px + 60px height + 10px gap) */
    right: 30px !important;
    /* Match WhatsApp .float right alignment */
}

#ccbot-wrap.ccbot-pos-bottom-left {
    bottom: 25px !important;
    left: 25px !important;
}

/* ── Trigger button ────────────────────────────────────────── */
.ccbot-trigger {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--ccbot-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 24px rgba(20, 122, 150, .40);
    transition: transform var(--ccbot-transition), box-shadow var(--ccbot-transition), background var(--ccbot-transition);
    position: relative;
    outline: none;
    z-index: 2147483647 !important;
    pointer-events: auto !important;
}

.ccbot-trigger:hover {
    background: var(--ccbot-primary-dk);
    transform: scale(1.08);
    box-shadow: 0 10px 32px rgba(20, 122, 150, .50);
}

.ccbot-trigger:focus-visible {
    outline: 3px solid var(--ccbot-primary);
    outline-offset: 3px;
}

.ccbot-trigger svg {
    width: 28px;
    height: 28px;
    color: #fff;
    transition: opacity var(--ccbot-transition), transform var(--ccbot-transition);
}

.ccbot-icon-chat {
    position: absolute;
    opacity: 1;
    transform: scale(1) rotate(0);
}

.ccbot-icon-close {
    position: absolute;
    opacity: 0;
    transform: scale(.5) rotate(-90deg);
}

/* When open */
#ccbot-wrap.ccbot-open .ccbot-icon-chat {
    opacity: 0;
    transform: scale(.5) rotate(90deg);
}

#ccbot-wrap.ccbot-open .ccbot-icon-close {
    opacity: 1;
    transform: scale(1) rotate(0);
}

/* Ping indicator */
.ccbot-ping {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    background: #25d366;
    border-radius: 50%;
    border: 2px solid #fff;
    animation: ccbot-ping 2s ease-in-out infinite;
}

@keyframes ccbot-ping {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.3);
        opacity: .7;
    }
}

/* Hide ping once opened */
#ccbot-wrap.ccbot-open .ccbot-ping {
    display: none;
}

/* ── Panel ──────────────────────────────────────────────────── */
.ccbot-panel {
    position: absolute;
    bottom: 76px;
    width: var(--ccbot-panel-w);
    max-height: var(--ccbot-panel-h);
    background: var(--ccbot-white);
    border-radius: var(--ccbot-radius);
    box-shadow: var(--ccbot-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    /* Hidden by default */
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px) scale(.97);
    transition: opacity var(--ccbot-transition), visibility var(--ccbot-transition), transform var(--ccbot-transition);
    pointer-events: none;
}

.ccbot-pos-bottom-right .ccbot-panel {
    right: 0;
}

.ccbot-pos-bottom-left .ccbot-panel {
    left: 0;
}

#ccbot-wrap.ccbot-open .ccbot-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ── Header ─────────────────────────────────────────────────── */
.ccbot-header {
    background: linear-gradient(135deg, var(--ccbot-primary) 0%, var(--ccbot-primary-dk) 100%);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.ccbot-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .2);
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 2px solid rgba(255, 255, 255, .35);
    overflow: hidden;
}

.ccbot-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ccbot-header-info {
    flex: 1;
}

.ccbot-header-info strong {
    display: block;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
}

.ccbot-status {
    font-size: 11.5px;
    color: rgba(255, 255, 255, .8);
    display: flex;
    align-items: center;
    gap: 5px;
}

.ccbot-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    animation: ccbot-dot-pulse 2s infinite;
}

@keyframes ccbot-dot-pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: .5;
    }
}

.ccbot-close-btn {
    background: rgba(255, 255, 255, .15);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: rgba(255, 255, 255, .9);
    transition: background var(--ccbot-transition);
}

.ccbot-close-btn:hover {
    background: rgba(255, 255, 255, .3);
}

/* ── Messages area ─────────────────────────────────────────── */
.ccbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    background: var(--ccbot-bg);
}

.ccbot-messages::-webkit-scrollbar {
    width: 4px;
}

.ccbot-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, .15);
    border-radius: 4px;
}

/* Bot message */
.ccbot-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: ccbot-msg-in var(--ccbot-transition) both;
}

@keyframes ccbot-msg-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ccbot-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--ccbot-primary);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.ccbot-msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ccbot-msg-bubble {
    max-width: 82%;
    padding: 11px 14px;
    border-radius: 18px 18px 18px 4px;
    font-size: 14px;
    line-height: 1.55;
    color: var(--ccbot-text-dark);
    background: var(--ccbot-bubble-bot);
    border: 1px solid rgba(0, 0, 0, .06);
}

/* User message */
.ccbot-msg.ccbot-msg-user {
    flex-direction: row-reverse;
}

.ccbot-msg.ccbot-msg-user .ccbot-msg-bubble {
    background: var(--ccbot-bubble-user);
    color: #fff;
    border: none;
    border-radius: 18px 18px 4px 18px;
}

/* Typing indicator */
.ccbot-typing .ccbot-msg-bubble {
    padding: 14px 18px;
}

.ccbot-typing-dots {
    display: flex;
    gap: 5px;
    align-items: center;
    height: 14px;
}

.ccbot-typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ccbot-primary);
    opacity: .5;
    animation: ccbot-dot-bounce .9s ease-in-out infinite;
}

.ccbot-typing-dots span:nth-child(2) {
    animation-delay: .18s;
}

.ccbot-typing-dots span:nth-child(3) {
    animation-delay: .36s;
}

@keyframes ccbot-dot-bounce {

    0%,
    100% {
        transform: translateY(0);
        opacity: .4;
    }

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

/* ── Options area ──────────────────────────────────────────── */
.ccbot-options {
    padding: 10px 14px 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex-shrink: 0;
    background: var(--ccbot-bg);
    border-top: 1px solid var(--ccbot-border);
    min-height: 0;
    transition: min-height var(--ccbot-transition);
}

.ccbot-opt-btn {
    background: var(--ccbot-white);
    border: 1.5px solid var(--ccbot-primary);
    color: var(--ccbot-primary);
    border-radius: 100px;
    padding: 8px 16px;
    font-family: var(--ccbot-font);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--ccbot-transition), color var(--ccbot-transition), transform .15s;
    white-space: nowrap;
    line-height: 1.3;
}

.ccbot-opt-btn:hover {
    background: var(--ccbot-primary);
    color: #fff;
    transform: translateY(-1px);
}

.ccbot-opt-btn:active {
    transform: translateY(0);
}

/* WhatsApp CTA Button */
.ccbot-whatsapp-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    background: #25d366;
    color: #fff;
    border: none;
    border-radius: 100px;
    padding: 13px 22px;
    font-family: var(--ccbot-font);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--ccbot-transition), transform .15s, box-shadow .15s;
    box-shadow: 0 4px 16px rgba(37, 211, 102, .35);
    animation: ccbot-msg-in .4s both;
}

.ccbot-whatsapp-btn:hover {
    background: #1db653;
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(37, 211, 102, .4);
}

.ccbot-whatsapp-btn svg {
    width: 20px;
    height: 20px;
    fill: #fff;
    flex-shrink: 0;
}

.ccbot-options-cta {
    padding: 12px 14px 14px;
    width: 100%;
    flex-direction: column;
    gap: 10px;
}

/* ── Footer ─────────────────────────────────────────────────── */
.ccbot-footer {
    text-align: center;
    padding: 6px 16px 10px;
    font-size: 11px;
    color: var(--ccbot-text-mid);
    background: var(--ccbot-bg);
    border-top: 1px solid var(--ccbot-border);
    flex-shrink: 0;
}

.ccbot-footer strong {
    color: var(--ccbot-primary);
}

/* ── Restart button ─────────────────────────────────────────── */
.ccbot-restart-btn {
    background: none;
    border: 1.5px solid rgba(0, 0, 0, .15);
    color: var(--ccbot-text-mid);
    border-radius: 100px;
    padding: 7px 14px;
    font-family: var(--ccbot-font);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--ccbot-transition);
    display: flex;
    align-items: center;
    gap: 6px;
}

.ccbot-restart-btn:hover {
    border-color: var(--ccbot-primary);
    color: var(--ccbot-primary);
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 480px) {
    :root {
        --ccbot-panel-w: calc(100vw - 32px);
    }

    #ccbot-wrap.ccbot-pos-bottom-right {
        right: 16px !important;
        bottom: 12px !important;
    }

    #ccbot-wrap.ccbot-pos-bottom-left {
        left: 16px !important;
        bottom: 250px !important;
    }

    /* Fix panel clipping on mobile — use fixed positioning anchored to viewport */
    .ccbot-panel {
        position: fixed !important;
        bottom: 82px !important;
        /* 60px trigger + 12px bottom + 10px gap */
        right: 16px !important;
        left: 16px !important;
        width: auto !important;
        max-width: calc(100vw - 32px) !important;
        max-height: 75vh;
        border-radius: 16px;
    }

    .ccbot-pos-bottom-right .ccbot-panel {
        right: 16px;
        left: auto;
    }
}