:root {
  --bg: #F3F5F9;
  --surface: #FFFFFF;
  --ink: #14213D;
  --muted: #5B6780;
  --line: #DCE2EC;
  --azul: #0F47AF;
  --azul-suave: #E5ECF9;
  --ok: #12805C;
  --ok-suave: #E2F3EC;
  --err: #C42B3A;
  --err-suave: #FBE7E9;
  --warn: #A8670B;
  --warn-suave: #FBF0DC;
  --pulso-vacio: #E7EBF2;
  color-scheme: light;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0D1424;
    --surface: #141D31;
    --ink: #E6EBF5;
    --muted: #93A0B8;
    --line: #26324A;
    --azul: #7AA2FF;
    --azul-suave: #1B2A4D;
    --ok: #3CC48F;
    --ok-suave: #12302A;
    --err: #FF6B76;
    --err-suave: #3A1B24;
    --warn: #E8A93A;
    --warn-suave: #3A2C14;
    --pulso-vacio: #1F2A41;
    color-scheme: dark;
  }
}
*, *::before, *::after { box-sizing: inherit; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Archivo", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}
.muted { color: var(--muted); }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--azul); outline-offset: 2px; }

/* Botones ---------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .4em; height: 34px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); cursor: pointer; text-decoration: none; color: var(--ink);
  font-size: 14px; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn-icono { width: 34px; padding: 0; font-size: 18px; }
.btn-primario { background: var(--azul); color: #fff; border-color: var(--azul); height: 42px; }
@media (prefers-color-scheme: dark) { .btn-primario { color: #0D1424; } }
.btn-salir { color: var(--muted); }

/* Login ------------------------------------------------------------ */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-box { width: min(380px, 100%); display: grid; gap: 14px; }
.login-box h1 { margin: 0; font-size: 34px; font-stretch: 80%; font-weight: 800; letter-spacing: -.01em; }
.login-box p { margin: 0; }
.login-box label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.login-box input {
  height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); font-size: 16px;
}
.login-error { color: var(--err); }

