/* ============================================================
   AI Viz — Premium Chat Interface
   Design-Consistent Refactor
   Pure CSS — no frameworks, no build tools.

   DESIGN SYSTEM:
   ┌─ Radii ──────────────────────────────────────┐
   │  Container:  16px (rounded-2xl)              │
   │  Inner:      12px (rounded-xl)               │
   │  Buttons:     8px (rounded-lg)               │
   │  Pills:       6px (rounded-md)               │
   ├─ Spacing (multiples of 4) ───────────────────┤
   │  Section pad: 24px                           │
   │  Internal pad: 16px                          │
   │  Gaps: 4 / 8 / 12 / 16 / 24                 │
   ├─ Shadows ────────────────────────────────────┤
   │  Subtle:  0 1px  4px rgba(0,0,0,0.08)       │
   │  Medium:  0 4px 16px rgba(0,0,0,0.12)       │
   │  Strong:  0 12px 48px rgba(0,0,0,0.35)       │
   ├─ Motion ─────────────────────────────────────┤
   │  Primary:  200ms ease-in-out                 │
   │  Hover:    150ms ease-out                    │
   │  Active:   scale(0.98)                       │
   │  Panel:    300ms cubic-bezier(.34,1.56,.64,1)│
   ├─ Typography ─────────────────────────────────┤
   │  Primary text:   opacity 1                   │
   │  Secondary text: opacity 0.6                 │
   │  Placeholder:    opacity 0.3                 │
   │  Line-height:    1.6                         │
   └──────────────────────────────────────────────┘
   ============================================================ */

/* ── Design Tokens ───────────────────────────────────────────── */
:root {
    /* Colors */
    --viz-accent: #7c3aed;
    --viz-accent-light: #a78bfa;
    --viz-accent-glow: rgba(124, 58, 237, 0.25);
    --viz-indigo: #6366f1;
    --viz-indigo-glow: rgba(99, 102, 241, 0.20);

    /* Surfaces */
    --viz-surface: rgba(15, 15, 25, 0.88);
    --viz-surface-hover: rgba(124, 58, 237, 0.08);
    --viz-border: rgba(255, 255, 255, 0.08);

    /* Text */
    --viz-text: rgba(240, 240, 245, 1);
    --viz-text-secondary: rgba(240, 240, 245, 0.6);
    --viz-text-placeholder: rgba(240, 240, 245, 0.3);

    /* Message bubbles */
    --viz-outgoing-bg: linear-gradient(135deg, var(--primary-neon, #00f3ff), #00c8d5);
    --viz-outgoing-text: #0a0a0a;
    --viz-incoming-bg: rgba(255, 255, 255, 0.04);
    --viz-incoming-border: rgba(255, 255, 255, 0.08);

    /* Radii */
    --viz-r-container: 16px;
    --viz-r-inner: 12px;
    --viz-r-button: 8px;
    --viz-r-pill: 6px;

    /* Shadows */
    --viz-shadow-subtle: 0 1px 4px rgba(0, 0, 0, 0.08);
    --viz-shadow-medium: 0 4px 16px rgba(0, 0, 0, 0.12);
    --viz-shadow-strong: 0 12px 48px rgba(0, 0, 0, 0.35);

    /* Motion */
    --viz-ease-primary: 200ms ease-in-out;
    --viz-ease-hover: 150ms ease-out;
    --viz-ease-panel: 300ms cubic-bezier(0.34, 1.56, 0.64, 1);

    /* Layout */
    --viz-panel-w: 420px;
    --viz-blur: 20px;
    --viz-glow-x: 50%;
    --viz-glow-y: 50%;
}

/* ── Light Mode Overrides ────────────────────────────────────── */
body.light-theme {
    --viz-surface: rgba(255, 255, 255, 0.92);
    --viz-surface-hover: rgba(124, 58, 237, 0.06);
    --viz-border: rgba(0, 0, 0, 0.07);
    --viz-text: rgba(20, 20, 35, 1);
    --viz-text-secondary: rgba(20, 20, 35, 0.6);
    --viz-text-placeholder: rgba(20, 20, 35, 0.3);
    --viz-incoming-bg: rgba(255, 255, 255, 1);
    --viz-incoming-border: rgba(0, 0, 0, 0.06);
    --viz-accent-glow: rgba(124, 58, 237, 0.14);
    --viz-indigo-glow: rgba(99, 102, 241, 0.10);
    --viz-shadow-subtle: 0 1px 4px rgba(0, 0, 0, 0.05);
    --viz-shadow-medium: 0 4px 16px rgba(0, 0, 0, 0.08);
    --viz-shadow-strong: 0 12px 48px rgba(0, 0, 0, 0.15);
}


/* ═══════════════════════════════════════════════════════════════
   1. TOGGLER BUTTON
   ═══════════════════════════════════════════════════════════════ */
.chatbot-toggler {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    outline: none;
    cursor: pointer;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--viz-accent), var(--viz-indigo));
    box-shadow:
        var(--viz-shadow-medium),
        0 0 32px var(--viz-accent-glow);
    transition:
        transform var(--viz-ease-primary),
        box-shadow var(--viz-ease-primary);
    animation: togglerPulse 3s ease-in-out infinite;
}

