:root {
    --ai-accent: #ff6600;
    --ai-surface: rgba(18, 18, 18, 0.95);
    --ai-text: #ffffff;
    --ai-muted: rgba(255, 255, 255, 0.52);
    --ai-border: rgba(255, 255, 255, 0.1);
    --ai-panel: rgba(255, 255, 255, 0.05);
    --ai-bubble: rgba(255, 255, 255, 0.08);
    --ai-input-surface: rgba(255, 255, 255, 0.06);
    --ai-input-border: rgba(255, 255, 255, 0.15);
    --ai-shadow: rgba(0, 0, 0, 0.7);
}

html[data-theme="light"] {
    --ai-surface: rgba(245, 241, 234, 0.96);
    --ai-text: #171717;
    --ai-muted: rgba(23, 23, 23, 0.56);
    --ai-border: rgba(23, 23, 23, 0.13);
    --ai-panel: rgba(255, 255, 255, 0.58);
    --ai-bubble: rgba(23, 23, 23, 0.07);
    --ai-input-surface: rgba(255, 255, 255, 0.7);
    --ai-input-border: rgba(23, 23, 23, 0.16);
    --ai-shadow: rgba(58, 45, 31, 0.2);
}

#ai-chat-launcher {
    position: fixed;
    bottom: var(--ai-bottom, 36px);
    right: 24px;
    width: 36px;
    height: 36px;
    background: var(--ai-accent);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(212, 163, 67, 0.3);
    /* Match SC shadow alpha 0.3 */
    z-index: 2020;
    opacity: 0;
    transition: opacity 1.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s;
    padding: 0;
    padding-top: 1px;
    /* Match SC padding-top: 1px */
    outline: none;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

#ai-chat-launcher.revealed {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

#ai-chat-launcher svg {
    width: 20px;
    height: 20px;
    fill: #000;
}

#ai-chat-launcher:hover {
    transform: scale(1.1);
}

/* Chat container with higher z-index */
#ai-chat-container {
    position: fixed;
    bottom: calc(var(--ai-bottom, 36px) + 50px);
    right: 24px;
    width: 330px;
    height: 550px;
    background: var(--ai-surface);
    color: var(--ai-text);
    border: 1px solid var(--ai-border);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px var(--ai-shadow);
    backdrop-filter: blur(15px);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
    z-index: 2030;
    overflow: hidden;
}

#ai-chat-container.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.ai-chat-header {
    background: var(--ai-panel);
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--ai-border);
}

.ai-avatar {
    width: 40px;
    height: 32px;
    background: var(--ai-panel);
    /* Subtle bg instead of solid accent */
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.ai-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Fill the 32x32 box */
    transition: filter 0.3s ease;
}

html[data-theme="light"] .ai-avatar img {
    filter: brightness(0);
}

.ai-info h3 {
    font-size: 1rem;
    margin: 0;
    color: var(--ai-text);
    font-weight: 600;
}

.ai-chat-close {
    margin-left: auto;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.3s, transform 0.3s;
    border-radius: 50%;
}

.ai-chat-close:hover {
    opacity: 1;
    background: var(--ai-bubble);
    transform: rotate(90deg);
}

.ai-chat-close svg {
    width: 18px;
    height: 18px;
    fill: var(--ai-text);
}

.ai-info span {
    font-size: 0.75rem;
    color: var(--ai-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

#ai-chat-messages {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE/Edge */
}

#ai-chat-messages::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari/Brave */
}

.ai-message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.4;
}

.ai-message.user {
    align-self: flex-end;
    background: var(--ai-accent);
    color: #000;
    border-bottom-right-radius: 4px;
}

.ai-message.assistant {
    align-self: flex-start;
    background: var(--ai-bubble);
    color: var(--ai-text);
    border-bottom-left-radius: 4px;
}

/* Specific styling for message content */
.ai-message strong, .ai-message b {
    color: var(--ai-accent);
}

.ai-message ul {
    padding-left: 20px;
    margin: 8px 0;
}

.ai-message li::marker {
    color: var(--ai-accent);
}

.ai-message a {
    color: #fff;
    background: var(--ai-accent);
    padding: 3px 12px;
    border-radius: 6px;
    text-decoration: none;
    display: inline-block;
    color: #000;
    font-weight: 600;
    margin: 4px 0;
    font-size: 0.85rem;
    transition: transform 0.2s, background 0.2s;
}

.ai-message a:hover {
    background: #e5b955;
    transform: translateY(-1px);
}

/* Typing Indicator */
.ai-typing-indicator {
    align-self: flex-start;
    background: var(--ai-panel);
    padding: 10px 20px;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    display: none;
    /* Hidden by default */
    align-items: center;
    gap: 5px;
    margin-bottom: 10px;
    margin-left: 20px;
    /* Shifted from the left wall */
}

.ai-typing-indicator.active {
    display: flex;
}

.ai-typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--ai-accent);
    border-radius: 50%;
    display: inline-block;
    opacity: 0.4;
    animation: ai-typing-pulse 1.4s infinite ease-in-out both;
}

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

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

@keyframes ai-typing-pulse {

    0%,
    80%,
    100% {
        transform: scale(0);
        opacity: 0.4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.ai-chat-input-container {
    padding: 1rem;
    border-top: 1px solid var(--ai-border);
}

.ai-input-wrapper {
    display: flex;
    background: var(--ai-input-surface);
    border-radius: 20px;
    padding: 4px;
    border: 1px solid var(--ai-input-border);
}

#ai-chat-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--ai-text);
    padding: 8px 12px;
    outline: none;
}

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

.ai-action-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    border-radius: 50%;
    opacity: 0.7;
}

.ai-action-btn:hover {
    opacity: 1;
    background: var(--ai-bubble);
    transform: scale(1.1);
}

.ai-action-btn svg {
    width: 18px;
    height: 18px;
    fill: var(--ai-accent);
    transition: all 0.3s;
}

/* Mic pulse when recording */
.ai-action-btn.recording svg {
    fill: #ff4d4d;
    animation: ai-mic-pulse 1.25s infinite ease-in-out;
}

@keyframes ai-mic-pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.15);
        opacity: 0.6;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Mobile Overrides at the end for higher specificity */
@media (max-width: 768px) {
    #ai-chat-launcher {
        bottom: var(--ai-bottom, 12px);
        right: 20px !important;
        width: 36px !important;
        height: 36px !important;
    }

    #ai-chat-launcher svg {
        width: 20px !important;
        height: 20px !important;
    }

    #ai-chat-container {
        left: 50% !important;
        right: auto !important;
        transform: translate(-50%, 20px) scale(0.95);
        width: 90vw !important;
        max-width: 360px !important;
        bottom: calc(var(--ai-bottom, 12px) + 60px) !important;
    }

    #ai-chat-container.active {
        transform: translate(-50%, 0) scale(1) !important;
    }
}
