/* Centinela — tema claro. CSS propio (sin Tailwind ni CDN): todo se sirve en local.
   Los colores de texto cumplen contraste AA sobre sus fondos. */

@font-face {
  font-family: "Inter";
  src: url("vendor/inter/InterVariable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --bg-top: #f6f7fb;
  --bg-bottom: #eceef6;
  --surface: #ffffff;
  --surface-tint: #f5f7fe;
  --surface-muted: #f2f4f8;
  --border: #e3e7ef;
  --border-strong: #d0d6e2;

  --text: #172033;
  --text-2: #344054;
  --muted: #5b6477;        /* 5.6:1 sobre blanco */
  --accent: #3b5bdb;       /* 5.9:1 sobre blanco */
  --accent-strong: #2f4ac0;
  --focus: #3b5bdb;

  --red: #c92a2a;          /* texto */
  --red-dot: #e03131;
  --red-soft: #fdecec;
  --red-seg: #f4c7c7;
  --amber: #a65200;
  --amber-dot: #e8890c;
  --amber-soft: #fdf1e3;
  --amber-seg: #f1dfc4;
  --green: #1d7a36;
  --green-dot: #2f9e44;
  --green-soft: #e7f6ec;
  --green-seg: #cde9d6;
  --violet: #6f4fd8;
  --teal: #0c8599;
  --grey-dot: #b6bdcb;
  --slate: #4b5263;        /* menciones en la dark web (pistas); 7.6:1 sobre blanco */
  --page: #8a5a3c;         /* páginas web que citan al sujeto */

  --r-hero: 28px;
  --r-card: 20px;
  --r-tile: 16px;
  --r-control: 14px;
  --r-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 1px 2px rgba(16, 24, 40, 0.04), 0 6px 18px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 2px 6px rgba(16, 24, 40, 0.04), 0 18px 44px rgba(41, 52, 98, 0.10);

  --topbar: 64px;
}

* { box-sizing: border-box; }

/* Que `hidden` gane siempre a los `display` de los componentes. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background:
    radial-gradient(900px 520px at 0% 0%, #edf0fc 0%, rgba(237, 240, 252, 0) 70%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--mono); font-size: 0.92em; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 10;
  padding: 10px 14px; border-radius: var(--r-control);
  background: var(--accent); color: #fff; text-decoration: none; font-weight: 600;
}
.skip-link:focus { top: 12px; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- Barra superior: marca, vistas y sesión ---------- */

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 24px;
  height: var(--topbar); padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.tabs {
  display: flex; gap: 4px; padding: 4px;
  border-radius: var(--r-pill); background: var(--surface-muted);
}
.tabs__tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px; border: 0; border-radius: var(--r-pill);
  background: none; color: var(--text-2);
  font: inherit; font-size: 15px; font-weight: 650; cursor: pointer;
}
.tabs__tab:hover { color: var(--text); }
.tabs__tab[aria-selected="true"] { background: var(--surface); color: var(--accent-strong); box-shadow: var(--shadow-sm); }
.tabs__badge {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: var(--r-pill);
  display: inline-grid; place-items: center;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
}

/* ---------- Distribución ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 460px);
  height: calc(100vh - var(--topbar));
}

/* Si el medidor crece (p. ej. con el alcance desplegado), baja la página entera: el grafo
   nunca se queda por debajo de su altura mínima. */
.workspace {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
}

.card--hero {
  border-radius: var(--r-hero);
  box-shadow: var(--shadow-lg);
}

.card--soft {
  border-radius: var(--r-card);
  box-shadow: var(--shadow-md);
}

/* ---------- Medidor de exposición ---------- */

/* Dos columnas: a la izquierda el nivel y los contadores; a la derecha lo que varía (términos,
   búsquedas en curso, no consultadas, alcance plegado, regla). Así crece a lo ancho. */
