/* Tema base de SysAuditores (sysauditores.vstelecom.cl): oscuro por defecto y claro con su propia paleta.
   Para cambiar de tema basta <html data-tema="claro|oscuro">, que pone el servidor desde la cookie FP.Tema. */
@font-face { font-family: Inter; font-style: normal; font-weight: 400; font-display: swap; src: url(/fuentes/inter-400.woff2) format("woff2"); }
@font-face { font-family: Inter; font-style: normal; font-weight: 500; font-display: swap; src: url(/fuentes/inter-500.woff2) format("woff2"); }
@font-face { font-family: Inter; font-style: normal; font-weight: 600; font-display: swap; src: url(/fuentes/inter-600.woff2) format("woff2"); }
@font-face { font-family: Inter; font-style: normal; font-weight: 700; font-display: swap; src: url(/fuentes/inter-700.woff2) format("woff2"); }

:root, [data-tema="oscuro"] {
    --bg: #0b1020;
    --panel: #101a2f;
    --panel-2: #16223e;
    --superficie-0: #0b1424;
    --elegido: #1b2b52;
    --chip: #1a2745;
    --borde: #24345a;
    --borde-suave: #1c2947;
    --borde-fuerte: #33477a;
    --texto: #e9effa;
    --muted: #9fb0cc;
    --mute-2: #7e8da8;
    --primario: #4c8dff;
    --primario-2: #2f6fe0;
    --primario-borde: #6ba2ff;
    --primario-texto: #f2f7ff;
    --violeta: #a78bfa;
    --ok: #34d399;
    --error: #f87171;
    --aviso: #fbbf24;
    --barra-fondo: rgb(10 16 32 / 78%);
    --velo: rgb(4 8 18 / 68%);
    --cielo-1: #16264a;
    --cielo-2: #1a1740;
    --tarjeta: linear-gradient(180deg, rgb(24 37 69 / 55%), rgb(19 29 51 / 85%));
    --hover: #21315b;
    --sombra: 0 10px 30px rgb(3 8 20 / 55%);
    --sombra-modal: 0 24px 60px rgb(0 0 0 / 55%);
    --radio: 10px;
    --radio-lg: 14px;
    --fuente: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    color-scheme: dark;
}

[data-tema="claro"] {
    --bg: #f4f6fb;
    --panel: #ffffff;
    --panel-2: #f2f5fb;
    --superficie-0: #eef2f9;
    --elegido: #e3ecfd;
    --chip: #eaf0fb;
    --borde: #d3dcea;
    --borde-suave: #e2e8f2;
    --borde-fuerte: #b3c2da;
    --texto: #16203a;
    --muted: #46536e;
    --mute-2: #6b7994;
    --primario: #2563eb;
    --primario-2: #1d4fb8;
    --primario-borde: #1d4fb8;
    --primario-texto: #ffffff;
    --violeta: #7c3aed;
    --ok: #047857;
    --error: #b91c1c;
    --aviso: #b45309;
    --barra-fondo: rgb(255 255 255 / 85%);
    --velo: rgb(22 32 58 / 38%);
    --cielo-1: #dbe6fb;
    --cielo-2: #e6e2fb;
    --tarjeta: linear-gradient(180deg, rgb(255 255 255 / 92%), rgb(247 250 255 / 96%));
    --hover: #e3ecfd;
    --sombra: 0 8px 24px rgb(22 32 58 / 10%);
    --sombra-modal: 0 24px 60px rgb(22 32 58 / 22%);
    color-scheme: light;
}

/* Mezclas para estados: se calculan del tema activo, se leen en ambos. */
:root, [data-tema] {
    --ok-suave: color-mix(in srgb, var(--ok) 16%, transparent);
    --error-suave: color-mix(in srgb, var(--error) 16%, transparent);
    --aviso-suave: color-mix(in srgb, var(--aviso) 18%, transparent);
    --primario-suave: color-mix(in srgb, var(--primario) 16%, transparent);
    --violeta-suave: color-mix(in srgb, var(--violeta) 18%, transparent);
    --gris-suave: color-mix(in srgb, var(--muted) 16%, transparent);
}

