/**
 * Tender Tracker V2 — AI Agent Widget
 */

/* Toggle button — pill with icon + label */
#tt-chatbot-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    height: 54px;
    border-radius: 27px;
    background: var(--k-blue, #5f80cf);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 6px 22px rgba(95, 128, 207, 0.45);
    z-index: 99998;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 22px 0 16px;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    animation: tt-chatbot-nudge 3.2s ease-in-out infinite;
}
#tt-chatbot-toggle:hover {
    transform: translateY(-2px) scale(1.03);
    background: #4a6bbf;
    box-shadow: 0 8px 28px rgba(95, 128, 207, 0.55);
    animation: none;
}
#tt-chatbot-toggle.active {
    display: none;
}
@keyframes tt-chatbot-nudge {
    0%, 100% { transform: translateY(0);    box-shadow: 0 6px 22px rgba(95, 128, 207, 0.45); }
    50%      { transform: translateY(-3px); box-shadow: 0 10px 28px rgba(95, 128, 207, 0.55); }
}

.tt-chatbot-toggle-icon {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.22);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
}
.tt-chatbot-toggle-label {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.3px;
}

/* Chat widget panel */
#tt-chatbot-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 400px;
    height: 560px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
    z-index: 99999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
}
#tt-chatbot-widget.open {
    display: flex;
}

/* Inline mode for shortcode */
#tt-chatbot-widget.inline {
    position: relative;
    bottom: auto;
    right: auto;
    width: 100%;
    height: 600px;
    border-radius: 12px;
    display: flex;
}

/* Header — gradient with agent identity */
.tt-chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: linear-gradient(135deg, var(--k-blue, #5f80cf) 0%, #4a6bbf 100%);
    color: #fff;
    flex-shrink: 0;
}

.tt-chatbot-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tt-chatbot-agent-avatar {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    flex-shrink: 0;
}

.tt-chatbot-title-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.tt-chatbot-title-name {
    font-size: 14px;
    font-weight: 600;
}
.tt-chatbot-title-status {
    font-size: 11px;
    font-weight: 400;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 5px;
}
.tt-chatbot-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
    animation: tt-status-pulse 2s infinite;
}
@keyframes tt-status-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.tt-chatbot-title i {
    font-size: 18px;
}

#tt-chatbot-close {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 15px;
    padding: 5px 9px;
    border-radius: 8px;
    opacity: 0.8;
    transition: opacity 0.15s, background 0.15s;
}
#tt-chatbot-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.2);
}

/* Messages area */
#tt-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: thin;
    background: #fafbfd;
}
#tt-chatbot-messages::-webkit-scrollbar {
    width: 5px;
}
#tt-chatbot-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

/* Messages */
.tt-chatbot-message {
    max-width: 88%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.55;
    word-wrap: break-word;
}

.tt-chatbot-message-user {
    align-self: flex-end;
    background: var(--k-blue, #5f80cf);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.tt-chatbot-message-assistant {
    align-self: flex-start;
    background: #fff;
    color: #1a1a1a;
    border: 1px solid #e8ebf0;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.tt-chatbot-msg-avatar {
    width: 26px;
    height: 26px;
    min-width: 26px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--k-blue, #5f80cf), var(--k-orange, #ff834a));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #fff;
    margin-top: 1px;
}

.tt-chatbot-msg-content {
    flex: 1;
    min-width: 0;
}

.tt-chatbot-message-assistant strong {
    font-weight: 600;
}

.tt-chatbot-message-error {
    align-self: center;
    background: #fef2f2;
    color: #b91c1c;
    border-radius: 8px;
    font-size: 12.5px;
    text-align: center;
}

/* Suggested prompts */
.tt-chatbot-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 16px 8px;
}