/* Barra superior --------------------------------------------------- */
.barra {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px clamp(16px, 3vw, 36px);
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.marca { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; font-stretch: 85%; }
.marca svg { width: 28px; height: 28px; }
.marca svg rect { fill: var(--azul); }
.marca svg path { stroke: var(--surface); stroke-width: 2.6; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.controles { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.controles input[type=date] {
  height: 34px; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface);
}
.estado-act { font-size: 13px; min-width: 130px; text-align: right; }

/* Pestañas de sistemas -------------------------------------------- */
.pestanas {
  position: sticky; top: 0; z-index: 5;
  display: flex; gap: 2px; overflow-x: auto;
  padding: 0 clamp(16px, 3vw, 36px);
  background: var(--surface); border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
}
.pestanas a {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 14px 10px; white-space: nowrap; text-decoration: none; color: var(--muted);
  border-bottom: 3px solid transparent; font-size: 14px;
}
.pestanas a:hover { color: var(--ink); }
.pestanas a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--azul); font-weight: 600; }
.punto { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.punto.ok { background: var(--ok); }
.punto.warn { background: var(--warn); }
.punto.err { background: var(--err); }

/* Vista ------------------------------------------------------------ */
.vista { padding: clamp(20px, 3vw, 36px); max-width: 1320px; margin: 0 auto; outline: none; }
.vista h2 { font-size: 19px; font-weight: 700; margin: 0 0 12px; font-stretch: 90%; }
.seccion { margin-top: 36px; }

/* Titular: la frase del día es el elemento principal */
.titular { max-width: 920px; }
.titular .fecha-larga { color: var(--muted); font-size: 15px; margin: 0 0 6px; }
.titular h1 {
  margin: 0; font-size: clamp(28px, 4.2vw, 46px); line-height: 1.12;
  font-weight: 500; font-stretch: 82%; letter-spacing: -.015em;
}
.titular h1 b { font-weight: 800; }
.titular h1 .n-ok { color: var(--ok); }
.titular h1 .n-err { color: var(--err); }
.titular h1 .n-azul { color: var(--azul); }

.cifras { display: flex; flex-wrap: wrap; gap: 8px 32px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.cifra { display: flex; flex-direction: column; }
.cifra strong { font-size: 24px; font-weight: 700; font-stretch: 85%; line-height: 1.2; }
.cifra span { font-size: 13px; color: var(--muted); }
.cifra.err strong { color: var(--err); }
.cifra.warn strong { color: var(--warn); }
.cifra.ok strong { color: var(--ok); }

/* Tablero de sistemas --------------------------------------------- */
.tablero { width: 100%; overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.tablero table { width: 100%; border-collapse: collapse; min-width: 860px; }
.tablero th {
  white-space: nowrap; text-align: left; font-weight: 500; font-size: 13px; color: var(--muted);
  padding: 10px 14px; border-bottom: 1px solid var(--line);
}
.tablero td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tablero tr:last-child td { border-bottom: 0; }
.tablero tbody tr { cursor: pointer; }
.tablero tbody tr:hover td { background: var(--azul-suave); }
.tablero .num { text-align: right; font-weight: 600; font-size: 16px; }
.tablero th.num { font-weight: 500; font-size: 13px; }
.tablero .nombre { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.tablero .sub { display: block; font-size: 12.5px; color: var(--muted); font-weight: 400; }
.cero { color: var(--muted); font-weight: 400 !important; }
.rojo { color: var(--err); }
.ambar { color: var(--warn); }

/* Pulso por hora: 24 barras */
.pulso { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; align-items: end; height: 30px; width: 220px; }
.pulso i { display: block; background: var(--azul); border-radius: 1px; min-height: 2px; position: relative; }
.pulso i.sin { background: var(--pulso-vacio); }
.pulso-eje { display: flex; justify-content: space-between; width: 220px; font-size: 10.5px; color: var(--muted); margin-top: 2px; }

/* APIs: barras de disponibilidad */
.uptime { display: grid; grid-template-columns: repeat(48, 1fr); gap: 1px; height: 26px; width: 240px; }
.uptime i { display: block; border-radius: 1px; background: var(--ok); }
.uptime i.u-aviso { background: var(--warn); }
.uptime i.u-caida { background: var(--err); }
.uptime i.u-sin { background: var(--pulso-vacio); }
.uptime-eje { width: 240px; }
.cab-seccion { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; margin-bottom: 12px; }
.cab-seccion h2 { margin: 0; }
.cab-seccion .btn { margin-left: auto; height: 30px; font-size: 13px; }
.alerta-api:not(:empty) { margin-top: 18px; max-width: 920px; }
.tabla-apis { min-width: 980px !important; }
.tabla-apis tbody tr { cursor: default; }
.tabla-apis td.num, .tabla-apis td.num .sub { white-space: nowrap; }
.tabla-apis td:nth-child(2) { max-width: 300px; }
.tabla-apis tbody tr:hover td { background: transparent; }

/* Rejilla de gráficos --------------------------------------------- */
.rejilla { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 20px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 18px; min-width: 0; }
.panel h2 { font-size: 16px; }
.grafico { position: relative; height: 260px; }

/* Listas simples ---------------------------------------------------- */
.lista-errores-top { list-style: none; margin: 0; padding: 0; }
.lista-errores-top li { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.lista-errores-top li:last-child { border-bottom: 0; }
.lista-errores-top .msg { font-weight: 500; overflow-wrap: anywhere; }
.lista-errores-top .meta { font-size: 13px; color: var(--muted); grid-column: 1; }
.lista-errores-top .cnt { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-weight: 700; font-size: 18px; color: var(--err); text-align: right; }
.lista-errores-top .cnt small { display: block; font-size: 11.5px; font-weight: 400; color: var(--muted); }

.tabla-simple { width: 100%; border-collapse: collapse; }
.tabla-simple th { text-align: left; font-weight: 500; font-size: 13px; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
.tabla-simple td { padding: 9px 8px; border-bottom: 1px solid var(--line); }
.tabla-simple tr:last-child td { border-bottom: 0; }
.tabla-simple .num { text-align: right; }
.codigo { display: inline-block; min-width: 2.2em; padding: 0 6px; border-radius: 4px; background: var(--azul-suave); color: var(--azul); font-weight: 600; font-size: 13px; text-align: center; }

/* Errores del sistema ---------------------------------------------- */
.filtros { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.filtros button {
  height: 32px; padding: 0 12px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: 13.5px;
}
.filtros button[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.buscar { height: 32px; padding: 0 12px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface); font-size: 13.5px; min-width: min(340px, 100%); }

.errores { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.error-item { border-bottom: 1px solid var(--line); }
.error-item:last-child { border-bottom: 0; }
.error-item > summary {
  list-style: none; cursor: pointer; display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto; gap: 4px 16px; padding: 14px 16px;
}
.error-item > summary::-webkit-details-marker { display: none; }
.error-item > summary:hover { background: var(--azul-suave); }
.error-hora { font-weight: 600; }
.error-hora small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.error-msg { font-weight: 600; overflow-wrap: anywhere; }
.error-doc { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.etiqueta { display: inline-block; padding: 2px 9px; border-radius: 10px; font-size: 12.5px; font-weight: 600; white-space: nowrap; align-self: start; }
.etiqueta.pend { background: var(--err-suave); color: var(--err); }
.etiqueta.corr { background: var(--ok-suave); color: var(--ok); }
.etiqueta.neutra { background: var(--azul-suave); color: var(--azul); }
.error-cuerpo { padding: 0 16px 16px 96px; }
.obs { margin: 0 0 12px; padding: 10px 14px; border-left: 3px solid var(--err); background: var(--err-suave); border-radius: 0 6px 6px 0; }
.obs ul { margin: 0; padding-left: 18px; }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px 20px; font-size: 13.5px; margin-bottom: 12px; }
.meta-grid dt { color: var(--muted); font-size: 12.5px; }
.meta-grid dd { margin: 0; overflow-wrap: anywhere; }

/* Modal ------------------------------------------------------------ */
.modal { width: min(820px, 94vw); max-height: 86vh; padding: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); }
.modal::backdrop { background: rgba(10, 18, 36, .45); }
.modal-cab { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.modal-cab h3 { margin: 0; font-size: 16px; }
.modal-cuerpo { padding: 16px; overflow: auto; }
.modal-cuerpo pre { margin: 0 0 14px; padding: 12px; background: var(--bg); border-radius: 6px; overflow-x: auto; font-size: 12.5px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, Menlo, Consolas, monospace; }
.modal-cuerpo h4 { margin: 0 0 6px; font-size: 14px; }

/* Avisos ----------------------------------------------------------- */
.aviso { padding: 14px 16px; border-radius: 8px; background: var(--err-suave); color: var(--ink); border-left: 4px solid var(--err); }
.aviso.warn { background: var(--warn-suave); border-left-color: var(--warn); }
.vacio { padding: 28px 16px; text-align: center; color: var(--muted); }
.cargando { padding: 60px 0; color: var(--muted); }

@media (max-width: 700px) {
  .estado-act { display: none; }
  .error-item > summary { grid-template-columns: 52px minmax(0, 1fr); }
  .error-item > summary .etiqueta { grid-column: 2; justify-self: start; }
  .error-cuerpo { padding-left: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
