/* =============================================
   RVT Chatbot Widget
   ============================================= */

#tri-chatbot-container {
    position: fixed;
    bottom: 70px;
    right: 24px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

/* Toggle Button */
#tri-chatbot-toggle {
    width: 70px !important;
    height: 70px !important;
    min-width: 70px !important;
    min-height: 70px !important;
    border-radius: 50% !important;
    background: #2c6fad !important;
    border: none !important;
    cursor: grab;                /* A: hint draggability */
    user-select: none;           /* prevent text selection during drag */
    -webkit-user-select: none;
    touch-action: none;          /* let our touch handlers fire instead of scroll */
    display: flex !important;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    transition: background 0.2s, transform 0.2s;
    outline: none !important;
    padding: 0 !important;
    overflow: hidden;
    -webkit-appearance: none;
    appearance: none;
}
#tri-chatbot-toggle:hover { background: #1e5a96; transform: scale(1.05); }

/* Quill avatar icon */
#tri-chatbot-toggle {
    background: linear-gradient(135deg, #ffffff 0%, #f0e7ff 100%) !important;
    border: 2px solid #2c6fad !important;
}
#tri-chatbot-toggle:hover {
    background: linear-gradient(135deg, #ffffff 0%, #e8dcff 100%) !important;
    transform: scale(1.06);
}
/* A: while user is actively dragging, force the grabbing cursor everywhere */
body.tri-chatbot-dragging, body.tri-chatbot-dragging * { cursor: grabbing !important; }

/* Disable native HTML5 image-drag on the icon images so our custom drag handler
   gets the mousedown cleanly instead of competing with the browser's image drag. */
#tri-chatbot-toggle img,
#tri-chatbot-icon-open,
#tri-chatbot-icon-close {
    -webkit-user-drag: none;
    user-drag: none;
    pointer-events: none;
}

/* C: one-time wiggle to invite interaction (added via JS, removed after animation) */
@keyframes tri-wiggle {
    0%, 100% { transform: translateX(0) rotate(0); }
    10%      { transform: translateX(-6px) rotate(-6deg); }
    20%      { transform: translateX( 6px) rotate( 6deg); }
    30%      { transform: translateX(-5px) rotate(-5deg); }
    40%      { transform: translateX( 5px) rotate( 5deg); }
    50%      { transform: translateX(-3px) rotate(-3deg); }
    60%      { transform: translateX( 3px) rotate( 3deg); }
    70%      { transform: translateX(-1px) rotate(-1deg); }
    80%      { transform: translateX( 1px) rotate( 1deg); }
}
#tri-chatbot-toggle.tri-chatbot-wiggle { animation: tri-wiggle 1.2s ease-in-out 1; }

/* B: "drag me" hint bubble next to Quill (added via JS) */
#tri-chatbot-drag-hint {
    position: absolute;
    bottom: 78px;
    right: 0;
    width: 320px;
    max-width: 90vw;
    background: #152b6b;
    color: #ffffff;
    padding: 10px 32px 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.4;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: auto;
    z-index: 10;
    white-space: normal;
}
#tri-chatbot-drag-hint.tri-drag-hint-visible { opacity: 1; transform: translateY(0); }
#tri-chatbot-drag-hint::after {
    content: '';
    position: absolute;
    bottom: -7px;
    right: 22px;
    border: 7px solid transparent;
    border-top-color: #152b6b;
    border-bottom: 0;
}
#tri-chatbot-drag-hint-close {
    position: absolute;
    top: 4px;
    right: 6px;
    background: transparent;
    border: 0;
    color: rgba(255,255,255,0.7);
    font-size: 16px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
#tri-chatbot-drag-hint-close:hover { color: #fff; }

#tri-chatbot-icon-open {
    width: 58px !important;
    height: 58px !important;
    object-fit: contain;
    display: block;
}
#tri-chatbot-icon-close {
    color: #2c6fad !important;
    font-weight: bold;
}


/* Chat Window */
#tri-chatbot-window {
    position: absolute;
    bottom: 114px;
    right: 0;
    width: 360px;
    max-height: 520px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: tri-slide-up 0.2s ease;
}

@keyframes tri-slide-up {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Header */
#tri-chatbot-header {
    background: #2c6fad;
    color: #fff !important;
    padding: 14px 16px;
    font-weight: 600;
    font-size: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
#tri-chatbot-close {
    background: transparent;
    border: none;
    color: #fff !important;
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    opacity: 0.8;
}
#tri-chatbot-close:hover { opacity: 1; }

/* Messages Area */
#tri-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.tri-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}
.tri-msg-user {
    align-self: flex-end;
    background: #2c6fad;
    color: #fff !important;
    border-bottom-right-radius: 4px;
}
.tri-msg-bot {
    align-self: flex-start;
    background: #f1f3f5;
    color: #222;
    border-bottom-left-radius: 4px;
}
.tri-msg-bot.tri-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
}
.tri-dot {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: tri-bounce 1.2s infinite;
}
.tri-dot:nth-child(2) { animation-delay: 0.2s; }
.tri-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes tri-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40%           { transform: translateY(-6px); }
}