.chatbot-toggler:hover {
    transform: scale(1.08);
    box-shadow:
        var(--viz-shadow-strong),
        0 0 48px var(--viz-accent-glow);
}

.chatbot-toggler:active {
    transform: scale(0.98);
}

body.show-chatbot .chatbot-toggler {
    transform: rotate(180deg);
    animation: none;
}

@keyframes togglerPulse {

    0%,
    100% {
        box-shadow: var(--viz-shadow-medium), 0 0 32px var(--viz-accent-glow);
    }

    50% {
        box-shadow: var(--viz-shadow-medium), 0 0 48px var(--viz-accent-glow);
    }
}

/* Icon swap */
.chatbot-toggler span {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    transition:
        opacity var(--viz-ease-primary),
        transform var(--viz-ease-primary);
}

.chatbot-toggler .icon-open {
    opacity: 1;
    transform: scale(1);
}

.chatbot-toggler .icon-close {
    opacity: 0;
    transform: scale(0.5) rotate(-90deg);
}

body.show-chatbot .chatbot-toggler .icon-open {
    opacity: 0;
    transform: scale(0.5) rotate(90deg);
}

body.show-chatbot .chatbot-toggler .icon-close {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}


/* ═══════════════════════════════════════════════════════════════
   2. CHAT PANEL (Container)
   ═══════════════════════════════════════════════════════════════ */
.chatbot-sidebar {
    position: fixed;
    right: 28px;
    bottom: 94px;
    width: var(--viz-panel-w);
    max-height: 80vh;
    border-radius: var(--viz-r-container);
    overflow: hidden;

    /* Glassmorphism */
    background: var(--viz-surface);
    backdrop-filter: blur(var(--viz-blur));
    -webkit-backdrop-filter: blur(var(--viz-blur));
    border: 1px solid var(--viz-border);

    /* Depth shadow */
    box-shadow:
        var(--viz-shadow-strong),
        0 0 40px var(--viz-indigo-glow);

    /* Hidden state */
    opacity: 0;
    pointer-events: none;
    transform: translateY(16px) scale(0.97);
    transform-origin: bottom right;
    transition:
        opacity 300ms ease-in-out,
        transform var(--viz-ease-panel);

    z-index: 1100;
    display: flex;
    flex-direction: column;
}

/* Mouse-following glow — subtle, never overpowers */
.chatbot-sidebar::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: radial-gradient(500px circle at var(--viz-glow-x) var(--viz-glow-y),
            rgba(124, 58, 237, 0.07),
            rgba(99, 102, 241, 0.03) 40%,
            transparent 65%);
    z-index: 0;
    pointer-events: none;
}

body.light-theme .chatbot-sidebar::before {
    background: radial-gradient(500px circle at var(--viz-glow-x) var(--viz-glow-y),
            rgba(124, 58, 237, 0.04),
            transparent 55%);
}

/* Open state */
body.show-chatbot .chatbot-sidebar {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}


/* ═══════════════════════════════════════════════════════════════
   3. HEADER
   ═══════════════════════════════════════════════════════════════ */
