/* ─────────────────────────────────────────────
   AIWC Variables
───────────────────────────────────────────── */

:root {
    --aiwc-primary: #7b68ee;
    --aiwc-primary-dark: #6a57dd;
    --aiwc-white: #ffffff;
    --aiwc-bg: #f5f5f5;
    --aiwc-border: #e5e5e5;
    --aiwc-text: #333333;
    --aiwc-text-light: #888888;
    --aiwc-bot-bg: #ffffff;
    --aiwc-user-bg: var(--aiwc-primary);
    --aiwc-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    --aiwc-radius: 16px;
    --aiwc-radius-sm: 8px;
    --aiwc-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ─────────────────────────────────────────────
   Floating Wrapper
───────────────────────────────────────────── */

.aiwc-floating-wrapper {
    position: fixed;
    z-index: 999999;
    font-family: var(--aiwc-font);
}

/* ─── Position Classes ─── */
.aiwc-pos-top-left      { top: 20px;    left: 20px;  bottom: auto; right: auto; }
.aiwc-pos-top-center    { top: 20px;    left: 50%;   bottom: auto; right: auto; transform: translateX(-50%); }
.aiwc-pos-top-right     { top: 20px;    right: 20px; bottom: auto; left: auto; }
.aiwc-pos-middle-left   { top: 50%;     left: 20px;  bottom: auto; right: auto; transform: translateY(-50%); }
.aiwc-pos-middle-center { top: 50%;     left: 50%;   bottom: auto; right: auto; transform: translate(-50%, -50%); }
.aiwc-pos-middle-right  { top: 50%;     right: 20px; bottom: auto; left: auto;  transform: translateY(-50%); }
.aiwc-pos-bottom-left   { bottom: 20px; left: 20px;  top: auto;    right: auto; }
.aiwc-pos-bottom-center { bottom: 20px; left: 50%;   top: auto;    right: auto; transform: translateX(-50%); }
.aiwc-pos-bottom-right  { bottom: 20px; right: 20px; top: auto;    left: auto; }

/* ─── Chat Window Direction based on Position ─── */
.aiwc-pos-top-left .aiwc-chat-window,
.aiwc-pos-middle-left .aiwc-chat-window     { left: 0; right: auto; top: 72px; bottom: auto; }
.aiwc-pos-bottom-left .aiwc-chat-window     { left: 0; right: auto; bottom: 72px; top: auto; }

.aiwc-pos-top-right .aiwc-chat-window,
.aiwc-pos-middle-right .aiwc-chat-window    { right: 0; left: auto; top: 72px; bottom: auto; }
.aiwc-pos-bottom-right .aiwc-chat-window    { right: 0; left: auto; bottom: 72px; top: auto; }

.aiwc-pos-top-center .aiwc-chat-window,
.aiwc-pos-middle-center .aiwc-chat-window   { left: 50%; transform: translateX(-50%); top: 72px; bottom: auto; right: auto; }
.aiwc-pos-bottom-center .aiwc-chat-window   { left: 50%; transform: translateX(-50%); bottom: 72px; top: auto; right: auto; }

/* ─── Greeting Popup Direction based on Position ─── */
.aiwc-pos-top-left .aiwc-greeting-popup,
.aiwc-pos-middle-left .aiwc-greeting-popup,
.aiwc-pos-bottom-left .aiwc-greeting-popup  { left: 0; right: auto; }

.aiwc-pos-top-right .aiwc-greeting-popup,
.aiwc-pos-middle-right .aiwc-greeting-popup,
.aiwc-pos-bottom-right .aiwc-greeting-popup { right: 0; left: auto; }

.aiwc-pos-top-center .aiwc-greeting-popup,
.aiwc-pos-middle-center .aiwc-greeting-popup,
.aiwc-pos-bottom-center .aiwc-greeting-popup { left: 50%; transform: translateX(-50%); right: auto; }

/* ─────────────────────────────────────────────
   Bubble Button
───────────────────────────────────────────── */

.aiwc-bubble-btn {
    width: 60px;
    height: 60px;
    border-radius: 50% !important;
    overflow: hidden;
    background: var(--aiwc-primary) !important;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--aiwc-white);
    box-shadow: 0 4px 16px rgba(123, 104, 238, 0.4) !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
    outline: none;
    padding: 0 !important;
}

