/* ═══════════════════════════════════════════════════════════════════════════
   Siren AI — 3D Avatar Widget & Creator Styles
   Floating companion widget + fullscreen creator panel
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Avatar Creator Full-Screen Overlay ─────────────────────────────── */
#avatar-creator-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(5, 10, 20, 0.92);
    backdrop-filter: blur(16px);
    align-items: stretch;
    justify-content: stretch;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
#avatar-creator-overlay.active { display: flex; }

.avatar-creator-panel {
    display: flex;
    width: 100%;
    height: 100%;
    gap: 0;
}

/* ── Left: 3D Viewport ─────────────────────────────────────────────── */
.avatar-viewport {
    flex: 1;
    position: relative;
    background: radial-gradient(ellipse at center, #0f172a 0%, #020617 100%);
    overflow: hidden;
    min-width: 0;
}
.avatar-viewport canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* Grid floor overlay */
.avatar-viewport::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 30%;
    background: linear-gradient(to top, rgba(99, 102, 241, 0.05) 0%, transparent 100%);
    pointer-events: none;
}

/* Viewport toolbar */
.viewport-toolbar {
    position: absolute;
    top: 16px;
    left: 16px;
    display: flex;
    gap: 8px;
    z-index: 2;
}
.viewport-toolbar button {
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: #e2e8f0;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
    backdrop-filter: blur(8px);
}
.viewport-toolbar button:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: rgba(99, 102, 241, 0.6);
}
.viewport-toolbar button.active {
    background: rgba(99, 102, 241, 0.3);
    border-color: #6366f1;
    color: #a5b4fc;
}

/* Viewport stats */
.viewport-stats {
    position: absolute;
    bottom: 16px;
    left: 16px;
    font-size: 11px;
    color: rgba(148, 163, 184, 0.6);
    z-index: 2;
    font-family: 'JetBrains Mono', monospace;
}

/* Close button */
.avatar-creator-close {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 10;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #f87171;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    backdrop-filter: blur(8px);
}
.avatar-creator-close:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: #ef4444;
}

/* ── Right: Builder Controls ───────────────────────────────────────── */
.avatar-builder {
    width: 380px;
    min-width: 380px;
    background: rgba(15, 23, 42, 0.95);
    border-left: 1px solid rgba(99, 102, 241, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.builder-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid rgba(99, 102, 241, 0.1);
}
.builder-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #e2e8f0;
    display: flex;
    align-items: center;
    gap: 10px;
}
.builder-header h2::before {
    content: '◆';
    color: #6366f1;
    font-size: 14px;
}
.builder-subtitle {
    margin: 4px 0 0;
    font-size: 12px;
    color: #64748b;
}

.builder-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px 24px;
    scrollbar-width: thin;
    scrollbar-color: rgba(99, 102, 241, 0.3) transparent;
}
.builder-body::-webkit-scrollbar { width: 6px; }
.builder-body::-webkit-scrollbar-track { background: transparent; }
.builder-body::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.3);
    border-radius: 3px;
}

/* Builder sections */
.builder-section {
    margin-bottom: 20px;
}
.builder-section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #6366f1;
    margin-bottom: 10px;
    font-weight: 600;
}

/* Option grids */
.option-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}
.option-grid.two-col { grid-template-columns: repeat(2, 1fr); }

.option-btn {
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(71, 85, 105, 0.3);
    color: #cbd5e1;
    padding: 8px 6px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 11px;
    text-align: center;
    transition: all 0.15s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.option-btn:hover {
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.4);
}
.option-btn.selected {
    background: rgba(99, 102, 241, 0.2);
    border-color: #6366f1;
    color: #a5b4fc;
    font-weight: 500;
}

/* Color swatches */
.color-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}
.color-swatch {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 8px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
}
.color-swatch:hover {
    transform: scale(1.1);
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.4);
}
.color-swatch.selected {
    border-color: #6366f1;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.3);
}
.color-swatch::after {
    content: attr(data-label);
    position: absolute;
    bottom: -16px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 8px;
    color: #64748b;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}
.color-swatch:hover::after { opacity: 1; }

/* Scale slider */
.scale-control {
    display: flex;
    align-items: center;
    gap: 12px;
}
.scale-control input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    height: 4px;
    background: rgba(99, 102, 241, 0.2);
    border-radius: 2px;
    outline: none;
}
.scale-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #6366f1;
    cursor: pointer;
}
.scale-value {
    font-size: 12px;
    color: #a5b4fc;
    min-width: 36px;
    text-align: right;
    font-family: 'JetBrains Mono', monospace;
}

