/* Solo2 Component: Tunnel Row (Premium Density) */

.tunnel-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    cursor: pointer;
    transition: background-color var(--transition-fast);
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    position: relative;
    overflow: hidden;
    /* iOS/Safari touch improvements */
    -webkit-tap-highlight-color: rgba(99, 102, 241, 0.3);
    -webkit-touch-callout: none;
    user-select: none;
}

.tunnel-item:hover {
    background-color: rgba(99, 102, 241, 0.08);
}

.tunnel-item.selected {
    background-color: rgba(99, 102, 241, 0.15);
}

.tunnel-item.selected::before {
    content: '';
    position: absolute;
    left: 0;
    top: var(--space-sm);
    bottom: var(--space-sm);
    width: 4px;
    background-color: var(--color-primary);
    border-radius: 0 4px 4px 0;
}

/* Avatar con gradiente dinámico */
.tunnel-avatar {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, 
        hsl(var(--user-hue, 220), 60%, 45%), 
        hsl(calc(var(--user-hue, 220) + 30), 70%, 35%)
    );
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: var(--fs-xl);
    color: white;
    flex-shrink: 0;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
    box-shadow: var(--shadow-sm);
}

/* Avatar propio clickable */
#user-avatar {
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}
#user-avatar:hover {
    transform: scale(1.05);
}
#user-avatar:active {
    transform: scale(0.97);
}

/* Avatar con foto de perfil */
.tunnel-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--radius-full);
}

/* Avatar propio en sidebar profile */
#user-avatar .tunnel-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--radius-full);
}

/* Cuerpo de la fila */
.tunnel-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tunnel-name-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 6px;
}

.tunnel-name {
    font-weight: 700;
    font-size: var(--fs-md);
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.tunnel-last-msg {
    font-size: var(--fs-sm);
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Fila de estado del túnel (indicadores + texto) */
.tunnel-status-row {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: var(--fs-xs);
    color: var(--color-text-muted);
}

.tunnel-conn-indicator {
    font-size: var(--fs-2xs);
    line-height: 1;
    flex-shrink: 0;
    display: inline-block;
}

/* Latido sutil solo para indicador conectado */
.tunnel-conn-indicator.heartbeat {
    animation: conn-heartbeat 3s ease-in-out infinite;
}

@keyframes conn-heartbeat {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.tunnel-e2e-indicator {
    font-size: var(--fs-2xs);
    font-weight: 600;
    line-height: 1;
    padding: 1px 3px;
    background: rgba(34, 197, 94, 0.2);
    color: var(--color-success, #22c55e);
    border-radius: 2px;
    flex-shrink: 0;
}

.tunnel-e2e-indicator.hidden {
    display: none;
}

.tunnel-status-text {
    font-size: var(--fs-2xs);
    font-weight: 500;
    white-space: nowrap;
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.tunnel-touch-toggle,
.tunnel-touch-btn {
    background: none;
    border: none;
    padding: 2px 4px;
    cursor: pointer;
    font-size: var(--fs-sm);
    opacity: 0.6;
    transition: opacity 0.2s, transform 0.2s;
    border-radius: 4px;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tunnel-touch-toggle:hover,
.tunnel-touch-btn:hover {
    opacity: 1;
    transform: scale(1.1);
    background: rgba(255, 255, 255, 0.1);
}

.tunnel-touch-toggle:active,
.tunnel-touch-btn:active {
    transform: scale(0.95);
}

.tunnel-touch-toggle.opacity-50 {
    opacity: 0.3;
}


/* Botones de toque (derecha) */
.tunnel-meta {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.tunnel-time {
    font-size: var(--fs-xs);
    color: var(--color-text-muted);
    font-weight: 500;
}


/* Punto de conexión */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
}

.status-online { 
    background-color: var(--color-success); 
    box-shadow: 0 0 6px var(--color-success);
}

.status-offline {
    background-color: var(--color-text-muted);
    opacity: 0.5;
}

/* Badge de La Bóveda */
.vault-badge {
    font-size: var(--fs-xs);
    color: var(--color-amber);
    display: flex;
    align-items: center;
}

.vault-badge.hidden {
    display: none;
}

/* Badges de estado en tunnel-status-row */
.tunnel-status-row .unread-badge {
    background-color: var(--color-primary, #6366f1);
    color: white;
    font-size: var(--fs-2xs);
    padding: 1px 4px;
    border-radius: 9999px;
    font-weight: 700;
    flex-shrink: 0;
}

.tunnel-status-row .queued-badge {
    background-color: var(--color-amber, #f59e0b);
    color: white;
    font-size: var(--fs-2xs);
    padding: 1px 4px;
    border-radius: 9999px;
    font-weight: 700;
    flex-shrink: 0;
}

.tunnel-status-row .unread-badge.hidden,
.tunnel-status-row .queued-badge.hidden {
    display: none;
}

/* Túnel cerrado por el peer */
.tunnel-item.tunnel-deleted {
    opacity: 0.55;
}

.tunnel-item.tunnel-deleted .tunnel-avatar {
    background: linear-gradient(135deg, #6b7280, #4b5563);
    filter: grayscale(0.6);
}

.tunnel-item.tunnel-deleted .tunnel-meta {
    display: none;
}

/* Cuenta eliminada del servidor (peer_gone) */
.tunnel-item.tunnel-gone {
    opacity: 0.45;
}

.tunnel-item.tunnel-gone .tunnel-avatar {
    background: linear-gradient(135deg, #6b7280, #4b5563);
    filter: grayscale(0.8);
}

.tunnel-item.tunnel-gone .tunnel-meta {
    display: none;
}

/* Túnel silenciado (muted) */
.tunnel-item.tunnel-muted {
    opacity: 0.6;
}

.tunnel-item.tunnel-muted .tunnel-avatar {
    background: linear-gradient(135deg, #92400e, #78350f);
    filter: grayscale(0.3);
}

/* Animación de toque recibido - 2 pulsos suaves y lentos */
.tunnel-item.touch-pulse {
    animation: touch-pulse 3s ease-in-out;
}

@keyframes touch-pulse {
    0% {
        background-color: rgba(234, 179, 8, 0.4);
        box-shadow: inset 0 0 20px rgba(234, 179, 8, 0.3);
    }
    25% {
        background-color: rgba(234, 179, 8, 0.1);
        box-shadow: inset 0 0 5px rgba(234, 179, 8, 0.1);
    }
    50% {
        background-color: rgba(234, 179, 8, 0.4);
        box-shadow: inset 0 0 20px rgba(234, 179, 8, 0.3);
    }
    75% {
        background-color: rgba(234, 179, 8, 0.1);
        box-shadow: inset 0 0 5px rgba(234, 179, 8, 0.1);
    }
    100% {
        background-color: transparent;
        box-shadow: none;
    }
}

/* Indicador persistente de toque pendiente */
.tunnel-item.touch-pending {
    border-left: 3px solid rgba(234, 179, 8, 0.6);
    transition: border-left 0.3s ease;
}

.touch-time-badge {
    font-size: 9px;
    color: rgba(234, 179, 8, 0.8);
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
    margin-left: 2px;
}