.aiwc-bubble-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

.aiwc-bubble-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(123, 104, 238, 0.5);
}

.aiwc-bubble-btn:active {
    transform: scale(0.95);
}

.aiwc-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ff4757;
    color: white;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
}

/* ─────────────────────────────────────────────
   Chat Window
───────────────────────────────────────────── */

.aiwc-chat-window {
    position: absolute;
    width: var(--aiwc-widget-width, 360px);
    height: var(--aiwc-widget-height, 520px);
    background: var(--aiwc-white);
    border-radius: var(--aiwc-radius);
    box-shadow: var(--aiwc-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: aiwcSlideUp 0.3s ease;
}

@keyframes aiwcSlideUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ─────────────────────────────────────────────
   Chat Header
───────────────────────────────────────────── */

.aiwc-chat-header {
    background: var(--aiwc-color-header, var(--aiwc-primary));
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--aiwc-color-header-text, var(--aiwc-white));
}

.aiwc-chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.aiwc-chat-avatar {
    width: 40px;
    height: 40px;
    background: none !important;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
    overflow: hidden;
    border-radius: 50%;
}

.aiwc-chat-avatar img {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

.aiwc-chat-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--aiwc-color-header-text, white);
}

.aiwc-chat-status {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.85);
    display: flex;
    align-items: center;
    gap: 4px;
}

.aiwc-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #2ecc71;
    display: inline-block;
    animation: aiwcPulse 2s infinite;
}

@keyframes aiwcPulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.5; }
}

.aiwc-chat-close {
    background: transparent;
    border: none;
    cursor: pointer;
    color: white;
    display: flex;
    align-items: center;
    padding: 4px !important;
    border-radius: 50% !important;
    transition: background 0.2s;
    outline: none;
}

.aiwc-chat-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ─────────────────────────────────────────────
   Chat Messages
───────────────────────────────────────────── */

.aiwc-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--aiwc-bg);
    scroll-behavior: smooth;
}

.aiwc-chat-messages::-webkit-scrollbar { width: 4px; }
.aiwc-chat-messages::-webkit-scrollbar-track { background: transparent; }
.aiwc-chat-messages::-webkit-scrollbar-thumb { background: var(--aiwc-border); border-radius: 4px; }

/* ─────────────────────────────────────────────
   Messages
───────────────────────────────────────────── */

.aiwc-message {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 85%;
    min-width: 0;
}

.aiwc-message-bot  { align-self: flex-start; }
.aiwc-message-user { align-self: flex-end; flex-direction: row-reverse; }

.aiwc-message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--aiwc-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
    overflow: hidden;
}

.aiwc-message-avatar img {
    width: 28px;
    height: 28px;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

.aiwc-message-content {
    background: var(--aiwc-color-agent-msg, var(--aiwc-bot-bg));
    border-radius: 16px 16px 16px 4px;
    padding: 10px 14px;
    color: var(--aiwc-color-agent-text, var(--aiwc-text));
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    word-break: break-word;
    overflow-wrap: break-word;
    min-width: 0;
}

.aiwc-message-content a {
    word-break: break-all;
    overflow-wrap: break-word;
    display: inline-block;
    max-width: 100%;
}

.aiwc-message-user .aiwc-message-content {
    background: var(--aiwc-color-visitor-msg, var(--aiwc-primary));
    border-radius: 16px 16px 4px 16px;
    color: var(--aiwc-color-visitor-text, white);
}

.aiwc-message-content p {
    margin: 0 0 4px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--aiwc-text);
}

