/* ==============================================================
   OPTIMIZED CHATBOT STYLES – MOBILE‑FIRST
   --------------------------------------------------------------
   The popup never exceeds 50 % of the viewport height.
   --------------------------------------------------------------
   All colours, spacing, radii, etc. are pulled from your existing
   design‑tokens (e.g. var(--gradient-primary), var(--radius-full) …)
   ============================================================== */

/* ------------------------------------------------------------------
   CSS CUSTOM PROPERTIES (Design Tokens)
   ------------------------------------------------------------------ */
:root {
    /* Colors */
    --gradient-primary: linear-gradient(135deg, #0066cc 0%, #0052a3 100%);
    --c-white: #ffffff;
    --danger-red: #dc2626;
    --light-gray: #e5e7eb;
    --medium-gray: #6b7280;
    --dark-gray: #1f2937;
    --primary-blue: #0066cc;
    --primary-blue-light: #60a5fa;
    --primary-blue-dark: #0052a3;
    --secondary-light: #f9fafb;
    --success-green: #10b981;
    
    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    
    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;
    
    /* Typography */
    --text-xs: 12px;
    --text-sm: 14px;
    --text-base: 16px;
    --text-lg: 18px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;

    /* Shadows */
    --shadow-xl: 0 16px 50px rgba(0,0,0,0.15);

    /* Font */
    --font-primary: 'Exo 2', sans-serif;

    /* Layout */
    --chatbot-header-offset: 70px;
}

/* ------------------------------------------------------------------
   1️⃣  Trigger button (FAB)
   ------------------------------------------------------------------ */
.chatbot-trigger {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: var(--gradient-primary);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0,102,204,.3);
    z-index: 9999;
    transition: transform var(--transition-normal);
    border: 2px solid var(--c-white);
}
.chatbot-trigger:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(0,102,204,.6);
}
.chatbot-trigger::before {
    content: "💬";
    font-size: 24px;
}

/* Notification badge (unread count) */
.chatbot-notification {
    position: absolute;
    inset-inline-end: -5px;
    inset-block-start: -5px;
    width: 18px;
    height: 18px;
    background: var(--danger-red);
    color: var(--c-white);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--c-white);
    z-index: 1;
    animation: pulse 2s infinite;
}

/* ------------------------------------------------------------------
   2️⃣  Popup – container, header, body
   ------------------------------------------------------------------ */
.chatbot-popup {
    position: fixed;
    inset-inline-end: 30px;
    inset-block-end: 100px;
    width: min(380px, calc(100vw - 40px));

    /* ---- HEIGHT LIMIT: never taller than 50 % of the viewport ---- */
    height: min(500px, 70vh, 50vh);   /* desktop fallback, but 50vh is the max */
    max-height: 80vh;                /* safety net for very tall screens */

    background: var(--c-white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--light-gray);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(.95);
    opacity: 0;
    visibility: hidden;
    transition: transform var(--transition-normal),
                opacity var(--transition-normal);
    will-change: transform, opacity;
    font-family: var(--font-primary);
}

/* When the popup is open */
.chatbot-popup.active {
    transform: translateY(0) scale(1);
    opacity: 1;
    visibility: visible;

}

/* Minimized “bubble” – works on every breakpoint */
.chatbot-popup.minimized {
    width: 60px;
    height: 60px;
    border-radius: var(--radius-full);
    inset-inline-end: 20px;
    inset-block-end: 20px;
    transform: none;
}
.chatbot-popup.minimized .chatbot-content { display: none; }

/* ------------------------------------------------------------------
   3️⃣  Header (drag handle, close/minimize)
   ------------------------------------------------------------------ */
.chatbot-header {
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md);
    background: var(--gradient-primary);
    color: var(--c-white);
    cursor: move;
    user-select: none;
}
.chatbot-title {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: var(--text-base);
    font-weight: 600;
}
.bot-avatar {
    width: 32px;
    height: 32px;
    background: rgba(255,255,255,.2);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
}
.bot-status {
    font-size: var(--text-xs);
    opacity: .9;
    display: flex;
    align-items: center;
    gap: 4px;
}
.bot-status::before {
    content: "";
    width: 6px;
    height: 6px;
    background: var(--success-green);
    border-radius: var(--radius-full);
}
.chatbot-controls button {
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    color: var(--c-white);
    font-size: var(--text-lg);
    border-radius: 4px;
    cursor: pointer;
    transition: background var(--transition-fast);
}
.chatbot-controls button:hover {
    background: rgba(255,255,255,.15);
}

