/* ============================================
   XR-CALL — Components
   Buttons, Dock, Modals, Chat, Tooltips
   ============================================ */

/* ── SVG Icon Utility ── */
.icon-svg {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.icon-svg svg {
    width: 1em;
    height: 1em;
    vertical-align: middle;
}

.icon-svg-sm svg {
    width: 16px;
    height: 16px;
}

.icon-svg-md svg {
    width: 20px;
    height: 20px;
}

.icon-svg-lg svg {
    width: 24px;
    height: 24px;
}

.icon-svg-xl svg {
    width: 32px;
    height: 32px;
}

.icon-svg-2xl svg {
    width: 42px;
    height: 42px;
}

.dock-btn .icon-svg svg {
    width: 22px;
    height: 22px;
}

.toast-icon {
    display: inline-flex;
    flex-shrink: 0;
}

.toast-icon svg {
    width: 16px;
    height: 16px;
}

/* ── Glass Card ── */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    transition: all var(--transition-base);
}

.glass-card:hover {
    border-color: var(--glass-border-hover);
    box-shadow: var(--shadow-xl), var(--shadow-glow);
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-xl);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-family: var(--font-primary);
    font-size: var(--text-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.btn:hover::after {
    opacity: 1;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-secondary), var(--accent-primary));
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover {
    box-shadow: 0 6px 25px rgba(99, 102, 241, 0.6);
    transform: translateY(-1px);
}

.btn-glass {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
}

.btn-glass:hover {
    background: var(--glass-bg-hover);
    border-color: var(--glass-border-hover);
}

.btn-danger {
    background: linear-gradient(135deg, #dc2626, #ef4444);
    color: white;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    box-shadow: 0 6px 25px rgba(239, 68, 68, 0.5);
}

.btn-icon {
    width: 48px;
    height: 48px;
    padding: 0;
    border-radius: var(--radius-full);
    font-size: var(--text-xl);
}

.btn-icon.btn-lg {
    width: 56px;
    height: 56px;
    font-size: var(--text-2xl);
}

/* ── Input Fields ── */
.input-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.input-group label {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.input-field {
    width: 100%;
    padding: var(--space-md);
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: var(--text-base);
    transition: all var(--transition-base);
    outline: none;
}

.input-field:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.15);
}

.input-field::placeholder {
    color: var(--text-muted);
}

select.input-field {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* ── Floating Control Dock ── */
.control-dock {
    position: fixed;
    bottom: var(--space-lg);
    left: 50%;
    transform: translateX(-50%) translateY(0);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-xl);
    background: rgba(10, 14, 26, 0.85);
    backdrop-filter: blur(var(--glass-blur-heavy));
    -webkit-backdrop-filter: blur(var(--glass-blur-heavy));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl), var(--shadow-neon);
    z-index: var(--z-dock);
    transition: all var(--transition-slow);
}

.control-dock.auto-hide {
    transform: translateX(-50%) translateY(calc(100% + 40px));
    opacity: 0;
}

.control-dock:hover,
.control-dock.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.dock-btn {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-full);
    background: rgba(30, 41, 59, 0.6);
    color: var(--text-primary);
    font-size: 22px;
    cursor: pointer;
    transition: all var(--transition-base);
    position: relative;
}

.dock-btn:hover {
    background: rgba(30, 41, 59, 0.9);
    border-color: var(--accent-primary);
    transform: scale(1.08);
    box-shadow: var(--shadow-glow);
}

.dock-btn.active {
    background: var(--accent-secondary);
    border-color: var(--accent-primary);
    color: white;
}

.dock-btn.danger {
    background: rgba(220, 38, 38, 0.3);
    border-color: rgba(248, 113, 113, 0.3);
}

.dock-btn.danger:hover {
    background: #dc2626;
    border-color: #f87171;
    box-shadow: 0 0 30px rgba(248, 113, 113, 0.3);
}

.dock-btn.muted {
    background: rgba(248, 113, 113, 0.15);
    border-color: rgba(248, 113, 113, 0.3);
    color: var(--neon-red);
}

