/* ============================================================
   Chatbot Widget — Self-contained styles
   Independent of Tailwind/Bootstrap — works on any site
   ============================================================ */

/* Chat Bubble (FAB) */
.cw-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #1a56db;
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,.25);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    transition: transform .2s, box-shadow .2s;
    font-size: 0;
    line-height: 1;
}
.cw-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0,0,0,.3);
}
.cw-bubble svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
}
.cw-bubble-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    border: 2px solid #fff;
}
.cw-bubble-badge:empty,
.cw-bubble-badge[data-count="0"] {
    display: none;
}

/* Chat Panel */
.cw-panel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 370px;
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
    display: none;
    flex-direction: column;
    z-index: 99998;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: #1f2937;
}
.cw-panel.cw-open {
    display: flex;
}

/* Header */
.cw-header {
    background: #1a56db;
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.cw-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}
.cw-header-avatar {
    width: 36px;
    height: 36px;
    background: rgba(255,255,255,.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.cw-header-avatar svg {
    width: 20px;
    height: 20px;
    fill: #fff;
}
.cw-header-title {
    font-weight: 600;
    font-size: 15px;
}
.cw-header-status {
    font-size: 12px;
    opacity: .85;
}
.cw-close-btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    opacity: .8;
    transition: opacity .15s;
    font-size: 0;
}
.cw-close-btn:hover {
    opacity: 1;
}
.cw-close-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* Messages Area */
.cw-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f9fafb;
    scroll-behavior: smooth;
}

/* Message Bubbles */
.cw-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    word-wrap: break-word;
    white-space: pre-line;
    animation: cwFadeIn .25s ease;
}
@keyframes cwFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.cw-msg-bot,
.cw-msg-agent {
    align-self: flex-start;
    background: #e5e7eb;
    color: #1f2937;
    border-bottom-left-radius: 4px;
}
.cw-msg-agent {
    background: #dbeafe;
}
.cw-msg-visitor {
    align-self: flex-end;
    background: #1a56db;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.cw-msg-system {
    align-self: center;
    background: transparent;
    color: #6b7280;
    font-size: 12px;
    font-style: italic;
    text-align: center;
    padding: 4px 8px;
    max-width: 100%;
}

.cw-msg-time {
    font-size: 10px;
    opacity: .6;
    margin-top: 4px;
    display: block;
}

/* Options (Bot Choice Buttons) */
.cw-options {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}
.cw-option-btn {
    background: #fff;
    color: #1a56db;
    border: 1.5px solid #1a56db;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, color .15s;
    text-align: left;
    font-family: inherit;
    line-height: 1.3;
}
.cw-option-btn:hover {
    background: #1a56db;
    color: #fff;
}
.cw-option-btn:disabled {
    opacity: .5;
    cursor: default;
    pointer-events: none;
}

/* Input Area */
.cw-input-area {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
    gap: 8px;
    flex-shrink: 0;
}
.cw-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color .15s;
    color: #1f2937;
    background: #fff;
}
.cw-input:focus {
    border-color: #1a56db;
}
.cw-input::placeholder {
    color: #9ca3af;
}
.cw-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #1a56db;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
    flex-shrink: 0;
    font-size: 0;
}
.cw-send-btn:hover {
    background: #1e40af;
}
.cw-send-btn:disabled {
    background: #9ca3af;
    cursor: default;
}
.cw-send-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* Typing Indicator */
.cw-typing {
    display: none;
    align-self: flex-start;
    padding: 10px 14px;
    background: #e5e7eb;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}
.cw-typing.cw-show {
    display: flex;
    gap: 4px;
    align-items: center;
}
.cw-typing-dot {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: cwBounce 1.4s infinite ease-in-out both;
}
.cw-typing-dot:nth-child(2) { animation-delay: .16s; }
.cw-typing-dot:nth-child(3) { animation-delay: .32s; }
@keyframes cwBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Powered by line */
.cw-powered {
    text-align: center;
    font-size: 10px;
    color: #9ca3af;
    padding: 4px 0 8px;
    background: #fff;
}

/* New Chat Button (after chat is closed) */
.cw-new-chat-btn {
    width: 100%;
    padding: 12px 16px;
    background: linear-gradient(135deg, #1a56db 0%, #1e40af 100%);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: transform .15s, box-shadow .15s;
}
.cw-new-chat-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(26, 86, 219, 0.4);
}
.cw-new-chat-btn:active {
    transform: translateY(0);
}

/* Mobile responsive */
@media (max-width: 480px) {
    .cw-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
    .cw-bubble {
        bottom: 16px;
        right: 16px;
    }
}
