/* ============================================================
   Terra Chatbot Widget
   Version: 1.0.0
   ============================================================ */

:root {
    --terra-chat-accent:     #e77a16;
    --terra-chat-blue:       #343c8b;
    --terra-chat-navy:       #1e2245;
    --terra-chat-ice:        #eef1f8;
    --terra-chat-white:      #ffffff;
    --terra-chat-radius:     14px;
    --terra-chat-shadow:     0 8px 40px rgba(30, 34, 69, 0.22);
    --terra-chat-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================================
   Widget Container
   ============================================================ */

.terra-chatbot-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    pointer-events: none;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.terra-chatbot-widget *,
.terra-chatbot-widget *::before,
.terra-chatbot-widget *::after {
    box-sizing: border-box;
}

/* ============================================================
   Elementor / theme reset — cancel global button overrides
   ============================================================ */

#terra-chatbot-widget button,
#terra-chatbot-widget button:hover,
#terra-chatbot-widget button:focus,
#terra-chatbot-widget button:active {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
    text-transform: none !important;
    letter-spacing: normal !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    text-decoration: none !important;
    /* Reset any theme-injected color/background so scoped rules below win */
    background-color: unset;
    color: unset;
    border-color: unset;
}

/* ============================================================
   Trigger Button
   ============================================================ */

.terra-chatbot-trigger {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50% !important;
    background: linear-gradient(135deg, #e77a16, #cf671d) !important;
    border: none !important;
    cursor: pointer;
    pointer-events: all;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(231, 122, 22, 0.45);
    transition: transform var(--terra-chat-transition), box-shadow var(--terra-chat-transition);
    z-index: 10000;
    animation: terraChatPulse 2s ease-in-out 3;
    color: #ffffff !important;
    padding: 0 !important;
    outline-offset: 3px;
}

.terra-chatbot-trigger svg {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
}

.terra-chatbot-trigger:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(231, 122, 22, 0.60);
}

.terra-chatbot-trigger:focus-visible {
    outline: 3px solid var(--terra-chat-accent);
}

@keyframes terraChatPulse {
    0%   { box-shadow: 0 4px 20px rgba(231, 122, 22, 0.45); }
    50%  { box-shadow: 0 4px 32px rgba(231, 122, 22, 0.75), 0 0 0 8px rgba(231, 122, 22, 0.15); }
    100% { box-shadow: 0 4px 20px rgba(231, 122, 22, 0.45); }
}

/* ============================================================
   Tooltip
   ============================================================ */

.terra-chatbot-trigger-tooltip {
    position: absolute;
    right: 64px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--terra-chat-navy);
    color: var(--terra-chat-white);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    padding: 8px 14px;
    border-radius: 8px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-width: 240px;
    white-space: normal;
    text-align: center;
}

/* Arrow pointing right toward chat bubble */
.terra-chatbot-trigger-tooltip::after {
    content: '';
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
    border-width: 6px;
    border-style: solid;
    border-color: transparent transparent transparent var(--terra-chat-navy);
}

.terra-chatbot-trigger-tooltip.is-visible {
    opacity: 1;
}

/* ============================================================
   Chat Window
   ============================================================ */

.terra-chatbot-window {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 380px;
    height: 520px;
    display: flex;
    flex-direction: column;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--terra-chat-shadow);
    pointer-events: all;
    transform: translateY(20px);
    opacity: 0;
    transition: transform var(--terra-chat-transition), opacity var(--terra-chat-transition);
    z-index: 9999;
    background: var(--terra-chat-white);
}

.terra-chatbot-window[hidden] {
    display: none !important;
}

.terra-chatbot-window.is-open {
    transform: translateY(0);
    opacity: 1;
}

/* ============================================================
   Header
   ============================================================ */

.terra-chatbot-header {
    background: linear-gradient(135deg, #343c8b, #1e2245);
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.terra-chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.terra-chatbot-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #e77a16, #cf671d);
    color: var(--terra-chat-white);
    font-family: 'Plus Jakarta Sans', 'DM Sans', sans-serif;
    font-weight: 800;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: none;
}

.terra-chatbot-header-name {
    color: var(--terra-chat-white);
    font-weight: 700;
    font-size: 15px;
    line-height: 1.3;
}

.terra-chatbot-header-status {
    color: rgba(255, 255, 255, 0.75);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
}

.terra-chatbot-online-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    flex-shrink: 0;
}

.terra-chatbot-close {
    background: transparent !important;
    border: none !important;
    color: rgba(255, 255, 255, 0.85) !important;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 6px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 !important;
    transition: background 0.2s ease, color 0.2s ease;
    flex-shrink: 0;
}