* { box-sizing: border-box; }
html { font-size: 14.5px; }
body {
    margin: 0; font-family: var(--fuente); line-height: 1.5; color: var(--texto);
    background:
        radial-gradient(1200px 700px at 12% -10%, var(--cielo-1) 0%, transparent 60%),
        radial-gradient(900px 600px at 100% 0%, var(--cielo-2) 0%, transparent 55%),
        var(--bg);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primario); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: color-mix(in srgb, var(--primario) 32%, transparent); color: var(--texto); }
:focus-visible { outline: 2px solid var(--primario); outline-offset: 2px; border-radius: 6px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--borde); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--borde-fuerte); background-clip: content-box; }
h1 { font-size: 1.5rem; font-weight: 700; margin: 0 0 1rem; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; font-weight: 600; margin: 1.8rem 0 .8rem; }
h3 { font-weight: 600; }

/* ---------- Barra superior ---------- */
.barra {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 1.2rem; padding: 0 1.5rem; height: 58px;
    background: var(--barra-fondo); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--borde-suave);
}
.barra nav { display: flex; gap: .2rem; flex: 1; }
.barra nav a { color: var(--muted); padding: .42rem .8rem; border-radius: 8px; font-weight: 500; }
.barra nav a:hover { background: var(--hover); color: var(--texto); text-decoration: none; }
.barra nav a.activo { background: var(--elegido); color: var(--texto); box-shadow: inset 0 0 0 1px var(--borde); }
.marca { color: var(--texto); font-size: 1.12rem; font-weight: 700; letter-spacing: .2px; }
.marca:hover { text-decoration: none; }
.marca b { color: var(--primario); }
.marca.grande { font-size: 1.9rem; text-align: center; display: block; }
.sesion { display: flex; align-items: center; gap: .8rem; font-size: .9rem; color: var(--muted); }
.sesion .estudio { font-size: .78rem; color: var(--muted); max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sesion .usuario { background: var(--chip); border: 1px solid var(--borde-suave); padding: .18rem .7rem; border-radius: 999px; color: var(--texto); font-weight: 600; text-decoration: none; }
.sesion .usuario:hover { border-color: var(--primario); }
.sesion form { margin: 0; }
.enlace { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; }
.enlace:hover { color: var(--texto); text-decoration: underline; }
.boton-tema {
    width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--borde); background: var(--panel);
    color: var(--texto); cursor: pointer; font-size: 1rem; display: inline-flex; align-items: center; justify-content: center;
}
.boton-tema:hover { background: var(--hover); }
.boton-tema.flotante { position: fixed; top: 1rem; right: 1rem; }

.selector-empresa { margin: 0; }
.selector-empresa select {
    width: auto; min-width: 240px; max-width: 340px; font-weight: 600;
    background: var(--chip); color: var(--texto); border: 1px solid var(--borde); padding: .42rem .6rem;
}

