.back-link {
  margin-left: auto;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  text-decoration: none;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--color-border-light);
  border-radius: 6px;
  transition: all 0.15s;
}
.back-link:hover {
  color: var(--color-primary);
  border-color: var(--color-primary);
  text-decoration: none;
}

.disclaimer-bar {
  margin: 0.75rem -2rem 0;
  padding: 0.5rem 2rem;
  background: var(--color-warning-bg);
  border-top: 1px solid rgba(217,119,6,0.15);
  font-size: 0.7rem;
  color: var(--color-text-dim);
  line-height: 1.5;
  text-align: center;
}

.kpi-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  padding: 1rem 2rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border-light);
}
.kpi {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.kpi-value { display: block; font-size: 1.5rem; font-weight: 700; color: var(--color-primary); }
.kpi-label { display: block; font-size: 0.75rem; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 0.25rem; }
.kpi.critical .kpi-value { color: var(--color-critical); }
.kpi.warning .kpi-value { color: var(--color-warning); }

.dashboard {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1rem;
  padding: 1rem 2rem 2rem;
  max-width: 1600px;
  margin: 0 auto;
  transition: opacity 0.5s;
}

.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: 10px;
  padding: 1rem;
  box-shadow: var(--shadow-sm);
}

.filters h2 { font-size: 1rem; margin-bottom: 1rem; color: var(--color-primary); }
.filters label { display: block; margin-bottom: 0.75rem; font-size: 0.8rem; color: var(--color-text-dim); }
.filters select, .filters input {
  width: 100%; margin-top: 0.25rem; padding: 0.4rem 0.5rem;
  background: var(--color-surface); color: var(--color-text);
  border: 1px solid var(--color-border-light); border-radius: 6px; font-size: 0.85rem;
}
.filters select:focus, .filters input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px var(--color-primary-bg);
}
.filters button {
  width: 100%; margin-top: 0.5rem; padding: 0.5rem;
  background: var(--color-primary); color: #fff; font-weight: 600;
  border: none; border-radius: 6px; cursor: pointer; font-size: 0.85rem;
}
.filters button:hover { opacity: 0.9; }

.main-content { min-height: 70vh; }

.tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--color-border-light); padding-bottom: 0.5rem; }
.tab-btn {
  padding: 0.5rem 1rem; background: transparent; color: var(--color-text-muted);
  border: 1px solid transparent; border-radius: 6px; cursor: pointer; font-size: 0.85rem;
}
.tab-btn:hover { color: var(--color-text); background: var(--color-surface-2); }
.tab-btn.active { background: var(--color-surface); color: var(--color-primary); border-color: var(--color-border-light); font-weight: 600; }

.tab-content { display: none; }
.tab-content.active { display: block; }

.tab-content h2 { font-size: 1.1rem; margin-bottom: 0.5rem; }
.tab-content h3 { font-size: 1rem; margin: 1.5rem 0 0.5rem; color: var(--color-text-dim); }
.help-text { color: var(--color-text-muted); font-size: 0.8rem; margin-bottom: 1rem; }

.alertas-controls { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.severity-filter {
  padding: 0.3rem 0.7rem; border: 1px solid var(--color-border-light); background: var(--color-surface);
  color: var(--color-text-dim); border-radius: 6px; cursor: pointer; font-size: 0.8rem;
}
.severity-filter.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

.global-search-bar {
  padding: 0.5rem 2rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border-light);
  position: relative;
}
.global-search-bar input {
  width: 100%;
  padding: 0.6rem 1rem;
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border-light);
  border-radius: 8px;
  font-size: 0.9rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.global-search-bar input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px var(--color-primary-bg);
}
.search-results {
  position: absolute;
  top: 100%;
  left: 2rem;
  right: 2rem;
  background: var(--color-surface);
  border: 1px solid var(--color-primary);
  border-radius: 0 0 8px 8px;
  max-height: 400px;
  overflow-y: auto;
  z-index: 1000;
  box-shadow: var(--shadow-lg);
}
.search-result-item {
  padding: 0.6rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border-light);
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.search-result-item:hover { background: var(--color-primary-bg); }
.search-result-item .sr-name { font-weight: 600; }
.search-result-item .sr-type { font-size: 0.7rem; color: var(--color-text-muted); }

.download-section {
  padding: 0 2rem 1.5rem;
  max-width: 1600px;
  margin: 0 auto;
}

.resumen-section { margin-bottom: 1.25rem; }
.resumen-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.resumen-stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: 10px;
  padding: 1rem;
  text-align: center;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow-sm);
}
.resumen-stat-card:hover { transform: translateY(-2px); border-color: var(--color-primary); box-shadow: var(--shadow-lg); }
.resumen-stat-icon { font-size: 1.4rem; margin-bottom: 0.25rem; display: block; }
.resumen-stat-value { display: block; font-size: 1.25rem; font-weight: 700; color: var(--color-primary); line-height: 1.2; }
.resumen-stat-label { display: block; font-size: 0.7rem; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 0.25rem; }
.resumen-stat-card.critical .resumen-stat-value { color: var(--color-critical); }
.resumen-stat-card.warning .resumen-stat-value { color: var(--color-warning); }
.resumen-stat-card.success .resumen-stat-value { color: var(--color-success); }

