/* =========================================================
   VB DYNAMICS AI CHAT — CLINTON CONSULTANT STYLING
   Palette: deep signal navy (#0b1220) + electric cyan (#0dcaf0)
   accented with royal blue (#2e6bff) and WhatsApp green (#25D366).
   ========================================================= */

.vb-ai-chat {
    --vb-ai-primary: #0dcaf0;
    --vb-ai-primary-2: #2e6bff;
    --vb-ai-ink: #0b1220;
    --vb-ai-ink-soft: #16213a;
    --vb-ai-canvas: #f4f6f9;
    --vb-ai-surface: #ffffff;
    --vb-ai-border: rgba(11, 18, 32, 0.08);
    --vb-ai-text: #1c2333;
    --vb-ai-text-muted: #6b7280;
    --vb-ai-wa-green: #25D366;
    --vb-ai-wa-green-hover: #1ebe5d;
    --vb-ai-radius-lg: 20px;
    --vb-ai-radius-md: 14px;
    --vb-ai-shadow: 0 24px 60px -12px rgba(11, 18, 32, 0.28),
                     0 8px 24px -8px rgba(11, 18, 32, 0.16);

    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.vb-ai-chat * {
    box-sizing: border-box;
}

/* =========================================================
   CHAT BUTTON (FLOATING TOGGLE)
   ========================================================= */

.vb-ai-chat-toggle {
    width: 60px;
    height: 60px;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(155deg, var(--vb-ai-primary) 0%, var(--vb-ai-primary-2) 115%);
    color: var(--vb-ai-ink);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 12px 28px -6px rgba(46, 107, 255, 0.45);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
    position: relative;
}

.vb-ai-chat-toggle:hover {
    transform: translateY(-3px) scale(1.03);
    box-shadow: 0 16px 34px -6px rgba(46, 107, 255, 0.55);
}

.vb-ai-chat-toggle:focus-visible {
    outline: 2px solid var(--vb-ai-ink);
    outline-offset: 3px;
}

.vb-ai-chat-toggle svg {
    width: 26px;
    height: 26px;
    position: absolute;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.vb-ai-chat-toggle .vb-ai-icon-close {
    width: 22px;
    height: 22px;
    opacity: 0;
    transform: rotate(-45deg) scale(0.6);
}

.vb-ai-chat-toggle[aria-expanded="true"] .vb-ai-icon-chat {
    opacity: 0;
    transform: rotate(45deg) scale(0.6);
}

.vb-ai-chat-toggle[aria-expanded="true"] .vb-ai-icon-close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* Unread Notification Badge */
.vb-ai-chat-notification {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    background: #ff4757;
    border: 2px solid #fff;
    border-radius: 999px;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* =========================================================
   CHAT WINDOW
   ========================================================= */

.vb-ai-chat-window {
    position: absolute;
    right: 0;
    bottom: 76px;

    width: 390px;
    max-width: calc(100vw - 32px);
    height: 590px;
    max-height: calc(100dvh - 110px);

    background: var(--vb-ai-surface);
    border-radius: var(--vb-ai-radius-lg);
    overflow: hidden;

    box-shadow: var(--vb-ai-shadow);
    border: 1px solid rgba(255, 255, 255, 0.2);

    display: flex;
    flex-direction: column;

    opacity: 0;
    visibility: hidden;
    transform: translateY(18px) scale(0.96);
    transform-origin: bottom right;

    transition:
        opacity 0.24s ease,
        transform 0.28s cubic-bezier(0.22, 1, 0.36, 1),
        visibility 0.24s ease;
}

.vb-ai-chat-window.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* =========================================================
   HEADER
   ========================================================= */

.vb-ai-chat-header {
    position: relative;
    background: linear-gradient(135deg, var(--vb-ai-ink) 0%, var(--vb-ai-ink-soft) 100%);
    color: #fff;
    padding: 16px 16px 14px;

    display: flex;
    align-items: center;
    justify-content: space-between;
}

.vb-ai-chat-header::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--vb-ai-primary), var(--vb-ai-primary-2));
}

