/* Solo2 - Core Styles */
/* Base layout, forms, buttons, cards, animations, and interactive states */
/* Theme system → themes.css | Notifications → notifications.css */
/* Modal → modal.css | Tooltips → tooltip.css | Lobby → duende.css */

/* ============================================================
   VIEWS & BASE
   ============================================================ */

* { box-sizing: border-box; }

body {
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--bg-primary) 50%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    transition: background 0.3s ease, color 0.3s ease;
}

.view {
    display: none !important;
    width: 100%;
    height: 100%;
    overflow: hidden; /* Prevent 200vw container from leaking */
    background: var(--bg-dark); /* Blindaje: fondo sólido evita ver body-gradient durante transiciones */
}
.view.active {
    display: flex !important;
}

#view-loading {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--bg-dark);
}

/* Effects */
.glow { box-shadow: 0 0 40px rgba(99, 102, 241, 0.3); }

/* Tailwind's .hidden loads BEFORE our CSS → any class here with display:X
   wins over .hidden by cascade order (same specificity, last wins).
   Fix: make .hidden always win, regardless of source order. */
.hidden {
    display: none !important;
}

/* ============================================================
   FORM ELEMENTS
   ============================================================ */

.input-field {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border-radius: 1.25rem;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s, background 0.3s;
    font-size: var(--fs-base);
}
.input-field::placeholder { color: var(--text-secondary); }
.input-field:focus { border-color: var(--accent); }

/* Sidebar tunnel finder keeps standard radius */
#sb-tunnel-finder { border-radius: 0.5rem; }

/* Anti-autofill: forzar tema oscuro cuando el navegador autorellena */
#sb-tunnel-finder:-webkit-autofill,
#sb-tunnel-finder:-webkit-autofill:hover,
#sb-tunnel-finder:-webkit-autofill:focus,
#inline-tunnel-code:-webkit-autofill,
#inline-tunnel-code:-webkit-autofill:hover,
#inline-tunnel-code:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px var(--bg-primary) inset !important;
    -webkit-text-fill-color: var(--text-primary) !important;
    caret-color: var(--text-primary) !important;
    transition: background-color 5000s ease-in-out 0s;
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn-primary {
    width: 100%;
    background: var(--accent-dark);
    color: white;
    font-weight: bold;
    padding: 0.5rem;
    border-radius: 0.5rem;
    border: none;
    cursor: pointer;
    transition: background 0.2s;
    font-size: var(--fs-base);
}
.btn-primary:hover { background: var(--accent); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
    width: 100%;
    background: color-mix(in srgb, var(--accent) 20%, transparent);
    color: white;
    font-weight: 600;
    padding: 0.5rem;
    border-radius: 0.5rem;
    border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
    cursor: pointer;
    transition: background 0.2s;
    font-size: var(--fs-base);
}
.btn-secondary:hover { background: color-mix(in srgb, var(--accent) 40%, transparent); }

/* ============================================================
   CARDS
   ============================================================ */

.card {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border-radius: 1rem;
    padding: 1rem;
    border: 1px solid var(--card-border);
    transition: background 0.3s, border-color 0.3s;
}

.card-compact {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border-radius: 0.75rem;
    padding: 0.75rem;
    border: 1px solid var(--card-border);
    transition: background 0.3s, border-color 0.3s;
}

/* ============================================================
   ANIMATIONS & SPINNERS
   ============================================================ */

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.animate-fade-in {
    animation: fadeIn 0.3s ease;
}