.resumen-row-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.resumen-chart-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: 10px;
  padding: 0.75rem;
  box-shadow: var(--shadow-sm);
}
.resumen-chart-title { font-size: 0.85rem; color: var(--color-text); margin-bottom: 0.5rem; font-weight: 600; }
.resumen-chart-wrap { position: relative; height: 280px; }

.resumen-table-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: 10px;
  padding: 0.75rem;
  overflow-x: auto;
}
.resumen-table-wrap table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.resumen-table-wrap th, .resumen-table-wrap td { padding: 0.45rem 0.5rem; text-align: left; border-bottom: 1px solid var(--color-border-light); }
.resumen-table-wrap th { background: var(--color-surface-2); color: var(--color-text-dim); font-weight: 600; white-space: nowrap; }
.resumen-table-wrap tr:hover td { background: rgba(0,0,0,0.02); }

.map-legend {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.map-legend-item { display: flex; align-items: center; gap: 0.3rem; }
.map-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }

.network-legend {
  display: flex; align-items: center; gap: 1rem; margin-bottom: 0.5rem;
  font-size: 0.75rem; flex-wrap: wrap;
}
.network-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 0.3rem; }

.filter-toggle {
  width: 100%;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border-light);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}
.filter-toggle:hover { border-color: var(--color-primary); }

.prov-name-link {
  color: var(--color-primary);
  cursor: pointer;
  font-weight: 600;
}
.prov-name-link:hover { text-decoration: underline; }
.inst-name-link {
  color: var(--color-primary);
  cursor: pointer;
  font-weight: 600;
}
.inst-name-link:hover { text-decoration: underline; }

