/* ===================== AI Shopping Assistant Widget ===================== */

#sd-ai-launcher {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: var(--gold-gradient);
    box-shadow: var(--shadow-gold);
    border: none;
    cursor: pointer;
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.5rem;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    animation: sd-ai-pulse 2.6s infinite;
}

#sd-ai-launcher:hover {
    transform: scale(1.08);
}

#sd-ai-launcher .sd-ai-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: #3ecf68;
    border: 2px solid #fff;
    border-radius: 50%;
}

@keyframes sd-ai-pulse {
    0% { box-shadow: 0 0 0 0 rgba(166, 124, 55, 0.45); }
    70% { box-shadow: 0 0 0 14px rgba(166, 124, 55, 0); }
    100% { box-shadow: 0 0 0 0 rgba(166, 124, 55, 0); }
}

#sd-ai-panel {
    position: fixed;
    right: 24px;
    bottom: 100px;
    width: 370px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100vh - 140px);
    background: var(--bg-card);
    border-radius: 20px;
    border: 1px solid var(--border-gold);
    box-shadow: var(--shadow-soft);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    font-family: var(--font-body);
}

#sd-ai-panel.sd-open {
    display: flex;
    animation: sd-ai-slideup 0.28s ease;
}

@keyframes sd-ai-slideup {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

.sd-ai-header {
    background: var(--gold-gradient);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sd-ai-header .sd-ai-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sd-ai-header .sd-ai-title h4 {
    margin: 0;
    font-family: var(--font-heading);
    font-size: 1.05rem;
    line-height: 1.1;
}

.sd-ai-header .sd-ai-title span {
    display: block;
    font-size: 0.72rem;
    opacity: 0.9;
    margin-top: 2px;
}

/* ---------- Character avatar: state-driven (IDLE / LISTENING / PROCESSING / SPEAKING / ERROR) ----------
   No character art asset yet (see Phase 3 notes) - this is a CSS-only animated
   orb stand-in. Swap the icon for <img class="sd-ai-avatar-img"> once
   ai-character-idle.png / ai-character-speaking.png are generated. */
.sd-ai-header .sd-ai-avatar {
    position: relative;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255,255,255,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.sd-ai-avatar-core {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: rgba(255,255,255,0.18);
    transition: background 0.3s ease;
}

.sd-ai-avatar-ring {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.55);
    opacity: 0;
    transform: scale(0.8);
}

.sd-ai-avatar-icon {
    position: relative;
    z-index: 2;
}

/* IDLE - gentle breathing */
.sd-ai-avatar[data-state="idle"] .sd-ai-avatar-core {
    animation: sd-ai-avatar-breathe 3s ease-in-out infinite;
}

/* LISTENING - pulsing ring, mic is "hearing" */
.sd-ai-avatar[data-state="listening"] .sd-ai-avatar-ring {
    opacity: 1;
    animation: sd-ai-avatar-listen-ring 1.1s ease-out infinite;
    border-color: #E4453A;
}

/* PROCESSING - fast rotating ring, "thinking" */
.sd-ai-avatar[data-state="processing"] .sd-ai-avatar-ring {
    opacity: 1;
    transform: scale(1);
    border-color: transparent;
    border-top-color: #fff;
    border-right-color: rgba(255,255,255,0.5);
    animation: sd-ai-avatar-spin 0.8s linear infinite;
}

/* SPEAKING - core glows brighter, waveform bars shown */
.sd-ai-avatar[data-state="speaking"] .sd-ai-avatar-core {
    background: #fff;
    box-shadow: 0 0 12px rgba(255,255,255,0.85);
}
.sd-ai-avatar[data-state="speaking"] .sd-ai-avatar-icon {
    color: var(--gold-dark);
}

/* ERROR - red flash / shake */
.sd-ai-avatar[data-state="error"] .sd-ai-avatar-core {
    background: #E4453A;
    animation: sd-ai-avatar-shake 0.4s ease-in-out;
}

@keyframes sd-ai-avatar-breathe {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

@keyframes sd-ai-avatar-listen-ring {
    0% { opacity: 0.9; transform: scale(0.85); }
    100% { opacity: 0; transform: scale(1.5); }
}

@keyframes sd-ai-avatar-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes sd-ai-avatar-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    75% { transform: translateX(3px); }
}

/* Audio waveform shown on the avatar while SPEAKING */
.sd-ai-waveform {
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 10px;
}

.sd-ai-waveform i {
    display: block;
    width: 2px;
    background: var(--gold-primary);
    border-radius: 1px;
    animation: sd-ai-wave-bar 0.9s ease-in-out infinite;
}

.sd-ai-waveform i:nth-child(1) { height: 4px; animation-delay: 0s; }
.sd-ai-waveform i:nth-child(2) { height: 8px; animation-delay: 0.1s; }
.sd-ai-waveform i:nth-child(3) { height: 10px; animation-delay: 0.2s; }
.sd-ai-waveform i:nth-child(4) { height: 6px; animation-delay: 0.3s; }
.sd-ai-waveform i:nth-child(5) { height: 4px; animation-delay: 0.4s; }

@keyframes sd-ai-wave-bar {
    0%, 100% { transform: scaleY(0.4); }
    50% { transform: scaleY(1.2); }
}

@media (prefers-reduced-motion: reduce) {
    .sd-ai-avatar-core,
    .sd-ai-avatar-ring,
    .sd-ai-waveform i {
        animation: none !important;
    }
}

.sd-ai-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sd-ai-header-actions button {
    background: rgba(255,255,255,0.18);
    border: none;
    color: #fff;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: background 0.2s;
}

.sd-ai-header-actions button:hover {
    background: rgba(255,255,255,0.32);
}

.sd-ai-header-actions button.sd-active {
    background: #fff;
    color: var(--gold-dark);
}

.sd-ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg-light);
}