.spinner {
    width: 16px; height: 16px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

.spinner-small {
    width: 12px; height: 12px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
    vertical-align: middle;
}

/* ============================================================
   SIDEBAR TOOL BUTTONS
   ============================================================ */

.sidebar-tool-btn {
    padding: 5px 8px;
    border-radius: 6px;
    border: 1px solid color-mix(in srgb, var(--card-border) 60%, transparent);
    color: var(--text-secondary);
    font-size: var(--fs-xs);
    font-weight: 500;
    background: color-mix(in srgb, var(--bg-secondary) 50%, transparent);
    transition: all 0.15s ease;
    text-align: center;
    white-space: nowrap;
}

.sidebar-tool-btn:hover {
    color: var(--text-primary);
    border-color: var(--card-border);
    background: color-mix(in srgb, var(--bg-secondary) 80%, transparent);
}

.sidebar-tool-btn:active {
    transform: scale(0.97);
}

[data-theme="light"] .sidebar-tool-btn {
    border-color: color-mix(in srgb, var(--card-border) 80%, transparent);
    background: color-mix(in srgb, var(--bg-primary) 60%, transparent);
}

/* ============================================================
   LAYOUT
   ============================================================ */

/* Responsive: Desktop layout */
@media (min-width: 768px) {
    .home-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
        max-width: 800px;
    }
}

/* Mobile: Stack vertically */
@media (max-width: 767px) {
    .home-grid {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }
}

/* Dual-pane: Sidebar + Main side by side */
@media (min-width: 768px) {
    .view.dual-pane.active {
        display: grid !important;
        grid-template-columns: 280px 1fr;
        height: 100vh;
        height: 100dvh;
    }
    .sidebar {
        display: flex !important;
        flex-direction: column;
    }
    .mobile-only { display: none !important; }
}

@media (max-width: 767px) {
    .desktop-only { display: none !important; }
}

/* ============================================================
   CONNECTION STATE INDICATORS (Chat header)
   ============================================================ */

.connection-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.connection-disconnected {
    background: #6b7280;
}

.connection-connecting {
    background: #eab308;
    animation: pulse 1.5s ease-in-out infinite;
}

.connection-connected-p2p {
    background: #22c55e;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}

.connection-connected-relay {
    background: #3b82f6;
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.5);
}

/* ============================================================
   MESSAGE ANIMATIONS
   ============================================================ */

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

.message-enter {
    animation: messageSlideIn 0.2s ease;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: #a78bfa;
}

.empty-state-icon {
    font-size: var(--fs-hero);
    margin-bottom: 1rem;
    opacity: 0.7;
}

/* ============================================================
   ORACLE (Waiting State)
   ============================================================ */

.oracle-container {
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 1rem;
    padding: 1.5rem;
    text-align: center;
}

.oracle-icon {
    font-size: var(--fs-icon);
    display: inline-block;
    padding: 1rem;
    border-radius: 50%;
    background: rgba(99, 102, 241, 0.2);
}

.oracle-proverb {
    font-style: italic;
    color: #c4b5fd;
    margin: 1rem 0;
    font-size: var(--fs-base);
}

/* ============================================================
   PRESENCE & NOTIFICATIONS
   ============================================================ */

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.status-online {
    background-color: #10b981;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.4);
}

.status-offline {
    background-color: rgba(255, 255, 255, 0.2);
}

.unread-badge {
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    0% { transform: scale(0); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* ============================================================
   TYPING INDICATOR
   ============================================================ */

.typing-dots {
    display: inline-flex;
    gap: 2px;
}

.typing-dots .dot {
    animation: typing-bounce 1.4s infinite ease-in-out both;
    font-weight: bold;
}

.typing-dots .dot:nth-child(1) { animation-delay: 0s; }
.typing-dots .dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dots .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    40% {
        opacity: 1;
        transform: translateY(-3px);
    }
}

/* ============================================================
   ETERNAL MESSAGES (La Bóveda)
   ============================================================ */

.msg-eternal {
    border: 2px solid var(--accent-light) !important;
    box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 30%, transparent);
    border-radius: 0.75rem;
}

/* Fallback for browsers without color-mix */
@supports not (color: color-mix(in srgb, red 50%, blue)) {
    .msg-eternal {
        box-shadow: 0 0 12px rgba(99, 102, 241, 0.2);
    }
}

