/* =========================================================================
   VIGIA-ENFERMERIA — terminal stylesheet
   Phosphor green CRT aesthetic. Dense grid. ASCII borders. No rounded.
   ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;700&family=Major+Mono+Display&display=swap');

:root {
  --bg:           #0a0e0a;
  --bg-panel:     #0d130d;
  --bg-well:      #060906;
  --bg-row:       #0b110b;
  --bg-row-alt:   #0a0e0a;
  --bg-hover:     #112011;

  --phos:         #39ff14;
  --phos-dim:     #1f8a14;
  --phos-fade:    #0d3d0a;
  --phos-ghost:   #082208;

  --amber:        #ffb000;
  --amber-dim:    #8a5f00;
  --red:          #ff3344;
  --red-dim:      #8a1c24;
  --alarm-red:        #ff003c;
  --alarm-red-bright: #ff5470;
  --alarm-red-glow:   rgba(255, 0, 60, 0.55);
  --alarm-red-bg:     rgba(255, 0, 60, 0.18);

  --fg:           #d4dcc6;
  --fg-dim:       #6f7a64;
  --fg-faint:     #3d4438;

  --mono:         'JetBrains Mono', 'IBM Plex Mono', ui-monospace, Menlo, Consolas, monospace;
  --display:      'Major Mono Display', 'JetBrains Mono', monospace;

  --gap:          14px;
  --gap-sm:       8px;
  --gap-lg:       24px;
  --row-h:        28px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

body {
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse 100% 60% at 50% -10%, rgba(57,255,20,0.04), transparent 70%),
    radial-gradient(ellipse 80% 50% at 50% 110%, rgba(57,255,20,0.03), transparent 70%);
}

/* Scanlines overlay (toggle via body[data-scanlines]) */
body::before {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0,
    rgba(0,0,0,0) 2px,
    rgba(0,0,0,0.18) 3px,
    rgba(0,0,0,0) 4px
  );
  mix-blend-mode: multiply;
  z-index: 9998;
  opacity: 0;
  transition: opacity .3s;
}
body[data-scanlines="on"]::before { opacity: 1; }

/* Subtle CRT vignette */
body::after {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 9997;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.55) 100%);
  opacity: 0.7;
}

/* =========================================================================
   Type
   ========================================================================= */
h1, h2, h3, h4 { font-weight: 500; margin: 0; letter-spacing: 0.02em; }
h1 { font-family: var(--mono); color: var(--phos); }
.section-title {
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--phos);
  text-transform: uppercase;
  display: flex; align-items: baseline; gap: 12px;
  margin: 0 0 var(--gap) 0;
}
.section-title::before { content: '▮'; color: var(--phos); animation: blink 1.1s steps(2) infinite; }
.section-title .num { color: var(--fg-dim); font-weight: 400; }
.section-title .rule {
  flex: 1;
  border-bottom: 1px dashed var(--phos-fade);
  transform: translateY(-3px);
}
.section-title .meta { color: var(--fg-dim); font-size: 10px; letter-spacing: 0.18em; }

a {
  color: var(--phos);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color .15s, color .15s, background .15s;
}
a:hover {
  color: #aeffa0;
  border-bottom-color: var(--phos);
  background: rgba(57,255,20,0.06);
}

::selection { background: var(--phos); color: var(--bg); }

/* =========================================================================
   Layout
   ========================================================================= */
.shell {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px 80px;
  position: relative;
  z-index: 1;
}

.statusbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--phos-fade);
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--fg-dim);
  padding: 8px 24px;
  display: flex; flex-wrap: wrap; gap: 18px; align-items: center;
}
.statusbar .item { display: inline-flex; gap: 8px; align-items: center; }
.statusbar .label { color: var(--fg-faint); }
.statusbar .val { color: var(--phos); font-weight: 500; }
.statusbar .val.amber { color: var(--amber); }
.statusbar .dot {
  display: inline-block; width: 7px; height: 7px;
  background: var(--phos);
  box-shadow: 0 0 8px var(--phos);
  animation: pulse 2s infinite;
}
.statusbar .sep { color: var(--fg-faint); }
.statusbar .right { margin-left: auto; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}
@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}
@keyframes flicker {
  0%, 18%, 22%, 25%, 53%, 57%, 100% { opacity: 1; }
  20%, 24%, 55% { opacity: 0.85; }
}
body[data-flicker="on"] .flickerable { animation: flicker 6s infinite; }

/* =========================================================================
   Section 1: Hero
   ========================================================================= */
.hero {
  padding: 36px 0 24px;
  border-bottom: 1px solid var(--phos-fade);
  margin-bottom: var(--gap-lg);
}
.hero .hero-meta {
  display: flex; flex-wrap: wrap; gap: 14px;
  font-size: 10.5px;
  letter-spacing: 0.22em;
  color: var(--fg-dim);
  text-transform: uppercase;
  margin-bottom: 14px;
  align-items: center;
  border-bottom: 1px dashed var(--phos-fade);
  padding-bottom: 12px;
}
.hero .hero-meta .glyph { color: var(--phos); }
.hero .hero-meta .v { color: var(--phos); }
.hero .hero-meta .sep { color: var(--fg-faint); }
.hero h1.title {
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(34px, 6vw, 76px);
  color: var(--phos);
  text-shadow: 0 0 12px rgba(57,255,20,0.32);
  letter-spacing: 0.02em;
  line-height: 1.05;
  margin-bottom: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}