.contenido { max-width: 1240px; margin: 0 auto; padding: 1.8rem 1.5rem 3rem; }
.miga { margin: 0 0 .3rem; color: var(--mute-2); font-size: .88rem; }
.miga a { color: var(--muted); }
.titulo-seccion { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.titulo-seccion h1, .titulo-seccion h2 { margin-bottom: .8rem; }
.acciones { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; align-items: center; }
.acciones form { margin: 0; }
.titulo-seccion .acciones { margin-top: 0; }
.muted { color: var(--muted); }
.rut { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Botones ---------- */
.boton {
    display: inline-flex; align-items: center; gap: .35rem; padding: .48rem 1rem; border-radius: var(--radio);
    border: 1px solid var(--borde); background: var(--panel-2); color: var(--texto); cursor: pointer;
    font: inherit; font-weight: 500; line-height: 1.3; text-decoration: none;
}
.boton:hover { background: var(--hover); text-decoration: none; }
.boton.primario {
    background: linear-gradient(180deg, var(--primario), var(--primario-2)); border-color: var(--primario-borde);
    color: var(--primario-texto); box-shadow: 0 4px 14px color-mix(in srgb, var(--primario) 30%, transparent);
}
.boton.primario:hover { filter: brightness(1.08); }
.boton.peligro { background: transparent; border-color: color-mix(in srgb, var(--error) 60%, transparent); color: var(--error); }
.boton.peligro:hover { background: var(--error-suave); }
.boton.chico { padding: .26rem .65rem; font-size: .85rem; }
.boton.ancho { width: 100%; justify-content: center; margin-top: 1.2rem; padding: .7rem; }
.boton:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Avisos ---------- */
.aviso { padding: .7rem 1rem; border-radius: var(--radio); margin-bottom: 1rem; border: 1px solid transparent; }
.aviso.ok { background: var(--ok-suave); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.aviso.error { background: var(--error-suave); color: var(--error); border-color: color-mix(in srgb, var(--error) 35%, transparent); }
.aviso.error ul { margin: 0; padding-left: 1.1rem; }
.validation-summary-valid.vacio-oculto { display: none; }
.err { color: var(--error); font-size: .85rem; }
.vacio { color: var(--muted); background: var(--tarjeta); border: 1px dashed var(--borde); border-radius: var(--radio); padding: 1.2rem; }
.resultados { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); padding: .8rem 1rem; white-space: pre-wrap; font-family: inherit; font-size: .88rem; color: var(--texto); }

/* ---------- Tablas ---------- */
.tabla { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--tarjeta); border: 1px solid var(--borde-suave); border-radius: var(--radio); overflow: hidden; }
.tabla th, .tabla td { padding: .6rem .8rem; text-align: left; border-bottom: 1px solid var(--borde-suave); }
.tabla th { background: var(--superficie-0); font-size: .76rem; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; }
.tabla tbody tr:hover td { background: color-mix(in srgb, var(--primario) 5%, transparent); }
.tabla tr:last-child td { border-bottom: 0; }
.tabla .num { text-align: right; font-variant-numeric: tabular-nums; }
.tabla tr.inactiva td { color: var(--mute-2); }
.tabla tr.descuadre td { background: var(--error-suave); }
.tabla td.detalle { color: var(--error); font-size: .85rem; max-width: 420px; }
.vencida { color: var(--error); font-weight: 600; }

/* ---------- Estados y niveles ---------- */
.estado { font-size: .76rem; font-weight: 600; padding: .18rem .6rem; border-radius: 999px; white-space: nowrap; display: inline-block; }
.e-planificacion { background: var(--primario-suave); color: var(--primario); }
.e-ejecucion { background: var(--aviso-suave); color: var(--aviso); }
.e-informe { background: var(--violeta-suave); color: var(--violeta); }
.e-cerrada { background: var(--ok-suave); color: var(--ok); }
.e-anulada { background: var(--gris-suave); color: var(--muted); }
.e-error { background: var(--error-suave); color: var(--error); }
a.estado.e-error:hover { text-decoration: none; filter: brightness(1.1); }
.sev-alta { background: var(--error-suave); color: var(--error); }
.sev-media { background: var(--aviso-suave); color: var(--aviso); }
.sev-baja { background: var(--primario-suave); color: var(--primario); }
.sev-info { background: var(--gris-suave); color: var(--muted); }

/* ---------- KPIs, tarjetas, ficha ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.kpi { background: var(--tarjeta); border: 1px solid var(--borde-suave); border-radius: var(--radio-lg); padding: 1rem 1.2rem; box-shadow: var(--sombra); }
.kpi span { color: var(--muted); font-size: .85rem; display: block; }
.kpi span + span { font-size: .8rem; }
.kpi b { font-size: 1.75rem; font-variant-numeric: tabular-nums; font-weight: 700; }
a.kpi { color: inherit; }
a.kpi:hover, a.kpi.activo { text-decoration: none; outline: 2px solid var(--primario); }
.tarjetas { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.tarjeta { display: flex; flex-direction: column; gap: .25rem; background: var(--tarjeta); border: 1px solid var(--borde-suave); border-radius: var(--radio-lg); padding: 1rem 1.2rem; color: var(--texto); }
.tarjeta:hover { border-color: var(--primario); text-decoration: none; }
.ficha { display: grid; grid-template-columns: 200px 1fr; gap: .55rem 1rem; background: var(--tarjeta); border: 1px solid var(--borde-suave); border-radius: var(--radio-lg); padding: 1.2rem; margin: 0; }
.ficha dt { color: var(--muted); }
.ficha dd { margin: 0; }
.ficha .texto { white-space: pre-wrap; }

.ciclo { display: flex; list-style: none; padding: 0; margin: 0 0 1.2rem; gap: .3rem; }
.ciclo li { flex: 1; text-align: center; padding: .5rem; background: var(--panel-2); color: var(--muted); font-size: .88rem; }
.ciclo li:first-child { border-radius: 8px 0 0 8px; }
.ciclo li:last-child { border-radius: 0 8px 8px 0; }
.ciclo li.hecho { background: var(--primario-suave); color: var(--primario); }
.ciclo li.actual { background: var(--primario); color: var(--primario-texto); font-weight: 600; }

/* ---------- Formularios ---------- */
.formulario { background: var(--tarjeta); border: 1px solid var(--borde-suave); border-radius: var(--radio-lg); padding: 1.4rem; max-width: 900px; }
.formulario label, .tarjeta-login label { display: block; font-size: .86rem; color: var(--muted); margin: .9rem 0 .3rem; }
input, select, textarea {
    width: 100%; padding: .55rem .7rem; border: 1px solid var(--borde); border-radius: 8px; font: inherit;
    background: var(--superficie-0); color: var(--texto);
}
input::placeholder, textarea::placeholder { color: var(--mute-2); }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primario) 45%, transparent); border-color: var(--primario); }
input[readonly] { opacity: .75; }
.fila { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 1rem; }
.fila .doble { grid-column: span 2; }
label.check { display: flex; align-items: center; gap: .5rem; color: var(--texto); }
label.check input { width: auto; }
.en-linea { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin: .8rem 0; }
.en-linea label { color: var(--muted); font-size: .9rem; }
.en-linea select { width: auto; min-width: 220px; }