.eternal-indicator {
    animation: eternal-shimmer 2s ease-in-out infinite;
    color: var(--accent-light) !important;
}

@keyframes eternal-shimmer {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

/* Autodestruct compact selector */
.autodestruct-compact {
    min-width: 48px;
    text-align: center;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%239ca3af' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3E%3C/svg%3E");
    background-position: right 4px center;
    background-repeat: no-repeat;
    background-size: 16px;
    padding-right: 24px;
}

/* ============================================================
   CHAT TRANSITIONS
   ============================================================ */

.chat-area-transition {
    transition: opacity 0.3s ease;
}

/* ============================================================
   TOUCH FEEDBACK — immediate interactive states
   ============================================================ */

/* Túneles con feedback táctil */
.tunnel-item {
    transition: background-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.tunnel-item:active {
    transform: scale(0.98);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
    background: rgba(99, 102, 241, 0.25);
}

/* Botones con feedback */
.btn-primary:active,
.btn-secondary:active {
    transform: scale(0.97);
    transition: transform 0.1s ease;
}

/* Touch feedback para elementos interactivos */
.touch-feedback {
    transition: transform 0.1s ease, opacity 0.1s ease;
}

.touch-feedback:active {
    transform: scale(0.95);
    opacity: 0.8;
}

/* Header buttons */
.header-btn {
    transition: background-color 0.15s ease, transform 0.1s ease;
}

.header-btn:active {
    transform: scale(0.92);
    background: rgba(255, 255, 255, 0.15);
}

/* ============================================================
   TUNNEL LIST — ENTRY ANIMATION
   ============================================================ */

.tunnel-list-enter .tunnel-item {
    opacity: 0;
    transform: translateX(-10px);
    animation: tunnel-slide-in 0.25s ease-out forwards;
}

.tunnel-list-enter .tunnel-item:nth-child(1) { animation-delay: 0s; }
.tunnel-list-enter .tunnel-item:nth-child(2) { animation-delay: 0.05s; }
.tunnel-list-enter .tunnel-item:nth-child(3) { animation-delay: 0.1s; }
.tunnel-list-enter .tunnel-item:nth-child(4) { animation-delay: 0.15s; }
.tunnel-list-enter .tunnel-item:nth-child(5) { animation-delay: 0.2s; }
.tunnel-list-enter .tunnel-item:nth-child(n+6) { animation-delay: 0.25s; }

@keyframes tunnel-slide-in {
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ============================================================
   VISUAL IMPROVEMENTS
   ============================================================ */

/* Sombra interna sutil para el panel de chat en desktop */
@media (min-width: 768px) {
    #chat-area {
        box-shadow: inset 3px 0 10px rgba(0, 0, 0, 0.1);
    }
}

/* Smooth scroll para mensajes */
#chat-messages {
    scroll-behavior: smooth;
}

/* Input inline código túnel */
#inline-tunnel-code {
    transition: border-color 0.15s ease;
}

#inline-tunnel-code:focus {
    outline: none;
    border-color: var(--color-primary, #6366f1);
}

#inline-tunnel-code::placeholder {
    text-transform: none;
    font-family: inherit;
}

/* ============================================================
   MIRROR STATUS RING (Protocol Espejo)
   ============================================================ */

/* Primary: anillo externo visible (outline no lo tapa el <img> del avatar) */
#user-avatar.mirror-primary {
    outline: 3px solid var(--accent-light, #818cf8);
    outline-offset: 2px;
    box-shadow: 0 0 12px var(--accent-light, #818cf8);
}

/* Mirror: apagado + borde tenue — contraste total con Primary */
#user-avatar.mirror-passive {
    opacity: 0.4;
    filter: grayscale(0.7);
    outline: 2px dashed rgba(255, 255, 255, 0.25);
    outline-offset: 2px;
}

/* Responsive móvil */
@media (max-width: 767px) {
    #inline-tunnel-code {
        width: 5.5rem;
    }
}
