/* Configuración General & Variables de Diseño Premium */
:root {
    --bg-primary: hsl(220, 20%, 8%);
    --bg-secondary: hsl(220, 20%, 12%);
    --bg-accent: hsl(174, 84%, 41%);
    --bg-accent-hover: hsl(174, 84%, 35%);
    --text-primary: hsl(210, 40%, 98%);
    --text-secondary: hsl(215, 20%, 65%);
    --text-muted: hsl(215, 15%, 45%);
    --border-color: hsla(215, 20%, 25%, 0.4);
    --glass-bg: rgba(20, 24, 35, 0.45);
    --glass-border: rgba(255, 255, 255, 0.06);
    --shadow-premium: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
    
    --font-primary: 'Inter', sans-serif;
    --font-title: 'Outfit', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-primary);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Contenedor SPA */
.app-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Vista de Autenticación */
.auth-view {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at top right, hsla(174, 84%, 25%, 0.15), transparent 45%),
                radial-gradient(circle at bottom left, hsla(220, 71%, 15%, 0.3), transparent 50%);
}

.auth-card {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 40px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-premium);
    animation: fadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

.logo-animation {
    display: inline-block;
    margin-bottom: 15px;
    animation: pulse 3s infinite ease-in-out;
}

.auth-header h1 {
    font-family: var(--font-title);
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #ffffff 30%, var(--bg-accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-top: 5px;
}

.input-group {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
}

.input-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
    transition: color 0.2s ease;
}

.input-group input, 
.input-group select {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 12px 16px;
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: 0.95rem;
    outline: none;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.input-group input::placeholder {
    color: var(--text-muted);
}

.input-group input:focus,
.input-group select:focus {
    border-color: var(--bg-accent);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.25);
}

.btn-primary {
    background: linear-gradient(135deg, var(--bg-accent), var(--bg-accent-hover));
    color: white;
    border: none;
    border-radius: 12px;
    padding: 14px;
    font-family: var(--font-title);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    width: 100%;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(15, 118, 110, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(15, 118, 110, 0.45);
}

.btn-primary:active {
    transform: translateY(1px);
}

.auth-switch {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 20px;
}

.auth-switch a {
    color: var(--bg-accent);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s ease;
}

.auth-switch a:hover {
    color: #2dd4bf;
}

.oauth-divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 25px 0;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.oauth-divider::before,
.oauth-divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border-color);
}

.oauth-divider span {
    padding: 0 10px;
}

.btn-oauth {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border-radius: 12px;
    padding: 12px;
    width: 100%;
    cursor: pointer;
    font-family: var(--font-primary);
    font-size: 0.95rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s ease;
}

.btn-oauth:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
}

/* VISTA DE CHAT PRINCIPAL */
.chat-view {
    width: 100%;
    height: 100%;
    display: flex;
    background-color: var(--bg-primary);
}

/* SIDEBAR DE CHATS */
.sidebar {
    width: 380px;
    border-right: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

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

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

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--bg-accent), #0d9488);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-title);
    font-weight: 700;
    color: white;
    font-size: 1.1rem;
    box-shadow: 0 4px 10px rgba(15, 118, 110, 0.25);
}

.user-info h3 {
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: -0.2px;
}

.status-badge {
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary);
}

.status-badge::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #10b981;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.header-actions button,
.chat-header-actions button {
    background: rgba(255, 255, 255, 0.05);
    border: none;
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.header-actions button:hover,
.chat-header-actions button:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.search-bar {
    padding: 15px 20px;
}

.search-input-wrapper {
    position: relative;
    width: 100%;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-bar input {
    width: 100%;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    padding: 10px 16px 10px 42px;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: all 0.3s ease;
}

.search-bar input:focus {
    border-color: var(--bg-accent);
    background: rgba(255, 255, 255, 0.07);
}

.chats-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 10px 20px 10px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    border-radius: 16px;
    cursor: pointer;
    margin-bottom: 4px;
    transition: all 0.2s ease;
}

.chat-item:hover {
    background: rgba(255, 255, 255, 0.03);
}

.chat-item.active {
    background: rgba(15, 118, 110, 0.15);
    border: 1px solid rgba(15, 118, 110, 0.2);
}

.chat-item-meta {
    flex: 1;
    min-width: 0;
}

.chat-item-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.chat-item-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-item-time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.chat-item-last {
    font-size: 0.8rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px;
    font-size: 0.9rem;
}

/* VENTANA DE CHAT ACTIVO */
.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    background-color: var(--bg-primary);
}

.no-chat-selected {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    padding: 40px;
    text-align: center;
    background: radial-gradient(circle at center, hsla(174, 84%, 15%, 0.04), transparent 60%);
}

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

.no-chat-selected h2 {
    font-family: var(--font-title);
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.no-chat-selected p {
    font-size: 0.95rem;
    max-width: 380px;
    line-height: 1.5;
}

.active-chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

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

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

.chat-details h3 {
    font-size: 1rem;
    font-weight: 600;
}

.chat-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: radial-gradient(circle at bottom right, hsla(174, 84%, 25%, 0.02), transparent 50%);
}

