/* GNA AI Chatbot v4.2 — Frontend Styles
   Mobile-first responsive. Tested on iOS Safari & Android Chrome.
   ---------------------------------------------------------------- */

/* ── Base widget container ── */
#gna-chat-widget {
    position: fixed;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1;
    box-sizing: border-box;
}

#gna-chat-widget *,
#gna-chat-widget *::before,
#gna-chat-widget *::after {
    box-sizing: border-box;
}

/* Desktop positioning */
#gna-chat-widget.gna-pos-right { right: 24px; bottom: 24px; }
#gna-chat-widget.gna-pos-left  { left:  24px; bottom: 24px; }

/* ── Toggle button ── */
#gna-chat-toggle {
    width: 58px !important;
    height: 58px !important;
    border-radius: 50% !important;
    border: none !important;
    cursor: pointer;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    color: #fff !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.28);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    outline: none;
    padding: 0 !important;
    margin: 0 !important;
    text-transform: none !important;
    letter-spacing: normal !important;
    line-height: 1 !important;
    background-clip: padding-box;
    -webkit-tap-highlight-color: transparent;
}

#gna-chat-toggle svg {
    stroke: #fff !important;
    fill: none !important;
    width: 26px !important;
    height: 26px !important;
    flex-shrink: 0;
    pointer-events: none;
    display: block;
}

#gna-chat-toggle:hover         { transform: scale(1.07); box-shadow: 0 6px 28px rgba(0,0,0,0.35); }
#gna-chat-toggle:focus-visible { outline: 3px solid rgba(255,255,255,0.8); outline-offset: 2px; }

/* ── Chat window — DESKTOP ── */
#gna-chat-window {
    position: absolute;
    bottom: 74px;
    width: 340px;
    max-height: 560px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(12px) scale(0.97);
    transition: opacity 0.22s ease, transform 0.22s ease;
    pointer-events: none;
}

#gna-chat-widget.gna-pos-right #gna-chat-window { right: 0; left: auto; }
#gna-chat-widget.gna-pos-left  #gna-chat-window { left:  0; right: auto; }

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

/* ── Header ── */
#gna-chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    color: #fff;
    flex-shrink: 0;
}

#gna-chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#gna-chat-avatar svg {
    stroke: #fff !important;
    fill: none !important;
    width: 18px !important;
    height: 18px !important;
}

#gna-chat-title  { font-size: 15px; font-weight: 600; line-height: 1.2; }
#gna-chat-status { font-size: 12px; opacity: 0.8; line-height: 1.2; }

/* ── Messages ── */
#gna-chat-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    min-height: 80px;
}

#gna-chat-messages::-webkit-scrollbar       { width: 4px; }
#gna-chat-messages::-webkit-scrollbar-track { background: transparent; }
#gna-chat-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

.gna-msg      { display: flex; max-width: 100%; }
.gna-msg-user { justify-content: flex-end; }
.gna-msg-bot  { justify-content: flex-start; }

.gna-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.55;
    max-width: 82%;
    word-break: break-word;
    white-space: pre-wrap;
}

.gna-msg-user .gna-bubble { color: #fff; border-bottom-right-radius: 4px; }
.gna-msg-bot  .gna-bubble { background: #f1f3f5; color: #1a1a2e; border-bottom-left-radius: 4px; }

/* Typing indicator */
.gna-typing .gna-bubble { background: #f1f3f5; padding: 12px 16px; }
.gna-dots { display: flex; gap: 5px; align-items: center; height: 16px; }
.gna-dots span {
    width: 7px; height: 7px;
    border-radius: 50%; background: #aaa;
    animation: gna-bounce 1.2s infinite ease-in-out;
}
.gna-dots span:nth-child(2) { animation-delay: 0.2s; }
.gna-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes gna-bounce {
    0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
    40%            { transform: scale(1);   opacity: 1;   }
}

/* ── Quick Replies ── */
#gna-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 10px 14px 4px;
    flex-shrink: 0;
}

.gna-qr-btn {
    padding: 7px 14px;
    border-radius: 20px;
    border: 1.5px solid;
    background: transparent !important;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity 0.15s;
    line-height: 1.4;
    text-transform: none !important;
    letter-spacing: normal !important;
    font-weight: 500 !important;
    box-shadow: none !important;
    min-height: 34px;
    -webkit-tap-highlight-color: transparent;
}

.gna-qr-btn:hover  { opacity: 0.75; }
.gna-qr-btn:active { opacity: 0.55; }

/* ── Business Contact Bar ── */
#gna-contact-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 2px 14px 10px;
    flex-shrink: 0;
}

.gna-contact-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border-radius: 20px;
    border: 1.5px solid;
    background: transparent;
    font-size: 12.5px;
    font-weight: 500;
    text-decoration: none;
    line-height: 1.3;
    white-space: nowrap;
    transition: opacity 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.gna-contact-item:hover  { opacity: 0.75; }
.gna-contact-item:active { opacity: 0.55; }
.gna-contact-item svg    { flex-shrink: 0; stroke: currentColor !important; fill: none !important; }

.gna-contact-quote { border: none; font-weight: 600; }

@media (max-width: 600px) {
    #gna-contact-bar {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    #gna-contact-bar::-webkit-scrollbar { display: none; }
}

/* ── Lead / Handoff Form ── */
#gna-lead-form {
    padding: 12px 14px;
    border-top: 1px solid #eee;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #fafafa;
    flex-shrink: 0;
}

#gna-lead-form input {
    border: 1.5px solid #e0e0e0 !important;
    border-radius: 8px !important;
    padding: 10px 12px !important;
    font-size: 16px !important;
    font-family: inherit !important;
    outline: none !important;
    background: #fff !important;
    color: #1a1a2e !important;
    transition: border-color 0.15s;
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    box-shadow: none !important;
}