.dock-btn .badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    border-radius: var(--radius-full);
    background: var(--neon-red);
    color: white;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: scaleIn var(--transition-spring);
}

.dock-divider {
    width: 1px;
    height: 32px;
    background: var(--glass-border);
    margin: 0 var(--space-xs);
}

/* ── Tooltip ── */
.tooltip {
    position: relative;
}

.tooltip::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%) scale(0.8);
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: var(--text-xs);
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all var(--transition-fast);
    z-index: var(--z-tooltip, 700);
}

.tooltip:hover::before {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}

/* ── Modal Overlay ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base);
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    padding: var(--space-2xl);
    max-width: 480px;
    width: 90%;
    box-shadow: var(--shadow-xl);
    transform: scale(0.9) translateY(20px);
    transition: transform var(--transition-spring);
}

.modal-overlay.active .modal {
    transform: scale(1) translateY(0);
}

.modal h2 {
    font-size: var(--text-xl);
    margin-bottom: var(--space-lg);
    color: var(--text-primary);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-md);
    margin-top: var(--space-xl);
}

/* ── Chat Sidebar (Desktop: Push Layout) ── */
.chat-sidebar {
    width: 0;
    min-width: 0;
    background: rgba(10, 14, 26, 0.95);
    border-left: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    z-index: 610;
    /* Higher than dock to fix input bug */
    transition: width var(--transition-spring), min-width var(--transition-spring);
    overflow: hidden;
    position: relative;
    /* Relative for flex layout */
}

.chat-sidebar.open {
    width: 320px;
    min-width: 320px;
}

/* Remove transform based open/close for desktop */


.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg) var(--space-xl);
    border-bottom: 1px solid var(--glass-border);
}

