/* AI Site Assistant Chat Widget */

:root {
    --aisa-primary: var(--aisa-primary-color, #C4622D);
    --aisa-primary-dark: color-mix(in srgb, var(--aisa-primary) 85%, black);
    --aisa-bg: #ffffff;
    --aisa-bg-secondary: #f5f5f5;
    --aisa-text: #333333;
    --aisa-text-muted: #666666;
    --aisa-border: #e0e0e0;
    --aisa-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    --aisa-radius: 16px;
    --aisa-radius-sm: 12px;
}

/* Toggle Button */
#aisa-chat-toggle {
    position: fixed;
    bottom: 24px;
    z-index: 99998;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--aisa-primary);
    border: none;
    cursor: pointer;
    box-shadow: var(--aisa-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, background 0.2s ease;
}

#aisa-chat-toggle:hover {
    transform: scale(1.05);
    background: var(--aisa-primary-dark);
}

#aisa-chat-toggle.aisa-hidden {
    transform: scale(0);
    pointer-events: none;
}

#aisa-chat-toggle svg {
    width: 28px;
    height: 28px;
    fill: white;
}

/* Position variants */
.aisa-position-bottom-right #aisa-chat-toggle,
.aisa-position-bottom-right #aisa-chat-panel {
    right: 24px;
}

.aisa-position-bottom-left #aisa-chat-toggle,
.aisa-position-bottom-left #aisa-chat-panel {
    left: 24px;
}

/* Chat Panel */
#aisa-chat-panel {
    position: fixed;
    bottom: 24px;
    z-index: 99999;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 520px;
    max-height: calc(100vh - 100px);
    background: var(--aisa-bg);
    border-radius: var(--aisa-radius);
    box-shadow: var(--aisa-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

#aisa-chat-panel.aisa-open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

/* Header */
#aisa-chat-header {
    padding: 16px 20px;
    background: var(--aisa-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

#aisa-chat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

#aisa-chat-close,
#aisa-chat-clear {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: opacity 0.2s;
}

#aisa-chat-close:hover,
#aisa-chat-clear:hover {
    opacity: 1;
}

#aisa-chat-close svg,
#aisa-chat-clear svg {
    width: 18px;
    height: 18px;
}

#aisa-chat-clear {
    margin-right: 4px;
}

/* Messages Area */
#aisa-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Message Bubbles */
.aisa-message {
    max-width: 85%;
    animation: aisa-fade-in 0.3s ease;
}

@keyframes aisa-fade-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.aisa-message-user {
    align-self: flex-end;
}

.aisa-message-assistant {
    align-self: flex-start;
}

.aisa-message-content {
    padding: 12px 16px;
    border-radius: var(--aisa-radius-sm);
    font-size: 14px;
    line-height: 1.5;
}

.aisa-message-user .aisa-message-content {
    background: var(--aisa-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.aisa-message-assistant .aisa-message-content {
    background: var(--aisa-bg-secondary);
    color: var(--aisa-text);
    border-bottom-left-radius: 4px;
}

.aisa-message-content a {
    color: inherit;
    text-decoration: underline;
}

/* Action Buttons */
.aisa-message-actions {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.aisa-action-btn {
    padding: 8px 16px;
    background: var(--aisa-primary);
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.aisa-action-btn:hover {
    background: var(--aisa-primary-dark);
    transform: translateY(-1px);
}

/* Mailto button — outline variant so it visually distinguishes from the
   solid Navigate button when both appear together. */
.aisa-action-btn--mailto {
    background: transparent;
    color: var(--aisa-primary);
    border: 1px solid var(--aisa-primary);
}
.aisa-action-btn--mailto::before {
    content: "✉ ";
    margin-right: 2px;
}
.aisa-action-btn--mailto:hover {
    background: var(--aisa-primary);
    color: white;
}

/* Typing Indicator */
.aisa-typing {
    display: flex;
    align-items: center;
    gap: 10px;
}

.aisa-typing .aisa-typing-dots {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--aisa-bg-secondary);
    border-radius: var(--aisa-radius-sm);
    border-bottom-left-radius: 4px;
}

.aisa-typing-label {
    color: var(--aisa-text-muted);
    font-size: 12px;
    font-style: italic;
    line-height: 1.3;
    max-width: 220px;
}

.aisa-typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--aisa-text-muted);
    border-radius: 50%;
    animation: aisa-typing-bounce 1.4s infinite ease-in-out both;
}

.aisa-typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.aisa-typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes aisa-typing-bounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input Area */
#aisa-chat-form {
    padding: 12px 16px;
    border-top: 1px solid var(--aisa-border);
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

#aisa-chat-input {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--aisa-border);
    border-radius: 24px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease;
}

#aisa-chat-input:focus {
    border-color: var(--aisa-primary);
}