/* ── Proveedor Detail Modal ────────────────────────────────────── */
.cd-modal { position: fixed; inset: 0; z-index: 9000; display: flex; align-items: center; justify-content: center; }
.cd-modal.hidden { display: none; }
.cd-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.cd-panel {
  position: relative; width: 95vw; max-width: 1400px; max-height: 92vh;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 12px; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.cd-close {
  position: absolute; top: 10px; right: 12px; background: transparent; border: none;
  color: var(--color-text-muted); font-size: 1.6rem; cursor: pointer; z-index: 10; line-height: 1;
}
.cd-close:hover { color: var(--color-text); }
.cd-header { padding: 1.2rem 1.5rem 0.8rem; border-bottom: 1px solid var(--color-border-light); }
.cd-name { font-size: 1.3rem; color: var(--color-primary); margin-bottom: 0.2rem; }
.cd-meta { color: var(--color-text-dim); font-size: 0.85rem; margin-bottom: 0.5rem; }
.cd-badges { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.cd-tabs {
  display: flex; gap: 0.25rem; padding: 0.5rem 1.5rem 0;
  border-bottom: 1px solid var(--color-border-light); background: var(--color-surface-2);
}
.cd-tab-btn {
  padding: 0.4rem 0.9rem; background: transparent; color: var(--color-text-muted);
  border: 1px solid transparent; border-radius: 6px 6px 0 0; cursor: pointer; font-size: 0.8rem;
}
.cd-tab-btn:hover { color: var(--color-text); }
.cd-tab-btn.active { background: var(--color-surface); color: var(--color-primary); border-color: var(--color-border-light); border-bottom-color: var(--color-surface); }
.cd-body { flex: 1; overflow-y: auto; padding: 1rem 1.5rem 1.5rem; }
.cd-content { display: none; }
.cd-content.active { display: block; }
.cd-stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem;
}
.cd-stat {
  background: var(--color-surface-2); border: 1px solid var(--color-border-light);
  border-radius: 8px; padding: 0.75rem; text-align: center;
}
.cd-stat span { display: block; font-size: 0.7rem; color: var(--color-text-muted); text-transform: uppercase; margin-bottom: 0.2rem; }
.cd-stat strong { display: block; font-size: 1.1rem; color: var(--color-primary); }
.cd-stat.neg strong { color: var(--color-critical); }
.cd-stat.pos strong { color: var(--color-success); }
.cd-table-wrap { overflow-x: auto; border: 1px solid var(--color-border-light); border-radius: 8px; margin-top: 0.5rem; }

@media (max-width: 1024px) {
  .cd-panel { max-height: 90vh; width: 98vw; border-radius: 8px; }
  .cd-header { padding: 0.7rem 0.8rem 0.4rem; }
  .cd-name { font-size: 1.05rem; }
  .cd-meta { font-size: 0.7rem; }
  .cd-tabs { padding: 0.25rem 0.4rem 0; overflow-x: auto; flex-wrap: nowrap; }
  .cd-tab-btn { padding: 0.25rem 0.45rem; font-size: 0.65rem; white-space: nowrap; flex-shrink: 0; }
  .cd-body { padding: 0.4rem 0.6rem 0.8rem; }
  .cd-stats-grid { grid-template-columns: repeat(3, 1fr); gap: 0.3rem; }
  .cd-stat { padding: 0.4rem; }
  .cd-stat strong { font-size: 0.8rem; }
  .cd-stat span { font-size: 0.55rem; }
}

@media (max-width: 500px) {
  .cd-stats-grid { grid-template-columns: repeat(2, 1fr); }
  .cd-tab-btn { font-size: 0.6rem; padding: 0.2rem 0.35rem; }
}

@media (max-width: 1024px) {
  .kpi-bar { grid-template-columns: repeat(3, 1fr); padding: 0.5rem 0.6rem; gap: 0.35rem; }
  .kpi { padding: 0.4rem 0.35rem; border-radius: 6px; }
  .kpi-value { font-size: 0.9rem; }
  .kpi-label { font-size: 0.58rem; }
  .dashboard { grid-template-columns: 1fr; padding: 0.4rem; gap: 0.4rem; }
  .filters { order: -1; max-height: 48px; padding: 0.4rem 0.5rem; }
  .filters label, .filters button, .filters h2 { display: none; }
  .filters.expanded { max-height: none; padding: 0.75rem; }
  .filters.expanded label, .filters.expanded button, .filters.expanded h2 { display: block; }
  .filters.expanded h2 { font-size: 0.85rem; margin-bottom: 0.5rem; }
  .filters.expanded label { font-size: 0.7rem; margin-bottom: 0.35rem; }
  .filters.expanded select, .filters.expanded input { font-size: 0.75rem; padding: 0.35rem 0.4rem; }
  .filter-toggle { font-size: 0.75rem; padding: 0.4rem 0.5rem; }
  .tabs { gap: 2px; flex-wrap: wrap; padding-bottom: 0.3rem; }
  .tab-btn { padding: 0.3rem 0.5rem; font-size: 0.68rem; white-space: nowrap; flex-shrink: 0; border-radius: 4px; }
  .tab-content h2 { font-size: 0.9rem; }
  .resumen-row-2 { grid-template-columns: 1fr; }
  .resumen-chart-wrap { height: 200px; }
  .resumen-stats-grid { grid-template-columns: repeat(3, 1fr); gap: 0.35rem; }
  .resumen-stat-card { padding: 0.45rem; }
  .resumen-stat-value { font-size: 0.9rem; }
  .global-search-bar { padding: 0.35rem 0.6rem; }
  .global-search-bar input { font-size: 0.78rem; padding: 0.45rem 0.6rem; }
  .search-results { left: 0.6rem; right: 0.6rem; max-height: 280px; }
  .disclaimer-bar { margin: 0.4rem -0.75rem 0; padding: 0.3rem 0.75rem; font-size: 0.6rem; }
  .back-link { font-size: 0.7rem; padding: 0.25rem 0.5rem; }
  .download-section { padding: 0 0.4rem 0.6rem; }
  #map-container { height: 380px !important; }
  #three-container { height: 400px !important; }
}

@media (max-width: 500px) {
  .kpi-bar { grid-template-columns: repeat(2, 1fr); padding: 0.35rem 0.4rem; gap: 0.25rem; }
  .kpi { padding: 0.3rem 0.25rem; }
  .kpi-value { font-size: 0.78rem; }
  .kpi-label { font-size: 0.5rem; }
  .dashboard { padding: 0.25rem; gap: 0.3rem; }
  .panel { padding: 0.5rem 0.4rem; border-radius: 8px; }
  .filters { max-height: 44px; padding: 0.3rem 0.4rem; }
  .filters.expanded { max-height: none; padding: 0.5rem; }
  .tab-btn { font-size: 0.6rem; padding: 0.22rem 0.35rem; }
  .resumen-stats-grid { grid-template-columns: repeat(2, 1fr); gap: 0.25rem; }
  .resumen-stat-card { padding: 0.35rem; }
  .resumen-stat-value { font-size: 0.8rem; }
  .resumen-chart-wrap { height: 170px; }
  .table-wrap { font-size: 0.58rem; border-radius: 5px; }
  table { font-size: 0.58rem; }
  th, td { padding: 0.18rem 0.22rem; }
  th { font-size: 0.5rem; }
  .badge { font-size: 0.5rem; padding: 0.08rem 0.2rem; }
  .global-search-bar input { font-size: 0.7rem; padding: 0.35rem 0.5rem; }
  .search-results { left: 0.4rem; right: 0.4rem; max-height: 220px; }
  #map-container { height: 300px !important; }
  #three-container { height: 300px !important; }
}
