/* =============================================================================
   STL Slots Chatbot — Widget Styles v2.1.1
   ============================================================================= */

:root {
    --stlslots-primary: #1a1a2e;
    --stlslots-accent:  #e94560;
    --stlslots-white:   #ffffff;
    --stlslots-bg:      #f8f9fa;
    --stlslots-text:    #333333;
    --stlslots-radius:  16px;
    --stlslots-shadow:  0 8px 32px rgba(0,0,0,.22);
    --stlslots-trans:   cubic-bezier(.4,0,.2,1);
}

/* =============================================================================
   Launcher
   ============================================================================= */
#stlslots-chat-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2147483640;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--stlslots-accent);
    color: var(--stlslots-white);
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 4px 18px rgba(0,0,0,.25);
    transition: transform .18s var(--stlslots-trans), box-shadow .18s var(--stlslots-trans), background .18s;
    user-select: none;
    touch-action: manipulation;
    outline-offset: 3px;
}
#stlslots-chat-launcher:hover,
#stlslots-chat-launcher:focus-visible {
    transform: scale(1.06) translateY(-2px);
    box-shadow: 0 6px 24px rgba(0,0,0,.32);
}
#stlslots-chat-launcher:active { transform: scale(.97); }
.stlslots-launcher-text {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
}

/* =============================================================================
   Chat window
   ============================================================================= */
#stlslots-chat-window {
    position: fixed;
    bottom: 88px;
    right: 24px;
    z-index: 2147483639;
    width: 360px;
    height: 540px;
    max-height: calc(100vh - 110px);   /* fallback for browsers without dvh */
    max-height: calc(100dvh - 110px);  /* dvh = true viewport height on mobile (no browser chrome) */
    background: var(--stlslots-white);
    border-radius: var(--stlslots-radius);
    box-shadow: var(--stlslots-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    color: var(--stlslots-text);
    /* Hidden */
    transform: scale(0.92) translateY(20px);
    opacity: 0;
    pointer-events: none;   /* BUG FIX: NOT "all" — Firefox ignores "all" */
    transition: transform .22s var(--stlslots-trans), opacity .22s var(--stlslots-trans);
}
#stlslots-chat-window.stlslots-open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: auto;   /* BUG FIX: "auto" is the correct valid value */
}

/* =============================================================================
   Header
   ============================================================================= */
#stlslots-chat-header {
    background: var(--stlslots-primary);
    color: var(--stlslots-white);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.stlslots-avatar { font-size: 22px; line-height: 1; flex-shrink: 0; }
.stlslots-header-info { flex: 1; display: flex; flex-direction: column; line-height: 1.3; }
.stlslots-bot-name { font-weight: 700; font-size: 15px; }
.stlslots-status  { font-size: 11px; opacity: .8; }

/* v2.1: Handoff + clear + close buttons */
#stlslots-handoff-btn,
#stlslots-chat-clear,
#stlslots-chat-close {
    background: transparent;
    border: none;
    color: rgba(255,255,255,.65);
    cursor: pointer;
    padding: 5px 6px;
    border-radius: 4px;
    line-height: 1;
    transition: color .15s, background .15s;
    touch-action: manipulation;
    font-size: 18px;
}
#stlslots-handoff-btn:hover,
#stlslots-chat-clear:hover,
#stlslots-chat-close:hover {
    color: var(--stlslots-white);
    background: rgba(255,255,255,.14);
}
/* Tooltip label on the handoff button */
#stlslots-handoff-btn {
    position: relative;
}
#stlslots-handoff-btn::after {
    content: 'Talk to a human';
    position: absolute;
    bottom: calc(100% + 6px);
    right: 0;
    background: rgba(0,0,0,.75);
    color: #fff;
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity .15s;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-weight: 400;
}
#stlslots-handoff-btn:hover::after { opacity: 1; }

/* =============================================================================
   Messages area
   ============================================================================= */
#stlslots-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}
/* Webkit scrollbar (Chrome, Safari, Edge) */
#stlslots-chat-messages::-webkit-scrollbar { width: 4px; }
#stlslots-chat-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 2px; }
/* Firefox scrollbar */
#stlslots-chat-messages { scrollbar-width: thin; scrollbar-color: #ddd transparent; }

/* Message rows */
.stlslots-msg-row {
    display: flex;
    flex-direction: column;
    max-width: 86%;
    margin-bottom: 6px;
    animation: stlslots-fade-in .2s ease-out;
}
@keyframes stlslots-fade-in {
    from { opacity:0; transform:translateY(6px); }
    to   { opacity:1; transform:translateY(0); }
}
.stlslots-user-row { align-self: flex-end; align-items: flex-end; }
.stlslots-bot-row  { align-self: flex-start; align-items: flex-start; }

/* Bubbles */
.stlslots-bubble {
    padding: 10px 13px;
    border-radius: 18px;
    line-height: 1.55;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
}
.stlslots-user-bubble {
    background: var(--stlslots-accent);
    color: var(--stlslots-white);
    border-bottom-right-radius: 4px;
}
.stlslots-bot-bubble {
    background: var(--stlslots-bg);
    color: var(--stlslots-text);
    border-bottom-left-radius: 4px;
    border: 1px solid #e8e8e8;
}
/* Links — must be clickable and visually distinct */
.stlslots-bot-bubble .stlslots-link {
    color: var(--stlslots-accent);
    text-decoration: underline;
    word-break: break-all;
    cursor: pointer;
}
.stlslots-bot-bubble .stlslots-link:hover { opacity: .8; }

