/* ===== Assistant Chat Widget ===== */

/* The in-wizard assistant FAB/panel only belong inside the wizard
   (body.chatting). On mobile the panel is fixed at bottom:0 covering 70vh
   with pointer-events:none — Android Chrome doesn't always pass touches
   through, swallowing taps on the landing-page Intercom FAB underneath. */
body:not(.chatting) .assistant-fab,
body:not(.chatting) .assistant-panel {
    display: none !important;
}

/* FAB Button */
.assistant-fab {
    position: fixed;
    bottom: 32px;
    right: 32px;
    z-index: 300;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent-gradient);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(255,95,95,0.35);
    transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease), opacity 0.2s var(--ease);
    opacity: 0;
    pointer-events: none;
}
.assistant-fab.visible {
    opacity: 1;
    pointer-events: auto;
}
.assistant-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(255,95,95,0.45);
}
.assistant-fab:active {
    transform: scale(0.95);
}
.assistant-fab svg {
    width: 26px;
    height: 26px;
    fill: #fff;
}

/* Unread dot on FAB */
.assistant-fab .fab-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--danger);
    border: 2px solid var(--surface);
    display: none;
}

/* Chat Panel */
.assistant-panel {
    position: fixed;
    bottom: 100px;
    right: 32px;
    width: 380px;
    height: min(520px, calc(100vh - 120px));
    z-index: 301;
    border-radius: var(--radius-container);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    box-shadow: 0 12px 48px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
}
.assistant-panel.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

/* Panel Header */
.assistant-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--surface-elevated);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.assistant-header-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.assistant-header-icon svg {
    width: 16px;
    height: 16px;
    fill: #fff;
}
.assistant-header-title {
    font-weight: 600;
    font-size: var(--text-md);
    color: var(--text);
    flex: 1;
}
.assistant-header-sub {
    font-size: var(--text-xs);
    color: var(--muted);
}
.assistant-close-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    transition: background 0.15s, color 0.15s;
}
.assistant-close-btn:hover {
    background: var(--border);
    color: var(--text);
}

.assistant-channel-switch {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    background: var(--surface-elevated);
    border-bottom: 1px solid var(--border);
}

.assistant-channel-btn {
    flex: 1;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--muted);
    border-radius: var(--radius-full);
    padding: 7px 10px;
    font-size: var(--text-sm);
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.assistant-channel-btn:hover {
    border-color: var(--accent);
    color: var(--text);
}

.assistant-channel-btn.active {
    background: rgba(255,95,95,0.1);
    border-color: rgba(255,95,95,0.35);
    color: var(--accent-hover);
}

.assistant-native-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.assistant-intercom-wrap {
    flex: 1;
    min-height: 0;
    padding: 18px 16px 16px;
    display: none;
    flex-direction: column;
    justify-content: flex-start;
    gap: 12px;
    background: var(--surface);
}

.assistant-intercom-wrap.open {
    display: flex;
}

.assistant-intercom-title {
    margin: 0;
    font-size: var(--text-md);
    font-weight: 700;
    color: var(--text);
}

.assistant-intercom-text {
    margin: 0;
    color: var(--muted);
    font-size: var(--text-sm);
    line-height: 1.45;
}

.assistant-intercom-btn {
    align-self: flex-start;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    border-radius: var(--radius-full);
    padding: 8px 14px;
    font-size: var(--text-sm);
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.15s;
}

.assistant-intercom-btn:hover {
    opacity: 0.88;
}

.assistant-intercom-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* Messages Area */
.assistant-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.assistant-messages::-webkit-scrollbar {
    width: 4px;
}
.assistant-messages::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 4px;
}

/* Message Bubbles */
.asst-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: var(--radius-card);
    font-size: var(--text-base);
    line-height: 1.5;
    word-wrap: break-word;
}
.asst-msg.bot {
    align-self: flex-start;
    background: var(--bg);
    color: var(--text);
    border-bottom-left-radius: 4px;
}
.asst-msg.user {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.asst-msg.action-confirm {
    align-self: flex-start;
    background: rgba(255,95,95,0.08);
    color: var(--accent-hover);
    font-size: var(--text-sm);
    padding: 8px 12px;
    border: 1px solid rgba(255,95,95,0.2);
}

/* Error Message */
.asst-msg.asst-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
}
.asst-retry-btn {
    display: inline-block;
    margin-left: 8px;
    padding: 4px 14px;
    border-radius: var(--radius-full);
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    font-size: var(--text-sm);
    cursor: pointer;
    transition: opacity 0.15s;
}
.asst-retry-btn:hover {
    opacity: 0.85;
}

/* Typing Indicator */
.asst-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--bg);
    border-radius: var(--radius-card);
    border-bottom-left-radius: 4px;
}
.asst-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--muted);
    animation: asst-dot-bounce 1.2s infinite;
}
.asst-typing span:nth-child(2) { animation-delay: 0.15s; }
.asst-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes asst-dot-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* Chip Tray */
.assistant-chips {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    overflow-x: auto;
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    background: var(--surface-elevated);
    -ms-overflow-style: none;
    scrollbar-width: none;
}
.assistant-chips::-webkit-scrollbar { display: none; }
.assistant-chip {
    flex-shrink: 0;
    padding: 6px 14px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font-size: var(--text-sm);
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.assistant-chip:hover {
    border-color: var(--accent);
    background: rgba(255,95,95,0.06);
    color: var(--accent-hover);
}

/* Input Bar */
.assistant-input-bar {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--surface-elevated);
    flex-shrink: 0;
}
.assistant-input {
    flex: 1;
    padding: 8px 14px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-strong);
    background: var(--bg);
    font-size: var(--text-base);
    font-family: inherit;
    color: var(--text);
    outline: none;
    transition: border-color 0.15s;
}
.assistant-input:focus {
    border-color: var(--accent);
}
.assistant-input::placeholder {
    color: var(--muted);
}
.assistant-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--accent-gradient);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, opacity 0.15s;
}
.assistant-send-btn:hover {
    transform: scale(1.05);
}
.assistant-send-btn:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
}
.assistant-send-btn svg {
    width: 16px;
    height: 16px;
    fill: #fff;
}

/* Mobile */
@media (max-width: 600px) {
    .assistant-fab {
        bottom: 20px;
        right: 20px;
        width: 48px;
        height: 48px;
    }
    .assistant-fab svg {
        width: 22px;
        height: 22px;
    }
    .assistant-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 70vh;
        border-radius: var(--radius-container) var(--radius-container) 0 0;
    }
}