.terra-chatbot-close svg {
    width: 18px;
    height: 18px;
}

.terra-chatbot-close:hover {
    background: rgba(255, 255, 255, 0.15) !important;
    color: #ffffff !important;
}

.terra-chatbot-close:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.7);
    outline-offset: 2px;
}

/* ============================================================
   Messages Area
   ============================================================ */

.terra-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    background: #f8f9ff;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.terra-chatbot-messages::-webkit-scrollbar {
    width: 4px;
}

.terra-chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.terra-chatbot-messages::-webkit-scrollbar-thumb {
    background: rgba(52, 60, 139, 0.2);
    border-radius: 4px;
}

/* ============================================================
   Message Rows
   ============================================================ */

.terra-chat-message {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.terra-chat-message--bot {
    flex-direction: row;
}

.terra-chat-message--user {
    flex-direction: row-reverse;
}

/* Avatar inside messages area */
.terra-chat-message .terra-chat-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, #343c8b, #1e2245);
    color: var(--terra-chat-white);
    font-weight: 700;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: none;
    margin-top: 2px;
}

/* ============================================================
   Bubbles
   ============================================================ */

.terra-chat-bubble {
    max-width: 85%;
    padding: 11px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
}

.terra-chat-bubble--bot {
    background: var(--terra-chat-white);
    box-shadow: 0 1px 8px rgba(52, 60, 139, 0.08);
    color: var(--terra-chat-navy);
    border-radius: 4px 12px 12px 12px;
}

.terra-chat-bubble--user {
    background: linear-gradient(135deg, #343c8b, #1e2245);
    color: var(--terra-chat-white);
    border-radius: 12px 12px 4px 12px;
}

/* ============================================================
   Animation
   ============================================================ */

.terra-chat-animate {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.terra-chat-animate.is-visible {
    opacity: 1;
    transform: translateY(0);
}

/* ============================================================
   Typing Indicator
   ============================================================ */

.terra-chat-typing .terra-chat-bubble--bot {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 52px;
}

.terra-typing-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(52, 60, 139, 0.45);
    animation: terraDotBounce 1.2s ease-in-out infinite;
}

.terra-typing-dot:nth-child(1) { animation-delay: 0s; }
.terra-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.terra-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes terraDotBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
    30%            { transform: translateY(-5px); opacity: 1; }
}

/* ============================================================
   Choice Buttons
   ============================================================ */

.terra-chat-choices {
    display: flex;
    flex-direction: column;
    gap: 7px;
    padding: 4px 0 4px 40px;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.terra-chat-choices.is-visible {
    opacity: 1;
    transform: translateY(0);
}

#terra-chatbot-widget .terra-chat-choice-btn {
    background: #ffffff !important;
    border: 1.5px solid #d0d6ee !important;
    color: #1e2245 !important;
    padding: 10px 12px 10px 16px !important;
    border-radius: 10px !important;
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 500;
    font-family: inherit;
    line-height: 1.35;
    text-align: left;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease,
                transform 0.18s ease, box-shadow 0.18s ease;
    box-shadow: 0 1px 3px rgba(52, 60, 139, 0.06);
}

/* Chevron arrow via pseudo-element */
#terra-chatbot-widget .terra-chat-choice-btn::after {
    content: '';
    display: block;
    width: 16px;
    height: 16px;
    min-width: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M7.5 5l5 5-5 5' stroke='%23aab2ce' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    transition: background-image 0.18s ease;
    flex-shrink: 0;
}

#terra-chatbot-widget .terra-chat-choice-btn:hover:not(:disabled) {
    background: #f0f3ff !important;
    border-color: #343c8b !important;
    color: #343c8b !important;
    transform: translateX(2px);
    box-shadow: 0 2px 8px rgba(52, 60, 139, 0.12);
}

#terra-chatbot-widget .terra-chat-choice-btn:hover:not(:disabled)::after {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M7.5 5l5 5-5 5' stroke='%23343c8b' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

#terra-chatbot-widget .terra-chat-choice-btn:focus-visible {
    outline: 2px solid var(--terra-chat-blue);
    outline-offset: 2px;
}

/* Selected state: navy fill + checkmark */
#terra-chatbot-widget .terra-chat-choice-btn.is-selected {
    background: linear-gradient(135deg, #343c8b, #1e2245) !important;
    color: #ffffff !important;
    border-color: transparent !important;
    box-shadow: 0 2px 10px rgba(52, 60, 139, 0.25);
}