.aiwc-message-user .aiwc-message-content p { color: white; }

.aiwc-message-time {
    font-size: 10px;
    color: var(--aiwc-text-light);
    display: block;
}

.aiwc-message-user .aiwc-message-time { color: rgba(255,255,255,0.7); }

/* ─────────────────────────────────────────────
   Quick Action Buttons
───────────────────────────────────────────── */

.aiwc-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 0;
}

.aiwc-quick-btn {
    background: var(--aiwc-white) !important;
    border: 1.5px solid var(--aiwc-primary) !important;
    color: var(--aiwc-primary) !important;
    padding: 6px 12px !important;
    border-radius: 20px !important;
    font-size: 12px !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    outline: none !important;
    letter-spacing: 0 !important;
}

.aiwc-quick-btn:hover {
    background: var(--aiwc-primary) !important;
    color: white !important;
    transform: translateY(-1px);
}

/* ─────────────────────────────────────────────
   Typing Indicator
───────────────────────────────────────────── */

.aiwc-typing-indicator {
    padding: 0 16px 8px;
    background: var(--aiwc-bg);
}

.aiwc-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px !important;
}

.aiwc-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--aiwc-text-light);
    display: inline-block;
    animation: aiwcTyping 1.2s infinite;
}

.aiwc-typing span:nth-child(2) { animation-delay: 0.2s; }
.aiwc-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes aiwcTyping {
    0%, 100% { transform: translateY(0); opacity: 0.4; }
    50%       { transform: translateY(-4px); opacity: 1; }
}

/* ─────────────────────────────────────────────
   Input Area
───────────────────────────────────────────── */

.aiwc-chat-input-area {
    padding: 12px 16px;
    background: var(--aiwc-white);
    border-top: 1px solid var(--aiwc-border);
}

.aiwc-chat-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--aiwc-bg);
    border-radius: 15px;
    padding: 8px 8px 8px 16px;
    border: 1.5px solid var(--aiwc-border);
    transition: border-color 0.2s;
}

.aiwc-chat-input-wrapper:focus-within { border-color: var(--aiwc-primary); }

.aiwc-chat-input {
    flex: 1;
    border: none;
    background: transparent !important;
    resize: none;
    outline: none;
    font-size: 14px !important;
    color: var(--aiwc-text) !important;
    font-family: var(--aiwc-font) !important;
    line-height: 1.5;
    max-height: 100px !important;
    overflow-y: auto;
    height: auto !important;
    min-height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
}

.aiwc-chat-input::placeholder { color: var(--aiwc-text-light); }

.aiwc-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50% !important;
    background: var(--aiwc-primary) !important;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.2s;
    outline: none;
    padding: 0 !important;
}

.aiwc-send-btn:hover {
    background: var(--aiwc-primary-dark) !important;
    transform: scale(1.05);
}

.aiwc-send-btn:disabled {
    background: var(--aiwc-border) !important;
    cursor: not-allowed;
    transform: none;
}

.aiwc-chat-footer-text {
    text-align: center;
    font-size: 10px;
    color: var(--aiwc-text-light);
    margin-top: 6px;
}

/* ─────────────────────────────────────────────
   Greeting Popup
───────────────────────────────────────────── */

.aiwc-greeting-popup {
    position: absolute;
    bottom: 72px;
    display: flex;
    align-items: center;
    gap: 10px;
    background: white;
    border-radius: 12px;
    padding: 12px 14px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    animation: aiwcSlideUp 0.4s ease;
    cursor: pointer;
    width: 280px;
}

.aiwc-greeting-avatar {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.aiwc-greeting-avatar img {
    width: 40px !important;
    height: 40px !important;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--aiwc-primary);
}

.aiwc-greeting-content p {
    margin: 0;
    font-size: 13px;
    color: var(--aiwc-text);
    line-height: 1.4;
}