.chatbot-sidebar header {
    position: relative;
    z-index: 2;
    padding: 16px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--viz-border);
    flex-shrink: 0;
    background: transparent;
}

.chatbot-sidebar header .viz-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chatbot-sidebar header .viz-brand-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--viz-r-button);
    background: linear-gradient(135deg, var(--viz-accent), var(--viz-indigo));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: var(--viz-shadow-subtle);
    flex-shrink: 0;
}

.chatbot-sidebar header .viz-brand-icon i,
.chatbot-sidebar header .viz-brand-icon svg {
    width: 16px;
    height: 16px;
}

.chatbot-sidebar header h2 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--viz-text);
    letter-spacing: 0.3px;
    line-height: 1.6;
}

.chatbot-sidebar header h2 span {
    background: linear-gradient(135deg, var(--viz-accent-light), var(--primary-neon, #00f3ff));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Close button — matches all button styling */
.chatbot-sidebar header .close-btn {
    display: none;
    background: none;
    border: none;
    color: var(--viz-text-secondary);
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: var(--viz-r-button);
    align-items: center;
    justify-content: center;
    transition:
        background var(--viz-ease-hover),
        color var(--viz-ease-hover);
}

.chatbot-sidebar header .close-btn:hover {
    background: var(--viz-surface-hover);
    color: var(--viz-text);
}

.chatbot-sidebar header .close-btn:active {
    transform: scale(0.98);
}


/* ═══════════════════════════════════════════════════════════════
   4. CHATBOX (Message Area)
   ═══════════════════════════════════════════════════════════════ */
.chatbox {
    position: relative;
    z-index: 2;
    overflow-y: auto;
    flex-grow: 1;
    padding: 24px 16px 16px;
    scroll-behavior: smooth;

    /* Scrollbar */
    scrollbar-width: thin;
    scrollbar-color: rgba(124, 58, 237, 0.2) transparent;
}

.chatbox::-webkit-scrollbar {
    width: 4px;
}

.chatbox::-webkit-scrollbar-track {
    background: transparent;
}

.chatbox::-webkit-scrollbar-thumb {
    background: rgba(124, 58, 237, 0.2);
    border-radius: 4px;
}

/* ── Messages ────────────────────────────────────────────────── */
.chatbox .chat {
    display: flex;
    margin-bottom: 16px;
    list-style: none;
    animation: msgSlideIn 300ms ease-out both;
}

@keyframes msgSlideIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

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

/* Outgoing (user) */
.chatbox .outgoing {
    justify-content: flex-end;
}

.chatbox .chat p {
    white-space: pre-wrap;
    padding: 12px 16px;
    max-width: 80%;
    font-size: 0.875rem;
    line-height: 1.6;
    word-break: break-word;
}

.chatbox .outgoing p {
    background: var(--viz-outgoing-bg);
    color: var(--viz-outgoing-text);
    border-radius: var(--viz-r-inner) var(--viz-r-inner) 4px var(--viz-r-inner);
    font-weight: 500;
    box-shadow: var(--viz-shadow-subtle);
}

/* Incoming (bot) */
.chatbox .incoming {
    align-items: flex-end;
    gap: 8px;
}

.chatbox .incoming p {
    background: var(--viz-incoming-bg);
    color: var(--viz-text);
    border: 1px solid var(--viz-incoming-border);
    border-radius: var(--viz-r-inner) var(--viz-r-inner) var(--viz-r-inner) 4px;
    box-shadow: var(--viz-shadow-subtle);
}

/* Bot avatar — consistent radii + shadow */
.chatbox .incoming .chat-icon {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border-radius: var(--viz-r-button);
    background: linear-gradient(135deg, var(--viz-accent), var(--viz-indigo));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--viz-shadow-subtle);
}

.chatbox .incoming .chat-icon i,
.chatbox .incoming .chat-icon svg {
    width: 14px;
    height: 14px;
}

/* Product image in chat */
.chat-img {
    width: 100%;
    border-radius: var(--viz-r-inner);
    margin: 8px 0;
    border: 1px solid var(--viz-border);
}


/* ═══════════════════════════════════════════════════════════════
   5. TYPING INDICATOR — Compact pill style
   ═══════════════════════════════════════════════════════════════ */

/* Compact bubble for the typing message */
.chatbox .typing-msg p {
    padding: 8px 14px;
    min-height: 0;
    display: inline-flex;
    align-items: center;
}

.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 0;
    height: 16px;
}

.typing-indicator .dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--viz-accent-light);
    animation: typingBounce 1.2s ease-in-out infinite;
    will-change: transform, opacity;
}