.vb-ai-chat-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.vb-ai-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #0b1220;
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--vb-ai-primary);

    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    padding: 6px;

    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.05em;
}

.vb-ai-chat-avatar .vb-ai-brand-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.vb-ai-chat-title {
    font-size: 14.5px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.vb-ai-chat-status {
    margin-top: 3px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.65);

    display: flex;
    align-items: center;
    gap: 6px;
}

.vb-ai-chat-status-dot {
    width: 7px;
    height: 7px;
    background: #2ed573;
    border-radius: 50%;
    box-shadow: 0 0 0 3px rgba(46, 213, 115, 0.22);
}

.vb-ai-chat-close {
    width: 32px;
    height: 32px;
    border: 0;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    cursor: pointer;
    border-radius: 8px;
    flex-shrink: 0;

    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, transform 0.15s ease;
}

.vb-ai-chat-close:hover {
    background: rgba(255, 255, 255, 0.18);
    transform: scale(1.05);
}

.vb-ai-chat-close:focus-visible {
    outline: 2px solid var(--vb-ai-primary);
    outline-offset: 2px;
}

.vb-ai-chat-close svg {
    width: 17px;
    height: 17px;
}

/* =========================================================
   MESSAGES AREA
   ========================================================= */

.vb-ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--vb-ai-canvas);
    display: flex;
    flex-direction: column;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
}

.vb-ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.vb-ai-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(11, 18, 32, 0.15);
    border-radius: 8px;
}

.vb-ai-message-row {
    display: flex;
    flex-direction: column;
    margin: 6px 0;
    max-width: 88%;
    animation: vbAiMessageIn 0.22s ease both;
}

.vb-ai-message-row.user {
    align-self: flex-end;
    align-items: flex-end;
}

.vb-ai-message-row.bot {
    align-self: flex-start;
    align-items: flex-start;
}

@keyframes vbAiMessageIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.vb-ai-message {
    font-size: 14px;
    line-height: 1.55;
    padding: 11px 14px;
    border-radius: var(--vb-ai-radius-md);
    word-break: break-word;
}

.vb-ai-message.bot {
    background: var(--vb-ai-surface);
    color: var(--vb-ai-text);
    border: 1px solid var(--vb-ai-border);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 6px rgba(11, 18, 32, 0.04);
}

.vb-ai-message.user {
    background: linear-gradient(135deg, var(--vb-ai-primary), var(--vb-ai-primary-2) 130%);
    color: #fff;
    font-weight: 500;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(46, 107, 255, 0.22);
}

.vb-ai-message a {
    color: var(--vb-ai-primary-2);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.vb-ai-message.user a {
    color: #fff;
}

.vb-ai-bullet {
    margin: 3px 0;
    padding-left: 2px;
}

.vb-ai-message-time {
    font-size: 10.5px;
    color: var(--vb-ai-text-muted);
    margin-top: 4px;
    padding: 0 4px;
}

/* =========================================================
   ACTION CARD (WHATSAPP HANDOFF & ESCALATION)
   ========================================================= */

.vb-ai-action-card {
    margin-top: 10px;
    padding: 12px;
    background: #f8fafc;
    border: 1.5px solid rgba(37, 211, 102, 0.25);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.vb-ai-action-head {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--vb-ai-ink);
}

.vb-ai-action-badge {
    background: rgba(37, 211, 102, 0.15);
    color: #1a8a43;
    font-size: 9.5px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.vb-ai-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none !important;
    transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
    cursor: pointer;
}

.vb-ai-wa-btn {
    background: var(--vb-ai-wa-green);
    color: #fff !important;
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.25);
}