.tt-chatbot-suggestion {
    background: #fff;
    border: 1px solid #dde1e8;
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 12px;
    color: var(--k-blue, #5f80cf);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.tt-chatbot-suggestion:hover {
    background: var(--k-blue, #5f80cf);
    color: #fff;
    border-color: var(--k-blue, #5f80cf);
    box-shadow: 0 2px 8px rgba(95, 128, 207, 0.2);
}

/* Loading / typing indicator */
#tt-chatbot-loading {
    padding: 8px 16px;
    flex-shrink: 0;
}

.tt-chatbot-typing {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 10px 14px;
    background: #fff;
    border: 1px solid #e8ebf0;
    border-radius: 14px;
    width: fit-content;
}
.tt-chatbot-typing span {
    width: 7px;
    height: 7px;
    background: var(--k-blue, #5f80cf);
    border-radius: 50%;
    opacity: 0.5;
    animation: tt-chatbot-bounce 1.2s infinite;
}
.tt-chatbot-typing span:nth-child(2) {
    animation-delay: 0.2s;
}
.tt-chatbot-typing span:nth-child(3) {
    animation-delay: 0.4s;
}
@keyframes tt-chatbot-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* Input area */
.tt-chatbot-input-area {
    display: flex;
    align-items: flex-end;
    padding: 12px;
    border-top: 1px solid #e8ebf0;
    gap: 8px;
    flex-shrink: 0;
    background: #fff;
}

#tt-chatbot-input {
    flex: 1;
    border: 1px solid #dde1e8;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 13.5px;
    resize: none;
    max-height: 80px;
    outline: none;
    font-family: inherit;
    line-height: 1.4;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: #fafbfd;
}
#tt-chatbot-input:focus {
    border-color: var(--k-blue, #5f80cf);
    box-shadow: 0 0 0 3px rgba(95, 128, 207, 0.1);
    background: #fff;
}
#tt-chatbot-input::placeholder {
    color: #9ca3af;
}

#tt-chatbot-send {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--k-blue, #5f80cf), #4a6bbf);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    transition: opacity 0.15s, box-shadow 0.15s;
}
#tt-chatbot-send:hover {
    box-shadow: 0 3px 10px rgba(95, 128, 207, 0.3);
}
#tt-chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Feedback buttons */
.tt-chatbot-feedback {
    display: flex;
    gap: 4px;
    margin-top: 6px;
    padding-top: 4px;
}
.tt-chatbot-feedback-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 6px;
    font-size: 12px;
    color: #9ca3af;
    border-radius: 4px;
    transition: all 0.15s;
}
.tt-chatbot-feedback-btn:hover {
    color: var(--k-blue, #5f80cf);
    background: rgba(95, 128, 207, 0.08);
}
.tt-chatbot-feedback-thanks {
    font-size: 11px;
    color: #9ca3af;
    font-style: italic;
}

/* Responsive */
/* Tablets / phones: widget pinned to TOP of viewport with dynamic height
   (100dvh) that shrinks when the mobile keyboard opens, keeping the input
   field visible while typing. */
@media (max-width: 768px) {
    #tt-chatbot-widget {
        top: 8px;
        left: 8px;
        right: 8px;
        bottom: auto;
        width: auto;
        /* Fallback for browsers without dvh (pre-2022) */
        height: calc(100vh - 16px);
        /* Modern browsers: dynamic viewport height — shrinks when keyboard appears */
        height: calc(100dvh - 16px);
        max-height: none;
        border-radius: 14px;
    }
    /* Match the Show Filters pill dimensions for visual consistency */
    #tt-chatbot-toggle {
        bottom: 16px;
        right: 16px;
        height: 48px;
        padding: 12px 22px;
        border-radius: 28px;
        gap: 8px;
    }
    .tt-chatbot-toggle-label { font-size: 13px; font-weight: 600; }
    .tt-chatbot-toggle-icon  { width: 26px; height: 26px; font-size: 14px; }
}

/* Prevent the page behind from scrolling while the chat is open on mobile.
   `overscroll-behavior: contain` on the messages area also stops scroll
   chaining at the individual element level (safety belt). */
@media (max-width: 991px) {
    body.tt-chatbot-open {
        overflow: hidden !important;
        position: fixed;
        width: 100%;
    }
}
#tt-chatbot-messages {
    overscroll-behavior: contain;
}

/* Small phones: compact everything a bit more, prevent iOS focus-zoom on input */
@media (max-width: 480px) {
    #tt-chatbot-toggle {
        height: 44px;
        padding: 10px 18px;
    }
    .tt-chatbot-toggle-label { font-size: 12px; }
    .tt-chatbot-header       { padding: 10px 14px; }
    .tt-chatbot-agent-avatar { width: 30px; height: 30px; font-size: 15px; }
    .tt-chatbot-title-name   { font-size: 13px; }
    .tt-chatbot-title-status { font-size: 10.5px; }
    #tt-chatbot-messages     { padding: 12px; }
    .tt-chatbot-input-area   { padding: 10px; }
    #tt-chatbot-input        { font-size: 16px; /* iOS: prevents zoom-on-focus */ }
    .tt-chatbot-suggestions  { padding: 4px 12px 8px; }
}