.typing-indicator .dot:nth-child(2) {
    animation-delay: 0.15s;
}

.typing-indicator .dot:nth-child(3) {
    animation-delay: 0.30s;
}

@keyframes typingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.3;
    }

    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}


/* ═══════════════════════════════════════════════════════════════
   6. COMMAND PALETTE
   — Matches container blur, radii, shadow hierarchy
   ═══════════════════════════════════════════════════════════════ */
.viz-command-palette {
    position: absolute;
    bottom: 72px;
    left: 16px;
    right: 16px;
    z-index: 10;

    background: var(--viz-surface);
    backdrop-filter: blur(var(--viz-blur));
    -webkit-backdrop-filter: blur(var(--viz-blur));
    border: 1px solid var(--viz-border);
    border-radius: var(--viz-r-inner);
    padding: 8px;
    box-shadow: var(--viz-shadow-strong);

    /* Hidden */
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
    transition:
        opacity var(--viz-ease-primary),
        transform var(--viz-ease-primary);
}

.viz-command-palette.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.viz-command-palette .palette-header {
    padding: 8px 8px 4px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--viz-text-secondary);
    line-height: 1.6;
}

/* Command items — unified button treatment */
.viz-command-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 8px;
    border-radius: var(--viz-r-button);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    color: var(--viz-text);
    font-size: 0.875rem;
    font-family: inherit;
    line-height: 1.6;
    transition:
        background var(--viz-ease-hover),
        transform var(--viz-ease-hover);
}

.viz-command-item:hover,
.viz-command-item:focus-visible {
    background: var(--viz-surface-hover);
    outline: none;
}

.viz-command-item:active {
    transform: scale(0.98);
}

.viz-command-item .cmd-icon {
    width: 28px;
    height: 28px;
    border-radius: var(--viz-r-pill);
    background: var(--viz-surface-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--viz-accent-light);
    flex-shrink: 0;
}

.viz-command-item .cmd-icon i,
.viz-command-item .cmd-icon svg {
    width: 14px;
    height: 14px;
}

.viz-command-item .cmd-label {
    font-weight: 500;
    font-size: 0.8125rem;
    line-height: 1.6;
}

.viz-command-item .cmd-desc {
    font-size: 0.6875rem;
    color: var(--viz-text-secondary);
    line-height: 1.6;
}

.viz-command-item .cmd-shortcut {
    margin-left: auto;
    font-size: 0.625rem;
    color: var(--viz-text-secondary);
    background: rgba(255, 255, 255, 0.04);
    padding: 2px 8px;
    border-radius: var(--viz-r-pill);
    font-family: 'SF Mono', 'Consolas', monospace;
    border: 1px solid var(--viz-border);
}


/* ═══════════════════════════════════════════════════════════════
   7. INPUT AREA — Premium refined
   ═══════════════════════════════════════════════════════════════ */
.chat-input {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--viz-border);
    flex-shrink: 0;

    /* Subtle glassmorphism + inner shadow for depth */
    background: rgba(255, 255, 255, 0.015);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

body.light-theme .chat-input {
    background: rgba(0, 0, 0, 0.01);
    box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.03);
}

.chat-input textarea {
    flex-grow: 1;
    height: 44px;
    min-height: 44px;
    max-height: 120px;
    border: 1px solid var(--viz-border);
    border-radius: var(--viz-r-inner);
    padding: 11px 16px;
    font-size: 0.875rem;
    line-height: 1.5;
    font-family: inherit;
    color: var(--viz-text);
    background: rgba(255, 255, 255, 0.03);
    resize: none;
    outline: none;
    box-shadow: var(--viz-shadow-subtle);
    transition:
        border-color var(--viz-ease-primary),
        box-shadow var(--viz-ease-primary),
        background var(--viz-ease-primary);
    /* Prevent visual jitter during expansion */
    overflow-y: hidden;
}

