/* =========================================
   1. VARIABLES Y RESET
   ========================================= */
:root {
    /* Paleta */
    --bg-body: #f3f4f6;
    --bg-card: #ffffff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --border-focus: #3b82f6;

    /* Botones */
    --btn-bg: #111827;
    --btn-bg-hover: #374151;
    --btn-text: #ffffff;

    /* Errores */
    --error-color: #ef4444;

    /* Efectos */
    --shadow-card: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.02);
    --radius-lg: 16px;
    --radius-md: 8px;
    --transition: all 0.2s ease-in-out;
}

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

/* =========================================
   2. BASE Y TIPOGRAFÍA
   ========================================= */
body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--bg-body);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Solo el login centra el contenido en pantalla */
body:has(.ingreso) {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

/* Contenido del panel interno */
main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px;
}

/* =========================================
   3. CONTENEDOR DE INGRESO (LOGIN)
   ========================================= */
.ingreso-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.ingreso {
    width: 100%;
    max-width: 420px;
    padding: 32px;
    background-color: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
}

/* =========================================
   4. FORMULARIO E INPUTS
   ========================================= */
.ingreso form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ingreso form label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: -8px;
}

.ingreso form input {
    height: 48px;
    padding: 0 16px;
    font-size: 16px; /* 16px evita el zoom automático en iOS */
    color: var(--text-primary);
    background-color: #fff;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.ingreso form input::placeholder {
    color: #9ca3af;
}

.ingreso form input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
}

/* =========================================
   5. BOTÓN Y MENSAJES
   ========================================= */
.ingreso form button {
    cursor: pointer;
    height: 48px;
    font-size: 16px;
    font-weight: 600;
    background-color: var(--btn-bg);
    color: var(--btn-text);
    border: none;
    border-radius: var(--radius-md);
    margin-top: 8px;
    transition: var(--transition);
}

.ingreso form button:hover {
    background-color: var(--btn-bg-hover);
    transform: translateY(-1px);
}

.ingreso form button:active {
    transform: translateY(0) scale(0.98);
}

.ingreso form span {
    font-size: 13px;
    font-weight: 500;
    color: var(--error-color);
    text-align: center;
}

/* =========================================
   6. FOOTER
   ========================================= */
footer {
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 32px;
}

/* =========================================
   7. MENSAJES DE ERROR
   ========================================= */
.error-message {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius-md);
    color: #dc2626;
    font-size: 14px;
    font-weight: 500;
    margin-top: 8px;
    animation: slideIn 0.3s ease-out;
}

.error-message::before {
    content: "⚠";
    font-size: 16px;
    flex-shrink: 0;
}

.error-message.static-error {
    background-color: #fef3c7;
    border-color: #fde68a;
    color: #92400e;
}

.error-message.static-error::before {
    content: "ℹ";
}

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

.errores-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

/* =========================================
   8. MENÚ SUPERIOR (PANEL INTERNO)
   Mismas medidas que la demo: barra baja, logo/avatar de 30/28px,
   links de 13px en píldora, badges rojos.
   Las variables viven en header para no tocar el login.
   Requiere en el <head> la fuente Public Sans (Google Fonts).
   ========================================= */
header {
    --panel: #ffffff;
    --bg: #f3f4f2;
    --sunk: #eceeeb;
    --fg: #1d2321;
    --muted: #5d6763;
    --line: #d5d9d6;
    --accent: #1f5f8b;
    --on-accent: #ffffff;
    --bad: #a8322a;
    --f-ui: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --f-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

    position: sticky;
    top: 0;
    z-index: 1030;
    background: var(--panel);
    color: var(--fg);
    font-family: var(--f-ui);
    font-size: 14px;
    line-height: normal; /* evita heredar el 1.5 del body */
    border-bottom: 1px solid var(--line);
}

