<?php
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

require_once __DIR__ . '/config.php';
require_once __DIR__ . '/config_ui.php';

$current_page = basename((string) ($_SERVER['PHP_SELF'] ?? 'consulta.php'));
$titulo_pagina = $titulo_pagina ?? ($ui_consulta_page_title ?? 'Consulta');
$brandPrimary = (string) ($ui_color_button_hex ?? $ui_color_primary_bg_hex ?? '#dc2626');
$brandSecondary = (string) ($ui_color_secondary_hex ?? '#991b1b');
$backgroundPath = trim((string) ($ui_fondo_login_path ?? 'assets/img/fondo.jpg'));
if (!preg_match('/^#[0-9a-fA-F]{6}$/', $brandPrimary)) $brandPrimary = '#dc2626';
if (!preg_match('/^#[0-9a-fA-F]{6}$/', $brandSecondary)) $brandSecondary = '#991b1b';
$afPublicContext = 'consulta';
?>
<!doctype html>
<html lang="<?= htmlspecialchars((string)($ui_language ?? 'es'), ENT_QUOTES) ?>">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="theme-color" content="<?= htmlspecialchars($brandPrimary, ENT_QUOTES) ?>">
    <title><?= htmlspecialchars((string) $titulo_pagina, ENT_QUOTES) ?> | <?= htmlspecialchars((string) ($ui_title_system ?? 'Ave Fénix'), ENT_QUOTES) ?></title>
    <?php if (!empty($ui_favicon_path)): ?><link rel="icon" href="<?= htmlspecialchars((string) $ui_favicon_path, ENT_QUOTES) ?>"><?php endif; ?>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@sweetalert2/theme-bootstrap-4/bootstrap-4.min.css">
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="assets/js/vendor/jquery-3.7.1.min.js?v=3.7.1"></script>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <link rel="stylesheet" href="assets/css/premium.css">
    <link rel="stylesheet" href="assets/css/public-shared.css?v=1.0.0">
    <link rel="stylesheet" href="assets/css/public-query.css?v=1.0.0">
    <style>
:root{--brand-primary:<?= htmlspecialchars($brandPrimary, ENT_QUOTES) ?>;--brand-secondary:<?= htmlspecialchars($brandSecondary, ENT_QUOTES) ?>;--public-red:<?= htmlspecialchars($brandPrimary, ENT_QUOTES) ?>;--public-red-dark:<?= htmlspecialchars($brandSecondary, ENT_QUOTES) ?>;--public-background:url('<?= htmlspecialchars($backgroundPath, ENT_QUOTES) ?>')}
body.public-query-body{padding-top:var(--public-header-height);padding-bottom:var(--public-footer-height);background-image:linear-gradient(110deg,rgba(2,6,23,.20),rgba(2,6,23,.04) 48%,rgba(15,23,42,.18)),url('<?= htmlspecialchars($backgroundPath, ENT_QUOTES) ?>'),url('assets/img/fondo.jpg');background-size:cover;background-position:center;background-attachment:fixed}
.public-query-main{min-height:100vh;padding-top:calc(var(--public-header-height) + 22px);padding-bottom:calc(var(--public-footer-height) + 22px)}
.public-query-container{width:min(1280px,100%)}
.public-session-chip{display:inline-flex;align-items:center;gap:8px;min-height:40px;padding:5px 10px;border:1px solid #dbe4ef;border-radius:11px;background:#fff;color:#334155}.public-session-chip>i{color:var(--public-red);font-size:20px}.public-session-chip>span{display:grid;line-height:1.05}.public-session-chip strong{max-width:120px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:10px}.public-session-chip small{margin-top:3px;color:#94a3b8;font-size:8px}
.public-footer-inner--compact{grid-template-columns:minmax(210px,.8fr) minmax(280px,1.3fr) auto}.public-footer-mark{overflow:hidden;background:#fff;color:var(--public-red)}.public-footer-mark img{width:100%;height:100%;object-fit:cover}.public-footer-mark i{width:100%;height:100%;place-items:center}.public-footer-support{padding:6px 10px;border:1px solid rgba(255,255,255,.14);border-radius:9px;background:rgba(255,255,255,.06)}
@media(max-width:760px){.public-query-main{padding-top:calc(var(--public-header-height) + 14px);padding-bottom:20px}.public-session-chip{display:none}.public-footer-inner--compact{grid-template-columns:1fr}.public-query-body{padding-bottom:0}.public-footer{position:relative}.public-footer-links--support{justify-content:center}}
    </style>
</head>
<body class="public-query-body">
<?php require __DIR__ . '/partials/public_header.php'; ?>
<main class="public-query-main">
    <div class="public-query-container">
