/* ClientIA — portal de administración.
   CSS propio, sin frameworks: la app se sirve on-premise y no queremos dependencias externas
   (además el CSP y la red del cliente pueden bloquear CDNs).
   Paleta corporativa de Plenario (--primary #1f4e79) y escala de espaciado de 4px. */

:root {
    /* Marca */
    --primary: #1f4e79;
    --primary-hover: #17395a;
    --primary-suave: #eaf1f8;

    /* Semánticos */
    --exito: #146c43;
    --exito-suave: #e8f5ee;
    --alerta: #b45309;
    --alerta-suave: #fef6e7;
    --peligro: #b02a37;
    --peligro-suave: #fdecee;

    /* Superficies y texto: contraste >= 4.5:1 sobre blanco */
    --fondo: #f4f6f9;
    --superficie: #ffffff;
    --texto: #1a2027;
    --texto-suave: #5a6672;
    --borde: #dde3ea;
    --borde-fuerte: #c3ccd6;

    --radio: 8px;
    --radio-sm: 6px;
    --sombra: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
    --sombra-md: 0 4px 12px rgba(16, 24, 40, .08);

    --esp-1: 4px;
    --esp-2: 8px;
    --esp-3: 12px;
    --esp-4: 16px;
    --esp-5: 24px;
    --esp-6: 32px;
    --esp-7: 48px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    /* Stack del sistema: sin webfonts, carga instantánea y se ve nativo en cada SO. */
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--texto);
    background: var(--fondo);
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 var(--esp-3); font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 var(--esp-3); }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Foco siempre visible: se navega con teclado y es requisito de accesibilidad. */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: var(--radio-sm);
}

/* ---------- Encabezado / navegación ---------- */

header {
    background: var(--primary);
    color: #fff;
    box-shadow: var(--sombra);
}

header nav {
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 var(--esp-5);
    display: flex;
    align-items: center;
    gap: var(--esp-5);
    min-height: 60px;
    flex-wrap: wrap;
}

.marca {
    color: #fff;
    font-weight: 600;
    font-size: 1.0625rem;
    letter-spacing: .01em;
}
.marca:hover { text-decoration: none; opacity: .9; }

header nav ul {
    list-style: none;
    display: flex;
    gap: var(--esp-1);
    margin: 0;
    padding: 0;
    flex: 1;
}

header nav ul a {
    color: rgba(255, 255, 255, .88);
    padding: var(--esp-2) var(--esp-3);
    border-radius: var(--radio-sm);
    display: block;
    font-size: .9375rem;
    /* 44px de alto real: objetivo táctil cómodo. */
    line-height: 28px;
}
header nav ul a:hover { background: rgba(255, 255, 255, .12); color: #fff; text-decoration: none; }

.usuario { display: flex; align-items: center; gap: var(--esp-3); font-size: .875rem; }
.usuario > span:first-child { color: rgba(255, 255, 255, .92); }

.chip {
    background: rgba(255, 255, 255, .18);
    border: 1px solid rgba(255, 255, 255, .25);
    padding: 2px var(--esp-2);
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 500;
    letter-spacing: .02em;
}

.salir {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, .4);
    color: #fff;
    padding: var(--esp-2) var(--esp-3);
    border-radius: var(--radio-sm);
    cursor: pointer;
    font: inherit;
    font-size: .875rem;
    min-height: 36px;
    transition: background .15s ease, border-color .15s ease;
}
.salir:hover { background: rgba(255, 255, 255, .14); border-color: rgba(255, 255, 255, .7); }

/* ---------- Contenido ---------- */

main {
    max-width: 1180px;
    margin: 0 auto;
    padding: var(--esp-6) var(--esp-5) var(--esp-7);
}

section {
    background: var(--superficie);
    border: 1px solid var(--borde);
    border-radius: var(--radio);
    padding: var(--esp-5);
    box-shadow: var(--sombra);
}

section > h2:first-child { margin-top: 0; }

fieldset {
    border: 1px solid var(--borde);
    border-radius: var(--radio-sm);
    padding: var(--esp-4);
    margin: 0 0 var(--esp-4);
}
legend {
    font-weight: 600;
    font-size: .875rem;
    padding: 0 var(--esp-2);
    color: var(--texto-suave);
    text-transform: uppercase;
    letter-spacing: .04em;
}

/* ---------- Formularios ---------- */

.campo { margin-bottom: var(--esp-4); max-width: 560px; }

