/*
 * Talk By HuyNguyen - Enterprise Core Stylesheet
 * Features: Mobile App Mode, Glassmorphism, E-commerce & N8N CDN Ready
 * Standard: HTML5 / CSS4 (2026)
 * Version: 3.0.1
 */

/* =========================================
   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.78);
    --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 *,
.tbhn-widget-root *::before,
.tbhn-widget-root *::after {
    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: rgba(255, 255, 255, 0.05);
}

/* Layout Slots */
.tbhn-dynamic-header {
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.tbhn-dynamic-body {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 5;
}

.tbhn-dynamic-footer {
    flex-shrink: 0;
    position: relative;
    z-index: 20;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* Scrollable Area (Supports both Template Wrapper & Default Chat Body) */
.tbhn-template-wrapper,
.tbhn-chat-body,
#tbhn-chat-container {
    width: 100%;
    height: 100%;
    flex: 1 1 auto;
    min-height: 0;
    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,
.tbhn-chat-body::-webkit-scrollbar,
#tbhn-chat-container::-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;
    overflow-wrap: anywhere;
    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,
.tbhn-video-card 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;
    min-width: 0;
}

.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. TBHN Instant QR Payment Card */
.tbhn-card-qr,
.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-qr .qr-code img,
.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-qr .amount,
.tbhn-card-sepay .amount {
    color: var(--tbhn-primary);
    font-weight: 800;
    font-size: 18px;
    margin: 8px 0;
}

.tbhn-card-qr .status,
.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);
    -webkit-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);
    }
}

@keyframes tbhnPulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.45;
    }
}

/* Loading & Active States */
.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;
}
.tbhn-voice-btn.is-listening,
.tbhn-action-mic.is-listening {
    color: var(--tbhn-danger) !important;
    animation: tbhnPulse 1s infinite;
}

/* =================================================================
   7. GLOBAL RESET & TRANSPARENCY
   Removes default widget styling to let Elementor Pro settings shine.
   ================================================================= */
.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) {
    .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;
    }

    .tbhn-dynamic-body::-webkit-scrollbar {
        display: none !important;
        width: 0 !important;
        height: 0 !important;
        background: transparent !important;
    }
}

/* =========================================
   9. CANVAS BACKGROUND CONFIGURATION
   ========================================= */
.particles-js-canvas-el {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 0 !important;
    pointer-events: none;
}

.widget-container-wrap {
    position: relative;
    overflow: visible !important;
    display: flex;
    flex-direction: column;
}

.widget-footer {
    background: transparent !important;
    position: relative;
    z-index: 10;
}

/* =========================================
   10. AUTO-EXPAND INPUT (USER & FALLBACK UNIFIED)
   ========================================= */
.tbhn-widget-root .chat-input-wrapper {
    width: 100%;
    display: flex;
    align-items: flex-end;
    padding: 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
}

.tbhn-widget-root .chat-input-field,
.tbhn-widget-root .tbhn-input-field {
    width: 100% !important;
    min-height: 40px !important;
    max-height: 200px !important;
    padding: 10px 15px !important;
    field-sizing: content !important;
    background: transparent !important;
    border: none !important;
    outline: none !important;
    color: #fff !important;
    font-family: inherit;
    font-size: 16px;
    line-height: 1.5;
    resize: none !important;
    overflow-y: auto !important;
    white-space: pre-wrap !important;
    word-break: break-word !important;
}

.tbhn-widget-root .chat-input-field::placeholder,
.tbhn-widget-root .tbhn-input-field::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.tbhn-widget-root .chat-input-field::-webkit-scrollbar,
.tbhn-widget-root .tbhn-input-field::-webkit-scrollbar {
    width: 4px;
}
.tbhn-widget-root .chat-input-field::-webkit-scrollbar-thumb,
.tbhn-widget-root .tbhn-input-field::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

/* =========================================
   11. TBHN CDN MEDIA SHORTCODES STYLING
   ========================================= */
.tbhn-cdn-gallery-grid,
.hn-cdn-gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: var(--e-global-typography-gap, 10px);
    width: 100%;
}

.tbhn-gallery-item img,
.tbhn-cdn-image-wrap img,
.tbhn-cdn-video-wrap video,
.hn-gallery-item img,
.hn-cdn-image-wrap img,
.hn-cdn-video-wrap video {
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.tbhn-gallery-item:hover img,
.tbhn-cdn-image-wrap:hover img,
.hn-gallery-item:hover img,
.hn-cdn-image-wrap:hover img {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}