:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #10b981;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --text-main: #f8fafc;
    --text-muted: #cbd5e1;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
}

* {
    margin: 0; padding: 0; box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh; width: 100vw;
}

.screen {
    display: none; width: 100%; height: 100%; position: absolute; top: 0; left: 0;
}
.screen.active { display: flex; }

/* OVERLAYS (LLAMADAS TELEFÓNICAS) */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(10px);
    z-index: 9999;
    display: flex; align-items: center; justify-content: center;
}
.modal-content.ringing-panel {
    display: flex; flex-direction: column; align-items: center;
    padding: 50px 40px;
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    box-shadow: 0 0 50px rgba(0,0,0,0.5);
    text-align: center;
    min-width: 300px;
}
.modal-content h2 { font-size: 1.5rem; margin-top: 20px; font-weight: 500;}
.modal-content h3 { font-size: 1.2rem; color: var(--text-muted); margin: 10px 0 30px;}

.action-row { display: flex; gap: 15px; width: 100%; }

.btn-cancel {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid var(--danger);
    padding: 12px 20px; border-radius: 12px;
    cursor: pointer; font-size: 1rem; font-weight: bold;
    width: 100%; transition: 0.2s;
}
.btn-cancel:hover { background: var(--danger); color: white; }

.ring-pulse {
    width: 80px; height: 80px;
    border-radius: 50%;
    background: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-size: 2rem; color: white;
    animation: ripple 1.5s linear infinite;
}
.ring-pulse.incoming { background: var(--success); animation: ripple-success 1.5s linear infinite;}

@keyframes ripple {
    0% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.5); }
    100% { box-shadow: 0 0 0 40px rgba(59, 130, 246, 0); }
}
@keyframes ripple-success {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5); }
    100% { box-shadow: 0 0 0 40px rgba(16, 185, 129, 0); }
}

/* APP LAYOUT - PANTALLA INICIO SPLIT */
#home-screen {
    background: radial-gradient(circle at top right, #1e293b, #0f172a);
    padding: 20px; display: flex; align-items: center; justify-content: center;
    overflow-y: auto;
}

.app-layout {
    display: flex; gap: 30px; width: 100%; max-width: 900px;
}
@media (max-width: 768px) { .app-layout { flex-direction: column-reverse; } }

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px); border: 1px solid var(--glass-border);
    border-radius: 20px; padding: 30px;
}
.panel-contacts { flex: 1.2; display: flex; flex-direction: column;}
.panel-classic { flex: 1; text-align: center;}

/* PERFIL LOCAL */
.profile-card {
    display: flex; align-items: center; gap: 15px; margin-bottom: 30px;
    padding-bottom: 20px; border-bottom: 1px solid var(--glass-border);
}
.profile-card .avatar {
    width: 60px; height: 60px; border-radius: 50%; background: var(--accent);
    display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
}
.profile-info { flex: 1; }
#my-name-input {
    background: transparent; border: none; border-bottom: 1px solid var(--glass-border);
    color: white; font-size: 1.2rem; font-weight: bold; outline: none; margin-bottom: 5px; width: 100%;
}
.my-id-box {
    font-size: 0.8rem; color: var(--text-muted);
}
#my-display-id { font-weight: bold; color: var(--accent); letter-spacing: 1px; }
#btn-copy-my-id { background: transparent; border: none; color: var(--text-muted); cursor: pointer; margin-left:5px;}

/* CONTACTOS */
.contacts-header h3 { font-size: 1rem; margin-bottom: 15px; }
.add-contact-form { display: flex; gap: 8px; margin-bottom: 20px; }
.add-contact-form input {
    background: rgba(0,0,0,0.2); border: 1px solid var(--glass-border);
    border-radius: 8px; padding: 10px; color: white; outline: none; flex: 1;
}
#contact-id { flex: 0.8;}
#btn-add-contact {
    background: var(--accent); border: none; color: white; border-radius: 8px;
    padding: 0 15px; cursor: pointer;
}