.chat-header h3 {
    font-size: var(--text-lg);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.chat-message {
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    max-width: 85%;
    animation: slideUp 200ms ease-out;
}

.chat-message.incoming {
    background: var(--bg-tertiary);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.chat-message.outgoing {
    background: rgba(99, 102, 241, 0.2);
    border: 1px solid rgba(99, 102, 241, 0.2);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.chat-message.system {
    align-self: center;
    background: transparent;
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-style: italic;
}

.chat-message .sender {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--accent-primary);
    margin-bottom: 2px;
}

.chat-message .text {
    font-size: var(--text-sm);
    line-height: 1.5;
    word-break: break-word;
}

.chat-message .time {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 4px;
    text-align: right;
}

.chat-input-area {
    padding: var(--space-md);
    border-top: 1px solid var(--glass-border);
    display: flex;
    gap: var(--space-sm);
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    padding: var(--space-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: var(--text-sm);
    resize: none;
    max-height: 120px;
    outline: none;
    transition: border-color var(--transition-fast);
}

.chat-input:focus {
    border-color: var(--accent-primary);
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    background: var(--accent-secondary);
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-base);
    flex-shrink: 0;
}

.chat-send-btn:hover {
    background: var(--accent-primary);
    transform: scale(1.05);
}

/* ── Emoji Picker ── */
.emoji-btn {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.emoji-btn:hover {
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

.emoji-picker {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: var(--space-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: var(--space-md);
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    box-shadow: var(--shadow-xl);
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: all var(--transition-fast);
    z-index: var(--z-dropdown);
}

.emoji-picker.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.emoji-picker button {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    font-size: 20px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.emoji-picker button:hover {
    background: var(--bg-tertiary);
}

/* ── Participants Panel (Desktop: Push Layout) ── */
.participants-panel {
    width: 0;
    min-width: 0;
    background: rgba(10, 14, 26, 0.95);
    border-left: 1px solid var(--glass-border);
    z-index: 610;
    transition: width var(--transition-spring), min-width var(--transition-spring);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.participants-panel.open {
    width: 320px;
    min-width: 320px;
}

/* Remove transform based open/close */


.participant-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-xl);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: background var(--transition-fast);
}

.participant-item:hover {
    background: rgba(255, 255, 255, 0.03);
}

.participant-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--accent-secondary), var(--accent-tertiary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: var(--text-sm);
    color: white;
    flex-shrink: 0;
}

.participant-info {
    flex: 1;
    min-width: 0;
}

.participant-name {
    font-size: var(--text-sm);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.participant-badges {
    display: flex;
    gap: var(--space-xs);
    align-items: center;
}

.participant-badge {
    font-size: 14px;
}

/* ── Settings Panel ── */
.settings-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: var(--z-modal);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base);
}

.settings-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.settings-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 90%;
    max-width: 520px;
    max-height: 80vh;
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    padding: var(--space-2xl);
    z-index: calc(var(--z-modal) + 1);
    opacity: 0;
    pointer-events: none;
    transition: all var(--transition-spring);
}

.settings-overlay.open .settings-panel {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

.settings-panel h2 {
    font-size: var(--text-xl);
    margin-bottom: var(--space-xl);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.settings-section {
    margin-bottom: var(--space-xl);
}

.settings-section h4 {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: var(--space-md);
}

/* ── Toast Notifications ── */
.toast-container {
    position: fixed;
    top: var(--space-xl);
    right: var(--space-xl);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    z-index: var(--z-toast);
    pointer-events: none;
}

.toast {
    padding: var(--space-md) var(--space-xl);
    background: var(--bg-tertiary);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: var(--text-sm);
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    animation: slideIn 300ms ease-out;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.toast.success {
    border-color: var(--neon-green);
}

.toast.error {
    border-color: var(--neon-red);
}

.toast.info {
    border-color: var(--neon-cyan);
}

@keyframes slideIn {
    from {
        transform: translateX(100px);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ── Loading Spinner ── */
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--glass-border);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── Mobile ── */
@media (max-width: 768px) {

    /* Revert to Fixed Overlay for Mobile */
    .chat-sidebar,
    .participants-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        height: 100vh;
        width: 100% !important;
        /* Force full width open */
        min-width: 0;
        transform: translateX(100%);
        transition: transform var(--transition-slow);
        z-index: 800;
        /* High z-index on mobile */
    }

    .chat-sidebar.open,
    .participants-panel.open {
        transform: translateX(0);
    }

    .control-dock {
        bottom: var(--space-md);
        padding: var(--space-sm) var(--space-md);
        gap: var(--space-sm);
        max-width: 90vw;
        overflow-x: auto;
        justify-content: flex-start;
        scrollbar-width: none;
    }

    .control-dock::-webkit-scrollbar {
        display: none;
    }

    .dock-btn, .dock-divider {
        flex-shrink: 0;
    }

    .dock-btn {
        width: 44px;
        height: 44px;
        font-size: 18px;
    }

    .chat-sidebar {
        width: 100%;
    }

    .participants-panel {
        width: 100%;
    }

    .modal {
        width: 95%;
        padding: var(--space-xl);
    }

    .toast-container {
        left: var(--space-md);
        right: var(--space-md);
    }

    .emoji-picker {
        grid-template-columns: repeat(6, 1fr);
        left: 0;
        right: 0;
    }
}

/* ── Very Small Screens ── */
@media (max-width: 480px) {
    .control-dock {
        bottom: var(--space-sm);
        padding: var(--space-xs) var(--space-sm);
        gap: var(--space-xs);
        border-radius: var(--radius-lg);
        max-width: 95vw;
        overflow-x: auto;
        justify-content: flex-start;
        scrollbar-width: none;
    }

    .dock-btn {
        width: 38px;
        height: 38px;
    }

    .dock-btn .icon-svg svg {
        width: 18px;
        height: 18px;
    }

    .dock-divider {
        height: 24px;
    }

    .chat-input-area {
        padding: var(--space-sm);
    }

    .settings-panel {
        padding: var(--space-xl);
        max-width: 100%;
        width: 95%;
    }

    .toast {
        padding: var(--space-sm) var(--space-md);
        font-size: var(--text-xs);
    }
}