/* 
   Zhonghao (Modern Blue / Academic) Chatbot Theme 
   Refined for: Compact Typography, Blue Palette, Clean Look.
*/

@import url('https://fonts.googleapis.com/css2?family=Merriweather:ital,wght@0,400;0,700;1,400&family=Nunito:wght@400;600;700&display=swap');

:root {
    /* --- Design Tokens --- */

    /* Palette: Blue / Academic */
    --cb-gradient-warm: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);

    --cb-accent-main: #0284c7;
    /* Cerulean Blue */
    --cb-accent-soft: #bae6fd;
    /* Light Blue */

    /* Backgrounds */
    --cb-surface-cream: #ffffff;
    /* Main Window */
    --cb-bubble-bot: #f0f9ff;
    /* Pale Blue */
    --cb-bubble-user: #f8fafc;
    /* Cool Grey */

    /* Text */
    --cb-text-primary: #1f2937;
    /* Deep Charcoal */
    --cb-text-secondary: #4b5563;
    /* Slate */

    /* Borders & Shadows */
    --cb-border-subtle: #e2e8f0;
    --cb-shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.08);
    --cb-shadow-glow: 0 0 0 3px rgba(2, 132, 199, 0.15);
    /* Focus ring */

    /* Fonts */
    --cb-font-head: 'Space Grotesk', system-ui, sans-serif;
    /* Matched with main site */
    --cb-font-body: 'Inter', system-ui, sans-serif;
    /* Matched with main site */
}

#chatbot-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: var(--cb-font-body);
    color: var(--cb-text-primary);
    line-height: 1.4;
}

/* Toggle Button */
.chatbot-toggle {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: white;
    border: 2px solid white;
    cursor: pointer;
    padding: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.chatbot-toggle:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 8px 24px rgba(2, 132, 199, 0.25);
}

.chatbot-toggle-icon {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chatbot-toggle.hidden {
    display: none;
}

/* Chat Window */
.chatbot-window {
    position: fixed;
    bottom: 100px;
    right: 20px;
    width: 360px;
    height: 600px;
    max-height: calc(100vh - 120px);
    background: var(--cb-surface-cream);
    border-radius: 16px;
    box-shadow: var(--cb-shadow-soft);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--cb-border-subtle);
    animation: slideUpFade 0.3s ease-out;
}

.chatbot-window.open {
    display: flex;
}

@keyframes slideUpFade {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

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

/* Header */
.chatbot-header {
    background: var(--cb-gradient-warm);
    color: white;
    padding: 14px 18px;
    position: relative;
    overflow: hidden;
}

/* Texture Overlay */
.chatbot-header::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.08'/%3E%3C/svg%3E");
    opacity: 1;
    pointer-events: none;
}

.header-content {
    position: relative;
    z-index: 2;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.header-info h3 {
    margin: 0;
    font-family: var(--cb-font-head);
    font-weight: 700;
    font-size: 1.05rem;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    color: #ffffff;
    /* Explicitly set to white */
}

.header-info .sub-header {
    display: block;
    font-size: 0.75rem;
    opacity: 0.9;
    margin-top: 2px;
    font-weight: 400;
}

.chatbot-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    /* larger touch target */
    min-width: 32px;
    min-height: 32px;
}

.chatbot-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Messages Area - Compact Mode */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    background: var(--cb-surface-cream);
    display: flex;
    flex-direction: column;
    gap: 12px;
    /* Reduced gap between messages */
}

.chatbot-messages::-webkit-scrollbar {
    width: 5px;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--cb-border-subtle);
    border-radius: 3px;
}

/* Message Bubbles */
.chatbot-message {
    display: flex;
    margin-bottom: 2px;
    animation: messagePop 0.2s ease-out;
}

