/* ── CERKIT LABS AI CHATBOT WIDGET ── */

:root {
    --chat-accent: #0ea5e9;
    --chat-accent-glow: rgba(14, 165, 233, 0.5);
    --chat-bg: #111114;
    --chat-border: rgba(255, 255, 255, 0.08);
    --chat-text: #ffffff;
    --chat-muted: #a1a1aa;
    --chat-muted2: #71717a;
    --chat-green: #22c55e;
    --chat-font-heading: 'Syne', sans-serif;
    --chat-font-body: 'Inter', sans-serif;
}

/* Custom Scrollbar for Chat */
#cerkit-chat-window *::-webkit-scrollbar {
    width: 6px;
}
#cerkit-chat-window *::-webkit-scrollbar-track {
    background: transparent;
}
#cerkit-chat-window *::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
}
#cerkit-chat-window *::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Firefox scrollbar */
#cerkit-chat-window * {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

/* Floating Trigger Button */
#cerkit-chat-trigger {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 65px;
    height: 65px;
    border-radius: 50%;
    background: var(--chat-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 30px var(--chat-accent-glow);
    z-index: 9999;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 2px solid rgba(255,255,255,0.1);
}

#cerkit-chat-trigger:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 12px 40px var(--chat-accent-glow);
}

#cerkit-chat-trigger svg {
    width: 32px;
    height: 32px;
    fill: #fff;
}

/* Online Pulsing Indicator */
.chat-online-indicator {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 14px;
    height: 14px;
    background: var(--chat-green);
    border: 3px solid #000;
    border-radius: 50%;
}

.chat-online-indicator::after {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 2px solid var(--chat-green);
    animation: chat-online-pulse 2s infinite;
}

@keyframes chat-online-pulse {
    0% { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(2.2); opacity: 0; }
}

/* Chat Window Container */
#cerkit-chat-window {
    position: fixed;
    bottom: 6.5rem;
    right: 2rem;
    width: 400px;
    height: 580px;
    max-height: calc(100vh - 8rem);
    background: var(--chat-bg);
    border: 1px solid var(--chat-border);
    border-radius: 28px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    transform: translateY(30px) scale(0.95);
    opacity: 0;
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: bottom right;
    overscroll-behavior: contain; /* Prevents background scroll */
}

#cerkit-chat-window.open {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: all;
}

/* Header */
.chat-header {
    padding: 1.25rem 1.5rem;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid var(--chat-border);
    display: flex;
    align-items: center;
    gap: 1.2rem;
}

.chat-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--chat-accent) 0%, #6366f1 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: #fff;
    font-family: 'Syne', sans-serif;
    font-size: 1.2rem;
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.2);
}

.chat-header-info {
    flex: 1;
}

.chat-header-name {
    font-weight: 700;
    font-size: 1.05rem;
    color: #fff;
    font-family: 'Inter', sans-serif;
}

.chat-header-status {
    font-size: 0.78rem;
    color: var(--chat-muted);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 1px;
}

.status-dot {
    width: 7px;
    height: 7px;
    background: var(--chat-green);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--chat-green);
}

.chat-close-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--chat-muted);
    font-size: 0.9rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.chat-close-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.2);
}

/* Login Gate Container */
#chat-login-container {
    flex: 1;
    padding: 2.5rem;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background: radial-gradient(circle at top right, rgba(14, 165, 233, 0.05) 0%, transparent 70%);
}

.chat-login-title {
    font-size: 2rem;
    font-weight: 800;
    font-family: var(--chat-font-heading);
    color: #fff;
    margin-bottom: 0.8rem;
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.chat-login-sub {
    color: var(--chat-muted);
    font-size: 1rem;
    font-family: var(--chat-font-body);
    margin-bottom: 2.5rem;
    line-height: 1.6;
}

.chat-input-group {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-bottom: 1.5rem;
}

.chat-input-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--chat-muted);
}

.chat-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--chat-border);
    padding: 1rem 1.2rem;
    border-radius: 14px;
    color: #fff;
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    outline: none;
    transition: all 0.3s;
}

.chat-input:focus {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--chat-accent);
    box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.1);
}