/* Floating container */
.tt-chatbot-floating {
    /* No styles needed - children are position:fixed */
}

/* Inline container for shortcode */
.tt-chatbot-inline {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
}

/* ---------------------------------------------------------------------
 * Header action cluster — groups the help "?" and close X buttons.
 * ------------------------------------------------------------------ */
.tt-chatbot-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}
#tt-chatbot-help {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    line-height: 1;
    transition: background-color 0.15s ease, transform 0.05s ease;
}
#tt-chatbot-help:hover {
    background: rgba(255, 255, 255, 0.32);
}
#tt-chatbot-help.active {
    background: var(--k-orange, #ff834a);
}
#tt-chatbot-help:active { transform: scale(0.94); }

/* Hide help button on mobile — same reason the tour pill is hidden:
 * the panel takes the full viewport and there's no room for a drawer. */
@media (max-width: 991px) {
    #tt-chatbot-help { display: none !important; }
    #tt-chatbot-capabilities { display: none !important; }
}

/* ---------------------------------------------------------------------
 * Capabilities cheat-sheet drawer — slides in below the header,
 * pushes the messages list down. Hidden by default via [hidden].
 * ------------------------------------------------------------------ */
.tt-chatbot-capabilities {
    background: linear-gradient(180deg, #f5f8ff 0%, #ffffff 100%);
    border-bottom: 1px solid #e6ebf3;
    padding: 14px 16px 10px;
    max-height: 300px;
    overflow-y: auto;
    animation: tt-chatbot-cap-slide 0.22s ease-out;
}
.tt-chatbot-capabilities[hidden] { display: none; }
@keyframes tt-chatbot-cap-slide {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.tt-chatbot-cap-header {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 8px;
}
.tt-chatbot-cap-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.tt-chatbot-cap-header strong {
    font-size: 13.5px;
    color: var(--k-blue, #5f80cf);
}
.tt-chatbot-cap-hint {
    font-size: 11.5px;
    color: #6b7280;
}
.tt-chatbot-cap-note {
    margin: 4px 0 6px;
    padding: 6px 10px;
    background: rgba(95, 128, 207, 0.08);
    border-left: 3px solid var(--k-blue, #5f80cf);
    border-radius: 4px;
    font-size: 11.5px;
    line-height: 1.45;
    color: #4b5668;
}
.tt-chatbot-cap-note i { color: var(--k-blue, #5f80cf); margin-right: 4px; }
.tt-chatbot-cap-note em { color: var(--k-orange, #ff834a); font-style: normal; font-weight: 600; }

/* Drawer-local "Take the tour" pill — orange accent to differentiate
 * from the standalone toolbar pills (blue). Inherits from .tt-tour-pill
 * so the JS engine's click delegation just works. */
.tt-chatbot-cap-tour.tt-tour-pill {
    padding: 3px 10px;
    font-size: 11.5px;
    color: var(--k-orange, #ff834a);
    border-color: var(--k-orange, #ff834a);
    background: rgba(255, 131, 74, 0.08);
}
.tt-chatbot-cap-tour.tt-tour-pill i { font-size: 12px; }
.tt-chatbot-cap-tour.tt-tour-pill:hover {
    background: var(--k-orange, #ff834a);
    color: #fff;
}
.tt-chatbot-cap-groups {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.tt-chatbot-cap-group h4 {
    margin: 4px 0 4px;
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #4b5668;
    display: flex;
    align-items: center;
    gap: 6px;
}
.tt-chatbot-cap-group h4 i { color: var(--k-orange, #ff834a); font-size: 13px; }
.tt-chatbot-cap-chip {
    display: inline-block;
    margin: 2px 4px 2px 0;
    padding: 5px 10px;
    background: #ffffff;
    border: 1px solid #d8dfeb;
    border-radius: 14px;
    font-size: 12px;
    color: #1f2937;
    cursor: pointer;
    transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
    text-align: left;
    line-height: 1.3;
    max-width: 100%;
    white-space: normal;
}
.tt-chatbot-cap-chip:hover {
    background: var(--k-orange, #ff834a);
    border-color: var(--k-orange, #ff834a);
    color: #fff;
}