/* Input Area */
#tri-chatbot-input-area {
    display: flex;
    align-items: flex-end;
    padding: 12px;
    border-top: 1px solid #e9ecef;
    gap: 8px;
    flex-shrink: 0;
}
#tri-chatbot-input {
    flex: 1;
    resize: none;
    border: 1px solid #dee2e6;
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    max-height: 100px;
    overflow-y: auto;
    line-height: 1.4;
    transition: border-color 0.15s;
}
#tri-chatbot-input:focus { border-color: #2c6fad; }
#tri-chatbot-send {
    width: 38px;
    height: 38px;
    background: #2c6fad;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
    color: #fff !important;
    font-size: 18px !important;
    line-height: 1;
    padding: 0;
}
#tri-chatbot-send:hover { background: #1e5a96; }
#tri-chatbot-send:disabled { background: #adb5bd; cursor: not-allowed; }

/* Mobile */
@media (max-width: 480px) {
    #tri-chatbot-window {
        width: calc(100vw - 32px);
        right: -8px;
        bottom: 110px;
    }
}

/* ---- Attention bubble ---- */
#tri-chatbot-bubble {
    background: linear-gradient(135deg, #2c6fad 0%, #1e5a96 100%) !important;
    border-radius: 16px 16px 4px 16px;
    padding: 16px 18px;
    box-shadow: 0 6px 24px rgba(44,111,173,0.35);
    font-size: 13px;
    line-height: 1.6;
    color: #fff !important;
    white-space: normal;
    display: none;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    order: 1;
    position: relative;
    max-width: 300px;
    animation: tri-bubble-pop 0.4s ease;
}
@keyframes tri-bubble-pop {
    0%   { transform: scale(0.8) translateY(10px); opacity: 0; }
    60%  { transform: scale(1.03) translateY(-2px); opacity: 1; }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}
#tri-chatbot-bubble::after {
    content: '';
    position: absolute;
    bottom: -7px;
    right: 18px;
    border-left: 7px solid transparent;
    border-right: 0 solid transparent;
    border-top: 8px solid #1e5a96;
}
#tri-chatbot-bubble.tri-bubble-visible {
    display: flex;
}
#tri-chatbot-bubble-close {
    background: transparent;
    border: none;
    cursor: pointer;
    color: rgba(255,255,255,0.6) !important;
    font-size: 16px;
    line-height: 1;
    padding: 0 0 0 4px;
    flex-shrink: 0;
}
#tri-chatbot-bubble-close:hover { color: #fff !important; }
#tri-chatbot-toggle { order: 2; }
#tri-chatbot-window { order: 0; }

/* Formatted bot responses */
.tri-msg-bot ul {
    margin: 6px 0 4px 0;
    padding-left: 18px;
    list-style: disc;
}
.tri-msg-bot li {
    margin-bottom: 4px;
}
.tri-msg-bot strong {
    font-weight: 600;
}
.tri-msg-bot a {
    word-break: break-all;
}

/* Kill any theme/Elementor overrides on toggle */
#tri-chatbot-toggle::before,
#tri-chatbot-toggle::after {
    display: none !important;
    content: none !important;
}
#tri-chatbot-toggle *::before,
#tri-chatbot-toggle *::after {
    display: none !important;
    content: none !important;
}
#tri-chatbot-toggle {
    background-image: none !important;
    text-decoration: none !important;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25) !important;
    text-shadow: none !important;
}

/* Hide Astra scroll-to-top — conflicts with chatbot position */
#ast-scroll-top {
    display: none !important;
}

/* Exit survey */
#tri-chatbot-survey {
    padding: 18px 16px;
    overflow-y: auto;
    flex: 1;
}
#tri-chatbot-survey .tri-survey-group {
    margin-bottom: 14px;
}
#tri-chatbot-survey .tri-survey-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #333;
    margin-bottom: 6px;
}
#tri-chatbot-survey .tri-survey-options {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
#tri-chatbot-survey .tri-survey-options label {
    font-size: 13px;
    color: #444;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
#tri-chatbot-survey .tri-survey-options input[type="radio"] {
    accent-color: #2c6fad;
}
#tri-chatbot-survey textarea {
    width: 100%;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 13px;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 6px;
    resize: vertical;
}
#tri-chatbot-survey textarea:focus {
    border-color: #2c6fad;
    outline: none;
}
#tri-chatbot-survey .tri-survey-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 10px;
}
#tri-chatbot-survey .tri-btn-primary {
    background: #2c6fad;
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
}
#tri-chatbot-survey .tri-btn-primary:hover { background: #1e5a96; }
#tri-chatbot-survey .tri-btn-primary:disabled { opacity: 0.5; cursor: default; }
#tri-chatbot-survey .tri-btn-secondary {
    background: transparent;
    color: #666;
    border: 1px solid #ccc;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}
#tri-chatbot-survey .tri-btn-secondary:hover { background: #f5f5f5; }