.hero h1.title .bracket { color: var(--phos-dim); }
.hero h1.title .accent { color: var(--amber); }
.hero h1.title .cursor { color: var(--phos); animation: blink 1.1s steps(2) infinite; font-weight: 400; }
@media (max-width: 720px) {
  .hero h1.title { white-space: normal; font-size: clamp(28px, 9vw, 44px); }
}
.hero .tagline {
  color: var(--fg);
  font-size: 13px;
  max-width: 580px;
  border-left: 2px solid var(--phos);
  padding-left: 14px;
}
.hero .tagline .prefix { color: var(--phos-dim); }

.counters {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap);
  margin-top: var(--gap-lg);
}
.counter {
  border: 1px solid var(--phos-fade);
  background: var(--bg-panel);
  padding: 14px 18px 16px;
  position: relative;
}
.counter .label {
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--fg-dim);
  text-transform: uppercase;
  display: flex; justify-content: space-between;
}
.counter .label .id { color: var(--phos-fade); }
.counter .val {
  font-family: var(--mono);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: clamp(34px, 5.5vw, 62px);
  color: var(--phos);
  line-height: 1.05;
  letter-spacing: 0.01em;
  text-shadow: 0 0 10px rgba(57,255,20,0.30);
  margin-top: 6px;
}
.counter .delta {
  font-size: 11px;
  color: var(--phos-dim);
  letter-spacing: 0.06em;
}
.counter .delta.amber { color: var(--amber); }
.counter::before {
  content: '┌';
  position: absolute; top: -1px; left: -1px;
  color: var(--phos); font-size: 14px; line-height: 1;
}
.counter::after {
  content: '┘';
  position: absolute; bottom: -8px; right: -1px;
  color: var(--phos); font-size: 14px; line-height: 1;
}

/* =========================================================================
   Section 2: Daily Feed
   ========================================================================= */
.feed { display: grid; grid-template-columns: 1fr; gap: var(--gap-sm); }
.feed-empty {
  border: 1px solid var(--phos-fade);
  padding: 60px 20px;
  text-align: center;
  background: var(--bg-panel);
}
.feed-empty .glyph {
  font-family: var(--display);
  font-size: 56px;
  color: var(--phos-dim);
  letter-spacing: 0.1em;
}
.feed-empty .msg {
  font-size: 16px; color: var(--phos);
  letter-spacing: 0.2em; margin-top: 12px;
}
.feed-empty .sub {
  color: var(--fg-dim); font-size: 11px; letter-spacing: 0.16em; margin-top: 8px;
}

