/* ============================================
   Server Scout — Chat Widget
   Floating sales chatbot, matches website design system
   ============================================ */

/* ── Chat Bubble ────────────────────────── */

.scout-chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--gradient-btn-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-brand-lg);
    z-index: 9998;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.scout-chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: var(--shadow-glow);
}

.scout-chat-bubble svg {
    width: 28px;
    height: 28px;
    fill: #fff;
    transition: transform 0.2s ease;
}

.scout-chat-bubble--open svg {
    transform: rotate(90deg);
}

/* ── Chat Panel ─────────────────────────── */

.scout-chat-panel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 380px;
    max-height: 560px;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    z-index: 9998;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.scout-chat-panel--visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ── Header ─────────────────────────────── */

.scout-chat-header {
    background: var(--gradient-cta);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.scout-chat-header__info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.scout-chat-header__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.scout-chat-header__text h4 {
    color: #fff;
    font-size: 0.9375rem;
    font-weight: 600;
    margin: 0;
    line-height: 1.3;
}

.scout-chat-header__text p {
    font-size: 0.75rem;
    margin: 0;
    opacity: 0.85;
}

.scout-chat-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    opacity: 0.8;
    transition: opacity 0.2s;
    line-height: 0;
}

.scout-chat-close:hover {
    opacity: 1;
}

.scout-chat-close svg {
    width: 20px;
    height: 20px;
}

/* ── Lead Form ──────────────────────────── */

.scout-chat-lead {
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.scout-chat-lead h4 {
    font-size: 1.0625rem;
    margin: 0;
    text-align: center;
    color: var(--text-heading);
}

.scout-chat-lead p {
    font-size: 0.8125rem;
    color: var(--text-muted);
    text-align: center;
    margin: 0;
    line-height: 1.5;
}

.scout-chat-lead__input {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border-default);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    color: var(--text-body);
    background: var(--bg-primary);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.scout-chat-lead__input:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.scout-chat-lead__input::placeholder {
    color: var(--text-muted);
}

.scout-chat-lead__btn {
    width: 100%;
    padding: 10px 16px;
    background: var(--gradient-btn-primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
}

.scout-chat-lead__btn:hover {
    opacity: 0.92;
}

.scout-chat-lead__btn:active {
    transform: scale(0.98);
}

.scout-chat-lead__btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.scout-chat-lead__error {
    font-size: 0.75rem;
    color: var(--color-danger);
    text-align: center;
    margin: 0;
    min-height: 1em;
}

/* ── Messages Area ──────────────────────── */

.scout-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 200px;
    max-height: 340px;
    scroll-behavior: smooth;
}

.scout-chat-messages::-webkit-scrollbar {
    width: 4px;
}

.scout-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.scout-chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: 2px;
}

/* ── Message Bubbles ────────────────────── */

.scout-chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.8125rem;
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.scout-chat-msg--user {
    align-self: flex-end;
    background: var(--brand-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.scout-chat-msg--bot {
    align-self: flex-start;
    background: var(--bg-secondary);
    color: var(--text-body);
    border-bottom-left-radius: 4px;
}

.scout-chat-msg--bot strong {
    font-weight: 600;
}

.scout-chat-msg--bot em {
    font-style: italic;
}

.scout-chat-msg--bot code {
    font-family: var(--font-mono);
    font-size: 0.8em;
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 4px;
    border-radius: 3px;
}

.scout-chat-msg--bot a {
    color: var(--brand-primary);
    text-decoration: underline;
}

.scout-chat-msg--bot a:hover {
    color: var(--brand-primary-dark);
}

.scout-chat-msg--bot ul {
    margin: 6px 0 2px;
    padding-left: 18px;
}

.scout-chat-msg--bot li {
    margin-bottom: 2px;
}

.scout-chat-msg--error {
    align-self: center;
    background: #fef2f2;
    color: var(--color-danger);
    font-size: 0.75rem;
    text-align: center;
    border-radius: var(--radius-sm);
}

/* ── CTA Buttons in Messages ────────────── */

.scout-chat-cta {
    display: inline-block;
    margin: 6px 4px 2px 0;
    padding: 6px 14px;
    background: var(--gradient-cta);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 20px;
    text-decoration: none;
    transition: opacity 0.2s, transform 0.1s;
}

.scout-chat-cta:hover {
    opacity: 0.9;
    color: #fff;
    transform: translateY(-1px);
}

/* ── Handoff Button ─────────────────────── */

.scout-chat-handoff {
    display: block;
    margin: 8px 0 2px;
    padding: 8px 16px;
    background: var(--bg-primary);
    border: 1.5px solid var(--brand-primary);
    color: var(--brand-primary);
    font-size: 0.8125rem;
    font-weight: 600;
    font-family: var(--font-sans);
    border-radius: 20px;
    cursor: pointer;
    text-align: center;
    transition: background 0.2s, color 0.2s;
}

.scout-chat-handoff:hover {
    background: var(--brand-primary);
    color: #fff;
}

/* ── Typing Indicator ───────────────────── */

.scout-chat-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 12px 18px;
    background: var(--bg-secondary);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}

.scout-chat-typing span {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: scoutChatBounce 1.2s infinite ease-in-out;
}

.scout-chat-typing span:nth-child(2) {
    animation-delay: 0.15s;
}

.scout-chat-typing span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes scoutChatBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ── Quick Replies ──────────────────────── */

.scout-chat-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 16px 8px;
    flex-shrink: 0;
}

