/* Xyphla Chatbot - Premium Dark Theme */

:root {
    --cb-bg: #030712;
    --cb-surface: rgba(11, 18, 34, 0.97);
    --cb-surface-2: rgba(17, 24, 39, 0.8);
    --cb-blue: #3b82f6;
    --cb-blue-dim: rgba(59, 130, 246, 0.15);
    --cb-blue-glow: 0 0 24px rgba(59, 130, 246, 0.45);
    --cb-green: #10b981;
    --cb-text: #f8fafc;
    --cb-text-dim: #94a3b8;
    --cb-border: rgba(255, 255, 255, 0.08);
    --cb-border-blue: rgba(59, 130, 246, 0.35);
    --cb-radius: 20px;
    --cb-font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --cb-font-head: 'Space Grotesk', sans-serif;
}

.xyphla-chatbot-wrapper {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 999999;
    font-family: var(--cb-font);
    /* default: desktop, toggle bottom-right */
}

/* ── Toggle Button ── */
.xyphla-chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    border: 1px solid var(--cb-border-blue);
    color: white;
    cursor: pointer;
    font-size: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--cb-blue-glow), 0 8px 24px rgba(0,0,0,0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    animation: cb-float 3.2s ease-in-out infinite;
}

.xyphla-chatbot-toggle::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 1px solid rgba(59, 130, 246, 0.3);
    animation: cb-ring-pulse 2.5s ease-out infinite;
}

@keyframes cb-ring-pulse {
    0%   { transform: scale(1); opacity: 0.6; }
    100% { transform: scale(1.5); opacity: 0; }
}

.xyphla-chatbot-toggle:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 0 32px rgba(59, 130, 246, 0.6), 0 12px 28px rgba(0,0,0,0.4);
}

@keyframes cb-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

/* ── Chat Window ── */
.xyphla-chatbot-widget {
    width: 390px;
    height: 620px;
    background: var(--cb-surface);
    border: 1px solid var(--cb-border-blue);
    border-radius: var(--cb-radius);
    box-shadow:
        0 0 0 1px rgba(255,255,255,0.04) inset,
        0 0 40px rgba(59, 130, 246, 0.2),
        0 24px 60px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    animation: cb-slide-in 0.38s cubic-bezier(0.34, 1.56, 0.64, 1);
    backdrop-filter: blur(20px);
    overflow: hidden;
    /* Prevent iOS zoom on input focus */
    font-size: 16px;
}

@keyframes cb-slide-in {
    from { opacity: 0; transform: translate(20px, 24px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* grid overlay like website */
.xyphla-chatbot-widget::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(59,130,246,0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(59,130,246,0.04) 1px, transparent 1px);
    background-size: 32px 32px;
    pointer-events: none;
    z-index: 0;
    border-radius: var(--cb-radius);
}

/* ── Header ── */
.xyphla-chatbot-header {
    position: relative;
    z-index: 1;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.9) 0%, rgba(29, 78, 216, 0.85) 100%);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 4px 20px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.12);
    flex-shrink: 0;
}

.xyphla-cb-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(59,130,246,0.3), rgba(37,99,235,0.5));
    border: 1.5px solid rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    box-shadow: 0 0 12px rgba(59,130,246,0.4);
}

.xyphla-cb-header-info {
    flex: 1;
    min-width: 0;
}

.xyphla-cb-header-info h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    font-family: var(--cb-font-head);
    color: #fff;
    letter-spacing: -0.3px;
}

.xyphla-cb-status {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}

.xyphla-cb-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--cb-green);
    animation: cb-pulse-green 2s infinite;
}

@keyframes cb-pulse-green {
    0%   { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70%  { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.xyphla-cb-status span {
    font-size: 11px;
    color: rgba(255,255,255,0.7);
    font-weight: 500;
}

.xyphla-chatbot-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.8);
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    line-height: 1;
}

.xyphla-chatbot-close:hover {
    background: rgba(255,255,255,0.2);
    color: #fff;
    transform: rotate(90deg);
}

.xyphla-chatbot-clear {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.8);
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    line-height: 1;
    margin-right: 8px;
}

.xyphla-chatbot-clear:hover {
    background: rgba(255,255,255,0.2);
    color: #fff;
    transform: rotate(180deg);
}

/* ── Messages Area ── */
.xyphla-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    position: relative;
    z-index: 1;
}

.xyphla-chatbot-messages::-webkit-scrollbar { width: 4px; }
.xyphla-chatbot-messages::-webkit-scrollbar-track { background: transparent; }
.xyphla-chatbot-messages::-webkit-scrollbar-thumb {
    background: rgba(59, 130, 246, 0.25);
    border-radius: 4px;
}
.xyphla-chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(59, 130, 246, 0.45);
}

/* ── Message Rows ── */
.xyphla-chatbot-message {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: cb-fade-up 0.3s ease;
}