#gna-lead-form input:focus     { border-color: #999 !important; }
#gna-lead-form input::placeholder { color: #aaa; }

#gna-lead-submit {
    border: none !important;
    border-radius: 8px !important;
    padding: 11px 14px !important;
    color: #fff !important;
    font-size: 14px !important;
    font-family: inherit !important;
    cursor: pointer;
    font-weight: 600 !important;
    transition: opacity 0.15s;
    width: 100%;
    text-transform: none !important;
    letter-spacing: normal !important;
    box-shadow: none !important;
    -webkit-tap-highlight-color: transparent;
}

#gna-lead-submit:hover    { opacity: 0.88; }
#gna-lead-submit:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Input Area ── */
#gna-chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #eee;
    background: #fff;
    flex-shrink: 0;
}

#gna-chat-input {
    flex: 1;
    border: 1.5px solid #e0e0e0 !important;
    border-radius: 10px !important;
    padding: 9px 12px !important;
    font-size: 16px !important;
    font-family: inherit !important;
    resize: none;
    max-height: 100px;
    outline: none !important;
    line-height: 1.45;
    color: #1a1a2e !important;
    background: #fafafa !important;
    transition: border-color 0.15s;
    -webkit-appearance: none;
    appearance: none;
    box-shadow: none !important;
}

#gna-chat-input:focus        { border-color: #999 !important; background: #fff !important; }
#gna-chat-input::placeholder { color: #aaa; }

#gna-chat-send {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    border: none !important;
    border-radius: 10px !important;
    cursor: pointer;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    color: #fff !important;
    flex-shrink: 0;
    transition: opacity 0.15s, transform 0.15s;
    outline: none;
    padding: 0 !important;
    box-shadow: none !important;
    text-transform: none !important;
    -webkit-tap-highlight-color: transparent;
}

#gna-chat-send svg {
    stroke: #fff !important;
    fill: none !important;
    width: 18px !important;
    height: 18px !important;
    flex-shrink: 0;
    pointer-events: none;
    display: block !important;
}

#gna-chat-send:hover         { opacity: 0.88; transform: scale(1.05); }
#gna-chat-send:active        { transform: scale(0.95); }
#gna-chat-send:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
#gna-chat-send:disabled      { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ── Error ── */
.gna-msg-error .gna-bubble {
    background: #fff0f0;
    color: #c0392b;
    border: 1px solid #fdd;
}

/* ════════════════════════════════════════════════════
   MOBILE — floating card layout
   Covers all iPhones incl. 16 Pro Max (430px),
   Galaxy S series (360–412px), and tablets in portrait.
   The window floats with a margin from the screen edges
   (not edge-to-edge) so it reads as a card, not a sheet.
   ════════════════════════════════════════════════════ */
@media (max-width: 600px) {

    /* Widget wrapper spans full width at bottom — just a positioning host */
    #gna-chat-widget.gna-pos-right,
    #gna-chat-widget.gna-pos-left {
        position: fixed !important;
        right: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        top: auto !important;
        width: 100% !important;
        padding: 0 !important;
        pointer-events: none; /* passthrough except toggle */
    }

    /* Toggle pinned in corner, always interactive */
    #gna-chat-toggle {
        position: fixed !important;
        bottom: 20px !important;
        pointer-events: all !important;
        z-index: 100000;
    }

    #gna-chat-widget.gna-pos-right #gna-chat-toggle {
        right: 16px !important;
        left: auto !important;
    }
    #gna-chat-widget.gna-pos-left #gna-chat-toggle {
        left:  16px !important;
        right: auto !important;
    }

    /* Chat window: floating card with margin on every side, not edge-to-edge */
    #gna-chat-window {
        position: fixed !important;
        left: 10px !important;
        right: 10px !important;
        bottom: calc(10px + env(safe-area-inset-bottom)) !important;
        top: auto !important;
        width: auto !important;
        /* dvh = dynamic viewport height (excludes iOS browser chrome) */
        max-height: calc(80dvh - 10px);
        max-height: calc(80vh - 10px); /* fallback */
        border-radius: 20px !important; /* rounded on all corners now it's a floating card */
        /* Override desktop absolute+right/left positioning */
        transform: translateY(20px);
        opacity: 0;
        pointer-events: none;
        box-shadow: 0 12px 40px rgba(0,0,0,0.28), 0 2px 10px rgba(0,0,0,0.14);
    }

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

    /* Allow interaction when open */
    #gna-chat-widget.gna-chat-is-open {
        pointer-events: all !important;
    }

    /* Quick replies: horizontal scroll, no wrap */
    #gna-quick-replies {
        overflow-x: auto;
        overflow-y: hidden;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 8px;
    }
    #gna-quick-replies::-webkit-scrollbar { display: none; }

    /* Slightly larger text on mobile */
    .gna-bubble  { font-size: 15px; }
    .gna-qr-btn  { min-height: 38px; }

    /* Input area no longer needs its own safe-area padding — the window's
       bottom offset already clears the home-indicator bar */
    #gna-chat-input-area {
        padding-bottom: 10px;
    }

    /* Prevent rubber-band scroll bleeding through */
    #gna-chat-messages {
        overscroll-behavior: contain;
    }
}

/* Extra-small screens — iPhone SE 1st gen (320px), old Android */
@media (max-width: 375px) {
    #gna-chat-window {
        max-height: calc(88dvh - 10px);
        max-height: calc(88vh - 10px);
    }
    .gna-bubble { font-size: 14px; }
}
