/* ============================================================================
   NEALMAR PREMIUM DESIGN SYSTEM & VARIABLES
   ============================================================================ */

:root {
    --primary: #0F2C59;
    --primary-light: #163c78;
    --accent: #DAC0A3;
    --accent-dark: #bba082;
    --bg-app: #F5F7FA;
    --bg-chat: #EFEFEF;
    --bubble-user: #0F2C59;
    --bubble-bot: #FFFFFF;
    --text-user: #FFFFFF;
    --text-bot: #1F2937;
    --text-muted: #6B7280;
    --border: #E5E7EB;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    --shadow-active: 0 8px 30px rgba(15, 44, 89, 0.15);
    --font: 'Outfit', sans-serif;
    --radius-bubble: 16px;
    --radius-card: 24px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

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

/* ============================================================================
   SCREENS & ANIMATIONS
   ============================================================================ */

.screen {
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform: scale(0.98);
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
}

.hide {
    display: none !important;
}

/* ============================================================================
   1. PANTALLA DE LOGIN
   ============================================================================ */

#login-screen {
    background: radial-gradient(circle at 10% 20%, #0F2C59 0%, #051329 90%);
    justify-content: center;
    align-items: center;
}

.login-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    width: 90%;
    max-width: 420px;
    padding: 40px 32px;
    border-radius: var(--radius-card);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    text-align: center;
    animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.logo-container {
    width: 80px;
    height: 80px;
    background: #FFFFFF;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 auto 20px;
    box-shadow: 0 10px 20px rgba(15, 44, 89, 0.3);
}

.login-header h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.5px;
    margin-bottom: 6px;
}

.login-header p {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 32px;
}

.login-form {
    text-align: left;
}

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

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

.form-group input[type="tel"],
.form-group input[type="text"] {
    width: 100%;
    padding: 14px 16px;
    font-family: var(--font);
    font-size: 15px;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    outline: none;
    transition: all 0.2s ease;
    background-color: #F9FAFB;
}

.form-group input[type="tel"]:focus,
.form-group input[type="text"]:focus {
    border-color: var(--primary);
    background-color: #FFFFFF;
    box-shadow: 0 0 0 4px rgba(15, 44, 89, 0.08);
}

/* Checkbox de Privacidad */
.form-group-checkbox {
    margin-bottom: 24px;
}

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 13.5px;
    color: #4B5563;
    cursor: pointer;
    line-height: 1.4;
}

.checkbox-label input[type="checkbox"] {
    margin-top: 3px;
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

.checkbox-text a {
    color: var(--primary);
    font-weight: 500;
    text-decoration: underline;
}

.checkbox-text a:hover {
    color: var(--primary-light);
}

.error-msg {
    background-color: #FEF2F2;
    border-left: 4px solid #EF4444;
    color: #991B1B;
    padding: 12px;
    border-radius: 8px;
    font-size: 13.5px;
    margin-bottom: 20px;
    font-weight: 500;
}

.btn-primary {
    width: 100%;
    padding: 16px;
    background-color: var(--primary);
    color: #FFFFFF;
    border: none;
    border-radius: 12px;
    font-family: var(--font);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

.btn-primary:hover {
    background-color: var(--primary-light);
    box-shadow: var(--shadow-active);
}

.btn-primary:active {
    transform: scale(0.98);
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}

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

.login-footer {
    margin-top: 32px;
    font-size: 11px;
    color: var(--text-muted);
}

/* ============================================================================
   2. PANTALLA DE CHAT
   ============================================================================ */

#chat-screen {
    background-color: var(--bg-chat);
    max-width: 480px;
    margin: 0 auto;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.1);
    position: relative;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
}