.vb-ai-wa-btn:hover {
    background: var(--vb-ai-wa-green-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(37, 211, 102, 0.35);
}

.vb-ai-action-sub {
    font-size: 11px;
    color: var(--vb-ai-text-muted);
    line-height: 1.4;
}

.vb-ai-action-sub a {
    color: var(--vb-ai-text);
    text-decoration: underline;
    font-weight: 500;
}

/* =========================================================
   QUICK QUESTIONS
   ========================================================= */

.vb-ai-quick {
    padding: 0 14px 12px;
    background: var(--vb-ai-canvas);
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.vb-ai-quick button {
    border: 1px solid rgba(11, 18, 32, 0.12);
    background: var(--vb-ai-surface);
    color: var(--vb-ai-ink);
    border-radius: 999px;
    padding: 6px 11px;
    font-size: 11.5px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.vb-ai-quick button:hover {
    background: var(--vb-ai-ink);
    border-color: var(--vb-ai-ink);
    color: #fff;
    transform: translateY(-1px);
}

.vb-ai-quick button:focus-visible {
    outline: 2px solid var(--vb-ai-primary-2);
    outline-offset: 2px;
}

/* =========================================================
   TYPING INDICATOR
   ========================================================= */

.vb-ai-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 12px;
}

.vb-ai-typing span {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: vbAiTyping 1.2s infinite ease-in-out;
}

.vb-ai-typing span:nth-child(2) {
    animation-delay: 0.15s;
}

.vb-ai-typing span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes vbAiTyping {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* =========================================================
   INPUT AREA
   ========================================================= */

.vb-ai-chat-input-area {
    padding: 10px 12px 8px;
    background: var(--vb-ai-surface);
    border-top: 1px solid var(--vb-ai-border);
}

.vb-ai-chat-form {
    display: flex;
    align-items: center;
    gap: 8px;
}

.vb-ai-chat-input {
    flex: 1;
    min-width: 0;
    border: 1px solid rgba(11, 18, 32, 0.14);
    border-radius: 999px;
    background: var(--vb-ai-canvas);
    padding: 10px 14px;
    font-family: inherit;
    font-size: 13.5px;
    color: var(--vb-ai-text);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.vb-ai-chat-input::placeholder {
    color: var(--vb-ai-text-muted);
}

.vb-ai-chat-input:focus {
    background: var(--vb-ai-surface);
    border-color: var(--vb-ai-primary-2);
    box-shadow: 0 0 0 3px rgba(46, 107, 255, 0.12);
}

.vb-ai-chat-send {
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(155deg, var(--vb-ai-primary), var(--vb-ai-primary-2) 130%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.vb-ai-chat-send:hover:not(:disabled) {
    transform: scale(1.06);
}

.vb-ai-chat-send:focus-visible {
    outline: 2px solid var(--vb-ai-ink);
    outline-offset: 2px;
}

.vb-ai-chat-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.vb-ai-chat-send svg {
    width: 16px;
    height: 16px;
}

.vb-ai-privacy-note {
    font-size: 10px;
    color: var(--vb-ai-text-muted);
    text-align: center;
    margin-top: 6px;
    line-height: 1.3;
}

.vb-ai-privacy-note a {
    color: var(--vb-ai-text);
    text-decoration: underline;
    font-weight: 500;
}

/* =========================================================
   REDUCED MOTION
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
    .vb-ai-chat-window,
    .vb-ai-chat-toggle,
    .vb-ai-chat-toggle svg,
    .vb-ai-message-row,
    .vb-ai-typing span {
        animation: none !important;
        transition: none !important;
    }
}

/* =========================================================
   RESPONSIVE MOBILE VIEW (KEYBOARD AWARE)
   ========================================================= */

@media (max-width: 576px) {
    .vb-ai-chat {
        right: 14px;
        bottom: 14px;
    }

    .vb-ai-chat-window {
        right: 0;
        bottom: 68px;
        width: calc(100vw - 28px);
        height: min(580px, calc(100dvh - 84px));
        max-height: calc(100dvh - 84px);
        border-radius: 16px;
    }

    .vb-ai-chat-toggle {
        width: 54px;
        height: 54px;
    }
}

/* Compact mobile floating chat: never take over the entire screen. */
@media (max-width: 576px) {
  .vb-ai-chat-window {
    width: min(350px, calc(100vw - 28px));
    height: min(430px, 65dvh);
    max-height: calc(100dvh - 110px);
    bottom: 68px;
    right: 0;
    border-radius: 18px;
  }
  .vb-ai-chat-header { padding: 11px 12px; }
  .vb-ai-chat-avatar { width: 34px; height: 34px; }
}