.contacts-list {
    display: flex; flex-direction: column; gap: 10px; overflow-y: auto; max-height: 250px;
}
.contact-item {
    display: flex; align-items: center; justify-content: space-between;
    background: rgba(255,255,255,0.03); padding: 12px 15px; border-radius: 12px;
}
.contact-item-info { display: flex; flex-direction: column; }
.contact-item-info strong { font-size: 0.9rem; }
.contact-item-info span { font-size: 0.75rem; color: var(--text-muted); font-family: monospace; letter-spacing: 1px;}
.btn-call-contact {
    background: rgba(16, 185, 129, 0.1); color: var(--success);
    border: 1px solid var(--success); border-radius: 50%;
    width: 36px; height: 36px; cursor: pointer; transition: 0.2s;
    display:flex; align-items:center; justify-content:center;
}
.btn-call-contact:hover { background: var(--success); color: white; }

/* CLÁSICO */
.logo { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 16px; color: var(--accent); }
.logo i { font-size: 2rem; }
.logo h1 { font-size: 1.8rem; font-weight: 700; color: #fff;}
.logo span { color: var(--accent); font-weight: 300;}
.subtitle { color: var(--text-muted); margin-bottom: 30px; font-size: 0.9rem; line-height: 1.5; }

.action-box { background: rgba(255, 255, 255, 0.03); border-radius: 16px; padding: 20px; margin-bottom: 20px; text-align: left; }
.action-box h3 { margin-bottom: 8px; font-size: 1rem; }
.action-box p { color: var(--text-muted); font-size: 0.8rem; margin-bottom: 16px; }

.btn-primary, .btn-secondary {
    width: 100%; padding: 12px 20px; border-radius: 12px; border: none; font-size: 1rem; font-weight: 600; cursor: pointer; transition: all 0.2s ease;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }

.code-display-box {
    display: flex; justify-content: center; align-items: center; gap: 15px;
    background: rgba(0,0,0,0.3); padding: 15px; border-radius: 8px; margin-bottom: 16px;
    font-family: monospace; font-size: 1.5rem; letter-spacing: 3px; font-weight: bold;
    color: var(--accent);
}
.loader-dots span { display: inline-block; width: 6px; height: 6px; background: white; border-radius: 50%; animation: jump 1.4s infinite; margin: 0 2px; }
.loader-dots span:nth-child(2) { animation-delay: 0.2s; }
.loader-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes jump { 0%, 100% {transform: translateY(0);} 50% {transform: translateY(-5px);} }

.divider { display: flex; align-items: center; color: var(--text-muted); margin: 20px 0; }
.divider::before, .divider::after { content: ''; flex: 1; border-bottom: 1px solid var(--glass-border); }
.divider span { padding: 0 10px; font-size: 0.8rem; }

.input-group { display: flex; gap: 10px; }
.input-group input {
    flex: 1; padding: 12px; border-radius: 12px; border: 1px solid var(--glass-border);
    background: rgba(0,0,0,0.2); color: white; font-size: 1rem; outline: none; width: 100%;
}
.input-group input:focus { border-color: var(--accent); }
.input-group .btn-secondary {
    flex: 0 0 auto; width: auto; background: var(--bg-secondary); color: white; border: 1px solid var(--glass-border);
}

/* LLAMADA */
#call-screen { flex-direction: column; background: #000; justify-content: center; align-items: center; }
.video-container { position: relative; width: 100%; height: 100%; flex: 1; overflow: hidden; background: #111; transition: all 0.3s ease; }
#remote-video { width: 100%; height: 100%; object-fit: cover; }
.local-video-wrapper {
    position: absolute; bottom: 100px; right: 20px; width: 120px; height: 160px;
    border-radius: 16px; overflow: hidden; box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    border: 2px solid var(--glass-border); z-index: 10; background: #222;
    cursor: grab; touch-action: none;
}
.local-video-wrapper:active { cursor: grabbing; }
#local-video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.name-tag { position: absolute; bottom: 8px; left: 8px; background: rgba(0,0,0,0.6); padding: 2px 8px; border-radius: 4px; font-size: 0.7rem; backdrop-filter: blur(4px); }
.status-overlay {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.7); z-index: 5;
}
.spinner { width: 40px; height: 40px; border: 3px solid rgba(255,255,255,0.1); border-radius: 50%; border-top-color: var(--accent); animation: spin 1s infinite; margin-bottom: 15px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* CONTROLS BAR */
.control-bar { position: absolute; bottom: 30px; left: 0; width: 100%; display: flex; justify-content: center; z-index: 100; pointer-events: none; transition: opacity 0.4s ease, transform 0.4s ease, visibility 0.4s; }
.control-bar.hidden { opacity: 0; visibility: hidden; transform: translateY(20px); }
.floating-controls { display: flex; gap: 15px; background: var(--glass-bg); backdrop-filter: blur(10px); padding: 10px 20px; border-radius: 100px; border: 1px solid var(--glass-border); pointer-events: auto; }
.control-btn { width: 50px; height: 50px; border-radius: 50%; border: none; background: rgba(255,255,255,0.1); color: white; font-size: 1.2rem; cursor: pointer; transition: 0.2s; position: relative; display: flex; align-items: center; justify-content: center; }
.control-btn:hover { background: rgba(255,255,255,0.2); }
.control-btn.active { background: #3b82f6; }
.control-btn.hangup { background: var(--danger); }
.control-btn.hangup:hover { background: var(--danger-hover); }
.control-btn:not(.active) i::after { content: ''; position: absolute; top: 50%; left: 50%; width: 25px; height: 2px; background: white; transform: translate(-50%, -50%) rotate(-45deg); }
.control-btn.active i::after { display: none; }
.badge { position: absolute; top: -2px; right: -2px; background: var(--danger); color: white; font-size: 0.6rem; font-weight: bold; width: 18px; height: 18px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }

/* CHAT PANEL */
.side-panel {
    position: absolute; top: 0; right: -350px; width: 320px; height: 100%;
    background: var(--glass-bg); backdrop-filter: blur(15px); border-left: 1px solid var(--glass-border);
    z-index: 50; transition: right 0.3s ease; display: flex; flex-direction: column;
}
.side-panel.open { right: 0; }
.panel-header { padding: 20px; border-bottom: 1px solid var(--glass-border); display: flex; justify-content: space-between; align-items: center; }
.icon-btn { background: transparent; border: none; color: var(--text-muted); font-size: 1.2rem; cursor: pointer; }
.icon-btn:hover { color: white; }
.chat-messages { flex: 1; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.system-msg { text-align: center; font-size: 0.75rem; color: #94a3b8; padding: 10px; background: rgba(0,0,0,0.2); border-radius: 8px; margin-bottom: 10px; }
.msg-bubble { max-width: 85%; padding: 10px 14px; border-radius: 16px; font-size: 0.9rem; line-height: 1.4; word-break: break-word; }
.msg-bubble.sent { background: var(--accent); color: white; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg-bubble.received { background: #334155; color: white; align-self: flex-start; border-bottom-left-radius: 4px; }
.chat-input-area { padding: 15px; border-top: 1px solid var(--glass-border); display: flex; gap: 10px; }
.chat-input-area input { flex: 1; background: rgba(0,0,0,0.3); border: 1px solid var(--glass-border); border-radius: 20px; padding: 10px 15px; color: white; outline: none; }
.submit-btn { width: 40px; height: 40px; background: var(--accent); color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; }

@media (min-width: 768px) {
    .video-container {
        max-width: 480px;
        height: 90vh;
        flex: none;
        border-radius: 20px;
        box-shadow: 0 0 30px rgba(0,0,0,0.8);
    }
    .video-container.fullscreen-mode {
        max-width: 100%;
        height: 100%;
        border-radius: 0;
        margin: 0;
        flex: 1;
    }
}

@media (max-width: 768px) {
    .local-video-wrapper { width: 90px; height: 120px; bottom: 80px; right: 10px; }
    .side-panel { width: 100%; right: -100%; }
    .control-bar { bottom: 15px; }
    .floating-controls { gap: 10px; padding: 8px 15px; }
    .control-btn { width: 44px; height: 44px; font-size: 1rem; }
    #btn-fullscreen { display: none; }
}