/* ------------------------------------------------------------------
   4️⃣  Body – flex container that fills the popup height
   ------------------------------------------------------------------ */
.chatbot-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;               /* crucial for internal scrolling */
    background: var(--secondary-light);
}

/* ------------------------------------------------------------------
   5️⃣  Quick‑question bar
   ------------------------------------------------------------------ */
.quick-questions {
    flex-shrink: 0;
    padding: var(--space-md);
    border-bottom: 1px solid var(--light-gray);
    background: var(--c-white);
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
}
.quick-question {
    flex: 1 1 calc(50% - var(--space-sm));
    min-width: 0;
    padding: var(--space-sm) var(--space-md);
    background: rgba(0,102,204,.08);
    border: 1px solid rgba(0,102,204,.2);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    color: var(--primary-blue);
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    transition: background var(--transition-fast);
}
.quick-question:hover {
    background: rgba(0,102,204,.15);
}

/* ------------------------------------------------------------------
   6️⃣  Chat messages – the only scrolling part
   ------------------------------------------------------------------ */
.chat-messages {
    flex: 1;                     /* take all remaining space */
    min-height: 0;               /* allow flex‑shrink */
    padding: var(--space-md);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Individual messages */
.message {
    max-width: 85%;
    animation: msgSlide .2s ease-out;
}
@keyframes msgSlide {
    from { opacity:0; transform:translateY(10px); }
    to   { opacity:1; transform:translateY(0); }
}
.bot-message { align-self:flex-start; }
.user-message{ align-self:flex-end; }

.message-content {
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-lg);
    font-size: var(--text-sm);
    line-height:1.4;
}
.bot-message .message-content {
    background: var(--c-white);
    border: 1px solid var(--light-gray);
    color: var(--dark-gray);
}
.user-message .message-content {
    background: var(--primary-blue);
    color: var(--c-white);
}
.message-time {
    margin-top:2px;
    font-size: var(--text-xs);
    color: var(--medium-gray);
}