.sd-ai-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.88rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.sd-ai-msg.bot {
    background: #fff;
    border: 1px solid var(--border-gold);
    color: var(--text-dark);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.sd-ai-msg.user {
    background: var(--gold-gradient);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.sd-ai-msg.typing {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 12px 16px;
}

.sd-ai-msg.typing span {
    width: 6px;
    height: 6px;
    background: var(--gold-primary);
    border-radius: 50%;
    display: inline-block;
    animation: sd-ai-bounce 1.2s infinite ease-in-out;
}

.sd-ai-msg.typing span:nth-child(2) { animation-delay: 0.15s; }
.sd-ai-msg.typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes sd-ai-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.sd-ai-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 16px 10px;
    background: var(--bg-light);
}

.sd-ai-suggestions button {
    background: #fff;
    border: 1px solid var(--border-gold);
    color: var(--gold-dark);
    font-size: 0.72rem;
    padding: 6px 10px;
    border-radius: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.sd-ai-suggestions button:hover {
    background: var(--gold-light);
    color: #1A1A1A;
}

.sd-ai-inputbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--border-gold);
    background: #fff;
}

.sd-ai-inputbar input[type="text"] {
    flex: 1;
    border: 1px solid var(--border-gold);
    border-radius: 20px;
    padding: 10px 14px;
    font-size: 0.85rem;
    outline: none;
    font-family: var(--font-body);
    color: var(--text-dark);
    background: var(--bg-light);
}

.sd-ai-inputbar input[type="text"]:focus {
    border-color: var(--gold-primary);
}

.sd-ai-inputbar button.sd-icon-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    border-radius: 50%;
    border: 1px solid var(--border-gold);
    background: var(--bg-light);
    color: var(--gold-dark);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    transition: background 0.2s, color 0.2s;
}

.sd-ai-inputbar button.sd-icon-btn:hover {
    background: var(--gold-light);
}

.sd-ai-inputbar button.sd-mic-active {
    background: #E4453A;
    border-color: #E4453A;
    color: #fff;
    animation: sd-ai-mic-pulse 1s infinite;
}

@keyframes sd-ai-mic-pulse {
    0% { box-shadow: 0 0 0 0 rgba(228, 69, 58, 0.5); }
    70% { box-shadow: 0 0 0 10px rgba(228, 69, 58, 0); }
    100% { box-shadow: 0 0 0 0 rgba(228, 69, 58, 0); }
}

.sd-ai-inputbar button.sd-send-btn {
    background: var(--gold-gradient);
    border: none;
    color: #fff;
}

.sd-ai-listening-hint {
    font-size: 0.7rem;
    color: var(--gold-dark);
    padding: 0 16px 8px;
    background: var(--bg-light);
    display: none;
}

.sd-ai-listening-hint.sd-show {
    display: block;
}

@media (max-width: 480px) {
    #sd-ai-panel {
        right: 12px;
        left: 12px;
        width: auto;
        bottom: 90px;
        height: 70vh;
        max-height: calc(100vh - 110px);
    }
    #sd-ai-launcher {
        right: 16px;
        bottom: 16px;
    }
}

/* Keyboard accessibility: visible focus rings inside the AI panel */
#sd-ai-panel button:focus-visible,
#sd-ai-panel input:focus-visible,
#sd-ai-launcher:focus-visible {
    outline: 2px solid var(--gold-primary);
    outline-offset: 2px;
}

/* Touch target sizing: keep interactive controls comfortably tappable */
.sd-ai-inputbar button.sd-icon-btn,
.sd-ai-header-actions button,
#sd-ai-launcher {
    min-width: 44px;
    min-height: 44px;
}