.scout-chat-quick-reply {
    padding: 6px 14px;
    background: var(--bg-primary);
    border: 1.5px solid var(--brand-primary);
    color: var(--brand-primary);
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
}

.scout-chat-quick-reply:hover {
    background: var(--brand-primary);
    color: #fff;
}

/* ── Input Area ─────────────────────────── */

.scout-chat-input {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border-default);
    flex-shrink: 0;
}

.scout-chat-input__textarea {
    flex: 1;
    resize: none;
    border: 1.5px solid var(--border-default);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    line-height: 1.4;
    color: var(--text-body);
    background: var(--bg-primary);
    outline: none;
    max-height: 88px;
    overflow-y: auto;
    transition: border-color 0.2s;
}

.scout-chat-input__textarea:focus {
    border-color: var(--brand-primary);
}

.scout-chat-input__textarea::placeholder {
    color: var(--text-muted);
}

.scout-chat-input__send {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    background: var(--gradient-btn-primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s, transform 0.1s;
}

.scout-chat-input__send:hover {
    opacity: 0.9;
}

.scout-chat-input__send:active {
    transform: scale(0.94);
}

.scout-chat-input__send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.scout-chat-input__send svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* ── Powered-by ─────────────────────────── */

.scout-chat-powered {
    text-align: center;
    font-size: 0.625rem;
    color: var(--text-muted);
    padding: 4px 16px 8px;
    flex-shrink: 0;
}

/* ── Mobile Responsive ──────────────────── */

@media (max-width: 480px) {
    .scout-chat-panel {
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
    }

    .scout-chat-bubble {
        bottom: 16px;
        right: 16px;
    }

    .scout-chat-messages {
        max-height: calc(100vh - 240px);
        max-height: calc(100dvh - 240px);
    }

    .scout-chat-input__mic,
    .scout-chat-input__tts {
        width: 44px;
        height: 44px;
    }
}

/* ── Mic / TTS shared base ─────────────── */

.scout-chat-input__mic,
.scout-chat-input__tts {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    background: none;
    border: 1.5px solid var(--border-default);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: border-color 0.2s, color 0.2s;
}

.scout-chat-input__mic:hover,
.scout-chat-input__tts:hover {
    border-color: var(--brand-primary);
    color: var(--brand-primary);
}

.scout-chat-input__mic svg,
.scout-chat-input__tts svg {
    width: 18px;
    height: 18px;
}

/* ── Mic-specific ──────────────────────── */

.scout-chat-input__mic {
    transition: border-color 0.2s, color 0.2s, box-shadow 0.2s;
}

.scout-chat-input__mic--listening {
    border-color: var(--color-danger);
    color: var(--color-danger);
    animation: scoutMicPulse 1.5s infinite;
}

@keyframes scoutMicPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

@media (prefers-reduced-motion: reduce) {
    .scout-chat-input__mic--listening {
        animation: none;
        box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25);
    }
}

.scout-chat-input__tts--on {
    border-color: var(--brand-primary);
    color: var(--brand-primary);
    background: rgba(99, 102, 241, 0.08);
}