/* Timestamps */
.stlslots-timestamp { font-size: 10px; color: #bbb; margin-top: 3px; padding: 0 4px; }

/* Feedback buttons */
.stlslots-feedback { display: flex; gap: 4px; margin-top: 4px; }
.stlslots-feedback-btn {
    background: none;
    border: 1px solid #e0e0e0;
    border-radius: 50px;
    padding: 2px 8px;
    font-size: 13px;
    cursor: pointer;
    line-height: 1.4;
    transition: background .15s, border-color .15s, transform .1s;
    touch-action: manipulation;
}
.stlslots-feedback-btn:hover { background: var(--stlslots-bg); transform: scale(1.1); }
.stlslots-feedback-btn.stlslots-fb-active {
    background: var(--stlslots-primary);
    color: var(--stlslots-white);
    border-color: var(--stlslots-primary);
}

/* Follow-up / quick-reply chips */
.stlslots-quick-replies {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 4px 0 8px;
    align-items: flex-start;
}
.stlslots-chip {
    background: var(--stlslots-white);
    border: 1.5px solid var(--stlslots-accent);
    color: var(--stlslots-accent);
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    min-height: 44px;    /* minimum touch target */
    display: flex;
    align-items: center;
    transition: background .15s, color .15s;
    touch-action: manipulation;
    text-align: left;
    line-height: 1.3;
}
.stlslots-chip:hover { background: var(--stlslots-accent); color: var(--stlslots-white); }

/* =============================================================================
   Typing indicator
   ============================================================================= */
#stlslots-typing-indicator {
    display: none;
    align-items: center;
    gap: 4px;
    padding: 8px 18px 0;
    flex-shrink: 0;
}
#stlslots-typing-indicator span {
    width: 7px; height: 7px;
    background: #bbb; border-radius: 50%;
    animation: stlslots-bounce 1.2s infinite ease-in-out;
}
#stlslots-typing-indicator span:nth-child(1) { animation-delay: 0s;   }
#stlslots-typing-indicator span:nth-child(2) { animation-delay: .2s;  }
#stlslots-typing-indicator span:nth-child(3) { animation-delay: .4s;  }
@keyframes stlslots-bounce {
    0%,60%,100% { transform:translateY(0);    opacity:.4; }
    30%         { transform:translateY(-6px); opacity:1;  }
}

/* =============================================================================
   Input area
   ============================================================================= */
#stlslots-chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 10px 12px;
    border-top: 1px solid #eee;
    background: var(--stlslots-white);
    flex-shrink: 0;
}
#stlslots-chat-input {
    flex: 1;
    border: 1.5px solid #ddd;
    border-radius: 20px;
    padding: 9px 14px;
    font-size: 16px;   /* BUG FIX: 16px prevents iOS auto-zoom */
    line-height: 1.4;
    font-family: inherit;
    resize: none;
    overflow: hidden;
    max-height: 120px;
    outline: none;
    transition: border-color .18s;
    touch-action: manipulation;
}
#stlslots-chat-input:focus { border-color: var(--stlslots-accent); }
#stlslots-char-count { font-size: 11px; color: #aaa; white-space: nowrap; align-self: center; min-width: 28px; text-align: right; }
#stlslots-chat-send {
    background: var(--stlslots-accent);
    color: var(--stlslots-white);
    border: none;
    border-radius: 50%;
    width: 40px; height: 40px;
    flex-shrink: 0;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s, transform .15s;
    touch-action: manipulation;
}
#stlslots-chat-send:hover:not(:disabled) { transform: scale(1.06); }
#stlslots-chat-send:disabled { opacity: .5; cursor: not-allowed; }

/* =============================================================================
   Footer
   ============================================================================= */
#stlslots-chat-footer {
    text-align: center;
    font-size: 11px;
    color: #aaa;
    padding: 6px 12px 8px;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
}
#stlslots-chat-footer a { color: var(--stlslots-accent); text-decoration: none; }
#stlslots-chat-footer a:hover { text-decoration: underline; }

/* =============================================================================
   Mobile — full-screen under 480px
   ============================================================================= */
@media (max-width: 480px) {
    #stlslots-chat-window {
        top: 0; right: 0; bottom: 0; left: 0;
        width: 100%; height: 100%; max-height: 100%;
        border-radius: 0;
        bottom: unset;
    }
    #stlslots-chat-launcher {
        bottom: 16px; right: 16px;
        width: 60px; height: 60px;
        padding: 0; justify-content: center; border-radius: 50%;
    }
    .stlslots-launcher-text { display: none; }
    #stlslots-chat-input { font-size: 16px; }
    /* Hide handoff tooltip on mobile — no hover */
    #stlslots-handoff-btn::after { display: none; }
}

/* =============================================================================
   Accessibility
   ============================================================================= */
#stlslots-chat-launcher:focus-visible,
#stlslots-chat-close:focus-visible,
#stlslots-chat-clear:focus-visible,
#stlslots-handoff-btn:focus-visible,
#stlslots-chat-send:focus-visible,
.stlslots-chip:focus-visible,
.stlslots-feedback-btn:focus-visible {
    outline: 2px solid var(--stlslots-accent);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    #stlslots-chat-window, #stlslots-chat-launcher,
    .stlslots-msg-row, .stlslots-chip, .stlslots-feedback-btn {
        transition: none; animation: none;
    }
}