/* Smooth scroll once content exceeds max-height */
.chat-input textarea.expanded {
    overflow-y: auto;
}

.chat-input textarea::placeholder {
    color: var(--viz-text-placeholder);
    opacity: 1;
}

.chat-input textarea:focus {
    border-color: rgba(124, 58, 237, 0.5);
    background: rgba(255, 255, 255, 0.05);
    box-shadow:
        var(--viz-shadow-subtle),
        0 0 0 3px rgba(124, 58, 237, 0.12);
}

body.light-theme .chat-input textarea {
    background: rgba(0, 0, 0, 0.02);
}

body.light-theme .chat-input textarea:focus {
    background: rgba(255, 255, 255, 1);
    box-shadow:
        var(--viz-shadow-subtle),
        0 0 0 3px rgba(124, 58, 237, 0.10);
}

/* Send button — height matches textarea, aligned */
.chat-input button {
    width: 44px;
    height: 44px;
    border-radius: var(--viz-r-inner);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--viz-accent), var(--viz-indigo));
    color: #fff;
    box-shadow: var(--viz-shadow-medium);
    transition:
        transform var(--viz-ease-primary),
        box-shadow var(--viz-ease-primary),
        filter var(--viz-ease-primary);
}

.chat-input button:hover {
    transform: scale(1.04);
    filter: brightness(1.12);
    box-shadow:
        var(--viz-shadow-medium),
        0 0 20px var(--viz-accent-glow);
}

.chat-input button:active {
    transform: scale(0.98);
}

.chat-input button i,
.chat-input button svg {
    width: 16px;
    height: 16px;
}

/* Slash hint */
.chat-input .slash-hint {
    position: absolute;
    right: 72px;
    bottom: 24px;
    font-size: 0.625rem;
    color: var(--viz-text-placeholder);
    pointer-events: none;
    font-family: 'SF Mono', 'Consolas', monospace;
    line-height: 1.6;
    transition: opacity var(--viz-ease-primary);
}

.chat-input textarea:focus~.slash-hint {
    opacity: 0;
}


/* ═══════════════════════════════════════════════════════════════
   8. RESPONSIVE — Mobile
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .chatbot-sidebar {
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        transform-origin: bottom center;
    }

    .chatbot-sidebar header .close-btn {
        display: flex;
    }

    .chatbot-toggler {
        bottom: 20px;
        right: 20px;
        width: 52px;
        height: 52px;
    }

    .chatbox .chat p {
        max-width: 90%;
    }

    .chatbox {
        padding: 16px 12px 12px;
    }

    .chat-input {
        padding: 10px 12px;
        gap: 8px;
    }

    .chat-input textarea {
        height: 42px;
        min-height: 42px;
        padding: 10px 14px;
        font-size: 1rem;
        /* 16px prevents iOS zoom on focus */
    }

    .chat-input button {
        width: 42px;
        height: 42px;
    }

    /* Compact typing pill on mobile */
    .chatbox .typing-msg p {
        padding: 7px 12px;
    }

    .viz-command-palette {
        left: 8px;
        right: 8px;
        bottom: 64px;
        max-height: 50vh;
        overflow-y: auto;
    }

    .chat-input .slash-hint {
        display: none;
    }
}


/* ═══════════════════════════════════════════════════════════════
   9. REDUCED MOTION
   ═══════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
    .chatbot-toggler {
        animation: none;
    }

    .chatbox .chat {
        animation: none;
    }

    .typing-indicator .dot {
        animation: none;
        opacity: 0.5;
    }

    .chatbot-sidebar,
    .viz-command-palette,
    .chatbot-toggler,
    .chatbot-toggler span,
    .viz-command-item,
    .chat-input textarea,
    .chat-input button,
    .chatbot-sidebar header .close-btn {
        transition-duration: 0.01ms !important;
    }
}