/*
 * Talk By HuyNguyen - Core Stylesheet
 * Features: Mobile App Mode, Glassmorphism, E-commerce Ready
 * Standard: HTML5/CSS4 (2026)
 * Version: 1.1.4
 */

/* =========================================
   1. VARIABLES & ROOT CONFIGURATION
   ========================================= */
:root {
    /* Color Palette */
    --tbhn-primary: #007AFF;
    --tbhn-primary-dark: #005ecb;
    --tbhn-success: #34C759;
    --tbhn-danger: #FF3B30;
    --tbhn-warning: #FF9500;
    
    /* Text Colors */
    --tbhn-text-light: #ffffff;
    --tbhn-text-dark: #1d1d1f;
    --tbhn-text-muted: #86868b;

    /* Backgrounds */
    --tbhn-bg-glass: rgba(255, 255, 255, 0.75);
    --tbhn-bg-dark: #000000;
    --tbhn-border-light: rgba(255, 255, 255, 0.2);
    
    /* Spacing & Layout */
    --tbhn-radius-lg: 20px;
    --tbhn-radius-md: 12px;
    --tbhn-radius-sm: 8px;
}

.tbhn-widget-root {
    width: 100%;
    height: 600px; /* Desktop Fallback */
    position: relative;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    box-sizing: border-box;
}

/* Reset for all internal elements */
.tbhn-widget-root * {
    box-sizing: border-box;
}

/* =========================================
   2. MAIN LAYOUT (GLASS SHELL)
   ========================================= */
