Files
recreopay/public/index.html
T

5178 lines
400 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
<title>SiboPay - Sistema Inteligente de Billetera Online</title>
<link rel="manifest" href="/manifest.json">
<link rel="icon" type="image/png" href="/img/sibopay-emblem.png">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<meta name="theme-color" content="#0284c7">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title" content="SiboPay">
<link rel="preload" href="/css/styles.css?v=19.9" as="style">
<link rel="preload" href="/js/app.js?v=19.9" as="script">
<link rel="stylesheet" href="/css/styles.css?v=19.9">
<link rel="stylesheet" href="/css/desktop.css?v=2.2">
<style>
/* Transiciones suaves */
.fade-enter { animation: fadeIn 0.2s ease-in-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
</style>
</head>
<body class="">
<!-- VISTA DE LOGIN: WELCOME SPLASH SCREEN & BOTTOM SHEET (ESTILO ORDER-EAT / SIBOPAY) -->
<div id="viewLogin" class="splash-welcome-screen" style="display: none;">
<!-- Patrón de alimentos en marca de agua difuminada -->
<div class="splash-doodle-bg"></div>
<!-- Contenido principal centrado -->
<div class="splash-content-wrap">
<!-- Sección superior/media: Emblema y Marca -->
<div class="splash-brand-hero">
<div class="splash-emblem-wrap">
<img src="/img/sibopay-emblem.png" alt="SiboPay" class="splash-emblem-img">
</div>
<h1 class="splash-title">SiboPay</h1>
<p class="splash-tagline">Sistema Digital de Pagos y Monedero Estudiantil</p>
</div>
<!-- Sección inferior: Botones de acción y Disclaimer -->
<div class="splash-actions-box">
<button type="button" class="splash-btn-primary" onclick="openLoginSheet('login')">
Iniciar Sesión
</button>
<button type="button" class="splash-btn-secondary" onclick="openLoginSheet('register')">
Registrarse
</button>
<p class="splash-disclaimer">
Al iniciar sesión y registrarse, acepta nuestros
<a href="/terminos" target="_blank" rel="noopener noreferrer">Términos y Condiciones</a>
y nuestra
<a href="/privacidad" target="_blank" rel="noopener noreferrer">Política de Privacidad</a>.
</p>
</div>
</div>
<!-- BOTTOM SHEET: VENTANA INFERIOR DESLIZABLE PARA LOGIN Y REGISTRO -->
<div id="loginBottomSheet" class="bottom-sheet-backdrop" onclick="closeLoginSheet(event)">
<div class="bottom-sheet-card" onclick="event.stopPropagation()">
<div class="bottom-sheet-pill-handle"></div>
<div class="bottom-sheet-header">
<div style="display: flex; align-items: center; gap: 8px;">
<img src="/img/sibopay-emblem.png" alt="SiboPay" style="width: 24px; height: 24px; object-fit: contain;">
<h3 id="bottomSheetTitle" style="margin: 0; font-size: 1.22rem; font-weight: 800; color: #0f172a;">Iniciar Sesión</h3>
</div>
<button type="button" class="bottom-sheet-close-btn" onclick="closeLoginSheet()" title="Cerrar">✕</button>
</div>
<!-- CONTENIDO 1: INICIAR SESIÓN -->
<div id="sheetContentLogin">
<form id="formLogin" onsubmit="handleLoginSubmit(event)">
<div class="login-form-group">
<label id="lblLoginUser" for="loginUsername">Usuario, Teléfono o Carné:</label>
<input type="text" id="loginUsername" class="login-input" placeholder="Ej: padre, carlos_papa, 8888-1122 o mateo" required autocomplete="username">
</div>
<div class="login-form-group">
<label id="lblLoginPass" for="loginPassword">Contraseña o PIN:</label>
<input type="password" id="loginPassword" class="login-input" placeholder="••••••••" required autocomplete="current-password">
</div>
<div id="loginErrorMsg" style="display: none; background: #fee2e2; border: 1px solid #fca5a5; color: #991b1b; padding: 9px 12px; border-radius: 10px; font-size: 0.82rem; font-weight: 700; margin-bottom: 12px; text-align: center;"></div>
<button type="submit" id="btnLoginSubmit" class="login-submit-btn" style="display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 48px; border-radius: 12px; font-weight: 800; font-size: 1rem; background: linear-gradient(135deg, #0284c7, #0369a1); color: white; border: none; cursor: pointer; box-shadow: 0 4px 14px rgba(2, 132, 199, 0.35);">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4"/><polyline points="10 17 15 12 10 7"/><line x1="15" x2="3" y1="12" y2="12"/></svg>
<span id="lblBtnLoginText">Ingresar al Sistema</span>
</button>
</form>
<div style="text-align: center; margin-top: 14px;">
<p style="font-size: 0.82rem; color: #64748b; margin: 0;">
¿Aún no tienes cuenta?
<button type="button" onclick="switchSheetView('register')" style="background: none; border: none; color: #0284c7; font-weight: 800; cursor: pointer; text-decoration: underline; font-size: 0.82rem; padding: 0;">Regístrate como Padre aquí</button>
</p>
</div>
<!-- ACCESOS RÁPIDOS DE PRUEBA DESPLEGABLES (DEMO) -->
<details style="margin-top: 16px; border-top: 1px solid #f1f5f9; padding-top: 12px;">
<summary style="font-size: 0.76rem; font-weight: 800; color: #64748b; cursor: pointer; text-align: center; outline: none;">
⚡ Accesos rápidos de prueba (Demo 1-Click)
</summary>
<div class="login-demo-btns" style="margin-top: 10px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;">
<button type="button" class="login-demo-btn" onclick="quickFillLogin('dev', 'dev123')" style="border: 1.5px solid #0284c7; background: #f0f9ff; padding: 6px 4px; font-size: 0.72rem;">
<span style="color: #0284c7; font-weight: 800;">Developer</span>
</button>
<button type="button" class="login-demo-btn" onclick="quickFillLogin('admin', 'admin123')" style="padding: 6px 4px; font-size: 0.72rem;">
<span>Admin Soda</span>
</button>
<button type="button" class="login-demo-btn" onclick="quickFillLogin('cajero', 'cajero123')" style="padding: 6px 4px; font-size: 0.72rem;">
<span>Cajero</span>
</button>
<button type="button" class="login-demo-btn" onclick="quickFillLogin('padre', 'padre123')" style="padding: 6px 4px; font-size: 0.72rem;">
<span>Padre Demo</span>
</button>
<button type="button" class="login-demo-btn" onclick="quickFillLogin('mateo', '1234')" style="padding: 6px 4px; font-size: 0.72rem;">
<span>Mateo (2°)</span>
</button>
<button type="button" class="login-demo-btn" onclick="quickFillLogin('sofia', '1234')" style="padding: 6px 4px; font-size: 0.72rem;">
<span>Sofía (3°)</span>
</button>
</div>
</details>
</div>
<!-- CONTENIDO 2: REGISTRO DE PADRES -->
<div id="sheetContentRegister" style="display: none;">
<div style="background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%); border: 1.5px solid #bae6fd; border-radius: 12px; padding: 10px 12px; margin-bottom: 14px; display: flex; align-items: center; gap: 10px;">
<div style="width: 36px; height: 36px; border-radius: 10px; background: white; border: 1px solid #bae6fd; display: flex; align-items: center; justify-content: center; flex-shrink: 0; padding: 4px;">
<img src="/img/sibopay-emblem.png" alt="SiboPay" style="width: 100%; height: 100%; object-fit: contain;">
</div>
<div>
<strong style="color: #0369a1; font-size: 0.86rem; display: block; font-weight: 800;">Registro de Padres o Encargados</strong>
<span style="font-size: 0.72rem; color: #475569; display: block;">Crea tu cuenta para vincular a tus hijos y recargarles saldo con SINPE móvil.</span>
</div>
</div>
<form id="formRegisterPadre" onsubmit="handleRegisterPadreSubmit(event)">
<div class="login-form-group">
<label for="regNombre">Nombre y Apellidos:</label>
<input type="text" id="regNombre" class="login-input" placeholder="Ej: Carlos Alvarado Castro" required autocomplete="name">
</div>
<div class="login-form-group">
<label for="regTelefono">Teléfono o Celular (para SINPE):</label>
<input type="tel" id="regTelefono" class="login-input" placeholder="Ej: 8888-1122" required autocomplete="tel">
</div>
<div class="login-form-group">
<label for="regEmail">Correo Electrónico <span style="font-size: 0.72rem; color: #64748b;">(Opcional)</span>:</label>
<input type="email" id="regEmail" class="login-input" placeholder="Ej: [email protected]" autocomplete="email">
</div>
<div class="login-form-group">
<label for="regUsername">Nombre de Usuario:</label>
<input type="text" id="regUsername" class="login-input" placeholder="Ej: carlos_papa" required autocomplete="username">
</div>
<div class="login-form-group">
<label for="regPassword">Contraseña:</label>
<input type="password" id="regPassword" class="login-input" placeholder="Mínimo 4 caracteres" required autocomplete="new-password">
</div>
<div id="registerErrorMsg" style="display: none; background: #fee2e2; border: 1px solid #fca5a5; color: #991b1b; padding: 8px 12px; border-radius: 10px; font-size: 0.8rem; font-weight: 700; margin-bottom: 12px; text-align: center;"></div>
<button type="submit" id="btnRegisterSubmit" class="login-submit-btn" style="display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 48px; border-radius: 12px; font-weight: 800; font-size: 1rem; background: linear-gradient(135deg, #0284c7, #0369a1); color: white; border: none; cursor: pointer; box-shadow: 0 4px 14px rgba(2, 132, 199, 0.35);">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="9" cy="7" r="3.5"/><path d="M3 20v-1.5A4.5 4.5 0 0 1 7.5 14h3A4.5 4.5 0 0 1 15 18.5V20"/><circle cx="17.5" cy="7.5" r="2.5"/><path d="M15 14a3.5 3.5 0 0 1 5.5 3v3"/></svg>
<span>Crear Cuenta de Padre y Entrar</span>
</button>
</form>
<div style="text-align: center; margin-top: 14px;">
<p style="font-size: 0.82rem; color: #64748b; margin: 0;">
¿Ya tienes cuenta registrada?
<button type="button" onclick="switchSheetView('login')" style="background: none; border: none; color: #0284c7; font-weight: 800; cursor: pointer; text-decoration: underline; font-size: 0.82rem; padding: 0;">Inicia sesión aquí</button>
</p>
</div>
</div>
</div>
</div>
</div>
<!-- PANEL MASTER DEVELOPER (#viewDeveloper) -->
<div id="viewDeveloper" class="dev-container" style="display: none;">
<!-- CABECERA DE DEVELOPER -->
<header class="dev-header">
<div class="dev-badge">
<div class="dev-icon">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>
</div>
<div>
<div style="display: flex; align-items: center; gap: 8px;">
<h2 style="font-size: 1.18rem; font-weight: 900; margin: 0; color: var(--text-main);">Developer Master Suite</h2>
<span style="background: #f0f9ff; color: #0284c7; border: 1px solid #bae6fd; font-size: 0.68rem; font-weight: 800; padding: 2px 8px; border-radius: 6px;">ROOT MASTER</span>
</div>
<span id="devLoggedName" style="font-size: 0.78rem; color: #64748b; font-weight: 700;">Master Developer (dev)</span>
</div>
</div>
<div class="dev-header-actions">
<button onclick="toggleTheme()" class="theme-toggle-btn" title="Alternar Modo Oscuro / Claro" style="display: inline-flex; align-items: center; justify-content: center;">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/></svg>
</button>
<button onclick="switchDevToView('admin')" class="dev-action-btn" title="Ir al Panel de Soda" style="display: inline-flex; align-items: center; gap: 6px;">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/></svg>
<span>Soda Admin</span>
</button>
<a href="/pos.html" target="_blank" class="dev-action-btn" title="Ir al Terminal de Caja POS" style="display: inline-flex; align-items: center; gap: 6px;">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="14" x="2" y="3" rx="2"/><line x1="8" x2="16" y1="21" y2="21"/><line x1="12" x2="12" y1="17" y2="21"/></svg>
<span>Caja POS</span>
</a>
<button onclick="switchDevToView('student')" class="dev-action-btn" title="Probar Vista de Alumno" style="display: inline-flex; align-items: center; gap: 6px;">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="14" x="2" y="5" rx="2"/><line x1="2" x2="22" y1="10" y2="10"/></svg>
<span>App Alumno</span>
</button>
<button onclick="logout(true)" class="dev-action-btn dev-action-btn-danger" style="display: inline-flex; align-items: center; gap: 6px;" title="Cerrar Sesión">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" x2="9" y1="12" y2="12"/></svg>
<span>Salir</span>
</button>
</div>
</header>
<!-- LAYOUT SPLIT: SIDEBAR A LA IZQUIERDA Y CONTENIDO A LA DERECHA -->
<div class="dev-layout-split">
<!-- SIDEBAR LATERAL IZQUIERDA -->
<aside class="dev-sidebar">
<div class="dev-sidebar-inner">
<div class="dev-sidebar-header">
<span class="dev-sidebar-title">Módulos del Sistema</span>
</div>
<nav class="dev-tabs-nav">
<button class="dev-tab-btn active" id="btnDevTabUsuarios" onclick="switchDevTab('usuarios')">
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>
<span>Usuarios & Administradores</span>
</button>
<button class="dev-tab-btn" id="btnDevTabDisenos" onclick="switchDevTab('disenos')">
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="13.5" cy="6.5" r=".5" fill="currentColor"/><circle cx="17.5" cy="10.5" r=".5" fill="currentColor"/><circle cx="8.5" cy="7.5" r=".5" fill="currentColor"/><circle cx="6.5" cy="12.5" r=".5" fill="currentColor"/><path d="M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z"/></svg>
<span>Diseños de Tarjetas</span>
</button>
<button class="dev-tab-btn" id="btnDevTabDiagnostico" onclick="switchDevTab('diagnostico')">
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 12h-4l-3 9L9 3l-3 9H2"/></svg>
<span>Diagnóstico del Sistema & BD</span>
</button>
<button class="dev-tab-btn" id="btnDevTabEscuelas" onclick="switchDevTab('escuelas')">
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 21h18"/><path d="M5 21V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16"/><path d="M9 21v-4a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v4"/><line x1="9" y1="9" x2="9" y2="9.01"/><line x1="15" y1="9" x2="15" y2="9.01"/></svg>
<span>Escuelas & Sedes</span>
</button>
<button class="dev-tab-btn" id="btnDevTabImportacion" onclick="switchDevTab('importacion')">
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>
<span>Carga Masiva (Excel/CSV)</span>
</button>
<button class="dev-tab-btn" id="btnDevTabSinpe" onclick="switchDevTab('sinpe')">
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
<span>Buscador SINPE Móvil</span>
<span id="devSinpePendingBadge" style="display: none; background: #ef4444; color: #ffffff; font-size: 0.68rem; font-weight: 900; padding: 2px 7px; border-radius: 999px; line-height: 1; margin-left: auto;">0</span>
</button>
<button class="dev-tab-btn" id="btnDevTabKardex" onclick="switchDevTab('kardex')">
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1-2.5-2.5Z"/><path d="M6 6h10"/><path d="M6 10h10"/><path d="M6 14h6"/></svg>
<span>Kardex & Alumnos 360°</span>
</button>
<button class="dev-tab-btn" id="btnDevTabLogs" onclick="switchDevTab('logs')">
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg>
<span>Terminal & Logs en Vivo</span>
</button>
<button class="dev-tab-btn" id="btnDevTabReglas" onclick="switchDevTab('reglas')">
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="4" y1="21" x2="4" y2="14"/><line x1="4" y1="10" x2="4" y2="3"/><line x1="12" y1="21" x2="12" y2="12"/><line x1="12" y1="8" x2="12" y2="3"/><line x1="20" y1="21" x2="20" y2="16"/><line x1="20" y1="12" x2="20" y2="3"/><line x1="1" y1="14" x2="7" y2="14"/><line x1="9" y1="8" x2="15" y2="8"/><line x1="17" y1="16" x2="23" y2="16"/></svg>
<span>Reglas "En Caliente"</span>
</button>
</nav>
</div>
</aside>
<!-- CONTENEDOR DE CONTENIDO PRINCIPAL A LA DERECHA -->
<main class="dev-main-content">
<!-- 1. PESTAÑA: USUARIOS Y ADMINISTRADORES -->
<div id="devTabContentUsuarios" class="dev-tab-content">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 12px;">
<div style="display: flex; gap: 8px; flex-wrap: wrap; align-items: center;">
<input type="text" id="devUserSearchInput" placeholder="Buscar por nombre, usuario, rol..." oninput="filterDevUsuarios()" style="padding: 9px 14px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--card-bg); color: var(--text-main); font-size: 0.85rem; width: 260px; max-width: 100%;">
<select id="devUserRoleFilter" onchange="filterDevUsuarios()" style="padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--card-bg); color: var(--text-main); font-size: 0.85rem; font-weight: 700;">
<option value="all">Todos los Roles</option>
<option value="admin">Administradores</option>
<option value="developer">Developers</option>
<option value="cajero">Cajeros</option>
<option value="vendedor">Vendedores</option>
<option value="padre">Padres de Familia</option>
<option value="estudiante">Estudiantes</option>
</select>
</div>
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
<button type="button" onclick="openNewStudentModalFromDev()" class="dev-action-btn" style="padding: 10px 18px; font-size: 0.88rem; display: inline-flex; align-items: center; gap: 6px; background: linear-gradient(135deg, #0284c7, #0369a1); color: #ffffff; border: none; font-weight: 800; border-radius: 10px; box-shadow: 0 2px 6px rgba(2,132,199,0.3); cursor: pointer;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 10v6M2 10l10-5 10 5-10 5z"/><path d="M6 12v5c3 3 9 3 12 0v-5"/></svg>
<span>🎓 + Registrar Estudiante</span>
</button>
<button onclick="openModalDevUser()" class="dev-action-btn dev-action-btn-primary" style="padding: 10px 18px; font-size: 0.88rem; display: inline-flex; align-items: center; gap: 6px;">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><line x1="19" x2="19" y1="8" y2="14"/><line x1="22" x2="16" y1="11" y2="11"/></svg>
<span>Crear Usuario / Admin</span>
</button>
</div>
</div>
<!-- Resumen rápido de usuarios -->
<div id="devUserStatsStrip" style="display: flex; gap: 10px; overflow-x: auto; margin-bottom: 18px; padding-bottom: 4px;">
<!-- Inyectado dinámicamente -->
</div>
<!-- Tabla de usuarios -->
<div style="background: var(--card-bg); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; box-shadow: 0 4px 15px rgba(0,0,0,0.05);">
<div style="overflow-x: auto;">
<table style="width: 100%; border-collapse: collapse; font-size: 0.86rem; text-align: left;">
<thead>
<tr style="background: var(--bg-main); border-bottom: 1.5px solid var(--border); color: var(--text-muted); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.5px;">
<th style="padding: 12px 14px;">ID</th>
<th style="padding: 12px 14px;">Usuario</th>
<th style="padding: 12px 14px;">Nombre</th>
<th style="padding: 12px 14px;">Rol</th>
<th style="padding: 12px 14px;">Contacto</th>
<th style="padding: 12px 14px;">Estado</th>
<th style="padding: 12px 14px; text-align: right;">Acciones</th>
</tr>
</thead>
<tbody id="devUsersTableBody">
<!-- Inyectado por JS -->
</tbody>
</table>
</div>
</div>
</div>
<!-- 2. PESTAÑA: DISEÑOS DE TARJETAS (SUBIR & GESTIONAR) -->
<div id="devTabContentDisenos" class="dev-tab-content" style="display: none;">
<!-- FORMULARIO DE SUBIDA DE NUEVO DISEÑO -->
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 18px; padding: 22px; margin-bottom: 30px; box-shadow: 0 6px 20px rgba(0,0,0,0.05);">
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 8px;">
<div>
<h3 style="font-size: 1.15rem; font-weight: 900; margin: 0; color: var(--text-main); display: flex; align-items: center; gap: 8px;">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 5v14"/><path d="M5 12h14"/></svg>
<span>Subir Nuevo Diseño de Tarjeta</span>
</h3>
<p style="font-size: 0.84rem; color: var(--text-muted); margin: 3px 0 0;">Sube una imagen personalizada. Quedará disponible inmediatamente para que los estudiantes la elijan.</p>
</div>
<span style="font-size: 0.78rem; font-weight: 800; background: #f0f9ff; color: #0284c7; border: 1px solid #bae6fd; padding: 4px 10px; border-radius: 8px;">Recomendado: 1200x756 (3:2)</span>
</div>
<form id="formDevCardDesign" onsubmit="saveDevCardDesign(event)" style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px;">
<!-- Columna Izquierda: Input de archivo y campos -->
<div>
<!-- Zona de subida -->
<label for="devCardFileInput" class="dev-card-uploader-box" id="devUploadDropZone" style="display: block;">
<input type="file" id="devCardFileInput" accept="image/*" style="display: none;" onchange="handleDevCardFileSelect(event)">
<div id="devUploadPrompt">
<div style="margin-bottom: 8px;">
<svg width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="#94a3b8" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/></svg>
</div>
<div style="font-weight: 800; font-size: 0.95rem; color: var(--text-main); margin-bottom: 4px;">Toca o arrastra una imagen de tarjeta aquí</div>
<div style="font-size: 0.78rem; color: var(--text-muted);">Soporta JPG, PNG, WEBP o SVG (hasta 20MB)</div>
</div>
<div id="devUploadSuccess" style="display: none; color: #10b981; font-weight: 800; font-size: 0.88rem;">
<span style="display: inline-flex; align-items: center; gap: 6px;"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg> Imagen seleccionada con éxito</span>
<div id="devUploadFileName" style="font-size: 0.75rem; color: var(--text-muted); margin-top: 4px;"></div>
</div>
</label>
<div style="margin-bottom: 12px;">
<label style="font-size: 0.82rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 5px;">Nombre del Diseño:</label>
<input type="text" id="devCardName" placeholder="Ej: Cyber Dragón, Galaxia Púrpura..." required style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;" oninput="updateDevCardLivePreview()">
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px;">
<div>
<label style="font-size: 0.82rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 5px;">Categoría:</label>
<select id="devCardCategory" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;" onchange="updateDevCardLivePreview()">
<option value="uni">Unisex / Universal</option>
<option value="fem">Femenino</option>
<option value="masc">Masculino</option>
</select>
</div>
<div>
<label style="font-size: 0.82rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 5px;">Contraste de Texto:</label>
<select id="devCardTextStyle" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;" onchange="updateDevCardLivePreview()">
<option value="dark">Texto Blanco (Fondo Oscuro)</option>
<option value="light">Texto Oscuro (Fondo Claro)</option>
</select>
</div>
</div>
<div style="margin-bottom: 16px;">
<label style="display: flex; align-items: center; gap: 8px; font-size: 0.82rem; font-weight: 700; color: var(--text-main); cursor: pointer;">
<input type="checkbox" id="devCardIsDefault" style="width: 17px; height: 17px; accent-color: #0284c7;">
<span>Establecer como tarjeta predeterminada para nuevos usuarios</span>
</label>
</div>
<button type="submit" id="btnDevSubmitCard" class="dev-action-btn dev-action-btn-primary" style="width: 100%; padding: 12px; justify-content: center; font-size: 0.95rem; border-radius: 12px; display: inline-flex; align-items: center; gap: 8px;">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" x2="12" y1="3" y2="15"/></svg>
<span>Guardar y Publicar Diseño</span>
</button>
</div>
<!-- Columna Derecha: Previsualizador en vivo con datos reales de estudiante -->
<div>
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;">
<span style="font-size: 0.82rem; font-weight: 800; color: var(--text-main); display: inline-flex; align-items: center; gap: 6px;">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>
<span>Previsualización en Vivo de la Tarjeta</span>
</span>
<span style="font-size: 0.72rem; color: #10b981; font-weight: 800;">✓ Sin asteriscos</span>
</div>
<!-- Contenedor de la tarjeta simulada -->
<div id="devLiveCardPreviewWrapper" style="position: relative; width: 100%; aspect-ratio: 1.586; border-radius: 18px; overflow: hidden; background: #0f172a; border: 1.5px solid var(--border); box-shadow: 0 10px 25px rgba(0,0,0,0.25);">
<img id="devLiveCardBgImg" src="/img/cards/card_robo_lab.jpg" alt="Fondo" style="width: 100%; height: 100%; object-fit: cover; display: block;">
<div id="devLiveCardOverlay" class="card-overlay" style="opacity: 1; position: absolute; inset: 0; padding: 16px 18px; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none;">
<div style="display: flex; justify-content: flex-end; align-items: center;">
<span id="devLiveCardBrand" style="font-weight: 900; font-size: 0.85rem; letter-spacing: 0.5px; text-transform: uppercase; color: #ffffff; text-shadow: 0 2px 8px rgba(0,0,0,0.8); display: inline-flex; align-items: center; gap: 5px;"><span style="color: #38bdf8; font-size: 0.65rem;">●</span> SIBOPAY</span>
</div>
<div style="margin-top: auto; margin-bottom: 6px;">
<div id="devLiveCardName" style="font-size: 1.05rem; font-weight: 900; color: #ffffff; text-shadow: 0 2px 8px rgba(0,0,0,0.9);">MATEO ALVARADO CASTRO</div>
<div id="devLiveCardGrade" style="font-size: 0.74rem; font-weight: 700; color: #cbd5e1; text-shadow: 0 2px 6px rgba(0,0,0,0.9);">2° Grado · Sección 2-A</div>
</div>
<div style="display: flex; justify-content: space-between; align-items: flex-end;">
<div>
<div id="devLiveCardBalLabel" style="font-size: 0.65rem; font-weight: 800; text-transform: uppercase; color: #cbd5e1; letter-spacing: 0.5px; margin-bottom: 4px;">Saldo Disponible</div>
<div id="devLiveCardBalValue" class="card-balance-glass" style="font-size: 1.25rem; font-weight: 900;">₡5.300</div>
</div>
<div id="devLiveCardCode" class="card-glass-badge">EST-2026-00001</div>
</div>
</div>
</div>
<div id="devLiveCardThemeTitle" style="font-size: 0.85rem; font-weight: 800; color: var(--text-main); margin-top: 8px; text-align: center;">
Robo-Lab Tech (Vista Previa)
</div>
</div>
</form>
</div>
<!-- GALERÍA DE DISEÑOS DISPONIBLES EN EL SISTEMA -->
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px;">
<div>
<h3 style="font-size: 1.15rem; font-weight: 900; margin: 0; color: var(--text-main); display: flex; align-items: center; gap: 8px;">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><line x1="3" x2="21" y1="9" y2="9"/><line x1="9" x2="9" y1="21" y2="9"/></svg>
<span>Catálogo de Diseños Publicados (<span id="devDisenosCount">0</span>)</span>
</h3>
<p style="font-size: 0.82rem; color: var(--text-muted); margin: 3px 0 0;">Estos son los diseños que pueden elegir los estudiantes en su carrusel.</p>
</div>
<div style="display: flex; gap: 6px;">
<button class="dev-action-btn" onclick="filterDevDisenosGrid('all', this)">Todos</button>
<button class="dev-action-btn" onclick="filterDevDisenosGrid('fem', this)">Femenino</button>
<button class="dev-action-btn" onclick="filterDevDisenosGrid('masc', this)">Masculino</button>
<button class="dev-action-btn" onclick="filterDevDisenosGrid('uni', this)">Unisex</button>
</div>
</div>
<div id="devDisenosGrid" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px;">
<!-- Inyectado dinámicamente -->
</div>
</div>
<!-- 3. PESTAÑA: DIAGNÓSTICO DEL SISTEMA & BD -->
<div id="devTabContentDiagnostico" class="dev-tab-content" style="display: none;">
<div id="devStatsContainer" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px;">
<!-- Inyectado dinámicamente -->
</div>
<!-- SECCIÓN: COPIAS DE SEGURIDAD (BACKUPS) AUTOMÁTICAS -->
<div class="dev-card" style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 18px; padding: 22px; margin-top: 20px;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 38px; height: 38px; border-radius: 10px; background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; display: flex; align-items: center; justify-content: center; font-size: 1.25rem;">
💾
</div>
<div>
<h3 style="margin: 0; font-size: 1.08rem; font-weight: 900; color: var(--text-main);">Copias de Seguridad del Sistema (Backups)</h3>
<span style="font-size: 0.76rem; color: var(--text-muted);">Respaldos automáticos diarios y descargas manuales</span>
</div>
</div>
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
<button type="button" onclick="switchDevTab('logs')" class="dev-action-btn" style="padding: 9px 16px; font-size: 0.84rem; display: inline-flex; align-items: center; gap: 6px; border-color: #38bdf8; color: #0284c7;" title="Abrir terminal interactiva en vivo">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg>
<span>Ver Terminal Web ↗</span>
</button>
<button type="button" onclick="ejecutarBackupManualDev()" id="btnDevCrearBackup" class="dev-action-btn dev-action-btn-primary" style="padding: 9px 18px; font-size: 0.84rem; display: inline-flex; align-items: center; gap: 6px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.3" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
<span>Crear Respaldo Ahora</span>
</button>
</div>
</div>
<div id="devBackupsStatusMsg" style="display: none; padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 0.82rem; font-weight: 700;"></div>
<div style="overflow-x: auto;">
<table class="dev-table" style="width: 100%; border-collapse: collapse; font-size: 0.82rem;">
<thead>
<tr style="border-bottom: 1.5px solid var(--border); text-align: left; color: var(--text-muted);">
<th style="padding: 10px 12px;">Archivo de Respaldo</th>
<th style="padding: 10px 12px;">Motor BD</th>
<th style="padding: 10px 12px;">Fecha y Hora</th>
<th style="padding: 10px 12px;">Tamaño</th>
<th style="padding: 10px 12px; text-align: right;">Acción</th>
</tr>
</thead>
<tbody id="devBackupsTableBody">
<tr>
<td colspan="5" style="text-align: center; padding: 18px; color: var(--text-muted);">Cargando copias de seguridad...</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- 4. PESTAÑA: ESCUELAS & SEDES (MULTI-TENANT) -->
<div id="devTabContentEscuelas" class="dev-tab-content" style="display: none;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 12px;">
<div>
<h3 style="margin: 0; font-size: 1.18rem; font-weight: 900; color: var(--text-main);">Gestión de Escuelas & Sedes Multi-Tenant</h3>
<p style="margin: 4px 0 0 0; font-size: 0.85rem; color: var(--text-muted);">Cada centro educativo opera de forma autónoma con su propio catálogo, SINPE Móvil, estudiantes y personal.</p>
</div>
<button onclick="openModalDevEscuela()" class="dev-action-btn dev-action-btn-primary" style="padding: 10px 18px; font-size: 0.88rem; display: inline-flex; align-items: center; gap: 8px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
<span>+ Dar de Alta Nueva Escuela</span>
</button>
</div>
<!-- Resumen global de sedes -->
<div id="devEscuelasSummaryStrip" style="display: flex; gap: 12px; overflow-x: auto; margin-bottom: 20px; padding-bottom: 4px;">
<!-- Inyectado dinámicamente -->
</div>
<!-- Grid de Tarjetas de Escuelas -->
<div id="devEscuelasGrid" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px;">
<!-- Inyectado dinámicamente -->
</div>
</div>
<!-- 5. PESTAÑA: CARGA MASIVA DE ESTUDIANTES (DEVELOPER) -->
<div id="devTabContentImportacion" class="dev-tab-content" style="display: none;">
<div class="dev-card" style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 18px; padding: 24px; margin-bottom: 20px;">
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; flex-wrap: wrap; gap: 12px;">
<div>
<h3 style="margin: 0; font-size: 1.2rem; font-weight: 900; color: var(--text-main); display: flex; align-items: center; gap: 8px;">
<span>👥 Carga Masiva de Estudiantes vía Excel / CSV</span>
</h3>
<p style="margin: 4px 0 0 0; font-size: 0.82rem; color: var(--text-muted); line-height: 1.4;">
Importa decenas o cientos de estudiantes en segundos. Puedes subir un archivo <code>.csv</code> o pegar las celdas directamente copiadas desde Microsoft Excel o Google Sheets.
</p>
</div>
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
<button type="button" onclick="cargarEjemploImportacionDev()" class="dev-action-btn" style="padding: 8px 14px; font-size: 0.80rem; display: inline-flex; align-items: center; gap: 6px; background: #e0f2fe; color: #0284c7; border: 1.5px solid #bae6fd; font-weight: 800;" title="Pega 3 estudiantes de muestra para probar la herramienta de inmediato">
<span>⚡ Cargar Datos de Ejemplo</span>
</button>
<button type="button" onclick="descargarPlantillaCsvEstudiantes()" class="dev-action-btn" style="padding: 8px 14px; font-size: 0.80rem; display: inline-flex; align-items: center; gap: 6px;">
<span>📥 Descargar Plantilla (.CSV)</span>
</button>
</div>
</div>
<!-- Paso 1: Seleccionar Escuela Destino -->
<div style="margin-bottom: 18px; background: #f8fafc; border: 1.5px solid var(--border); padding: 16px; border-radius: 14px;">
<label style="font-size: 0.84rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 6px;">
1. Selecciona la Escuela / Sede de Destino: *
</label>
<select id="devImportEscuelaSelect" style="width: 100%; max-width: 420px; padding: 10px 14px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--card-bg); color: var(--text-main); font-weight: 700; font-size: 0.90rem;">
<option value="1">Soda Escolar Central (ESC01)</option>
</select>
</div>
<!-- Paso 2: Pegar o Subir Datos -->
<div style="margin-bottom: 18px;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px;">
<label style="font-size: 0.84rem; font-weight: 800; color: var(--text-main); display: block;">
2. Pega aquí los datos desde Excel o escribe en formato CSV:
</label>
<span style="font-size: 0.74rem; color: var(--text-muted);">Columnas: <strong>Nombre, Grado, Sección, Saldo (opcional), Alergias (opcional), Tel. Padre (opcional)</strong></span>
</div>
<textarea id="devImportTextarea" rows="7" placeholder="Ejemplo pegado desde Excel:&#10;Santiago Morales Castro&#9;5to&#9;5-B&#9;2500&#9;Lactosa&#9;8888-1234&#10;Valeria Solano Gómez&#9;3ro&#9;3-A&#9;5000&#9;Ninguna&#9;8765-4321&#10;Mateo Alvarado Pérez&#9;2do&#9;2-A&#9;0&#9;Maní&#9;8333-2211" style="width: 100%; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--card-bg); color: var(--text-main); font-family: monospace; font-size: 0.84rem; line-height: 1.45; box-sizing: border-box;"></textarea>
<div style="display: flex; justify-content: space-between; align-items: center; margin-top: 10px; flex-wrap: wrap; gap: 10px;">
<div style="display: flex; align-items: center; gap: 8px;">
<span style="font-size: 0.78rem; font-weight: 700; color: var(--text-muted);">O selecciona archivo CSV:</span>
<input type="file" id="devImportFileInput" accept=".csv,.txt" onchange="handleDevImportFile(event)" style="font-size: 0.78rem;">
</div>
<button type="button" onclick="analizarDatosImportacionDev()" class="dev-action-btn dev-action-btn-primary" style="padding: 10px 20px; font-size: 0.88rem; display: inline-flex; align-items: center; gap: 6px;">
<span>🔍 Previsualizar y Validar</span>
</button>
</div>
</div>
<!-- Paso 3: Previsualización de Datos -->
<div id="devImportPreviewBox" style="display: none; border-top: 1.5px dashed var(--border); padding-top: 18px; margin-top: 18px;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; flex-wrap: wrap; gap: 8px;">
<div style="display: flex; align-items: center; gap: 10px;">
<span id="devImportPreviewCount" style="background: #e0f2fe; color: #0284c7; padding: 4px 10px; border-radius: 8px; font-weight: 800; font-size: 0.80rem;">0 Alumnos Detectados</span>
<span style="font-size: 0.78rem; color: var(--text-muted);">Revisa la lista antes de guardar</span>
</div>
<button type="button" onclick="ejecutarImportacionMasivaDev()" id="btnDevEjecutarImport" class="dev-action-btn dev-action-btn-primary" style="background: linear-gradient(135deg, #16a34a, #15803d); border-color: #16a34a; padding: 10px 22px; font-size: 0.90rem; font-weight: 800;">
<span>⚡ Confirmar e Importar Todos los Estudiantes</span>
</button>
</div>
<div style="overflow-x: auto; max-height: 380px; overflow-y: auto; border: 1px solid var(--border); border-radius: 12px;">
<table class="dev-table" style="width: 100%; border-collapse: collapse; font-size: 0.82rem;">
<thead style="position: sticky; top: 0; background: var(--card-bg); z-index: 2;">
<tr style="border-bottom: 1.5px solid var(--border); text-align: left; color: var(--text-muted);">
<th style="padding: 8px 10px;">#</th>
<th style="padding: 8px 10px;">Nombre Completo</th>
<th style="padding: 8px 10px;">Grado/Sección</th>
<th style="padding: 8px 10px;">Saldo Inicial</th>
<th style="padding: 8px 10px;">Alergias</th>
<th style="padding: 8px 10px;">Teléfono Padre</th>
<th style="padding: 8px 10px;">Código Asignado</th>
</tr>
</thead>
<tbody id="devImportPreviewTbody">
<!-- Filas inyectadas -->
</tbody>
</table>
</div>
</div>
<div id="devImportResultMsg" style="display: none; margin-top: 16px; padding: 14px; border-radius: 12px; font-size: 0.84rem; line-height: 1.45;"></div>
</div>
</div>
<!-- 6. PESTAÑA: BUSCADOR UNIVERSAL SINPE MÓVIL & AUDITORÍA -->
<div id="devTabContentSinpe" class="dev-tab-content" style="display: none;">
<!-- CABECERA Y ACCIONES RÁPIDAS -->
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; flex-wrap: wrap; gap: 14px;">
<div>
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 38px; height: 38px; border-radius: 12px; background: linear-gradient(135deg, #0284c7, #0369a1); color: #ffffff; display: flex; align-items: center; justify-content: center; font-size: 1.25rem; box-shadow: 0 4px 12px rgba(2,132,199,0.3);">
🔍
</div>
<div>
<h3 style="margin: 0; font-size: 1.25rem; font-weight: 900; color: var(--text-main);">Buscador Universal de SINPE Móvil & Conciliación</h3>
<p style="margin: 3px 0 0 0; font-size: 0.82rem; color: var(--text-muted);">Auditoría global en tiempo real de comprobantes, solicitudes de padres, depósitos bancarios y resolución de disputas.</p>
</div>
</div>
</div>
<div style="display: flex; gap: 8px; flex-wrap: wrap; align-items: center;">
<button type="button" onclick="loadDevSinpeUniversal()" class="dev-action-btn" style="padding: 9px 15px; font-size: 0.84rem; display: inline-flex; align-items: center; gap: 6px;" title="Actualizar datos en tiempo real">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.2"/></svg>
<span>Actualizar</span>
</button>
<button type="button" onclick="openModalDevSimularSinpe()" class="dev-action-btn" style="padding: 9px 15px; font-size: 0.84rem; display: inline-flex; align-items: center; gap: 6px; background: #f0fdf4; color: #166534; border: 1.5px solid #bbf7d0; font-weight: 800;" title="Simular depósito bancario para pruebas">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg>
<span>⚡ Simular Depósito Banco</span>
</button>
<button type="button" onclick="exportarSinpeUniversalCsv()" class="dev-action-btn" style="padding: 9px 15px; font-size: 0.84rem; display: inline-flex; align-items: center; gap: 6px;" title="Descargar reporte en Excel / CSV">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
<span>Descargar CSV</span>
</button>
</div>
</div>
<!-- KPIS EN TIEMPO REAL -->
<div id="devSinpeKpiGrid" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 22px;">
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 14px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.03);">
<div style="font-size: 0.72rem; font-weight: 800; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.5px; margin-bottom: 6px; display: flex; align-items: center; justify-content: space-between;">
<span>Acreditado SINPE</span>
<span style="color: #10b981; font-size: 1rem;">💳</span>
</div>
<div id="devSinpeKpiTotalMonto" style="font-size: 1.35rem; font-weight: 900; color: #10b981;">₡0</div>
<div id="devSinpeKpiTotalCant" style="font-size: 0.74rem; color: var(--text-muted); font-weight: 700; margin-top: 2px;">0 recargas verificadas</div>
</div>
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 14px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.03);">
<div style="font-size: 0.72rem; font-weight: 800; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.5px; margin-bottom: 6px; display: flex; align-items: center; justify-content: space-between;">
<span>En Revisión (Pendientes)</span>
<span style="color: #f59e0b; font-size: 1rem;">⏳</span>
</div>
<div id="devSinpeKpiPendientes" style="font-size: 1.35rem; font-weight: 900; color: #f59e0b;">0</div>
<div style="font-size: 0.74rem; color: var(--text-muted); font-weight: 700; margin-top: 2px;">Requieren verificación</div>
</div>
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 14px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.03);">
<div style="font-size: 0.72rem; font-weight: 800; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.5px; margin-bottom: 6px; display: flex; align-items: center; justify-content: space-between;">
<span>Rechazadas / Alertas</span>
<span style="color: #ef4444; font-size: 1rem;">⚠️</span>
</div>
<div id="devSinpeKpiRechazadas" style="font-size: 1.35rem; font-weight: 900; color: #ef4444;">0</div>
<div style="font-size: 0.74rem; color: var(--text-muted); font-weight: 700; margin-top: 2px;">Comprobantes no válidos</div>
</div>
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 14px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.03);">
<div style="font-size: 0.72rem; font-weight: 800; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.5px; margin-bottom: 6px; display: flex; align-items: center; justify-content: space-between;">
<span>Banco Sin Reclamar</span>
<span style="color: #0284c7; font-size: 1rem;">🏦</span>
</div>
<div id="devSinpeKpiBancoUnclaimed" style="font-size: 1.35rem; font-weight: 900; color: #0284c7;">0</div>
<div id="devSinpeKpiBancoUnclaimedMonto" style="font-size: 0.74rem; color: var(--text-muted); font-weight: 700; margin-top: 2px;">₡0 en depósitos huérfanos</div>
</div>
</div>
<!-- CAJA DE BÚSQUEDA Y FILTROS MULTI-CRITERIO -->
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 16px; padding: 18px; margin-bottom: 20px; box-shadow: 0 4px 15px rgba(0,0,0,0.04);">
<!-- Fila de barra de búsqueda principal -->
<div style="display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap;">
<div style="position: relative; flex: 1; min-width: 280px;">
<input type="text" id="devSinpeSearchInput" placeholder="Buscar por comprobante (ej: BAC244304, 303063), cód. detalle (SIBO-XC69), estudiante, teléfono padre..." oninput="debounceDevSinpeSearch()" style="width: 100%; padding: 12px 38px 12px 42px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.90rem; font-weight: 700; box-sizing: border-box;">
<div style="position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none;">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
</div>
<button type="button" onclick="clearDevSinpeSearch()" id="btnDevSinpeClearSearch" style="position: absolute; right: 12px; top: 50%; transform: translateY(-50%); background: none; border: none; font-size: 1.1rem; color: var(--text-muted); cursor: pointer; display: none;">✕</button>
</div>
<button type="button" onclick="loadDevSinpeUniversal()" class="dev-action-btn dev-action-btn-primary" style="padding: 12px 22px; font-size: 0.90rem; font-weight: 800; display: inline-flex; align-items: center; gap: 8px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
<span>Buscar</span>
</button>
</div>
<!-- Fila de filtros selectivos -->
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px;">
<div>
<label style="font-size: 0.74rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; display: block; margin-bottom: 4px;">Estado:</label>
<select id="devSinpeFilterEstado" onchange="loadDevSinpeUniversal()" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.84rem; font-weight: 700;">
<option value="todas">Todos los Estados</option>
<option value="pendiente">⏳ Solo Pendientes</option>
<option value="aprobada">✓ Aprobadas / Acreditadas</option>
<option value="rechazada">✕ Rechazadas</option>
<option value="unclaimed">🏦 Banco Sin Reclamar</option>
</select>
</div>
<div>
<label style="font-size: 0.74rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; display: block; margin-bottom: 4px;">Escuela / Sede:</label>
<select id="devSinpeFilterEscuela" onchange="loadDevSinpeUniversal()" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.84rem; font-weight: 700;">
<option value="todas">Todas las Escuelas</option>
</select>
</div>
<div>
<label style="font-size: 0.74rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; display: block; margin-bottom: 4px;">Rango de Fecha:</label>
<select id="devSinpeFilterFecha" onchange="loadDevSinpeUniversal()" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.84rem; font-weight: 700;">
<option value="todas">Todo el Historial</option>
<option value="hoy">Hoy</option>
<option value="7dias">Últimos 7 días</option>
<option value="30dias">Últimos 30 días</option>
</select>
</div>
<div>
<label style="font-size: 0.74rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; display: block; margin-bottom: 4px;">Tipo de Registro:</label>
<select id="devSinpeFilterOrigen" onchange="loadDevSinpeUniversal()" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.84rem; font-weight: 700;">
<option value="todas">Todo Unificado</option>
<option value="solicitudes">📱 Solicitudes de Padres</option>
<option value="banco">🏦 Notificaciones Bancarias</option>
<option value="saldo">💳 Movimientos de Saldo</option>
</select>
</div>
</div>
</div>
<!-- LISTADO DE RESULTADOS -->
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 16px; overflow: hidden; box-shadow: 0 4px 15px rgba(0,0,0,0.04);">
<div style="padding: 14px 18px; border-bottom: 1.5px solid var(--border); display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px;">
<div style="font-weight: 800; font-size: 0.88rem; color: var(--text-main); display: flex; align-items: center; gap: 8px;">
<span>Resultados de Búsqueda</span>
<span id="devSinpeResultCountBadge" style="background: #e0f2fe; color: #0284c7; padding: 2px 8px; border-radius: 8px; font-size: 0.75rem; font-weight: 800;">0 registros</span>
</div>
<span style="font-size: 0.76rem; color: var(--text-muted);">Haz clic en cualquier acción para gestionar o auditar</span>
</div>
<div style="overflow-x: auto; max-height: 600px; overflow-y: auto;">
<table class="dev-table" style="width: 100%; border-collapse: collapse; font-size: 0.82rem; text-align: left;">
<thead style="position: sticky; top: 0; background: var(--card-bg); z-index: 2; border-bottom: 1.5px solid var(--border);">
<tr style="color: var(--text-muted); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.5px;">
<th style="padding: 12px 14px;">Fecha / Hora</th>
<th style="padding: 12px 14px;">Comprobante / Detalle</th>
<th style="padding: 12px 14px;">Origen</th>
<th style="padding: 12px 14px;">Estudiante / Sede</th>
<th style="padding: 12px 14px;">Remitente / Banco</th>
<th style="padding: 12px 14px;">Monto</th>
<th style="padding: 12px 14px;">Estado</th>
<th style="padding: 12px 14px; text-align: right;">Acciones</th>
</tr>
</thead>
<tbody id="devSinpeTableBody">
<tr>
<td colspan="8" style="text-align: center; padding: 30px; color: var(--text-muted);">
Cargando transacciones de SINPE Móvil...
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- 7. PESTAÑA: KARDEX & AUDITORÍA 360° DE ESTUDIANTES -->
<div id="devTabContentKardex" class="dev-tab-content" style="display: none;">
<!-- ENCABEZADO Y CONTROLES DE BÚSQUEDA -->
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 18px; padding: 20px; margin-bottom: 20px; box-shadow: 0 4px 16px rgba(0,0,0,0.04);">
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; flex-wrap: wrap; gap: 12px;">
<div>
<h3 style="font-size: 1.25rem; font-weight: 900; margin: 0; color: var(--text-main); display: flex; align-items: center; gap: 8px;">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="#0284c7" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1-2.5-2.5Z"/><path d="M6 6h10"/><path d="M6 10h10"/><path d="M6 14h6"/></svg>
<span>Auditoría & Kardex 360° de Estudiantes</span>
</h3>
<p style="font-size: 0.84rem; color: var(--text-muted); margin: 4px 0 0;">
Consulta en tiempo real el saldo actual, compras en soda con desglose de productos y recargas bancarias de cualquier alumno del sistema.
</p>
</div>
<span id="devKardexResultCountBadge" style="font-size: 0.8rem; font-weight: 800; background: #e0f2fe; color: #0369a1; padding: 4px 12px; border-radius: 20px;">
0 estudiantes
</span>
</div>
<!-- FILTROS -->
<div style="display: flex; gap: 10px; flex-wrap: wrap; align-items: center;">
<div style="flex: 2; min-width: 260px;">
<input type="text" id="devKardexSearchInput" placeholder="Buscar por nombre, carné, escuela o teléfono del padre (ej: Sofía, Mateo, EST-002)..." oninput="buscarEstudiantesKardexDev()" style="width: 100%; padding: 11px 14px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.88rem; font-weight: 700; box-sizing: border-box;">
</div>
<div style="flex: 1; min-width: 180px;">
<select id="devKardexEscuelaFilter" onchange="buscarEstudiantesKardexDev()" style="width: 100%; padding: 11px 12px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.86rem; font-weight: 700; box-sizing: border-box;">
<option value="todas">🏫 Todas las Sedes</option>
</select>
</div>
<button type="button" onclick="recargarListaKardexDev()" class="dev-action-btn dev-action-btn-outline" style="height: 42px; padding: 0 16px; font-weight: 800;" title="Refrescar lista de estudiantes">
🔄 Actualizar
</button>
</div>
</div>
<!-- ESTRUCTURA PRINCIPAL: SELECTOR RÁPIDO DE ALUMNOS + FICHA TÉCNICA 360° -->
<div style="display: grid; grid-template-columns: minmax(280px, 340px) 1fr; gap: 20px; align-items: start;" id="devKardexMainGrid">
<!-- COLUMNA IZQUIERDA: LISTADO DE ALUMNOS COINCIDENTES -->
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 18px; padding: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.03);">
<div style="font-size: 0.76rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; margin-bottom: 10px; letter-spacing: 0.5px;">
Selecciona un Estudiante:
</div>
<div id="devKardexStudentList" style="max-height: 650px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px;">
<!-- Inyectado por JS -->
</div>
</div>
<!-- COLUMNA DERECHA: FICHA TÉCNICA & KARDEX DETALLADO -->
<div id="devKardexDetailContainer" style="display: flex; flex-direction: column; gap: 18px;">
<!-- Mensaje inicial antes de seleccionar -->
<div id="devKardexPlaceholder" style="background: var(--card-bg); border: 1.5px dashed var(--border); border-radius: 18px; padding: 60px 20px; text-align: center; color: var(--text-muted);">
<div style="font-size: 2.5rem; margin-bottom: 10px;">🎓</div>
<h4 style="font-size: 1.1rem; font-weight: 800; margin: 0 0 6px 0; color: var(--text-main);">Auditoría Individual de Estudiante</h4>
<p style="font-size: 0.85rem; margin: 0; max-width: 380px; margin: 0 auto;">Selecciona a un alumno de la lista o escribe en el buscador para ver su saldo actual, compras detalladas y recargas bancarias.</p>
</div>
<!-- FICHA TÉCNICA Y AUDITORÍA 360° (SE ACTIVA AL SELECCIONAR) -->
<div id="devKardexStudentView" style="display: none;">
<!-- TARJETA CABECERA DEL ESTUDIANTE -->
<div style="background: linear-gradient(135deg, rgba(2, 132, 199, 0.05), rgba(99, 102, 241, 0.05)); border: 2px solid #0284c7; border-radius: 18px; padding: 20px; margin-bottom: 16px; box-shadow: 0 4px 16px rgba(2, 132, 199, 0.08);">
<div style="display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 14px; margin-bottom: 18px;">
<div style="display: flex; align-items: center; gap: 14px;">
<div id="devKardexAvatar" style="width: 52px; height: 52px; border-radius: 14px; background: linear-gradient(135deg, #0284c7, #3b82f6); color: white; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 1.3rem; box-shadow: 0 4px 12px rgba(2, 132, 199, 0.3); flex-shrink: 0;">
ES
</div>
<div>
<div style="display: flex; align-items: center; gap: 8px; flex-wrap: wrap;">
<span id="devKardexBadgeCarnet" style="font-size: 0.74rem; font-weight: 800; background: #e0f2fe; color: #0369a1; padding: 2px 8px; border-radius: 6px;">EST-001</span>
<span id="devKardexBadgeEscuela" style="font-size: 0.74rem; font-weight: 700; color: #64748b; background: var(--bg-main); padding: 2px 8px; border-radius: 6px;">Escuela</span>
</div>
<h3 id="devKardexNombre" style="margin: 3px 0 2px 0; font-size: 1.25rem; font-weight: 900; color: var(--text-main);">Nombre Alumno</h3>
<div style="font-size: 0.8rem; color: #0284c7; font-weight: 700;">
<span id="devKardexGradoSeccion">Grado · Sección</span> · <span id="devKardexPadreInfo" style="color: var(--text-muted);">Encargado</span>
</div>
</div>
</div>
<!-- ACCIONES RÁPIDAS DE ESTUDIANTE -->
<div style="display: flex; gap: 8px; align-items: center;">
<button type="button" id="devKardexBtnVerCarnet" onclick="abrirCarnetEstudianteDesdeDev()" class="dev-action-btn dev-action-btn-outline" style="font-size: 0.8rem; padding: 6px 12px; font-weight: 800;" title="Ver carné digital">
🪪 Ver Carné QR
</button>
</div>
</div>
<!-- CUADRÍCULA DE KPIS FINANCIEROS (4 MÉTRICAS CLAVE) -->
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px;">
<div style="background: var(--card-bg); border: 1.5px solid #10b981; border-radius: 12px; padding: 12px; text-align: center;">
<div style="font-size: 0.68rem; font-weight: 800; color: #059669; text-transform: uppercase;">Saldo Actual</div>
<div id="devKardexKpiSaldoActual" style="font-size: 1.35rem; font-weight: 950; color: #10b981; margin: 3px 0 1px 0;">₡0</div>
<span style="font-size: 0.68rem; color: #64748b; font-weight: 700;">Disponible en tarjeta</span>
</div>
<div style="background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 12px; text-align: center;">
<div style="font-size: 0.68rem; font-weight: 800; color: #0284c7; text-transform: uppercase;">Total Recargado</div>
<div id="devKardexKpiTotalRecargas" style="font-size: 1.25rem; font-weight: 900; color: #0284c7; margin: 3px 0 1px 0;">₡0</div>
<span id="devKardexKpiCantRecargas" style="font-size: 0.68rem; color: #64748b; font-weight: 700;">0 recargas</span>
</div>
<div style="background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 12px; text-align: center;">
<div style="font-size: 0.68rem; font-weight: 800; color: #f59e0b; text-transform: uppercase;">Total Consumido</div>
<div id="devKardexKpiTotalCompras" style="font-size: 1.25rem; font-weight: 900; color: #d97706; margin: 3px 0 1px 0;">₡0</div>
<span id="devKardexKpiCantCompras" style="font-size: 0.68rem; color: #64748b; font-weight: 700;">0 compras</span>
</div>
<div style="background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 12px; text-align: center;">
<div style="font-size: 0.68rem; font-weight: 800; color: #64748b; text-transform: uppercase;">Límite Diario</div>
<div id="devKardexKpiLimiteDiario" style="font-size: 1.25rem; font-weight: 900; color: var(--text-main); margin: 3px 0 1px 0;">₡0</div>
<span style="font-size: 0.68rem; color: #64748b; font-weight: 700;">Máx por día</span>
</div>
</div>
</div>
<!-- SUB-PESTAÑAS DE AUDITORÍA: COMPRAS, RECARGAS, KARDEX -->
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 18px; padding: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.03);">
<div style="display: flex; gap: 8px; border-bottom: 1.5px solid var(--border); padding-bottom: 12px; margin-bottom: 16px; flex-wrap: wrap;">
<button type="button" id="btnDevKardexTabCompras" onclick="cambiarSubTabKardexDev('compras')" class="dev-action-btn dev-action-btn-primary" style="font-size: 0.85rem; font-weight: 800; display: inline-flex; align-items: center; gap: 6px;">
🛒 Compras en Soda (<span id="devKardexBadgeTabComprasCount">0</span>)
</button>
<button type="button" id="btnDevKardexTabRecargas" onclick="cambiarSubTabKardexDev('recargas')" class="dev-action-btn dev-action-btn-outline" style="font-size: 0.85rem; font-weight: 800; display: inline-flex; align-items: center; gap: 6px;">
⚡ Recargas de Saldo (<span id="devKardexBadgeTabRecargasCount">0</span>)
</button>
<button type="button" id="btnDevKardexTabMovimientos" onclick="cambiarSubTabKardexDev('movimientos')" class="dev-action-btn dev-action-btn-outline" style="font-size: 0.85rem; font-weight: 800; display: inline-flex; align-items: center; gap: 6px;">
📊 Kardex Contable Integral (<span id="devKardexBadgeTabMovimientosCount">0</span>)
</button>
</div>
<!-- CONTENIDO DE SUB-PESTAÑA 1: COMPRAS -->
<div id="devKardexSubViewCompras">
<!-- Inyectado por JS -->
</div>
<!-- CONTENIDO DE SUB-PESTAÑA 2: RECARGAS -->
<div id="devKardexSubViewRecargas" style="display: none;">
<!-- Inyectado por JS -->
</div>
<!-- CONTENIDO DE SUB-PESTAÑA 3: KARDEX COMPLETO -->
<div id="devKardexSubViewMovimientos" style="display: none;">
<!-- Inyectado por JS -->
</div>
</div>
</div>
</div>
</div>
</div>
<!-- 8. PESTAÑA: VISOR DE LOGS DEL SERVIDOR Y TERMINAL WEB EN VIVO -->
<div id="devTabContentLogs" class="dev-tab-content" style="display: none;">
<!-- ENCABEZADO Y TELEMETRÍA SUPERIOR -->
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 18px; padding: 20px; margin-bottom: 20px; box-shadow: 0 4px 16px rgba(0,0,0,0.04); display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 14px;">
<div style="display: flex; align-items: center; gap: 14px;">
<div style="width: 46px; height: 46px; border-radius: 12px; background: #0f172a; color: #38bdf8; display: flex; align-items: center; justify-content: center; font-size: 1.35rem; border: 1.5px solid #334155; flex-shrink: 0;">
💻
</div>
<div>
<div style="display: flex; align-items: center; gap: 10px; flex-wrap: wrap;">
<h3 style="margin: 0; font-size: 1.22rem; font-weight: 900; color: var(--text-main);">Terminal Web & Logs en Vivo</h3>
<span class="dev-terminal-badge-live" id="devTermStatusBadge"><span class="pulse-dot"></span> EN VIVO</span>
</div>
<p style="font-size: 0.82rem; color: var(--text-muted); margin: 3px 0 0;">Monitoreo en tiempo real de peticiones HTTP, eventos SINPE Móvil, errores y procesos en el servidor.</p>
</div>
</div>
<div style="display: flex; gap: 8px; flex-wrap: wrap; align-items: center;">
<button type="button" class="dev-action-btn" onclick="toggleDevLogsPause()" id="btnDevLogsPause" title="Pausar o reanudar el flujo en vivo">
<span id="devLogsPauseIcon">⏸</span> <span id="devLogsPauseText">Pausar Flujo</span>
</button>
<button type="button" class="dev-action-btn" onclick="clearDevTerminalScreen()" title="Limpiar la pantalla de la terminal">
<span>🧹</span> <span>Limpiar Pantalla</span>
</button>
<button type="button" class="dev-action-btn" onclick="descargarDevLogs()" title="Descargar registro de logs a un archivo">
<span>📥</span> <span>Descargar .log</span>
</button>
</div>
</div>
<!-- VENTANA PRINCIPAL DE LA TERMINAL WEB -->
<div class="dev-terminal-wrapper">
<!-- HEADER DE LA TERMINAL -->
<div class="dev-terminal-header">
<div class="dev-terminal-dots">
<div class="dev-terminal-dot dot-red" title="Cerrar"></div>
<div class="dev-terminal-dot dot-yellow" title="Minimizar"></div>
<div class="dev-terminal-dot dot-green" title="Maximizar"></div>
</div>
<div class="dev-terminal-title">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg>
<span>bash ~ sibopay-server (PM2 #4) [tail -f]</span>
</div>
<div style="display: flex; align-items: center; gap: 12px; font-size: 0.74rem; color: #94a3b8; font-family: ui-monospace, monospace;">
<span>Líneas: <strong id="devTermLineCount" style="color: #38bdf8;">0</strong></span>
<span style="color: #475569;">|</span>
<span id="devTermUptimeLabel">Uptime: --</span>
</div>
</div>
<!-- BARRA DE FILTROS Y BÚSQUEDA -->
<div class="dev-terminal-toolbar">
<div class="dev-terminal-filters">
<button type="button" class="dev-terminal-filter-btn active" data-filter="all" onclick="setDevLogsFilter('all', this)">Todos</button>
<button type="button" class="dev-terminal-filter-btn" data-filter="auth" onclick="setDevLogsFilter('auth', this)">🔒 Auth</button>
<button type="button" class="dev-terminal-filter-btn" data-filter="orden" onclick="setDevLogsFilter('orden', this)">🥪 Órdenes</button>
<button type="button" class="dev-terminal-filter-btn" data-filter="sinpe" onclick="setDevLogsFilter('sinpe', this)">💸 Finanzas</button>
<button type="button" class="dev-terminal-filter-btn" data-filter="http" onclick="setDevLogsFilter('http', this)">⚡ HTTP</button>
<button type="button" class="dev-terminal-filter-btn" data-filter="warn" onclick="setDevLogsFilter('warn', this)">⚠️ Avisos</button>
<button type="button" class="dev-terminal-filter-btn" data-filter="error" onclick="setDevLogsFilter('error', this)">❌ Errores</button>
<button type="button" class="dev-terminal-filter-btn" data-filter="sistema" onclick="setDevLogsFilter('sistema', this)">⚙️ Sistema</button>
</div>
<div class="dev-terminal-actions">
<input type="text" id="devTermSearchInput" class="dev-terminal-search-input" placeholder="🔍 Filtrar logs (grep)..." oninput="applyDevLogsSearch()">
<label style="display: inline-flex; align-items: center; gap: 6px; font-size: 0.74rem; color: #94a3b8; cursor: pointer; user-select: none;">
<input type="checkbox" id="devTermAutoScrollCheck" checked style="accent-color: #0284c7;"> Auto-scroll
</label>
</div>
</div>
<!-- PANTALLA DE CONSOLA / LOGS -->
<div id="devTerminalScreen" class="dev-terminal-screen">
<div style="color: #64748b; font-style: italic; padding: 12px 6px;">Conectando con el stream del servidor...</div>
</div>
<!-- FOOTER DE ESTADO DE LA TERMINAL -->
<div class="dev-terminal-footer">
<div class="dev-terminal-prompt">
<span>sibopay@server:~$</span>
<span class="terminal-blink">_</span>
</div>
<div class="dev-terminal-telemetry" id="devTermTelemetry">
<span>Memoria: <strong id="devTermMemMb" style="color: #f1f5f9;">--</strong></span>
<span>·</span>
<span>Node: <strong id="devTermNodeVer" style="color: #f1f5f9;">--</strong></span>
<span>·</span>
<span style="color: #10b981;">● Stream Activo</span>
</div>
</div>
</div>
</div>
<!-- 9. PESTAÑA: CONFIGURADOR DE REGLAS DE NEGOCIO "EN CALIENTE" -->
<div id="devTabContentReglas" class="dev-tab-content" style="display: none;">
<!-- CABECERA DE LA SECCIÓN -->
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 18px; padding: 22px; margin-bottom: 22px; box-shadow: 0 4px 16px rgba(0,0,0,0.04); display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 16px;">
<div style="display: flex; align-items: center; gap: 14px;">
<div style="width: 48px; height: 48px; border-radius: 14px; background: linear-gradient(135deg, #0284c7, #0369a1); color: #ffffff; display: flex; align-items: center; justify-content: center; font-size: 1.4rem; box-shadow: 0 4px 12px rgba(2, 132, 199, 0.3); flex-shrink: 0;">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><line x1="4" y1="21" x2="4" y2="14"/><line x1="4" y1="10" x2="4" y2="3"/><line x1="12" y1="21" x2="12" y2="12"/><line x1="12" y1="8" x2="12" y2="3"/><line x1="20" y1="21" x2="20" y2="16"/><line x1="20" y1="12" x2="20" y2="3"/><line x1="1" y1="14" x2="7" y2="14"/><line x1="9" y1="8" x2="15" y2="8"/><line x1="17" y1="16" x2="23" y2="16"/></svg>
</div>
<div>
<h3 style="margin: 0; font-size: 1.25rem; font-weight: 900; color: var(--text-main); display: flex; align-items: center; gap: 8px;">
<span>Configurador de Reglas de Negocio "En Caliente"</span>
<span style="background: #e0f2fe; color: #0284c7; font-size: 0.72rem; padding: 2px 8px; border-radius: 999px; font-weight: 800;">Tiempo Real</span>
</h3>
<p style="margin: 4px 0 0 0; font-size: 0.83rem; color: var(--text-muted); line-height: 1.4;">
Modifica parámetros financieros, topes operativos y políticas del sistema sin reiniciar el servidor ni tocar código.
</p>
</div>
</div>
<div style="display: flex; align-items: center; gap: 10px; flex-wrap: wrap;">
<button type="button" onclick="resetearReglasNegocioDev()" class="dev-action-btn" style="padding: 10px 16px; font-size: 0.84rem; display: inline-flex; align-items: center; gap: 6px;" title="Restablecer todos los parámetros a sus valores recomendados de fábrica">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>
<span>Valores de Fábrica</span>
</button>
<button type="button" onclick="guardarReglasNegocioDev()" class="dev-action-btn dev-action-btn-primary" style="padding: 10px 22px; font-size: 0.88rem; display: inline-flex; align-items: center; gap: 8px; box-shadow: 0 4px 12px rgba(2, 132, 199, 0.25);">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg>
<span>Guardar y Aplicar en Vivo</span>
</button>
</div>
</div>
<!-- BANNER DE ESTADO DE SINCRONIZACIÓN -->
<div id="devReglasSyncAlert" style="display: none; padding: 12px 16px; border-radius: 12px; margin-bottom: 20px; font-size: 0.84rem; font-weight: 700; align-items: center; gap: 10px;"></div>
<!-- REJILLA DE TARJETAS DE CONFIGURACIÓN -->
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px;">
<!-- CARD 1: FINANZAS Y RECARGAS SINPE -->
<div class="dev-card" style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 16px; padding: 20px; display: flex; flex-direction: column; gap: 16px;">
<div style="display: flex; align-items: center; gap: 10px; border-bottom: 1.5px solid var(--border); padding-bottom: 12px;">
<div style="width: 36px; height: 36px; border-radius: 10px; background: rgba(16, 185, 129, 0.15); color: #10b981; display: flex; align-items: center; justify-content: center; font-size: 1.1rem;">
💸
</div>
<div>
<h4 style="margin: 0; font-size: 0.98rem; font-weight: 800; color: var(--text-main);">Finanzas & Recargas SINPE</h4>
<span style="font-size: 0.74rem; color: var(--text-muted);">Límites y montos sugeridos para los padres</span>
</div>
</div>
<div>
<label style="font-size: 0.76rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; display: block; margin-bottom: 6px;">Monto Mínimo por Recarga (CRC):</label>
<div style="position: relative;">
<span style="position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-weight: 800; color: var(--text-muted);">₡</span>
<input type="number" id="cfg_sinpe_monto_minimo" min="100" step="500" style="width: 100%; padding: 10px 12px 10px 30px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.95rem; font-weight: 700; box-sizing: border-box;">
</div>
<span style="font-size: 0.72rem; color: var(--text-muted); display: block; margin-top: 4px;">Rechaza reportes de recarga por montos inferiores a este valor.</span>
</div>
<div>
<label style="font-size: 0.76rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; display: block; margin-bottom: 6px;">Monto Máximo de Seguridad (CRC):</label>
<div style="position: relative;">
<span style="position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-weight: 800; color: var(--text-muted);">₡</span>
<input type="number" id="cfg_sinpe_monto_maximo" min="1000" step="5000" style="width: 100%; padding: 10px 12px 10px 30px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.95rem; font-weight: 700; box-sizing: border-box;">
</div>
<span style="font-size: 0.72rem; color: var(--text-muted); display: block; margin-top: 4px;">Tope máximo admitido por cada transacción individual.</span>
</div>
<div>
<label style="font-size: 0.76rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; display: block; margin-bottom: 6px;">Botones de Montos Sugeridos Rápidos:</label>
<input type="text" id="cfg_sinpe_montos_sugeridos" placeholder="2000, 3000, 5000, 10000" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.88rem; font-weight: 700; box-sizing: border-box;">
<span style="font-size: 0.72rem; color: var(--text-muted); display: block; margin-top: 4px;">Separados por coma. Se renderizan como píldoras de 1 toque en la app.</span>
</div>
</div>
<!-- CARD 2: ALUMNOS Y NUEVOS REGISTROS -->
<div class="dev-card" style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 16px; padding: 20px; display: flex; flex-direction: column; gap: 16px;">
<div style="display: flex; align-items: center; gap: 10px; border-bottom: 1.5px solid var(--border); padding-bottom: 12px;">
<div style="width: 36px; height: 36px; border-radius: 10px; background: rgba(2, 132, 199, 0.15); color: #0284c7; display: flex; align-items: center; justify-content: center; font-size: 1.1rem;">
🎓
</div>
<div>
<h4 style="margin: 0; font-size: 0.98rem; font-weight: 800; color: var(--text-main);">Alumnos & Nuevas Matrículas</h4>
<span style="font-size: 0.74rem; color: var(--text-muted);">Valores iniciales aplicados a nuevos estudiantes</span>
</div>
</div>
<div>
<label style="font-size: 0.76rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; display: block; margin-bottom: 6px;">Límite Diario por Defecto (CRC):</label>
<div style="position: relative;">
<span style="position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-weight: 800; color: var(--text-muted);">₡</span>
<input type="number" id="cfg_estudiante_limite_diario_default" min="500" step="500" style="width: 100%; padding: 10px 12px 10px 30px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.95rem; font-weight: 700; box-sizing: border-box;">
</div>
<span style="font-size: 0.72rem; color: var(--text-muted); display: block; margin-top: 4px;">Tope diario de gasto sugerido al registrar o importar alumnos masivamente.</span>
</div>
<div style="padding: 12px 14px; background: var(--bg-main); border: 1.5px solid var(--border); border-radius: 12px;">
<div style="display: flex; justify-content: space-between; align-items: center;">
<div>
<div style="display: flex; align-items: center; gap: 8px;">
<span style="font-size: 0.85rem; font-weight: 800; color: var(--text-main); display: block;">Transferencias P2P entre alumnos</span>
<span style="background: #e0f2fe; color: #0284c7; font-size: 0.68rem; padding: 1px 7px; border-radius: 999px; font-weight: 800;">Kill-Switch Global</span>
</div>
<span style="font-size: 0.73rem; color: var(--text-muted);">Interruptor maestro: Si se apaga, se deshabilitan y ocultan de inmediato en todo el sistema</span>
</div>
<label class="switch-saas" title="Habilitar o apagar transferencias P2P en todo el sistema">
<input type="checkbox" id="cfg_estudiante_permitir_transferencias_default">
<span class="switch-saas-slider round"></span>
</label>
</div>
</div>
</div>
<!-- CARD 3: PRE-ÓRDENES Y HORARIOS DE SODA -->
<div class="dev-card" style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 16px; padding: 20px; display: flex; flex-direction: column; gap: 16px;">
<div style="display: flex; align-items: center; gap: 10px; border-bottom: 1.5px solid var(--border); padding-bottom: 12px;">
<div style="width: 36px; height: 36px; border-radius: 10px; background: rgba(249, 115, 22, 0.15); color: #f97316; display: flex; align-items: center; justify-content: center; font-size: 1.1rem;">
🥪
</div>
<div>
<h4 style="margin: 0; font-size: 0.98rem; font-weight: 800; color: var(--text-main);">Pre-órdenes & Horarios</h4>
<span style="font-size: 0.74rem; color: var(--text-muted);">Horas de corte y políticas de cancelación</span>
</div>
</div>
<div>
<label style="font-size: 0.76rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; display: block; margin-bottom: 6px;">Hora de Corte General (HH:mm):</label>
<input type="time" id="cfg_preordenes_hora_corte" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.92rem; font-weight: 700; box-sizing: border-box;">
<span style="font-size: 0.72rem; color: var(--text-muted); display: block; margin-top: 4px;">Hora de cierre habitual para realizar pedidos del día siguiente.</span>
</div>
<div>
<label style="font-size: 0.76rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; display: block; margin-bottom: 6px;">Anticipación Mínima (Minutos):</label>
<input type="number" id="cfg_preordenes_anticipacion_minutos" min="5" max="240" step="5" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.92rem; font-weight: 700; box-sizing: border-box;">
<span style="font-size: 0.72rem; color: var(--text-muted); display: block; margin-top: 4px;">Minutos antes de cada recreo requeridos para preparar el pedido en cocina.</span>
</div>
<div style="padding: 12px 14px; background: var(--bg-main); border: 1.5px solid var(--border); border-radius: 12px;">
<div style="display: flex; justify-content: space-between; align-items: center;">
<div>
<span style="font-size: 0.85rem; font-weight: 800; color: var(--text-main); display: block;">Cancelación por Alumnos</span>
<span style="font-size: 0.73rem; color: var(--text-muted);">Si se apaga, solo los padres pueden cancelar órdenes</span>
</div>
<label class="switch-saas">
<input type="checkbox" id="cfg_preordenes_cancelacion_estudiantes">
<span class="switch-saas-slider round"></span>
</label>
</div>
</div>
</div>
<!-- CARD 4: CANALES DE ATENCIÓN Y SOPORTE -->
<div class="dev-card" style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 16px; padding: 20px; display: flex; flex-direction: column; gap: 16px;">
<div style="display: flex; align-items: center; gap: 10px; border-bottom: 1.5px solid var(--border); padding-bottom: 12px;">
<div style="width: 36px; height: 36px; border-radius: 10px; background: rgba(34, 197, 94, 0.15); color: #22c55e; display: flex; align-items: center; justify-content: center; font-size: 1.1rem;">
📞
</div>
<div>
<h4 style="margin: 0; font-size: 0.98rem; font-weight: 800; color: var(--text-main);">Atención & Soporte Técnico</h4>
<span style="font-size: 0.74rem; color: var(--text-muted);">Líneas directas oficiales de asistencia</span>
</div>
</div>
<div>
<label style="font-size: 0.76rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; display: block; margin-bottom: 6px;">WhatsApp Oficial de Soporte (con código país):</label>
<input type="text" id="cfg_soporte_whatsapp" placeholder="50688888888" oninput="actualizarPreviewWhatsapp(this.value)" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.92rem; font-weight: 700; box-sizing: border-box;">
<span style="font-size: 0.72rem; color: var(--text-muted); display: block; margin-top: 4px;">Al cambiarlo aquí, todos los enlaces y botones de ayuda en la app se redirigirán a este número.</span>
</div>
<div style="padding: 10px 12px; background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 10px; font-size: 0.76rem; color: #166534; line-height: 1.4;">
💡 <strong>Enlace en vivo generado:</strong> <span id="cfgWhatsappPreview" style="font-family: monospace; font-weight: 700;">https://wa.me/50688888888</span>
</div>
</div>
<!-- CARD 5: MODO MANTENIMIENTO / PAUSA OPERATIVA -->
<div class="dev-card" style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 16px; padding: 20px; display: flex; flex-direction: column; gap: 16px; grid-column: 1 / -1;">
<div style="display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; border-bottom: 1.5px solid var(--border); padding-bottom: 12px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 36px; height: 36px; border-radius: 10px; background: rgba(239, 68, 68, 0.15); color: #ef4444; display: flex; align-items: center; justify-content: center; font-size: 1.1rem;">
🛡️
</div>
<div>
<h4 style="margin: 0; font-size: 0.98rem; font-weight: 800; color: var(--text-main);">Pausa de Operaciones & Modo Mantenimiento</h4>
<span style="font-size: 0.74rem; color: var(--text-muted);">Pausa temporal de órdenes y aviso institucional a padres</span>
</div>
</div>
<div style="display: flex; align-items: center; gap: 10px;">
<span id="cfgMantenimientoStatusTag" style="padding: 4px 10px; border-radius: 8px; font-size: 0.75rem; font-weight: 800; background: #f1f5f9; color: #64748b;">Desactivado</span>
<label class="switch-saas">
<input type="checkbox" id="cfg_modo_mantenimiento" onchange="toggleMantenimientoUiState(this.checked)">
<span class="switch-saas-slider round rose"></span>
</label>
</div>
</div>
<div>
<label style="font-size: 0.76rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; display: block; margin-bottom: 6px;">Mensaje de Aviso al Usuario:</label>
<textarea id="cfg_modo_mantenimiento_mensaje" rows="2" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.88rem; line-height: 1.4; box-sizing: border-box;"></textarea>
<span style="font-size: 0.72rem; color: var(--text-muted); display: block; margin-top: 4px;">Este texto aparecerá en un banner flotante en la app de los padres y bloqueará la creación de pre-órdenes.</span>
</div>
</div>
</div>
</div>
</main>
</div>
</div>
<!-- PANEL DE ADMINISTRACIÓN DE LA SODA (#viewAdmin) -->
<div id="viewAdmin" class="admin-container" style="display: none;">
<!-- CABECERA DE ADMINISTRADOR -->
<header class="admin-header" style="display: flex; flex-direction: column; gap: 12px;">
<!-- FILA SUPERIOR: MARCA/TÍTULO A LA IZQUIERDA Y BOTÓN SALIR ÚNICO ARRIBITA A LA DERECHA -->
<div style="display: flex; justify-content: space-between; align-items: center; width: 100%; gap: 10px;">
<div class="admin-badge" style="display: flex; align-items: center; gap: 10px; min-width: 0;">
<div class="admin-icon" style="flex-shrink: 0;">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/></svg>
</div>
<div style="min-width: 0;">
<h2 style="font-size: 1.15rem; font-weight: 900; margin: 0; color: var(--text-main); line-height: 1.2;">Administración de la Soda</h2>
<span id="adminLoggedName" style="font-size: 0.76rem; color: #0284c7; font-weight: 700; display: block;">Soda Escolar Central</span>
</div>
</div>
<!-- ACCIONES SUPERIORES: TEMA Y BOTÓN SALIR ARRIBITA A LA DERECHA -->
<div style="display: flex; align-items: center; gap: 8px; flex-shrink: 0;">
<button onclick="toggleTheme()" class="btn-saas btn-saas-outline" style="width: 34px; height: 34px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 9px;" title="Alternar Modo Oscuro / Modo Claro">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/></svg>
</button>
<button onclick="logout(true)" class="btn-saas btn-saas-danger-subtle" style="height: 34px; font-size: 0.82rem; font-weight: 800; border-radius: 9px; padding: 0 14px; box-shadow: 0 1px 3px rgba(220, 38, 38, 0.08); display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;" title="Cerrar sesión y cambiar de cuenta">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.3" stroke-linecap="round" stroke-linejoin="round"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" y1="12" x2="9" y2="12"/></svg>
<span class="admin-btn-text">Salir</span>
</button>
</div>
</div>
<!-- FILA DE ACCIONES RÁPIDAS: DASHBOARD, RECARGAR SALDO, TERMINAL POS, PANEL DEV -->
<div class="admin-header-actions" style="display: flex; align-items: center; gap: 8px; flex-wrap: wrap; width: 100%;">
<button id="btnAdminDevPanel" onclick="switchAdminToDev()" class="btn-saas btn-saas-outline" style="display: none; border-color: #0284c7; color: #0284c7; height: 34px;" title="Volver al Panel Developer Master">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m18 16 4-4-4-4"/><path d="m6 8-4 4 4 4"/><path d="m14.5 4-5 16"/></svg>
<span class="admin-btn-text">Panel Dev</span>
</button>
<button onclick="switchAdminTab('dashboard')" class="btn-saas btn-saas-outline" style="height: 34px; border-color: #0284c7; color: #0284c7; font-weight: 800; background: rgba(2, 132, 199, 0.05);" title="Ver Dashboard Ejecutivo de Métricas y Finanzas">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><rect width="7" height="9" x="3" y="3" rx="1"/><rect width="7" height="5" x="14" y="3" rx="1"/><rect width="7" height="9" x="14" y="12" rx="1"/><rect width="7" height="5" x="3" y="16" rx="1"/></svg>
<span class="admin-btn-text">📊 Dashboard</span>
</button>
<button onclick="switchAdminTab('recarga')" class="btn-saas btn-saas-primary" style="height: 34px;" title="Recargar saldo a un estudiante">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="14" x="2" y="5" rx="2"/><line x1="2" x2="22" y1="10" y2="10"/></svg>
<span class="admin-btn-text">Recargar Saldo</span>
</button>
<a href="/pos.html" target="_blank" class="btn-saas btn-saas-outline" style="height: 34px;" title="Abrir Caja / Terminal POS">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="14" x="2" y="3" rx="2"/><line x1="8" x2="16" y1="21" y2="21"/><line x1="12" x2="12" y1="17" y2="21"/></svg>
<span class="admin-btn-text">Terminal POS</span>
</a>
</div>
</header>
<!-- MÉTRICAS DE HOY -->
<div class="admin-stats-grid">
<div class="admin-stat-card">
<div class="val" id="adminStatVentas">₡0</div>
<div class="lbl">Ventas Hoy</div>
</div>
<div class="admin-stat-card">
<div class="val" id="adminStatOrdenes">0</div>
<div class="lbl">Órdenes Despachadas</div>
</div>
<div class="admin-stat-card">
<div class="val" id="adminStatEstudiantes">0</div>
<div class="lbl">Estudiantes Activos</div>
</div>
<div class="admin-stat-card">
<div class="val" id="adminStatBloqueados" style="color: #ef4444;">0</div>
<div class="lbl">Tarjetas Bloqueadas</div>
</div>
<div class="admin-stat-card">
<div class="val" id="adminStatCriticos" style="color: #f59e0b;">0</div>
<div class="lbl">Bajo Stock / Agotados</div>
</div>
</div>
<!-- PESTAÑAS DE NAVEGACIÓN ADMIN -->
<div class="admin-tabs">
<button class="admin-tab-btn active" id="btnTabAdminDashboard" onclick="switchAdminTab('dashboard')" title="Dashboard Ejecutivo de Información">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="7" height="9" x="3" y="3" rx="1"/><rect width="7" height="5" x="14" y="3" rx="1"/><rect width="7" height="9" x="14" y="12" rx="1"/><rect width="7" height="5" x="3" y="16" rx="1"/></svg>
<span>Dashboard</span>
</button>
<button class="admin-tab-btn" id="btnTabAdminInventario" onclick="switchAdminTab('inventario')" title="Inventario y Stock de Productos">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m7.5 4.27 9 5.15"/><path d="M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z"/><path d="m3.3 7 8.7 5 8.7-5"/><path d="M12 22V12"/></svg>
<span>Inventario & Stock</span>
</button>
<button class="admin-tab-btn" id="btnTabAdminEstudiantes" onclick="switchAdminTab('estudiantes')" title="Gestión de Estudiantes, Carnés y Bloqueos">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M7 7h.01"/><path d="M11 7h6"/><path d="M7 11h.01"/><path d="M11 11h6"/><path d="M7 15h.01"/><path d="M11 15h6"/></svg>
<span>Estudiantes & Carnés</span>
</button>
<button class="admin-tab-btn" id="btnTabAdminPersonal" onclick="switchAdminTab('personal')" title="Personal y Cajeros de la Soda">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>
<span>Personal & Cajeros</span>
</button>
<button class="admin-tab-btn" id="btnTabAdminRecarga" onclick="switchAdminTab('recarga')" title="Recargas Bancarias SINPE Móvil">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="14" x="2" y="5" rx="2"/><line x1="2" x2="22" y1="10" y2="10"/></svg>
<span>Recargas SINPE</span>
<span id="badgeAdminTabSinpeCount" style="background: #10b981; color: white; padding: 2px 7px; border-radius: 10px; font-size: 0.70rem; font-weight: 800; display: none; margin-left: 5px;">0</span>
</button>
<button class="admin-tab-btn" id="btnTabAdminMovimientos" onclick="switchAdminTab('movimientos')" title="Movimientos de Caja y Reversiones">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M16 22h2a2 2 0 0 0 2-2V7.5L14.5 2H6a2 2 0 0 0-2 2v3"/><path d="m3 12.5 3 3 6-6"/></svg>
<span>Movimientos & Reversiones</span>
</button>
<button class="admin-tab-btn" id="btnTabAdminHorarios" onclick="switchAdminTab('horarios')" title="Horarios de Recreos y Almuerzos">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>
<span>Horarios & Recreos</span>
</button>
</div>
<!-- TAB 0: DASHBOARD EJECUTIVO -->
<div id="adminTabContentDashboard" class="admin-card">
<div class="admin-dash-container">
<!-- CABECERA DASHBOARD: TÍTULO Y SELECTORES DE PERÍODO -->
<div class="admin-dash-header">
<div>
<div style="display: flex; align-items: center; gap: 8px;">
<span style="font-size: 1.3rem;">📊</span>
<h3 style="margin: 0; font-size: 1.15rem; font-weight: 800; color: var(--text-main);">Dashboard Ejecutivo & Finanzas</h3>
</div>
<p style="margin: 3px 0 0 0; font-size: 0.78rem; color: var(--text-muted);">
Métricas financieras, saldos circulantes en monederos y análisis operativo en tiempo real.
</p>
</div>
<div style="display: flex; align-items: center; gap: 8px; flex-wrap: wrap;">
<div class="admin-dash-period-pills" id="adminDashPeriodPills">
<button type="button" class="admin-dash-pill-btn active" data-periodo="hoy" onclick="cambiarPeriodoDashboard('hoy')">Hoy</button>
<button type="button" class="admin-dash-pill-btn" data-periodo="7dias" onclick="cambiarPeriodoDashboard('7dias')">7 Días</button>
<button type="button" class="admin-dash-pill-btn" data-periodo="mes" onclick="cambiarPeriodoDashboard('mes')">Este Mes</button>
<button type="button" class="admin-dash-pill-btn" data-periodo="todo" onclick="cambiarPeriodoDashboard('todo')">Histórico</button>
</div>
<button type="button" onclick="cargarDashboardAdmin()" class="btn-saas btn-saas-outline" style="height: 32px; padding: 0 10px; font-size: 0.78rem;" title="Recargar datos del Dashboard">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"/><path d="M16 21h5v-5"/></svg>
<span>Actualizar</span>
</button>
</div>
</div>
<!-- BANNER DE ALERTAS OPERATIVAS (Oculto si no hay alertas) -->
<div id="adminDashAlertsContainer" style="display: none; flex-direction: column; gap: 8px;">
<!-- Dinámico -->
</div>
<!-- 4 TARJETAS KPI EJECUTIVAS -->
<div class="admin-dash-grid">
<!-- KPI 1: VENTAS TOTALES -->
<div class="admin-dash-kpi-card kpi-blue">
<div class="admin-dash-kpi-header">
<span class="admin-dash-kpi-title">Ventas Totales</span>
<div class="admin-dash-kpi-icon">💰</div>
</div>
<div class="admin-dash-kpi-val" id="dashKpiVentas">₡0</div>
<div class="admin-dash-kpi-meta">
<span>Órdenes cobradas: <strong id="dashKpiOrdenes" style="color: var(--text-main);">0</strong></span>
<span>Ticket promedio: <strong id="dashKpiTicketPromedio" style="color: #0284c7;">₡0</strong></span>
</div>
</div>
<!-- KPI 2: SALDO CIRCULANTE EN MONEDEROS -->
<div class="admin-dash-kpi-card kpi-green">
<div class="admin-dash-kpi-header">
<span class="admin-dash-kpi-title">Monederos Estudiantes</span>
<div class="admin-dash-kpi-icon">💳</div>
</div>
<div class="admin-dash-kpi-val" id="dashKpiSaldoCirculante">₡0</div>
<div class="admin-dash-kpi-meta">
<span>Disponible: <strong id="dashKpiSaldoDisponible" style="color: #10b981;">₡0</strong></span>
<span>Retenido preórdenes: <strong id="dashKpiSaldoRetenido" style="color: #f59e0b;">₡0</strong></span>
</div>
</div>
<!-- KPI 3: RECARGAS DEL PERÍODO -->
<div class="admin-dash-kpi-card kpi-purple">
<div class="admin-dash-kpi-header">
<span class="admin-dash-kpi-title">Recargas Ingresadas</span>
<div class="admin-dash-kpi-icon">📥</div>
</div>
<div class="admin-dash-kpi-val" id="dashKpiRecargas">₡0</div>
<div class="admin-dash-kpi-meta">
<span>SINPE Móvil: <strong id="dashKpiRecargasSinpe" style="color: #8b5cf6;">₡0</strong></span>
<span>Efectivo / Caja: <strong id="dashKpiRecargasEfectivo" style="color: var(--text-main);">₡0</strong></span>
</div>
</div>
<!-- KPI 4: DESPACHO Y PREÓRDENES -->
<div class="admin-dash-kpi-card kpi-amber">
<div class="admin-dash-kpi-header">
<span class="admin-dash-kpi-title">Canal de Venta</span>
<div class="admin-dash-kpi-icon">⏱️</div>
</div>
<div class="admin-dash-kpi-val" id="dashKpiCanalRatio">0% Pre-orden</div>
<div class="admin-dash-kpi-meta">
<span>Preórdenes: <strong id="dashKpiPreordenDetalle" style="color: var(--text-main);">₡0 (0 ord)</strong></span>
<span>Mostrador: <strong id="dashKpiMostradorDetalle" style="color: var(--text-main);">₡0 (0 ord)</strong></span>
</div>
</div>
</div>
<!-- SECCIÓN 2 COLUMNAS: MOMENTOS ESCOLARES Y TOP PRODUCTOS -->
<div class="admin-dash-split">
<!-- COLUMNA 1: VENTAS POR MOMENTO ESCOLAR -->
<div class="admin-dash-section">
<div class="admin-dash-section-title">
<span>🕒 Ventas por Momento Escolar</span>
<span style="font-size: 0.72rem; color: var(--text-muted); font-weight: 600;">Participación %</span>
</div>
<div id="adminDashMomentosList" style="display: flex; flex-direction: column; gap: 12px;">
<!-- Barras dinámicas de Primer Recreo, Almuerzo, Segundo Recreo, Mostrador -->
</div>
</div>
<!-- COLUMNA 2: TOP 5 PRODUCTOS MÁS VENDIDOS -->
<div class="admin-dash-section">
<div class="admin-dash-section-title">
<span>🏆 Top 5 Productos Más Vendidos</span>
<span style="font-size: 0.72rem; color: var(--text-muted); font-weight: 600;">Unidades & Total</span>
</div>
<div id="adminDashTopProductosList" style="display: flex; flex-direction: column; gap: 10px;">
<!-- Lista dinámica de Top Productos -->
</div>
</div>
</div>
<!-- SECCIÓN TENDENCIA SEMANAL: ÚLTIMOS 7 DÍAS -->
<div class="admin-dash-section">
<div class="admin-dash-section-title">
<span>📈 Tendencia Semanal de Ventas (Últimos 7 Días)</span>
<span style="font-size: 0.72rem; color: var(--text-muted); font-weight: 600;">Facturación diaria en ₡</span>
</div>
<div class="admin-dash-chart" id="adminDashChart7Dias">
<!-- 7 Columnas dinámicas -->
</div>
</div>
<!-- ACCIONES RÁPIDAS DE EXPORTACIÓN Y REPORTES -->
<div style="display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; padding-top: 10px; border-top: 1px solid var(--border, #e2e8f0);">
<button type="button" onclick="exportarVentasCsv()" class="btn-saas btn-saas-outline" style="height: 36px; border-color: #10b981; color: #166534; font-size: 0.82rem; font-weight: 800;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
<span>Descargar Ventas XLSX</span>
</button>
<button type="button" onclick="descargarReporteRecargasExcel(true)" class="btn-saas btn-saas-outline" style="height: 36px; border-color: #8b5cf6; color: #6d28d9; font-size: 0.82rem; font-weight: 800;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
<span>Descargar Recargas SINPE XLSX</span>
</button>
<button type="button" onclick="exportarEstudiantesCsv()" class="btn-saas btn-saas-outline" style="height: 36px; border-color: #0284c7; color: #0284c7; font-size: 0.82rem; font-weight: 800;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
<span>Descargar Saldos Alumnos XLSX</span>
</button>
</div>
</div>
</div>
<!-- TAB 1: INVENTARIO Y STOCK -->
<div id="adminTabContentInventario" class="admin-card" style="display: none;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px;">
<div>
<h3 style="margin: 0; font-size: 1.1rem; font-weight: 800; color: var(--text-main);">Inventario y Existencias</h3>
<p style="margin: 2px 0 0 0; font-size: 0.75rem; color: var(--text-muted);">
Crea, edita productos, controla precios, existencias y clasificación nutricional.
</p>
</div>
<div style="display: flex; gap: 8px; align-items: center; flex-wrap: wrap;">
<input type="text" id="adminSearchProduct" placeholder="Buscar alimento o bebida..." oninput="filterAdminProducts(this.value)" style="padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); font-size: 0.85rem; width: 190px; background: var(--card-bg); color: var(--text-main); outline: none;">
<button type="button" onclick="openCreateProductModal()" class="btn-saas btn-saas-primary" style="height: 36px; padding: 0 14px; font-size: 0.84rem;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14"/><path d="M12 5v14"/></svg>
<span>Nuevo Producto</span>
</button>
</div>
</div>
<div id="adminProductsList">
<!-- Renderizado dinámico de productos y stock -->
</div>
</div>
<!-- TAB 2: ESTUDIANTES Y CARNÉS -->
<div id="adminTabContentEstudiantes" class="admin-card" style="display: none;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px;">
<div>
<h3 style="margin: 0; font-size: 1.1rem; font-weight: 800; color: var(--text-main);">Alumnos y Tarjetas Escolares</h3>
<p style="margin: 2px 0 0 0; font-size: 0.75rem; color: var(--text-muted);">
Bloquea tarjetas perdidas, crea nuevos alumnos o genera carnés con código QR.
</p>
</div>
<div style="display: flex; gap: 8px; align-items: center; flex-wrap: wrap;">
<input type="text" id="adminSearchStudentsTab2" placeholder="Filtrar alumnos..." oninput="filterAdminStudentsTab2(this.value)" style="padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); font-size: 0.85rem; width: 190px; background: var(--card-bg); color: var(--text-main); outline: none;">
<button onclick="openNewStudentModal()" class="btn-saas btn-saas-primary" style="height: 36px; padding: 0 14px; font-size: 0.84rem;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14"/><path d="M12 5v14"/></svg>
<span>Nuevo Estudiante</span>
</button>
</div>
</div>
<div id="adminStudentsList">
<!-- Renderizado dinámico de estudiantes con botones de bloqueo -->
</div>
</div>
<!-- TAB 3: CARGA MANUAL DE DINERO Y APROBACIÓN SINPE -->
<div id="adminTabContentRecarga" class="admin-card" style="display: none; max-width: 820px; margin: 0 auto;">
<!-- SECCIÓN 1: SOLICITUDES SINPE PENDIENTES DE APROBACIÓN -->
<div id="adminSinpeRequestsBox" style="margin-bottom: 24px; background: #ffffff; border: 1.5px solid #86efac; border-radius: 16px; padding: 14px 14px; box-sizing: border-box; overflow: hidden; box-shadow: 0 2px 10px rgba(16, 185, 129, 0.08);">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 40px; height: 40px; border-radius: 12px; background: #ecfdf5; color: #10b981; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; border: 1.5px solid #a7f3d0; flex-shrink: 0;">
📱
</div>
<div>
<h4 style="margin: 0; font-size: 1.05rem; font-weight: 900; color: #0f172a; display: flex; align-items: center; gap: 8px;">
<span>Aprobar Recargas SINPE Móvil</span>
<span id="adminSinpeCountBadge" style="background: #10b981; color: white; font-size: 0.72rem; font-weight: 800; padding: 2px 8px; border-radius: 12px; display: none;">0</span>
</h4>
<p style="margin: 2px 0 0 0; font-size: 0.78rem; color: #64748b;">
Verifica las transferencias reportadas por los padres y acredita el saldo al instante.
</p>
</div>
</div>
<button type="button" onclick="loadAdminSinpeRequests()" class="btn-saas btn-saas-outline" style="height: 32px; padding: 0 12px; font-size: 0.78rem; font-weight: 700;">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="display: inline-block; vertical-align: middle; margin-right: 4px;"><path d="M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"/><path d="M21 3v5h-5"/><path d="M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"/><path d="M3 21v-5h5"/></svg>
<span>Refrescar</span>
</button>
</div>
<div id="adminSinpeRequestsList" style="display: flex; flex-direction: column; gap: 12px;">
<!-- Solicitudes SINPE pendientes cargadas dinámicamente -->
</div>
<!-- BARRA DE EXPORTACIÓN EXCEL DE RECARGAS SINPE -->
<div style="margin-top: 16px; padding: 14px; background: #f8fafc; border: 1.5px solid #e2e8f0; border-radius: 12px;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; flex-wrap: wrap; gap: 8px;">
<strong style="font-size: 0.86rem; color: #0f172a; display: flex; align-items: center; gap: 6px;">
<span>📊 Exportar Reporte de Recargas / Depósitos (Excel)</span>
</strong>
<button type="button" onclick="descargarReporteRecargasExcel(true)" class="btn-saas btn-saas-outline" style="height: 28px; padding: 0 10px; font-size: 0.74rem; font-weight: 700; color: #0284c7; border-color: #bae6fd; background: #f0f9ff;" title="Descargar todas las recargas registradas sin filtro">
⬇️ Todo el Historial
</button>
</div>
<div style="display: flex; gap: 8px; flex-wrap: wrap; align-items: center;">
<div style="display: flex; align-items: center; gap: 4px; font-size: 0.76rem; color: #64748b;">
<span>Desde:</span>
<input type="date" id="inputExportRecargasDesde" style="padding: 5px 8px; font-size: 0.78rem; border-radius: 6px; border: 1px solid #cbd5e1; outline: none; background: white;">
</div>
<div style="display: flex; align-items: center; gap: 4px; font-size: 0.76rem; color: #64748b;">
<span>Hasta:</span>
<input type="date" id="inputExportRecargasHasta" style="padding: 5px 8px; font-size: 0.78rem; border-radius: 6px; border: 1px solid #cbd5e1; outline: none; background: white;">
</div>
<select id="selectExportRecargasEstado" style="padding: 5px 8px; font-size: 0.78rem; border-radius: 6px; border: 1px solid #cbd5e1; outline: none; background: white;">
<option value="todos">Todos los Estados</option>
<option value="aprobado">Solo Aprobadas</option>
<option value="pendiente">Solo Pendientes</option>
<option value="rechazado">Solo Rechazadas</option>
</select>
<button type="button" onclick="descargarReporteRecargasExcel(false)" class="btn-saas btn-saas-primary" style="height: 32px; padding: 0 14px; font-size: 0.78rem; font-weight: 800; display: inline-flex; align-items: center; gap: 5px;">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
<span>Descargar Filtrado</span>
</button>
</div>
</div>
</div>
<!-- SEPARADOR CON RECARGA EN EFECTIVO -->
<div style="text-align: center; margin: 26px 0 20px 0; position: relative;">
<hr style="border: none; border-top: 1px solid #e2e8f0; margin: 0;">
<span style="position: absolute; top: -10px; left: 50%; transform: translateX(-50%); background: var(--card-bg, #ffffff); padding: 0 14px; font-size: 0.78rem; font-weight: 800; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.5px;">O Recarga Manual en Efectivo</span>
</div>
<div style="text-align: center; margin-bottom: 18px;">
<div style="width: 48px; height: 48px; border-radius: 12px; background: rgba(2, 132, 199, 0.1); color: #0284c7; display: flex; align-items: center; justify-content: center; margin: 0 auto 8px;">
<svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="14" x="2" y="5" rx="2"/><line x1="2" x2="22" y1="10" y2="10"/></svg>
</div>
<h3 style="margin: 6px 0 2px 0; font-size: 1.25rem; font-weight: 900; color: var(--text-main);">Carga Manual de Dinero</h3>
<p style="margin: 0; font-size: 0.78rem; color: var(--text-muted);">
Recarga de monedero estudiantil por pago en efectivo en la soda o ajuste escolar
</p>
</div>
<!-- BUSCADOR INTELIGENTE Y BOTÓN ESCANEAR QR -->
<div style="background: rgba(2, 132, 199, 0.05); border: 2px solid #0284c7; border-radius: 16px; padding: 14px; margin-bottom: 16px; box-shadow: 0 3px 12px rgba(2, 132, 199, 0.08);">
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; flex-wrap: wrap; gap: 6px;">
<label for="inputAdminSearchStudent" style="font-size: 0.88rem; font-weight: 900; color: var(--text-main); display: flex; align-items: center; gap: 6px; margin: 0;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="#0284c7" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg>
<span>Buscador Inteligente de Estudiante:</span>
</label>
<span style="font-size: 0.68rem; font-weight: 800; background: #0284c7; color: white; padding: 2px 8px; border-radius: 6px;">
⚡ Búsqueda en vivo
</span>
</div>
<div class="admin-search-container" style="position: relative;">
<div class="admin-search-input-wrap" style="display: flex; gap: 8px; align-items: center;">
<div style="position: relative; flex: 1; width: 100%;">
<input type="text" id="inputAdminSearchStudent" class="admin-search-input" placeholder="Escribe para buscar (ej: Mateo, EST-2026, Alvarado)..." oninput="onAdminSearchStudent(this.value)" onfocus="onAdminSearchFocus()" autocomplete="off" style="width: 100%; box-sizing: border-box; padding: 11px 36px 11px 14px; font-size: 0.95rem; font-weight: 700; border-radius: 12px; border: 2px solid #cbd5e1; outline: none; background: var(--card-bg, #ffffff); color: var(--text-main);">
<button type="button" id="btnClearAdminSearch" onclick="clearAdminSearchStudent()" style="display: none; position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: #e2e8f0; border: none; border-radius: 50%; width: 22px; height: 22px; font-size: 0.75rem; font-weight: 900; color: #475569; cursor: pointer; align-items: center; justify-content: center;" title="Borrar búsqueda">✕</button>
</div>
<button type="button" onclick="openAdminScanQrModal()" class="btn-saas btn-saas-primary" title="Escanear carné físico o código QR con la cámara" style="flex-shrink: 0; height: 42px; padding: 0 14px; font-size: 0.85rem; border-radius: 10px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M7 7h.01"/><path d="M17 7h.01"/><path d="M7 17h.01"/><path d="M17 17h.01"/></svg>
<span>Escanear QR</span>
</button>
</div>
<div id="adminSearchResultsDropdown" class="admin-search-dropdown" style="display: none;"></div>
</div>
<div style="font-size: 0.72rem; color: var(--text-muted); margin-top: 6px;">
<span style="display: inline-flex; align-items: center; gap: 4px;">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" x2="12" y1="16" y2="12"/><line x1="12" x2="12.01" y1="8" y2="8"/></svg>
<em>Toca el buscador para ver alumnos o escribe nombre, apellidos o carné para filtrar al instante.</em>
</span>
</div>
</div>
<!-- ESTADO 2: FICHA DEL ESTUDIANTE SELECCIONADO TRAS ESCANEO O BÚSQUEDA -->
<div id="adminSelectedStudentWrap" style="display: none; margin-bottom: 16px;">
<div style="margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center;">
<span style="font-size: 0.75rem; font-weight: 800; color: #166534; text-transform: uppercase; letter-spacing: 0.5px; display: flex; align-items: center; gap: 4px;">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#16a34a" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>
<span>Estudiante Seleccionado:</span>
</span>
<button type="button" onclick="clearAdminSelectedStudent()" style="background: none; border: none; color: #ef4444; font-size: 0.74rem; font-weight: 800; cursor: pointer; display: flex; align-items: center; gap: 3px;">
✕ Cambiar / Quitar
</button>
</div>
<div id="adminSelectedStudentBanner" class="selected-student-banner" style="display: flex;">
<div style="display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1;">
<div id="adminSelectedAvatar" class="admin-selected-avatar-badge">ES</div>
<div style="min-width: 0;">
<div style="display: flex; align-items: center; gap: 6px; flex-wrap: wrap;">
<strong id="adminSelectedName" style="font-size: 1rem; color: var(--text-main); word-break: break-word;">Selecciona un alumno</strong>
<span id="adminSelectedStatusBadge" style="font-size: 0.65rem; font-weight: 800; background: #dcfce7; color: #166534; padding: 2px 6px; border-radius: 4px;">ACTIVA</span>
</div>
<div id="adminSelectedMeta" style="font-size: 0.75rem; color: var(--text-muted); margin-top: 2px;">
Grado y Sección • Cód: EST-2026-000
</div>
</div>
</div>
<div style="text-align: right; flex-shrink: 0;">
<div style="font-size: 0.68rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase;">Saldo Actual</div>
<div id="adminSelectedBalance" style="font-size: 1.25rem; font-weight: 900; color: #10b981;">₡0</div>
</div>
</div>
</div>
<!-- SELECT OCULTO PARA COMPATIBILIDAD CON FUNCIONES JS -->
<select id="adminRecargaStudentSelect" style="display: none;" onchange="onAdminSelectChange(this.value)"></select>
<!-- SECCIÓN DE MONTO Y RECARGA (HABILITADA TRAS ESCANEO) -->
<div id="adminRecargaFormFields" style="opacity: 0.45; pointer-events: none; transition: all 0.25s ease;">
<div style="margin-bottom: 12px;">
<label style="display: block; font-size: 0.8rem; font-weight: 800; color: var(--text-main); margin-bottom: 5px;">
Monto a Recargar en Colones:
</label>
<div style="position: relative;">
<span style="position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-weight: 900; font-size: 1.1rem; color: #10b981;">₡</span>
<input type="tel" inputmode="numeric" pattern="[0-9]*" id="adminRecargaMonto" placeholder="Ej: 5000" style="width: 100%; padding: 11px 12px 11px 32px; border-radius: 10px; border: 2px solid #10b981; font-size: 1.15rem; font-weight: 900; color: var(--text-main); background: var(--card-bg); box-sizing: border-box;">
</div>
</div>
<div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 14px;">
<button type="button" onclick="setAdminRecargaPreset(1000)" class="btn-saas btn-saas-outline" style="height: 36px; font-weight: 800;">₡1.000</button>
<button type="button" onclick="setAdminRecargaPreset(2000)" class="btn-saas btn-saas-outline" style="height: 36px; font-weight: 800;">₡2.000</button>
<button type="button" onclick="setAdminRecargaPreset(5000)" class="btn-saas btn-saas-outline" style="height: 36px; font-weight: 800;">₡5.000</button>
<button type="button" onclick="setAdminRecargaPreset(10000)" class="btn-saas btn-saas-outline" style="height: 36px; font-weight: 800;">₡10.000</button>
</div>
<div style="margin-bottom: 16px;">
<label style="display: block; font-size: 0.78rem; font-weight: 700; color: var(--text-muted); margin-bottom: 4px;">
Detalle o Recibo (Opcional):
</label>
<input type="text" id="adminRecargaDescripcion" placeholder="Ej: Pago en efectivo en mostrador" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border); font-size: 0.85rem; box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
</div>
<button type="button" id="btnAdminSubmitRecarga" onclick="submitAdminManualRecharge()" class="btn-saas btn-saas-primary" style="width: 100%; height: 44px; font-size: 0.95rem; font-weight: 800; border-radius: 10px;">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="14" x="2" y="5" rx="2"/><line x1="2" x2="22" y1="10" y2="10"/></svg>
<span>Aplicar Recarga Inmediata</span>
</button>
</div>
</div>
<!-- TAB 4: MOVIMIENTOS Y REVERSIONES -->
<div id="adminTabContentMovimientos" class="admin-card" style="display: none; max-width: 900px; margin: 0 auto;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px;">
<div>
<h3 style="margin: 0; font-size: 1.2rem; font-weight: 900; color: var(--text-main); display: flex; align-items: center; gap: 8px;">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M16 22h2a2 2 0 0 0 2-2V7.5L14.5 2H6a2 2 0 0 0-2 2v3"/><path d="m3 12.5 3 3 6-6"/></svg>
<span>Movimientos & Reversiones</span>
</h3>
<p style="margin: 3px 0 0 0; font-size: 0.78rem; color: var(--text-muted);">
Historial de recargas de monedero y cobros de meriendas. Permite anular o revertir transacciones erróneas.
</p>
</div>
<button type="button" onclick="loadAdminMovimientos()" class="btn-saas btn-saas-outline" style="height: 32px;">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"/><path d="M21 3v5h-5"/><path d="M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"/><path d="M8 16H3v5"/></svg>
<span>Actualizar</span>
</button>
</div>
<!-- BARRA DE FILTROS Y BÚSQUEDA -->
<div style="display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; justify-content: space-between;">
<div style="display: flex; gap: 4px; background: rgba(148, 163, 184, 0.12); padding: 4px; border-radius: 10px; overflow-x: auto; max-width: 100%;">
<button type="button" class="mov-filter-btn active" id="btnFilterMovAll" onclick="setMovFilter('all')" style="padding: 6px 12px; border: none; border-radius: 7px; font-weight: 800; font-size: 0.78rem; cursor: pointer; background: white; color: #0284c7; box-shadow: 0 1px 3px rgba(0,0,0,0.08); white-space: nowrap;">
Todos
</button>
<button type="button" class="mov-filter-btn" id="btnFilterMovRecargas" onclick="setMovFilter('recargas')" style="padding: 6px 12px; border: none; border-radius: 7px; font-weight: 700; font-size: 0.78rem; cursor: pointer; background: transparent; color: #64748b; white-space: nowrap;">
Recargas
</button>
<button type="button" class="mov-filter-btn" id="btnFilterMovCobros" onclick="setMovFilter('cobros')" style="padding: 6px 12px; border: none; border-radius: 7px; font-weight: 700; font-size: 0.78rem; cursor: pointer; background: transparent; color: #64748b; white-space: nowrap;">
Cobros
</button>
<button type="button" class="mov-filter-btn" id="btnFilterMovRechazados" onclick="setMovFilter('rechazados')" style="padding: 6px 12px; border: none; border-radius: 7px; font-weight: 700; font-size: 0.78rem; cursor: pointer; background: transparent; color: #64748b; white-space: nowrap;">
Rechazados
</button>
</div>
<input type="text" id="inputSearchMovimientos" placeholder="Buscar por alumno, carné o detalle..." oninput="filterMovimientosUI(this.value)" style="flex: 1; min-width: 180px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); font-size: 0.85rem; box-sizing: border-box; background: var(--card-bg); color: var(--text-main); outline: none;">
</div>
<!-- LISTA DE MOVIMIENTOS -->
<div id="adminMovimientosList" style="display: flex; flex-direction: column; gap: 10px;">
<div style="text-align: center; color: var(--text-muted); padding: 30px; font-size: 0.88rem;">
Cargando movimientos...
</div>
</div>
</div>
<!-- TAB 5: GESTIÓN DE PERSONAL Y CAJEROS -->
<div id="adminTabContentPersonal" class="admin-card" style="display: none; max-width: 900px; margin: 0 auto;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px;">
<div>
<h3 style="margin: 0; font-size: 1.2rem; font-weight: 900; color: var(--text-main); display: flex; align-items: center; gap: 8px;">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>
<span>Control de Personal & Cajeros</span>
</h3>
<p style="margin: 3px 0 0 0; font-size: 0.78rem; color: var(--text-muted);">
Crea cajeros, vendedores y personal. Administra contraseñas, bloquea o elimina accesos.
</p>
</div>
<button type="button" onclick="openCreateStaffModal()" class="btn-saas btn-saas-primary" style="height: 36px; padding: 0 14px; font-size: 0.84rem;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><line x1="19" x2="19" y1="8" y2="14"/><line x1="22" x2="16" y1="11" y2="11"/></svg>
<span>Nuevo Empleado / Cajero</span>
</button>
</div>
<div id="adminStaffList" style="display: flex; flex-direction: column; gap: 10px;">
<div style="text-align: center; color: var(--text-muted); padding: 30px; font-size: 0.88rem;">
Cargando personal...
</div>
</div>
</div>
<!-- TAB 6: HORARIOS ESCOLARES (RECREOS Y ALMUERZO) -->
<div id="adminTabContentHorarios" class="admin-card" style="display: none; max-width: 780px; margin: 0 auto;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px;">
<div>
<h3 style="margin: 0; font-size: 1.15rem; font-weight: 900; color: var(--text-main);">
⏰ Horarios de Recreos y Almuerzo
</h3>
<p style="margin: 3px 0 0 0; font-size: 0.78rem; color: var(--text-muted);">
Configura los turnos específicos de tu escuela. Los pedidos anticipados de estudiantes y padres se agruparán bajo estos horarios.
</p>
</div>
</div>
<div style="background: var(--bg-main); border: 1.5px solid var(--border); border-radius: 14px; padding: 20px; display: flex; flex-direction: column; gap: 16px;">
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px;">
<!-- Primer Recreo -->
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 12px; padding: 14px; box-shadow: 0 1px 3px rgba(0,0,0,0.03);">
<div style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
<span style="font-size: 1.3rem;">🔔</span>
<div>
<strong style="display: block; font-size: 0.90rem; color: var(--text-main);">1er Recreo</strong>
<span style="font-size: 0.72rem; color: var(--text-muted);">Turno de la Mañana</span>
</div>
</div>
<label style="display: block; font-size: 0.74rem; font-weight: 700; color: var(--text-muted); margin-bottom: 5px;">Hora de Inicio:</label>
<input type="time" id="inputAdminHoraRecreo1" value="09:30" style="width: 100%; padding: 8px 12px; border-radius: 8px; border: 1.5px solid var(--border); font-size: 1.05rem; font-weight: 800; color: var(--text-main); background: var(--bg-main); outline: none; box-sizing: border-box;">
</div>
<!-- Almuerzo -->
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 12px; padding: 14px; box-shadow: 0 1px 3px rgba(0,0,0,0.03);">
<div style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
<span style="font-size: 1.3rem;">🍲</span>
<div>
<strong style="display: block; font-size: 0.90rem; color: var(--text-main);">Almuerzo</strong>
<span style="font-size: 0.72rem; color: var(--text-muted);">Comedor / Almuerzo</span>
</div>
</div>
<label style="display: block; font-size: 0.74rem; font-weight: 700; color: var(--text-muted); margin-bottom: 5px;">Hora de Inicio:</label>
<input type="time" id="inputAdminHoraAlmuerzo" value="11:45" style="width: 100%; padding: 8px 12px; border-radius: 8px; border: 1.5px solid var(--border); font-size: 1.05rem; font-weight: 800; color: var(--text-main); background: var(--bg-main); outline: none; box-sizing: border-box;">
</div>
<!-- Segundo Recreo -->
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 12px; padding: 14px; box-shadow: 0 1px 3px rgba(0,0,0,0.03);">
<div style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
<span style="font-size: 1.3rem;">⏰</span>
<div>
<strong style="display: block; font-size: 0.90rem; color: var(--text-main);">2do Recreo</strong>
<span style="font-size: 0.72rem; color: var(--text-muted);">Turno de la Tarde</span>
</div>
</div>
<label style="display: block; font-size: 0.74rem; font-weight: 700; color: var(--text-muted); margin-bottom: 5px;">Hora de Inicio:</label>
<input type="time" id="inputAdminHoraRecreo2" value="13:45" style="width: 100%; padding: 8px 12px; border-radius: 8px; border: 1.5px solid var(--border); font-size: 1.05rem; font-weight: 800; color: var(--text-main); background: var(--bg-main); outline: none; box-sizing: border-box;">
</div>
</div>
<div style="background: #e0f2fe; border: 1.5px solid #bae6fd; border-radius: 10px; padding: 12px 14px; font-size: 0.78rem; color: #0369a1; display: flex; align-items: center; gap: 10px;">
<span style="font-size: 1.2rem;">💡</span>
<span>Al presionar <strong>Guardar Horarios</strong>, los cambios se aplican automáticamente para padres y estudiantes en el selector de pedidos y para los cajeros en la terminal POS.</span>
</div>
<div style="display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px;">
<button type="button" onclick="guardarHorariosEscolares()" class="btn-saas btn-saas-primary" style="padding: 10px 24px; font-size: 0.88rem; font-weight: 800; display: inline-flex; align-items: center; gap: 6px; box-shadow: 0 2px 8px rgba(2, 132, 199, 0.35);">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg>
<span>Guardar Horarios</span>
</button>
</div>
</div>
</div>
</div>
<!-- ========================================== -->
<!-- PORTAL COMPLETO DE PADRES (#viewPadres) -->
<!-- ========================================== -->
<div id="viewPadres" class="parent-container" style="display: none;">
<!-- CABECERA DE PADRES -->
<header class="parent-header">
<div class="parent-badge">
<div class="parent-icon">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>
</div>
<div>
<h2 style="font-size: 1.15rem; font-weight: 900; margin: 0; color: var(--text-main);">Portal de Padres</h2>
<span id="parentLoggedName" style="font-size: 0.76rem; color: #10b981; font-weight: 700;">Familia SiboPay</span>
</div>
</div>
<div class="parent-header-actions">
<button onclick="toggleTheme()" class="theme-toggle-btn" title="Alternar Modo Oscuro / Modo Claro" style="display: inline-flex; align-items: center; justify-content: center;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/></svg>
</button>
<button type="button" onclick="switchToSodaMenuAsParent()" class="mode-btn" style="background: var(--bg-main); border: 1.5px solid var(--border); font-size: 0.78rem; font-weight: 800; border-radius: 10px; padding: 7px 11px; cursor: pointer; color: var(--text-main); display: inline-flex; align-items: center; gap: 6px;" title="Ver menú y pre-ordenar para mi hijo">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1-2.5-2.5Z"/></svg>
<span>Ver Menú</span>
</button>
<button type="button" onclick="abrirModalAjustesCuenta()" class="mode-btn" style="background: var(--bg-main); border: 1.5px solid var(--border); font-size: 0.78rem; font-weight: 800; border-radius: 10px; padding: 7px 11px; cursor: pointer; color: var(--text-main); display: inline-flex; align-items: center; gap: 6px;" title="Ajustes de Cuenta y Privacidad">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>
<span>Ajustes</span>
</button>
<button onclick="logout(true)" class="logout-btn" title="Cerrar sesión" style="display: inline-flex; align-items: center; gap: 6px;">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" x2="9" y1="12" y2="12"/></svg>
<span class="logout-text">Salir</span>
</button>
</div>
</header>
<!-- BANNER DE MODO MANTENIMIENTO EN PORTAL DE PADRES -->
<div id="parentMaintenanceBanner" style="display: none; background: #fff1f2; border: 1.5px solid #fecdd3; color: #9f1239; padding: 12px 16px; border-radius: 14px; margin-bottom: 16px; font-size: 0.84rem; align-items: center; gap: 10px; box-shadow: 0 4px 12px rgba(225, 29, 72, 0.08);">
<span style="font-size: 1.3rem;">🛡️</span>
<div style="flex: 1;">
<strong style="display: block; font-size: 0.86rem; color: #881337;">Aviso de Pausa Temporal</strong>
<span id="parentMaintenanceBannerText">Estamos realizando mejoras técnicas en el sistema. Los pedidos se reanudarán en breve.</span>
</div>
</div>
<!-- BANNER SI NO HAY HIJOS VINCULADOS -->
<div id="parentNoChildrenBanner" class="parent-card" style="display: none; text-align: center; border: 2px dashed #0284c7; background: #f0f9ff;">
<div style="width: 52px; height: 52px; border-radius: 50%; background: #e0f2fe; color: #0284c7; display: flex; align-items: center; justify-content: center; margin: 0 auto 10px;">
<svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>
</div>
<h3 style="font-size: 1.15rem; font-weight: 900; color: #0369a1; margin: 8px 0 4px 0;">¡Bienvenido a SiboPay!</h3>
<p style="font-size: 0.82rem; color: #64748b; margin-bottom: 14px;">
Aún no has vinculado ningún estudiante a tu cuenta de padre. Escanea el carné de tu hijo para monitorear su saldo y recargarle al instante.
</p>
<button type="button" onclick="openScanChildQrModal()" class="login-submit-btn" style="background: linear-gradient(135deg, #0284c7, #0369a1); display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: auto; padding: 12px 24px;">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M7 7h.01"/><path d="M17 7h.01"/><path d="M7 17h.01"/><path d="M17 17h.01"/></svg>
<span>Escanear Carné QR de mi Hijo</span>
</button>
</div>
<!-- SECCIÓN: MIS HIJOS (TARJETAS VISUALES) -->
<div id="parentChildrenSection" style="margin-bottom: 16px;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;">
<h3 style="font-size: 0.92rem; font-weight: 900; color: var(--text-main); text-transform: uppercase; letter-spacing: 0.5px; display: inline-flex; align-items: center; gap: 6px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>
<span>Mis Hijos</span>
</h3>
<button type="button" onclick="openScanChildQrModal()" style="background: none; border: none; color: #0284c7; font-size: 0.8rem; font-weight: 800; cursor: pointer; display: flex; align-items: center; gap: 4px;">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 5v14"/><path d="M5 12h14"/></svg>
<span>Vincular otro hijo con QR</span>
</button>
</div>
<!-- Cuadrícula de tarjetas de hijos -->
<div id="parentChildrenGrid" class="parent-children-grid">
<!-- Renderizado dinámico de tarjetas de hijos -->
</div>
</div>
<!-- SECCIÓN DE GESTIÓN DEL HIJO SELECCIONADO -->
<div id="parentSelectedChildContainer" style="display: none;">
<!-- TARJETA ELEGANTE DE SALDO Y RESUMEN DEL HIJO (BARRA SUPERIOR) -->
<div class="parent-balance-card-refined" style="margin-bottom: 16px;">
<div class="parent-balance-header-row">
<div style="display: flex; align-items: center; gap: 10px; min-width: 0;">
<div id="parentActiveChildAvatar" class="parent-active-child-avatar-badge">ES</div>
<div style="min-width: 0;">
<span class="parent-balance-tag-title">Estudiante Seleccionado</span>
<div style="display: flex; align-items: center; gap: 6px; margin-top: 2px; flex-wrap: wrap;">
<span id="parentActiveChildName" class="parent-balance-child-pill">Cargando...</span>
<span id="parentActiveChildMeta" class="parent-balance-grade-pill">Grado • Carné</span>
<span id="parentActiveSchoolNameBadge" style="font-size: 0.72rem; color: #0284c7; font-weight: 800; background: #f0f9ff; padding: 2px 7px; border-radius: 6px;">Soda Central</span>
</div>
</div>
</div>
<div style="display: flex; align-items: center; gap: 8px;">
<button type="button" onclick="openParentSubView('preordenes')" class="btn-saas btn-saas-outline" style="font-size: 0.78rem; font-weight: 800; border-radius: 10px; padding: 7px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px;">
<span>🥪 Ver Menú</span>
</button>
</div>
</div>
<div class="parent-balance-amount-display">
<span id="parentActiveChildBalance">₡0</span>
</div>
<div id="parentActiveChildRetenidoNote" style="display: none; font-size: 0.74rem; color: #b45309; background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; padding: 4px 10px; margin-top: 4px; font-weight: 700;"></div>
<div class="parent-balance-footer-row">
<div class="parent-balance-limit-info">
Límite Diario: <strong id="parentDailyLimitInlineDisplay" style="color: #0284c7;">₡3.000</strong>
</div>
<button type="button" onclick="openParentSubView('sinpe')" class="parent-balance-btn-recharge">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
<span>Recargar Saldo con SINPE</span>
</button>
</div>
</div>
<!-- LAYOUT DIVIDIDO A IZQUIERDA Y DERECHA (ESTILO GMAIL) -->
<div class="parent-split-wrapper">
<!-- COLUMNA IZQUIERDA: MENÚ DE CAJITAS (SIDEBAR) -->
<aside class="parent-sidebar-boxes" id="parentSidebarBoxes">
<div class="parent-nav-box active" data-view="resumen" onclick="openParentSubView('resumen')">
<div class="parent-nav-box-icon">📊</div>
<div class="parent-nav-box-text">
<strong>Resumen General</strong>
<span>Saldo y estado del carné</span>
</div>
<span class="parent-nav-arrow">›</span>
</div>
<div class="parent-nav-box" data-view="preordenes" onclick="openParentSubView('preordenes')">
<div class="parent-nav-box-icon">🥪</div>
<div class="parent-nav-box-text">
<strong>Pre-ordenar / Ver Menú</strong>
<span>Catálogo y pedidos de merienda</span>
</div>
<span class="parent-nav-arrow">›</span>
</div>
<div class="parent-nav-box" data-view="alergias" onclick="openParentSubView('alergias')">
<div class="parent-nav-box-icon rose-halo">⚠️</div>
<div class="parent-nav-box-text">
<strong style="color: #e11d48;">Alertas y Salud</strong>
<span>Alergias y veto de golosinas</span>
</div>
<span class="parent-nav-arrow" style="color: #f43f5e;">›</span>
</div>
<div class="parent-nav-box" data-view="limites" onclick="openParentSubView('limites')">
<div class="parent-nav-box-icon">💳</div>
<div class="parent-nav-box-text">
<strong>Límite Diario de Gasto</strong>
<span>Control y transferencias</span>
</div>
<span class="parent-nav-arrow">›</span>
</div>
<div class="parent-nav-box" data-view="historial" onclick="openParentSubView('historial')">
<div class="parent-nav-box-icon">📜</div>
<div class="parent-nav-box-text">
<strong>Historial de Compras</strong>
<span>Consumos en la soda</span>
</div>
<span class="parent-nav-arrow">›</span>
</div>
<div class="parent-nav-box" data-view="credenciales" onclick="openParentSubView('credenciales')">
<div class="parent-nav-box-icon">🔒</div>
<div class="parent-nav-box-text">
<strong>Seguridad y PIN</strong>
<span>Huella / Face ID y contraseñas</span>
</div>
<span class="parent-nav-arrow">›</span>
</div>
<div class="parent-nav-box" data-view="sinpe" onclick="openParentSubView('sinpe')">
<div class="parent-nav-box-icon green-halo">💸</div>
<div class="parent-nav-box-text">
<strong style="color: #166534;">Recargar con SINPE</strong>
<span>Validar recarga bancaria</span>
</div>
<span class="parent-nav-arrow" style="color: #16a34a;">›</span>
</div>
<div class="parent-nav-box" data-view="dashboard" onclick="openParentSubView('dashboard')">
<div class="parent-nav-box-icon" style="background: rgba(2, 132, 199, 0.12); color: #0284c7;">📊</div>
<div class="parent-nav-box-text">
<strong style="color: #0284c7;">Dashboard Ejecutivo</strong>
<span>Saldos, compras y recargas</span>
</div>
<span class="parent-nav-arrow" style="color: #0284c7;">›</span>
</div>
</aside>
<!-- COLUMNA DERECHA: ESCENARIO DE CONTENIDO ACTIVO -->
<main class="parent-content-stage" id="parentContentStage">
<!-- SUBVISTA 0: RESUMEN GENERAL DEL ESTUDIANTE -->
<div id="parentSubViewResumen" class="parent-subview">
<div class="parent-subview-header">
<button type="button" onclick="closeParentSubView()" class="parent-subview-back-btn">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>
<span>Volver</span>
</button>
<div class="parent-subview-child-tag">
<span class="parentSubViewChildAvatarBadge">ES</span>
<span class="parentSubViewChildName">Estudiante</span>
</div>
</div>
<div class="parent-card" style="background: var(--card-bg, #ffffff); border: 1px solid var(--border, #e2e8f0); border-radius: 18px; padding: 22px; margin-bottom: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.03);">
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 10px;">
<div style="display: flex; align-items: center; gap: 12px;">
<div class="parent-refined-icon-box" style="width: 44px; height: 44px; background: rgba(2, 132, 199, 0.1); color: #0284c7; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.25rem;">
📊
</div>
<div>
<h3 style="font-size: 1.1rem; font-weight: 900; color: var(--text-main); margin: 0;">Panel Principal del Estudiante</h3>
<span style="font-size: 0.76rem; color: var(--text-muted);">Monitoreo escolar en tiempo real de <strong id="parentSummaryChildName" style="color: #0284c7;">su hijo</strong></span>
</div>
</div>
<div class="parent-subview-child-tag" style="margin: 0;">
<span class="parentSubViewChildAvatarBadge">ES</span>
<span class="parentSubViewChildName">Estudiante</span>
</div>
</div>
<!-- Grid de métricas rápidas del estudiante -->
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 18px;">
<div style="background: var(--bg-main, #f8fafc); border: 1px solid var(--border, #e2e8f0); border-radius: 14px; padding: 14px;">
<span style="font-size: 0.72rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase;">Saldo Disponible</span>
<div id="parentSummaryBalanceDisplay" style="font-size: 1.6rem; font-weight: 900; color: #0284c7; margin-top: 4px;">₡0</div>
<span id="parentSummaryRetenidoSubtitle" style="font-size: 0.68rem; color: #10b981; font-weight: 700;">● Disponible para compras</span>
</div>
<div style="background: var(--bg-main, #f8fafc); border: 1px solid var(--border, #e2e8f0); border-radius: 14px; padding: 14px;">
<span style="font-size: 0.72rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase;">Límite por Día</span>
<div id="parentSummaryLimitDisplay" style="font-size: 1.6rem; font-weight: 900; color: var(--text-main); margin-top: 4px;">₡3.000</div>
<span style="font-size: 0.68rem; color: var(--text-muted); font-weight: 700;">Tope de consumo diario</span>
</div>
<div style="background: var(--bg-main, #f8fafc); border: 1px solid var(--border, #e2e8f0); border-radius: 14px; padding: 14px;">
<span style="font-size: 0.72rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase;">Salud & Veto</span>
<div id="parentSummaryAllergyStatus" style="font-size: 1.1rem; font-weight: 900; color: #10b981; margin-top: 8px;">Sin alertas</div>
<span style="font-size: 0.68rem; color: var(--text-muted); font-weight: 700;">Expediente activo en caja</span>
</div>
</div>
<!-- WIDGET DE ÓRDENES ACTIVAS DEL HIJO -->
<div id="parentSummaryActiveOrdersSection" style="display: none; background: #f0f9ff; border: 1.5px solid #bae6fd; border-radius: 16px; padding: 16px; margin-bottom: 18px; box-shadow: 0 2px 8px rgba(2, 132, 199, 0.06);">
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; border-bottom: 1px dashed #bae6fd; padding-bottom: 8px;">
<div style="display: flex; align-items: center; gap: 8px;">
<span style="font-size: 1.2rem;">🥪</span>
<div>
<strong style="font-size: 0.88rem; color: #0369a1; display: block; font-weight: 800;">Pedidos Activos de tu Hijo</strong>
<span style="font-size: 0.7rem; color: #0284c7;">Pre-órdenes en curso en la soda</span>
</div>
</div>
<span id="parentSummaryActiveCountBadge" style="background: #0284c7; color: white; border-radius: 20px; padding: 2px 9px; font-size: 0.72rem; font-weight: 800;">0 activos</span>
</div>
<div id="parentSummaryActiveOrdersList" style="display: flex; flex-direction: column; gap: 10px;">
<!-- Inyectado dinámicamente -->
</div>
</div>
<!-- Atajos Rápidos -->
<h4 style="font-size: 0.85rem; font-weight: 900; color: var(--text-main); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 10px;">Acciones Rápidas</h4>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px;">
<button type="button" onclick="openParentSubView('preordenes')" class="btn-saas btn-saas-outline" style="padding: 12px 14px; border-radius: 12px; display: flex; align-items: center; gap: 10px; justify-content: flex-start; text-align: left;">
<span style="font-size: 1.3rem;">🥪</span>
<div>
<strong style="display: block; font-size: 0.84rem; color: var(--text-main);">Pre-ordenar Merienda</strong>
<span style="font-size: 0.7rem; color: var(--text-muted);">Ver platillos de la soda</span>
</div>
</button>
<button type="button" onclick="openParentSubView('sinpe')" class="btn-saas btn-saas-outline" style="padding: 12px 14px; border-radius: 12px; display: flex; align-items: center; gap: 10px; justify-content: flex-start; text-align: left; border-color: #86efac; background: #f0fdf4;">
<span style="font-size: 1.3rem;">💸</span>
<div>
<strong style="display: block; font-size: 0.84rem; color: #166534;">Recargar por SINPE</strong>
<span style="font-size: 0.7rem; color: #15803d;">Acreditar saldo al instante</span>
</div>
</button>
<button type="button" onclick="openParentSubView('historial')" class="btn-saas btn-saas-outline" style="padding: 12px 14px; border-radius: 12px; display: flex; align-items: center; gap: 10px; justify-content: flex-start; text-align: left;">
<span style="font-size: 1.3rem;">📜</span>
<div>
<strong style="display: block; font-size: 0.84rem; color: var(--text-main);">Ver Compras Recientes</strong>
<span style="font-size: 0.7rem; color: var(--text-muted);">Auditar consumos en caja</span>
</div>
</button>
<button type="button" onclick="openParentSubView('credenciales')" class="btn-saas btn-saas-outline" style="padding: 12px 14px; border-radius: 12px; display: flex; align-items: center; gap: 10px; justify-content: flex-start; text-align: left; border-color: #86efac; background: #f0fdf4;">
<span style="font-size: 1.3rem;">🛡️</span>
<div>
<strong style="display: block; font-size: 0.84rem; color: #166534;">Seguridad del Carné QR</strong>
<span style="font-size: 0.7rem; color: #15803d;">Huella, Face ID y PIN</span>
</div>
</button>
</div>
</div>
</div>
<!-- SUBVISTA: PRE-ORDENAR MERIENDA Y VER CATÁLOGO -->
<div id="parentSubViewMenu" class="parent-subview" style="display: none;">
<div class="parent-subview-header">
<button type="button" onclick="closeParentSubView()" class="parent-subview-back-btn">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>
<span>Volver</span>
</button>
<div class="parent-subview-child-tag">
<span class="parentSubViewChildAvatarBadge">ES</span>
<span class="parentSubViewChildName">Estudiante</span>
</div>
</div>
<div class="parent-card" style="background: var(--card-bg, #ffffff); border: 1px solid var(--border, #e2e8f0); border-radius: 18px; padding: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.03);">
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 8px;">
<div>
<h3 style="font-size: 1.1rem; font-weight: 900; color: var(--text-main); margin: 0; display: flex; align-items: center; gap: 8px;">
<span>🥪 Menú de la Soda y Pre-órdenes</span>
</h3>
<span style="font-size: 0.76rem; color: var(--text-muted);">Selecciona los alimentos para la merienda escolar de tu hijo</span>
</div>
<button type="button" onclick="openCartModal()" class="btn-saas btn-saas-primary" style="padding: 8px 16px; border-radius: 10px; font-size: 0.82rem; display: inline-flex; align-items: center; gap: 6px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2"><path d="M6 2L3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4z"/><line x1="3" y1="6" x2="21" y2="6"/><path d="M16 10a4 4 0 0 1-8 0"/></svg>
<span>Ver Mi Orden</span>
<span id="parentCartBadgeCount" style="background: #ffffff; color: #0284c7; padding: 1px 7px; border-radius: 10px; font-weight: 900; font-size: 0.72rem; margin-left: 2px;">0</span>
</button>
</div>
<!-- Buscador inteligente en catálogo de padres -->
<div style="margin-bottom: 14px;">
<div style="position: relative;">
<input type="text" id="parentCatalogSearch" placeholder="Buscar platillo, fresco, snack o precio (<1000)..." oninput="filterParentCatalog(this.value)" style="width: 100%; box-sizing: border-box; padding: 11px 12px 11px 36px; border-radius: 12px; border: 1.5px solid var(--border, #cbd5e1); font-size: 0.88rem; font-weight: 600; outline: none; background: var(--bg-main, #f8fafc); color: var(--text-main);">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#94a3b8" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="position: absolute; left: 11px; top: 50%; transform: translateY(-50%); pointer-events: none;">
<circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/>
</svg>
</div>
<div style="display: flex; gap: 6px; overflow-x: auto; padding-top: 8px; scrollbar-width: none;">
<button type="button" class="search-chip" onclick="quickFilterParentCatalog('fresco')">🥤 Frescos</button>
<button type="button" class="search-chip" onclick="quickFilterParentCatalog('almuerzo')">🍛 Almuerzos</button>
<button type="button" class="search-chip" onclick="quickFilterParentCatalog('saludable')">🥗 Saludables</button>
<button type="button" class="search-chip" onclick="quickFilterParentCatalog('<1000')">💰 < ₡1.000</button>
<button type="button" class="search-chip" onclick="quickFilterParentCatalog('')">✨ Todos</button>
</div>
</div>
<!-- Grid de productos en portal de padres -->
<div id="parentProductsGrid" class="parent-products-grid" style="display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px;">
<!-- Se llena dinámicamente con renderParentCatalog() -->
</div>
</div>
</div>
<!-- 1. SUB-PANTALLA: RECARGA SINPE MÓVIL -->
<div id="parentSubViewSinpe" class="parent-subview" style="display: none;">
<div class="parent-subview-header">
<button type="button" onclick="closeParentSubView()" class="parent-subview-back-btn">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>
<span>Volver</span>
</button>
<div class="parent-subview-child-tag">
<span class="parentSubViewChildAvatarBadge">ES</span>
<span class="parentSubViewChildName">Estudiante</span>
</div>
</div>
<div class="parent-sinpe-desktop-grid">
<!-- Columna 1: Formulario de Recarga SINPE -->
<div class="parent-card parent-sinpe-form-card" style="background: #f0fdf4; border: 1.5px solid #86efac; margin-bottom: 0;">
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 36px; height: 36px; border-radius: 10px; background: #dcfce7; color: #166534; display: flex; align-items: center; justify-content: center; flex-shrink: 0;">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="20" x="5" y="2" rx="2" ry="2"/><line x1="12" x2="12.01" y1="18" y2="18"/></svg>
</div>
<div>
<strong style="color: #166534; font-size: 1rem; display: block;">Recarga por SINPE Móvil</strong>
<p style="font-size: 0.74rem; color: #15803d; margin: 0;">
<span id="parentSinpeEscuelaNombre" style="font-weight: 800;">Soda Escolar</span> · Tel: <strong id="parentSinpeNumero">8888-8888</strong>
</p>
<p style="font-size: 0.70rem; color: #166534; margin: 2px 0 0 0;">
Titular: <span id="parentSinpeTitular" style="font-weight: 700;">Soda Central</span>
</p>
</div>
</div>
<span style="font-size: 0.7rem; color: #166534; background: #dcfce7; font-weight: 800; padding: 3px 8px; border-radius: 6px;">Inmediato</span>
</div>
<!-- 1. Monto a Recargar -->
<div style="margin-bottom: 12px;">
<label for="inputParentSinpeMonto" style="display: block; font-size: 0.80rem; font-weight: 800; color: #166534; margin-bottom: 4px;">
1. Monto a recargar (₡):
</label>
<div style="position: relative;">
<span style="position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-weight: 900; color: #166534; font-size: 1.1rem;">₡</span>
<input type="tel" inputmode="numeric" pattern="[0-9]*" id="inputParentSinpeMonto" placeholder="Ej: 3000" style="width: 100%; padding: 10px 12px 10px 30px; border-radius: 10px; border: 1.8px solid #86efac; font-size: 1.1rem; font-weight: 800; color: #166534; background: white; box-sizing: border-box; outline: none;">
</div>
<!-- Montos sugeridos rápidos -->
<div id="parentSinpePresetsContainer" style="display: flex; gap: 6px; margin-top: 7px; flex-wrap: wrap;">
<button type="button" onclick="setParentSinpeMonto(1000)" style="background: white; border: 1px solid #86efac; color: #166534; font-size: 0.74rem; font-weight: 700; padding: 4px 9px; border-radius: 8px; cursor: pointer;">₡1.000</button>
<button type="button" onclick="setParentSinpeMonto(2000)" style="background: white; border: 1px solid #86efac; color: #166534; font-size: 0.74rem; font-weight: 700; padding: 4px 9px; border-radius: 8px; cursor: pointer;">₡2.000</button>
<button type="button" onclick="setParentSinpeMonto(3000)" style="background: white; border: 1px solid #86efac; color: #166534; font-size: 0.74rem; font-weight: 700; padding: 4px 9px; border-radius: 8px; cursor: pointer;">₡3.000</button>
<button type="button" onclick="setParentSinpeMonto(5000)" style="background: white; border: 1px solid #86efac; color: #166534; font-size: 0.74rem; font-weight: 700; padding: 4px 9px; border-radius: 8px; cursor: pointer;">₡5.000</button>
<button type="button" onclick="setParentSinpeMonto(10000)" style="background: white; border: 1px solid #86efac; color: #166534; font-size: 0.74rem; font-weight: 700; padding: 4px 9px; border-radius: 8px; cursor: pointer;">₡10.000</button>
</div>
</div>
<!-- 2. Caja de Código de Detalle Obligatorio -->
<div style="background: #ffffff; border: 2px dashed #16a34a; border-radius: 12px; padding: 12px; margin-bottom: 12px; text-align: center; box-shadow: 0 2px 6px rgba(22, 163, 74, 0.06);">
<div style="font-size: 0.74rem; font-weight: 800; color: #15803d; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 3px;">
2. Código Obligatorio en el Detalle
</div>
<p style="font-size: 0.72rem; color: #475569; margin: 0 0 8px 0; line-height: 1.3;">
En la app de tu banco, coloca este código en el campo <strong>"Detalle"</strong> o <strong>"Motivo"</strong>:
</p>
<div style="display: flex; align-items: center; justify-content: center; gap: 8px; background: #f0fdf4; border: 1.5px solid #86efac; border-radius: 10px; padding: 8px 12px; margin-bottom: 6px;">
<span id="parentSinpeCodigoDisplay" style="font-family: 'Courier New', Courier, monospace; font-size: 1.45rem; font-weight: 900; color: #166534; letter-spacing: 1.5px; user-select: all;">SIBO-CARGANDO</span>
<button type="button" id="btnCopiarCodigoSinpe" onclick="copiarCodigoSinpe()" style="background: #16a34a; color: white; border: none; padding: 7px 12px; border-radius: 8px; font-weight: 800; font-size: 0.80rem; cursor: pointer; display: flex; align-items: center; gap: 4px; box-shadow: 0 2px 5px rgba(22, 163, 74, 0.25);">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>
<span id="lblCopiarCodigoSinpe">Copiar código</span>
</button>
</div>
<div style="display: flex; justify-content: space-between; align-items: center; font-size: 0.68rem; color: #64748b; padding: 0 2px;">
<span>Válido pegado, con guión o minúsculas.</span>
<button type="button" onclick="obtenerNuevoCodigoSinpe()" style="background: none; border: none; color: #0284c7; font-weight: 700; cursor: pointer; text-decoration: underline; font-size: 0.68rem; padding: 0;">
🔄 Cambiar código
</button>
</div>
</div>
<!-- 3. Comprobante Opcional -->
<div style="margin-bottom: 12px;">
<label for="inputParentSinpeComprobante" style="display: block; font-size: 0.76rem; font-weight: 800; color: #166534; margin-bottom: 3px;">
3. N° de Comprobante bancario <span style="font-size: 0.68rem; font-weight: 600; color: #64748b;">(Opcional)</span>:
</label>
<input type="text" id="inputParentSinpeComprobante" placeholder="Ej: 894321 (Opcional si pusiste el código en el detalle)" style="width: 100%; padding: 9px 11px; border-radius: 10px; border: 1.5px solid #86efac; font-size: 0.95rem; font-weight: 700; color: #166534; background: white; box-sizing: border-box;">
</div>
<!-- Botón de Validar SINPE -->
<button type="button" id="btnParentValidarSinpe" onclick="executeParentSinpeRecharge()" style="width: 100%; padding: 13px; background: linear-gradient(135deg, #16a34a, #15803d); color: white; border: none; border-radius: 12px; font-weight: 900; font-size: 0.98rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 4px 10px rgba(22, 163, 74, 0.3);">
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.3" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>
<span id="btnParentValidarSinpeText">Validar SINPE</span>
</button>
<!-- Enlace a Términos y Condiciones SINPE -->
<div style="text-align: center; margin-top: 10px; font-size: 0.72rem; color: #64748b; line-height: 1.45;">
<span>Al hacer pagos por SINPE acepta los </span>
<button type="button" onclick="openModalSinpeTerms()" style="background: none; border: none; padding: 0; color: #0284c7; font-weight: 800; font-size: 0.72rem; cursor: pointer; text-decoration: underline; display: inline;">
términos de pago con SINPE móvil
</button>
</div>
<!-- Banner de estado dinámico -->
<div id="parentSinpeStatusMsg" style="display: none; margin-top: 10px; padding: 10px 12px; border-radius: 10px; font-size: 0.80rem; line-height: 1.4;"></div>
<!-- LISTA DE SOLICITUDES SINPE PENDIENTES DEL HIJO -->
<div id="parentSinpePendingBox" style="margin-top: 14px; border-top: 1px dashed #86efac; padding-top: 10px; display: none;">
<div style="font-size: 0.76rem; font-weight: 800; color: #166534; margin-bottom: 6px;">Estado de Recargas Recientes:</div>
<div id="parentSinpePendingList" style="display: flex; flex-direction: column; gap: 6px;"></div>
</div>
</div>
<!-- Columna 2: Términos, Condiciones y Guía de Seguridad SINPE -->
<div class="parent-card parent-sinpe-terms-card" style="background: #ffffff; border: 1.5px solid var(--border, #cbd5e1); border-radius: 18px; padding: 22px; box-shadow: 0 2px 8px rgba(0,0,0,0.03); margin-bottom: 0;">
<!-- Encabezado de la Guía -->
<div style="display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border, #f1f5f9); padding-bottom: 12px; margin-bottom: 14px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 36px; height: 36px; border-radius: 10px; background: #e0f2fe; color: #0284c7; display: flex; align-items: center; justify-content: center; font-size: 1.15rem; flex-shrink: 0;">
🛡️
</div>
<div>
<strong style="color: var(--text-main, #0f172a); font-size: 0.96rem; display: block;">Términos y Guía SINPE Móvil</strong>
<span style="font-size: 0.73rem; color: var(--text-muted, #64748b);">Reglas para acreditación automática</span>
</div>
</div>
<span style="font-size: 0.68rem; font-weight: 800; background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; padding: 3px 8px; border-radius: 6px;">
Oficial
</span>
</div>
<!-- Alerta Dorada: Coincidencia Exacta -->
<div style="background: #fffbeb; border: 1.5px solid #fde68a; border-radius: 12px; padding: 12px; margin-bottom: 14px;">
<div style="display: flex; align-items: flex-start; gap: 8px;">
<span style="font-size: 1.15rem; line-height: 1;">⚠️</span>
<div style="font-size: 0.77rem; color: #92400e; line-height: 1.45;">
<strong style="display: block; font-size: 0.82rem; margin-bottom: 2px;">Atención a dos datos obligatorios:</strong>
El <strong>monto</strong> y el <strong>código SIBO</strong> deben coincidir con total precisión para que el sistema de la soda apruebe el saldo en segundos.
</div>
</div>
</div>
<!-- Lista de Términos Numerados -->
<div style="display: flex; flex-direction: column; gap: 13px; font-size: 0.78rem; color: var(--text-main, #334155); line-height: 1.45;">
<!-- 1. Monto Exacto -->
<div style="display: flex; gap: 10px; align-items: flex-start;">
<div style="width: 22px; height: 22px; border-radius: 50%; background: #dcfce7; color: #166534; font-weight: 900; font-size: 0.72rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px;">
1
</div>
<div>
<strong style="color: var(--text-main, #0f172a); display: block; font-size: 0.82rem;">Monto idéntico al transferido:</strong>
<span>El monto elegido en esta pantalla debe ser <strong>exactamente igual</strong> al transferido desde su banco (ej: si transfirió ₡3.000, digite ₡3.000). Diferencias en el importe impiden la conciliación automática.</span>
</div>
</div>
<!-- 2. Código Obligatorio -->
<div style="display: flex; gap: 10px; align-items: flex-start;">
<div style="width: 22px; height: 22px; border-radius: 50%; background: #dcfce7; color: #166534; font-weight: 900; font-size: 0.72rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px;">
2
</div>
<div>
<strong style="color: var(--text-main, #0f172a); display: block; font-size: 0.82rem;">Copiar y pegar el código en el Detalle:</strong>
<span>Es <strong>estrictamente obligatorio</strong> colocar el código que empieza con <code style="background: rgba(2, 132, 199, 0.08); color: #0284c7; padding: 1px 6px; border-radius: 4px; font-weight: 800; font-family: monospace;">SIBO-XXXXXX</code> en la casilla de <em>Detalle</em>, <em>Motivo</em> o <em>Concepto</em> del SINPE Móvil bancario.</span>
</div>
</div>
<!-- 3. Destinatario Oficial -->
<div style="display: flex; gap: 10px; align-items: flex-start;">
<div style="width: 22px; height: 22px; border-radius: 50%; background: #dcfce7; color: #166534; font-weight: 900; font-size: 0.72rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px;">
3
</div>
<div>
<strong style="color: var(--text-main, #0f172a); display: block; font-size: 0.82rem;">Verificación del Destinatario:</strong>
<span>Transfiera únicamente al número telefónico y titular oficial registrados de la soda escolar. SiboPay nunca le solicitará fondos a cuentas particulares.</span>
</div>
</div>
<!-- 4. Comprobante de Respaldo -->
<div style="display: flex; gap: 10px; align-items: flex-start;">
<div style="width: 22px; height: 22px; border-radius: 50%; background: #dcfce7; color: #166534; font-weight: 900; font-size: 0.72rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px;">
4
</div>
<div>
<strong style="color: var(--text-main, #0f172a); display: block; font-size: 0.82rem;">Comprobante de Respaldo:</strong>
<span>Conserve la captura o número de comprobante emitido por su banco. En caso de requerir aclaración, este servirá como comprobante ante la administración de la soda.</span>
</div>
</div>
<!-- 5. Disponibilidad del Saldo -->
<div style="display: flex; gap: 10px; align-items: flex-start;">
<div style="width: 22px; height: 22px; border-radius: 50%; background: #dcfce7; color: #166534; font-weight: 900; font-size: 0.72rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px;">
5
</div>
<div>
<strong style="color: var(--text-main, #0f172a); display: block; font-size: 0.82rem;">Disponibilidad Inmediata:</strong>
<span>Una vez validado el pago, los fondos quedan disponibles de inmediato para compras con carné QR o pre-órdenes. El saldo no vence durante el curso lectivo.</span>
</div>
</div>
<!-- 6. No Canjeable por Efectivo -->
<div style="display: flex; gap: 10px; align-items: flex-start;">
<div style="width: 22px; height: 22px; border-radius: 50%; background: #fee2e2; color: #991b1b; font-weight: 900; font-size: 0.72rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px;">
6
</div>
<div>
<strong style="color: #991b1b; display: block; font-size: 0.82rem;">No Canjeable por Dinero Real o Efectivo:</strong>
<span>Los fondos recargados corresponden a créditos escolares exclusivos para consumo de alimentos en la soda. <strong>No pueden ser convertidos ni devueltos en dinero en efectivo</strong> bajo ninguna circunstancia.</span>
</div>
</div>
</div>
<!-- Pie de Seguridad -->
<div style="margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border, #f1f5f9); display: flex; align-items: center; justify-content: space-between; font-size: 0.72rem; color: var(--text-muted, #64748b);">
<span style="display: flex; align-items: center; gap: 6px;">
<span style="width: 7px; height: 7px; border-radius: 50%; background: #10b981; display: inline-block;"></span>
<span>Conciliación automática activa 24/7</span>
</span>
<span style="font-weight: 800; color: #0284c7;">SiboPay Protegido</span>
</div>
</div>
</div>
</div>
<!-- 2. SUB-PANTALLA: ALERGIAS Y SALUD -->
<div id="parentSubViewAlergias" class="parent-subview" style="display: none;">
<div class="parent-subview-header">
<button type="button" onclick="closeParentSubView()" class="parent-subview-back-btn">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>
<span>Volver</span>
</button>
<div class="parent-subview-child-tag">
<span class="parentSubViewChildAvatarBadge">ES</span>
<span class="parentSubViewChildName">Estudiante</span>
</div>
</div>
<div id="parentAllergiesCard" class="parent-card" style="background: #ffffff; border: 1.5px solid #fecdd3; border-radius: 20px; box-shadow: 0 4px 14px rgba(225, 29, 72, 0.05);">
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div class="parent-refined-icon-box rose-halo" style="width: 36px; height: 36px;">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>
</div>
<div>
<strong style="color: #9f1239; font-size: 0.95rem; display: block;">Alergias y Restricciones</strong>
<span style="font-size: 0.72rem; color: #e11d48; font-weight: 600;">Expediente de salud y veto de golosinas</span>
</div>
</div>
<span id="parentAllergiesStatusBadge" style="font-size: 0.7rem; color: #e11d48; background: #ffe4e6; font-weight: 800; padding: 3px 8px; border-radius: 6px;">Sin alergias</span>
</div>
<!-- Alergias clínicas -->
<div style="margin-bottom: 14px; background: #fff1f2; border: 1px solid #fecdd3; padding: 12px; border-radius: 14px;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px;">
<label style="font-size: 0.76rem; font-weight: 800; color: #9f1239; display: block;">Alergias o Intolerancias Médicas:</label>
<span style="font-size: 0.68rem; color: #e11d48; font-weight: 700;">Visible en caja de soda</span>
</div>
<input type="text" id="inputParentStudentAllergies" placeholder="Ej: Maní, Gluten, Lactosa, Mariscos..." style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid #fca5a5; font-size: 0.85rem; font-weight: 700; color: #881337; background: #ffffff; box-sizing: border-box;">
<div style="display: flex; gap: 5px; margin-top: 8px; flex-wrap: wrap;">
<button type="button" onclick="addParentAllergyTag('Maní')" class="allergy-tag-pill">+ Maní</button>
<button type="button" onclick="addParentAllergyTag('Gluten')" class="allergy-tag-pill">+ Gluten</button>
<button type="button" onclick="addParentAllergyTag('Lactosa')" class="allergy-tag-pill">+ Lactosa</button>
<button type="button" onclick="addParentAllergyTag('Mariscos')" class="allergy-tag-pill">+ Mariscos</button>
<button type="button" onclick="addParentAllergyTag('Huevo')" class="allergy-tag-pill">+ Huevo</button>
<button type="button" onclick="clearParentAllergies()" class="allergy-tag-pill" style="color: #64748b; background: white; border-color: #cbd5e1;">Ninguna</button>
</div>
</div>
<!-- Toggle Veto de Chucherías / Comida no saludable -->
<div style="display: flex; justify-content: space-between; align-items: center; background: #f8fafc; border: 1px solid #e2e8f0; padding: 12px; border-radius: 14px; margin-bottom: 12px;">
<div>
<strong style="font-size: 0.84rem; color: #1e293b; display: block;">Veto de Comida Chatarra / Golosinas</strong>
<span style="font-size: 0.70rem; color: #64748b; display: block; margin-top: 2px;">Bloquea confites, gaseosas y comida chatarra en caja</span>
</div>
<label class="switch-saas" title="Bloquear comida chatarra">
<input type="checkbox" id="chkParentBlockJunkFood" onchange="onToggleParentBlockJunkFood(this.checked)">
<span class="switch-saas-slider rose"></span>
</label>
</div>
<!-- Botón Guardar Alergias -->
<button type="button" onclick="saveParentAllergiesSettings()" style="width: 100%; padding: 11px; background: linear-gradient(135deg, #e11d48, #be123c); color: white; border: none; border-radius: 12px; font-weight: 800; font-size: 0.86rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; box-shadow: 0 3px 8px rgba(225, 29, 72, 0.25);">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg>
<span>Guardar Configuración de Salud</span>
</button>
</div>
</div>
<!-- 3. SUB-PANTALLA: LÍMITE DIARIO Y TRANSFERENCIAS -->
<div id="parentSubViewLimites" class="parent-subview" style="display: none;">
<div class="parent-subview-header">
<button type="button" onclick="closeParentSubView()" class="parent-subview-back-btn">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>
<span>Volver</span>
</button>
<div class="parent-subview-child-tag">
<span class="parentSubViewChildAvatarBadge">ES</span>
<span class="parentSubViewChildName">Estudiante</span>
</div>
</div>
<!-- TARJETA ÚNICA DE LÍMITE DIARIO Y TRANSFERENCIAS (COMPACTA, ESTÉTICA Y FINTECH) -->
<div id="parentDailyLimitCard" class="parent-card" style="background: var(--card-bg, #ffffff); border: 1.5px solid #bae6fd; box-shadow: 0 4px 16px rgba(2, 132, 199, 0.06); padding: 22px; border-radius: 18px; margin-bottom: 14px;">
<!-- Cabecera con Icono y Badge -->
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 8px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 40px; height: 40px; border-radius: 11px; background: #e0f2fe; color: #0284c7; display: flex; align-items: center; justify-content: center; font-size: 1.15rem; flex-shrink: 0;">
🛡️
</div>
<div>
<strong style="font-size: 0.98rem; color: var(--text-main); display: block; line-height: 1.2;">Límite de Gasto Diario</strong>
<span style="font-size: 0.74rem; color: var(--text-muted); display: block; margin-top: 2px;">Tope de consumo por jornada escolar</span>
</div>
</div>
<div style="text-align: right;">
<span id="lblParentDailyLimitDisplay" style="font-size: 1.15rem; color: #0284c7; font-weight: 900; background: #f0f9ff; border: 1.5px solid #bae6fd; padding: 5px 14px; border-radius: 10px; display: inline-block; letter-spacing: -0.3px;">₡3.000 / día</span>
</div>
</div>
<!-- Selector de Montos Rápidos (Pills) -->
<div style="margin-bottom: 14px;">
<span style="display: block; font-size: 0.72rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px;">Montos sugeridos:</span>
<div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;">
<button type="button" onclick="setParentLimitPreset(1500)" class="limit-preset-pill">₡1.500</button>
<button type="button" onclick="setParentLimitPreset(2500)" class="limit-preset-pill">₡2.500</button>
<button type="button" onclick="setParentLimitPreset(3500)" class="limit-preset-pill">₡3.500</button>
<button type="button" onclick="setParentLimitPreset(5000)" class="limit-preset-pill">₡5.000</button>
</div>
</div>
<!-- Barra Deslizadora Compacta y Estilizada -->
<div style="background: var(--bg-main, #f8fafc); border: 1px solid var(--border, #e2e8f0); border-radius: 12px; padding: 12px 14px; margin-bottom: 16px;">
<div style="display: flex; justify-content: space-between; align-items: center; font-size: 0.72rem; font-weight: 800; color: var(--text-muted);">
<span>Ajuste rápido:</span>
<span style="color: #0284c7; font-weight: 900;">Arrastra la barra</span>
</div>
<input type="range" id="rangeParentLimit" class="saas-range-slider" min="1000" max="10000" step="500" value="3000" oninput="onParentLimitSliderChange(this.value)">
<div style="display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--text-muted); font-weight: 700;">
<span>₡1.000 min</span>
<span>₡5.000</span>
<span>₡10.000 max</span>
</div>
</div>
<!-- Input Manual y Botón Guardar en Fila Compacta -->
<div style="display: flex; gap: 8px; align-items: center; margin-bottom: 18px;">
<div style="position: relative; flex: 1;">
<span style="position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-weight: 900; color: #0284c7; font-size: 1.05rem;">₡</span>
<input type="tel" inputmode="numeric" pattern="[0-9]*" id="inputParentCustomLimit" placeholder="Ej: 3000" oninput="onParentLimitInputChange(this.value)" style="width: 100%; height: 42px; padding: 0 12px 0 32px; border-radius: 10px; border: 1.5px solid var(--border, #cbd5e1); font-size: 1.05rem; font-weight: 900; color: var(--text-main); background: var(--card-bg, #ffffff); box-sizing: border-box; outline: none;">
</div>
<button type="button" onclick="saveParentCustomLimit()" class="btn-saas btn-saas-primary" style="height: 42px; padding: 0 20px; font-size: 0.85rem; font-weight: 800; border-radius: 10px; white-space: nowrap; flex-shrink: 0; display: inline-flex; align-items: center; gap: 6px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><polyline points="20 6 9 17 4 12"/></svg>
<span>Guardar Límite</span>
</button>
</div>
<!-- Divisor Separador Elegante -->
<div style="border-top: 1px solid var(--border, #e2e8f0); margin: 18px 0 16px 0;"></div>
<!-- REGLA DE PERMISOS: TRANSFERENCIAS ENTRE COMPAÑEROS CON SWITCH TIPO IOS -->
<div style="display: flex; justify-content: space-between; align-items: center; gap: 14px;">
<div style="display: flex; align-items: center; gap: 10px; min-width: 0;">
<div style="width: 36px; height: 36px; border-radius: 10px; background: rgba(2, 132, 199, 0.08); color: #0284c7; display: flex; align-items: center; justify-content: center; font-size: 1.05rem; flex-shrink: 0;">
🔄
</div>
<div>
<strong style="font-size: 0.88rem; color: var(--text-main); display: block; line-height: 1.25;">Transferencias entre Compañeros</strong>
<span style="font-size: 0.72rem; color: var(--text-muted); display: block; margin-top: 2px;">Permitir transferir saldo a compañeros de clase</span>
</div>
</div>
<label class="switch-saas" title="Activar o desactivar transferencias">
<input type="checkbox" id="chkParentAllowTransferDirect" onchange="onToggleParentTransfer(this.checked)" checked>
<span class="switch-saas-slider"></span>
</label>
</div>
</div>
</div>
<!-- 4. SUB-PANTALLA: HISTORIAL DE COMPRAS -->
<div id="parentSubViewHistorial" class="parent-subview" style="display: none;">
<div class="parent-subview-header">
<button type="button" onclick="closeParentSubView()" class="parent-subview-back-btn">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>
<span>Volver</span>
</button>
<div class="parent-subview-child-tag">
<span class="parentSubViewChildAvatarBadge">ES</span>
<span class="parentSubViewChildName">Estudiante</span>
</div>
</div>
<div id="parentHistoryCard" class="parent-card">
<h4 style="font-size: 0.95rem; font-weight: 900; color: var(--text-main); margin-bottom: 12px; display: flex; align-items: center; gap: 8px;">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" x2="8" y1="13" y2="13"/><line x1="16" x2="8" y1="17" y2="17"/></svg>
<span>Historial Detallado de Compras</span>
</h4>
<div id="parentStudentHistoryList" style="font-size: 0.85rem; color: var(--text-muted);">
Sin compras recientes registradas.
</div>
</div>
</div>
<!-- 5. SUB-PANTALLA: SEGURIDAD Y CREDENCIALES -->
<div id="parentSubViewCredenciales" class="parent-subview" style="display: none;">
<div class="parent-subview-header">
<button type="button" onclick="closeParentSubView()" class="parent-subview-back-btn">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>
<span>Volver</span>
</button>
<div class="parent-subview-child-tag">
<span class="parentSubViewChildAvatarBadge">ES</span>
<span class="parentSubViewChildName">Estudiante</span>
</div>
</div>
<!-- 1. BLOQUEO BIOMÉTRICO / FACE ID / PIN DEL CARNÉ QR -->
<div class="parent-card" style="border: 1.5px solid #86efac; background: #f0fdf4; margin-bottom: 16px;">
<div style="display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px;">
<div style="display: flex; align-items: center; gap: 12px; min-width: 220px;">
<div style="width: 44px; height: 44px; border-radius: 12px; background: #dcfce7; color: #16a34a; display: flex; align-items: center; justify-content: center; font-size: 1.35rem; flex-shrink: 0; box-shadow: 0 2px 6px rgba(22, 163, 74, 0.15);">
🛡️
</div>
<div>
<strong style="font-size: 0.95rem; color: #166534; display: block;">Bloqueo Huella / Face ID / PIN del QR</strong>
<span style="font-size: 0.76rem; color: #475569; display: block; margin-top: 2px;">Exigir autenticación biométrica en el teléfono para mostrar el carné QR de pago</span>
</div>
</div>
<button type="button" onclick="openQrSecuritySettings()" class="btn-saas btn-saas-primary" style="background: #16a34a; border-color: #16a34a; padding: 9px 18px; font-weight: 800; font-size: 0.84rem; cursor: pointer; border-radius: 10px; box-shadow: 0 3px 8px rgba(22, 163, 74, 0.25); display: inline-flex; align-items: center; gap: 6px;">
<span>Configurar Seguridad</span>
<span id="badgeParentQrSecStatus" style="background: rgba(255,255,255,0.25); font-size: 0.72rem; padding: 2px 6px; border-radius: 6px;">⚙️</span>
</button>
</div>
</div>
<div class="parent-card" style="border: 1.5px solid var(--border);">
<div style="display: flex; align-items: center; gap: 10px; margin-bottom: 14px;">
<div style="width: 38px; height: 38px; border-radius: 10px; background: rgba(51, 65, 85, 0.1); color: #334155; display: flex; align-items: center; justify-content: center; flex-shrink: 0;">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="11" x="3" y="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg>
</div>
<div>
<strong style="font-size: 0.95rem; color: var(--text-main); display: block;">Credenciales de Acceso Escolar</strong>
<span style="font-size: 0.74rem; color: var(--text-muted);">Restablece el PIN de 4 dígitos o contraseña de tu hijo</span>
</div>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px;">
<div>
<label style="display: block; font-size: 0.76rem; font-weight: 800; color: var(--text-muted); margin-bottom: 4px;">Nuevo PIN (4 dígitos):</label>
<input type="password" inputmode="numeric" maxlength="4" id="inputParentStudentPin" placeholder="1234" style="width: 100%; padding: 11px; border-radius: 10px; border: 1.5px solid var(--border); font-weight: 900; letter-spacing: 3px; text-align: center; box-sizing: border-box; background: var(--card-bg); color: var(--text-main); font-size: 1.05rem;">
</div>
<div>
<label style="display: block; font-size: 0.76rem; font-weight: 800; color: var(--text-muted); margin-bottom: 4px;">Nueva Contraseña:</label>
<input type="text" id="inputParentStudentPass" placeholder="Ej: 1234" style="width: 100%; padding: 11px; border-radius: 10px; border: 1.5px solid var(--border); font-weight: 800; box-sizing: border-box; background: var(--card-bg); color: var(--text-main); font-size: 0.95rem;">
</div>
</div>
<button type="button" onclick="saveParentStudentCredentials()" style="width: 100%; padding: 12px; background: #334155; color: white; border: none; border-radius: 10px; font-weight: 800; font-size: 0.88rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="20 6 9 17 4 12"/></svg>
<span>Guardar Nuevas Credenciales</span>
</button>
</div>
</div>
<!-- SUBVISTA: DASHBOARD EJECUTIVO FAMILIAR -->
<div id="parentSubViewDashboard" class="parent-subview" style="display: none;">
<div class="parent-subview-header">
<button type="button" onclick="closeParentSubView()" class="parent-subview-back-btn">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>
<span>Volver</span>
</button>
<div style="display: flex; align-items: center; gap: 8px;">
<span style="font-size: 1.1rem;">📊</span>
<strong style="font-size: 0.92rem; color: var(--text-main);">Dashboard Ejecutivo Familiar</strong>
</div>
</div>
<div class="parent-card" style="background: var(--card-bg, #ffffff); border: 1px solid var(--border, #e2e8f0); border-radius: 18px; padding: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.03);">
<!-- BARRA DE CONTROLES: FILTRO DE HIJO, PERÍODO Y ACTUALIZAR -->
<div style="display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--border, #e2e8f0);">
<div style="display: flex; align-items: center; gap: 10px; flex-wrap: wrap;">
<div>
<label for="parentDashChildFilter" style="display: block; font-size: 0.72rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; margin-bottom: 3px;">Estudiante:</label>
<select id="parentDashChildFilter" onchange="cambiarHijoDashboardPadres(this.value)" style="padding: 6px 12px; border-radius: 9px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.82rem; font-weight: 800; outline: none; cursor: pointer;">
<option value="todos">👨‍👩‍👧‍👦 Todos mis hijos (Consolidado)</option>
</select>
</div>
<div>
<label style="display: block; font-size: 0.72rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; margin-bottom: 3px;">Período:</label>
<div class="admin-dash-period-pills" id="parentDashPeriodPills">
<button type="button" class="admin-dash-pill-btn active" data-periodo="mes" onclick="cambiarPeriodoDashboardPadres('mes')">Este Mes</button>
<button type="button" class="admin-dash-pill-btn" data-periodo="30dias" onclick="cambiarPeriodoDashboardPadres('30dias')">30 Días</button>
<button type="button" class="admin-dash-pill-btn" data-periodo="hoy" onclick="cambiarPeriodoDashboardPadres('hoy')">Hoy</button>
<button type="button" class="admin-dash-pill-btn" data-periodo="todo" onclick="cambiarPeriodoDashboardPadres('todo')">Histórico</button>
</div>
</div>
</div>
<button type="button" onclick="cargarDashboardPadres()" class="btn-saas btn-saas-outline" style="height: 32px; padding: 0 10px; font-size: 0.76rem;" title="Recargar datos">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"/><path d="M16 21h5v-5"/></svg>
<span>Actualizar</span>
</button>
</div>
<!-- CUADRÍCULA DE 4 TARJETAS KPI EJECUTIVAS -->
<div class="admin-dash-grid" style="margin-bottom: 18px;">
<!-- KPI 1: SALDO DISPONIBLE -->
<div class="admin-dash-kpi-card kpi-blue">
<div class="admin-dash-kpi-header">
<span class="admin-dash-kpi-title">Saldo Disponible</span>
<div class="admin-dash-kpi-icon">💳</div>
</div>
<div class="admin-dash-kpi-val" id="parentDashKpiSaldo">₡0</div>
<div class="admin-dash-kpi-meta">
<span id="parentDashKpiSaldoMeta">Retenido preórdenes: <strong>₡0</strong></span>
</div>
</div>
<!-- KPI 2: TOTAL RECARGADO -->
<div class="admin-dash-kpi-card kpi-purple">
<div class="admin-dash-kpi-header">
<span class="admin-dash-kpi-title">Recargas del Período</span>
<div class="admin-dash-kpi-icon">📥</div>
</div>
<div class="admin-dash-kpi-val" id="parentDashKpiRecargas">₡0</div>
<div class="admin-dash-kpi-meta">
<span id="parentDashKpiRecargasMeta">SINPE Móvil: <strong>₡0 (0 recargas)</strong></span>
</div>
</div>
<!-- KPI 3: CONSUMO / COMPRAS -->
<div class="admin-dash-kpi-card kpi-green">
<div class="admin-dash-kpi-header">
<span class="admin-dash-kpi-title">Compras en la Soda</span>
<div class="admin-dash-kpi-icon">🥪</div>
</div>
<div class="admin-dash-kpi-val" id="parentDashKpiCompras">₡0</div>
<div class="admin-dash-kpi-meta">
<span id="parentDashKpiComprasMeta">0 compras despachadas</span>
</div>
</div>
<!-- KPI 4: PROMEDIO POR COMPRA -->
<div class="admin-dash-kpi-card kpi-amber">
<div class="admin-dash-kpi-header">
<span class="admin-dash-kpi-title">Promedio de Compra</span>
<div class="admin-dash-kpi-icon">📊</div>
</div>
<div class="admin-dash-kpi-val" id="parentDashKpiTicket">₡0</div>
<div class="admin-dash-kpi-meta">
<span id="parentDashKpiTicketMeta">Ticket promedio por orden</span>
</div>
</div>
</div>
<!-- SECCIÓN 2 COLUMNAS: TOP PRODUCTOS CONSUMIDOS Y MOVIMIENTOS RECIENTES -->
<div class="admin-dash-split" style="margin-bottom: 18px;">
<!-- COLUMNA 1: TOP MERIENDAS CONSUMIDAS -->
<div class="admin-dash-section">
<div class="admin-dash-section-title">
<span>🏆 Meriendas Más Consumidas</span>
<span style="font-size: 0.72rem; color: var(--text-muted); font-weight: 600;">Unidades & Monto</span>
</div>
<div id="parentDashTopProductosList" style="display: flex; flex-direction: column; gap: 10px;">
<!-- Dinámico -->
</div>
</div>
<!-- COLUMNA 2: ÚLTIMOS MOVIMIENTOS -->
<div class="admin-dash-section">
<div class="admin-dash-section-title">
<span>📜 Movimientos Recientes</span>
<span style="font-size: 0.72rem; color: var(--text-muted); font-weight: 600;">Compras & Recargas</span>
</div>
<div id="parentDashMovimientosList" style="display: flex; flex-direction: column; gap: 8px; max-height: 280px; overflow-y: auto;">
<!-- Dinámico -->
</div>
</div>
</div>
<!-- BOTÓN EXPORTAR EXCEL ESTADO DE CUENTA -->
<div style="display: flex; justify-content: flex-end; padding-top: 12px; border-top: 1px solid var(--border, #e2e8f0);">
<button type="button" onclick="descargarEstadoCuentaPadresExcel()" class="btn-saas btn-saas-outline" style="height: 36px; border-color: #10b981; color: #166534; font-size: 0.82rem; font-weight: 800;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
<span>Descargar Estado de Cuenta (Excel XLSX)</span>
</button>
</div>
</div>
</div>
</main>
</div>
</div>
</div>
<div class="app-container" id="appContainer" style="display: none;">
<!-- BANNER DE TARJETA SUSPENDIDA / BLOQUEADA -->
<div id="bannerCardBlocked" class="banner-card-blocked" style="display: none;">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#ef4444" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="4.93" x2="19.07" y1="4.93" y2="19.07"/></svg>
<span><strong>TARJETA SUSPENDIDA POR LA SODA.</strong> Acércate al mostrador de la soda para reactivar tu cuenta.</span>
</div>
<!-- BANNER DE MODO MANTENIMIENTO EN CATÁLOGO / ESTUDIANTES -->
<div id="studentMaintenanceBanner" style="display: none; background: #fff1f2; border: 1.5px solid #fecdd3; color: #9f1239; padding: 12px 16px; border-radius: 12px; margin: 10px 16px 0 16px; font-size: 0.84rem; align-items: center; gap: 10px; box-shadow: 0 4px 12px rgba(225, 29, 72, 0.08);">
<span style="font-size: 1.3rem;">🛡️</span>
<div style="flex: 1;">
<strong style="display: block; font-size: 0.86rem; color: #881337;">Aviso de Pausa Temporal</strong>
<span id="studentMaintenanceBannerText">Estamos realizando mejoras técnicas en el sistema. Los pedidos se reanudarán en breve.</span>
</div>
</div>
<!-- BANNER DE ADVERTENCIA HTTPS PARA TELÉFONOS MÓVILES -->
<div id="bannerHttpsWarning" style="display: none; background: linear-gradient(135deg, #f59e0b, #d97706); color: white; padding: 10px 14px; font-size: 0.78rem; font-weight: 700; text-align: center; border-radius: 12px; margin: 10px 16px 0 16px; box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);">
<span style="display: inline-flex; align-items: center; gap: 6px;">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="11" x="3" y="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg>
<span>Estás en HTTP. Para activar la cámara y pagos QR, tu celular requiere HTTPS:</span>
</span>
<div style="margin-top: 6px;">
<a id="linkHttpsRedirect" href="#" onclick="window.location.protocol = 'https:'; return false;" style="display: inline-flex; align-items: center; gap: 6px; padding: 5px 14px; background: white; color: #b45309; border-radius: 20px; font-weight: 900; text-decoration: none; font-size: 0.8rem; box-shadow: 0 2px 5px rgba(0,0,0,0.15);">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" x2="21" y1="14" y2="3"/></svg>
<span>Abrir en HTTPS Seguro</span>
</a>
</div>
</div>
<!-- BARRA SUPERIOR UNIFICADA -->
<header class="top-bar">
<a href="#" class="brand-badge">
<div class="logo-icon" style="padding: 2px;">
<img src="/img/sibopay-emblem.png" alt="SiboPay" style="width: 26px; height: 26px; object-fit: contain;">
</div>
<div>
<span>Sibo<strong>Pay</strong></span>
<span style="font-size: 0.65rem; display: block; color: var(--text-muted); font-weight: 600;">SODA ESCOLAR CR</span>
</div>
</a>
<!-- ACCIONES DE CABECERA (TEMA OSCURO/CLARO Y SALIR) -->
<div class="top-actions">
<button id="btnCardDesigns" onclick="openCardDesignModal()" class="theme-toggle-btn card-design-toggle-btn" title="Personalizar diseño de mi tarjeta" style="display: inline-flex; align-items: center; justify-content: center; margin-right: 4px;">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="13.5" cy="6.5" r=".5" fill="currentColor"/><circle cx="17.5" cy="10.5" r=".5" fill="currentColor"/><circle cx="8.5" cy="7.5" r=".5" fill="currentColor"/><circle cx="6.5" cy="12.5" r=".5" fill="currentColor"/><path d="M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z"/></svg>
</button>
<button id="btnThemeToggle" onclick="toggleTheme()" class="theme-toggle-btn" title="Alternar Modo Oscuro / Modo Claro" style="display: inline-flex; align-items: center; justify-content: center;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/></svg>
<button id="btnTopAjustes" onclick="abrirModalAjustesCuenta()" class="mode-btn" style="background: var(--bg-main); border: 1.5px solid var(--border); font-size: 0.8rem; font-weight: 800; border-radius: 10px; padding: 7px 11px; cursor: pointer; color: var(--text-main); display: inline-flex; align-items: center; gap: 6px;" title="Mi Cuenta, Ajustes y Privacidad">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>
<span>Ajustes</span>
</button>
<button id="btnModePadres" onclick="toggleParentPanel(true)" class="mode-btn" style="background: var(--bg-main); border: 1.5px solid var(--border); font-size: 0.8rem; font-weight: 800; border-radius: 10px; padding: 7px 11px; cursor: pointer; color: var(--text-main); display: inline-flex; align-items: center; gap: 6px;" title="Acceso al Portal de Padres">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>
<span>Padres</span>
</button>
<button id="btnLogout" onclick="logout(true)" class="logout-btn" title="Cerrar sesión y cambiar de cuenta" style="display: inline-flex; align-items: center; gap: 6px;">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" x2="9" y1="12" y2="12"/></svg>
<span class="logout-text">Salir</span>
</button>
</div>
</header>
<!-- SELECTOR OCULTO PARA COMPATIBILIDAD JS -->
<select id="studentSelector" onchange="onStudentChange(this.value)" style="display: none;"></select>
<!-- TARJETA DIGITAL DE MONEDERO Y SALDO (ESTILO UNIFICADO TEENS) -->
<section class="wallet-card" id="mainWalletCard">
<!-- ELEMENTOS DE TARJETA INTELIGENTE (PAGO SIN CONTACTO, SIN ASTERISCOS) -->
<div class="card-chip-container" style="justify-content: flex-end;">
<div class="card-contactless-wave" title="Tecnología QR / Sin Contacto">
<span>)</span><span>)</span><span>)</span>
</div>
</div>
<div class="student-info">
<div id="walletAvatar" class="student-avatar">ES</div>
<div class="student-meta" style="flex: 1; min-width: 0;">
<div style="min-width: 0;">
<h2 id="walletName" style="word-break: break-word; margin: 0; font-size: 1.15rem; font-weight: 800;">Cargando...</h2>
<div style="display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 3px;">
<span id="walletGrade" class="student-grade">Grado y Sección</span>
<span id="walletStudentCode" class="card-glass-badge">Cód: EST-00000</span>
</div>
</div>
</div>
</div>
<div class="balance-row">
<div class="balance-col">
<div class="label" id="balanceLabel" style="margin-bottom: 4px;">SALDO DISPONIBLE</div>
<div class="amount">
<span id="walletBalance" class="card-balance-glass">₡0</span>
<span class="kids-coin-icon" id="kidsCoinIcon" style="display: none;"></span>
</div>
<!-- Desglose transparente cuando hay pre-órdenes flotantes -->
<div id="breakdownSaldoBox" style="display: none; font-size: 0.72rem; margin-top: 5px; line-height: 1.35; background: rgba(0, 0, 0, 0.22); padding: 5px 8px; border-radius: 8px; backdrop-filter: blur(4px);">
<div style="color: rgba(255, 255, 255, 0.95);">Saldo total: <strong id="lblSaldoTotalBreakdown">₡0</strong></div>
<div style="color: #fef08a;">Retenido en pre-órdenes: <strong id="lblSaldoRetenidoBreakdown">₡0</strong></div>
</div>
</div>
</div>
</section>
<!-- BANNER DE LÍMITE DIARIO Y DISPONIBILIDAD (SÓLO LECTURA INFORMATIVA PARA EL ESTUDIANTE) -->
<div class="daily-limit-badge" id="dailyLimitBadge" style="cursor: default;" title="Límite diario establecido por tus padres">
<div>
<span>Límite diario fijado: </span>
<strong id="dailyLimitText">₡0</strong>
</div>
<div style="font-size: 0.76rem; color: var(--text-muted);" id="dailyAvailableText">
Disponible hoy: ₡0
</div>
</div>
<!-- BANNER DE ALERTA: LÍMITE DIARIO ALCANZADO (QR BLOQUEADO) -->
<div id="bannerQrDailyLimitBlocked" style="display: none; margin: 0 16px 12px 16px; background: #fef2f2; border: 1.5px solid #fecaca; border-radius: 12px; padding: 10px 14px; font-size: 0.8rem; color: #991b1b; align-items: center; gap: 8px;">
<span style="font-size: 1.3rem; line-height: 1;">⛔</span>
<div>
<strong style="display: block; font-size: 0.82rem; margin-bottom: 2px;">Límite diario alcanzado</strong>
<span id="bannerQrDailyLimitMsg" style="font-size: 0.75rem; color: #7f1d1d; line-height: 1.35;">
Has consumido tu límite de gasto de hoy. Tu código QR está bloqueado para nuevas compras hasta la siguiente jornada.
</span>
</div>
</div>
<!-- ALERGIAS (SI TIENE) -->
<div id="allergyWarning" style="display:none; margin: 0 16px 12px 16px; background: #fffbeb; border: 1px solid #fde68a; border-radius: 12px; padding: 8px 12px; font-size: 0.8rem; color: #92400e; align-items: center; gap: 6px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="#b45309" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><line x1="12" x2="12" y1="9" y2="13"/><line x1="12" x2="12.01" y1="17" y2="17"/></svg>
<strong>Atención médica:</strong> <span id="allergyText"></span>
</div>
<!-- ÓRDENES ACTIVAS Y PRE-ÓRDENES PENDIENTES DEL ESTUDIANTE -->
<section id="studentActiveOrdersSection" class="student-active-orders-section" style="display: none; margin: 0 16px 14px 16px;">
<div style="background: var(--card-bg, #ffffff); border: 1.5px solid #bae6fd; border-radius: 16px; padding: 14px 16px; box-shadow: 0 3px 12px rgba(2, 132, 199, 0.08);">
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; border-bottom: 1px dashed var(--border, #e2e8f0); padding-bottom: 8px;">
<div style="display: flex; align-items: center; gap: 8px;">
<div style="width: 32px; height: 32px; border-radius: 10px; background: rgba(2, 132, 199, 0.12); display: flex; align-items: center; justify-content: center; font-size: 1.1rem;">
🥪
</div>
<div>
<strong style="font-size: 0.88rem; color: #0284c7; display: block; font-weight: 800;">Tus Pedidos Activos</strong>
<span style="font-size: 0.7rem; color: var(--text-muted);">Pendientes de retirar en la soda</span>
</div>
</div>
<span id="studentActiveOrdersCountBadge" style="background: #0284c7; color: white; border-radius: 20px; padding: 2px 9px; font-size: 0.72rem; font-weight: 800;">0 activos</span>
</div>
<div id="studentActiveOrdersList" style="display: flex; flex-direction: column; gap: 10px;">
<!-- Inyectado dinámicamente -->
</div>
</div>
</section>
<!-- BUSCADOR INTELIGENTE DEL MENÚ PARA ESTUDIANTES Y PADRES -->
<div class="menu-smart-search-section" id="menuSmartSearchSection">
<div class="menu-smart-search-box">
<div class="menu-smart-search-icon">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="11" cy="11" r="8"/>
<path d="m21 21-4.3-4.3"/>
</svg>
</div>
<input
type="text"
id="menuSearchInput"
class="menu-smart-search-input"
placeholder="Buscar merienda, fresco, snack o precio (<1000)..."
oninput="handleMenuSearchInput(this.value)"
onkeydown="handleMenuSearchKeyDown(event)"
autocomplete="off"
spellcheck="false"
aria-label="Buscador inteligente del menú"
>
<button
type="button"
id="menuSearchClearBtn"
class="menu-smart-search-clear-btn"
onclick="clearMenuSearch()"
title="Borrar búsqueda"
style="display: none;"
>
✕
</button>
</div>
<!-- CHIPS INTELIGENTES DE ACCESO RÁPIDO -->
<div class="menu-smart-search-chips" id="menuSmartSearchChips">
<button type="button" class="search-chip" onclick="setMenuSearchSuggestion('fresco')">
<span>🥤 Frescos</span>
</button>
<button type="button" class="search-chip" onclick="setMenuSearchSuggestion('casado')">
<span>🍛 Casados</span>
</button>
<button type="button" class="search-chip" onclick="setMenuSearchSuggestion('empanada')">
<span>🥟 Empanadas</span>
</button>
<button type="button" class="search-chip" onclick="setMenuSearchSuggestion('<1000')">
<span>💰 Menos de ₡1.000</span>
</button>
<button type="button" class="search-chip" onclick="setMenuSearchSuggestion('saludable')">
<span>🥗 Saludables</span>
</button>
</div>
<!-- ESTADÍSTICAS Y RESET DE BÚSQUEDA -->
<div id="menuSearchStats" class="menu-smart-search-stats" style="display: none;">
<span id="menuSearchStatsText">Mostrando 0 productos</span>
<button type="button" class="menu-smart-search-reset-link" onclick="clearMenuSearch()">Mostrar menú completo</button>
</div>
</div>
<!-- BARRA DE CATEGORÍAS -->
<div class="category-scroll" id="categoriesBar">
<!-- Se llena dinámicamente -->
</div>
<!-- TÍTULO DE SECCIÓN -->
<div class="section-title">
<span id="catalogTitle">Menú del Recreo</span>
</div>
<!-- GRILLA DE PRODUCTOS -->
<div class="products-grid" id="productsGrid">
<!-- Se llena con productos de la soda -->
</div>
</div>
<!-- MODAL INMERSIVO: CÓDIGO QR PARA PRESENTAR EN LA SODA (DISEÑO SIBOPAY EXACTO) -->
<div class="modal-qr-sibopay-immersive" id="modalQr" style="display: none;" onclick="closeQrModal(event)">
<!-- FONDO SUPERIOR CELESTE CON LOGO Y MARCA SIBOPAY -->
<div class="qr-immersive-bg-header">
<div class="qr-immersive-brand-header">
<div class="qr-immersive-brand-logo-wrap">
<img src="/img/sibopay-emblem.png" alt="SiboPay" class="qr-immersive-brand-logo">
</div>
<div class="qr-immersive-brand-title">
<span>Sibo</span><strong class="brand-pay-text">Pay</strong>
</div>
</div>
</div>
<!-- CONTENEDOR CENTRAL: TARJETA BLANCA Y BOTÓN CERRAR -->
<div class="qr-immersive-content" onclick="event.stopPropagation()">
<div class="qr-immersive-card">
<div class="qr-card-header-title">MI CARNÉ SIBOPAY</div>
<!-- Banner especial cuando el límite diario fue alcanzado pero tiene preórdenes -->
<div id="qrPreorderOnlyBanner" style="display: none; background: #eff6ff; border: 1.5px solid #bfdbfe; color: #1e40af; border-radius: 10px; padding: 7px 10px; margin-bottom: 10px; font-size: 0.75rem; text-align: center; font-weight: 700; line-height: 1.35;">
📦 Válido exclusivamente para retirar tu Pre-Orden en la soda.<br>
<span style="font-size: 0.70rem; color: #3b82f6;">Compras nuevas en mostrador bloqueadas por límite diario.</span>
</div>
<div class="qr-scanner-frame-wrapper">
<div class="qr-frame-corner top-left"></div>
<div class="qr-frame-corner top-right"></div>
<div class="qr-frame-corner bottom-left"></div>
<div class="qr-frame-corner bottom-right"></div>
<img id="qrDisplayImg" class="qr-immersive-code-img" src="" alt="Código QR">
<!-- LOGO DE LA 'S' EN EL CENTRO DEL QR -->
<div class="qr-center-logo-badge" title="SiboPay">
<img src="/img/sibopay-emblem.png" alt="S" class="qr-center-logo-img">
</div>
</div>
<div class="qr-card-token-text" id="qrTokenDisplay">
CODIGO-QR
</div>
</div>
<!-- BOTÓN CELESTE TIPO PÍLDORA -->
<button type="button" onclick="closeQrModal()" class="qr-immersive-btn-close">
Cerrar
</button>
</div>
</div>
<!-- MODAL DE SEGURIDAD / DESBLOQUEO DE CARNÉ QR (BIOMETRÍA / PIN) -->
<div class="modal-qr-backdrop" id="modalQrPinPrompt" style="display: none; z-index: 10001;" onclick="cancelQrSecurityPrompt(event)">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 360px; text-align: center; border-radius: 24px; padding: 26px 20px;">
<div style="width: 60px; height: 60px; border-radius: 20px; background: #e0f2fe; color: #0284c7; display: flex; align-items: center; justify-content: center; margin: 0 auto 16px; box-shadow: 0 4px 14px rgba(2, 132, 199, 0.2);">
<svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<rect width="18" height="11" x="3" y="11" rx="2" ry="2"/>
<path d="M7 11V7a5 5 0 0 1 10 0v4"/>
</svg>
</div>
<h3 id="lblQrPinPromptTitle" style="font-size: 1.15rem; font-weight: 900; color: var(--text-main, #0f172a); margin: 0 0 6px 0;">Carné QR Protegido</h3>
<p id="lblQrPinPromptDesc" style="font-size: 0.8rem; color: var(--text-muted, #64748b); margin: 0 0 18px 0; line-height: 1.4;">
Verifica tu identidad para mostrar tu código de pago en la soda.
</p>
<!-- Botón para reintentar biometría (Face ID / Huella) si el dispositivo la soporta -->
<div id="qrBioRetryContainer" style="display: none; margin-bottom: 16px;">
<button type="button" onclick="retryQrBiometrics()" style="width: 100%; height: 46px; border-radius: 12px; background: #f0f9ff; border: 1.5px solid #0284c7; color: #0284c7; font-weight: 800; font-size: 0.92rem; display: flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; box-shadow: 0 2px 6px rgba(2, 132, 199, 0.15);">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M12 2a10 10 0 0 0-10 10c0 3.2 1.5 6 3.8 7.8"/>
<path d="M12 6a6 6 0 0 0-6 6c0 1.9.9 3.6 2.3 4.7"/>
<path d="M12 10a2 2 0 0 0-2 2c0 .6.3 1.2.8 1.6"/>
<path d="M12 22a10 10 0 0 0 10-10c0-3.2-1.5-6-3.8-7.8"/>
</svg>
<span>Usar Huella o Face ID</span>
</button>
<div style="font-size: 0.72rem; color: #94a3b8; margin-top: 8px;">— o ingresa tu PIN de 4 dígitos —</div>
</div>
<!-- Inputs de PIN (4 dígitos) -->
<div style="margin-bottom: 18px;">
<label for="inputQrPin" style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main, #334155); margin-bottom: 8px;">
PIN de Seguridad:
</label>
<input type="password" inputmode="numeric" maxlength="4" id="inputQrPin" placeholder="••••" autocomplete="off" onkeyup="handleQrPinInput(event)" style="width: 150px; height: 50px; text-align: center; font-size: 1.8rem; font-weight: 900; letter-spacing: 12px; border-radius: 12px; border: 2px solid #cbd5e1; outline: none; margin: 0 auto; display: block; box-sizing: border-box; color: #0f172a; background: white;">
<div id="msgQrPinError" style="display: none; color: #dc2626; font-size: 0.78rem; font-weight: 800; margin-top: 8px;">
PIN incorrecto. Intenta de nuevo.
</div>
</div>
<!-- Botones de Acción -->
<div style="display: flex; gap: 8px;">
<button type="button" onclick="cancelQrSecurityPrompt()" style="flex: 1; height: 44px; border-radius: 12px; background: #f1f5f9; border: none; color: #475569; font-weight: 800; font-size: 0.9rem; cursor: pointer;">
Cancelar
</button>
<button type="button" onclick="submitQrSecurityPin()" style="flex: 1; height: 44px; border-radius: 12px; background: linear-gradient(135deg, #0284c7, #0369a1); border: none; color: white; font-weight: 800; font-size: 0.9rem; cursor: pointer; box-shadow: 0 4px 12px rgba(2, 132, 199, 0.35);">
Desbloquear
</button>
</div>
</div>
</div>
<!-- MODAL DE AJUSTES DE SEGURIDAD BIOMÉTRICA DEL CARNÉ QR -->
<div class="modal-qr-backdrop" id="modalQrSecuritySettings" style="display: none; z-index: 10000;" onclick="closeQrSecuritySettings(event)">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 420px; text-align: left; border-radius: 22px; padding: 22px;">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1.5px solid var(--border, #e2e8f0); padding-bottom: 12px; margin-bottom: 16px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 38px; height: 38px; border-radius: 10px; background: #e0f2fe; color: #0284c7; display: flex; align-items: center; justify-content: center; flex-shrink: 0;">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>
</svg>
</div>
<div>
<h3 style="margin: 0; font-size: 1.05rem; font-weight: 800; color: var(--text-main, #0f172a);">Seguridad del Carné QR</h3>
<span id="lblQrSecuritySettingsSub" style="font-size: 0.72rem; color: var(--text-muted, #64748b);">Protege tu código de pago en este teléfono</span>
</div>
</div>
<button type="button" onclick="closeQrSecuritySettings()" style="background: none; border: none; font-size: 1.2rem; cursor: pointer; color: #64748b;">✕</button>
</div>
<!-- Switch de Activación -->
<div style="background: #f8fafc; border: 1.5px solid #e2e8f0; border-radius: 14px; padding: 14px; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center;">
<div>
<strong style="font-size: 0.88rem; color: #0f172a; display: block;">Bloqueo con Huella / Face ID</strong>
<span style="font-size: 0.73rem; color: #64748b; line-height: 1.35; display: block; margin-top: 2px;">
Pide autenticación biométrica cada vez que quieras abrir el código QR de pago.
</span>
</div>
<label class="switch-toggle" style="position: relative; display: inline-block; width: 48px; height: 26px; flex-shrink: 0; margin-left: 10px;">
<input type="checkbox" id="chkQrBiometricsEnabled" onchange="toggleQrBiometricSetting(this.checked)" style="opacity: 0; width: 0; height: 0;">
<span class="switch-slider" style="position: absolute; cursor: pointer; inset: 0; background-color: #cbd5e1; border-radius: 34px; transition: .3s;"></span>
</label>
</div>
<!-- Estado de compatibilidad del dispositivo -->
<div id="qrBioDeviceStatus" style="font-size: 0.76rem; padding: 8px 12px; border-radius: 10px; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; font-weight: 700;">
</div>
<!-- PIN de Respaldo -->
<div style="background: #ffffff; border: 1.5px solid #cbd5e1; border-radius: 14px; padding: 14px; margin-bottom: 16px;">
<strong style="font-size: 0.84rem; color: #1e293b; display: block; margin-bottom: 4px;">PIN de Respaldo (4 dígitos)</strong>
<span style="font-size: 0.72rem; color: #64748b; display: block; margin-bottom: 10px;">
Se utilizará si el sensor biométrico no te reconoce o si el dispositivo no tiene lector.
</span>
<div style="display: flex; gap: 8px;">
<input type="password" inputmode="numeric" maxlength="4" id="inputSettingsPinBackup" placeholder="1234" style="flex: 1; padding: 8px 12px; border-radius: 8px; border: 1.5px solid #94a3b8; font-size: 1.1rem; font-weight: 900; letter-spacing: 4px; text-align: center; box-sizing: border-box;">
<button type="button" onclick="saveSettingsPinBackup()" style="padding: 8px 16px; border-radius: 8px; background: #0284c7; color: white; border: none; font-weight: 800; font-size: 0.85rem; cursor: pointer; white-space: nowrap;">
Guardar PIN
</button>
</div>
<div id="msgSettingsPinSaved" style="display: none; color: #16a34a; font-size: 0.74rem; font-weight: 800; margin-top: 6px;">
✅ PIN guardado con éxito
</div>
</div>
<button type="button" onclick="closeQrSecuritySettings()" style="width: 100%; height: 44px; border-radius: 12px; background: #f1f5f9; border: none; font-weight: 800; font-size: 0.9rem; color: #475569; cursor: pointer;">
Listo
</button>
</div>
</div>
<!-- BARRA FLOTANTE GLOBAL DE PRE-ORDEN / CARRITO (ALUMNOS Y PORTAL PADRES) -->
<div class="floating-cart-bar" id="floatingCart" style="display: none;" onclick="openCartModal()" title="Ver y confirmar mi pre-orden">
<div class="cart-summary">
<span class="cart-count-badge" id="cartCountBadge">0 ítems</span>
<div class="cart-total-text" id="cartTotalText">₡0</div>
</div>
<button class="cart-action-btn" id="btnCartFloatingAction" type="button" style="display: flex; align-items: center; justify-content: center; gap: 8px;">
<span>Pedir para el Recreo</span>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="8" cy="21" r="1"/><circle cx="19" cy="21" r="1"/>
<path d="M2.05 2.05h2l2.66 12.42a2 2 0 0 0 2 1.58h9.78a2 2 0 0 0 1.95-1.57l1.65-7.43H5.12"/>
</svg>
</button>
</div>
<!-- MODAL: CARRITO Y PRE-ORDEN -->
<div class="modal-qr-backdrop" id="modalCart" style="display: none;" onclick="closeCartModal(event)">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 420px; text-align: left;">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #e2e8f0; padding-bottom: 10px; margin-bottom: 12px;">
<div>
<h3 style="color: #0f172a; font-size: 1.15rem; font-weight: 800; margin: 0;">Mi Pre-Orden Escolar</h3>
<span id="modalCartStudentName" style="display: none; font-size: 0.76rem; color: #0284c7; font-weight: 700; margin-top: 2px;"></span>
</div>
<button onclick="closeCartModal()" style="background: none; border: none; font-size: 1.2rem; cursor: pointer; color: #64748b;">✕</button>
</div>
<div style="margin-bottom: 14px; background: #f8fafc; border: 1.5px solid #e2e8f0; border-radius: 12px; padding: 12px;">
<label style="display: block; font-size: 0.82rem; font-weight: 800; color: #0f172a; margin-bottom: 6px; display: flex; align-items: center; gap: 6px;">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#0284c7" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>
<span>¿Para cuál recreo deseas tu orden?</span>
</label>
<select id="momentoEntregaSelect" style="width: 100%; box-sizing: border-box; padding: 10px 12px; border-radius: 10px; border: 1.5px solid #cbd5e1; font-weight: 700; font-size: 0.88rem; color: #1e293b; background: white; outline: none; cursor: pointer;">
<option value="recreo_1">🔔 1er Recreo de la Mañana (9:30 AM)</option>
<option value="almuerzo">🍲 Hora de Almuerzo (11:45 AM)</option>
<option value="recreo_2">⏰ 2do Recreo de la Tarde (1:45 PM)</option>
</select>
<div style="font-size: 0.72rem; color: #64748b; margin-top: 6px; display: flex; align-items: center; gap: 4px;">
<span>⚡</span> <span>La soda preparará tus alimentos frescos para este horario.</span>
</div>
</div>
<!-- LISTA DE PRODUCTOS EN EL CARRITO -->
<div id="cartItemsList" style="max-height: 220px; overflow-y: auto; margin-bottom: 14px;">
<!-- Se llena dinámicamente -->
</div>
<div style="border-top: 1px solid #e2e8f0; padding-top: 10px; margin-bottom: 14px; display: flex; flex-direction: column; gap: 4px;">
<div style="display: flex; justify-content: space-between; align-items: center;">
<span style="font-weight: 800; color: #334155; font-size: 0.92rem;">Total a Reservar (Monto Flotante):</span>
<span id="modalCartTotal" style="font-size: 1.3rem; font-weight: 900; color: #0284c7;">₡0</span>
</div>
<div style="font-size: 0.73rem; color: #64748b; text-align: right;">
🔒 El monto queda retenido y se rebajará definitivamente al retirar en la soda.
</div>
</div>
<button id="btnConfirmarOrden" onclick="submitPreOrder()" style="width: 100%; padding: 12px; background: #10b981; color: white; border: none; border-radius: 12px; font-weight: 800; font-size: 1rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></svg> <span>Confirmar Pre-Orden (Monto Flotante)</span>
</button>
</div>
</div>
<!-- MODAL: PANEL DE PADRES (RECARGA SINPE Y LÍMITES) -->
<div class="modal-qr-backdrop" id="modalPadres" style="display: none;" onclick="toggleParentPanel(false, event)">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 440px; text-align: left;">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #e2e8f0; padding-bottom: 10px; margin-bottom: 14px;">
<div>
<h3 style="color: #0f172a; font-size: 1.15rem; font-weight: 800;">Portal de Padres SiboPay</h3>
<span style="font-size: 0.75rem; color: #64748b;">Control de meriendas, nutrición y recargas SINPE</span>
</div>
<button onclick="toggleParentPanel(false)" style="background: none; border: none; font-size: 1.2rem; cursor: pointer; color: #64748b;">✕</button>
</div>
<!-- SELECTOR DE HIJO PARA PADRES -->
<div id="parentChildSelectorBox" style="display: none; margin-bottom: 14px; background: #e0f2fe; padding: 10px 12px; border-radius: 12px; border: 1.5px solid #bae6fd;">
<label for="parentChildSelect" style="display: block; font-size: 0.76rem; font-weight: 800; color: #0369a1; margin-bottom: 4px;">Viendo información de:</label>
<select id="parentChildSelect" onchange="onParentChildSelect(this.value)" style="width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid #7dd3fc; font-weight: 800; color: #0c4a6e; background: white; font-size: 0.9rem;">
</select>
</div>
<!-- RECARGA SINPE MÓVIL (MONTO ESCRITO Y ACCESOS RÁPIDOS) -->
<div style="background: #f0fdf4; border: 1.5px solid #86efac; border-radius: 14px; padding: 14px; margin-bottom: 16px;">
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px;">
<div style="display: flex; align-items: center; gap: 8px;">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="#16a34a" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="20" x="5" y="2" rx="2" ry="2"/><path d="M12 18h.01"/></svg>
<div>
<strong style="color: #166534; font-size: 0.95rem;">Recarga por SINPE Móvil</strong>
<p style="font-size: 0.74rem; color: #15803d;">Número de la Soda: <strong>8888-SODA (7632)</strong></p>
</div>
</div>
<span style="font-size: 0.7rem; color: #166534; background: #dcfce7; font-weight: 800; padding: 2px 8px; border-radius: 6px;">Acreditación Inmediata</span>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px;">
<div>
<label for="inputCustomSinpe" style="display: block; font-size: 0.76rem; font-weight: 800; color: #166534; margin-bottom: 4px;">
Monto a recargar (₡):
</label>
<div style="position: relative;">
<span style="position: absolute; left: 10px; top: 50%; transform: translateY(-50%); font-weight: 900; color: #166534; font-size: 1.05rem;">₡</span>
<input type="tel" inputmode="numeric" pattern="[0-9]*" id="inputCustomSinpe" placeholder="Ej: 3000" style="width: 100%; padding: 10px 10px 10px 28px; border-radius: 10px; border: 1.5px solid #86efac; font-size: 1.05rem; font-weight: 800; color: #166534; background: white; box-sizing: border-box;">
</div>
</div>
<div>
<label for="inputCustomSinpeComprobante" style="display: block; font-size: 0.76rem; font-weight: 800; color: #166534; margin-bottom: 4px;">
N° Comprobante:
</label>
<input type="text" id="inputCustomSinpeComprobante" placeholder="Ej: 894321" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid #86efac; font-size: 1.05rem; font-weight: 800; color: #166534; background: white; box-sizing: border-box;">
</div>
</div>
<button type="button" onclick="customSinpeRecharge()" style="width: 100%; padding: 12px; background: linear-gradient(135deg, #16a34a, #15803d); color: white; border: none; border-radius: 10px; font-weight: 900; font-size: 0.95rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 4px 10px rgba(22, 163, 74, 0.3);">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg> Validar SINPE
</button>
</div>
<!-- CONFIGURACIÓN DE LÍMITE DIARIO (ESCRITO Y DESLIZABLE) -->
<div style="background: #f0f9ff; border: 2px solid #38bdf8; border-radius: 14px; padding: 14px; margin-bottom: 16px; box-shadow: 0 2px 8px rgba(56, 189, 248, 0.15);">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;">
<div>
<strong style="font-size: 0.92rem; color: #0369a1; display: flex; align-items: center; gap: 6px;"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#0284c7" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg> Límite de Gasto Máximo Diario</strong>
<span style="font-size: 0.74rem; color: #64748b;">Monto máximo que el estudiante puede gastar por día</span>
</div>
<span id="lblParentDailyLimit" style="font-size: 1.05rem; color: #0284c7; font-weight: 900; background: white; border: 1.5px solid #bae6fd; padding: 3px 10px; border-radius: 8px;">₡3.000</span>
</div>
<label for="inputCustomDailyLimit" style="display: block; font-size: 0.8rem; font-weight: 800; color: #0369a1; margin-bottom: 4px;">
Digita o escribe el límite en colones:
</label>
<div style="display: flex; gap: 8px; margin-bottom: 8px;">
<div style="position: relative; flex: 1;">
<span style="position: absolute; left: 10px; top: 50%; transform: translateY(-50%); font-weight: 900; color: #0284c7; font-size: 1.1rem;">₡</span>
<input type="tel" inputmode="numeric" pattern="[0-9]*" id="inputCustomDailyLimit" placeholder="Ej: 3000" oninput="onCustomDailyLimitInput(this.value)" style="width: 100%; padding: 10px 10px 10px 30px; border-radius: 10px; border: 2px solid #0284c7; font-size: 1.1rem; font-weight: 900; color: #0f172a; background: white; box-shadow: inset 0 1px 2px rgba(0,0,0,0.06);">
</div>
<button type="button" onclick="saveCustomDailyLimit()" style="padding: 10px 16px; background: linear-gradient(135deg, #0284c7, #0369a1); color: white; border: none; border-radius: 10px; font-weight: 900; font-size: 0.85rem; cursor: pointer; white-space: nowrap; box-shadow: 0 2px 6px rgba(2, 132, 199, 0.35); display: inline-flex; align-items: center; gap: 6px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg> Guardar
</button>
</div>
<div id="msgDailyLimitFeedback" style="display: none; font-size: 0.76rem; font-weight: 800; margin-bottom: 8px; padding: 4px 8px; border-radius: 6px; background: #dcfce7; color: #166534; text-align: center;"></div>
<!-- ACCESOS RÁPIDOS DE LÍMITES COMUNES -->
<div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin-bottom: 10px;">
<button type="button" onclick="setWrittenDailyLimit(1500)" style="padding: 6px 2px; background: white; border: 1.5px solid #cbd5e1; border-radius: 8px; font-size: 0.74rem; font-weight: 800; color: #1e293b; cursor: pointer;">₡1.500</button>
<button type="button" onclick="setWrittenDailyLimit(2500)" style="padding: 6px 2px; background: white; border: 1.5px solid #cbd5e1; border-radius: 8px; font-size: 0.74rem; font-weight: 800; color: #1e293b; cursor: pointer;">₡2.500</button>
<button type="button" onclick="setWrittenDailyLimit(3500)" style="padding: 6px 2px; background: white; border: 1.5px solid #cbd5e1; border-radius: 8px; font-size: 0.74rem; font-weight: 800; color: #1e293b; cursor: pointer;">₡3.500</button>
<button type="button" onclick="setWrittenDailyLimit(5000)" style="padding: 6px 2px; background: white; border: 1.5px solid #cbd5e1; border-radius: 8px; font-size: 0.74rem; font-weight: 800; color: #1e293b; cursor: pointer;">₡5.000</button>
</div>
<div style="font-size: 0.72rem; color: #64748b; margin-bottom: 2px;">O desliza para ajustar rápido:</div>
<input type="range" id="rangeDailyLimit" min="1000" max="10000" step="500" value="3000" oninput="onDailyLimitSlider(this.value)" style="width: 100%;">
<div style="display: flex; justify-content: space-between; font-size: 0.7rem; color: #64748b; margin-top: 2px;">
<span>₡1.000 min</span>
<span>₡10.000 max</span>
</div>
</div>
<!-- CONTROL PARENTAL: PERMITIR O BLOQUEAR TRANSFERENCIAS ENTRE COMPAÑEROS -->
<div style="background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center;">
<div>
<strong style="font-size: 0.85rem; color: #1e293b; display: flex; align-items: center; gap: 6px;"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#0284c7" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="m16 3 4 4-4 4"/><path d="M20 7H4"/><path d="m8 21-4-4 4-4"/><path d="M4 17h16"/></svg> RecreoTransfer entre Compas</strong>
<span style="font-size: 0.72rem; color: #64748b;">Permitir transferir saldo a compañeros de clase</span>
</div>
<input type="checkbox" id="chkParentAllowTransfer" onchange="onToggleAllowTransfer(this.checked)" style="width: 22px; height: 22px; cursor: pointer; accent-color: #0284c7;" checked>
</div>
<!-- CONTROL PARENTAL: BLOQUEO BIOMÉTRICO / PIN DEL CARNÉ QR -->
<div style="background: #f0fdf4; border: 1.5px solid #86efac; border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 32px; height: 32px; border-radius: 8px; background: #dcfce7; color: #16a34a; display: flex; align-items: center; justify-content: center; flex-shrink: 0;">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>
</div>
<div>
<strong style="font-size: 0.85rem; color: #166534; display: block;">Bloqueo Huella / Face ID / PIN</strong>
<span style="font-size: 0.72rem; color: #475569;">Exigir autenticación antes de mostrar el carné QR</span>
</div>
</div>
<button type="button" onclick="openQrSecuritySettings()" style="background: #16a34a; color: white; border: none; padding: 7px 14px; border-radius: 8px; font-weight: 800; font-size: 0.78rem; cursor: pointer; white-space: nowrap; box-shadow: 0 2px 6px rgba(22, 163, 74, 0.25);">
Configurar
</button>
</div>
<!-- RESTABLECER PIN Y CONTRASEÑA ESCOLAR DEL ALUMNO -->
<div style="background: #f8fafc; border: 1.5px dashed #cbd5e1; border-radius: 14px; padding: 14px; margin-bottom: 16px;">
<div style="display: flex; align-items: center; gap: 8px; margin-bottom: 8px;">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#475569" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="11" x="3" y="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg>
<div>
<strong style="font-size: 0.88rem; color: #1e293b; display: block;">Seguridad y Contraseña del Alumno</strong>
<span style="font-size: 0.72rem; color: #64748b;">Cambia el PIN de transferencias o la contraseña de acceso</span>
</div>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px;">
<div>
<label style="display: block; font-size: 0.74rem; font-weight: 800; color: #475569; margin-bottom: 3px;">Nuevo PIN (4 dígitos):</label>
<input type="password" inputmode="numeric" maxlength="4" id="inputParentNewPin" placeholder="1234" style="width: 100%; padding: 8px; border-radius: 8px; border: 1.5px solid #cbd5e1; font-weight: 900; letter-spacing: 2px; text-align: center; box-sizing: border-box;">
</div>
<div>
<label style="display: block; font-size: 0.74rem; font-weight: 800; color: #475569; margin-bottom: 3px;">Nueva Contraseña:</label>
<input type="text" id="inputParentNewPass" placeholder="Ej: 1234" style="width: 100%; padding: 8px; border-radius: 8px; border: 1.5px solid #cbd5e1; font-weight: 800; box-sizing: border-box;">
</div>
</div>
<button type="button" onclick="saveParentChildAccess()" style="width: 100%; padding: 10px; background: #334155; color: white; border: none; border-radius: 8px; font-weight: 800; font-size: 0.82rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg> Guardar Nuevas Credenciales
</button>
</div>
</div>
<!-- HISTORIAL RECIENTE -->
<h4 style="font-size: 0.85rem; font-weight: 800; color: #1e293b; margin-bottom: 8px;">Consumos Recientes</h4>
<div id="parentHistoryList" style="max-height: 140px; overflow-y: auto; font-size: 0.78rem;">
<!-- Se llena dinámicamente -->
</div>
</div>
</div>
<!-- MODAL: REGISTRAR NUEVO ESTUDIANTE (ADMIN) -->
<div class="modal-qr-backdrop" id="modalNewStudent" style="display: none;">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 460px; text-align: left;">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #e2e8f0; padding-bottom: 10px; margin-bottom: 14px;">
<div>
<h3 style="color: #0f172a; font-size: 1.15rem; font-weight: 800;">Registrar Nuevo Alumno</h3>
<span style="font-size: 0.75rem; color: #64748b;">Genera carné oficial y código QR al instante</span>
</div>
<button onclick="closeNewStudentModal()" style="background: none; border: none; font-size: 1.2rem; cursor: pointer; color: #64748b;">✕</button>
</div>
<form id="formNewStudent" onsubmit="submitNewStudent(event)">
<!-- Selector de Escuela Destino (Visible en Modo Developer) -->
<div id="newEstEscuelaContainer" style="display: none; margin-bottom: 12px; background: #f0fdf4; border: 1.5px solid #86efac; border-radius: 10px; padding: 10px;">
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: #166534; margin-bottom: 4px;">🏫 Escuela / Institución Destino *:</label>
<select id="newEstEscuelaSelect" style="width: 100%; padding: 8px 10px; border-radius: 8px; border: 1.5px solid #86efac; font-weight: 800; box-sizing: border-box; background: #ffffff; color: #0f172a;">
<!-- Opciones cargadas dinámicamente -->
</select>
<small style="display: block; font-size: 0.70rem; color: #15803d; margin-top: 3px;">El estudiante se registrará en esta sede y heredará su código institucional.</small>
</div>
<div style="margin-bottom: 10px;">
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 3px;">Tipo de Perfil / Negocio:</label>
<select id="newEstTipo" style="width: 100%; padding: 8px 10px; border-radius: 8px; border: 1.5px solid var(--border); font-weight: 800; box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
<option value="EST">Estudiante / Alumno (Escuela o Colegio)</option>
<option value="EMP">Colaborador / Empleado (Empresa o Comedor)</option>
<option value="EVT">Asistente / Pulsera (Evento o Feria)</option>
<option value="SOC">Socio / Miembro (Club o Gimnasio)</option>
</select>
</div>
<div style="margin-bottom: 10px;">
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 3px;">Nombre Completo *:</label>
<input type="text" id="newEstNombre" placeholder="Ej: Daniel Sánchez Méndez" required style="width: 100%; padding: 8px 10px; border-radius: 8px; border: 1.5px solid var(--border); font-weight: 700; box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 10px;">
<div>
<label style="display: block; font-size: 0.75rem; font-weight: 700; color: #334155; margin-bottom: 3px;">Edad:</label>
<input type="number" id="newEstEdad" value="8" min="5" max="19" required style="width: 100%; padding: 8px; border-radius: 8px; border: 1.5px solid #cbd5e1; font-weight: 700; box-sizing: border-box;">
</div>
<div>
<label style="display: block; font-size: 0.75rem; font-weight: 700; color: #334155; margin-bottom: 3px;">Grado:</label>
<input type="text" id="newEstGrado" placeholder="Ej: 3° Grado" required style="width: 100%; padding: 8px; border-radius: 8px; border: 1.5px solid #cbd5e1; font-weight: 700; box-sizing: border-box;">
</div>
<div>
<label style="display: block; font-size: 0.75rem; font-weight: 700; color: #334155; margin-bottom: 3px;">Sección:</label>
<input type="text" id="newEstSeccion" placeholder="Ej: 3-B" required style="width: 100%; padding: 8px; border-radius: 8px; border: 1.5px solid #cbd5e1; font-weight: 700; box-sizing: border-box;">
</div>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px;">
<div>
<label style="display: block; font-size: 0.75rem; font-weight: 700; color: #334155; margin-bottom: 3px;">Saldo Inicial (₡):</label>
<input type="tel" inputmode="numeric" id="newEstSaldo" value="2000" style="width: 100%; padding: 8px; border-radius: 8px; border: 1.5px solid #cbd5e1; font-weight: 700; box-sizing: border-box;">
</div>
<div>
<label style="display: block; font-size: 0.75rem; font-weight: 700; color: #334155; margin-bottom: 3px;">Límite Diario (₡):</label>
<input type="tel" inputmode="numeric" id="newEstLimite" value="2500" style="width: 100%; padding: 8px; border-radius: 8px; border: 1.5px solid #cbd5e1; font-weight: 700; box-sizing: border-box;">
</div>
</div>
<div style="margin-bottom: 10px;">
<label style="display: block; font-size: 0.75rem; font-weight: 700; color: #334155; margin-bottom: 3px;">Alergias o Restricciones Médicas:</label>
<input type="text" id="newEstAlergias" placeholder="Ej: Ninguna conocida, Alergia al gluten..." style="width: 100%; padding: 8px; border-radius: 8px; border: 1.5px solid #cbd5e1; box-sizing: border-box;">
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px;">
<div>
<label style="display: block; font-size: 0.75rem; font-weight: 700; color: #334155; margin-bottom: 3px;">Nombre del Padre:</label>
<input type="text" id="newEstPadre" placeholder="Ej: Juan Sánchez" style="width: 100%; padding: 8px; border-radius: 8px; border: 1.5px solid #cbd5e1; box-sizing: border-box;">
</div>
<div>
<label style="display: block; font-size: 0.75rem; font-weight: 700; color: #334155; margin-bottom: 3px;">Teléfono Padre:</label>
<input type="text" id="newEstTel" placeholder="+506 8888-0000" style="width: 100%; padding: 8px; border-radius: 8px; border: 1.5px solid #cbd5e1; box-sizing: border-box;">
</div>
</div>
<button type="submit" id="btnSubmitNewStudent" style="width: 100%; padding: 12px; background: linear-gradient(135deg, #0284c7, #0369a1); color: white; border: none; border-radius: 12px; font-weight: 900; font-size: 0.95rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg> Guardar y Generar Carné
</button>
</form>
</div>
</div>
<!-- MODAL: CREAR / EDITAR PRODUCTO (ADMIN) -->
<div class="modal-qr-backdrop" id="modalAdminProduct" style="display: none;">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 480px; text-align: left; max-height: 90vh; overflow-y: auto;">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 14px;">
<div>
<h3 id="modalProductTitle" style="color: var(--text-main); font-size: 1.15rem; font-weight: 800; margin: 0; display: flex; align-items: center; gap: 6px;"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg> <span>Crear Nuevo Producto</span></h3>
<span style="font-size: 0.75rem; color: var(--text-muted);">Alimentos, bebidas y meriendas escolares</span>
</div>
<button type="button" onclick="closeAdminProductModal()" style="background: none; border: none; font-size: 1.25rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
</div>
<form id="formAdminProduct" onsubmit="submitAdminProduct(event)">
<input type="hidden" id="adminProdId" value="">
<div style="margin-bottom: 10px;">
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 3px;">Nombre del Alimento / Bebida *:</label>
<input type="text" id="adminProdNombre" placeholder="Ej: Empanada de Pollo, Fresco Natural..." required style="width: 100%; padding: 9px 12px; border-radius: 8px; border: 1.5px solid var(--border); font-weight: 700; box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px;">
<div>
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 3px;">Categoría *:</label>
<select id="adminProdCategoria" required style="width: 100%; padding: 9px; border-radius: 8px; border: 1.5px solid var(--border); font-weight: 700; box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
<!-- Opciones dinámicas de categorías -->
</select>
</div>
<div>
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 3px;">Precio en Colones (₡) *:</label>
<input type="number" id="adminProdPrecio" placeholder="Ej: 1200" min="50" step="50" required style="width: 100%; padding: 9px; border-radius: 8px; border: 1.5px solid var(--border); font-weight: 800; color: #0284c7; box-sizing: border-box; background: var(--card-bg);">
</div>
</div>
<div style="margin-bottom: 12px;">
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 6px;">Ícono Vectorial del Alimento:</label>
<input type="hidden" id="adminProdIcono" value="sandwich">
<div style="display: flex; gap: 12px; align-items: center; background: var(--bg-main, #f8fafc); border: 1.5px solid var(--border); border-radius: 12px; padding: 10px;">
<div id="adminProdIconPreview" style="flex-shrink: 0;"></div>
<div style="flex: 1; min-width: 0;">
<div style="display: flex; gap: 6px; flex-wrap: wrap;" id="adminProdIconPickerList"></div>
</div>
</div>
</div>
<div style="margin-bottom: 10px;">
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 3px;">Descripción (opcional):</label>
<input type="text" id="adminProdDescripcion" placeholder="Ej: Rellena de pollo mechado, horneada al día" style="width: 100%; padding: 8px 10px; border-radius: 8px; border: 1.5px solid var(--border); font-size: 0.85rem; box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
</div>
<div style="background: var(--bg-main, #f8fafc); border: 1px solid var(--border, #e2e8f0); border-radius: 10px; padding: 10px; margin-bottom: 12px;">
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: center;">
<div>
<label style="display: flex; align-items: center; gap: 6px; font-size: 0.8rem; font-weight: 800; cursor: pointer; color: var(--text-main);">
<input type="checkbox" id="adminProdControlStock" checked onchange="toggleStockInput(this.checked)">
<span>Controlar Existencias</span>
</label>
<div style="margin-top: 6px;" id="boxProdStockCount">
<label style="display: block; font-size: 0.72rem; color: var(--text-muted); font-weight: 700;">Stock Actual:</label>
<input type="number" id="adminProdStock" value="10" min="0" style="width: 100%; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border); font-weight: 800; background: var(--card-bg); color: var(--text-main); box-sizing: border-box;">
</div>
</div>
<div>
<label style="display: block; font-size: 0.75rem; font-weight: 800; color: var(--text-main); margin-bottom: 4px;">Clasificación Nutricional:</label>
<select id="adminProdMep" style="width: 100%; padding: 7px; border-radius: 6px; border: 1px solid var(--border); font-weight: 700; font-size: 0.8rem; background: var(--card-bg); color: var(--text-main); box-sizing: border-box;">
<option value="1">Saludable (Permitido)</option>
<option value="0">Consumo Ocasional</option>
</select>
</div>
</div>
</div>
<div style="display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px;">
<button type="button" id="btnDeleteProduct" onclick="handleDeleteProduct()" style="display: none; padding: 10px 14px; background: #fee2e2; color: #dc2626; border: 1px solid #fecaca; border-radius: 10px; font-weight: 800; font-size: 0.84rem; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg> Eliminar
</button>
<button type="button" onclick="closeAdminProductModal()" style="padding: 10px 14px; background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; border-radius: 10px; font-weight: 800; font-size: 0.84rem; cursor: pointer;">
Cancelar
</button>
<button type="submit" id="btnSaveProductSubmit" style="padding: 10px 18px; background: linear-gradient(135deg, #0284c7, #0369a1); color: white; border: none; border-radius: 10px; font-weight: 900; font-size: 0.88rem; cursor: pointer; display: flex; align-items: center; gap: 6px; box-shadow: 0 2px 6px rgba(2, 132, 199, 0.3);">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg> <span>Guardar Producto</span>
</button>
</div>
</form>
</div>
</div>
<!-- MODAL: CREAR / EDITAR EMPLEADO O CAJERO (ADMIN) -->
<div class="modal-qr-backdrop" id="modalAdminStaff" style="display: none;">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 460px; text-align: left;">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 14px;">
<div>
<h3 id="modalStaffTitle" style="color: var(--text-main); font-size: 1.15rem; font-weight: 800; margin: 0; display: flex; align-items: center; gap: 6px;"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg> <span>Nuevo Empleado / Cajero</span></h3>
<span style="font-size: 0.75rem; color: var(--text-muted);">Crea credenciales de acceso para la soda</span>
</div>
<button type="button" onclick="closeAdminStaffModal()" style="background: none; border: none; font-size: 1.25rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
</div>
<form id="formAdminStaff" onsubmit="submitAdminStaff(event)">
<input type="hidden" id="adminStaffId" value="">
<div style="margin-bottom: 10px;">
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 3px;">Nombre Completo *:</label>
<input type="text" id="adminStaffNombre" placeholder="Ej: Carlos Murillo Vega" required style="width: 100%; padding: 9px 12px; border-radius: 8px; border: 1.5px solid var(--border); font-weight: 700; box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px;">
<div>
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 3px;">Usuario de Acceso *:</label>
<input type="text" id="adminStaffUsername" placeholder="cajero1" required style="width: 100%; padding: 9px; border-radius: 8px; border: 1.5px solid var(--border); font-weight: 700; box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
</div>
<div>
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 3px;">Rol en el Sistema *:</label>
<select id="adminStaffRol" required style="width: 100%; padding: 9px; border-radius: 8px; border: 1.5px solid var(--border); font-weight: 800; box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
<option value="cajero">Cajero (Terminal POS)</option>
<option value="vendedor">Vendedor / Despacho</option>
<option value="admin">Administrador</option>
</select>
</div>
</div>
<div style="margin-bottom: 10px;">
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 3px;" id="lblStaffPassword">Contraseña de Acceso *:</label>
<input type="password" id="adminStaffPassword" placeholder="••••••••" style="width: 100%; padding: 9px 12px; border-radius: 8px; border: 1.5px solid var(--border); font-weight: 700; box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
<small id="hintStaffPassword" style="display: none; font-size: 0.7rem; color: var(--text-muted); margin-top: 3px;">Deja en blanco para conservar la contraseña actual.</small>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px;">
<div>
<label style="display: block; font-size: 0.78rem; font-weight: 700; color: var(--text-main); margin-bottom: 3px;">Teléfono:</label>
<input type="text" id="adminStaffTel" placeholder="+506 8888-0000" style="width: 100%; padding: 8px 10px; border-radius: 8px; border: 1.5px solid var(--border); box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
</div>
<div>
<label style="display: block; font-size: 0.78rem; font-weight: 700; color: var(--text-main); margin-bottom: 3px;">Email (opcional):</label>
<input type="email" id="adminStaffEmail" placeholder="[email protected]" style="width: 100%; padding: 8px 10px; border-radius: 8px; border: 1.5px solid var(--border); box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
</div>
</div>
<div style="display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px;">
<button type="button" onclick="closeAdminStaffModal()" style="padding: 10px 14px; background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; border-radius: 10px; font-weight: 800; font-size: 0.84rem; cursor: pointer;">
Cancelar
</button>
<button type="submit" id="btnSaveStaffSubmit" style="padding: 10px 18px; background: linear-gradient(135deg, #10b981, #059669); color: white; border: none; border-radius: 10px; font-weight: 900; font-size: 0.88rem; cursor: pointer; display: flex; align-items: center; gap: 6px; box-shadow: 0 2px 6px rgba(16, 185, 129, 0.3);">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg> <span>Guardar Empleado</span>
</button>
</div>
</form>
</div>
</div>
<!-- MODAL: RECREOTRANSFER (PASAR PLATA A UN COMPAÑERO ESCANEANDO SU QR O CARNÉ) -->
<div class="modal-qr-backdrop" id="modalTransfer" style="display: none;">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 420px; text-align: left;">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #e2e8f0; padding-bottom: 10px; margin-bottom: 12px;">
<div>
<h3 style="color: #0f172a; font-size: 1.15rem; font-weight: 800; display: flex; align-items: center; gap: 6px;"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#0284c7" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="m16 3 4 4-4 4"/><path d="M20 7H4"/><path d="m8 21-4-4 4-4"/><path d="M4 17h16"/></svg> Pasar Plata a un Compa</h3>
<span style="font-size: 0.75rem; color: #64748b;">Escanea el carné o celular de tu amigo</span>
</div>
<button onclick="closeTransferModal()" style="background: none; border: none; font-size: 1.2rem; cursor: pointer; color: #64748b;">✕</button>
</div>
<!-- PASO 1: ESCANEAR CÁMARA O ELEGIR COMPAÑERO DE PRUEBA -->
<div id="transferStepScan">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px;">
<span style="font-size: 0.75rem; color: #64748b; font-weight: 700;" id="transferCameraStatus">Iniciando cámara...</span>
<div style="display: flex; gap: 6px;">
<button id="btnFlipTransferCamera" type="button" onclick="flipTransferCamera()" style="display:none; padding: 3px 8px; background: #334155; color: white; border: none; border-radius: 6px; font-size: 0.72rem; font-weight: 700; cursor: pointer; align-items: center; gap: 4px;"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21.5 2v6h-6M21.34 15.57a10 10 0 1 1-.57-8.38l5.67-5.67"/></svg> Girar</button>
<button id="btnRetryTransferCamera" type="button" onclick="startTransferCamera(true)" style="display:none; padding: 3px 8px; background: #0284c7; color: white; border: none; border-radius: 6px; font-size: 0.72rem; font-weight: 700; cursor: pointer; align-items: center; gap: 4px;"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"/><circle cx="12" cy="13" r="3"/></svg> Activar</button>
</div>
</div>
<div style="position: relative; border-radius: 12px; overflow: hidden; background: #000; min-height: 170px; margin-bottom: 10px; display: flex; align-items: center; justify-content: center;">
<video id="transferVideo" style="width: 100%; height: 170px; object-fit: cover;" autoplay playsinline webkit-playsinline muted></video>
<div class="laser-scan-line"></div>
<div id="transferCameraHelp" style="display: none; position: absolute; inset: 0; background: rgba(15, 23, 42, 0.92); padding: 14px; text-align: center; flex-direction: column; justify-content: center; align-items: center; gap: 10px; z-index: 10;">
<svg width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="#38bdf8" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"/><circle cx="12" cy="13" r="3"/></svg>
<div id="transferCameraHelpText" style="font-size: 0.76rem; color: #f8fafc; line-height: 1.35;">Toca el botón para permitir la cámara</div>
<div id="transferCameraActionContainer" style="display: flex; flex-direction: column; gap: 8px; width: 100%; align-items: center;">
<button id="btnAllowTransferCamera" type="button" onclick="startTransferCamera(true)" style="padding: 8px 18px; background: #0284c7; color: white; border: none; border-radius: 8px; font-weight: 800; font-size: 0.82rem; cursor: pointer; box-shadow: 0 4px 10px rgba(2, 132, 199, 0.3);">
Permitir Cámara
</button>
</div>
</div>
</div>
<!-- ACCESO DIRECTO PARA SUBIR O TOMAR FOTO DEL QR CON LA CÁMARA NATIVA -->
<div style="display: flex; justify-content: center; margin-bottom: 12px;">
<label style="cursor: pointer; display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; background: #f0fdf4; border: 1.5px dashed #86efac; border-radius: 10px; font-size: 0.78rem; font-weight: 800; color: #166534; box-shadow: 0 1px 3px rgba(0,0,0,0.04);">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"/><circle cx="12" cy="13" r="3"/></svg> Tomar foto del QR o carné
<input type="file" accept="image/*" capture="environment" style="display: none;" onchange="handleTransferQrPhoto(event)">
</label>
</div>
<div style="text-align: center; margin-bottom: 12px;">
<span style="font-size: 0.74rem; color: #64748b; font-weight: 700;">O selecciona a un compañero para transferirle:</span>
<div id="quickTransferFriends" style="display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-top: 8px;">
<!-- Se llena dinámicamente con los otros estudiantes -->
</div>
</div>
</div>
<!-- PASO 2: CONFIRMAR COMPAÑERO Y MONTO -->
<div id="transferStepConfirm" style="display: none;">
<!-- Tarjeta del receptor -->
<div style="background: #f0fdf4; border: 1.5px solid #86efac; border-radius: 14px; padding: 12px; display: flex; align-items: center; gap: 12px; margin-bottom: 14px;">
<div id="transferTargetAvatar" class="transfer-target-avatar-badge">ES</div>
<div style="flex: 1;">
<div style="font-size: 0.7rem; color: #15803d; font-weight: 800; text-transform: uppercase;">Vas a transferir a:</div>
<h4 id="transferTargetName" style="font-size: 1rem; font-weight: 900; color: #0f172a; line-height: 1.2;">Nombre</h4>
<span id="transferTargetGrade" style="font-size: 0.75rem; color: #64748b;">Grado y Sección</span>
</div>
<button onclick="resetTransferScan()" style="background: #e2e8f0; border: none; padding: 4px 8px; border-radius: 6px; font-size: 0.75rem; font-weight: 700; cursor: pointer;">Cambiar</button>
</div>
<!-- MONTO A PASAR -->
<label style="display: block; font-size: 0.82rem; font-weight: 800; color: #1e293b; margin-bottom: 6px;">
¿Cuánto le vas a pasar?
</label>
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px;">
<button type="button" class="transfer-amount-btn active" id="btnTransfer500" onclick="setTransferAmount(500, this)">₡500</button>
<button type="button" class="transfer-amount-btn" id="btnTransfer1000" onclick="setTransferAmount(1000, this)">₡1.000</button>
<button type="button" class="transfer-amount-btn" id="btnTransfer1500" onclick="setTransferAmount(1500, this)">₡1.500</button>
</div>
<div style="margin-bottom: 12px;">
<input type="tel" inputmode="numeric" pattern="[0-9]*" id="inputTransferCustomAmount" value="500" placeholder="Otro monto (ej. 750)" style="width: 100%; padding: 10px; border-radius: 10px; border: 1.5px solid #cbd5e1; font-size: 1.05rem; font-weight: 800; color: #0284c7; box-sizing: border-box; text-align: center;">
</div>
<!-- MOTIVO OPCIONAL -->
<div style="margin-bottom: 12px;">
<label style="display: block; font-size: 0.75rem; font-weight: 700; color: #64748b; margin-bottom: 4px;">Motivo (Opcional):</label>
<input type="text" id="inputTransferMotivo" placeholder="Ej: Mitad de la empanada, fresco..." style="width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid #cbd5e1; font-size: 0.85rem; box-sizing: border-box;">
</div>
<!-- PIN DE SEGURIDAD (TECLADO NATIVO DEL TELÉFONO) -->
<div style="background: #f8fafc; border: 1.5px dashed #cbd5e1; border-radius: 14px; padding: 14px; margin-bottom: 14px; text-align: center;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;">
<label for="inputTransferPin" style="font-size: 0.8rem; font-weight: 800; color: #0f172a; display: flex; align-items: center; gap: 5px;"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#475569" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="11" x="3" y="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg> Digita tu PIN de seguridad:</label>
<span style="font-size: 0.72rem; color: #64748b; font-weight: 700;">(4 dígitos)</span>
</div>
<div style="position: relative; max-width: 240px; margin: 0 auto;">
<input type="password" inputmode="numeric" pattern="[0-9]*" maxlength="4" autocomplete="one-time-code" id="inputTransferPin" placeholder="••••" style="width: 100%; text-align: center; font-size: 1.8rem; letter-spacing: 10px; padding: 10px 42px 10px 18px; border-radius: 12px; border: 2px solid #cbd5e1; font-weight: 900; background: white; color: #0f172a; box-sizing: border-box; outline: none; transition: border-color 0.2s;" onfocus="this.style.borderColor='#0284c7'" onblur="this.style.borderColor='#cbd5e1'">
<button type="button" id="btnTogglePin" onclick="togglePinVisibility()" style="position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; font-size: 1.1rem; cursor: pointer; color: #64748b; padding: 4px; display: flex; align-items: center;" title="Ver/Ocultar PIN"><svg id="iconTogglePin" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg></button>
</div>
<div style="font-size: 0.72rem; color: #64748b; margin-top: 6px; font-weight: 600;">Se abrirá automáticamente el teclado numérico de tu teléfono</div>
</div>
<button id="btnConfirmTransfer" onclick="executeP2PTransfer()" style="width: 100%; padding: 14px; background: linear-gradient(135deg, #10b981, #059669); color: white; border: none; border-radius: 14px; font-weight: 900; font-size: 1.05rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg> <span id="lblBtnConfirmTransferText">Enviar ₡500 al Instante</span>
</button>
</div>
</div>
</div>
<!-- MODAL: VINCULAR HIJO POR QR O CÓDIGO (PORTAL PADRES) -->
<div class="modal-qr-backdrop" id="modalScanChildQr" style="display: none;" onclick="closeScanChildQrModal(event)">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 440px; text-align: center; border-radius: 20px;">
<!-- CABECERA -->
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; border-bottom: 1px solid var(--border); padding-bottom: 10px;">
<div style="display: flex; align-items: center; gap: 8px;">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="#0284c7" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>
<strong style="font-size: 1.05rem; color: var(--text-main);">Vincular Estudiante</strong>
</div>
<button type="button" onclick="closeScanChildQrModal()" style="background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
</div>
<!-- VISTA 1: SELECCIÓN DE MÉTODO (PESTAÑAS) -->
<div id="linkChildViewTabs">
<div style="display: flex; gap: 6px; background: #f1f5f9; padding: 4px; border-radius: 12px; margin-bottom: 14px;">
<button type="button" id="tabBtnLinkCamera" onclick="switchLinkChildTab('camera')" style="flex: 1; padding: 9px 8px; border: none; border-radius: 8px; font-weight: 800; font-size: 0.82rem; cursor: pointer; transition: all 0.2s; background: #ffffff; color: #0284c7; box-shadow: 0 2px 4px rgba(0,0,0,0.06);">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" style="display:inline-block; vertical-align:middle; margin-right:4px;"><path d="M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"/><circle cx="12" cy="13" r="3"/></svg> Escanear con Cámara
</button>
<button type="button" id="tabBtnLinkCode" onclick="switchLinkChildTab('code')" style="flex: 1; padding: 9px 8px; border: none; border-radius: 8px; font-weight: 700; font-size: 0.82rem; cursor: pointer; transition: all 0.2s; background: transparent; color: #64748b;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" style="display:inline-block; vertical-align:middle; margin-right:4px;"><rect width="20" height="16" x="2" y="4" rx="2"/><path d="M6 8h.01"/><path d="M10 8h.01"/><path d="M14 8h.01"/><path d="M18 8h.01"/><path d="M8 12h.01"/><path d="M12 12h.01"/><path d="M16 12h.01"/><path d="M7 16h10"/></svg> Digitar Código
</button>
</div>
<!-- PANEL 1: CÁMARA QR -->
<div id="panelLinkCamera" style="display: block;">
<div style="position: relative; width: 100%; height: 220px; background: #000; border-radius: 14px; overflow: hidden; margin-bottom: 10px; border: 2px solid #0284c7;">
<video id="videoScanChild" playsinline webkit-playsinline autoplay muted style="width: 100%; height: 100%; object-fit: cover;"></video>
<canvas id="canvasScanChild" style="display: none;"></canvas>
<div class="laser-scan-line"></div>
<div id="badgeCameraChildStatus" style="position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); background: rgba(15, 23, 42, 0.9); color: #38bdf8; padding: 3px 12px; border-radius: 20px; font-size: 0.72rem; font-weight: 800; border: 1px solid #0284c7; white-space: nowrap; display: flex; align-items: center; gap: 4px;">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"/><circle cx="12" cy="13" r="3"/></svg> Apunta al código QR del carné
</div>
</div>
<p style="font-size: 0.78rem; color: var(--text-muted); margin: 0 0 10px 0;">
Apunta la cámara hacia el código QR impreso en el carné del estudiante.
</p>
</div>
<!-- PANEL 2: DIGITAR CÓDIGO -->
<div id="panelLinkCode" style="display: none; text-align: left;">
<label for="inputManualStudentCode" style="display: block; font-size: 0.8rem; font-weight: 800; color: var(--text-main); margin-bottom: 6px;">
Código de carné del estudiante:
</label>
<div style="display: flex; gap: 8px; margin-bottom: 6px;">
<input type="text" id="inputManualStudentCode" placeholder="Ej: EST-2026-001" onkeydown="if(event.key==='Enter'){event.preventDefault();validateStudentCodeForLink();}" style="flex: 1; padding: 11px 12px; border-radius: 10px; border: 2px solid var(--border); font-size: 0.95rem; font-weight: 800; background: var(--card-bg); color: var(--text-main); box-sizing: border-box; text-transform: uppercase;">
<button type="button" id="btnValidateStudentCode" onclick="validateStudentCodeForLink()" style="padding: 10px 16px; background: #0284c7; color: white; border: none; border-radius: 10px; font-weight: 800; font-size: 0.85rem; cursor: pointer; white-space: nowrap; display: flex; align-items: center; gap: 6px; box-shadow: 0 2px 6px rgba(2, 132, 199, 0.3);">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg> Validar
</button>
</div>
<p style="font-size: 0.75rem; color: var(--text-muted); margin: 0 0 10px 0;">
Digita el código oficial que aparece en el carné escolar (ej: EST-2026-001).
</p>
</div>
<!-- MENSAJE DE ERROR -->
<div id="linkStudentErrorMsg" style="display: none; background: #fee2e2; border: 1.5px solid #ef4444; color: #991b1b; padding: 10px 12px; border-radius: 10px; font-size: 0.8rem; font-weight: 700; margin-top: 10px; text-align: center;"></div>
</div>
<!-- VISTA 2: TARJETA DE VERIFICACIÓN / CONFIRMACIÓN -->
<div id="linkChildViewConfirm" style="display: none; text-align: left;">
<div style="background: #f0fdf4; border: 1.5px solid #86efac; border-radius: 14px; padding: 10px 12px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px;">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#16a34a" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>
<span style="font-size: 0.82rem; font-weight: 800; color: #166534;">Estudiante Identificado Correctamente</span>
</div>
<!-- TARJETA DEL ESTUDIANTE -->
<div style="background: var(--card-bg); border: 2px solid #0284c7; border-radius: 16px; padding: 14px; margin-bottom: 14px; display: flex; align-items: center; gap: 14px; box-shadow: 0 4px 12px rgba(2, 132, 199, 0.1);">
<div id="linkPreviewAvatar" class="link-preview-avatar-badge">ES</div>
<div style="flex: 1; min-width: 0;">
<div style="font-size: 0.7rem; color: #64748b; font-weight: 800; text-transform: uppercase;">Alumno a vincular:</div>
<h3 id="linkPreviewName" style="font-size: 1.05rem; font-weight: 900; color: var(--text-main); margin: 2px 0; word-break: break-word; line-height: 1.2;">Nombre Alumno</h3>
<div id="linkPreviewGrade" style="font-size: 0.8rem; color: #0284c7; font-weight: 800; margin-top: 2px;">2° Grado - Sección 2-A</div>
<div id="linkPreviewCode" style="font-size: 0.72rem; color: var(--text-muted); font-weight: 700; margin-top: 2px;">Carné: EST-2026-001</div>
</div>
</div>
<p style="font-size: 0.78rem; color: var(--text-muted); margin: 0 0 14px 0; text-align: center;">
¿Confirmas que este es tu hijo/a para vincularlo a tu cuenta y gestionar sus fondos?
</p>
<!-- BOTONES DE ACCIÓN -->
<div style="display: flex; gap: 8px;">
<button type="button" onclick="resetLinkChildToTabs()" style="flex: 1; padding: 11px; background: #f1f5f9; color: #475569; border: 1px solid var(--border); border-radius: 10px; font-weight: 800; font-size: 0.82rem; cursor: pointer;">
← Cambiar
</button>
<button type="button" id="btnConfirmLinkChild" onclick="confirmLinkValidatedChild()" style="flex: 2; padding: 11px; background: linear-gradient(135deg, #10b981, #059669); color: white; border: none; border-radius: 10px; font-weight: 900; font-size: 0.88rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></svg> Confirmar y Vincular
</button>
</div>
</div>
</div>
</div>
</div>
<!-- MODAL: ESCANEAR QR PARA RECARGA EN SODA (ADMIN) -->
<div class="modal-qr-backdrop" id="modalAdminScanQr" style="display: none;" onclick="closeAdminScanQrModal(event)">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 420px; text-align: center;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; border-bottom: 1px solid var(--border); padding-bottom: 8px;">
<strong style="font-size: 1rem; color: var(--text-main); display: flex; align-items: center; gap: 6px;">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"/><circle cx="12" cy="13" r="3"/></svg> Escanear Carné para Recarga
</strong>
<button type="button" onclick="closeAdminScanQrModal()" style="background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-muted);">✕</button>
</div>
<div style="position: relative; width: 100%; height: 230px; background: #000; border-radius: 14px; overflow: hidden; margin-bottom: 10px;">
<video id="videoAdminScan" playsinline webkit-playsinline autoplay muted style="width: 100%; height: 100%; object-fit: cover;"></video>
<canvas id="canvasAdminScan" style="display: none;"></canvas>
<div style="position: absolute; inset: 16px; border: 2px dashed #10b981; border-radius: 12px; pointer-events: none; overflow: hidden;">
<div style="position: absolute; left: 0; right: 0; height: 3px; background: #10b981; box-shadow: 0 0 10px #10b981, 0 0 20px #34d399; animation: adminScanLaser 2s ease-in-out infinite;"></div>
</div>
<button type="button" onclick="toggleAdminCameraFacing()" style="position: absolute; right: 10px; bottom: 10px; background: rgba(15, 23, 42, 0.75); color: white; border: 1px solid rgba(255,255,255,0.25); border-radius: 8px; padding: 5px 9px; font-size: 0.72rem; font-weight: 800; cursor: pointer; backdrop-filter: blur(4px); display: flex; align-items: center; gap: 4px;">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21.5 2v6h-6M21.34 15.57a10 10 0 1 1-.57-8.38l5.67-5.67"/></svg> Voltear
</button>
</div>
<style>
@keyframes adminScanLaser {
0% { top: 4%; opacity: 0.6; }
50% { top: 92%; opacity: 1; }
100% { top: 4%; opacity: 0.6; }
}
</style>
<div id="adminScanModalStatus" style="font-size: 0.8rem; font-weight: 800; color: #0284c7; min-height: 22px; margin-bottom: 6px; padding: 6px 10px; border-radius: 8px; background: #e0f2fe; transition: all 0.2s ease; display: flex; align-items: center; justify-content: center; gap: 6px;">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"/><circle cx="12" cy="13" r="3"/></svg> Enfoca el código QR del carné
</div>
<!-- ALTERNATIVA: DIGITAR CÓDIGO O CARNÉ MANUALMENTE -->
<div style="margin: 8px 0 10px 0; display: flex; gap: 6px;">
<input type="text" id="inputAdminScanManualCode" placeholder="O digita carné (ej: EST-2026-001)" onkeydown="if(event.key==='Enter')submitAdminScanManualCode()" style="flex: 1; padding: 9px 12px; border-radius: 10px; border: 1.5px solid #cbd5e1; font-size: 0.85rem; font-weight: 700; outline: none; background: var(--card-bg, #ffffff); color: var(--text-main);">
<button type="button" onclick="submitAdminScanManualCode()" style="padding: 9px 14px; background: #0284c7; color: white; border: none; border-radius: 10px; font-weight: 800; font-size: 0.8rem; cursor: pointer; white-space: nowrap; display: flex; align-items: center; gap: 4px;">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg> Validar
</button>
</div>
<button type="button" onclick="closeAdminScanQrModal()" style="width: 100%; padding: 10px; background: #f1f5f9; color: #475569; border: 1px solid var(--border); border-radius: 10px; font-weight: 800; font-size: 0.82rem; cursor: pointer;">
Cerrar Cámara
</button>
</div>
</div>
<!-- MODAL: CARRUSEL DE PERSONALIZACIÓN DE TARJETA VIRTUAL -->
<div class="modal-qr-backdrop" id="modalCardDesigns" style="display: none;" onclick="closeCardDesignModal(event)">
<div class="modal-qr-card card-design-modal-card" onclick="event.stopPropagation()" style="max-width: 480px; text-align: left; padding: 18px 16px;">
<!-- CABECERA MODAL -->
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 10px;">
<div style="display: flex; align-items: center; gap: 8px;">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="#ec4899" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><circle cx="13.5" cy="6.5" r=".5" fill="currentColor"/><circle cx="17.5" cy="10.5" r=".5" fill="currentColor"/><circle cx="8.5" cy="7.5" r=".5" fill="currentColor"/><circle cx="6.5" cy="12.5" r=".5" fill="currentColor"/><path d="M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.563-2.512 5.563-5.563C22 6.5 17.5 2 12 2Z"/></svg>
<div>
<h3 style="margin: 0; font-size: 1.15rem; font-weight: 900; color: var(--text-main);">Diseños de Tarjeta</h3>
<span style="font-size: 0.74rem; color: var(--text-muted); font-weight: 600;">Desliza y elige tu estilo favorito</span>
</div>
</div>
<button type="button" onclick="closeCardDesignModal()" style="background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
</div>
<!-- CARRUSEL WRAPPER CON BOTONES PREV / NEXT -->
<div class="card-carousel-wrapper">
<button type="button" class="carousel-nav-btn prev" onclick="scrollCardCarousel(-1)" title="Diseño anterior">‹</button>
<button type="button" class="carousel-nav-btn next" onclick="scrollCardCarousel(1)" title="Siguiente diseño">›</button>
<div class="card-carousel-container" id="cardCarouselContainer">
<!-- Slides generados dinámicamente con JS -->
</div>
</div>
<!-- PUNTOS INDICADORES DE PAGINACIÓN -->
<div class="carousel-dots" id="carouselDots">
<!-- Generados dinámicamente -->
</div>
<!-- TIRA DE ACCESO RÁPIDO A TEMAS -->
<div style="margin-top: 8px;">
<div style="font-size: 0.72rem; font-weight: 800; color: var(--text-muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px;">
Colección de Estilos:
</div>
<div class="theme-quick-strip" id="themeQuickStrip">
<!-- Generado dinámicamente -->
</div>
</div>
<!-- BOTÓN CERRAR / LISTO -->
<div style="margin-top: 14px; display: flex; justify-content: flex-end;">
<button type="button" onclick="closeCardDesignModal()" style="padding: 9px 18px; background: var(--bg-main); border: 1.5px solid var(--border); border-radius: 10px; font-weight: 800; font-size: 0.85rem; color: var(--text-main); cursor: pointer;">
Listo
</button>
</div>
</div>
</div>
<!-- MODAL: AJUSTES DE CUENTA, PRIVACIDAD Y EXPERIENCIA SENSORIAL -->
<div class="modal-qr-backdrop" id="modalAjustesCuenta" style="display: none; z-index: 10005;" onclick="cerrarModalAjustesCuenta(event)">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 440px; text-align: left; padding: 22px;">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1.5px solid var(--border); padding-bottom: 12px; margin-bottom: 16px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 38px; height: 38px; border-radius: 10px; background: #e0f2fe; color: #0284c7; display: flex; align-items: center; justify-content: center; flex-shrink: 0;">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/>
</svg>
</div>
<div>
<h3 style="margin: 0; font-size: 1.12rem; font-weight: 900; color: var(--text-main);">Mi Cuenta y Ajustes</h3>
<span id="ajustesCuentaSub" style="font-size: 0.74rem; color: var(--text-muted); font-weight: 600;">Preferencias, privacidad y seguridad</span>
</div>
</div>
<button type="button" onclick="cerrarModalAjustesCuenta()" style="background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
</div>
<!-- Resumen de Usuario Activo -->
<div style="background: var(--bg-main); border: 1.5px solid var(--border); border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between;">
<div>
<span style="font-size: 0.70rem; color: var(--text-muted); font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; display: block;">Usuario Activo</span>
<strong id="ajustesCuentaNombre" style="font-size: 0.92rem; color: var(--text-main); display: block;">Usuario</strong>
<span id="ajustesCuentaRol" style="font-size: 0.74rem; color: #0284c7; font-weight: 700;">Padre / Encargado</span>
</div>
<span style="font-size: 0.72rem; background: #e0f2fe; color: #0369a1; padding: 4px 10px; border-radius: 20px; font-weight: 800;">Activo</span>
</div>
<!-- Ajustes de Experiencia Sensorial y Táctil -->
<div style="margin-bottom: 16px;">
<span style="font-size: 0.72rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; display: block; margin-bottom: 8px;">
Experiencia Sensorial y Táctil
</span>
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 12px; padding: 10px 14px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center;">
<div>
<strong style="font-size: 0.85rem; color: var(--text-main); display: block;">🔊 Efectos de Sonido</strong>
<span style="font-size: 0.72rem; color: var(--text-muted);">Tonos sintetizados para cobros, pagos y escaneos</span>
</div>
<label class="switch-toggle" style="position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; margin-left: 10px;">
<input type="checkbox" id="chkAjustesSound" onchange="toggleSensorySoundUI(this.checked)" style="opacity: 0; width: 0; height: 0;">
<span class="switch-slider" style="position: absolute; cursor: pointer; inset: 0; background-color: #cbd5e1; border-radius: 34px; transition: .25s;"></span>
</label>
</div>
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 12px; padding: 10px 14px; display: flex; justify-content: space-between; align-items: center;">
<div>
<strong style="font-size: 0.85rem; color: var(--text-main); display: block;">📳 Vibración Háptica</strong>
<span style="font-size: 0.72rem; color: var(--text-muted);">Micro-vibración táctil al pulsar botones y escanear QR</span>
</div>
<label class="switch-toggle" style="position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; margin-left: 10px;">
<input type="checkbox" id="chkAjustesHaptic" onchange="toggleSensoryHapticUI(this.checked)" style="opacity: 0; width: 0; height: 0;">
<span class="switch-slider" style="position: absolute; cursor: pointer; inset: 0; background-color: #cbd5e1; border-radius: 34px; transition: .25s;"></span>
</label>
</div>
</div>
<!-- Enlaces de Políticas y Privacidad -->
<div style="margin-bottom: 18px; padding-top: 4px; border-top: 1px solid var(--border);">
<div style="display: flex; gap: 8px; justify-content: space-between; margin-top: 8px;">
<a href="/privacidad?from=app" style="font-size: 0.75rem; color: #0284c7; text-decoration: underline; font-weight: 700;">
Política de Privacidad
</a>
<a href="/legal?from=app" style="font-size: 0.75rem; color: #0284c7; text-decoration: underline; font-weight: 700;">
Términos de Servicio
</a>
</div>
</div>
<!-- Zona de Peligro: Eliminación de Cuenta -->
<div class="danger-zone-box" style="margin-bottom: 12px;">
<strong style="display: block; font-size: 0.82rem; font-weight: 900; margin-bottom: 3px;">
⚠️ Zona de Peligro: Eliminación de Cuenta
</strong>
<p style="font-size: 0.72rem; line-height: 1.35; margin: 0 0 10px 0;">
Puedes dar de baja tu cuenta y borrar tus datos personales de SiboPay. Esta acción es definitiva e irreversible.
</p>
<button type="button" onclick="abrirModalConfirmarEliminarCuenta()" class="btn-saas" style="width: 100%; height: 36px; background: #dc2626; color: white; border: 1px solid #b91c1c; font-weight: 800; font-size: 0.82rem; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>
<span>Eliminar mi Cuenta y Datos</span>
</button>
<div style="text-align: center; margin-top: 10px;">
<a href="/eliminar-cuenta?from=app" style="font-size: 0.72rem; color: #dc2626; text-decoration: underline; font-weight: 700;">
O abre el formulario web oficial: sibopay.com/eliminar-cuenta
</a>
</div>
</div>
<!-- Botón de Cerrar Modal -->
<div style="display: flex; justify-content: flex-end;">
<button type="button" onclick="cerrarModalAjustesCuenta()" class="btn-saas btn-saas-outline" style="height: 36px; padding: 0 18px; font-weight: 700; cursor: pointer;">
Cerrar
</button>
</div>
</div>
</div>
<!-- MODAL: CONFIRMACIÓN ESTRICTA DE ELIMINACIÓN DE CUENTA -->
<div class="modal-qr-backdrop" id="modalConfirmarEliminarCuenta" style="display: none; z-index: 10010;" onclick="cerrarModalConfirmarEliminarCuenta(event)">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 420px; text-align: left; padding: 22px; border: 2px solid #fecdd3;">
<div style="text-align: center; margin-bottom: 14px;">
<div style="width: 48px; height: 48px; border-radius: 50%; background: #fee2e2; color: #dc2626; display: flex; align-items: center; justify-content: center; margin: 0 auto 10px;">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>
</div>
<h3 style="margin: 0; font-size: 1.18rem; font-weight: 900; color: #991b1b;">¿Confirmas eliminar tu cuenta?</h3>
<p style="font-size: 0.76rem; color: #64748b; margin-top: 4px;">
Esta acción no se puede deshacer. Tus accesos, notificaciones y vínculos familiares se borrarán de forma inmediata.
</p>
</div>
<div style="background: #fff1f2; border: 1px solid #fecdd3; border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; font-size: 0.74rem; color: #9f1239; line-height: 1.4;">
<strong>Para confirmar el borrado:</strong> Introduce tu contraseña de acceso o escribe la palabra <strong>ELIMINAR</strong> a continuación:
</div>
<div style="margin-bottom: 16px;">
<label style="display: block; font-size: 0.74rem; font-weight: 800; color: var(--text-main); margin-bottom: 4px;">
Contraseña o palabra de confirmación:
</label>
<input type="password" id="inputConfirmarPassEliminar" placeholder="Contraseña o escribe ELIMINAR" style="width: 100%; height: 40px; padding: 0 12px; border: 1.5px solid #cbd5e1; border-radius: 9px; font-size: 0.88rem; box-sizing: border-box; background: var(--bg-main); color: var(--text-main);">
</div>
<div style="display: flex; gap: 8px; justify-content: flex-end;">
<button type="button" onclick="cerrarModalConfirmarEliminarCuenta()" class="btn-saas btn-saas-outline" style="height: 38px; padding: 0 16px; font-weight: 700; cursor: pointer;">
Cancelar
</button>
<button type="button" id="btnEjecutarEliminacionDefinitiva" onclick="confirmarEliminarCuentaDefinitiva()" class="btn-saas" style="height: 38px; padding: 0 18px; background: #dc2626; color: white; border: 1px solid #b91c1c; font-weight: 800; cursor: pointer;">
Sí, Borrar Mi Cuenta
</button>
</div>
</div>
</div>
<script>
// CONTROLADOR DE ACCESO DIRECTO: AJUSTES, PRIVACIDAD Y ELIMINACIÓN DE CUENTA
window.abrirModalAjustesCuenta = function() {
const modal = document.getElementById('modalAjustesCuenta');
if (!modal) return;
const lblNombre = document.getElementById('ajustesCuentaNombre');
const lblRol = document.getElementById('ajustesCuentaRol');
const chkSound = document.getElementById('chkAjustesSound');
const chkHaptic = document.getElementById('chkAjustesHaptic');
let user = (typeof currentUser !== 'undefined' && currentUser) ? currentUser : null;
if (!user) {
try {
const raw = localStorage.getItem('sibopay_user') || localStorage.getItem('recreopay_user');
if (raw) user = JSON.parse(raw);
} catch (e) {}
}
if (user) {
if (lblNombre) lblNombre.textContent = user.nombre || user.username || 'Usuario';
if (lblRol) {
let r = user.rol || 'Usuario';
if (r === 'padre') r = 'Padre / Encargado';
else if (r === 'estudiante') r = 'Estudiante / Alumno';
else if (r === 'cajero') r = 'Cajero de Soda';
else if (r === 'admin') r = 'Administrador de Soda';
lblRol.textContent = r;
}
}
try {
if (chkSound && window.sounds && typeof window.sounds.isSoundEnabled === 'function') {
chkSound.checked = window.sounds.isSoundEnabled();
}
if (chkHaptic && window.sounds && typeof window.sounds.isHapticEnabled === 'function') {
chkHaptic.checked = window.sounds.isHapticEnabled();
}
} catch (e) {}
modal.style.display = 'flex';
};
window.cerrarModalAjustesCuenta = function(e) {
if (e && e.target !== e.currentTarget && e.currentTarget !== document) return;
const modal = document.getElementById('modalAjustesCuenta');
if (modal) modal.style.display = 'none';
};
window.toggleSensorySoundUI = function(checked) {
if (window.sounds && typeof window.sounds.toggleSound === 'function') {
window.sounds.toggleSound(checked);
}
};
window.toggleSensoryHapticUI = function(checked) {
if (window.sounds && typeof window.sounds.toggleHaptics === 'function') {
window.sounds.toggleHaptics(checked);
}
};
window.abrirModalConfirmarEliminarCuenta = function() {
window.cerrarModalAjustesCuenta();
const modal = document.getElementById('modalConfirmarEliminarCuenta');
const input = document.getElementById('inputConfirmarPassEliminar');
if (input) input.value = '';
if (modal) modal.style.display = 'flex';
};
window.cerrarModalConfirmarEliminarCuenta = function(e) {
if (e && e.target !== e.currentTarget && e.currentTarget !== document) return;
const modal = document.getElementById('modalConfirmarEliminarCuenta');
if (modal) modal.style.display = 'none';
};
window.confirmarEliminarCuentaDefinitiva = async function() {
let user = (typeof currentUser !== 'undefined' && currentUser) ? currentUser : null;
if (!user) {
try {
const raw = localStorage.getItem('sibopay_user') || localStorage.getItem('recreopay_user');
if (raw) user = JSON.parse(raw);
} catch (e) {}
}
if (!user || !user.id) {
alert('Sesión no detectada. Te redirigiremos al formulario público de eliminación de datos.');
window.location.href = '/eliminar-cuenta';
return;
}
const input = document.getElementById('inputConfirmarPassEliminar');
const val = input ? input.value.trim() : '';
if (!val) {
alert('Por favor ingresa tu contraseña o escribe la palabra ELIMINAR para verificar tu identidad.');
return;
}
const btn = document.getElementById('btnEjecutarEliminacionDefinitiva');
if (btn) {
btn.disabled = true;
btn.textContent = 'Eliminando cuenta...';
}
try {
const res = await fetch('/api/auth/eliminar-cuenta', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
usuario_id: user.id,
password_confirmacion: val,
motivo: 'Eliminación voluntaria solicitada por el usuario desde la app'
})
});
const data = await res.json();
if (!res.ok) throw new Error(data.error || 'No se pudo eliminar la cuenta');
if (window.sounds && typeof window.sounds.playSuccess === 'function') {
window.sounds.playSuccess();
}
alert('Tu cuenta y datos personales han sido eliminados permanentemente de SiboPay.');
try {
localStorage.clear();
sessionStorage.clear();
if ('caches' in window) {
const keys = await caches.keys();
for (const k of keys) await caches.delete(k);
}
} catch (e) {}
window.location.href = '/index.html';
} catch (err) {
if (window.sounds && typeof window.sounds.playError === 'function') {
window.sounds.playError();
}
alert('Error: ' + err.message);
if (btn) {
btn.disabled = false;
btn.textContent = 'Sí, Borrar Mi Cuenta';
}
}
};
</script>
<!-- MODAL: CREAR / EDITAR USUARIO (DEVELOPER) -->
<div class="modal-qr-backdrop" id="modalDevUser" style="display: none;">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 500px; text-align: left; padding: 22px;">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1.5px solid var(--border); padding-bottom: 12px; margin-bottom: 16px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 38px; height: 38px; border-radius: 10px; background: #f0f9ff; color: #0284c7; border: 1px solid #bae6fd; display: flex; align-items: center; justify-content: center; flex-shrink: 0;">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>
</div>
<div>
<h3 id="modalDevUserTitle" style="margin: 0; font-size: 1.15rem; font-weight: 900; color: var(--text-main);">Crear Nuevo Usuario</h3>
<span style="font-size: 0.76rem; color: var(--text-muted); font-weight: 600;">Control total de cuentas y permisos</span>
</div>
</div>
<button type="button" onclick="closeModalDevUser()" style="background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
</div>
<form id="formDevUser" onsubmit="saveDevUser(event)">
<input type="hidden" id="devUserId" value="">
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px;">
<div>
<label style="font-size: 0.8rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Usuario (Login):</label>
<input type="text" id="devInputUsername" required placeholder="ej: admin2, carlos" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;">
</div>
<div>
<label style="font-size: 0.8rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Rol en el Sistema:</label>
<select id="devInputRol" required onchange="handleDevUserRoleChange()" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;">
<option value="admin">Administrador (Soda/Escuela)</option>
<option value="developer">Developer Master</option>
<option value="cajero">Cajero POS</option>
<option value="vendedor">Vendedor</option>
<option value="padre">Padre de Familia</option>
<option value="estudiante">Estudiante</option>
</select>
</div>
</div>
<!-- Banner de sugerencia si seleccionan Estudiante -->
<div id="devStudentRoleTip" style="display: none; background: #f0fdf4; border: 1.5px solid #86efac; border-radius: 10px; padding: 10px 14px; margin-bottom: 12px;">
<div style="display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;">
<div style="font-size: 0.76rem; color: #166534; line-height: 1.35;">
🎓 <strong>¿Deseas generar carné oficial y código QR automático?</strong><br>
Este formulario solo crea credenciales de login. Para crear el estudiante completo con carné, QR y saldo:
</div>
<button type="button" onclick="closeModalDevUser(); openNewStudentModalFromDev();" class="dev-action-btn" style="padding: 6px 12px; font-size: 0.76rem; background: #0284c7; color: white; border: none; font-weight: 800; border-radius: 8px; cursor: pointer;">
Abrir Registro Oficial 🎓
</button>
</div>
</div>
<div style="margin-bottom: 12px;">
<label style="font-size: 0.8rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Nombre Completo:</label>
<input type="text" id="devInputNombre" required placeholder="ej: Juan Pérez Rojas" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;">
</div>
<div id="devPasswordRow" style="margin-bottom: 12px;">
<label id="devPasswordLabel" style="font-size: 0.8rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Contraseña:</label>
<input type="password" id="devInputPassword" placeholder="Contraseña de acceso" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;">
<small id="devPasswordHelp" style="font-size: 0.72rem; color: var(--text-muted); display: none;">Dejar en blanco si no deseas cambiar la contraseña actual.</small>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px;">
<div>
<label style="font-size: 0.8rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Teléfono:</label>
<input type="text" id="devInputTelefono" placeholder="ej: 8888-8888" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;">
</div>
<div>
<label style="font-size: 0.8rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Email:</label>
<input type="email" id="devInputEmail" placeholder="[email protected]" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;">
</div>
</div>
<div style="display: flex; justify-content: flex-end; gap: 10px; border-top: 1.5px solid var(--border); padding-top: 14px;">
<button type="button" onclick="closeModalDevUser()" style="padding: 10px 18px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 800; font-size: 0.85rem; cursor: pointer;">
Cancelar
</button>
<button type="submit" class="dev-action-btn dev-action-btn-primary" style="padding: 10px 22px; font-size: 0.9rem; display: flex; align-items: center; gap: 6px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg> Guardar Usuario
</button>
</div>
</form>
</div>
</div>
<!-- MODAL: CAMBIO RÁPIDO DE CONTRASEÑA (DEVELOPER) -->
<div class="modal-qr-backdrop" id="modalDevPassword" style="display: none;">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 420px; text-align: left; padding: 22px;">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1.5px solid var(--border); padding-bottom: 12px; margin-bottom: 16px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 38px; height: 38px; border-radius: 10px; background: #f0f9ff; color: #0284c7; border: 1px solid #bae6fd; display: flex; align-items: center; justify-content: center; flex-shrink: 0;">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><circle cx="7.5" cy="15.5" r="5.5"/><path d="m21 2-9.6 9.6"/><path d="m15.5 7.5 3 3L22 7l-3-3"/></svg>
</div>
<div>
<h3 style="margin: 0; font-size: 1.15rem; font-weight: 900; color: var(--text-main);">Cambiar Contraseña</h3>
<span id="devPwdTargetUser" style="font-size: 0.78rem; color: #0284c7; font-weight: 700;">Usuario</span>
</div>
</div>
<button type="button" onclick="closeModalDevPassword()" style="background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
</div>
<form id="formDevPassword" onsubmit="saveDevPassword(event)">
<input type="hidden" id="devPwdUserId" value="">
<div style="margin-bottom: 16px;">
<label style="font-size: 0.82rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 6px;">Nueva Contraseña:</label>
<input type="password" id="devInputNewPassword" required minlength="4" placeholder="Mínimo 4 caracteres" style="width: 100%; padding: 11px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box; font-size: 0.95rem;">
</div>
<div style="display: flex; justify-content: flex-end; gap: 10px; border-top: 1.5px solid var(--border); padding-top: 14px;">
<button type="button" onclick="closeModalDevPassword()" style="padding: 10px 18px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 800; font-size: 0.85rem; cursor: pointer;">
Cancelar
</button>
<button type="submit" class="dev-action-btn dev-action-btn-primary" style="padding: 10px 22px; font-size: 0.9rem; display: flex; align-items: center; gap: 6px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><rect width="18" height="11" x="3" y="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg> Actualizar Contraseña
</button>
</div>
</form>
</div>
</div>
<!-- MODAL: CREAR NUEVA ESCUELA / SEDE MULTI-TENANT (DEVELOPER) -->
<div class="modal-qr-backdrop" id="modalDevEscuela" style="display: none;">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 540px; text-align: left; padding: 24px;">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1.5px solid var(--border); padding-bottom: 12px; margin-bottom: 16px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 38px; height: 38px; border-radius: 10px; background: #f0f9ff; color: #0284c7; border: 1px solid #bae6fd; display: flex; align-items: center; justify-content: center; flex-shrink: 0;">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 21h18"/><path d="M5 21V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16"/><path d="M9 21v-4a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v4"/><line x1="9" y1="9" x2="9" y2="9.01"/><line x1="15" y1="9" x2="15" y2="9.01"/></svg>
</div>
<div>
<h3 style="margin: 0; font-size: 1.18rem; font-weight: 900; color: var(--text-main);">Alta de Nueva Sede Escolar</h3>
<span style="font-size: 0.76rem; color: #0284c7; font-weight: 700;">Multi-Tenant & Soda Independiente</span>
</div>
</div>
<button type="button" onclick="closeModalDevEscuela()" style="background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
</div>
<form id="formDevEscuela" onsubmit="guardarDevEscuela(event)">
<div style="display: grid; grid-template-columns: 1fr 2fr; gap: 12px; margin-bottom: 14px;">
<div>
<label style="font-size: 0.8rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Código Único: *</label>
<input type="text" id="devEscuelaCodigo" required maxlength="8" placeholder="Ej: SJT" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 800; text-transform: uppercase; box-sizing: border-box;" oninput="this.value = this.value.toUpperCase().replace(/[^A-Z0-9]/g, '')">
<span style="font-size: 0.68rem; color: var(--text-muted); display: block; margin-top: 2px;">Prefijo para carnés</span>
</div>
<div>
<label style="font-size: 0.8rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Nombre del Centro Educativo: *</label>
<input type="text" id="devEscuelaNombre" required placeholder="Ej: Saint Joseph School" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;">
</div>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px;">
<div>
<label style="font-size: 0.8rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Teléfono SINPE Móvil: *</label>
<input type="tel" id="devEscuelaSinpe" required placeholder="Ej: 8888-1234" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;">
<span style="font-size: 0.68rem; color: var(--text-muted); display: block; margin-top: 2px;">Para recargas de los padres</span>
</div>
<div>
<label style="font-size: 0.8rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Titular SINPE Móvil:</label>
<input type="text" id="devEscuelaSinpeNombre" placeholder="Ej: Soda Saint Joseph" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;">
</div>
</div>
<div style="margin-bottom: 16px;">
<label style="font-size: 0.8rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Concesionario / Responsable Legal:</label>
<input type="text" id="devEscuelaConcesionario" placeholder="Ej: Servicios Alimentarios Gómez S.A." style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;">
</div>
<div style="background: #f0f9ff; border: 1px solid #bae6fd; border-radius: 12px; padding: 12px; margin-bottom: 18px; font-size: 0.78rem; color: var(--text-main); line-height: 1.45;">
<span style="display:inline-flex; align-items:center; gap:5px; color:#0284c7; font-weight:800;"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg> Automatización Instantánea:</span> Al registrar la sede, el sistema clonará de forma automática el menú base de productos saludables y creará sus credenciales operativas (<code>cajero_codigo</code> y <code>admin_codigo</code>, clave temporal <code>123456</code>).
</div>
<div style="display: flex; justify-content: flex-end; gap: 10px; border-top: 1.5px solid var(--border); padding-top: 14px;">
<button type="button" onclick="closeModalDevEscuela()" style="padding: 10px 18px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 800; font-size: 0.85rem; cursor: pointer;">
Cancelar
</button>
<button type="submit" id="btnDevSubmitEscuela" class="dev-action-btn dev-action-btn-primary" style="padding: 10px 22px; font-size: 0.9rem; display: flex; align-items: center; gap: 6px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg> Dar de Alta Escuela
</button>
</div>
</form>
</div>
</div>
<!-- ======================================================== -->
<!-- MODALES DE CONTROL DEVELOPER: BUSCADOR Y AUDITORÍA SINPE -->
<!-- ======================================================== -->
<!-- 1. MODAL: FICHA TÉCNICA Y AUDITORÍA DE TRANSACCIÓN SINPE -->
<div class="modal-qr-backdrop" id="modalDevSinpeDetalle" style="display: none;" onclick="closeModalDevSinpeDetalle()">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 560px; text-align: left; padding: 24px;">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1.5px solid var(--border); padding-bottom: 14px; margin-bottom: 16px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 36px; height: 36px; border-radius: 10px; background: #e0f2fe; color: #0284c7; display: flex; align-items: center; justify-content: center; font-size: 1.2rem;">
🔍
</div>
<div>
<h3 style="margin: 0; font-size: 1.15rem; font-weight: 900; color: var(--text-main);">Ficha de Auditoría SINPE</h3>
<span style="font-size: 0.76rem; color: var(--text-muted); font-weight: 600;">Detalle completo de trazabilidad bancaria</span>
</div>
</div>
<button type="button" onclick="closeModalDevSinpeDetalle()" style="background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
</div>
<div id="modalDevSinpeDetalleBody" style="max-height: 480px; overflow-y: auto; padding-right: 4px;">
<!-- Inyectado dinámicamente -->
</div>
<div style="display: flex; justify-content: space-between; align-items: center; border-top: 1.5px solid var(--border); padding-top: 14px; margin-top: 16px; flex-wrap: wrap; gap: 10px;">
<button type="button" onclick="copiarMensajeSoporteWhatsAppSinpe()" class="dev-action-btn" style="padding: 9px 15px; font-size: 0.82rem; display: inline-flex; align-items: center; gap: 6px; background: #f0fdf4; color: #166534; border: 1.5px solid #bbf7d0; font-weight: 800;">
<span>💬 Copiar para WhatsApp</span>
</button>
<div id="modalDevSinpeDetalleActions" style="display: flex; gap: 8px;">
<!-- Inyectado dinámicamente según el estado -->
</div>
</div>
</div>
</div>
<!-- 2. MODAL: RECHAZAR SOLICITUD SINPE DEVELOPER -->
<div class="modal-qr-backdrop" id="modalDevSinpeRechazar" style="display: none;" onclick="closeModalDevSinpeRechazar()">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 480px; text-align: left; padding: 22px;">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1.5px solid var(--border); padding-bottom: 12px; margin-bottom: 16px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 36px; height: 36px; border-radius: 10px; background: #fef2f2; color: #ef4444; display: flex; align-items: center; justify-content: center; font-size: 1.2rem;">
⚠️
</div>
<div>
<h3 style="margin: 0; font-size: 1.15rem; font-weight: 900; color: #ef4444;">Rechazar Recarga SINPE</h3>
<span style="font-size: 0.76rem; color: var(--text-muted); font-weight: 600;">Se registrará en auditoría y notificará al padre</span>
</div>
</div>
<button type="button" onclick="closeModalDevSinpeRechazar()" style="background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
</div>
<form id="formDevSinpeRechazar" onsubmit="ejecutarRechazoSinpeDev(event)">
<input type="hidden" id="devRechazoSolicitudId">
<div style="margin-bottom: 14px;">
<label style="font-size: 0.82rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 5px;">Motivo Frecuente:</label>
<select id="devRechazoSelectMotivo" onchange="actualizarTextoMotivoRechazoDev()" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; font-size: 0.85rem;">
<option value="Comprobante no verificado en cuenta bancaria">Comprobante no aparece en la cuenta bancaria</option>
<option value="El monto transferido no coincide con la solicitud">Monto no coincide con lo reportado</option>
<option value="Comprobante duplicado ya utilizado anteriormente">Comprobante duplicado / ya utilizado</option>
<option value="Comprobante ilegible o incompleto">Comprobante ilegible o cortado</option>
<option value="otro">Otro motivo personalizado...</option>
</select>
</div>
<div style="margin-bottom: 18px;">
<label style="font-size: 0.82rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 5px;">Detalle o Explicación para el Usuario:</label>
<textarea id="devRechazoTextoExplicacion" rows="3" required style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.85rem; font-weight: 600; box-sizing: border-box;"></textarea>
</div>
<div style="display: flex; justify-content: flex-end; gap: 10px; border-top: 1.5px solid var(--border); padding-top: 14px;">
<button type="button" onclick="closeModalDevSinpeRechazar()" style="padding: 10px 16px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 800; font-size: 0.85rem; cursor: pointer;">
Cancelar
</button>
<button type="submit" id="btnDevConfirmarRechazo" class="dev-action-btn dev-action-btn-danger" style="padding: 10px 20px; font-size: 0.88rem; font-weight: 800;">
Confirmar Rechazo
</button>
</div>
</form>
</div>
</div>
<!-- 3. MODAL: VINCULAR DEPÓSITO BANCARIO HUÉRFANO A UN ESTUDIANTE -->
<div class="modal-qr-backdrop" id="modalDevSinpeVincular" style="display: none;" onclick="closeModalDevSinpeVincular()">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 530px; max-height: 90vh; overflow-y: auto; text-align: left; padding: 22px; box-sizing: border-box;">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1.5px solid var(--border); padding-bottom: 12px; margin-bottom: 16px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 36px; height: 36px; border-radius: 10px; background: #f0f9ff; color: #0284c7; display: flex; align-items: center; justify-content: center; font-size: 1.2rem;">
🔗
</div>
<div>
<h3 style="margin: 0; font-size: 1.15rem; font-weight: 900; color: var(--text-main);">Vincular Depósito Bancario</h3>
<span style="font-size: 0.76rem; color: var(--text-muted); font-weight: 600;">Asignar dinero huérfano al monedero de un alumno</span>
</div>
</div>
<button type="button" onclick="closeModalDevSinpeVincular()" style="background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
</div>
<form id="formDevSinpeVincular" onsubmit="ejecutarVinculacionBancoDev(event)">
<input type="hidden" id="devVincularBancoTxId">
<!-- Resumen del depósito bancario -->
<div id="devVincularDepositoResumen" style="background: #f8fafc; border: 1.5px solid var(--border); border-radius: 12px; padding: 12px; margin-bottom: 16px; font-size: 0.82rem; line-height: 1.5;">
<!-- Inyectado dinámicamente -->
</div>
<!-- SECCIÓN DE BÚSQUEDA Y SELECCIÓN -->
<div id="devVincularSeccionBuscador">
<div style="margin-bottom: 14px;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px;">
<label style="font-size: 0.82rem; font-weight: 800; color: var(--text-main); margin: 0;">Buscar Estudiante Beneficiario: *</label>
<span id="devVincularCountBadge" style="font-size: 0.74rem; color: #0284c7; font-weight: 800;"></span>
</div>
<input type="text" id="devVincularEstudianteSearch" placeholder="Escribe el nombre del alumno, grado o carné (ej: Sofía, Mateo)..." oninput="filtrarEstudiantesParaVincular()" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.86rem; font-weight: 700; box-sizing: border-box; margin-bottom: 6px;">
<select id="devVincularEstudianteSelect" required size="5" onchange="seleccionarEstudianteParaVincular(this.value)" onclick="seleccionarEstudianteParaVincular(this.value)" ondblclick="seleccionarEstudianteParaVincular(this.value, true)" style="width: 100%; min-height: 120px; padding: 6px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--card-bg); color: var(--text-main); font-size: 0.82rem; font-weight: 600;">
<!-- Opciones inyectadas -->
</select>
<div style="font-size: 0.72rem; color: var(--text-muted); margin-top: 4px; font-weight: 600;">
💡 Toca o da doble clic a un estudiante para ver su ficha técnica y saldo actual.
</div>
</div>
<!-- TARJETA / FICHA TÉCNICA DEL ALUMNO SELECCIONADO -->
<div id="devVincularFichaEstudiante" style="display: none; background: linear-gradient(135deg, rgba(2, 132, 199, 0.05), rgba(16, 185, 129, 0.06)); border: 2px solid #0284c7; border-radius: 14px; padding: 14px; margin-bottom: 16px; box-shadow: 0 4px 14px rgba(2, 132, 199, 0.08);">
<!-- Encabezado con datos del estudiante -->
<div style="display: flex; align-items: center; gap: 12px; margin-bottom: 12px;">
<div id="devVincularFichaAvatar" style="width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(135deg, #0284c7, #3b82f6); color: white; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 1.1rem; box-shadow: 0 4px 10px rgba(2, 132, 199, 0.25); flex-shrink: 0;">
ES
</div>
<div style="flex: 1; min-width: 0;">
<div style="display: flex; align-items: center; gap: 6px; flex-wrap: wrap;">
<span id="devVincularFichaCarnet" style="font-size: 0.72rem; font-weight: 800; background: #e0f2fe; color: #0369a1; padding: 2px 7px; border-radius: 6px;">EST-001</span>
<span id="devVincularFichaEscuela" style="font-size: 0.72rem; font-weight: 700; color: #64748b;">Escuela</span>
</div>
<h4 id="devVincularFichaNombre" style="margin: 2px 0 0 0; font-size: 1.05rem; font-weight: 900; color: var(--text-main); word-break: break-word;">Nombre Estudiante</h4>
<div style="font-size: 0.76rem; color: #0284c7; font-weight: 700; margin-top: 1px;">
<span id="devVincularFichaGrado">Grado - Sección</span> · <span id="devVincularFichaPadre" style="color: var(--text-muted);">Encargado</span>
</div>
</div>
</div>
<!-- Cuadrícula de Balances: Antes, Depósito, Saldo Resultante -->
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; background: var(--card-bg); border-radius: 10px; padding: 10px; border: 1px solid var(--border);">
<div style="text-align: center;">
<div style="font-size: 0.67rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase;">Saldo Actual</div>
<div id="devVincularSaldoActual" style="font-size: 0.98rem; font-weight: 900; color: var(--text-main); margin-top: 2px;">₡0</div>
<span style="font-size: 0.63rem; color: #64748b;">(Antes)</span>
</div>
<div style="text-align: center; border-left: 1px dashed var(--border); border-right: 1px dashed var(--border);">
<div style="font-size: 0.67rem; font-weight: 800; color: #0284c7; text-transform: uppercase;">+ Acreditar</div>
<div id="devVincularMontoIngreso" style="font-size: 0.98rem; font-weight: 900; color: #0284c7; margin-top: 2px;">+₡0</div>
<span style="font-size: 0.63rem; color: #0284c7;">(Depósito)</span>
</div>
<div style="text-align: center; background: rgba(16, 185, 129, 0.08); border-radius: 8px; padding: 4px;">
<div style="font-size: 0.67rem; font-weight: 800; color: #166534; text-transform: uppercase;">Proyección</div>
<div id="devVincularSaldoProyectado" style="font-size: 1.05rem; font-weight: 950; color: #10b981; margin-top: 2px;">₡0</div>
<span style="font-size: 0.63rem; color: #059669; font-weight: 700;">↗️ Nuevo</span>
</div>
</div>
</div>
</div>
<!-- PANTALLA DE AUDITORÍA POST-VINCULACIÓN (VERIFICACIÓN EN BASE DE DATOS) -->
<div id="devVincularResultadoExito" style="display: none; background: #f0fdf4; border: 2px solid #10b981; border-radius: 14px; padding: 18px; text-align: center; margin-bottom: 16px;">
<div style="width: 46px; height: 46px; border-radius: 50%; background: #10b981; color: white; display: inline-flex; align-items: center; justify-content: center; font-size: 1.5rem; margin-bottom: 8px; box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);">
✓
</div>
<h3 style="margin: 0 0 4px 0; color: #065f46; font-size: 1.15rem; font-weight: 900;">¡Depósito Bancario Acreditado!</h3>
<p style="margin: 0 0 14px 0; font-size: 0.78rem; color: #047857; font-weight: 600;">
El saldo fue asignado y verificado en la base de datos PostgreSQL.
</p>
<div style="background: white; border: 1.5px solid #a7f3d0; border-radius: 12px; padding: 12px; text-align: left; margin-bottom: 14px;">
<div style="display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 0.82rem;">
<span style="color: #64748b; font-weight: 700;">Estudiante:</span>
<strong id="devExitoEstudianteNombre" style="color: var(--text-main); font-weight: 800;">-</strong>
</div>
<div style="display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 0.82rem;">
<span style="color: #64748b; font-weight: 700;">Comprobante:</span>
<code id="devExitoComprobante" style="color: #0284c7; font-weight: 800;">-</code>
</div>
<div style="border-top: 1px dashed #d1d5db; margin: 8px 0; padding-top: 8px;">
<div style="display: flex; justify-content: space-between; margin-bottom: 4px; font-size: 0.82rem;">
<span style="color: #64748b;">Saldo anterior:</span>
<span id="devExitoSaldoAnterior" style="font-weight: 700; color: #475569;">₡0</span>
</div>
<div style="display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 0.82rem;">
<span style="color: #059669; font-weight: 700;">+ Depósito acreditado:</span>
<strong id="devExitoMontoAcreditado" style="color: #059669; font-weight: 800;">+₡0</strong>
</div>
<div style="display: flex; justify-content: space-between; align-items: center; background: #ecfdf5; padding: 8px 10px; border-radius: 8px; border: 1px solid #a7f3d0;">
<span style="color: #065f46; font-weight: 900; font-size: 0.88rem;">SALDO ACTUALIZADO:</span>
<strong id="devExitoSaldoNuevo" style="color: #059669; font-size: 1.15rem; font-weight: 950;">₡0</strong>
</div>
</div>
</div>
<button type="button" onclick="cerrarModalVincularExitoDev()" class="dev-action-btn dev-action-btn-primary" style="width: 100%; padding: 12px; font-size: 0.92rem; font-weight: 900; box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);">
Entendido / Cerrar
</button>
</div>
<!-- NOTA Y BOTONES DE ACCIÓN DEL FORMULARIO -->
<div id="devVincularFormAcciones">
<div style="margin-bottom: 18px;">
<label style="font-size: 0.82rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 5px;">Nota de Auditoría (Opcional):</label>
<input type="text" id="devVincularNotas" placeholder="Ej: Confirmado vía WhatsApp con el padre Carlos" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.84rem; box-sizing: border-box;">
</div>
<div style="display: flex; justify-content: flex-end; gap: 10px; border-top: 1.5px solid var(--border); padding-top: 14px;">
<button type="button" onclick="closeModalDevSinpeVincular()" style="padding: 10px 16px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 800; font-size: 0.85rem; cursor: pointer;">
Cancelar
</button>
<button type="submit" id="btnDevConfirmarVincular" class="dev-action-btn dev-action-btn-primary" style="padding: 10px 22px; font-size: 0.88rem; font-weight: 800;">
Acreditar y Vincular
</button>
</div>
</div>
</form>
</div>
</div>
<!-- 4. MODAL: SIMULADOR DE CORREO / NOTIFICACIÓN BANCARIA SINPE -->
<div class="modal-qr-backdrop" id="modalDevSimularSinpe" style="display: none;" onclick="closeModalDevSimularSinpe()">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 480px; text-align: left; padding: 22px;">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1.5px solid var(--border); padding-bottom: 12px; margin-bottom: 16px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 36px; height: 36px; border-radius: 10px; background: #f0fdf4; color: #166534; display: flex; align-items: center; justify-content: center; font-size: 1.2rem;">
⚡
</div>
<div>
<h3 style="margin: 0; font-size: 1.15rem; font-weight: 900; color: var(--text-main);">Simulador de Notificación Bancaria</h3>
<span style="font-size: 0.76rem; color: var(--text-muted); font-weight: 600;">Inyecta una transferencia real o huérfana para pruebas</span>
</div>
</div>
<button type="button" onclick="closeModalDevSimularSinpe()" style="background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
</div>
<form id="formDevSimularSinpe" onsubmit="ejecutarSimulacionSinpeDev(event)">
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px;">
<div>
<label style="font-size: 0.80rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Banco Emisor:</label>
<select id="devSimBanco" style="width: 100%; padding: 9px 10px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; font-size: 0.84rem;">
<option value="BAC San José">BAC San José</option>
<option value="Banco Nacional">Banco Nacional (BNCR)</option>
<option value="Banco de Costa Rica">Banco de Costa Rica (BCR)</option>
<option value="Banco Popular">Banco Popular</option>
</select>
</div>
<div>
<label style="font-size: 0.80rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Monto (₡): *</label>
<input type="number" id="devSimMonto" value="3500" step="500" min="500" required style="width: 100%; padding: 9px 10px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 800; font-size: 0.90rem; box-sizing: border-box;">
</div>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px;">
<div>
<label style="font-size: 0.80rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Nombre Remitente:</label>
<input type="text" id="devSimRemitente" value="Carlos Alvarado" style="width: 100%; padding: 9px 10px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; font-size: 0.84rem; box-sizing: border-box;">
</div>
<div>
<label style="font-size: 0.80rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Teléfono Remitente:</label>
<input type="text" id="devSimTelefono" value="88776655" style="width: 100%; padding: 9px 10px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; font-size: 0.84rem; box-sizing: border-box;">
</div>
</div>
<div style="margin-bottom: 14px;">
<label style="font-size: 0.80rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Código de Detalle (Opcional):</label>
<input type="text" id="devSimCodigoDetalle" placeholder="Ej: SIBO-XC69 (deja vacío para depósito huérfano)" style="width: 100%; padding: 9px 10px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; font-size: 0.84rem; box-sizing: border-box;">
<span style="font-size: 0.72rem; color: var(--text-muted);">Si lo dejas vacío, el depósito llegará como 'Sin Reclamar' para probar la vinculación.</span>
</div>
<div style="display: flex; justify-content: flex-end; gap: 10px; border-top: 1.5px solid var(--border); padding-top: 14px;">
<button type="button" onclick="closeModalDevSimularSinpe()" style="padding: 10px 16px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 800; font-size: 0.85rem; cursor: pointer;">
Cancelar
</button>
<button type="submit" id="btnDevConfirmarSimulacion" class="dev-action-btn dev-action-btn-primary" style="padding: 10px 22px; font-size: 0.88rem; font-weight: 800;">
⚡ Disparar Transacción
</button>
</div>
</form>
</div>
</div>
<!-- ======================================================== -->
<!-- MODAL DE VALIDACIÓN Y ESTADO SINPE EN TIEMPO REAL -->
<!-- ======================================================== -->
<div class="modal-qr-backdrop modal-sinpe-backdrop" id="modalSinpeValidacion" style="display: none;" onclick="handleSinpeBackdropClick(event)">
<div class="modal-qr-card modal-sinpe-card" onclick="event.stopPropagation()">
<button type="button" class="modal-sinpe-close-btn" id="modalSinpeBtnCloseX" onclick="closeSinpeModal()" style="display: none;" title="Cerrar">✕</button>
<!-- 1. ESTADO: CARGANDO / VALIDANDO SINPE (Hasta 2 minutos con mensajes sutiles) -->
<div id="modalSinpeStateLoading" style="display: none;">
<div class="sinpe-spinner-container">
<div class="sinpe-pulse-ring"></div>
<div class="sinpe-icon-badge loading">
<svg class="sinpe-spin-svg" width="46" height="46" viewBox="0 0 24 24" fill="none">
<circle cx="12" cy="12" r="10" stroke="#e0f2fe" stroke-width="2.5"/>
<path d="M12 2a10 10 0 0 1 10 10" stroke="#0284c7" stroke-width="2.5" stroke-linecap="round"/>
</svg>
<div class="sinpe-center-s-circle">
<span>S</span>
</div>
</div>
</div>
<h3 style="margin: 14px 0 4px 0; font-size: 1.25rem; font-weight: 900; color: var(--text-main);">Validando SINPE</h3>
<p id="modalSinpeLoadingSubtext" style="font-size: 0.85rem; color: #64748b; margin: 0 0 10px 0; line-height: 1.35;">
Validando comprobante con el banco. Esto podría tardar hasta 1 minuto...
</p>
<!-- Subtítulos sutiles que rotan -->
<div style="text-align: center; margin: 0 0 14px 0; font-size: 0.78rem; color: #0284c7; font-weight: 800; min-height: 20px; display: flex; align-items: center; justify-content: center; gap: 6px;">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" class="sinpe-spin-svg"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>
<span id="modalSinpeStepText">Consultando confirmación bancaria en tiempo real...</span>
</div>
<!-- Resumen de la Operación -->
<div class="sinpe-info-summary">
<div class="sinpe-info-row">
<span>Estudiante:</span>
<strong id="modalSinpeSummaryChild">-</strong>
</div>
<div class="sinpe-info-row">
<span>Monto a validar:</span>
<strong id="modalSinpeSummaryMonto" style="color: #0284c7; font-size: 0.96rem;">₡0</strong>
</div>
<div class="sinpe-info-row">
<span>Código de detalle:</span>
<strong id="modalSinpeSummaryCodigo" style="font-family: monospace; letter-spacing: 0.5px; color: #0369a1;">-</strong>
</div>
</div>
<div style="font-size: 0.73rem; color: #64748b; margin-top: 14px; line-height: 1.4; background: #f0f9ff; border: 1px solid #bae6fd; padding: 9px 12px; border-radius: 10px; text-align: left;">
<span style="font-weight: 800; color: #0284c7;">⏳ Espere un momento, por favor:</span> Esto podría tardar hasta 1 minuto mientras el banco emite el comprobante digital. No cierre esta pantalla.
</div>
</div>
<!-- ESTADO: TIEMPO DE ESPERA AGOTADO (2 minutos sin confirmación bancaria) -->
<div id="modalSinpeStateTimeout" style="display: none;">
<div class="sinpe-icon-badge timeout">
<svg width="38" height="38" viewBox="0 0 24 24" fill="none" stroke="#0284c7" stroke-width="2.3" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"/>
<polyline points="12 6 12 12 16 14"/>
</svg>
</div>
<h3 style="margin: 14px 0 4px 0; font-size: 1.25rem; font-weight: 900; color: var(--text-main);">El banco aún no confirma</h3>
<p style="font-size: 0.84rem; color: #64748b; margin: 0 0 14px 0; line-height: 1.45;">
No hemos recibido el correo de confirmación de tu banco todavía. Puedes seguir esperando 1 minuto más o enviarla para que el comercio la revise manualmente.
</p>
<div class="sinpe-info-summary" style="margin-bottom: 16px;">
<div class="sinpe-info-row">
<span>Monto reportado:</span>
<strong id="modalSinpeTimeoutMonto" style="color: #0284c7; font-size: 0.96rem;">₡0</strong>
</div>
<div class="sinpe-info-row">
<span>Código de detalle:</span>
<strong id="modalSinpeTimeoutCodigo" style="font-family: monospace;">-</strong>
</div>
</div>
<div style="display: flex; flex-direction: column; gap: 8px;">
<button type="button" class="btn-sinpe-action btn-sinpe-sky" onclick="retrySinpeWaitMore()">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.3" stroke-linecap="round" stroke-linejoin="round"><path d="M21.5 2v6h-6M21.34 15.57a10 10 0 1 1-.57-8.38l5.67-5.67"/></svg>
<span>Seguir esperando 1 minuto más</span>
</button>
<button type="button" class="btn-sinpe-action btn-sinpe-subtle" onclick="confirmSinpeSendManualReview()">
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.3" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/></svg>
<span>Enviar a revisión manual</span>
</button>
</div>
</div>
<!-- 2. ESTADO: ÉXITO / VALIDADO -->
<div id="modalSinpeStateSuccess" style="display: none;">
<div class="sinpe-icon-badge success">
<svg width="42" height="42" viewBox="0 0 24 24" fill="none" stroke="#16a34a" stroke-width="2.8" stroke-linecap="round" stroke-linejoin="round">
<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/>
<polyline points="22 4 12 14.01 9 11.01"/>
</svg>
</div>
<h3 style="margin: 14px 0 4px 0; font-size: 1.25rem; font-weight: 900; color: #15803d;">¡Pago Verificado con Éxito!</h3>
<p style="font-size: 0.84rem; color: #64748b; margin: 0 0 12px 0;">
El dinero fue acreditado automáticamente al monedero.
</p>
<div class="sinpe-card-receipt">
<div style="font-size: 0.72rem; text-transform: uppercase; color: #166534; font-weight: 800; letter-spacing: 0.5px; margin-bottom: 2px;">Monto Acreditado</div>
<div id="modalSinpeSuccessMonto" style="font-size: 1.8rem; font-weight: 900; color: #15803d; margin-bottom: 10px;">₡0</div>
<div class="sinpe-info-row">
<span>Estudiante:</span>
<strong id="modalSinpeSuccessChild">-</strong>
</div>
<div class="sinpe-info-row">
<span>Banco emisor:</span>
<strong id="modalSinpeSuccessBanco">Banco</strong>
</div>
<div class="sinpe-info-row">
<span>Comprobante:</span>
<strong id="modalSinpeSuccessComp" style="font-family: monospace;">-</strong>
</div>
<div class="sinpe-info-row" style="border-top: 1px dashed #86efac; padding-top: 8px; margin-top: 6px;">
<span style="font-weight: 800; color: #166534;">Nuevo Saldo Disponible:</span>
<strong id="modalSinpeSuccessNuevoSaldo" style="color: #15803d; font-size: 1.05rem;">₡0</strong>
</div>
</div>
<button type="button" class="btn-sinpe-action btn-sinpe-success" onclick="closeSinpeModal()">
<span>Aceptar y Continuar</span>
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"/></svg>
</button>
</div>
<!-- 3. ESTADO: PENDIENTE DE REVISIÓN COMERCIO (Timeout / sin notificación bancaria) -->
<div id="modalSinpeStatePending" style="display: none;">
<div class="sinpe-icon-badge pending">
<svg width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="#d97706" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"/>
<polyline points="12 6 12 12 16 14"/>
</svg>
</div>
<h3 style="margin: 14px 0 4px 0; font-size: 1.25rem; font-weight: 900; color: #b45309;">Solicitud en Revisión</h3>
<p style="font-size: 0.85rem; color: #475569; margin: 0 0 14px 0; line-height: 1.45;">
Aún no ingresó la confirmación de tu banco. Tu solicitud de recarga por <strong>₡<span id="modalSinpePendingMonto">0</span></strong> quedó registrada para que el comercio la valide.
</p>
<div style="background: #fffbeb; border: 1.5px solid #fde68a; border-radius: 12px; padding: 12px; margin-bottom: 16px; text-align: left; font-size: 0.78rem; color: #92400e; line-height: 1.45;">
<div style="font-weight: 800; display: flex; align-items: center; gap: 5px; margin-bottom: 4px;">
<span>⚡ Acreditación Automática:</span>
</div>
Si la notificación del banco entra en los próximos minutos, el sistema la acreditará de forma automática sin que tengas que hacer nada más.
</div>
<button type="button" class="btn-sinpe-action btn-sinpe-pending" onclick="closeSinpeModal()">
<span>Entendido</span>
</button>
</div>
<!-- 4. ESTADO: ERROR / INVÁLIDO / REPETIDO -->
<div id="modalSinpeStateError" style="display: none;">
<div class="sinpe-icon-badge error">
<svg width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="#dc2626" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"/>
<line x1="12" y1="8" x2="12" y2="12"/>
<line x1="12" y1="16" x2="12.01" y2="16"/>
</svg>
</div>
<h3 id="modalSinpeErrorTitle" style="margin: 14px 0 4px 0; font-size: 1.22rem; font-weight: 900; color: #b91c1c;">No se pudo validar</h3>
<p id="modalSinpeErrorMessage" style="font-size: 0.86rem; color: #475569; margin: 0 0 16px 0; line-height: 1.45;">
Ocurrió un inconveniente al validar la recarga.
</p>
<button type="button" class="btn-sinpe-action btn-sinpe-error" onclick="closeSinpeModal()">
<span>Entendido</span>
</button>
</div>
</div>
</div>
<!-- MODAL: TÉRMINOS, CONDICIONES Y GUÍA DE RECARGA SINPE MÓVIL -->
<div class="modal-qr-backdrop modal-sinpe-backdrop" id="modalSinpeTerms" style="display: none;" onclick="closeModalSinpeTerms(event)">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 480px; max-height: 85vh; overflow-y: auto; text-align: left; padding: 22px; border-radius: 20px; box-sizing: border-box;">
<!-- Encabezado del Modal -->
<div style="display: flex; align-items: center; justify-content: space-between; border-bottom: 1.5px solid var(--border, #e2e8f0); padding-bottom: 12px; margin-bottom: 14px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 38px; height: 38px; border-radius: 10px; background: #e0f2fe; color: #0284c7; display: flex; align-items: center; justify-content: center; font-size: 1.25rem; flex-shrink: 0;">
🛡️
</div>
<div>
<h3 style="margin: 0; font-size: 1.05rem; font-weight: 900; color: var(--text-main, #0f172a);">Términos y Guía SINPE Móvil</h3>
<span style="font-size: 0.74rem; color: var(--text-muted, #64748b);">Reglas para acreditación automática</span>
</div>
</div>
<button type="button" onclick="closeModalSinpeTerms()" style="background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted, #64748b); padding: 4px;" title="Cerrar">✕</button>
</div>
<!-- Alerta Dorada: Coincidencia Exacta -->
<div style="background: #fffbeb; border: 1.5px solid #fde68a; border-radius: 12px; padding: 12px; margin-bottom: 14px;">
<div style="display: flex; align-items: flex-start; gap: 8px;">
<span style="font-size: 1.15rem; line-height: 1;">⚠️</span>
<div style="font-size: 0.77rem; color: #92400e; line-height: 1.45;">
<strong style="display: block; font-size: 0.82rem; margin-bottom: 2px;">Atención a dos datos obligatorios:</strong>
El <strong>monto</strong> y el <strong>código SIBO</strong> deben coincidir con total precisión para que el sistema de la soda apruebe el saldo en segundos.
</div>
</div>
</div>
<!-- Lista de Términos Numerados -->
<div style="display: flex; flex-direction: column; gap: 13px; font-size: 0.78rem; color: var(--text-main, #334155); line-height: 1.45;">
<!-- 1. Monto Exacto -->
<div style="display: flex; gap: 10px; align-items: flex-start;">
<div style="width: 22px; height: 22px; border-radius: 50%; background: #dcfce7; color: #166534; font-weight: 900; font-size: 0.72rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px;">
1
</div>
<div>
<strong style="color: var(--text-main, #0f172a); display: block; font-size: 0.82rem;">Monto idéntico al transferido:</strong>
<span>El monto elegido en esta pantalla debe ser <strong>exactamente igual</strong> al transferido desde su banco (ej: si transfirió ₡3.000, digite ₡3.000). Diferencias en el importe impiden la conciliación automática.</span>
</div>
</div>
<!-- 2. Código Obligatorio -->
<div style="display: flex; gap: 10px; align-items: flex-start;">
<div style="width: 22px; height: 22px; border-radius: 50%; background: #dcfce7; color: #166534; font-weight: 900; font-size: 0.72rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px;">
2
</div>
<div>
<strong style="color: var(--text-main, #0f172a); display: block; font-size: 0.82rem;">Copiar y pegar el código en el Detalle:</strong>
<span>Es <strong>estrictamente obligatorio</strong> colocar el código que empieza con <code style="background: rgba(2, 132, 199, 0.08); color: #0284c7; padding: 1px 6px; border-radius: 4px; font-weight: 800; font-family: monospace;">SIBO-XXXXXX</code> en la casilla de <em>Detalle</em>, <em>Motivo</em> o <em>Concepto</em> del SINPE Móvil bancario.</span>
</div>
</div>
<!-- 3. Destinatario Oficial -->
<div style="display: flex; gap: 10px; align-items: flex-start;">
<div style="width: 22px; height: 22px; border-radius: 50%; background: #dcfce7; color: #166534; font-weight: 900; font-size: 0.72rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px;">
3
</div>
<div>
<strong style="color: var(--text-main, #0f172a); display: block; font-size: 0.82rem;">Verificación del Destinatario:</strong>
<span>Transfiera únicamente al número telefónico y titular oficial registrados de la soda escolar. SiboPay nunca le solicitará fondos a cuentas particulares.</span>
</div>
</div>
<!-- 4. Comprobante de Respaldo -->
<div style="display: flex; gap: 10px; align-items: flex-start;">
<div style="width: 22px; height: 22px; border-radius: 50%; background: #dcfce7; color: #166534; font-weight: 900; font-size: 0.72rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px;">
4
</div>
<div>
<strong style="color: var(--text-main, #0f172a); display: block; font-size: 0.82rem;">Comprobante de Respaldo:</strong>
<span>Conserve la captura o número de comprobante emitido por su banco. En caso de requerir aclaración, este servirá como comprobante ante la administración de la soda.</span>
</div>
</div>
<!-- 5. Disponibilidad del Saldo -->
<div style="display: flex; gap: 10px; align-items: flex-start;">
<div style="width: 22px; height: 22px; border-radius: 50%; background: #dcfce7; color: #166534; font-weight: 900; font-size: 0.72rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px;">
5
</div>
<div>
<strong style="color: var(--text-main, #0f172a); display: block; font-size: 0.82rem;">Disponibilidad Inmediata:</strong>
<span>Una vez validado el pago, los fondos quedan disponibles de inmediato para compras con carné QR o pre-órdenes. El saldo no vence durante el curso lectivo.</span>
</div>
</div>
<!-- 6. No Canjeable por Efectivo -->
<div style="display: flex; gap: 10px; align-items: flex-start;">
<div style="width: 22px; height: 22px; border-radius: 50%; background: #fee2e2; color: #991b1b; font-weight: 900; font-size: 0.72rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px;">
6
</div>
<div>
<strong style="color: #991b1b; display: block; font-size: 0.82rem;">No Canjeable por Dinero Real o Efectivo:</strong>
<span>Los fondos recargados corresponden a créditos escolares exclusivos para consumo de alimentos en la soda. <strong>No pueden ser convertidos ni devueltos en dinero en efectivo</strong> bajo ninguna circunstancia.</span>
</div>
</div>
</div>
<!-- Pie de Seguridad y Botón de Aceptar -->
<div style="margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border, #f1f5f9); display: flex; flex-direction: column; gap: 12px;">
<div style="display: flex; align-items: center; justify-content: space-between; font-size: 0.72rem; color: var(--text-muted, #64748b);">
<span style="display: flex; align-items: center; gap: 6px;">
<span style="width: 7px; height: 7px; border-radius: 50%; background: #10b981; display: inline-block;"></span>
<span>Conciliación automática activa 24/7</span>
</span>
<span style="font-weight: 800; color: #0284c7;">SiboPay Protegido</span>
</div>
<button type="button" onclick="closeModalSinpeTerms()" style="width: 100%; padding: 12px; background: linear-gradient(135deg, #16a34a, #15803d); color: white; border: none; border-radius: 12px; font-weight: 900; font-size: 0.95rem; cursor: pointer; box-shadow: 0 4px 10px rgba(22, 163, 74, 0.25);">
Entendido y Aceptar
</button>
</div>
</div>
</div>
<!-- MODAL: RECHAZAR RECARGA SINPE CON MOTIVO Y TRAZABILIDAD -->
<div class="modal-qr-backdrop" id="modalRechazarSinpe" style="display: none; z-index: 99999;">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 440px; text-align: left; padding: 22px; border-radius: 18px;">
<!-- Encabezado -->
<div style="display: flex; align-items: center; justify-content: space-between; border-bottom: 1.5px solid var(--border, #e2e8f0); padding-bottom: 10px; margin-bottom: 14px;">
<div style="display: flex; align-items: center; gap: 8px;">
<span style="font-size: 1.3rem;">🚫</span>
<div>
<h3 style="margin: 0; font-size: 1.05rem; font-weight: 900; color: #991b1b;">Rechazar Recarga SINPE</h3>
<span style="font-size: 0.72rem; color: var(--text-muted, #64748b);">Trazabilidad detallada para la soda y el padre</span>
</div>
</div>
<button type="button" onclick="cerrarModalRechazoSinpe()" style="background: none; border: none; font-size: 1.3rem; color: var(--text-muted, #64748b); cursor: pointer; padding: 4px;">✕</button>
</div>
<!-- Resumen de Solicitud -->
<div style="background: rgba(148, 163, 184, 0.08); border: 1px solid var(--border, #e2e8f0); border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; font-size: 0.80rem; line-height: 1.45;">
<div style="display: flex; justify-content: space-between;">
<span style="color: var(--text-muted, #64748b);">Estudiante:</span>
<strong id="rechazoSinpeEstudiante" style="color: var(--text-main, #0f172a);">-</strong>
</div>
<div style="display: flex; justify-content: space-between; margin-top: 3px;">
<span style="color: var(--text-muted, #64748b);">Monto Solicitado:</span>
<strong id="rechazoSinpeMonto" style="color: #0284c7; font-size: 0.92rem;">₡0</strong>
</div>
<div style="display: flex; justify-content: space-between; margin-top: 3px;">
<span style="color: var(--text-muted, #64748b);">Comprobante / Cód:</span>
<strong id="rechazoSinpeComprobante" style="color: var(--text-main, #334155);">-</strong>
</div>
</div>
<!-- Motivo de Rechazo (Opciones Rápidas) -->
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main, #0f172a); margin-bottom: 6px;">
Selecciona el motivo del rechazo:
</label>
<div style="display: flex; flex-direction: column; gap: 7px; margin-bottom: 12px;">
<label class="sinpe-reject-option" style="display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1.5px solid var(--border, #e2e8f0); border-radius: 9px; cursor: pointer; font-size: 0.78rem; font-weight: 700; color: var(--text-main, #334155);">
<input type="radio" name="sinpeRejectReason" value="fondos_no_recibidos" checked onchange="toggleSinpeRejectInputs()">
<span>🚫 Fondos no recibidos en cuenta bancaria</span>
</label>
<label class="sinpe-reject-option" style="display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1.5px solid var(--border, #e2e8f0); border-radius: 9px; cursor: pointer; font-size: 0.78rem; font-weight: 700; color: var(--text-main, #334155);">
<input type="radio" name="sinpeRejectReason" value="monto_no_coincide" onchange="toggleSinpeRejectInputs()">
<span>⚠️ Monto no coincide con comprobante</span>
</label>
<label class="sinpe-reject-option" style="display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1.5px solid var(--border, #e2e8f0); border-radius: 9px; cursor: pointer; font-size: 0.78rem; font-weight: 700; color: var(--text-main, #334155);">
<input type="radio" name="sinpeRejectReason" value="comprobante_invalido" onchange="toggleSinpeRejectInputs()">
<span>📄 Comprobante falso, duplicado o ilegible</span>
</label>
<label class="sinpe-reject-option" style="display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1.5px solid var(--border, #e2e8f0); border-radius: 9px; cursor: pointer; font-size: 0.78rem; font-weight: 700; color: var(--text-main, #334155);">
<input type="radio" name="sinpeRejectReason" value="telefono_no_coincide" onchange="toggleSinpeRejectInputs()">
<span>📱 Teléfono o destinatario no coincide</span>
</label>
<label class="sinpe-reject-option" style="display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1.5px solid var(--border, #e2e8f0); border-radius: 9px; cursor: pointer; font-size: 0.78rem; font-weight: 700; color: var(--text-main, #334155);">
<input type="radio" name="sinpeRejectReason" value="otro" onchange="toggleSinpeRejectInputs()">
<span>✏️ Otro motivo personalizado</span>
</label>
</div>
<!-- Campo de Monto Real cuando el monto no coincide -->
<div id="sinpeRejectMontoContainer" style="display: none; background: #fffbeb; border: 1px solid #fde68a; border-radius: 10px; padding: 10px; margin-bottom: 12px;">
<label style="display: block; font-size: 0.75rem; font-weight: 800; color: #92400e; margin-bottom: 4px;">
¿De cuánto era realmente el SINPE recibido? (₡):
</label>
<input type="number" id="sinpeRejectMontoReal" placeholder="Ej: 1000" style="width: 100%; height: 36px; padding: 0 10px; border: 1.5px solid #fcd34d; border-radius: 8px; font-size: 0.88rem; font-weight: 800; color: #92400e; box-sizing: border-box;" oninput="updateSinpeRejectPreview()">
<span id="sinpeRejectMontoPreview" style="display: block; font-size: 0.72rem; color: #b45309; margin-top: 4px; font-weight: 600;">
Se intentaron recargar ₡0 pero el SINPE fue de ₡0
</span>
</div>
<!-- Notas o detalles adicionales -->
<div style="margin-bottom: 16px;">
<label style="display: block; font-size: 0.75rem; font-weight: 700; color: var(--text-muted, #64748b); margin-bottom: 4px;">
Detalle u observación adicional (opcional):
</label>
<input type="text" id="sinpeRejectNotasExtra" placeholder="Ej: Fondos no figuran en estado bancario al corte" style="width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--border, #cbd5e1); border-radius: 8px; font-size: 0.80rem; box-sizing: border-box;">
</div>
<!-- Botones de Acción -->
<div style="display: flex; gap: 8px; justify-content: flex-end;">
<button type="button" onclick="cerrarModalRechazoSinpe()" class="btn-saas btn-saas-outline" style="height: 36px; padding: 0 14px; font-weight: 700;">
Cancelar
</button>
<button type="button" id="btnConfirmarRechazoSinpe" onclick="confirmarRechazoSinpeModal()" class="btn-saas" style="height: 36px; padding: 0 16px; background: #dc2626; color: #ffffff; border: 1px solid #dc2626; font-weight: 800;">
Confirmar Rechazo
</button>
</div>
</div>
</div>
<!-- MODAL: VER MOTIVO DE RECHAZO SINPE (PORTAL DE PADRES) -->
<div class="modal-qr-backdrop" id="modalParentVerMotivoRechazo" style="display: none; z-index: 99999;" onclick="cerrarModalParentMotivoRechazo(event)">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 440px; text-align: left; padding: 22px; border-radius: 18px; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.2), 0 8px 10px -6px rgba(0,0,0,0.2);">
<!-- Encabezado -->
<div style="display: flex; align-items: center; justify-content: space-between; border-bottom: 1.5px solid var(--border, #e2e8f0); padding-bottom: 10px; margin-bottom: 14px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 36px; height: 36px; border-radius: 10px; background: #fee2e2; color: #dc2626; display: flex; align-items: center; justify-content: center; font-size: 1.15rem; flex-shrink: 0;">
🚫
</div>
<div>
<h3 style="margin: 0; font-size: 1.05rem; font-weight: 900; color: #991b1b;">Recarga No Acreditada</h3>
<span style="font-size: 0.72rem; color: var(--text-muted, #64748b);">Detalle del rechazo reportado por la soda</span>
</div>
</div>
<button type="button" onclick="cerrarModalParentMotivoRechazo()" style="background: none; border: none; font-size: 1.3rem; color: var(--text-muted, #64748b); cursor: pointer; padding: 4px;" title="Cerrar">✕</button>
</div>
<!-- Resumen de Solicitud -->
<div style="background: rgba(148, 163, 184, 0.08); border: 1px solid var(--border, #e2e8f0); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 0.80rem; line-height: 1.45;">
<div style="display: flex; justify-content: space-between;">
<span style="color: var(--text-muted, #64748b);">Estudiante:</span>
<strong id="parentMotivoEstudiante" style="color: var(--text-main, #0f172a);">-</strong>
</div>
<div style="display: flex; justify-content: space-between; margin-top: 3px;">
<span style="color: var(--text-muted, #64748b);">Monto Solicitado:</span>
<strong id="parentMotivoMonto" style="color: #0284c7; font-size: 0.92rem;">₡0</strong>
</div>
<div style="display: flex; justify-content: space-between; margin-top: 3px;">
<span style="color: var(--text-muted, #64748b);">Referencia / Cód:</span>
<strong id="parentMotivoComprobante" style="color: var(--text-main, #334155); font-family: monospace;">-</strong>
</div>
<div style="display: flex; justify-content: space-between; margin-top: 3px;">
<span style="color: var(--text-muted, #64748b);">Fecha de Solicitud:</span>
<span id="parentMotivoFecha" style="color: var(--text-muted, #64748b); font-size: 0.76rem;">-</span>
</div>
</div>
<!-- Caja del Motivo de Rechazo -->
<div style="background: #fff1f2; border: 1.5px solid #fecdd3; border-radius: 12px; padding: 12px 14px; margin-bottom: 12px;">
<div style="font-size: 0.72rem; font-weight: 800; color: #be123c; text-transform: uppercase; letter-spacing: 0.5px; display: flex; align-items: center; gap: 5px;">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>
<span>Motivo indicado por la soda:</span>
</div>
<div id="parentMotivoTexto" style="font-size: 0.88rem; font-weight: 800; color: #991b1b; margin-top: 5px; line-height: 1.45;">
Fondos no verificados en la cuenta bancaria de la soda.
</div>
</div>
<!-- Guía y Orientación para el Padre -->
<div style="font-size: 0.74rem; color: #64748b; line-height: 1.42; display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; background: #f8fafc; border: 1px solid #e2e8f0; margin-bottom: 16px;">
<span style="font-size: 1rem; line-height: 1.1;">ℹ️</span>
<span>
Si realizaste la transferencia correctamente desde tu banco, por favor comunícate con la administración de la soda escolar y presenta el comprobante oficial para su verificación manual.
</span>
</div>
<!-- Botón de Cerrar -->
<button type="button" onclick="cerrarModalParentMotivoRechazo()" class="btn-saas btn-saas-primary" style="width: 100%; height: 38px; font-weight: 800; font-size: 0.88rem; justify-content: center; cursor: pointer;">
Entendido
</button>
</div>
</div>
<!-- BARRA DE NAVEGACIÓN INFERIOR PWA (MÓVILES) -->
<nav class="pwa-bottom-nav" id="pwaBottomNav" style="display: none;">
<button class="pwa-nav-item active" id="pwaNavMenu" onclick="pwaNavigateTo('menu')">
<span class="pwa-nav-icon"><svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 2v7c0 1.1.9 2 2 2h4a2 2 0 0 0 2-2V2"/><path d="M7 2v20"/><path d="M21 15V2v0a5 5 0 0 0-5 5v6c0 1.1.9 2 2 2h3Zm0 0v7"/></svg></span>
<span class="pwa-nav-label">Menú</span>
</button>
<button class="pwa-nav-item" id="pwaNavQr" onclick="pwaNavigateTo('qr')">
<span class="pwa-nav-icon"><svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="5" height="5" x="3" y="3" rx="1"/><rect width="5" height="5" x="16" y="3" rx="1"/><rect width="5" height="5" x="3" y="16" rx="1"/><path d="M21 16h-3a2 2 0 0 0-2 2v3"/><path d="M21 21v.01"/><path d="M12 7v3a2 2 0 0 1-2 2H7"/><path d="M3 12h.01"/><path d="M12 3h.01"/><path d="M12 16v.01"/><path d="M16 12h1"/><path d="M21 12v.01"/><path d="M12 21v-1"/></svg></span>
<span class="pwa-nav-label">Mi QR</span>
</button>
<button class="pwa-nav-item" id="pwaNavTransfer" onclick="pwaNavigateTo('transfer')">
<span class="pwa-nav-icon"><svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m16 3 4 4-4 4"/><path d="M20 7H4"/><path d="m8 21-4-4 4-4"/><path d="M4 17h16"/></svg></span>
<span class="pwa-nav-label">Transferir</span>
</button>
<button class="pwa-nav-item" id="pwaNavPadres" onclick="pwaNavigateTo('padres')">
<span class="pwa-nav-icon"><svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg></span>
<span class="pwa-nav-label">Padres</span>
</button>
<button class="pwa-nav-item" id="pwaNavAjustes" onclick="pwaNavigateTo('ajustes')" title="Mi Cuenta y Ajustes">
<span class="pwa-nav-icon"><svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg></span>
<span class="pwa-nav-label">Ajustes</span>
</button>
<button class="pwa-nav-item pwa-nav-logout" onclick="logout(true)" title="Cerrar sesión y cambiar de cuenta">
<span class="pwa-nav-icon"><svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" x2="9" y1="12" y2="12"/></svg></span>
<span class="pwa-nav-label">Salir</span>
</button>
</nav>
<script src="/js/dialogs.js?v=19.4"></script>
<script src="/js/sounds.js?v=19.4"></script>
<script src="/js/jsQR.js" defer></script>
<script src="/js/food-icons.js?v=19.4" defer></script>
<script src="/js/app.js?v=20.2"></script>
</body>
</html>