/* ------------------------------------------------------------------
   7️⃣  Typing indicator
   ------------------------------------------------------------------ */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: var(--space-sm);
    background:black;
    
    width: fit-content;
}
.typing-dot {
    width: 4px;
    height: 4px;
    background: var(--primary-blue-light);
    border-radius: var(--radius-full);
    animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(1){ animation-delay:-.32s; }
.typing-dot:nth-child(2){ animation-delay:-.16s; }
@keyframes typingBounce{
    0%,80%,100%{ transform:scale(.7); opacity:.5; }
    40%{ transform:scale(1); opacity:1; }
}

/* ------------------------------------------------------------------
   8️⃣  Suggestion card
   ------------------------------------------------------------------ */
.suggestion-message{
    background:#f0f9ff;
    border:1px solid #bae6fd;
    border-radius:12px;
    padding:12px;
    margin-top:8px;
}
.suggestion-content{
    display:flex;
    flex-direction:column;
    gap:8px;
}
.suggestion-content span{
    font-size:12px;
    color:#0369a1;
    font-weight:500;
}
.suggestion-btn{
    background:#fff;
    border:1px solid #38bdf8;
    color:#0369a1;
    padding:8px 12px;
    border-radius:8px;
    cursor:pointer;
    font-size:14px;
    text-align:left;
    transition:background .2s,border-color .2s;
}
.suggestion-btn:hover{
    background:#f0f9ff;
    border-color:#0284c7;
}

/* ------------------------------------------------------------------
   9️⃣  Input area (sticky foot on mobile)
   ------------------------------------------------------------------ */
.chat-input-area{
    flex-shrink:0;
    padding: var(--space-md);
    border-top: black;
    background: black;
}
.input-wrapper{
    display:flex;
    gap:var(--space-sm);
    align-items:center;
}
.chat-input{
    flex:1;
    padding: var(--space-sm) var(--space-md);
    border:1px solid var(--light-gray);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    line-height:1.4;
    resize:none;
    min-height:40px;
    background:var(--c-white);
    color: black;
    outline:none;
    transition:border-color var(--transition-fast);
}
.chat-input:focus{
    border-color:var(--primary-blue);
    box-shadow:0 0 0 3px rgba(0,102,204,.12);
}
.send-button{
    width:40px;
    height:40px;
    border-radius:var(--radius-full);
    background:var(--primary-blue);
    color:var(--c-white);
    border:none;
    cursor:pointer;
    font-size:var(--text-base);
    display:flex;
    align-items:center;
    justify-content:center;
    transition:background var(--transition-fast),
                transform var(--transition-fast);
}
.send-button:hover:not(:disabled){
    background:var(--primary-blue-dark);
    transform:scale(1.05);
}
.send-button:disabled{
    opacity:.5;
    cursor:not-allowed;
}
.chat-disclaimer{
    margin-top:var(--space-sm);
    text-align:center;
    color:var(--medium-gray);
    font-size:var(--text-xs);
    opacity:.7;
}

/* ------------------------------------------------------------------
   10️⃣  Misc helpers (price highlight, feature list)
   ------------------------------------------------------------------ */
.price-highlight{ color:#059669; font-weight:600; }
.feature-list{
    list-style:none;
    padding:0;
    margin:8px 0;
}
.feature-list li{
    padding:4px 0;
    display:flex;
    align-items:center;
    gap:8px;
}

/* ------------------------------------------------------------------
   11️⃣  MOBILE‑FIRST RESPONSIVE ADJUSTMENTS
   ------------------------------------------------------------------ */
@media (max-width:768px) {

    /* ---- POPUP – full‑width, capped at 50 vh ---- */
    .chatbot-popup.active{
        inset:0;                                         /* fill the screen horizontally */
        inset-block-start: var(--chatbot-header-offset);/* start just below the navbar   */
        inset-inline-start: 0;
        inset-inline-end: 0;
        height: 500px;
        width:83%;
        max-height: 500px;
        border-top-right-radius: 5%;                               /* square edges on mobile */
        box-shadow:none;
        transform:none;
    }

    /* Optional – shrink a bit more when the soft‑keyboard is visible */
    .chatbot-popup.active.keyboard-visible{
        height: calc(45vh - var(--chatbot-header-offset));
        max-height: calc(45vh - var(--chatbot-header-offset));
    }

    /* Minimized - stays in the corner */
    .chatbot-popup.minimized{
        inset-inline-end:20px;
        inset-block-end:20px;
        width:60px;
        height:60px;
        border-radius:var(--radius-full);
    }

    /* QUICK‑QUESTIONS stack vertically on narrow screens */
    .quick-questions{
        flex-direction:column;
        padding:var(--space-sm);
    }
    .quick-question{
        width:100%;
        flex:1 0 auto;
        padding:var(--space-md);
        font-size:var(--text-base);
    }

    /* INPUT AREA – safe‑area insets for iPhone‑X‑like devices */
    .chat-input-area{
        padding:var(--space-sm);
        padding-bottom:max(var(--space-sm), env(safe-area-inset-bottom, var(--space-sm)));
        position:sticky;
        bottom:0;
        z-index:2;
    }
    .chat-input{
        font-size:16px;           /* stop iOS zoom on focus */
        min-height:44px;          /* minimum touch target */
    }
    .send-button{
        min-width:44px;
        min-height:44px;
    }

    /* Hide the FAB while the chatbot is open */
    .chatbot-popup.active ~ .chatbot-trigger{
        display:none;
    }

    /* Prevent background page scroll while chatbot is open */
    body.chatbot-open{
        overflow:hidden;
        position:fixed;
        width:100%;
        height:100%;
    }
}

/* ------------------------------------------------------------------
   12️⃣  SMALL‑MOBILE (portrait) tweaks
   ------------------------------------------------------------------ */
@media (max-width:480px) and (max-height:480px){
    .chatbot-popup.active{
        height:calc(100vh - var(--chatbot-header-offset) - 60px); /* tiny extra room for close button */
        max-height:calc(100vh - var(--chatbot-header-offset) - 60px);
    }
    .chatbot-popup.active.keyboard-visible{
        height:calc(50vh - var(--chatbot-header-offset));
        max-height:calc(50vh - var(--chatbot-header-offset));
    }
    .chat-messages{ padding:8px; }
    .message{ max-width:90%; }
    .message-content{ padding:2px; font-size:14px; }


/* ------------------------------------------------------------------
   13️⃣  LANDSCAPE‑MOBILE tweaks
   ------------------------------------------------------------------ */
@media (max-width:900px) and (orientation:landscape){
    .chatbot-popup.active{
        height:calc(100vh - var(--chatbot-header-offset) - 80px);
        max-height:calc(100vh - var(--chatbot-header-offset) - 80px);
    }
    .chatbot-popup.active.keyboard-visible{
        height:calc(70vh - var(--chatbot-header-offset));
        max-height:calc(70vh - var(--chatbot-header-offset));
    }
    .chatbot-header{ padding:2px; }
    .chatbot-title{ font-size:9px; }
    .quick-questions{
        flex-direction:row;
        padding:2px;
    }
    .quick-question{
        padding:6px 10px;
        font-size:12px;
        flex:0 0 auto;
    }
    .chat-messages{ padding:8px; }
    .message{ max-width:75%; }
}

/* ------------------------------------------------------------------
   14️⃣  TABLET (mid‑size) tweaks
   ------------------------------------------------------------------ */
@media (min-width:769px) and (max-width:1024px){
    .chatbot-popup{
        width:min(350px,calc(100vw - 60px));
        height:min(500px,60vh);
        inset-inline-end:20px;
        inset-block-end:100px;
    }
}

/* ------------------------------------------------------------------
   15️⃣  DARK‑MODE SUPPORT
   ------------------------------------------------------------------ */
@media (prefers-color-scheme:dark){
    .chatbot-popup{
        background:#1e293b;
        border-color:rgba(255,255,255,.1);
    }
    .chatbot-content{ background:#cfd1d6; }
    .quick-questions{ background:#1e293b; }
    .quick-question{
        background:rgba(0,102,204,.15);
        border-color:rgba(0,102,255,.3);
        color:#fff;
    }
    .bot-message .message-content{
        background:#334155;
        border-color:rgba(255,255,255,.1);
        color:#eceaea;
    }
    .chat-input-area{
        background:#1e293b;
        border-top-color:rgba(255,255,255,.1);
    }
    .chat-input{
        background:#0f172a;
        border-color:rgba(255, 255, 255, 0.1);
        color:#3d3b3b;
    }
    .typing-indicator{
        background:#334155;
        border-color:rgba(255,255,255,.1);
    }
    .suggestion-message{
        background:rgba(3,105,161,.1);
        border-color:rgba(56,189,248,.3);
    }
    .suggestion-btn{
        background:#334155;
        color:#7dd3fc;
        border-color:rgba(56,189,248,.3);
    }
}

/* ------------------------------------------------------------------
   16️⃣  TOUCH‑DEVICE OPTIMIZATIONS
   ------------------------------------------------------------------ */
@media (hover:none) and (pointer:coarse){
    .chatbot-popup{ touch-action:pan-y pinch-zoom; }
    .chatbot-header{ cursor:default; }
    .quick-question{
        min-height:22px;
        display:flex;
        align-items:center;
        justify-content:center;
        -webkit-tap-highlight-color:transparent;
    }
    .chat-input{
        min-height:44px;
        font-size:16px;            /* avoid iOS zoom */
    }
    .send-button{
        min-width:44px;
        min-height:44px;
        -webkit-tap-highlight-color:transparent;
    }
    .chat-messages{
        scrollbar-width:none;      /* Firefox */
        -ms-overflow-style:none;  /* IE/Edge */
    }
    .chat-messages::-webkit-scrollbar{ display:none; }
}

/* ------------------------------------------------------------------
   17️⃣  PERFORMANCE & ACCESSIBILITY
   ------------------------------------------------------------------ */
@media (prefers-reduced-motion:reduce){
    .chatbot-popup,
    .message,
    .send-button,
    .quick-question,
    .typing-dot{
        transition:none !important;
        animation:none !important;
    }
}

/* ------------------------------------------------------------------
   18️⃣  Utility – pulse animation (badge)
   ------------------------------------------------------------------ */
@keyframes pulse{
    0%,100%{ opacity:1; }
    50%{ opacity:.5; }
}
}
}