#terra-chatbot-widget .terra-chat-choice-btn.is-selected::after {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M5 10l4 4 6-8' stroke='%23ffffff' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

#terra-chatbot-widget .terra-chat-choice-btn:disabled {
    opacity: 0.55;
    cursor: default;
    transform: none;
}

/* ============================================================
   Capture Form
   ============================================================ */

.terra-chat-capture-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.terra-chat-capture-form p {
    margin: 0 0 4px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--terra-chat-navy);
}

.terra-chat-input {
    border: 1.5px solid #dde2f0;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    width: 100%;
    outline: none;
    background: #ffffff;
    color: var(--terra-chat-navy);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.terra-chat-input::placeholder {
    color: #8892b0;
}

.terra-chat-input:focus {
    border-color: var(--terra-chat-accent);
    box-shadow: 0 0 0 3px rgba(231, 122, 22, 0.15);
}

.terra-chat-capture-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
}

#terra-chatbot-widget .terra-chat-btn-primary {
    background: #e77a16 !important;
    color: #ffffff !important;
    border: none !important;
    padding: 11px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    width: 100%;
    transition: filter 0.2s ease, transform 0.15s ease;
}

#terra-chatbot-widget .terra-chat-btn-primary:hover:not(:disabled) {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

#terra-chatbot-widget .terra-chat-btn-primary:disabled {
    opacity: 0.65;
    cursor: default;
    transform: none;
}

#terra-chatbot-widget .terra-chat-btn-skip {
    background: transparent !important;
    border: none !important;
    color: #4a5068 !important;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    padding: 4px 0;
    text-decoration: underline;
    text-align: center;
    transition: color 0.2s ease;
}

#terra-chatbot-widget .terra-chat-btn-skip:hover {
    color: #1e2245 !important;
}

.terra-chat-capture-error {
    color: #dc2626;
    font-size: 13px;
    padding: 8px 10px;
    background: #fef2f2;
    border-radius: 6px;
    border: 1px solid #fecaca;
    line-height: 1.4;
}

/* ============================================================
   Footer Bar
   ============================================================ */

.terra-chatbot-footer-bar {
    padding: 8px 16px;
    background: var(--terra-chat-white);
    border-top: 1px solid #eef1f8;
    font-size: 11px;
    color: #6b7280;
    text-align: center;
    flex-shrink: 0;
    letter-spacing: 0.01em;
}

/* ============================================================
   Position Variant: Bottom Left
   ============================================================ */

.terra-chatbot-position-left .terra-chatbot-trigger {
    left: 24px;
    right: auto;
}

.terra-chatbot-position-left .terra-chatbot-window {
    left: 24px;
    right: auto;
}

.terra-chatbot-position-left .terra-chatbot-trigger-tooltip {
    right: auto;
    left: 64px;
    text-align: center;
}

.terra-chatbot-position-left .terra-chatbot-trigger-tooltip::after {
    right: auto;
    left: -6px;
    border-color: transparent var(--terra-chat-navy) transparent transparent;
}

/* ============================================================
   Mobile Responsive (max-width: 480px)
   ============================================================ */

@media (max-width: 480px) {
    .terra-chatbot-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        max-height: 100%;
    }

    .terra-chatbot-position-left .terra-chatbot-window {
        left: 0;
        right: 0;
    }

    .terra-chatbot-trigger {
        bottom: 16px;
        right: 16px;
    }

    .terra-chatbot-position-left .terra-chatbot-trigger {
        left: 16px;
        right: auto;
    }
}

/* ============================================================
   Reduced Motion
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
    .terra-chatbot-trigger {
        animation: none;
    }

    .terra-chatbot-window {
        transition: none;
        transform: none;
    }

    .terra-chatbot-window.is-open {
        transform: none;
    }

    .terra-chatbot-trigger-tooltip {
        transition: none;
    }

    .terra-chatbot-trigger {
        transition: none;
    }

    .terra-chat-animate {
        transition: none;
        transform: none;
        opacity: 1;
    }

    .terra-chat-animate.is-visible {
        transform: none;
    }

    .terra-chat-choices {
        transition: none;
        transform: none;
        opacity: 1;
    }

    .terra-chat-choices.is-visible {
        transform: none;
    }

    .terra-typing-dot {
        animation: none;
        opacity: 1;
    }

    #terra-chatbot-widget .terra-chat-choice-btn {
        transition: none;
        transform: none !important;
    }

    .terra-chat-input {
        transition: none;
    }

    #terra-chatbot-widget .terra-chat-btn-primary {
        transition: none;
    }

    .terra-chatbot-close {
        transition: none;
    }
}