#aisa-chat-input::placeholder {
    color: var(--aisa-text-muted);
}

#aisa-chat-submit {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--aisa-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

#aisa-chat-submit:hover {
    background: var(--aisa-primary-dark);
}

#aisa-chat-submit svg {
    width: 18px;
    height: 18px;
    fill: white;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    #aisa-chat-panel {
        width: calc(100vw - 24px);
        height: calc(100vh - 100px);
        bottom: 12px;
        right: 12px !important;
        left: 12px !important;
        border-radius: var(--aisa-radius-sm);
    }

    #aisa-chat-toggle {
        bottom: 16px;
        right: 16px !important;
        left: auto !important;
        width: 56px;
        height: 56px;
    }
}

/* ── Inline results panel (hero + header) ───────────────────────────── */

.aisa-panel {
    position: absolute;
    z-index: 99997;
    max-width: 560px;
    background: var(--aisa-bg);
    border: 1px solid var(--aisa-border);
    border-radius: var(--aisa-radius-sm);
    box-shadow: var(--aisa-shadow);
    overflow: hidden;
    font-family: inherit;
    color: var(--aisa-text);
}

.aisa-panel[hidden] {
    display: none;
}

.aisa-panel__instant {
    max-height: 360px;
    overflow-y: auto;
}

.aisa-panel__row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
    text-decoration: none !important;
    color: var(--aisa-text) !important;
    border-bottom: 1px solid color-mix(in srgb, var(--aisa-border) 70%, transparent);
    cursor: pointer;
    transition: background 0.12s ease;
}

.aisa-panel__row:last-child {
    border-bottom: none;
}

.aisa-panel__row:hover,
.aisa-panel__row.is-active {
    background: color-mix(in srgb, var(--aisa-primary) 8%, var(--aisa-bg));
}

.aisa-panel__row--past {
    opacity: 0.7;
}

.aisa-panel__icon {
    flex-shrink: 0;
    color: var(--aisa-primary);
    margin-top: 2px;
    display: inline-flex;
}

.aisa-panel__body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.aisa-panel__title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    color: var(--aisa-text);
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
}

.aisa-panel__sub {
    font-size: 12px;
    color: var(--aisa-text-muted);
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.aisa-panel__date {
    font-size: 11px;
    font-weight: 500;
    padding: 1px 7px;
    border-radius: 8px;
    white-space: nowrap;
}

.aisa-panel__date--upcoming {
    background: color-mix(in srgb, var(--aisa-primary) 20%, transparent);
    color: var(--aisa-primary-dark);
}

.aisa-panel__date--past {
    background: color-mix(in srgb, var(--aisa-text-muted) 18%, transparent);
    color: var(--aisa-text-muted);
}

.aisa-panel__empty {
    padding: 14px 16px;
    font-size: 13px;
    color: var(--aisa-text-muted);
    font-style: italic;
}

/* Agent answer block */
.aisa-panel__agent {
    border-top: 2px solid color-mix(in srgb, var(--aisa-primary) 25%, transparent);
}

.aisa-panel__agent:empty {
    display: none;
}

.aisa-panel__agent-header {
    padding: 10px 14px 6px;
    font-size: 12px;
    color: var(--aisa-text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
    background: color-mix(in srgb, var(--aisa-primary) 5%, var(--aisa-bg));
}

.aisa-panel__agent-body {
    padding: 4px 14px 10px;
    font-size: 14px;
    line-height: 1.5;
}

.aisa-panel__chips {
    padding: 0 14px 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.aisa-panel__spinner {
    width: 12px;
    height: 12px;
    border: 2px solid color-mix(in srgb, var(--aisa-primary) 30%, transparent);
    border-top-color: var(--aisa-primary);
    border-radius: 50%;
    animation: aisa-spin 0.8s linear infinite;
    display: inline-block;
}

@keyframes aisa-spin {
    to { transform: rotate(360deg); }
}

.aisa-panel__footer {
    border-top: 1px solid var(--aisa-border);
    padding: 8px 14px;
    text-align: right;
    background: color-mix(in srgb, var(--aisa-bg-secondary) 60%, transparent);
}

.aisa-panel__open-chat {
    background: none;
    border: none;
    color: var(--aisa-primary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 6px;
}

.aisa-panel__open-chat:hover {
    text-decoration: underline;
}

/* Phone: the panel becomes near-full-width to stay readable */
@media (max-width: 600px) {
    .aisa-panel {
        max-width: calc(100vw - 16px);
    }
}

/* Scrollbar Styling */
#aisa-chat-messages::-webkit-scrollbar {
    width: 6px;
}

#aisa-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

#aisa-chat-messages::-webkit-scrollbar-thumb {
    background: var(--aisa-border);
    border-radius: 3px;
}

#aisa-chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--aisa-text-muted);
}