.card {
  border: 1px solid var(--phos-fade);
  background: var(--bg-panel);
  padding: 0;
  transition: border-color .15s, background .15s;
}
.card:hover { border-color: var(--phos-dim); background: #0e150e; }
.card .head {
  display: grid;
  grid-template-columns: 80px 110px 1fr auto;
  gap: 14px;
  padding: 12px 14px;
  align-items: center;
  cursor: pointer;
}
.card .head:hover { background: var(--bg-hover); }
.card .ts { color: var(--phos-dim); font-size: 11px; letter-spacing: 0.06em; }
.card .ts .age { color: var(--phos); }

.badge {
  display: inline-block;
  font-size: 10px;
  letter-spacing: 0.16em;
  padding: 2px 8px;
  border: 1px solid var(--phos-dim);
  color: var(--phos);
  text-transform: uppercase;
  white-space: nowrap;
  text-align: center;
}
.badge.cat { color: var(--amber); border-color: var(--amber-dim); }
.badge.boe                 { --b: #ff8a3d; }
.badge.bocm                { --b: #c46cff; }
.badge.boam                { --b: #ff3344; }
.badge.comunidad_madrid    { --b: #6cb4ff; }
.badge.ayuntamiento_madrid { --b: #ff6c8a; }
.badge.canal_isabel_ii     { --b: #6cffe1; }
.badge.codem               { --b: #ffe46c; }
.badge.datos_madrid        { --b: #a0a0a0; }
.badge.metro_madrid        { --b: #00bcd4; }
.badge.administracion_gob  { --b: #888888; }
.badge[class*="badge"][class*=" "] { } /* noop */
.badge.src {
  color: var(--b, var(--phos));
  border-color: color-mix(in oklab, var(--b, var(--phos)) 50%, transparent);
}

.card .title {
  color: var(--fg);
  font-size: 13px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .chev {
  color: var(--phos);
  font-family: var(--mono);
  font-size: 14px;
  transition: transform .2s;
  user-select: none;
}
.card.open .chev { transform: rotate(90deg); }

.card .body {
  display: none;
  padding: 0 14px 14px 14px;
  border-top: 1px dashed var(--phos-fade);
  margin-top: 4px;
}
.card.open .body { display: block; }
.card .summary-block {
  margin: 14px 0;
  padding: 12px 14px;
  background: var(--bg-well);
  border-left: 2px solid var(--phos);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--fg);
}
.card .summary-block .lbl {
  font-size: 10px; letter-spacing: 0.2em; color: var(--phos-dim);
  display: block; margin-bottom: 6px;
}
.card .meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px 24px;
  font-size: 11px;
  margin-bottom: 14px;
}
.card .meta-grid div { color: var(--fg-dim); }
.card .meta-grid div b { color: var(--phos); font-weight: 500; }
.card .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-term {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  padding: 6px 12px;
  background: transparent;
  color: var(--phos);
  border: 1px solid var(--phos-dim);
  cursor: pointer;
  text-transform: uppercase;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-term:hover {
  background: var(--phos);
  color: var(--bg);
  border-color: var(--phos);
}
.btn-term.amber { color: var(--amber); border-color: var(--amber-dim); }
.btn-term.amber:hover { background: var(--amber); color: var(--bg); border-color: var(--amber); }
.btn-term.ghost { color: var(--fg-dim); border-color: var(--phos-fade); }
.btn-term.ghost:hover { color: var(--phos); border-color: var(--phos-dim); background: transparent; }
.btn-term.copied { background: var(--phos); color: var(--bg); }

/* =========================================================================
   Section 3: Historical Database
   ========================================================================= */
.cmdbar {
  background: var(--bg-well);
  border: 1px solid var(--phos-fade);
  padding: 10px 14px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  font-size: 12px;
  margin-bottom: 12px;
}
.cmdbar .prompt { color: var(--phos); }
.cmdbar .seg {
  display: inline-flex; align-items: center; gap: 4px;
  border: 1px dashed var(--phos-fade);
  padding: 3px 8px;
  color: var(--fg-dim);
}
.cmdbar .seg label { color: var(--phos-dim); font-size: 10.5px; letter-spacing: 0.1em; }
.cmdbar .seg select,
.cmdbar .seg input {
  background: transparent;
  color: var(--fg);
  border: 0;
  outline: 0;
  font-family: var(--mono);
  font-size: 12px;
  padding: 0;
  min-width: 0;
}
.cmdbar .seg select option { background: var(--bg-panel); color: var(--fg); }
.cmdbar .seg input.q { width: 220px; }
.cmdbar .seg input::placeholder { color: var(--fg-faint); }
.cmdbar .clear {
  margin-left: auto;
  font-size: 11px;
  color: var(--fg-dim); cursor: pointer;
  letter-spacing: 0.14em;
}
.cmdbar .clear:hover { color: var(--phos); }

.tbl-wrap { border: 1px solid var(--phos-fade); background: var(--bg-panel); overflow-x: auto; }
table.term {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-family: var(--mono);
}
table.term thead th {
  text-align: left;
  font-weight: 500;
  font-size: 10.5px;
  letter-spacing: 0.18em;
  color: var(--phos);
  text-transform: uppercase;
  padding: 10px 12px;
  background: var(--bg-well);
  border-bottom: 1px solid var(--phos-fade);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
table.term thead th .sort {
  color: var(--phos-fade);
  margin-left: 4px;
  font-size: 10px;
}
table.term thead th[aria-sort="asc"] .sort,
table.term thead th[aria-sort="desc"] .sort { color: var(--phos); }
table.term tbody td {
  padding: 8px 12px;
  border-bottom: 1px dashed var(--phos-ghost);
  vertical-align: top;
  color: var(--fg);
}
table.term tbody tr { cursor: pointer; }
table.term tbody tr:hover td { background: var(--bg-hover); }
table.term tbody tr.expanded td { background: #0e160e; }
table.term td.col-date { color: var(--phos-dim); white-space: nowrap; width: 100px; }
table.term td.col-src { width: 130px; }
table.term td.col-cat { width: 130px; }
table.term td.col-arrow { color: var(--phos); width: 24px; text-align: right; }
table.term td.col-title {
  max-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.expanded-row td {
  background: var(--bg-well) !important;
  padding: 14px 18px !important;
  border-bottom: 1px solid var(--phos-fade) !important;
}
.expanded-row .e-title { color: var(--phos); font-size: 13px; line-height: 1.5; margin-bottom: 10px; }
.expanded-row .e-summary { color: var(--fg); font-size: 12px; line-height: 1.6; margin-bottom: 12px; padding: 10px 12px; background: var(--bg); border-left: 2px solid var(--phos-dim); }
.expanded-row .e-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.expanded-row .e-aux-row {
  display: flex; flex-wrap: wrap; gap: 8px 18px;
  margin: 0 0 12px 0;
  font-size: 10.5px; letter-spacing: 0.1em;
  color: var(--fg-dim);
}
.expanded-row .e-aux b { color: var(--phos-dim); font-weight: 500; margin-right: 4px; }
.expanded-row .e-aux.e-discarded { color: var(--amber); }
.expanded-row .e-aux.e-discarded b { color: var(--amber); }

/* =========================================================================
   Enricher v2 — chips de campos estructurados (proceso/plazas/deadline/tasa)
   ========================================================================= */
.chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 0 0 12px 0;
}
.expanded-row .chips { margin-bottom: 10px; }
.chip {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  padding: 3px 8px;
  border: 1px solid var(--phos-fade);
  background: var(--bg-well);
  color: var(--phos-dim);
  text-transform: uppercase;
}
.chip-pt { color: var(--phos); border-color: var(--phos-dim); }
.chip-plz { color: #6cb4ff; border-color: color-mix(in oklab, #6cb4ff 40%, transparent); }
.chip-eur { color: var(--amber); border-color: var(--amber-dim); }
.chip-fase { color: #c46cff; border-color: color-mix(in oklab, #c46cff 40%, transparent); }
.chip-dl { color: var(--phos-dim); border-color: var(--phos-fade); }
.chip-dl-open { color: var(--phos); border-color: var(--phos-dim); }
.chip-dl-urgent {
  color: var(--amber);
  border-color: var(--amber);
  text-shadow: 0 0 6px color-mix(in oklab, var(--amber) 50%, transparent);
}
.chip-dl-closed { color: var(--fg-faint); border-color: var(--phos-ghost); text-decoration: line-through; }
.chip-discard {
  color: #ff6c8a;
  border-color: color-mix(in oklab, #ff6c8a 40%, transparent);
  background: color-mix(in oklab, #ff6c8a 10%, var(--bg-well));
}

/* Card descartada por el enricher: opaca para indicar que es ruido */
.card.card-discarded { opacity: 0.55; border-style: dashed; }
.card.card-discarded:hover { opacity: 0.9; }

/* Línea destacada para el next_action en la card */
.card .meta-grid .next-action {
  grid-column: 1 / -1;
  color: var(--amber);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  border-top: 1px dashed var(--phos-ghost);
  padding-top: 8px; margin-top: 4px;
}

/* Toggle "show discarded" en el cmdbar */
.cmdbar .toggle-seg input[type="checkbox"] {
  accent-color: var(--phos);
  width: 12px; height: 12px;
  cursor: pointer;
}
.cmdbar .toggle-seg label { cursor: pointer; }

.tbl-foot {
  display: flex; align-items: center; gap: 14px;
  font-size: 10.5px; letter-spacing: 0.14em;
  color: var(--fg-dim); padding: 10px 14px;
  border-top: 1px solid var(--phos-fade);
  background: var(--bg-well);
}
.tbl-foot .count b { color: var(--phos); font-weight: 500; }

/* =========================================================================
   Section 4: Intelligence
   ========================================================================= */
.intel {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: var(--gap);
}
.intel .full { grid-column: 1 / -1; }
.panel {
  border: 1px solid var(--phos-fade);
  background: var(--bg-panel);
  padding: 14px 16px 18px;
  position: relative;
}
.panel h3 {
  font-size: 10.5px;
  letter-spacing: 0.22em;
  color: var(--phos);
  text-transform: uppercase;
  margin-bottom: 14px;
  display: flex; justify-content: space-between; align-items: baseline;
}
.panel h3 .meta { color: var(--fg-faint); font-weight: 400; font-size: 10px; }

.bars { display: flex; flex-direction: column; gap: 8px; font-size: 11.5px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 40px; gap: 10px; align-items: center; }
.bar-row .name { color: var(--fg); letter-spacing: 0.06em; }
.bar-row .track {
  height: 14px;
  background: var(--bg-well);
  border: 1px solid var(--phos-ghost);
  position: relative;
  overflow: hidden;
}
.bar-row .fill {
  height: 100%;
  background:
    repeating-linear-gradient(
      to right,
      var(--phos) 0 6px,
      var(--phos-dim) 6px 7px
    );
  box-shadow: 0 0 6px rgba(57,255,20,0.3) inset;
  width: 0;
  transition: width 1.2s cubic-bezier(.2,.7,.2,1);
}
.bar-row .num { color: var(--phos); text-align: right; font-variant-numeric: tabular-nums; }

.donut-wrap { display: grid; grid-template-columns: 180px 1fr; gap: 18px; align-items: center; }
.donut-wrap svg { display: block; }
.donut-legend { font-size: 11px; }
.donut-legend .li { display: grid; grid-template-columns: 14px 1fr auto auto; gap: 8px; padding: 4px 0; align-items: center; }
.donut-legend .sw { width: 10px; height: 10px; }
.donut-legend .lname { color: var(--fg); letter-spacing: 0.06em; text-transform: uppercase; font-size: 10.5px; }
.donut-legend .lcount { color: var(--phos); font-variant-numeric: tabular-nums; }
.donut-legend .lpct { color: var(--fg-dim); font-size: 10px; width: 42px; text-align: right; }

/* =========================================================================
   Section 5: Sources Status
   ========================================================================= */
.sources-tbl td.col-name { font-weight: 500; color: var(--phos); width: 150px; letter-spacing: 0.06em; }
.sources-tbl td.col-url { color: var(--fg-dim); font-size: 11px; }
.sources-tbl td.col-code { width: 64px; color: var(--phos); }
.sources-tbl td.col-status { width: 100px; }
.sources-tbl td.col-hits { width: 80px; text-align: right; color: var(--phos); font-variant-numeric: tabular-nums; }
.sources-tbl .hits-link {
  background: transparent;
  border: 1px solid transparent;
  color: var(--phos);
  font: inherit;
  padding: 0 6px;
  cursor: pointer;
  letter-spacing: 0;
}
.sources-tbl .hits-link:hover,
.sources-tbl .hits-link:focus-visible {
  border-color: var(--phos-dim);
  background: rgba(57, 255, 20, 0.06);
  outline: none;
}
.sources-tbl td.col-probe { width: 130px; color: var(--fg-dim); font-size: 11px; }
.status-pill {
  display: inline-block;
  padding: 1px 8px;
  border: 1px solid;
  font-size: 10px;
  letter-spacing: 0.16em;
}
.status-pill.ok { color: var(--phos); border-color: var(--phos-dim); }
.status-pill.down { color: var(--red); border-color: var(--red-dim); }
.status-pill.skipped { color: var(--amber); border-color: var(--amber-dim); }

.src-detail-row td {
  background: var(--bg-well) !important;
  border-bottom: 1px solid var(--phos-fade) !important;
  padding: 12px 18px !important;
}
.src-detail {
  font-size: 12px;
  line-height: 1.6;
  color: var(--fg);
  border-left: 2px solid var(--phos-dim);
  padding: 6px 12px;
  font-style: italic;
}
.src-detail::before {
  content: 'FIELD MEMO ';
  color: var(--phos);
  font-style: normal;
  letter-spacing: 0.2em;
  font-size: 10px;
  display: block;
  margin-bottom: 4px;
}

/* =========================================================================
   Section 6: Coverage / Watchlist
   ========================================================================= */
.watchlist {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--gap-sm);
}
.target {
  border: 1px solid var(--phos-fade);
  background: var(--bg-panel);
  padding: 10px 12px;
  font-size: 11.5px;
  display: flex; flex-direction: column; gap: 4px;
  position: relative;
}
.target::before {
  content: '◉';
  color: var(--phos);
  position: absolute;
  top: 10px; right: 10px;
  font-size: 9px;
  text-shadow: 0 0 6px var(--phos);
  animation: pulse 2.4s infinite;
}
.target.cold::before { color: var(--phos-fade); animation: none; text-shadow: none; }
.target.urgent::before { color: var(--alarm-red); text-shadow: 0 0 10px var(--alarm-red-glow); animation: alarmDot 1.6s ease-in-out infinite; }
.target .id { color: var(--fg-faint); font-size: 9.5px; letter-spacing: 0.18em; }
.target .name { color: var(--phos); letter-spacing: 0.04em; }
.target .desc { color: var(--fg-dim); font-size: 10.5px; }
.target .stat {
  display: flex; gap: 8px; font-size: 10px;
  color: var(--fg-faint); margin-top: 4px; letter-spacing: 0.1em;
}
.target .stat b { color: var(--phos); font-weight: 500; }
.target.cold .name { color: var(--fg-dim); }
.target .countdown {
  font-size: 10px; letter-spacing: 0.12em;
  color: var(--phos-dim);
  border-top: 1px dashed var(--phos-ghost);
  padding-top: 4px; margin-top: 2px;
}
.target .phase {
  font-size: 9.5px; letter-spacing: 0.14em;
  color: var(--fg-dim);
}
/* Hits clickable en watchlist (mismo patrón que en SOURCES) */
.target .stat .hits-link {
  display: inline; padding: 0; margin: 0;
  font: inherit; color: inherit; background: transparent;
  border: 0; border-bottom: 1px dashed var(--phos-fade);
  cursor: pointer;
}
.target .stat .hits-link:hover,
.target .stat .hits-link:focus { color: var(--phos); border-bottom-color: var(--phos); outline: none; }

/* ===== Alarma roja: tile urgente del watchlist =========================
   Pulso simultáneo del fondo + borde sin tocar el color del texto.
   Texto se mantiene a 100% de contraste por encima del bg pulsante.
   ===================================================================== */
.target.urgent {
  border-color: var(--alarm-red);
  animation: alarmTile 1.6s ease-in-out infinite;
  position: relative;
}
.target.urgent .name { color: var(--alarm-red-bright); text-shadow: 0 0 6px var(--alarm-red-glow); }
.target.urgent .countdown { color: var(--alarm-red-bright); font-weight: 500; }
.target.urgent .stat .hits-link { border-bottom-color: var(--alarm-red); }
.target.urgent .stat .hits-link:hover { color: var(--alarm-red-bright); border-bottom-color: var(--alarm-red-bright); }

@keyframes alarmTile {
  0%, 100% { background-color: var(--bg-panel); border-color: var(--alarm-red); box-shadow: 0 0 0 0 transparent; }
  50%      { background-color: var(--alarm-red-bg); border-color: var(--alarm-red-bright); box-shadow: 0 0 16px -4px var(--alarm-red-glow); }
}
@keyframes alarmDot {
  0%, 100% { color: var(--alarm-red);        text-shadow: 0 0 6px var(--alarm-red-glow); }
  50%      { color: var(--alarm-red-bright); text-shadow: 0 0 14px var(--alarm-red); }
}
@keyframes alarmText {
  0%, 100% { color: var(--alarm-red);        text-shadow: 0 0 4px var(--alarm-red-glow); }
  50%      { color: var(--alarm-red-bright); text-shadow: 0 0 10px var(--alarm-red); }
}

/* ===== Bell de alarma en la status bar ===============================
   Se muestra solo si DATA.meta.targets_urgent > 0. Pulso sincronizado
   con los tiles. Si hay un único urgente, muestra `🔔 NAME · CIERRA EN N`;
   si hay varios, `🔔 N URGENTES`. Click → modal con los items urgentes.
   ===================================================================== */
.statusbar .item.alarm {
  cursor: pointer;
  color: var(--alarm-red);
  animation: alarmPill 1.6s ease-in-out infinite;
  border: 1px solid var(--alarm-red);
  padding: 1px 8px;
  letter-spacing: 0.18em;
  margin-left: 4px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.statusbar .item.alarm:hover { background: var(--alarm-red-bg); }

/* Campana SVG ────────────────────────────────────────────────────────
   Inline en el pill del header y en los tiles urgent del watchlist.
   `currentColor` hereda del padre para integrarse con el pulso del pill;
   los tamaños van en `em` para escalar con la letra del contenedor (no
   tiene la misma altura una etiqueta del header ~11px que un countdown
   de tile ~10px). El drop-shadow también va en em para no saturar
   contextos chicos.
   ───────────────────────────────────────────────────────────────── */
.bell-svg {
  width: 1.1em;
  height: 1.1em;
  flex-shrink: 0;
  color: var(--alarm-red);
  vertical-align: -0.18em;
  filter: drop-shadow(0 0 0.15em var(--alarm-red-glow));
}
.bell-svg.bell-alarm {
  animation: bellGlow 1.6s ease-in-out infinite;
}
.target.urgent .bell-svg { color: var(--alarm-red-bright); }
.statusbar .item.alarm .bell-svg { color: inherit; }
@keyframes bellGlow {
  0%, 100% { filter: drop-shadow(0 0 0.08em var(--alarm-red-glow)); }
  50%      { filter: drop-shadow(0 0 0.55em var(--alarm-red)); }
}
@media (prefers-reduced-motion: reduce) {
  .bell-svg.bell-alarm { animation: none; filter: drop-shadow(0 0 0.3em var(--alarm-red-glow)); }
}
/* Pulso del pill: color, borde y un fondo tenue van y vienen al unísono.
   Sin movimiento — solo intensidad, como una luz que palpita. */
@keyframes alarmPill {
  0%, 100% {
    color: var(--alarm-red);
    border-color: var(--alarm-red);
    background-color: transparent;
    text-shadow: 0 0 4px var(--alarm-red-glow);
    box-shadow: 0 0 0 0 transparent;
  }
  50% {
    color: var(--alarm-red-bright);
    border-color: var(--alarm-red-bright);
    background-color: var(--alarm-red-bg);
    text-shadow: 0 0 10px var(--alarm-red);
    box-shadow: 0 0 12px -3px var(--alarm-red-glow);
  }
}

/* ===== Modal terminal (<dialog>) ========================================
   Open via `dlg.showModal()`; close via ESC / click en backdrop / botón ×.
   Estética CRT: marco ASCII con corners, borde phosphor, scanlines.
   ===================================================================== */
.term-modal {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--fg);
  max-width: 920px;
  width: calc(100vw - 64px);
  max-height: calc(100vh - 64px);
  font-family: var(--mono);
}
.term-modal::backdrop {
  background: rgba(4, 7, 4, 0.78);
  backdrop-filter: blur(2px);
}
.term-modal[open] { animation: modalIn 180ms ease-out; }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(-6px) scale(0.985); }
  to   { opacity: 1; transform: none; }
}
.term-modal-frame {
  border: 1px solid var(--phos-dim);
  background: var(--bg-panel);
  box-shadow: 0 0 0 1px var(--bg), 0 0 32px -8px rgba(57, 255, 20, 0.35);
  display: flex; flex-direction: column;
  max-height: calc(100vh - 64px);
}
.term-modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px dashed var(--phos-fade);
  background: var(--bg-well);
  font-size: 11px;
  letter-spacing: 0.18em;
}
.term-modal-head .corner {
  color: var(--phos-dim);
  font-family: var(--mono);
  user-select: none;
}
.term-modal-head .corner.left { margin-right: -4px; }
.term-modal-head .corner.right { margin-left: auto; }
.term-modal-title {
  color: var(--phos);
  text-transform: uppercase;
  font-weight: 500;
}
.term-modal-meta {
  color: var(--fg-dim);
  font-size: 10px;
  letter-spacing: 0.14em;
}
.term-modal-close {
  background: transparent;
  border: 0;
  color: var(--fg-dim);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.16em;
  padding: 2px 6px;
  cursor: pointer;
}
.term-modal-close:hover { color: var(--alarm-red); }

.term-modal-body {
  overflow-y: auto;
  padding: 14px 18px;
  flex: 1 1 auto;
  display: flex; flex-direction: column; gap: 8px;
}
.term-modal-body .card {
  /* Anular el ancho cardado del feed para que el contenido ocupe todo
     el modal-body y la card pinte sus chips/grid sin estrecheces. */
  width: 100%;
}
.term-modal-empty {
  text-align: center;
  padding: 36px 0;
  color: var(--fg-dim);
  letter-spacing: 0.18em;
  font-size: 12px;
}
.term-modal-foot {
  display: flex; flex-direction: column; gap: 4px;
  padding: 8px 14px 10px;
  border-top: 1px dashed var(--phos-fade);
  background: var(--bg-well);
  color: var(--fg-faint);
  font-size: 10px;
  letter-spacing: 0.16em;
}
.term-modal-foot .hint { color: var(--phos-dim); }
.term-modal-foot .bracket {
  font-family: var(--mono);
  color: var(--phos-fade);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  user-select: none;
}

/* Scrollbar discreto */
.term-modal-body::-webkit-scrollbar { width: 8px; }
.term-modal-body::-webkit-scrollbar-track { background: var(--bg-well); }
.term-modal-body::-webkit-scrollbar-thumb { background: var(--phos-fade); }
.term-modal-body::-webkit-scrollbar-thumb:hover { background: var(--phos-dim); }

@media (max-width: 600px) {
  .term-modal {
    width: 100vw;
    max-width: 100vw;
    max-height: 100vh;
    height: 100vh;
    margin: 0;
  }
  .term-modal-frame { max-height: 100vh; height: 100vh; }
  .term-modal-foot .bracket { display: none; }

  /* En pantallas estrechas el header de 5 elementos
     (corner, title, meta, close, corner) se desbordaba: el título
     envolvía a 2 líneas, "11 ITEMS" caía a la derecha, y el botón
     `[ × ]` se partía en dos líneas separando `[ ×` y `]`.
     Solución: ocultar los corners ASCII (decorativos), título nowrap
     con ellipsis si excede, meta a la izquierda del cierre, y el botón
     × con su propia caja flex-shrink:0 al borde derecho. */
  .term-modal-head { padding: 8px 10px; gap: 8px; flex-wrap: nowrap; }
  .term-modal-head .corner { display: none; }
  .term-modal-title {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .term-modal-meta {
    flex-shrink: 0;
    font-size: 9.5px;
    margin-left: auto;
  }
  .term-modal-close {
    flex-shrink: 0;
    margin-left: 0;
    padding: 4px 10px;
    border: 1px dashed var(--phos-fade);
    color: var(--phos-dim);
  }
  .term-modal-close:active { background: var(--alarm-red-bg); color: var(--alarm-red); }
}

@media (prefers-reduced-motion: reduce) {
  .target.urgent { animation: none; background-color: var(--alarm-red-bg); }
  .target.urgent::before { animation: none; }
  .statusbar .item.alarm { animation: none; }
  .statusbar .item.alarm .bell { animation: none; }
  .term-modal[open] { animation: none; }
}

/* =========================================================================
   Section 7: Subscribe Terminal
   ========================================================================= */
.subscribe-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap-lg);
  align-items: start;
}
.tty {
  background: #02060a;
  border: 1px solid var(--phos-dim);
  padding: 22px 24px 26px;
  box-shadow: 0 0 24px rgba(57,255,20,0.05) inset;
  font-size: 13px;
  line-height: 1.6;
  position: relative;
  overflow: hidden;
}
.tty::before {
  content: '';
  position: absolute; top: 8px; right: 12px;
  width: 8px; height: 8px;
  background: var(--phos);
  box-shadow: 0 0 6px var(--phos);
  animation: pulse 1.6s infinite;
}
.tty .ascii-frame { color: var(--phos-dim); white-space: pre; font-size: 11.5px; line-height: 1.15; margin-bottom: 4px; }
.tty .line { color: var(--fg); margin: 2px 0; }
.tty .line .p { color: var(--phos); margin-right: 6px; }
.tty .line .ok { color: var(--phos); }
.tty .line .err { color: var(--red); }
.tty .line .muted { color: var(--fg-dim); }
.tty .line .amber { color: var(--amber); }
.tty .input-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.tty .input-row .p { color: var(--phos); }
.tty input[type="text"], .tty input[type="email"] {
  background: transparent; border: 0;
  color: var(--phos);
  font-family: var(--mono); font-size: 13px;
  letter-spacing: 0.12em;
  outline: 0; padding: 0;
  width: 220px;
  border-bottom: 1px dashed var(--phos-fade);
}
.tty input::placeholder { color: var(--phos-fade); letter-spacing: 0.12em; }
.tty .cursor::after {
  content: '▮';
  color: var(--phos);
  margin-left: 4px;
  animation: blink 1.1s steps(2) infinite;
}
.tty .submit-row { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.tty .stepper {
  display: flex; gap: 6px; font-size: 10px; letter-spacing: 0.2em;
  color: var(--fg-faint); margin-bottom: 14px;
}
.tty .stepper .s { padding: 2px 8px; border: 1px dashed var(--phos-fade); }
.tty .stepper .s.active { color: var(--bg); background: var(--phos); border-color: var(--phos); }
.tty .stepper .s.done { color: var(--phos); border-color: var(--phos-dim); }

.subscribe-side { font-size: 12px; line-height: 1.7; color: var(--fg); }
.subscribe-side h4 { color: var(--phos); font-size: 11px; letter-spacing: 0.2em; margin-bottom: 10px; text-transform: uppercase; }
.subscribe-side ol { padding-left: 20px; margin: 0 0 16px; }
.subscribe-side ol li { margin: 4px 0; color: var(--fg); }
.subscribe-side ol li code { color: var(--amber); }
.subscribe-side .note {
  border: 1px dashed var(--phos-fade);
  padding: 10px 12px;
  font-size: 11px;
  color: var(--fg-dim);
}
.subscribe-side .note b { color: var(--phos); }

/* =========================================================================
   Section 8: How it works
   ========================================================================= */
.howitworks {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: var(--gap-lg);
}
.diagram {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--phos);
  background: var(--bg-well);
  border: 1px solid var(--phos-fade);
  padding: 18px 20px;
  white-space: pre;
  overflow-x: auto;
  line-height: 1.4;
  text-shadow: 0 0 6px rgba(57,255,20,0.18);
}
.diagram .dim { color: var(--phos-dim); }
.diagram .fg { color: var(--fg); }
.diagram .amb { color: var(--amber); }

.changelog { font-size: 12px; line-height: 1.6; color: var(--fg); }
.changelog h4 { color: var(--phos); font-size: 11px; letter-spacing: 0.2em; margin-bottom: 12px; text-transform: uppercase; }
.changelog .entry { margin-bottom: 14px; padding-left: 16px; border-left: 1px dashed var(--phos-fade); }
.changelog .entry .stamp { color: var(--phos-dim); font-size: 10.5px; letter-spacing: 0.1em; display: block; margin-bottom: 2px; }
.changelog .entry .title { color: var(--amber); font-size: 11.5px; margin-bottom: 4px; }
.changelog .entry p { margin: 0; color: var(--fg-dim); font-size: 11.5px; }

/* =========================================================================
   Footer
   ========================================================================= */
footer.foot {
  margin-top: 60px;
  padding: 22px 0 0;
  border-top: 1px solid var(--phos-fade);
  display: flex; flex-wrap: wrap; gap: 14px; align-items: center;
  font-size: 11px;
  color: var(--fg-dim);
  letter-spacing: 0.1em;
}
footer.foot .right { margin-left: auto; }
footer.foot a { color: var(--phos); }
footer.foot .commit { color: var(--amber); }

/* =========================================================================
   Tweaks panel
   ========================================================================= */
.tweaks {
  position: fixed; bottom: 18px; right: 18px;
  width: 280px;
  background: var(--bg-panel);
  border: 1px solid var(--phos);
  box-shadow: 0 0 22px rgba(57,255,20,0.15);
  z-index: 200;
  font-size: 11px;
  display: none;
}
.tweaks.open { display: block; }
.tweaks header {
  padding: 8px 12px;
  border-bottom: 1px solid var(--phos-fade);
  display: flex; justify-content: space-between; align-items: center;
  letter-spacing: 0.18em; color: var(--phos);
  text-transform: uppercase;
}
.tweaks header .x { cursor: pointer; color: var(--fg-dim); }
.tweaks header .x:hover { color: var(--red); }
.tweaks .body { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.tweaks .row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.tweaks .row label { color: var(--fg); letter-spacing: 0.1em; }
.tweaks .row .v { color: var(--phos-dim); font-size: 10px; }
.tweaks input[type="range"] { flex: 1; }
.tweaks .toggle {
  width: 36px; height: 16px;
  background: var(--bg-well);
  border: 1px solid var(--phos-fade);
  position: relative; cursor: pointer;
}
.tweaks .toggle::before {
  content: ''; position: absolute;
  top: 1px; left: 1px;
  width: 12px; height: 12px;
  background: var(--phos-fade);
  transition: left .15s, background .15s;
}
.tweaks .toggle.on { border-color: var(--phos); }
.tweaks .toggle.on::before { left: 21px; background: var(--phos); box-shadow: 0 0 6px var(--phos); }

/* =========================================================================
   Mobile
   ========================================================================= */
@media (max-width: 900px) {
  .shell { padding: 0 14px 60px; }
  .statusbar { padding: 8px 14px; gap: 10px; font-size: 10px; }
  .counters { grid-template-columns: 1fr; }
  .intel { grid-template-columns: 1fr; }
  .donut-wrap { grid-template-columns: 1fr; }
  .subscribe-wrap { grid-template-columns: 1fr; }
  .howitworks { grid-template-columns: 1fr; }
  .card .head {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "ts chev"
      "src src"
      "cat cat"
      "title title";
    gap: 6px;
  }
  .card .head .ts { grid-area: ts; }
  .card .head .badge.src { grid-area: src; justify-self: start; }
  .card .head .badge.cat { grid-area: cat; justify-self: start; }
  .card .head .title { grid-area: title; -webkit-line-clamp: 3; }
  .card .head .chev { grid-area: chev; }
  /* En pantallas estrechas, "AYUNTAMIENTO MADRID" o "COMUNIDAD" se cortaban
     por el letter-spacing y los 110px reservados. Aflojamos el badge para
     que entre cualquier label sin truncado. */
  .card .head .badge {
    font-size: 9px;
    letter-spacing: 0.1em;
    padding: 2px 6px;
  }

  table.term td.col-cat { display: none; }

  /* Cmdbar: cada filtro en su propia línea (ancho completo). El filtro
     date: tenía dos inputs de 130px hardcoded en el JS que sumaban 260px
     y desbordaban; los reducimos vía !important sin tocar el inline. */
  .cmdbar { gap: 6px; }
  .cmdbar .seg { width: 100%; flex-wrap: wrap; }
  .cmdbar .seg input.q { flex: 1 1 auto; min-width: 0; width: auto; }
  .cmdbar .seg input[type="date"] { width: 110px !important; min-width: 0; }
  .cmdbar .clear { margin-left: 0; }

  /* ----- Mobile: secciones colapsables ----------------------------------
     Cada <section> tiene un .section-title clickable que pliega el resto
     del contenido bajo demanda. Útil cuando la página es muy larga.
  ----------------------------------------------------------------------- */
  .shell > section .section-title { cursor: pointer; user-select: none; }
  .shell > section .section-title::after {
    content: '▾';
    margin-left: auto;
    color: var(--phos);
    font-size: 14px;
    transition: transform .2s;
  }
  .shell > section.collapsed .section-title::after { transform: rotate(-90deg); }
  .shell > section.collapsed > *:not(.section-title) {
    display: none;
  }

  /* ----- Mobile: animación glitch al entrar en viewport ----------------
     Las secciones nacen con .pre-glitch (invisible y sin pointer-events).
     Cuando el IntersectionObserver les pone .glitch-in, disparamos un
     keyframe corto que simula interferencia de CRT (offset horizontal +
     leve hue-shift). Solo en móvil para no saturar el desktop.
  ----------------------------------------------------------------------- */
  .shell > section.pre-glitch { opacity: 0; pointer-events: none; }
  .shell > section.glitch-in {
    animation: section-glitch 700ms steps(8, end) both;
  }
  @keyframes section-glitch {
    0%   { opacity: 0; transform: translateX(-3px); filter: hue-rotate(120deg) brightness(1.4); clip-path: inset(40% 0 40% 0); }
    20%  { opacity: 0.55; transform: translateX(2px); filter: hue-rotate(0deg) brightness(1.1); clip-path: inset(10% 0 60% 0); }
    40%  { opacity: 0.85; transform: translateX(-1px); filter: hue-rotate(15deg); clip-path: inset(0 0 0 0); }
    60%  { opacity: 0.95; transform: translateX(1px); filter: none; }
    100% { opacity: 1; transform: translateX(0); filter: none; clip-path: inset(0 0 0 0); }
  }
}

/* Donut: cuando JS cambia el dasharray de "0 C" al valor final, esta
   transición dibuja el sweep. Las bars usan el transition que ya tiene
   .bar-row .fill (width: 0 → target). Fuera del @media porque solo se
   activa cuando JS modifica el atributo (en móvil); en desktop el
   render arranca con el dasharray final, así que no hay transición. */
#donut circle[data-target-dasharray] {
  transition: stroke-dasharray 0.9s cubic-bezier(.2, .7, .2, 1);
}

/* Reduce motion: respetar preferencias del usuario */
@media (prefers-reduced-motion: reduce) {
  .shell > section.glitch-in { animation: none; }
  .bar-row .fill { transition: none; }
  #donut circle[data-target-dasharray] { transition: none; }
}

/* High-density (toggle) */
body[data-density="high"] {
  --row-h: 22px;
  font-size: 12px;
}
body[data-density="high"] .card .head { padding: 8px 12px; }
body[data-density="high"] table.term tbody td { padding: 5px 10px; }
body[data-density="high"] .panel { padding: 10px 12px 14px; }