header nav {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 18px;
    padding-block: 8px;
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* ---- Izquierda: logo + nombre del sitio + municipalidad ---- */
nav .left {
    display: grid;
    grid-template-columns: auto auto;
    column-gap: 10px;
    align-items: center;
    min-width: 0;
}

nav .left img {
    grid-column: 1;
    grid-row: 1 / span 2;
    display: block;
    width: 40px;
    height: 30px;
    object-fit: cover;
}

/* Alternativa: sello circular con letras, en vez de imagen: <div class="seal">OP</div> */
nav .left .seal {
    grid-column: 1;
    grid-row: 1 / span 2;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    display: grid;
    place-items: center;
    font: 700 11px var(--f-mono);
    color: var(--accent);
}

nav .left .titulo {
    grid-column: 2;
    grid-row: 1;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.15;
    color: var(--fg);
    text-decoration: none;
}

nav .left .subtitulo {
    grid-column: 2;
    grid-row: 2;
    font-size: 10.5px;
    line-height: 1.15;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .09em;
}

nav .left button {
    display: none; /* solo se ve en móvil */
    grid-column: 3;
    grid-row: 1 / span 2;
    width: 36px;
    height: 36px;
    font-size: 22px;
    line-height: 1;
    color: var(--fg);
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 6px;
    cursor: pointer;
}

/* ---- Centro: links ---- */
nav .center {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1 1 auto;
    min-width: 0;
}

nav .center a {
    display: inline-flex;
    align-items: center;
    padding: 7px 11px;
    border-radius: 6px;
    color: var(--muted);
    text-decoration: none;
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
}

nav .center a:hover {
    color: var(--fg);
    background: var(--sunk);
}

nav .center a[aria-current="page"] {
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
}

/* "Cerrar sesión" (último link) al final de la barra */
nav .center > a:last-child {
    margin-left: auto;
}

nav .center > a:last-child:hover {
    color: var(--bad);
}

/* Badge opcional: <a href="">Seguimiento <span>1</span></a> */
nav .center a span {
    display: inline-block;
    min-width: 16px;
    padding: 0 5px;
    margin-left: 5px;
    border-radius: 9px;
    background: var(--bad);
    color: var(--panel);
    font-size: 11px;
    text-align: center;
}

/* ---- Dropdown de barrios ---- */
nav .dropdown {
    position: relative;
}

nav .dropdown ul {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 260px;
    max-height: 320px;
    overflow-y: auto;
    padding: 8px;
    list-style: none;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
}

nav .dropdown:hover ul,
nav .dropdown:focus-within ul {
    display: block;
}

nav .dropdown input {
    width: 100%;
    padding: 7px 10px;
    margin-bottom: 6px;
    font: inherit;
    color: var(--fg);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
}

nav .dropdown input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

nav .dropdown li a {
    display: block;
}

/* ---- Derecha: avatar + usuario y rol ---- */
nav .right {
    display: grid;
    grid-template-columns: auto auto;
    column-gap: 9px;
    align-items: center;
    min-width: 0;
}

nav .right img {
    grid-column: 1;
    grid-row: 1 / span 2;
    display: block;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--sunk);
}

/* Alternativa: avatar con iniciales, en vez de foto: <div class="av">AB</div> */
nav .right .av {
    grid-column: 1;
    grid-row: 1 / span 2;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--on-accent);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 12px;
}

nav .right span:first-of-type {
    grid-column: 2;
    grid-row: 1;
    font-size: 12.5px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 190px;
}

nav .right span:last-of-type {
    grid-column: 2;
    grid-row: 2;
    font-size: 11px;
    line-height: 1.2;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .07em;
}

nav .center a.activo {
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
}

/* =========================================
   9. RESPONSIVE
   ========================================= */
@media (max-width: 820px) {
    nav .left {
        width: 100%;
        grid-template-columns: auto 1fr auto;
    }

    nav .left button {
        display: block;
    }

    nav .center,
    nav .right {
        display: none;
        width: 100%;
    }

    header.abierto nav .center {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 2px;
    }

    header.abierto nav .right {
        display: grid;
        padding-top: 8px;
        border-top: 1px solid var(--line);
    }

    nav .center > a:last-child {
        margin-left: 0;
    }

    nav .dropdown ul {
        position: static;
        display: block;
        max-height: 240px;   /* antes: none */
        border: 0;
        box-shadow: none;
        padding: 4px 0 0 12px;
    }

    main {
        padding: 16px;
    }
}

@media (max-width: 480px) {
    body:has(.ingreso) {
        padding: 16px;
        padding-top: 10vh;
        justify-content: flex-start;
    }

    .ingreso {
        padding: 24px 20px;
        border-radius: 12px;
    }
}