:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #dde1e6;
  --text: #1b1f24;
  --text-dim: #6b7280;
  --accent: #c8102e; /* rojo Cadena SER */
  --accent-dark: #9c0c22;
  --ok: #1a8a4a;
  --err: #c62828;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel: #1d2025;
    --border: #2c3036;
    --text: #eceef0;
    --text-dim: #9aa1a9;
    --accent: #ff4d5e;
    --accent-dark: #ff7280;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button {
  font-family: inherit;
  cursor: pointer;
}

.hidden { display: none !important; }

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  margin: 0 0 10px;
  font-size: 18px;
}

.loader {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.loader select, .loader input[type=text] {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

.loader input[type=text] { flex: 1; min-width: 260px; }
.loader .or { color: var(--text-dim); font-size: 13px; }

button {
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 14px;
}
button:hover { background: var(--accent-dark); }
button:disabled { opacity: .5; cursor: not-allowed; }
button#btn-config { background: transparent; color: var(--text); font-size: 16px; padding: 8px 10px; }
button#btn-config:hover { background: var(--border); }

.feed-info {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-dim);
}

.main {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
  padding: 16px 20px;
  align-items: start;
}

.filtros {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  position: sticky;
  top: 90px;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
}

.filtros h2 { margin: 0 0 10px; font-size: 15px; }
.filtros h3 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); }
.filtros section:first-of-type h3 { margin-top: 0; }

.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-dim); flex: 1; min-width: 110px; }
.row input { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 500;
  font-size: 12px;
  padding: 5px 10px;
}
.chip:hover { border-color: var(--accent); }
.chip.activo { background: var(--accent); color: white; border-color: var(--accent); }

#f-texto { width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }

.secciones-wrap h3 { display: flex; justify-content: space-between; align-items: center; }
.link-btn { background: none; border: none; color: var(--accent); font-size: 12px; padding: 0; font-weight: 600; }
.link-btn:hover { text-decoration: underline; background: none; }

.secciones-list { display: flex; flex-direction: column; gap: 4px; max-height: 260px; overflow-y: auto; }
.seccion-item { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.seccion-item label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seccion-item .n { color: var(--text-dim); font-size: 11px; }

.resultados {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 300px;
}

.tabla-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--panel);
}
thead th:hover { color: var(--text); }
tbody td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:hover { background: var(--bg); }
.col-check { width: 34px; }
td.titulo-cell { max-width: 420px; }
td.titulo-cell .desc { display: block; color: var(--text-dim); font-size: 12px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#sin-resultados { padding: 30px; text-align: center; color: var(--text-dim); }

.pie-resultados {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  background: var(--panel);
}
#resumen-seleccion { color: var(--text-dim); font-size: 13px; }

.progreso {
  margin: 0 20px 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.progreso-header { display: flex; justify-content: space-between; align-items: center; }
.progreso-header h2 { margin: 0; font-size: 15px; }
.progreso-acciones { display: flex; gap: 8px; }
.progreso-acciones button { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.progreso-acciones button:hover { border-color: var(--accent); }

.barra-global-wrap { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.barra-global { flex: 1; height: 8px; border-radius: 4px; background: var(--border); overflow: hidden; }
.barra-fill { height: 100%; background: var(--accent); width: 0%; transition: width .2s; }
#progreso-resumen { font-size: 12px; color: var(--text-dim); white-space: nowrap; }

.lista-tareas { display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow-y: auto; }
.tarea {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 4px 10px;
  align-items: center;
  font-size: 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.tarea .nombre { grid-column: 1 / -1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tarea .barra { grid-column: 1 / 2; height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.tarea .barra-fill { height: 100%; background: var(--ok); }
.tarea.error .barra-fill { background: var(--err); }
.tarea .estado { color: var(--text-dim); }
.tarea button { padding: 2px 8px; font-size: 11px; background: var(--bg); color: var(--text); border: 1px solid var(--border); }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; width: 420px; max-width: 90vw;
}
.modal-card h2 { margin: 0 0 14px; font-size: 16px; }
.modal-row { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-dim); margin-bottom: 12px; }
.modal-row input { padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font-size: 13px; }
.hint { font-size: 11px; color: var(--text-dim); margin: -6px 0 14px; }
.link-btn-danger {
  background: none; border: none; color: var(--err); font-size: 12px;
  padding: 0; font-weight: 600; margin-bottom: 14px; display: block;
}
.link-btn-danger:hover { text-decoration: underline; background: none; }
.modal-acciones { display: flex; justify-content: flex-end; gap: 8px; }
.modal-acciones button:first-child { background: var(--bg); color: var(--text); border: 1px solid var(--border); }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 8px;
  font-size: 13px; z-index: 200; max-width: 80vw;
}
.toast.error { background: var(--err); color: white; }

@media (max-width: 800px) {
  .main { grid-template-columns: 1fr; }
  .filtros { position: static; max-height: none; }
}