.aiwc-greeting-close {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 25px;
    height: 25px;
    border-radius: 50% !important;
    background: #ff4757;
    border: none;
    color: white;
    font-size: 16px !important;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1 !important;
    padding: 0 !important;
}

/* ─────────────────────────────────────────────
   Full Page Chatbot
───────────────────────────────────────────── */

.aiwc-fullpage-wrapper {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    height: 600px;
    background: var(--aiwc-white);
    border-radius: var(--aiwc-radius);
    box-shadow: var(--aiwc-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: var(--aiwc-font);
}

.aiwc-fullpage-header {
    background: var(--aiwc-primary);
    padding: 16px 20px;
    color: white;
}

.aiwc-fullpage-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--aiwc-bg);
    scroll-behavior: smooth;
}

.aiwc-fullpage-messages::-webkit-scrollbar { width: 4px; }
.aiwc-fullpage-messages::-webkit-scrollbar-thumb { background: var(--aiwc-border); border-radius: 4px; }

.aiwc-fullpage-input-area {
    padding: 16px 20px;
    background: var(--aiwc-white);
    border-top: 1px solid var(--aiwc-border);
}

.aiwc-fullpage-typing {
    padding: 0 20px 8px;
    background: var(--aiwc-bg);
}

/* ─────────────────────────────────────────────
   Responsive
───────────────────────────────────────────── */

@media ( max-width: 480px ) {

    .aiwc-chat-window {
        width: calc(100vw - 32px);
        height: 70vh;
    }

    .aiwc-pos-bottom-right .aiwc-chat-window,
    .aiwc-pos-bottom-left .aiwc-chat-window,
    .aiwc-pos-bottom-center .aiwc-chat-window {
        bottom: 72px;
        left: 0;
        right: 0;
        margin: 0 auto;
        transform: none;
    }

    .aiwc-floating-wrapper {
        bottom: 16px !important;
        top: auto !important;
    }

    .aiwc-fullpage-wrapper {
        height: 100vh;
        border-radius: 0;
    }

}
/* ─────────────────────────────────────────────
   Dynamic Position — Top-anchored overrides
   (JS sets these via applyPosition, CSS as fallback)
───────────────────────────────────────────── */

/* Top-position wrappers: greeting appears below the icon */
.aiwc-pos-top-left .aiwc-greeting-popup,
.aiwc-pos-top-center .aiwc-greeting-popup,
.aiwc-pos-top-right .aiwc-greeting-popup {
    bottom: auto;
    top: 72px;
}

/* Middle-position wrappers */
.aiwc-pos-middle-left .aiwc-greeting-popup,
.aiwc-pos-middle-center .aiwc-greeting-popup,
.aiwc-pos-middle-right .aiwc-greeting-popup {
    bottom: 72px;
    top: auto;
}

/* Bottom-position wrappers (default) */
.aiwc-pos-bottom-left .aiwc-greeting-popup,
.aiwc-pos-bottom-center .aiwc-greeting-popup,
.aiwc-pos-bottom-right .aiwc-greeting-popup {
    bottom: 72px;
    top: auto;
}

/* ── Mobile: allow top positions too ── */
@media ( max-width: 480px ) {

    /* Reset the forced bottom for top-positioned wrappers */
    .aiwc-pos-top-left.aiwc-floating-wrapper,
    .aiwc-pos-top-right.aiwc-floating-wrapper {
        bottom: auto !important;
        top: 16px !important;
    }

    .aiwc-pos-top-left .aiwc-chat-window,
    .aiwc-pos-top-right .aiwc-chat-window {
        top: 72px;
        bottom: auto;
        left: 0;
        right: 0;
        margin: 0 auto;
    }

    .aiwc-pos-top-left .aiwc-greeting-popup,
    .aiwc-pos-top-right .aiwc-greeting-popup {
        bottom: auto;
        top: 72px;
    }
}