/* Burbujas de Chat Premium */
.message-bubble {
    max-width: 65%;
    display: flex;
    flex-direction: column;
    padding: 10px 14px 6px 14px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.45;
    position: relative;
    animation: messageSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.message-bubble.incoming {
    align-self: flex-start;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border-top-left-radius: 4px;
}

.message-bubble.outgoing {
    align-self: flex-end;
    background: linear-gradient(135deg, hsl(174, 84%, 35%), hsl(174, 84%, 28%));
    color: white;
    border-top-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(15, 118, 110, 0.15);
}

.message-sender {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--bg-accent);
    margin-bottom: 4px;
}

.message-info {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 4px;
    align-self: flex-end;
}

.message-time {
    font-size: 0.7rem;
    opacity: 0.6;
}

.message-status {
    display: flex;
    align-items: center;
}

.message-status svg {
    width: 14px;
    height: 14px;
}

/* Chat Footer / Entrada de Texto */
.chat-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
}

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

.chat-footer input {
    flex: 1;
    background-color: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    padding: 12px 20px;
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: all 0.3s ease;
}

.chat-footer input:focus {
    border-color: var(--bg-accent);
    background-color: rgba(255, 255, 255, 0.08);
}

.send-btn {
    background-color: var(--bg-accent);
    color: white;
    border: none;
    border-radius: 12px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.send-btn:hover {
    background-color: var(--bg-accent-hover);
    transform: scale(1.05);
}

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

/* Indicador de "Escribiendo" */
.typing-indicator {
    padding: 8px 24px;
    background: transparent;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.typing-dots {
    display: flex;
    gap: 3px;
    align-items: center;
}

.typing-dots span {
    width: 4px;
    height: 4px;
    background-color: var(--text-muted);
    border-radius: 50%;
    display: inline-block;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

/* MODALES */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    width: 90%;
    max-width: 400px;
    padding: 30px;
    border-radius: 20px;
}

.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-premium);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.modal-header h2 {
    font-family: var(--font-title);
    font-size: 1.3rem;
    font-weight: 700;
}

.close-modal-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.8rem;
    cursor: pointer;
    line-height: 1;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: rgba(20, 24, 35, 0.85);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
    border-left: 4px solid var(--bg-accent);
    padding: 12px 20px;
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.85rem;
    box-shadow: var(--shadow-premium);
    animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Utilidades */
.hidden {
    display: none !important;
}

.hidden-f1 {
    display: none !important; /* Will keep Phase 2 items hidden in Phase 1 */
}

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

@keyframes pulse {
    0%, 100% { transform: scale(1); filter: brightness(1); }
    50% { transform: scale(1.03); filter: brightness(1.15); }
}

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

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

@keyframes toastIn {
    from { transform: translateX(100%) scale(0.9); opacity: 0; }
    to { transform: translateX(0) scale(1); opacity: 1; }
}

/* WebRTC Calling UI Styles */
.call-modal {
    display: flex;
    justify-content: center;
    align-items: center;
}

.call-content {
    max-width: 420px;
    width: 100%;
    padding: 30px;
    border-radius: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.call-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--bg-accent), #0d9488);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-title);
    font-weight: 700;
    color: white;
    font-size: 2.2rem;
    margin-bottom: 20px;
    box-shadow: 0 0 0 0 rgba(20, 184, 166, 0.4);
    animation: callingPulse 2s infinite;
}

.call-status-text {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin: 8px 0 24px 0;
    letter-spacing: 0.5px;
}

.video-container {
    width: 100%;
    height: 280px;
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    background-color: #000;
    margin-bottom: 24px;
    border: 1px solid var(--border-color);
}

.remote-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.local-video {
    position: absolute;
    bottom: 12px;
    right: 12px;
    width: 100px;
    height: 130px;
    object-fit: cover;
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    background-color: #111;
}

.call-controls {
    display: flex;
    gap: 16px;
    justify-content: center;
    align-items: center;
}

.call-btn {
    border: none;
    border-radius: 50%;
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.call-btn:hover {
    transform: scale(1.08);
}

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

.btn-accept {
    background-color: #10b981;
}
.btn-accept:hover {
    background-color: #059669;
    box-shadow: 0 0 16px rgba(16, 185, 129, 0.4);
}

.btn-hangup {
    background-color: #ef4444;
}
.btn-hangup:hover {
    background-color: #dc2626;
    box-shadow: 0 0 16px rgba(239, 68, 68, 0.4);
}

.btn-control {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.btn-control:hover {
    background-color: rgba(255, 255, 255, 0.15);
    color: var(--text-primary);
}

.btn-control.active {
    background-color: var(--bg-accent);
    color: white;
    border-color: var(--bg-accent);
}

/* Animations */
@keyframes callingPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(20, 184, 166, 0.5);
    }
    70% {
        box-shadow: 0 0 0 20px rgba(20, 184, 166, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(20, 184, 166, 0);
    }
}