/* Cabecera */
.chat-header {
    background-color: var(--primary);
    color: #FFFFFF;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

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

.avatar {
    width: 40px;
    height: 40px;
    background-color: var(--accent);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.user-details h2 {
    font-size: 16px;
    font-weight: 600;
}

.status-container {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.status-dot {
    width: 7px;
    height: 7px;
    background-color: #10B981;
    border-radius: 50%;
    display: inline-block;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.4); opacity: 0.5; }
    100% { transform: scale(1); opacity: 1; }
}

.status-text {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.8);
}

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

.resident-badge {
    background-color: rgba(255, 255, 255, 0.15);
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
    color: var(--accent);
}

#btn-logout {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    transition: all 0.2s ease;
}

#btn-logout:hover {
    color: #FFFFFF;
    background-color: rgba(255, 255, 255, 0.1);
}

/* Área de mensajes */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: radial-gradient(circle at center, rgba(15, 44, 89, 0.02) 0%, rgba(15, 44, 89, 0.05) 100%), var(--bg-chat);
}

/* Burbujas de chat */
.message {
    max-width: 80%;
    padding: 12px 16px;
    font-size: 14.5px;
    line-height: 1.5;
    position: relative;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.message.user {
    align-self: flex-end;
    background-color: var(--bubble-user);
    color: var(--text-user);
    border-radius: var(--radius-bubble) var(--radius-bubble) 2px var(--radius-bubble);
    animation: popInRight 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.message.bot {
    align-self: flex-start;
    background-color: var(--bubble-bot);
    color: var(--text-bot);
    border-radius: var(--radius-bubble) var(--radius-bubble) var(--radius-bubble) 2px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    animation: popInLeft 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes popInRight {
    from { opacity: 0; transform: scale(0.9) translate(10px, 10px); }
    to { opacity: 1; transform: scale(1) translate(0, 0); }
}

@keyframes popInLeft {
    from { opacity: 0; transform: scale(0.9) translate(-10px, 10px); }
    to { opacity: 1; transform: scale(1) translate(0, 0); }
}

/* Formato markdown simple */
.message p {
    margin-bottom: 8px;
}
.message p:last-child {
    margin-bottom: 0;
}
.message strong {
    font-weight: 600;
}
.message code {
    background-color: rgba(0,0,0,0.05);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 13px;
}
.message.user code {
    background-color: rgba(255,255,255,0.15);
}

/* ============================================================================
   BANNER DE INSTALACIÓN (DESCARGAR APP)
   ============================================================================ */

.install-banner {
    background-color: var(--accent);
    color: var(--primary);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    z-index: 10;
    animation: slideUpBanner 0.4s ease;
}

@keyframes slideUpBanner {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.install-banner-content {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
}

.btn-install-pwa {
    background-color: var(--primary);
    color: #FFFFFF;
    border: none;
    padding: 8px 14px;
    border-radius: 20px;
    font-family: var(--font);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(15, 44, 89, 0.15);
}

.btn-install-pwa:hover {
    background-color: var(--primary-light);
    transform: translateY(-1px);
}

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

/* Footer / Entrada de Mensajes */
.chat-footer {
    background-color: #F0F2F5;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    z-index: 10;
}

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

#chat-input {
    flex: 1;
    padding: 14px 18px;
    border: none;
    border-radius: 24px;
    font-family: var(--font);
    font-size: 15px;
    outline: none;
    background-color: #FFFFFF;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: all 0.2s ease;
}

#chat-input:focus {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.btn-send {
    width: 48px;
    height: 48px;
    background-color: var(--primary);
    color: #FFFFFF;
    border: none;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(15, 44, 89, 0.2);
}

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

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

/* Indicador de Escritura (Typing Indicator) */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
    align-items: center;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background-color: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

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

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

/* ============================================================================
   RESPONSIVE DESIGN (DESKTOP & LANDSCAPE)
   ============================================================================ */

@media (min-width: 481px) {
    body {
        background-color: var(--bg-app);
    }
    
    #chat-screen {
        height: 90vh;
        max-height: 800px;
        border-radius: 20px;
        overflow: hidden;
        border: 1px solid var(--border);
    }
}