.tbhn-embedded-glass {
    width: 100%;
    height: 100%;
    border-radius: var(--tbhn-radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    /* Background handled by Elementor, fallback here */
    background: rgba(255, 255, 255, 0.05); 
}

/* Layout Slots */
.tbhn-dynamic-header {
    flex-shrink: 0;
    z-index: 10;
}

.tbhn-dynamic-body {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 5;
}

.tbhn-dynamic-footer {
    flex-shrink: 0;
    z-index: 20;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* Scrollable Area */
.tbhn-template-wrapper {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
    padding-bottom: 20px;
    z-index: 5;
    scroll-behavior: smooth;
}

.tbhn-template-wrapper::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

/* =========================================
   3. MESSAGING COMPONENTS
   ========================================= */
.tbhn-msg-row {
    display: flex;
    margin-bottom: 16px;
    padding: 0 16px;
    opacity: 0;
    animation: tbhnSlideUp 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

.tbhn-msg-row.user-msg { justify-content: flex-end; }
.tbhn-msg-row.bot-msg { justify-content: flex-start; }

.tbhn-msg-bubble {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 15px;
    word-wrap: break-word;
    position: relative;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

/* User Styling */
.user-msg .tbhn-msg-bubble {
    background: var(--tbhn-primary);
    color: var(--tbhn-text-light);
    border-bottom-right-radius: 4px;
}

/* Bot Styling (Glassy) */
.bot-msg .tbhn-msg-bubble {
    background: var(--tbhn-bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--tbhn-text-dark);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-bottom-left-radius: 4px;
}

/* Markdown Content */
.tbhn-msg-bubble p { margin: 0 0 8px; }
.tbhn-msg-bubble p:last-child { margin: 0; }
.tbhn-msg-bubble a { color: inherit; text-decoration: underline; }
.tbhn-msg-bubble code { background: rgba(0,0,0,0.1); padding: 2px 5px; border-radius: 4px; font-family: monospace; font-size: 0.9em; }

/* =========================================
   4. RICH MEDIA & E-COMMERCE CARDS
   ========================================= */

/* 4.1. Images & Video */
.tbhn-msg-image img,
.tbhn-msg-video video {
    max-width: 100%;
    height: auto;
    border-radius: var(--tbhn-radius-md);
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    margin-top: 8px;
    display: block;
}

/* 4.2. WooCommerce Product Card */
.tbhn-card-woo {
    display: flex;
    gap: 12px;
    background: #fff;
    padding: 12px;
    border-radius: var(--tbhn-radius-md);
    border: 1px solid rgba(0,0,0,0.05);
    max-width: 300px;
    margin-top: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.08);
}

.tbhn-card-woo .thumb {
    width: 80px;
    height: 80px;
    background-size: cover;
    background-position: center;
    border-radius: var(--tbhn-radius-sm);
    flex-shrink: 0;
    position: relative;
    background-color: #f5f5f7;
}

.tbhn-card-woo .thumb .badge {
    position: absolute;
    top: -6px; left: -6px;
    background: var(--tbhn-danger);
    color: #fff;
    font-size: 10px;
    padding: 3px 6px;
    border-radius: 4px;
    font-weight: 700;
}

.tbhn-card-woo .details {
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex: 1;
}

.tbhn-card-woo h4 {
    margin: 0 0 4px;
    font-size: 14px;
    font-weight: 600;
    color: var(--tbhn-text-dark);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tbhn-card-woo .price {
    font-size: 14px;
    color: var(--tbhn-danger);
    font-weight: 700;
    margin-bottom: 8px;
}

.tbhn-card-woo .tbhn-btn-add-cart {
    background: var(--tbhn-text-dark);
    color: #fff;
    border: none;
    padding: 8px 12px;
    font-size: 12px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.1s, background 0.2s;
    width: fit-content;
}
.tbhn-card-woo .tbhn-btn-add-cart:active { transform: scale(0.95); }
.tbhn-card-woo .tbhn-btn-add-cart.success { background: var(--tbhn-success); }

/* 4.3. SePay QR Card */
.tbhn-card-sepay {
    background: #fff;
    padding: 20px;
    border-radius: var(--tbhn-radius-lg);
    text-align: center;
    margin-top: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}

.tbhn-card-sepay .qr-code img {
    width: 180px;
    height: 180px;
    object-fit: contain;
    border-radius: 8px;
    margin-bottom: 12px;
    mix-blend-mode: multiply;
}

.tbhn-card-sepay .amount {
    color: var(--tbhn-primary);
    font-weight: 800;
    font-size: 18px;
    margin: 8px 0;
}

.tbhn-card-sepay .status {
    font-size: 12px;
    color: var(--tbhn-warning);
    background: rgba(255, 149, 0, 0.1);
    padding: 6px 12px;
    border-radius: 20px;
    display: inline-block;
    margin-top: 8px;
}

/* 4.4. Carousel (Horizontal Scroll) */
.tbhn-carousel-container {
    display: flex;
    overflow-x: auto;
    padding: 10px 5px 20px 5px;
    scroll-snap-type: x mandatory;
    gap: 12px;
}
.tbhn-carousel-container::-webkit-scrollbar { display: none; }

.tbhn-carousel-item {
    min-width: 220px;
    max-width: 220px;
    background: rgba(255,255,255,0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: var(--tbhn-radius-md);
    overflow: hidden;
    scroll-snap-align: start;
    display: flex;
    flex-direction: column;
}

/* 4.5. Quick Replies Buttons */
.tbhn-btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}
.tbhn-quick-reply {
    background: rgba(255,255,255,0.1);
    border: 1px solid var(--tbhn-primary);
    color: var(--tbhn-primary);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}
.tbhn-quick-reply:hover {
    background: var(--tbhn-primary);
    color: white;
}

/* 4.6. Order Status Timeline */
.tbhn-order-card {
    border-left: 3px solid var(--tbhn-primary);
}
.tbhn-timeline {
    margin-top: 10px;
}

/* =========================================
   5. SECURITY & OVERLAYS
   ========================================= */
#tbhn-otp-overlay,
#tbhn-qr-overlay {
    animation: tbhnFadeIn 0.3s ease;
}

#tbhn-otp-overlay input {
    font-size: 16px; /* Prevents iOS auto-zoom */
    transition: all 0.2s;
}
#tbhn-otp-overlay input:focus {
    border-color: var(--tbhn-primary);
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.2);
}

/* =========================================
   6. ANIMATIONS & UTILS
   ========================================= */
@keyframes tbhnSlideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes tbhnFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes tbhnFloatUp {
    0% { transform: translateY(0) scale(1); opacity: 1; }
    100% { transform: translateY(-120px) scale(1.5); opacity: 0; }
}

@keyframes tbhnSpin {
    100% { transform: rotate(360deg); }
}