/* ---------- Ingreso ---------- */
body.acceso { display: grid; place-items: center; min-height: 100vh; }
.tarjeta-login { background: var(--tarjeta); border: 1px solid var(--borde-suave); width: min(390px, 92vw); padding: 2rem; border-radius: 16px; box-shadow: var(--sombra-modal); backdrop-filter: blur(8px); }
.tarjeta-login .sub { text-align: center; color: var(--muted); margin: .3rem 0 1.2rem; }

/* ---------- FairPharma ---------- */
.barra .sesion { margin-left: auto; }
.sesion .usuario { font-size: .85rem; max-width: 22rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.buscador { display: flex; gap: .5rem; max-width: 760px; margin-bottom: 1.2rem; }
.buscador input { font-size: 1.05rem; padding: .7rem .9rem; }
.buscador .boton { flex: none; }
.filtros { display: flex; flex-wrap: wrap; gap: .35rem; margin: 1.2rem 0; }
.filtro { font-size: .82rem; padding: .22rem .7rem; border-radius: 999px; border: 1px solid var(--borde-suave); background: var(--chip); color: var(--muted); }
.filtro:hover { color: var(--texto); border-color: var(--primario); text-decoration: none; }
.filtro.activo { background: var(--elegido); color: var(--texto); border-color: var(--primario); font-weight: 600; }
.tabla-marco { overflow-x: auto; margin-top: 1rem; }
.paginacion { display: flex; align-items: center; gap: 1rem; margin: 1rem 0; }
@media (max-width: 700px) { .sesion .usuario { display: none; } .ficha { grid-template-columns: 1fr; } }