/* ElevenLabs-Style Embeddable Widget - White, Red, Black */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-red: #ff0000;
    --primary-red-hover: #cc0000;
    --primary-red-light: rgba(255, 0, 0, 0.1);
    --text-black: #000000;
    --text-gray: #666666;
    --bg-white: #ffffff;
    --bg-light-gray: #f8f8f8;
    --border-gray: #e0e0e0;
    --shadow: rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, Arial, sans-serif;
    background: #f5f5f5;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* Widget Container - Embeddable */
.widget-container {
    width: 100%;
    max-width: 400px;
    background: var(--bg-white);
    border-radius: 20px;
    box-shadow: 0 8px 32px var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Widget Header */
.widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-gray);
}

.widget-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-black);
}

.widget-header-buttons {
    display: flex;
    gap: 8px;
}

.widget-clear-btn,
.widget-end-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-gray);
    transition: all 0.2s;
}

.widget-clear-btn:hover {
    background: var(--bg-light-gray);
    color: var(--text-black);
}

.widget-end-btn:hover {
    background: var(--primary-red-light);
    color: var(--primary-red);
}

/* Widget Body */
.widget-body {
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Spherical Visualizer Container */
.visualizer-container {
    position: relative;
    width: 280px;
    height: 280px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

#visualizer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Center Control Button */
.control-button {
    position: relative;
    z-index: 10;
    width: 80px;
    height: 80px;
    border: none;
    border-radius: 50%;
    background: var(--primary-red);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 16px rgba(255, 0, 0, 0.3);
}

.control-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 24px rgba(255, 0, 0, 0.4);
}

.control-button:active {
    transform: scale(0.95);
}

.control-button[data-state="listening"] {
    animation: pulse-red 2s ease-in-out infinite;
}

.control-button[data-state="processing"],
.control-button[data-state="speaking"] {
    background: var(--text-black);
    cursor: not-allowed;
}

@keyframes pulse-red {
    0%, 100% {
        box-shadow: 0 4px 16px rgba(255, 0, 0, 0.3);
    }
    50% {
        box-shadow: 0 4px 32px rgba(255, 0, 0, 0.6);
    }
}

/* Mute Button */
.mute-button {
    position: absolute;
    bottom: 20px;
    right: 20px;
    z-index: 11;
    width: 44px;
    height: 44px;
    border: 2px solid var(--border-gray);
    background: var(--bg-white);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--text-gray);
}

.mute-button:hover {
    border-color: var(--primary-red);
    color: var(--primary-red);
}

.mute-button[data-muted="true"] {
    background: var(--primary-red);
    border-color: var(--primary-red);
    color: white;
}

.mute-icon-off {
    display: none;
}

.mute-button[data-muted="true"] .mute-icon-on {
    display: none;
}

.mute-button[data-muted="true"] .mute-icon-off {
    display: block;
}

/* State Label */
.state-label {
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 13px;
    color: var(--text-gray);
    white-space: nowrap;
}

/* Transcript Box */
.transcript-box {
    min-height: 60px;
    padding: 16px;
    background: var(--bg-light-gray);
    border-radius: 12px;
    font-size: 14px;
    color: var(--text-black);
    line-height: 1.6;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s;
}

.transcript-box.visible {
    opacity: 1;
    transform: translateY(0);
}

.transcript-box.partial {
    color: var(--text-gray);
    font-style: italic;
}

.transcript-box.final {
    color: var(--text-black);
    font-weight: 500;
}

/* History Container */
.history-container {
    border-top: 1px solid var(--border-gray);
    padding-top: 12px;
}

.history-toggle {
    width: 100%;
    padding: 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-black);
    transition: all 0.2s;
}

.history-toggle:hover {
    background: var(--bg-light-gray);
    border-radius: 8px;
}

.history-toggle svg {
    transition: transform 0.3s;
}

.history-container.expanded .history-toggle svg {
    transform: rotate(180deg);
}

.history-messages {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.history-container.expanded .history-messages {
    max-height: 300px;
    overflow-y: auto;
    margin-top: 12px;
}

.message {
    display: flex;
    margin-bottom: 12px;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    justify-content: flex-end;
}

.message.assistant {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
}

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

.message.assistant .message-bubble {
    background: var(--bg-light-gray);
    color: var(--text-black);
    border-bottom-left-radius: 4px;
}

/* Widget Footer */
.widget-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    background: var(--bg-light-gray);
    border-top: 1px solid var(--border-gray);
    font-size: 12px;
    color: var(--text-gray);
}

.status-indicator {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary-red);
}

.status-indicator.active {
    animation: blink 1.5s ease-in-out infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Scrollbar */
.history-messages::-webkit-scrollbar {
    width: 4px;
}

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

.history-messages::-webkit-scrollbar-thumb {
    background: var(--border-gray);
    border-radius: 2px;
}

.history-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-gray);
}

/* Responsive */
@media (max-width: 480px) {
    .widget-container {
        max-width: 100%;
        border-radius: 0;
    }

    .visualizer-container {
        width: 240px;
        height: 240px;
    }

    #visualizer {
        width: 240px;
        height: 240px;
    }

    .control-button {
        width: 70px;
        height: 70px;
    }
}