label {
    display: block;
    font-weight: 500;
    font-size: .875rem;
    margin-bottom: var(--esp-1);
}

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], select, textarea {
    width: 100%;
    padding: 10px var(--esp-3);
    /* 16px evita que iOS haga zoom automático al enfocar. */
    font: inherit;
    font-size: 1rem;
    color: var(--texto);
    background: var(--superficie);
    border: 1px solid var(--borde-fuerte);
    border-radius: var(--radio-sm);
    min-height: 44px;
    transition: border-color .15s ease, box-shadow .15s ease;
}

input:hover:not(:disabled), select:hover:not(:disabled) { border-color: #a9b4c0; }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-suave);
}

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    min-height: 0;
    margin-right: var(--esp-2);
    accent-color: var(--primary);
    vertical-align: -3px;
}

/* Un label que contiene un checkbox es la fila entera: no debe verse como título de campo. */
label:has(input[type="checkbox"]) { font-weight: 400; display: flex; align-items: center; cursor: pointer; }

.nota, .ayuda {
    display: block;
    font-size: .8125rem;
    color: var(--texto-suave);
    margin-top: var(--esp-1);
    line-height: 1.45;
}
.ayuda { margin-bottom: var(--esp-4); max-width: 70ch; }

button[type="submit"]:not(.salir) {
    background: var(--primary);
    color: #fff;
    border: 1px solid var(--primary);
    padding: 10px var(--esp-5);
    border-radius: var(--radio-sm);
    font: inherit;
    font-size: .9375rem;
    font-weight: 500;
    min-height: 44px;
    cursor: pointer;
    transition: background .15s ease;
}
button[type="submit"]:not(.salir):hover { background: var(--primary-hover); }
button[type="submit"]:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Mensajes ---------- */

.mensaje, .error, .exito {
    padding: var(--esp-3) var(--esp-4);
    border-radius: var(--radio-sm);
    margin-bottom: var(--esp-4);
    font-size: .9375rem;
    border: 1px solid transparent;
}
.mensaje, .exito { background: var(--exito-suave); border-color: #bcdfcb; color: var(--exito); }
.error { background: var(--peligro-suave); border-color: #f1c2c7; color: var(--peligro); }

/* ---------- Tablas ---------- */

table { width: 100%; border-collapse: collapse; font-size: .9375rem; }

th {
    text-align: left;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--texto-suave);
    padding: var(--esp-3);
    border-bottom: 1px solid var(--borde);
    white-space: nowrap;
}

td { padding: var(--esp-3); border-bottom: 1px solid var(--borde); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }

/* Los importes y números se leen en columna: cifras de ancho fijo evitan el zigzag. */
td.numero, th.numero { text-align: right; font-variant-numeric: tabular-nums; }

/* Las tablas anchas scrollean solas en vez de romper el layout. */
.tabla-scroll { overflow-x: auto; }

/* ---------- Tablero (métricas) ---------- */

.metricas {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--esp-4);
    margin-bottom: var(--esp-5);
}

.metrica {
    background: var(--superficie);
    border: 1px solid var(--borde);
    border-radius: var(--radio);
    padding: var(--esp-4) var(--esp-5);
    box-shadow: var(--sombra);
}
.metrica .valor { font-size: 2rem; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.metrica .rotulo { font-size: .8125rem; color: var(--texto-suave); margin-top: var(--esp-1); }

/* ---------- Login ---------- */

/* El login no usa el header: es una tarjeta centrada en la pantalla. */
body.login {
    display: grid;
    place-items: center;
    min-height: 100dvh;
    padding: var(--esp-4);
    background: linear-gradient(160deg, #eef2f7 0%, var(--fondo) 55%);
}

.tarjeta-login {
    background: var(--superficie);
    border: 1px solid var(--borde);
    border-radius: 12px;
    box-shadow: var(--sombra-md);
    padding: var(--esp-6);
    width: 100%;
    max-width: 400px;
}
.tarjeta-login h1 { font-size: 1.5rem; margin-bottom: var(--esp-1); }
.tarjeta-login .subtitulo { color: var(--texto-suave); font-size: .9375rem; margin-bottom: var(--esp-5); }
.tarjeta-login .campo { max-width: none; }
.tarjeta-login button[type="submit"] { width: 100%; margin-top: var(--esp-2); }

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
    header nav { padding: var(--esp-3) var(--esp-4); gap: var(--esp-3); }
    header nav ul { order: 3; width: 100%; overflow-x: auto; }
    main { padding: var(--esp-4) var(--esp-4) var(--esp-6); }
    section { padding: var(--esp-4); }
    h1 { font-size: 1.375rem; }
}

/* Respeta a quien pidió menos movimiento en su sistema. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
