/* Reset de Interacción Premium: Eliminar el recuadro azul/gris al dar tap en móviles */
* {
    -webkit-tap-highlight-color: transparent !important;
    -webkit-touch-callout: none !important;
}

button:focus, 
a:focus, 
input:focus {
    outline: none !important;
}

/* Evitar destellos blancos durante el ajuste de viewport */
@media (max-width: 768px) {
    body.synapse-active,
    body.synapse-active html {
        background: var(--color-bg) !important;
    }
}

/* Coordinación de Botones Flotantes - Esquina DERECHA */
#synapse-trigger, 
#core-fab {
    position: fixed !important;
    right: 24px !important;
    left: auto !important;
    z-index: 10001 !important;
    transition: opacity 0.3s ease, transform 0.3s ease !important;
}

/* Ocultar botones cuando el asistente está abierto */
body.synapse-active #synapse-trigger,
body.synapse-active #core-fab,
body.synapse-active #debugToggle {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: scale(0.9) !important;
}

/* Nivel 1: Synapse (Derecha) */
#synapse-trigger {
    bottom: 24px !important;
}

/* Nivel 2: Standalone / Profile (Derecha - Apilado sobre Synapse) */
#core-fab {
    bottom: 92px !important; /* 24 + 56 + 12 */
}

/* Coordinación de Botones Flotantes - Esquina IZQUIERDA */
#debugToggle {
    position: fixed !important;
    left: 24px !important;
    bottom: 24px !important; /* El debug vuelve a la base en la izquierda */
    right: auto !important;
    z-index: 10001 !important;
    margin: 0 !important;
}

/* Ajustes de apertura de menús para botones a la DERECHA */
#core-fab .core-fab-menu {
    right: 0 !important;
    left: auto !important;
}

/* SIDE-PANEL GLOBAL - Ahora abre desde la DERECHA */
.synapse-sidebar {
    position: fixed;
    top: 0;
    right: -100%; /* Oculto a la derecha */
    left: auto;
    width: 400px;
    height: 100dvh; /* Altura dinámica para móviles */
    background: rgba(var(--color-surface-rgb), 0.85);
    backdrop-filter: blur(25px) saturate(180%);
    -webkit-backdrop-filter: blur(25px) saturate(180%);
    border-left: 1px solid var(--color-border);
    z-index: 10002;
    transition: right 0.4s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.4s;
    display: grid; /* Cambiado a Grid para máxima estabilidad */
    grid-template-rows: auto 1fr auto;
    box-shadow: -20px 0 50px rgba(0, 0, 0, 0.2);
    visibility: hidden;
    pointer-events: none;
    overflow: hidden; /* Evitar que el panel completo scrollee */
    overscroll-behavior: none; /* Bloquear gestos de arrastre nativos */
}

.synapse-sidebar.open {
    right: 0;
    visibility: visible;
    pointer-events: auto;
}

/* El botón circular principal */
.synapse-global-trigger {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3), inset 0 1px 1px rgba(255, 255, 255, 0.1);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: hidden;
    color: var(--color-primary);
}

.synapse-global-trigger:hover {
    transform: scale(1.1) rotate(5deg);
    border-color: var(--color-primary);
    box-shadow: 0 8px 25px rgba(var(--color-primary-rgb), 0.4);
}

.synapse-global-trigger.active {
    background: var(--color-primary);
    color: white !important;
}

.synapse-global-trigger svg {
    display: block;
    pointer-events: none;
}

/* Indicador de "Cerebros Online" */
.synapse-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--color-surface);
    transition: background 0.3s ease;
}

.synapse-badge.online {
    background: #10b981; /* Emerald 500 */
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}

.synapse-badge.offline {
    background: #6b7280; /* Gray 500 */
}

/* SIDE-PANEL GLOBAL */
.synapse-sidebar.open ~ .synapse-overlay {
    opacity: 1;
    pointer-events: auto;
}

/* Estilos de Chat y Header (Reaprovechados y mejorados) */
.syn-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 85px; /* Altura fija calculada */
    padding: 0 24px;
    padding-top: env(safe-area-inset-top, 0);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
    background: rgba(var(--color-surface-rgb), 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.syn-node-selector {
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
}

.syn-chat-container {
    position: absolute;
    top: 85px; /* Mismo que la altura del header */
    bottom: 110px; /* Espacio para el footer */
    left: 0;
    right: 0;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0;
}

/* Truco para clavar mensajes abajo (estilo ChatGPT/Claude) */
.syn-chat-container > :first-child {
    margin-top: auto !important;
}

.syn-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    animation: synSlideIn 0.3s ease-out;
    color: var(--color-text);
}

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

.syn-message.user {
    align-self: flex-end;
    background: var(--color-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.syn-message.ai {
    align-self: flex-start;
    background: var(--color-surface-alt);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-bottom-left-radius: 4px;
}

.syn-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 110px; /* Altura fija calculada */
    padding: 0 24px;
    padding-bottom: env(safe-area-inset-bottom, 20px);
    border-top: 1px solid var(--color-border);
    background: rgba(var(--color-surface-rgb), 0.95);
    display: flex;
    flex-direction: column;
    justify-content: center;
    z-index: 100;
}

.syn-input-group {
    display: flex;
    gap: 12px;
    background: var(--color-bg);
    padding: 8px;
    border-radius: 12px;
    border: 1px solid var(--color-border);
}

.syn-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--color-text);
    padding: 8px;
    outline: none;
    font-size: 0.9rem;
}

.syn-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--color-primary);
    color: white !important;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.syn-send-btn svg {
    fill: none !important;
    stroke: white !important;
    stroke-width: 2px;
    display: block;
    width: 18px;
    height: 18px;
}

.syn-send-btn:hover {
    transform: scale(1.05);
}

/* Responsividad */
@media (max-width: 640px) {
    .synapse-sidebar {
        width: 100%;
        right: -100%;
        left: auto;
    }
    
    .synapse-sidebar.open {
        right: 0;
    }

    #synapse-trigger, 
    #core-fab,
    #debugToggle {
        right: 16px !important;
        left: auto !important;
    }

    #synapse-trigger {
        bottom: 80px !important;
    }

    #core-fab {
        bottom: 148px !important; /* 80 + 56 + 12 */
    }
    
    #debugToggle {
        left: 16px !important;
        bottom: 80px !important;
        right: auto !important;
    }

    /* Evitar destellos blancos durante el ajuste de viewport - Solo Móvil */
    body.synapse-active,
    body.synapse-active html {
        background: #0f1117 !important;
    }
}