@keyframes messagePop {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

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

/* Compact Content Styling */
.message-content {
    max-width: 88%;
    padding: 10px 14px;
    /* Tighter padding */
    border-radius: 10px;
    line-height: 1.35;
    /* More compact line height */
    font-size: 0.92rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

/* Paragraphs & Typography inside messages */
.message-content p {
    margin: 0.35em 0;
}

.message-content p:first-child {
    margin-top: 0;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content h3,
.message-content h4 {
    margin: 0.5em 0 0.25em;
    font-weight: 700;
    font-size: 1em;
    font-family: var(--cb-font-head);
    color: var(--cb-accent-main);
}

.message-content a {
    color: var(--cb-accent-main);
    text-decoration: underline;
    font-weight: 500;
}

.message-content a:hover {
    color: #0369a1;
    /* Darker blue on hover */
}

.message-content ul,
.message-content ol {
    margin: 0.35em 0;
    padding-left: 1.2em;
}

.message-content li {
    margin: 0.15em 0;
}

/* Bot Implementation */
.bot-message .message-content {
    background: var(--cb-bubble-bot);
    color: var(--cb-text-primary);
    border-bottom-left-radius: 2px;
    /* Very soft accent line */
    border-left: 2px solid rgba(2, 132, 199, 0.25);
}

/* User Implementation */
.user-message {
    justify-content: flex-end;
}

.user-message .message-content {
    background: var(--cb-bubble-user);
    color: var(--cb-text-primary);
    /* Dark text for readability on light bg */
    border-bottom-right-radius: 2px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

/* Chips */
.chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
    margin-left: 4px;
}

.chip {
    background: white;
    border: 1px solid var(--cb-border-subtle);
    color: var(--cb-text-primary);
    padding: 5px 12px;
    border-radius: 16px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.chip:hover {
    border-color: var(--cb-accent-main);
    color: var(--cb-accent-main);
    background: var(--cb-bubble-bot);
    transform: translateY(-1px);
}

/* Typing Indicator (Updated to match soft theme) */
.typing-indicator {
    padding: 10px 14px;
    background: var(--cb-bubble-bot);
    border-radius: 10px;
    border-bottom-left-radius: 2px;
    border-left: 2px solid rgba(2, 132, 199, 0.25);
    display: flex;
    gap: 4px;
    align-items: center;
    width: fit-content;
}

.typing-indicator span {
    width: 5px;
    height: 5px;
    background: var(--cb-accent-main);
    border-radius: 50%;
    opacity: 0.6;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

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

@keyframes typingBounce {

    0%,
    80%,
    100% {
        transform: scale(0);
        opacity: 0.4;
    }

    40% {
        transform: scale(1);
        opacity: 0.8;
    }
}

/* Input Area */
.chatbot-input-area {
    padding: 12px 16px;
    /* Compact */
    background: var(--cb-surface-cream);
    border-top: 1px solid var(--cb-border-subtle);
    display: flex;
    gap: 8px;
    align-items: center;
    /* Safe Area for iPhone Home Indicator */
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.chatbot-input {
    flex: 1;
    background: white;
    border: 1px solid var(--cb-border-subtle);
    border-radius: 999px;
    padding: 10px 16px;
    font-size: 0.9rem;
    color: var(--cb-text-primary);
    outline: none;
    transition: border-color 0.2s;
    font-family: var(--cb-font-body);
}

.chatbot-input:focus {
    border-color: var(--cb-accent-main);
    box-shadow: var(--cb-shadow-glow);
}

.chatbot-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--cb-gradient-warm);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: 0 2px 6px rgba(2, 132, 199, 0.2);
}

.chatbot-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 10px rgba(2, 132, 199, 0.3);
}

.chatbot-send:active {
    transform: scale(0.95);
}

/* Mobile */
@media (max-width: 480px) {
    .chatbot-window {
        width: 100vw;
        height: 100dvh;
        /* Dynamic viewport height */
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: 0;
        max-height: none;
        z-index: 2147483647 !important;
        background: var(--cb-surface-cream);

        /* iOS Layer Promotion / Hardware Acceleration Fix */
        transform: translate3d(0, 0, 0);
        -webkit-transform: translate3d(0, 0, 0);
        will-change: transformbox;

        /* Prevent scroll chaining */
        overscroll-behavior: none;
        touch-action: none;

        display: none;
        flex-direction: column;
    }

    .chatbot-window.open {
        display: flex;
    }

    /* Make header sticky and more prominent on mobile */
    .chatbot-header {
        padding: 16px 18px;
        padding-top: calc(16px + env(safe-area-inset-top));
        position: sticky;
        top: 0;
        z-index: 100;
        flex-shrink: 0;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    }

    /* Ensure input area is fixed at bottom and visible above keyboard (Legacy Fix) */
    .chatbot-input-area {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        flex-shrink: 0;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.03);
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        z-index: 200;
        /* Above messages */
        background: var(--cb-surface-cream);
        /* Ensure opacity */
    }

    /* Adjust input field size for mobile */
    .chatbot-input {
        font-size: 16px;
        /* Prevents iOS zoom on focus */
    }

    /* Messages area takes remaining space with proper padding at bottom */
    .chatbot-messages {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 90px;
        /* Space for fixed input area */
        padding-top: 10px;
    }

    .chatbot-close {
        width: 44px;
        height: 44px;
        /* Large touch target */
        min-width: 44px;
        min-height: 44px;
    }
}