/* Builder footer */
.builder-footer {
    padding: 16px 24px;
    border-top: 1px solid rgba(99, 102, 241, 0.1);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.builder-footer .btn-build {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.builder-footer .btn-build:hover {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
}
.builder-footer .btn-build:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}
.builder-footer .btn-build .spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.builder-footer .btn-secondary {
    width: 100%;
    padding: 10px;
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(71, 85, 105, 0.3);
    border-radius: 8px;
    color: #94a3b8;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}
.builder-footer .btn-secondary:hover {
    background: rgba(71, 85, 105, 0.3);
    color: #e2e8f0;
}

/* ── Saved Avatars List ────────────────────────────────────────────── */
.saved-avatars-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 120px;
    overflow-y: auto;
}
.saved-avatar-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    background: rgba(30, 41, 59, 0.4);
    cursor: pointer;
    transition: background 0.15s;
    font-size: 11px;
    color: #cbd5e1;
}
.saved-avatar-item:hover { background: rgba(99, 102, 241, 0.1); }
.saved-avatar-item.active {
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.3);
}
.saved-avatar-item .avatar-thumb {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    background: #1e293b;
    flex-shrink: 0;
    overflow: hidden;
}
.saved-avatar-item .avatar-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.saved-avatar-item .avatar-meta { flex: 1; min-width: 0; }
.saved-avatar-item .avatar-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.saved-avatar-item .avatar-detail {
    font-size: 9px;
    color: #64748b;
}
.saved-avatar-item .btn-delete-avatar {
    flex-shrink: 0;
    background: none;
    border: none;
    color: #64748b;
    cursor: pointer;
    padding: 2px 4px;
    font-size: 12px;
    opacity: 0;
    transition: all 0.15s;
}
.saved-avatar-item:hover .btn-delete-avatar { opacity: 0.7; }
.saved-avatar-item .btn-delete-avatar:hover { color: #ef4444; opacity: 1; }


/* ═══════════════════════════════════════════════════════════════════════
   Floating Companion Widget
   ═══════════════════════════════════════════════════════════════════════ */
#avatar-companion-widget {
    position: fixed;
    z-index: 9999;
    width: 180px;
    height: 220px;
    cursor: grab;
    transition: box-shadow 0.3s;
    pointer-events: auto;
}
#avatar-companion-widget.dragging { cursor: grabbing; }
#avatar-companion-widget.minimized {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
}

/* Widget container */
.companion-container {
    width: 100%;
    height: 100%;
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    background: radial-gradient(ellipse at 50% 80%, rgba(99, 102, 241, 0.08) 0%, transparent 70%);
}
#avatar-companion-widget.minimized .companion-container {
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
}

/* Widget canvas */
.companion-canvas-wrap {
    width: 100%;
    height: 100%;
}
.companion-canvas-wrap canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* Widget glow ring */
.companion-glow {
    position: absolute;
    inset: -4px;
    border-radius: 20px;
    border: 2px solid transparent;
    pointer-events: none;
    transition: border-color 0.5s, box-shadow 0.5s;
}
#avatar-companion-widget[data-state="talking"] .companion-glow {
    border-color: rgba(99, 102, 241, 0.5);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.3);
    animation: pulse-glow 1s ease-in-out infinite;
}
#avatar-companion-widget[data-state="thinking"] .companion-glow {
    border-color: rgba(168, 85, 247, 0.4);
    box-shadow: 0 0 16px rgba(168, 85, 247, 0.25);
    animation: pulse-glow 2s ease-in-out infinite;
}
#avatar-companion-widget[data-state="listening"] .companion-glow {
    border-color: rgba(34, 211, 238, 0.4);
    box-shadow: 0 0 16px rgba(34, 211, 238, 0.25);
    animation: pulse-glow 1.5s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Widget hover controls */
.companion-controls {
    position: absolute;
    top: 4px;
    right: 4px;
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 3;
}
#avatar-companion-widget:hover .companion-controls { opacity: 1; }

.companion-ctrl-btn {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: rgba(15, 23, 42, 0.8);
    color: #94a3b8;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.companion-ctrl-btn:hover {
    background: rgba(99, 102, 241, 0.3);
    color: #e2e8f0;
}

/* Expression label */
.companion-expression-label {
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 9px;
    color: rgba(148, 163, 184, 0.6);
    pointer-events: none;
    text-transform: capitalize;
    z-index: 2;
}

/* Minimized avatar icon */
.companion-mini-icon {
    display: none;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: white;
}
#avatar-companion-widget.minimized .companion-mini-icon { display: flex; }
#avatar-companion-widget.minimized .companion-canvas-wrap,
#avatar-companion-widget.minimized .companion-glow,
#avatar-companion-widget.minimized .companion-controls,
#avatar-companion-widget.minimized .companion-expression-label { display: none; }


/* ── Loading overlay ───────────────────────────────────────────────── */
.avatar-loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(5, 10, 20, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 5;
    gap: 12px;
}
.avatar-loading-overlay .loader-ring {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(99, 102, 241, 0.1);
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.avatar-loading-overlay .loader-text {
    font-size: 13px;
    color: #a5b4fc;
}

/* ── Upload drop zone ──────────────────────────────────────────────── */
.avatar-drop-zone {
    border: 2px dashed rgba(99, 102, 241, 0.3);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    color: #64748b;
    font-size: 12px;
    transition: all 0.2s;
    cursor: pointer;
}
.avatar-drop-zone:hover,
.avatar-drop-zone.dragover {
    border-color: #6366f1;
    background: rgba(99, 102, 241, 0.05);
    color: #a5b4fc;
}

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .avatar-creator-panel {
        flex-direction: column;
    }
    .avatar-builder {
        width: 100%;
        min-width: 0;
        max-height: 50vh;
    }
    .avatar-viewport {
        min-height: 40vh;
    }
    #avatar-companion-widget {
        width: 120px;
        height: 150px;
    }
}
