:root {
  --navy: #0A1628;
  --navy2: #0F2044;
  --panel: #fff;
  --bg: #F1F5FB;
  --bg2: #E8EFFE;
  --blue: #2563EB;
  --blue2: #3B82F6;
  --blue-l: #DBEAFE;
  --text: #0A1628;
  --sub: #3D5A8A;
  --muted: #7B93BC;
  --border: #DDE6F5;
  --green: #059669;
  --green-l: #D1FAE5;
  --amber: #D97706;
  --amber-l: #FEF3C7;
  --red: #DC2626;
  --red-l: #FEE2E2;
  --r: 12px;
  --r2: 16px;
  --sidebar: 256px;
  --top: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: rgba(37, 99, 235, .18); border-radius: 8px; }

.shell { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* ── Topbar brand ────────────────────────────────────────── */
.tp-brand { display: flex; align-items: center; gap: 10px; padding-right: 16px; border-right: 1px solid var(--border); flex-shrink: 0; }
.sb-ico {
  width: 36px; height: 36px; border-radius: 9px;
  background: linear-gradient(135deg, #1D4ED8, #3B82F6);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; box-shadow: 0 4px 12px rgba(59,130,246,.3); flex-shrink: 0;
}
.sb-name { font-size: 14px; font-weight: 800; color: var(--navy); }
.sb-sub { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* ── Barra horizontal (carga + filtros) ─────────────────── */
.hbar {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 10px 20px; background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(10,22,40,.04); flex-shrink: 0;
}
.hbar-sec { display: flex; align-items: center; gap: 12px; }
.hbar-lbl {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 800; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted); flex-shrink: 0;
}
.hbar-items { display: flex; gap: 8px; flex-wrap: wrap; }
.sb-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 8px; cursor: pointer;
  background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 13px; font-weight: 600;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease, background .12s;
  white-space: nowrap; box-shadow: 0 1px 2px rgba(10,22,40,.05);
}
.sb-item:hover {
  background: #fff; border-color: var(--blue);
  box-shadow: 0 4px 12px rgba(37,99,235,.14);
  transform: translateY(-1px);
}
.sb-item input { display: none; }
.sb-key {
  width: 20px; height: 20px; border-radius: 6px;
  font-size: 11px; font-weight: 900; font-family: 'DM Mono', monospace;
  display: flex; align-items: center; justify-content: center;
  color: #fff; flex-shrink: 0;
}
.sb-nm { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sb-st {
  font-size: 11px; font-weight: 700; color: var(--muted);
  font-family: 'DM Mono', monospace; flex-shrink: 0;
}
.sb-st.ok { color: #059669; }
.sb-st.err { color: var(--red); }
.hbar-sep { width: 1px; height: 34px; background: var(--border); flex-shrink: 0; }
.hbar-filters { background: var(--bg); box-shadow: none; }
.hbar-fields { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.hf-field { display: flex; flex-direction: column; gap: 4px; }
.hf-lbl {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted);
}
.hf-pair { display: flex; gap: 6px; }
.hf-sel {
  background: #fff; border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 6px 10px; font-size: 13px;
  font-family: 'Outfit', sans-serif; outline: none; cursor: pointer; min-width: 92px;
  transition: border-color .12s, box-shadow .12s;
}
.hf-sel:hover { border-color: #c8d6ef; }
.hf-sel:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.hf-sel option { color: var(--text); }

/* ── Main / topbar ───────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.topbar {
  height: var(--top); flex-shrink: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 0 18px; background: #fff;
  border-bottom: 1px solid var(--border);
}
.tp-info { flex: 1; min-width: 0; }
.tp-title { font-size: 14px; font-weight: 800; color: var(--navy); }
.tp-sub { font-size: 12px; color: var(--muted); }

.btn {
  font-family: 'Outfit', sans-serif; font-weight: 700; font-size: 13px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid transparent;
  cursor: pointer; transition: opacity .15s, transform .05s; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: #1D4ED8; }
.btn-ghost { background: rgba(59,130,246,.1); border-color: rgba(59,130,246,.25); color: #3B82F6; }
.btn-ghost:disabled { opacity: .4; cursor: not-allowed; }

.content { flex: 1; overflow-y: auto; min-height: 0; padding: 18px 20px 28px; }
.status { display: none; margin-top: 10px; padding: 9px 12px; border-radius: 8px; font-size: 13px; }
.status.ok { display: block; background: var(--green-l); color: #065F46; }
.status.err { display: block; background: var(--red-l); color: #991B1B; }

/* ── KPI cards ───────────────────────────────────────────── */
.kpi-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--border); border-radius: var(--r); padding: 14px 16px; }
.kpi-l { font-size: 12px; font-weight: 600; color: var(--muted); }
.kpi-v { font-size: 24px; font-weight: 800; margin-top: 4px; font-family: 'DM Mono', monospace; }
.kpi-s { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ── Panels / tablas ─────────────────────────────────────── */
.panel {
  background: #fff; border: 1px solid var(--border); border-radius: var(--r2);
  padding: 16px 18px; margin-bottom: 16px;
}
.panel-hd { font-size: 14px; font-weight: 800; color: var(--navy); margin-bottom: 10px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: right; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 700; padding: 8px 10px;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
thead th:first-child, tbody td:first-child { text-align: left; }
tbody td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: right; font-family: 'DM Mono', monospace; }
tbody td:first-child { font-family: 'Outfit', sans-serif; font-weight: 500; }
tbody tr:hover { background: #F8FAFF; }
.ind-tipo {
  display: inline-block; margin-left: 6px; font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 99px; vertical-align: middle; font-family: 'DM Mono', monospace;
}
.tipo-count { background: var(--blue-l); color: #1D4ED8; }
.tipo-prop { background: var(--amber-l); color: #B45309; }
.cell-sub { display: block; color: var(--muted); font-size: 11px; font-weight: 400; }

/* ── Cards de indicadores ─────────────────────────────────── */
#ic-grid { display: flex; flex-direction: column; }
.ic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 12px; margin-bottom: 16px; }
.ic-grid-single { grid-template-columns: 1fr; }
.ic { background: #fff; border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; box-shadow: 0 1px 3px rgba(10,22,40,.06); position: relative; }
.ic-stripe { height: 3px; }
.ic-body { padding: 10px 12px; }
.ic-head { display: flex; align-items: flex-start; gap: 5px; margin-bottom: 7px; }
.ic-ltr { width: 20px; height: 20px; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 900; font-family: 'DM Mono', monospace; flex-shrink: 0; color: #fff; }
.ic-nm { font-size: 13px; font-weight: 700; color: var(--text); line-height: 1.3; flex: 1; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ic-cov { font-size: 12px; font-weight: 900; font-family: 'DM Mono', monospace; flex-shrink: 0; padding: 2px 5px; border-radius: 4px; }
.ic-num { font-size: 20px; font-weight: 900; font-family: 'DM Mono', monospace; line-height: 1; }
.ic-ns { font-size: 11px; color: var(--muted); margin-top: 2px; }
.bar-t { height: 4px; background: var(--bg); border-radius: 9px; overflow: hidden; margin-top: 8px; }
.bar-f { height: 100%; border-radius: 9px; transition: width 1.1s cubic-bezier(.16,1,.3,1); }
.ic-foot { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }

/* ── Gráfica ──────────────────────────────────────────────── */
.chart-box { position: relative; height: 340px; }

/* ── Cards: interacción ───────────────────────────────────── */
.ic { cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; }
.ic:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(10,22,40,.12); }
.ic-has-err { box-shadow: inset 0 0 0 1px rgba(220,38,38,.4); }

/* ── Modal de detalle ─────────────────────────────────────── */
.modal-bg { position: fixed; inset: 0; background: rgba(10,22,40,.55); display: none; align-items: center; justify-content: center; z-index: 100; padding: 24px; }
.modal-bg.open { display: flex; }
.modal { background: var(--panel); border-radius: var(--r2); width: min(1100px, 100%); max-height: 92vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 24px 60px rgba(10,22,40,.32); }
.m-bar { height: 4px; background: linear-gradient(90deg, var(--blue), var(--blue2)); flex-shrink: 0; }
.m-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.m-ico { font-size: 24px; }
.m-info { flex: 1; min-width: 0; }
.m-title { font-size: 17px; font-weight: 800; color: var(--navy); }
.m-sub { font-size: 13px; color: var(--muted); }
.m-kpis { display: flex; gap: 10px; }
.m-kpi { text-align: center; min-width: 58px; }
.m-kv { font-size: 16px; font-weight: 900; font-family: 'DM Mono', monospace; color: var(--blue); }
.m-kl { font-size: 11px; color: var(--muted); }
.m-close { background: none; border: none; font-size: 16px; cursor: pointer; color: var(--muted); padding: 4px; }
.m-close:hover { color: var(--navy); }
.m-body { overflow-y: auto; padding: 16px 18px; }
.m-tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.m-tab { border: 1px solid var(--border); background: var(--bg); color: var(--sub); font-size: 13px; font-weight: 700; padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.m-tab.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.m-tab.err-tab { color: var(--red); }
.rule-box { background: var(--blue-l); border: 1px solid rgba(37,99,235,.2); border-radius: 8px; padding: 10px 12px; font-size: 11.5px; color: var(--sub); margin-bottom: 12px; }
.dual-cmp { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dc-box { border-radius: 10px; padding: 14px; }
.dc-raw { background: var(--blue-l); }
.dc-val { background: var(--green-l); }
.dc-t { font-size: 13px; font-weight: 700; }
.dc-n { font-size: 28px; font-weight: 900; font-family: 'DM Mono', monospace; margin: 4px 0; }
.dc-s { font-size: 12px; color: var(--muted); }
.m-tbl-wrap { overflow: auto; max-height: 55vh; border: 1px solid var(--border); border-radius: 8px; }
.m-tbl-wrap table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.m-tbl-wrap th, .m-tbl-wrap td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.m-tbl-wrap th { background: var(--bg2); color: var(--sub); font-size: 11.5px; position: sticky; top: 0; }
.choose-bar { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--border); background: #fafcff; flex-shrink: 0; flex-wrap: wrap; }
.ch-info { flex: 1; font-size: 13px; color: var(--sub); min-width: 180px; }
.btn-ch-raw, .btn-ch-val { border: 1px solid var(--border); background: var(--panel); color: var(--sub); font-size: 13px; font-weight: 700; padding: 7px 12px; border-radius: 8px; cursor: pointer; }
.btn-ch-raw.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-ch-val.on { background: var(--green); color: #fff; border-color: var(--green); }
.ic-sel { font-size: 11px; font-weight: 900; font-family: 'DM Mono', monospace; padding: 1px 5px; border-radius: 4px; flex-shrink: 0; }

/* ── Loader global ────────────────────────────────────────── */
.loader-bg { position: fixed; inset: 0; background: rgba(10,22,40,.4); display: none; align-items: center; justify-content: center; z-index: 200; flex-direction: column; gap: 12px; backdrop-filter: blur(2px); }
.loader-bg.open { display: flex; }
.loader-spin { width: 40px; height: 40px; border: 3px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
.loader-txt { color: #fff; font-size: 14px; font-weight: 600; letter-spacing: .2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Indicador de carga por fuente (dot) ──────────────────── */
.sb-st::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #cbd5e1; margin-right: 4px; vertical-align: middle; }
.sb-st.ok::before { background: #059669; }
.sb-st.err::before { background: var(--red); }

@media (max-width: 900px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .tp-brand { display: none; }
}

/* ── Toolbar (buscador + chips de grupo) ─────────────────── */
.ic-toolbar {
  position: sticky; top: -1px; z-index: 5;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--bg); padding: 10px 0 12px; margin-bottom: 4px;
}
.ic-search {
  flex: 1; min-width: 200px; max-width: 340px;
  font-family: 'Outfit', sans-serif; font-size: 14px;
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.ic-search:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.ic-search::placeholder { color: var(--muted); }
.ic-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-family: 'Outfit', sans-serif; font-size: 12.5px; font-weight: 600;
  padding: 6px 11px; border-radius: 99px; cursor: pointer;
  border: 1px solid var(--border); background: #fff; color: var(--sub);
  transition: background .12s, color .12s, border-color .12s;
}
.chip:hover { border-color: var(--blue); color: var(--blue); }
.chip.chip-on { background: var(--navy); color: #fff; border-color: var(--navy); }

/* ── Secciones por grupo ──────────────────────────────────── */
.ic-sec { margin-bottom: 20px; }
.ic-sec-hd { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.ic-sec-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.ic-sec-name { font-size: 14px; font-weight: 800; color: var(--navy); }
.ic-sec-count {
  font-family: 'DM Mono', monospace; font-size: 11.5px; font-weight: 700;
  padding: 2px 8px; border-radius: 99px;
}
.ic-sec .ic-grid { margin-bottom: 0; }

/* ── Fila separadora de grupo (tabla) ─────────────────────── */
.grp-row td {
  background: #f8fafc; text-align: left !important;
  padding: 8px 10px !important; border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
.grp-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