.chat-error {
    color: #fb7185;
    font-size: 0.78rem;
    font-weight: 500;
    margin-top: 4px;
    display: none;
}

.chat-submit-btn {
    width: 100%;
    background: linear-gradient(135deg, var(--chat-accent) 0%, #6366f1 100%);
    color: #fff;
    padding: 1.1rem;
    border: none;
    border-radius: 14px;
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 8px 25px var(--chat-accent-glow);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-top: 1rem;
    font-family: var(--chat-font-body);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.chat-submit-btn:active {
    transform: scale(0.98);
}

.chat-submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 30px var(--chat-accent-glow);
    filter: brightness(1.1);
}

.chat-privacy-note {
    text-align: center;
    font-size: 0.8rem;
    color: var(--chat-muted2);
    margin-top: 2rem;
}

/* Chat container (where n8n loads) */
#n8n-chat-container {
    flex: 1;
    display: none; /* Will be flex via JS */
    flex-direction: column;
    height: 100%;
    width: 100%;
    position: relative;
    overflow: hidden; /* n8n chat handles its own scroll */
}

.chat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 180px;
    height: 100%;
    padding: 2rem;
    color: rgba(255, 255, 255, 0.72);
    font-size: 0.9rem;
    text-align: center;
}

/* n8n Chat Overrides for Theme Match */
.n8n-chat-widget {
    height: 100% !important;
}

/* Force internal message list to be scrollable */
[class*="chat-messages-list"],
.n8n-chat-messages-list {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    overscroll-behavior: contain !important; /* Critical for scroll isolation */
}

/* Ensure the scrollbar is visible and usable */
[class*="chat-messages-list"]::-webkit-scrollbar,
.n8n-chat-messages-list::-webkit-scrollbar {
    width: 6px !important;
    display: block !important;
}

/* Hide internal n8n header since we have a custom one */
#n8n-chat-container .n8n-chat-header, 
#n8n-chat-container [class*="chat-header"] {
    display: none !important;
}

/* Ensure input area and send button are visible and match theme */
[class*="chat-input-area"],
.n8n-chat-input-area {
    background: var(--chat-bg) !important;
    border-top: 1px solid var(--chat-border) !important;
    padding-bottom: env(safe-area-inset-bottom) !important;
}

/* Fix for possible missing send button icon color */
[class*="chat-input-send-button"] svg,
.n8n-chat-input-send-button svg {
    fill: var(--chat-accent) !important;
    width: 24px !important;
    height: 24px !important;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    #cerkit-chat-window {
        width: min(100vw - 1rem, 400px);
        height: min(72vh, 580px);
        max-height: calc(100dvh - 5.75rem);
        right: 0.5rem;
        bottom: 5rem;
        border-radius: 22px;
    }

    #cerkit-chat-trigger {
        right: 1rem;
        bottom: 1rem;
        width: 58px;
        height: 58px;
    }

    #cerkit-chat-trigger svg {
        width: 28px;
        height: 28px;
    }
}

@media (max-width: 520px) {
    #cerkit-chat-window {
        width: 100% !important;
        height: 100vh !important; /* Fallback must be first */
        height: 100dvh !important;
        max-height: 100% !important;
        bottom: 0 !important;
        right: 0 !important;
        top: 0 !important;
        left: 0 !important;
        border-radius: 0 !important;
        border: none !important;
        display: flex;
        flex-direction: column;
        z-index: 999999 !important; /* Ensure it stays on top of everything */
    }
    .chat-header {
        border-radius: 0 !important;
        padding: 1rem 1.5rem !important;
        z-index: 10;
        position: relative;
    }

    #chat-login-container {
        padding: 1.5rem;
    }

    .chat-login-title {
        font-size: 1.6rem;
    }

    .chat-login-sub {
        font-size: 0.92rem;
        margin-bottom: 1.75rem;
    }

    #cerkit-chat-trigger {
        bottom: 1.2rem !important;
        right: 1.2rem !important;
        width: 55px !important;
        height: 55px !important;
    }
    /* Force hide trigger when open with CSS as backup */
    body.cerkit-chat-open #cerkit-chat-trigger {
        display: none !important;
    }
}