@keyframes cb-fade-up {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.xyphla-chatbot-message.user {
    flex-direction: row-reverse;
}

/* bot mini-avatar */
.xyphla-cb-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(59,130,246,0.25), rgba(37,99,235,0.4));
    border: 1px solid rgba(59,130,246,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
}

.xyphla-chatbot-message.user .xyphla-cb-msg-avatar {
    display: none;
}

/* ── Bubbles ── */
.xyphla-chatbot-message-text {
    padding: 11px 15px;
    border-radius: 16px;
    word-wrap: break-word;
    font-size: 14px;
    line-height: 1.55;
    max-width: 72%;
    position: relative;
}

.xyphla-chatbot-message.user .xyphla-chatbot-message-text {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
    border-radius: 16px 4px 16px 16px;
    box-shadow: 0 4px 14px rgba(59,130,246,0.35);
}

.xyphla-chatbot-message.bot .xyphla-chatbot-message-text {
    background: var(--cb-surface-2);
    color: var(--cb-text);
    border: 1px solid var(--cb-border);
    border-radius: 4px 16px 16px 16px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

/* Markdown */
.xyphla-chatbot-message.bot .xyphla-chatbot-message-text strong {
    font-weight: 700;
    color: #93c5fd;
}
.xyphla-chatbot-message.bot .xyphla-chatbot-message-text em {
    font-style: italic;
    color: #7dd3fc;
}
.xyphla-chatbot-message.bot .xyphla-chatbot-message-text br { display: block; margin: 3px 0; }
.xyphla-chatbot-message.bot .xyphla-chatbot-message-text a {
    color: #60a5fa;
    text-decoration: none;
    border-bottom: 1px dotted rgba(96,165,250,0.5);
    transition: color 0.2s;
}
.xyphla-chatbot-message.bot .xyphla-chatbot-message-text a:hover { color: #93c5fd; }

/* Lists */
.xyphla-chatbot-message.bot .xyphla-chatbot-message-text ul {
    list-style: none;
    padding: 0;
    margin: 8px 0;
}

.xyphla-chatbot-message.bot .xyphla-chatbot-message-text li {
    margin: 6px 0 6px 20px;
    padding-left: 8px;
    position: relative;
    line-height: 1.5;
    color: var(--cb-text);
}

.xyphla-chatbot-message.bot .xyphla-chatbot-message-text li::before {
    content: '•';
    position: absolute;
    left: 0;
    color: var(--cb-blue);
    font-weight: bold;
    top: 0;
}

/* ── Input Area ── */
.xyphla-chatbot-input-area {
    padding: 14px 16px;
    border-top: 1px solid var(--cb-border);
    display: flex;
    gap: 10px;
    align-items: center;
    background: rgba(7, 13, 27, 0.8);
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}

.xyphla-chatbot-input {
    flex: 1;
    padding: 11px 16px;
    border: 1px solid var(--cb-border);
    border-radius: 50px;
    font-size: 16px;
    font-family: inherit;
    resize: none;
    background: rgba(255, 255, 255, 0.05);
    color: var(--cb-text);
    transition: all 0.25s;
    line-height: 1.4;
    /* iOS keyboard fix: prevent auto-zoom */
    font-size: 16px;
    /* Better mobile keyboard support */
    -webkit-appearance: none;
    appearance: none;
}

.xyphla-chatbot-input::placeholder { color: var(--cb-text-dim); }

.xyphla-chatbot-input:focus {
    outline: none;
    border-color: rgba(59, 130, 246, 0.6);
    background: rgba(255, 255, 255, 0.07);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.xyphla-chatbot-send {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.25s;
    box-shadow: 0 4px 12px rgba(59,130,246,0.35);
}

.xyphla-chatbot-send svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; }

.xyphla-chatbot-send:hover {
    transform: scale(1.1) translateY(-1px);
    box-shadow: 0 6px 18px rgba(59,130,246,0.5);
}

.xyphla-chatbot-send:active {
    transform: scale(0.96);
}

/* ── Typing Indicator ── */
.xyphla-chatbot-loading {
    display: flex;
    gap: 5px;
    padding: 12px 16px;
    background: var(--cb-surface-2);
    border: 1px solid var(--cb-border);
    border-radius: 4px 16px 16px 16px;
    width: fit-content;
}

.xyphla-chatbot-loading span {
    width: 7px;
    height: 7px;
    background: var(--cb-blue);
    border-radius: 50%;
    animation: cb-bounce 1.3s ease-in-out infinite;
    opacity: 0.4;
}

.xyphla-chatbot-loading span:nth-child(2) { animation-delay: 0.16s; }
.xyphla-chatbot-loading span:nth-child(3) { animation-delay: 0.32s; }

@keyframes cb-bounce {
    0%, 80%, 100% { transform: translateY(0);    opacity: 0.4; }
    40%            { transform: translateY(-8px); opacity: 1;   }
}

/* ──────────────────────────────────────────────────────────────────
   RESPONSIVE & MOBILE KEYBOARD HANDLING
   ────────────────────────────────────────────────────────────────── */

/* Mobile toggle button: bottom-LEFT */
@media (max-width: 768px) {
    .xyphla-chatbot-wrapper {
        bottom: 20px;
        right: 20px;
        left: auto;
    }

    /* Widget is full-screen when open.
       Height is driven by JS (visualViewport) so the keyboard
       never pushes the header off-screen.                        */
    .xyphla-chatbot-widget {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        /* fallback height before JS kicks in */
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        border: none;
        max-height: none;
        /* messages area must shrink so header + input stay visible */
        display: flex;
        flex-direction: column;
    }

    /* CRITICAL: messages grows to fill space, never pushes other rows */
    .xyphla-chatbot-messages {
        flex: 1 1 0;
        min-height: 0;               /* allow flex child to shrink below content height */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    /* Header & input never shrink — keyboard shrinks messages only */
    .xyphla-chatbot-header {
        flex-shrink: 0;
    }
    .xyphla-chatbot-input-area {
        flex-shrink: 0;
        padding-bottom: max(14px, env(safe-area-inset-bottom));
    }

    .xyphla-chatbot-message-text { max-width: 85%; }
}

/* Compact adjustments when screen is short (keyboard visible or landscape) */
@media (max-width: 768px) and (max-height: 500px) {
    .xyphla-chatbot-header {
        padding: 8px 12px;
        gap: 8px;
    }
    .xyphla-cb-avatar { width: 32px; height: 32px; font-size: 14px; }
    .xyphla-cb-header-info h3 { font-size: 13px; }
    .xyphla-cb-status span { display: none; }   /* hide sub-text when cramped */
    .xyphla-chatbot-messages { padding: 10px 12px; gap: 8px; }
    .xyphla-chatbot-input-area { padding: 8px 12px; gap: 8px; }
    .xyphla-chatbot-input { padding: 8px 14px; }
    .xyphla-chatbot-send { width: 36px; height: 36px; }
    .xyphla-chatbot-close,
    .xyphla-chatbot-clear { width: 28px; height: 28px; font-size: 14px; }
}

/* Prevent iOS zoom on input focus (font-size < 16px triggers zoom) */
@media (max-width: 1024px) {
    .xyphla-chatbot-input { font-size: 16px; }
    .xyphla-chatbot-send svg { width: 16px; height: 16px; }
}

/* ── Inquiry Submit Banner ── */
.xyphla-inquiry-submit-prompt {
    margin: 0 12px 10px;
    padding: 12px 14px;
    background: linear-gradient(135deg, rgba(59,130,246,0.12), rgba(37,99,235,0.08));
    border: 1px solid rgba(59,130,246,0.3);
    border-radius: 12px;
    display: flex;
    gap: 10px;
    align-items: center;
    position: relative;
    z-index: 1;
    animation: cb-fade-up 0.3s ease;
}

.xyphla-inquiry-submit-prompt span {
    flex: 1;
    font-size: 13px;
    color: #93c5fd;
    font-weight: 500;
}

.xyphla-inquiry-submit-prompt button {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
    border: none;
    padding: 7px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.2s;
    white-space: nowrap;
    box-shadow: 0 3px 10px rgba(59,130,246,0.3);
}

.xyphla-inquiry-submit-prompt button:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 16px rgba(59,130,246,0.45);
}

.xyphla-inquiry-submit-prompt button:active { transform: translateY(0); }

/* ── Welcome / empty state ── */
.xyphla-cb-welcome {
    text-align: center;
    padding: 24px 16px;
    color: var(--cb-text-dim);
    font-size: 13px;
    line-height: 1.6;
}

.xyphla-cb-welcome strong {
    display: block;
    color: var(--cb-text);
    font-size: 15px;
    margin-bottom: 6px;
    font-family: var(--cb-font-head);
}

.xyphla-cb-quick-actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(96, 165, 250, 0.55) transparent;
    padding: 0 12px 14px;
    position: relative;
    z-index: 1;
    -webkit-overflow-scrolling: touch;
}

.xyphla-cb-quick-actions::-webkit-scrollbar {
    height: 4px;
}

.xyphla-cb-quick-actions::-webkit-scrollbar-track {
    background: transparent;
}

.xyphla-cb-quick-actions::-webkit-scrollbar-thumb {
    background: rgba(96, 165, 250, 0.45);
    border-radius: 999px;
}

.xyphla-cb-quick-actions-inline {
    padding: 10px 12px 10px;
    border-top: 1px solid var(--cb-border);
    background: rgba(7, 13, 27, 0.75);
    flex-shrink: 0;
}

.xyphla-cb-action-btn {
    border: 1px solid rgba(59, 130, 246, 0.35);
    background: linear-gradient(135deg, rgba(30, 64, 175, 0.42), rgba(37, 99, 235, 0.26));
    color: #dbeafe;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.1px;
    padding: 7px 12px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    flex: 0 0 auto;
    white-space: nowrap;
}

.xyphla-cb-action-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(147, 197, 253, 0.65);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.25);
}

.xyphla-cb-action-btn:active {
    transform: translateY(0);
}