.meter {
  flex: none;
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(260px, 1fr);
  grid-template-areas: "head facts" "segments facts" "labels facts" "counters facts";
  grid-template-rows: auto auto auto 1fr;
  column-gap: 32px;
  padding: 22px 28px 20px;
  background: linear-gradient(135deg, var(--surface-tint) 0%, var(--surface) 55%);
}
.meter__head { grid-area: head; }
.segments { grid-area: segments; }
.segments__labels { grid-area: labels; }
.counters { grid-area: counters; align-self: start; }
.meter__facts { grid-area: facts; min-width: 0; align-self: start; }
.meter__facts > :first-child { margin-top: 0; }
.meter[data-level="alto"] { background: linear-gradient(135deg, #fdf1f1 0%, var(--surface) 55%); }
.meter[data-level="medio"] { background: linear-gradient(135deg, #fdf6ec 0%, var(--surface) 55%); }
.meter[data-level="bajo"] { background: linear-gradient(135deg, #eef8f1 0%, var(--surface) 55%); }

.meter__head { display: flex; align-items: center; gap: 18px; min-width: 0; }

.meter__icon {
  display: grid; place-items: center;
  width: 64px; height: 64px; flex: none;
  border-radius: 18px;
  background: var(--surface-muted);
  color: var(--muted);
}
.meter[data-level="alto"] .meter__icon { background: var(--red-soft); color: var(--red); }
.meter[data-level="medio"] .meter__icon { background: var(--amber-soft); color: var(--amber); }
.meter[data-level="bajo"] .meter__icon { background: var(--green-soft); color: var(--green); }

.eyebrow {
  margin: 0;
  font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted);
}

.meter__level {
  margin: 2px 0 0;
  font-size: 40px; line-height: 1.05; font-weight: 750; letter-spacing: -0.02em;
  color: var(--muted);
}
.meter[data-level="alto"] .meter__level { color: var(--red); }
.meter[data-level="medio"] .meter__level { color: var(--amber); }
.meter[data-level="bajo"] .meter__level { color: var(--green); }
.meter[data-level="sin_determinar"] .meter__level { color: var(--text-2); }
.meter[data-level="sin_determinar"] .meter__icon { background: var(--surface-muted); color: var(--text-2); }

.segments { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 22px; }
.segment { height: 10px; border-radius: var(--r-pill); background: var(--surface-muted); }
/* «Sin determinar» deja la barra apagada, igual que antes de evaluar: no hay nivel. */
.meter:not([data-level="none"]):not([data-level="sin_determinar"]) .segment--bajo { background: var(--green-seg); }
.meter:not([data-level="none"]):not([data-level="sin_determinar"]) .segment--medio { background: var(--amber-seg); }
.meter:not([data-level="none"]):not([data-level="sin_determinar"]) .segment--alto { background: var(--red-seg); }
.meter[data-level="bajo"] .segment--bajo { background: var(--green-dot); }
.meter[data-level="medio"] .segment--medio { background: var(--amber-dot); }
.meter[data-level="alto"] .segment--alto { background: var(--red-dot); }

.segments__labels {
  display: flex; justify-content: space-between;
  margin-top: 6px; font-size: 13px; color: var(--muted);
}

.counters {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px;
  margin: 18px 0 0;
}
.counter {
  display: flex; flex-direction: column-reverse; align-items: center;
  padding: 12px 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-tile);
  background: var(--surface);
}
.counter dt { font-size: 13px; color: var(--muted); }
.counter dd {
  margin: 0; font-size: 30px; font-weight: 700; line-height: 1.1;
  font-variant-numeric: tabular-nums; color: var(--text);
}
.counter--credentials.is-positive dd { color: var(--red); }

.terms { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-top: 16px; }
.terms__label { font-size: 14px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.chips li {
  padding: 4px 12px; border-radius: var(--r-pill);
  background: var(--surface-muted); color: var(--text-2); font-size: 14px;
}
.chips li.chips__empty { background: none; padding: 4px 0; color: var(--muted); }

.missing { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-top: 12px; }
/* Búsqueda en segundo plano (dark web): un punto que late mientras busca. */
.pending { display: flex; align-items: center; gap: 8px; margin: 12px 0 0; font-size: 14px; color: var(--text-2); }
.pending::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%; flex: none;
  background: var(--slate); animation: pending-pulse 1.4s ease-in-out infinite;
}
@keyframes pending-pulse { 50% { opacity: 0.25; } }
.missing__label { font-size: 14px; color: var(--muted); }
.chips--missing li { background: var(--amber-soft); color: var(--text-2); }
.chips--coverage li { background: var(--surface-muted); color: var(--text-2); }

.meter__rule { margin: 14px 0 0; font-size: 13px; color: var(--muted); }

/* Alcance de lo consultado: plegado (textos largos). */
.scope { margin-top: 12px; }
.scope summary { cursor: pointer; }
.scope summary:hover { color: var(--text-2); }
.scope .chips { margin-top: 8px; }
.chips--coverage li { border-radius: var(--r-control); }

/* ---------- Grafo ---------- */

/* La leyenda tiene su propia columna (abajo a la izquierda) y el lienzo ocupa el resto:
   así ningún nodo queda nunca debajo de ella, se coloque como se coloque el grafo. */
/* Altura mínima = lo que deja el medidor plegado (unos 330 px con sus márgenes): si el medidor
   crece, el grafo no se encoge; baja la página. */
.graph {
  flex: 1 0 auto; min-height: max(460px, calc(100vh - 330px));
  display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: minmax(0, 1fr);
  gap: 16px;
}
.graph__canvas { grid-column: 2; grid-row: 1; position: relative; min-height: 0; }
.graph__empty {
  grid-column: 2; grid-row: 1; margin: 0;
  display: grid; place-items: center; padding: 24px;
  color: var(--muted); font-size: 15px; text-align: center; pointer-events: none;
}

.legend {
  grid-column: 1; grid-row: 1; align-self: end;
  padding: 14px 18px;
  font-size: 13px; color: var(--text-2);
}
.legend ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.legend li { display: flex; align-items: center; gap: 10px; }
.legend .legend__gap { margin-top: 6px; }

/* Las formas del grafo (app.js): círculo, cuadrado redondeado, hoja, rombo y hexágono. */
.swatch { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.swatch--subject { width: 14px; height: 14px; background: var(--accent); box-shadow: 0 0 0 3px #dfe5fb; }
.swatch--datum { border-radius: 3px; background: var(--green-dot); }
.swatch--account { background: var(--green-dot); }
.swatch--page { width: 10px; height: 13px; border-radius: 0; background: var(--page); }
.swatch--leak { width: 11px; height: 11px; border-radius: 1px; background: var(--red-dot); transform: rotate(45deg); }
.swatch--org { background: var(--violet); }
.swatch--darkweb {
  width: 13px; border-radius: 0; background: var(--slate);
  clip-path: polygon(25% 5%, 75% 5%, 100% 50%, 75% 95%, 25% 95%, 0 50%);
}
.swatch--special { background: var(--surface); box-shadow: inset 0 0 0 3px var(--amber-dot); }

.stroke { width: 26px; height: 0; flex: none; border-top: 2px solid #8a93a6; }
.stroke--inferred { border-top-style: dashed; }
.stroke--analyst { border-top: 3px dotted var(--teal); }
.stroke--new { border-top: 3px solid var(--green-dot); }
/* Vínculo societario cesado: gris claro y terminado en barra, como la arista del grafo. */
.stroke--ceased { border-top-color: #b6bdcb; position: relative; }
.stroke--ceased::after {
  content: ""; position: absolute; right: 0; top: -6px; height: 10px; border-right: 2px solid #b6bdcb;
}

/* ---------- Panel derecho ---------- */

.panel {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(16, 24, 40, 0.04);
}

.brand__mark {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--accent); color: #fff;
}
.brand__text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand__name { font-size: 22px; font-weight: 750; letter-spacing: -0.01em; }
.brand__tagline { font-size: 13px; color: var(--muted); }

/* Sesión: quién está dentro y cómo salir. */
.session { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 14px; }
.session__user {
  max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 650; color: var(--text-2);
}
.session__logout {
  padding: 7px 12px; border: 0; border-radius: var(--r-control);
  background: var(--surface); color: var(--accent-strong);
  box-shadow: inset 0 0 0 1px var(--border-strong);
  font: inherit; font-size: 13px; font-weight: 650; cursor: pointer;
}
.session__logout:hover { background: var(--surface-tint); }

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

.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login__card {
  width: min(400px, 100%);
  display: flex; flex-direction: column; gap: 16px;
  padding: 32px 28px;
  border-radius: var(--r-card);
  box-shadow: var(--shadow-lg);
}
.login__brand { display: flex; align-items: center; gap: 12px; }
.login__title { margin: 0; font-size: 22px; font-weight: 700; }
.login__note { margin: 4px 0 0; font-size: 14px; color: var(--muted); }
.login__error {
  margin: 0; padding: 10px 12px; border-radius: var(--r-control);
  background: var(--red-soft); color: var(--red); font-size: 14px;
}
.login__submit { min-height: 46px; width: 100%; }
.login__help { margin: 0; font-size: 13px; color: var(--muted); }
.login__help a { color: var(--accent); font-weight: 600; }
.field__help { margin: -8px 0 0; font-size: 12.5px; color: var(--muted); }

.stub-banner {
  margin: 0; padding: 9px 24px;
  background: var(--amber-soft); color: var(--amber);
  font-size: 13px; font-weight: 600;
  border-bottom: 1px solid #f3d9b5;
}

.panel__body { flex: 1; overflow-y: auto; padding: 20px 24px 8px; }

.identity {
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  background: linear-gradient(135deg, var(--surface-tint) 0%, var(--surface) 100%);
}
.identity__name { margin: 0; font-size: 24px; font-weight: 750; letter-spacing: -0.01em; }
.identity__ids { margin: 6px 0 0; color: var(--text-2); word-break: break-word; }
.identity__hint, .identity__source { margin: 6px 0 0; font-size: 13px; color: var(--muted); }

.section { margin-top: 24px; }
.section__title {
  margin: 0 0 4px;
  font-size: 13px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted);
}

.rows { display: flex; flex-direction: column; }
.rows__empty { margin: 8px 0; font-size: 14px; color: var(--muted); }

.row {
  display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 4px 14px;
  align-items: start;
  width: 100%; padding: 14px 6px;
  border: 0; border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-muted); }
.row.is-selected { background: #eef2ff; }
.row:focus-visible { border-radius: 10px; }

.dot { width: 10px; height: 10px; margin-top: 6px; border-radius: 50%; }
.dot--red { background: var(--red-dot); }
.dot--green { background: var(--green-dot); }
.dot--violet { background: var(--violet); }
.dot--grey { background: var(--grey-dot); }

.row__title { font-size: 16px; font-weight: 600; color: var(--text); }
.row__meta { font-weight: 400; color: var(--muted); }
.row__handle { font-family: var(--mono); font-weight: 400; font-size: 0.92em; color: var(--text-2); }
.row__sub { grid-column: 2; font-size: 14px; color: var(--muted); }

.badge {
  grid-row: 1; grid-column: 3;
  padding: 2px 10px; border-radius: var(--r-pill);
  font-size: 13px; font-weight: 600; white-space: nowrap;
  background: var(--surface-muted); color: var(--text-2);
}
.badge--red { background: var(--red-soft); color: var(--red); }
.badge--amber { background: var(--amber-soft); color: var(--amber); }
.badge--green { background: var(--green-soft); color: var(--green); }

/* Dato de categoría especial (art. 9 RGPD): etiqueta visible, nunca oculta. */
.tag {
  display: inline-block; padding: 0 8px; border-radius: var(--r-pill);
  font-size: 12px; font-weight: 600; vertical-align: 1px;
}
.tag--special { background: var(--amber-soft); color: var(--amber); }
/* Vigencia de un vínculo societario: un cese nunca se lee como actual. */
.tag--current { background: #efeafd; color: #5a3fc0; }
.tag--ceased { background: var(--surface-muted); color: var(--text-2); box-shadow: inset 0 0 0 1px var(--border-strong); }
.detail__special { font-weight: 600; color: var(--amber); }
/* Brecha que es un registro de infostealer: malware en un equipo en el que inició sesión. */
.tag--stealer { background: var(--red-soft); color: var(--red); }
.detail__stealer { font-weight: 600; color: var(--red); }
.detail__facts { margin: 2px 0 4px; padding-left: 18px; }

.summary__note { margin: 0 0 8px; font-size: 13px; color: var(--muted); }

/* «Qué se revisó»: también lo que no dio resultado, plegado (son listas largas). */
.checked { margin: 6px 0 4px; font-size: 13px; color: var(--text-2); }
.checked summary { cursor: pointer; color: var(--muted); padding: 4px 0; }
.checked summary:hover { color: var(--text-2); }
.checked__line { margin: 6px 0; line-height: 1.5; word-break: break-word; }
.checked__pages { margin: 4px 0 8px; padding-left: 18px; }
.checked__pages li { margin: 2px 0; }

/* Monitorización: diff con la pasada anterior. */
.monitor__group { margin: 10px 0 0; }
.monitor__title { margin: 0 0 4px; font-size: 14px; font-weight: 650; color: var(--text); }
.monitor__list { margin: 0; padding-left: 18px; font-size: 14px; color: var(--text-2); }
.monitor__list li { margin: 2px 0; }
.monitor__first { margin: 0; font-size: 14px; color: var(--text-2); }
.summary {
  padding: 14px 16px; border-radius: var(--r-tile);
  background: var(--surface-muted); color: var(--text-2);
  font-size: 14px; white-space: pre-wrap;
}
.summary code { font-family: var(--mono); font-size: 0.92em; }
.summary hr { border: 0; border-top: 1px solid var(--border-strong); margin: 4px 0; }

.detail {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  background: var(--surface-tint);
  font-size: 14px; color: var(--text-2);
  max-height: 34vh; overflow-y: auto;
}
.detail__title { display: block; font-weight: 650; color: var(--text); }
.detail__muted { color: var(--muted); }
.detail a { color: var(--accent-strong); word-break: break-all; }
.detail .mono { word-break: break-all; }
.detail--error { background: var(--red-soft); color: var(--red); }

/* Formulario del sujeto: dos columnas de campos y, debajo, las acciones a todo lo ancho. */
.composer {
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px 24px 18px;
  border-top: 1px solid var(--border);
}
.composer__fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field__label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field input {
  width: 100%; min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border-strong); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 15px;
}
.field input::placeholder { color: #6b7385; }
.field input:focus-visible { outline-offset: 0; border-color: var(--accent); }
.field input:disabled { background: var(--surface-muted); }
.composer__actions { display: flex; gap: 12px; }
.composer__frequency {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px 8px;
  margin-top: 8px; font-size: 13px; color: var(--muted);
}
.composer__hint { flex-basis: 100%; margin: 0; text-align: right; font-size: 12px; color: var(--muted); }
.composer__frequency select, .watch__frequency select {
  min-height: 34px; padding: 0 10px; border: 1px solid var(--border-strong);
  border-radius: var(--r-control); background: var(--surface); color: var(--text); font: inherit;
}
.composer__actions .button { min-height: 46px; }
.composer__actions .button--primary { flex: 1; }
.composer__actions .button--secondary { padding: 0 18px; font-size: 15px; }

.button {
  padding: 0 22px; border: 0; border-radius: var(--r-control);
  font: inherit; font-size: 16px; font-weight: 650; cursor: pointer;
}
.button--primary { background: var(--accent); color: #fff; box-shadow: var(--shadow-sm); }
.button--primary:hover { background: var(--accent-strong); }
.button:disabled { opacity: 0.7; cursor: progress; }
.button--secondary {
  background: var(--surface); color: var(--accent-strong);
  box-shadow: inset 0 0 0 1px var(--border-strong), var(--shadow-sm);
}
.button--secondary:hover { background: var(--surface-tint); }
.meter__report { margin-left: auto; align-self: flex-start; padding: 10px 18px; font-size: 14px; }
.button--danger {
  background: var(--surface); color: var(--red);
  box-shadow: inset 0 0 0 1px #efb9b9, var(--shadow-sm);
}
.button--danger:hover { background: var(--red-soft); }

/* ---------- Vista de monitorización ---------- */

.monitoring {
  display: flex; flex-direction: column; gap: 16px;
  max-width: 1440px; margin: 0 auto; padding: 24px;
}
.monitoring__head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 16px 24px; }
.monitoring__title { margin: 0; font-size: 26px; font-weight: 750; letter-spacing: -0.01em; }
.monitoring__intro { margin: 6px 0 0; max-width: 72ch; font-size: 14px; color: var(--muted); }
/* La hora de la pasada programada: la de cada usuario. */
.schedule { display: flex; flex-direction: column; gap: 8px; max-width: 56ch; }
.schedule__title { margin: 0; font-size: 14px; font-weight: 700; color: var(--text-2); }
.schedule__form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.schedule__form[hidden] { display: none; }
.schedule__hour {
  min-height: 38px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--r-control);
  background: var(--surface); color: var(--text); font: inherit; font-variant-numeric: tabular-nums;
}
.schedule__hour:disabled { background: var(--surface-muted); color: var(--muted); }
.schedule__tz { font-size: 13px; color: var(--muted); }
.schedule__save { min-height: 38px; padding: 0 14px; font-size: 14px; }
.cron {
  margin: 0; max-width: 56ch; padding: 10px 14px; border-radius: var(--r-control);
  background: var(--surface-muted); color: var(--text-2); font-size: 14px;
}
.cron--none { background: var(--amber-soft); color: var(--amber); }
.cron--ok { background: var(--green-soft); color: var(--green); }

/* Qué se vigila de un sujeto y cada cuánto (su ficha). */
.watch {
  margin: 4px 0 14px; padding: 14px 16px; border: 1px solid var(--border);
  border-radius: var(--r-tile); background: var(--surface-tint);
}
.watch[hidden] { display: none; }
.watch__title { margin: 0 0 6px; font-size: 14px; font-weight: 700; color: var(--text-2); }
.watch__list { margin: 0 0 10px; padding-left: 18px; font-size: 14px; color: var(--text-2); display: grid; gap: 3px; }
.watch__frequency { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.watch__label { font-size: 14px; font-weight: 600; color: var(--text-2); }
.watch__save { min-height: 34px; padding: 0 14px; font-size: 14px; }
.watch__next { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.watch__next--warn { color: var(--amber); }
.cron--failed { background: var(--red-soft); color: var(--red); }
.monitoring__body {
  display: grid; grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
  gap: 16px; align-items: start;
}
.subjects, .history { padding: 20px; }

.subjects__list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.subjects__empty { margin: 0; font-size: 14px; color: var(--muted); }
.subject {
  display: grid; gap: 6px; width: 100%; padding: 14px 16px;
  border: 1px solid var(--border); border-radius: var(--r-tile);
  background: var(--surface); color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.subject:hover { background: var(--surface-tint); }
.subject[aria-current="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.subject--error { cursor: default; background: var(--surface-muted); }
.subject__name { font-size: 16px; font-weight: 700; overflow-wrap: anywhere; }
.subject__ids { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.subject__meta { font-size: 13px; color: var(--text-2); }
.subject__state { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

/* Historial: cada investigación con su botón de borrar al lado. */
.past__item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.past__delete { min-height: 36px; padding: 0 12px; font-size: 13px; }
.past__status { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.past__status:empty { display: none; }
.past__status--error { color: var(--red); }

.pill {
  display: inline-block; padding: 2px 9px; border-radius: var(--r-pill);
  background: var(--surface-muted); color: var(--text-2); font-size: 12px; font-weight: 700;
}
.pill--alto { background: var(--red-soft); color: var(--red); }
.pill--medio { background: var(--amber-soft); color: var(--amber); }
.pill--bajo { background: var(--green-soft); color: var(--green); }
.count {
  display: inline-block; padding: 2px 8px; border-radius: var(--r-pill);
  background: var(--surface-muted); color: var(--text-2); font-size: 12px; font-weight: 600;
}
.count--new { background: var(--green-soft); color: var(--green); }
.count--change { background: var(--amber-soft); color: var(--amber); }
.count--gone { background: var(--red-soft); color: var(--red); }
.count--quiet { background: none; color: var(--muted); font-weight: 500; padding-left: 0; }

.history__head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px 16px; }
.history__who { min-width: 0; }
.history__title { margin: 0; font-size: 20px; font-weight: 700; overflow-wrap: anywhere; }
.history__meta { margin: 4px 0 0; font-size: 14px; color: var(--muted); }
.history__actions { display: flex; gap: 10px; align-items: flex-start; }
.history__actions .button { min-height: 40px; padding: 0 16px; font-size: 14px; }
.history__status {
  margin: 12px 0 0; padding: 10px 12px; border-radius: var(--r-control);
  background: var(--surface-tint); color: var(--text-2); font-size: 14px;
}
.history__status--error { background: var(--red-soft); color: var(--red); }
.history__tools { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; margin: 16px 0 10px; }
.history__summary { margin: 0; font-size: 14px; color: var(--text-2); }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-2); cursor: pointer; }
.toggle input { width: 16px; height: 16px; accent-color: var(--accent); }

/* El historial: las pasadas a la izquierda y, a la derecha, la elegida con su grafo. */
.history__body {
  display: grid; grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
  gap: 16px; align-items: start;
}
.timeline { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.timeline__empty { margin: 0; font-size: 14px; color: var(--muted); }
.pass { border: 1px solid var(--border); border-radius: var(--r-tile); background: var(--surface); overflow: hidden; }
.pass--changes { border-left: 4px solid var(--accent); }
.pass__head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; width: 100%;
  padding: 12px 14px; border: 0; background: none;
  color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.pass__head:hover { background: var(--surface-tint); }
.pass__head[aria-pressed="true"] { background: var(--surface-tint); box-shadow: inset 0 0 0 2px var(--accent); }
.pass__when { font-weight: 650; font-variant-numeric: tabular-nums; }
.pass__origin { font-size: 13px; color: var(--muted); }
.pass__counts { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }

.passview {
  display: flex; flex-direction: column; gap: 10px; min-width: 0; padding: 16px;
  border: 1px solid var(--border); border-radius: var(--r-tile); background: var(--surface);
}
.passview[hidden] { display: none; }
.passview__title { margin: 0; font-size: 17px; font-weight: 700; }
.passview__meta { margin: 0; font-size: 14px; color: var(--text-2); }
.passview__graph { position: relative; }
.passview__canvas {
  height: 520px; border-radius: var(--r-control); background: var(--surface-muted);
}
.passview__empty {
  position: absolute; inset: 0; display: grid; place-items: center; margin: 0; padding: 24px;
  color: var(--muted); font-size: 14px; text-align: center;
}
.passview__empty[hidden] { display: none; }
.passview__detail {
  margin: 0; padding: 10px 12px; border-radius: var(--r-control);
  background: var(--surface-tint); color: var(--text-2); font-size: 13.5px; overflow-wrap: anywhere;
}
.passview__diff .monitor__group:first-child { margin-top: 0; }

/* Leyenda del grafo de una pasada: las mismas líneas que DIFF_STYLE (app.js). */
.difflegend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0; padding: 0; list-style: none; font-size: 13px; color: var(--text-2); }
.difflegend:empty { display: none; }
.difflegend li { display: inline-flex; align-items: center; gap: 8px; }
.diffkey { display: inline-block; width: 26px; border-top: 3px solid var(--grey-dot); }
.diffkey--novedad { border-top-color: var(--green-dot); }
.diffkey--pista_nueva { border-top-color: var(--green-dot); border-top-style: dashed; }
.diffkey--cambio { border-top-color: var(--amber-dot); }
.diffkey--ya_no_aparece { border-top-color: var(--red-dot); border-top-style: dashed; }
.diffkey--fuera_de_ventana { border-top-color: #9aa3b6; border-top-style: dotted; }
.diffkey--sin_comprobar { border-top-color: #6b7385; border-top-style: dashed; }
.diffkey--de_partida { border-top-color: #ae3ec9; }
.diffkey--vuelve { border-top-color: #1098ad; }
.diffkey--sin_cambios { border-top-color: #9aa3b6; opacity: 0.5; }

.dialog {
  width: min(440px, calc(100vw - 32px)); padding: 0; border: 0;
  border-radius: var(--r-card); box-shadow: var(--shadow-lg); color: var(--text);
}
.dialog::backdrop { background: rgba(16, 24, 40, 0.35); }
.dialog__body { display: flex; flex-direction: column; gap: 12px; padding: 24px; }
.dialog__body p { margin: 0; }
.dialog__title { margin: 0; font-size: 20px; font-weight: 700; }
.dialog__note { font-size: 14px; color: var(--muted); }
.dialog__actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.dialog__actions .button { min-height: 42px; padding: 0 18px; font-size: 15px; }

/* ---------- Pantallas estrechas ---------- */

/* Medidor en una columna cuando no cabe en dos. */
@media (max-width: 1380px) {
  .meter {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "head" "segments" "labels" "counters" "facts";
    grid-template-rows: none;
  }
  .meter__facts { margin-top: 16px; }
  .graph { min-height: max(400px, calc(100vh - 420px)); }
}

@media (max-width: 1000px) {
  .topbar { flex-wrap: wrap; height: auto; gap: 10px 16px; padding: 10px 16px; position: static; }
  .monitoring { padding: 16px; }
  .monitoring__body { grid-template-columns: 1fr; }
  .history__body { grid-template-columns: 1fr; }
  .passview__canvas { height: 60vh; }
  .layout { grid-template-columns: 1fr; height: auto; }
  .workspace { padding: 16px; overflow: visible; }
  .graph { min-height: 0; grid-template-columns: 1fr; grid-template-rows: auto auto; }
  .graph__canvas, .graph__empty { grid-column: 1; grid-row: 1; height: 60vh; }
  .legend { grid-column: 1; grid-row: 2; justify-self: start; }
  .panel { border-left: 0; border-top: 1px solid var(--border); }
  .panel__body { overflow: visible; }
}

@media (max-width: 560px) {
  .counters { gap: 8px; }
  .counter dd { font-size: 24px; }
  .meter__level { font-size: 32px; }
}

/* ---------- Tarea larga en curso ---------- */

/* Qué hace el servidor, paso a paso. Fija abajo, en las dos pestañas;
   en la de investigación, en el hueco entre la leyenda del grafo (unos 320px) y el panel de la
   derecha (460px). */
.progress {
  position: fixed; left: calc(320px + (100vw - 780px) / 2); bottom: 24px; z-index: 40;
  transform: translateX(-50%);
  width: clamp(360px, calc(100vw - 812px), 560px); max-height: min(60vh, 520px);
  display: flex; flex-direction: column; gap: 6px; padding: 16px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card);
  box-shadow: var(--shadow-lg);
}
.progress[hidden] { display: none; }
.progress__head { display: flex; align-items: center; gap: 10px; }
.progress__title { flex: 1; margin: 0; font-weight: 650; color: var(--text); }
.progress__time { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.progress__hint { margin: 0; color: var(--muted); font-size: 13px; }
.progress__steps {
  display: grid; gap: 4px; margin: 4px 0 0; padding: 0; list-style: none; overflow-y: auto;
  font-size: 14px; color: var(--text-2);
}
.progress__step { display: grid; grid-template-columns: 16px 1fr auto; gap: 8px; align-items: baseline; }
.progress__step::before { content: "✓"; color: var(--green); font-weight: 700; text-align: center; }
.progress__step[data-state="en_curso"] { color: var(--text); font-weight: 600; }
.progress__step[data-state="en_curso"]::before { content: "›"; color: var(--accent); }
.progress__step[data-state="sin_consultar"]::before { content: "!"; color: var(--amber); }
.progress__step[data-state="segundo_plano"]::before { content: "↻"; color: var(--slate); }
.progress__step[data-state="cortado"]::before { content: "×"; color: var(--red); }
.progress__secs { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.progress__spinner {
  flex: none; width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid var(--border-strong); border-top-color: var(--accent);
  animation: progress-spin 0.9s linear infinite;
}
@keyframes progress-spin { to { transform: rotate(360deg); } }
body:has(#view-monitoring:not([hidden])) .progress { left: 50%; width: min(580px, calc(100vw - 32px)); }
/* Por debajo de ~1180px no cabe entre la leyenda y el panel: centrada en la ventana. */
@media (max-width: 1180px) {
  .progress { left: 50%; width: min(580px, calc(100vw - 32px)); }
}
/* Mientras llega lo nuevo, lo de antes queda atenuado: no es el resultado de esta petición. */
.is-stale { opacity: 0.45; transition: opacity 0.2s; }

/* ---------- Movimiento reducido ---------- */

@media (prefers-reduced-motion: reduce) {
  .progress__spinner { border-color: var(--accent); }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Elemento del diff de la monitorización que lleva a su arista en el grafo. */
.row.row--inline {
  display: inline; width: auto; padding: 0; border: 0; border-radius: 0; background: none;
  font: inherit; color: var(--accent-strong); text-align: left; cursor: pointer;
}
.row.row--inline:hover { text-decoration: underline; background: none; }
