/* Importar Tipografía de Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* Reset y Variables Globales */
:root {
    --bg-primary: #0b0f19;
    --bg-secondary: rgba(17, 24, 39, 0.7);
    --bg-tertiary: rgba(31, 41, 55, 0.5);
    
    --border-color: rgba(255, 255, 255, 0.08);
    --border-active: rgba(99, 102, 241, 0.4);
    
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    
    --accent-primary: #6366f1; /* Indigo */
    --accent-secondary: #a855f7; /* Purple */
    --accent-glow: rgba(99, 102, 241, 0.15);
    
    --status-online: #10b981; /* Esmerald */
    --status-offline: #6b7280;
    
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-sans);
}

body {
    background: radial-gradient(circle at top right, #1e1b4b 0%, var(--bg-primary) 60%);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* Contenedor Principal con Glassmorphism */
.app-container {
    width: 90vw;
    height: 85vh;
    max-width: 1200px;
    max-height: 800px;
    background: var(--bg-secondary);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    display: flex;
    overflow: hidden;
    position: relative;
}

/* Pantalla de Login / Registro */
.auth-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at bottom left, #1e1b4b 0%, var(--bg-primary) 70%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    transition: var(--transition-smooth);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    padding: 40px;
    background: rgba(17, 24, 39, 0.6);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    animation: fadeIn 0.5s ease-out;
}

.auth-header {
    text-align: center;
    margin-bottom: 30px;
}

.auth-header h2 {
    font-size: 28px;
    font-weight: 700;
    background: linear-gradient(135deg, #a855f7 0%, #6366f1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
}

.auth-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

.form-group {
    margin-bottom: 20px;
    position: relative;
}

.form-group label {
    display: block;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 600;
}

.form-input {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    transition: var(--transition-smooth);
}

.form-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 12px var(--accent-glow);
}

.auth-btn {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--accent-secondary) 0%, var(--accent-primary) 100%);
    border: none;
    border-radius: 12px;
    color: #ffffff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-smooth);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.auth-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.auth-btn:active {
    transform: translateY(0);
}

.auth-toggle-link {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: var(--text-secondary);
}

.auth-toggle-link span {
    color: var(--accent-primary);
    cursor: pointer;
    font-weight: 500;
    text-decoration: underline;
}

.auth-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: #f87171;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    margin-bottom: 20px;
    display: none;
    animation: shake 0.3s ease-in-out;
}

/* Panel Lateral (Sidebar) */
.sidebar {
    width: 320px;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background: rgba(10, 15, 30, 0.4);
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    color: #ffffff;
    font-size: 16px;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.user-info .username {
    font-weight: 600;
    font-size: 15px;
}

.user-info .status-text {
    font-size: 12px;
    color: var(--status-online);
    display: flex;
    align-items: center;
    gap: 4px;
}

.user-info .status-text::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--status-online);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--status-online);
}

.logout-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: var(--transition-smooth);
}

.logout-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #ef4444;
}

/* Lista de Contactos */
.contact-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.contact-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border-radius: 16px;
    cursor: pointer;
    transition: var(--transition-smooth);
    margin-bottom: 8px;
    border: 1px solid transparent;
}

.contact-item:hover {
    background: rgba(255, 255, 255, 0.03);
    border-color: var(--border-color);
}

.contact-item.active {
    background: rgba(99, 102, 241, 0.12);
    border-color: var(--border-active);
}

.contact-avatar-wrapper {
    position: relative;
}

.contact-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 600;
    font-size: 16px;
    color: var(--text-primary);
}

.status-badge {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--bg-primary);
}

.status-badge.online {
    background: var(--status-online);
    box-shadow: 0 0 8px var(--status-online);
}

.status-badge.offline {
    background: var(--status-offline);
}

.contact-details {
    flex: 1;
    min-width: 0;
}

.contact-name {
    font-weight: 500;
    font-size: 15px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-status-label {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Área de Chat Principal */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: rgba(15, 23, 42, 0.2);
}

/* Chat Vacío */
.chat-welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

.chat-welcome svg {
    margin-bottom: 20px;
    color: var(--text-muted);
}

.chat-welcome h3 {
    color: var(--text-primary);
    margin-bottom: 8px;
    font-size: 20px;
}

/* Chat Activo: Cabecera */
.chat-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(10, 15, 30, 0.2);
}

.chat-partner-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-partner-details h4 {
    font-size: 16px;
    font-weight: 600;
}

.chat-partner-details .status-desc {
    font-size: 12px;
    color: var(--text-secondary);
}

.back-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    margin-right: 12px;
}

/* Ventana de Mensajes */
.messages-container {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message-row {
    display: flex;
    width: 100%;
}

.message-row.sent {
    justify-content: flex-end;
}

.message-row.received {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 65%;
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    line-height: 1.5;
    font-size: 15px;
    word-break: break-word;
}

.message-row.sent .message-bubble {
    background: linear-gradient(135deg, var(--accent-secondary) 0%, var(--accent-primary) 100%);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.message-row.received .message-bubble {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border-color);
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 6px;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.6);
}

.message-row.received .message-meta {
    color: var(--text-muted);
}

.read-status-icon {
    font-size: 12px;
}

/* Entrada de Mensaje */
.chat-input-area {
    padding: 20px 24px;
    border-top: 1px solid var(--border-color);
    background: rgba(10, 15, 30, 0.3);
}

.chat-input-form {
    display: flex;
    gap: 12px;
    align-items: center;
}

.message-input {
    flex: 1;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 14px 18px;
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    transition: var(--transition-smooth);
}

.message-input:focus {
    border-color: var(--accent-primary);
    background: rgba(31, 41, 55, 0.7);
}

.send-btn {
    background: linear-gradient(135deg, var(--accent-secondary) 0%, var(--accent-primary) 100%);
    border: none;
    border-radius: 14px;
    width: 48px;
    height: 48px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #ffffff;
    cursor: pointer;
    transition: var(--transition-smooth);
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.2);
}

.send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 15px rgba(99, 102, 241, 0.4);
}

.send-btn:active {
    transform: scale(0.95);
}

/* Animaciones */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

/* Personalización del Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Soporte Responsivo (Celulares y Tablets) */
@media (max-width: 768px) {
    body {
        padding: 0;
    }
    
    .app-container {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
        border: none;
    }
    
    .sidebar {
        width: 100%;
        display: flex;
    }
    
    .chat-area {
        display: none;
        width: 100%;
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 10;
        background: radial-gradient(circle at top right, #1a183d 0%, var(--bg-primary) 100%);
    }
    
    .app-container.show-chat .sidebar {
        display: none;
    }
    
    .app-container.show-chat .chat-area {
        display: flex;
    }
    
    .back-btn {
        display: flex;
    }
    
    .message-bubble {
        max-width: 80%;
    }
}