/* Loading State */
.tbhn-widget-root.is-loading .tbhn-action-send {
    opacity: 0.6;
    pointer-events: none;
}
.tbhn-widget-root.is-loading .tbhn-action-send svg {
    animation: tbhnSpin 0.8s linear infinite;
}

/* =================================================================
   7. GLOBAL RESET & TRANSPARENCY
   Removes default widget styling to let Elementor Pro settings shine.
   ================================================================= */

/* Force transparency on all structural components */
.tbhn-widget-root,
.tbhn-dynamic-header, 
.tbhn-dynamic-footer {
    background: transparent !important;
    background-color: transparent !important;
    box-shadow: none !important;
    border: none !important;
}

/* =================================================================
   8. RESPONSIVE OPTIMIZATION (MOBILE & TABLET)
   Applies to screens 1024px and below.
   ================================================================= */

@media screen and (max-width: 1024px) {

    /* RESET CONTAINER TO NATURAL FLOW */
    .tbhn-widget-root {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        width: 100% !important;
        height: auto !important;
        min-height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        z-index: 1 !important;
    }

    /* MEDIA CONSTRAINTS */
    .tbhn-widget-root img, 
    .tbhn-widget-root svg,
    .elementor-widget-image img {
        max-width: 100% !important;
        height: auto !important;
        object-fit: contain !important;
    }

    /* BODY TYPOGRAPHY SCALING */
    .tbhn-dynamic-body p {
        font-size: 14px !important;
        line-height: 1.5 !important;
    }

    /* SCROLLBAR SUPPRESSION (STRICT MODE) */
    .tbhn-dynamic-body {
        scrollbar-width: none !important; /* Firefox */
        -ms-overflow-style: none !important;  /* IE/Edge */
        overflow-y: auto;
    }

    /* Chrome, Safari and Opera */
    .tbhn-dynamic-body::-webkit-scrollbar {
        display: none !important;
        width: 0 !important;
        height: 0 !important;
        background: transparent !important;
    }
}

/* =========================================
   9. CANVAS BACKGROUND CONFIGURATION
   ========================================= */
   /* Force the particles canvas to cover the entire container including the footer */
.particles-js-canvas-el {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 0 !important; /* Keep it behind all UI elements */
    pointer-events: none;  /* Ensures the canvas doesn't block clicks on buttons */
}

/* Ensure the parent wrapper allows the canvas to overflow into the footer area */
.widget-container-wrap { 
    position: relative;
    overflow: visible !important; 
    display: flex;
    flex-direction: column;
}

/* Optional: Make the footer background transparent so particles are visible behind it */
.widget-footer {
    background: transparent !important;
    position: relative;
    z-index: 10; /* Bring buttons/input to the front */
}


/* =========================================
   10. AUTO-EXPAND INPUT (USER INJECTED)
   ========================================= */

/* Main container to manage layout and alignment */
.tbhn-widget-root .chat-input-wrapper {
    width: 100%;
    display: flex;
    align-items: flex-end; /* Keeps action icons bottom-aligned as the input grows */
    padding: 0; /* Adjusted padding to fit container */
    background: rgba(255,255,255,0.1); /* Keep glass consistency */
    border-radius: 20px;
}

.tbhn-widget-root .chat-input-field {
    width: 100% !important;
    min-height: 40px !important;
    max-height: 200px !important; /* Prevents the footer from dominating the screen height */
    padding: 10px 15px !important; /* Visual spacing */
    
    /* Modern 2026 CSS standard for auto-expanding textareas */
    field-sizing: content !important; 
    
    /* Styling to match your specific deep red/dark theme */
    background: transparent !important;
    border: none !important;
    outline: none !important;
    color: #fff !important;
    font-family: inherit;
    font-size: 16px;
    line-height: 1.5;
    
    /* Behavioural controls */
    resize: none !important;
    overflow-y: auto !important; /* Enables scrolling only after hitting max-height */
    white-space: pre-wrap !important;
    word-break: break-word !important;
}

/* Custom placeholder styling for high visibility on dark backgrounds */
.tbhn-widget-root .chat-input-field::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

/* Fix for Scrollbar inside textarea */
.tbhn-widget-root .chat-input-field::-webkit-scrollbar {
    width: 4px;
}
.tbhn-widget-root .chat-input-field::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.3);
    border-radius: 4px;
}