/* ============================================================================
   components.css — TWEAKEO Dashboard v3 — Kit de componentes base
   ----------------------------------------------------------------------------
   v3 (2026-07-19) — Rediseño integral:
     - KPIs con delta (Δ), sparklines inline, tooltips, pulso de alerta.
     - Tablas con row indicators, mejor zebra, tipografía refinada.
     - Alertas con iconos SVG semánticos, jerarquía crítica/warning/info.
     - Badges, paneles, service tiles, agent cards, sparklines.
     - Todo tokenizado con --ds-*.
   v2 (2026-07-17) — Kit inicial.

   AUDIT-CODE: Excepciones de tokenización documentadas.
     - minmax grid values (160px, 200px, 280px): constraints de layout
       responsive, no espaciado estético.
     - Dimensiones de avatar (44px), dot indicador (12px): forma del
       componente, consistente con el sistema.
     - Breakpoints (780px, 480px): CSS no permite var() en @media.
   ========================================================================== */

/* ==========================================================================
   KPI CARD
   ========================================================================== */
.ds-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--ds-space-3);
}
.ds-kpi-grid .ds-kpi {
  animation: ds-kpi-enter var(--ds-duration-normal) var(--ds-easing-decelerate) forwards;
  opacity: 0;
  transform: translateY(8px);
}
.ds-kpi-grid .ds-kpi:nth-child(1) { animation-delay: 0.00s; }
.ds-kpi-grid .ds-kpi:nth-child(2) { animation-delay: 0.05s; }
.ds-kpi-grid .ds-kpi:nth-child(3) { animation-delay: 0.10s; }
.ds-kpi-grid .ds-kpi:nth-child(4) { animation-delay: 0.15s; }
.ds-kpi-grid .ds-kpi:nth-child(5) { animation-delay: 0.20s; }
.ds-kpi-grid .ds-kpi:nth-child(6) { animation-delay: 0.25s; }
@keyframes ds-kpi-enter { to { opacity: 1; transform: translateY(0); } }

@media (prefers-reduced-motion: reduce) {
  .ds-kpi-grid .ds-kpi { animation: none; opacity: 1; transform: none; }
}

.ds-kpi {
  background: var(--ds-surface);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md);
  padding: var(--ds-space-4);
  transition: border-color var(--ds-duration-fast) var(--ds-easing-standard),
              box-shadow var(--ds-duration-fast) var(--ds-easing-standard);
  position: relative;
  overflow: hidden;
}
.ds-kpi:hover {
  border-color: var(--ds-border-visible);
  transform: translateY(-1px);
  box-shadow: var(--ds-shadow-raised);
}

/* Indicador de alerta (pulso cuando KPI requiere atención) */
.ds-kpi--alert {
  border-color: var(--ds-danger-dim);
}
.ds-kpi--alert::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  animation: ds-pulse-ring 2s ease-out infinite;
  pointer-events: none;
}

.ds-kpi__label {
  font-size: var(--ds-font-size-xs);
  color: var(--ds-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: var(--ds-font-weight-semibold);
  margin-bottom: var(--ds-space-1);
}

.ds-kpi__value {
  font-size: var(--ds-font-size-3xl);
  font-weight: var(--ds-font-weight-bold);
  letter-spacing: -0.02em;
  color: var(--ds-heading);
  line-height: 1.1;
  display: flex;
  align-items: baseline;
  gap: var(--ds-space-1);
  flex-wrap: wrap;
}
.ds-kpi__value small {
  font-size: var(--ds-font-size-sm);
  font-weight: var(--ds-font-weight-medium);
  color: var(--ds-text-muted);
  letter-spacing: 0;
}

/* Delta (Δ) — variación vs periodo anterior */
.ds-kpi__delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: var(--ds-font-size-sm);
  font-weight: var(--ds-font-weight-semibold);
  margin-left: var(--ds-space-2);
  padding: 1px 6px;
  border-radius: var(--ds-radius-sm);
  line-height: 1.4;
}
.ds-kpi__delta--up {
  color: var(--ds-ok);
  background: var(--ds-ok-dim);
}
.ds-kpi__delta--down {
  color: var(--ds-danger);
  background: var(--ds-danger-dim);
}

/* Trend text */
.ds-kpi__trend {
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-semibold);
  margin-top: var(--ds-space-1);
}
.ds-kpi__trend--up   { color: var(--ds-ok); }
.ds-kpi__trend--down { color: var(--ds-danger); }

/* Barra de progreso */
.ds-kpi__bar {
  height: 5px;
  background: var(--ds-surface-overlay);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin-top: var(--ds-space-2);
}
.ds-kpi__bar-fill {
  display: block;
  height: 100%;
  border-radius: var(--radius-pill);
  transition: width var(--ds-duration-slow) var(--ds-easing-standard);
}

/* Sparkline inline (mini, dentro del KPI) */
.ds-kpi__spark {
  margin-top: var(--ds-space-2);
  height: 32px;
}

/* ==========================================================================
   BADGE
   ========================================================================== */
.ds-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--ds-font-size-xs);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-weight: var(--ds-font-weight-semibold);
  white-space: nowrap;
  line-height: 1.5;
}
.ds-badge--ok      { background: var(--ds-ok-dim);      color: var(--ds-ok); }
.ds-badge--warn    { background: var(--ds-warn-dim);    color: var(--ds-warn); }
.ds-badge--danger  { background: var(--ds-danger-dim);  color: var(--ds-danger); }
.ds-badge--info    { background: var(--ds-info-dim);    color: var(--ds-info); }
.ds-badge--muted   { background: var(--ds-surface-overlay); color: var(--ds-text-muted); }
.ds-badge--neutral { background: var(--ds-surface-raised);  color: var(--ds-text); }

/* ==========================================================================
   PANEL
   ========================================================================== */
.ds-panel {
  background: var(--ds-surface);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md);
  padding: var(--ds-space-4);
}
.ds-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ds-space-2);
  margin-bottom: var(--ds-space-3);
  padding-bottom: var(--ds-space-2);
  border-bottom: 1px solid var(--ds-border);
}
.ds-panel__title {
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-bold);
  color: var(--ds-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
}
.ds-panel__count {
  font-size: var(--ds-font-size-xs);
  color: var(--ds-text-subtle);
  font-weight: var(--ds-font-weight-semibold);
}

/* ==========================================================================
   DATA TABLE
   ========================================================================== */
.ds-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.ds-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--ds-font-size-sm);
  font-variant-numeric: tabular-nums;
}
.ds-table th {
  text-align: left;
  padding: var(--ds-space-2) var(--ds-space-3);
  color: var(--ds-text-muted);
  font-size: var(--ds-font-size-sm);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: var(--ds-font-weight-semibold);
  border-bottom: 2px solid var(--ds-border);
  white-space: nowrap;
  background: var(--ds-surface);
}
.ds-table td {
  padding: var(--ds-space-2) var(--ds-space-3);
  border-bottom: 1px solid var(--ds-border);
  color: var(--ds-text);
  vertical-align: middle;
}
.ds-table tr:last-child td { border-bottom: 0; }
.ds-table tbody tr {
  transition: background var(--ds-duration-instant) var(--ds-easing-standard);
}
.ds-table tbody tr:hover { background: var(--ds-surface-raised); }

/* Zebra sutil (solo si no hay row-status ni cat-sep) */
.ds-table tbody tr:nth-child(even):not(.ds-table-row--status):not(.ds-cat-sep) td {
  background: var(--ds-zebra-stripe);
}
.ds-table tbody tr:nth-child(even):not(.ds-table-row--status):not(.ds-cat-sep):hover td {
  background: var(--ds-surface-overlay);
}

/* Row status indicator (barra izquierda de color) */
.ds-table-row--ok     { border-left: 3px solid var(--ds-ok); }
.ds-table-row--warn   { border-left: 3px solid var(--ds-warn); }
.ds-table-row--danger { border-left: 3px solid var(--ds-danger); }
.ds-table-row--info   { border-left: 3px solid var(--ds-info); }

/* Sticky header */
.ds-table thead { position: sticky; top: 0; z-index: 1; }

/* ── Category separator rows ─────────────────────────────────────── */
.ds-cat-sep td {
  padding: var(--ds-space-1) var(--ds-space-3) !important;
  background: var(--ds-surface-raised) !important;
  border-bottom: 1px solid var(--ds-border) !important;
}
.ds-cat-sep { border-left: 0 !important; }
.ds-cat-label {
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-semibold);
  color: var(--ds-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.ds-cat-count {
  font-size: var(--ds-font-size-xs);
  color: var(--ds-text-subtle);
}

/* ==========================================================================
   AGENT CARD
   ========================================================================== */
.ds-agent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--ds-space-3);
}
.ds-agent-card {
  background: var(--ds-surface);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md);
  padding: var(--ds-space-4);
  transition: border-color var(--ds-duration-fast) var(--ds-easing-standard),
              box-shadow var(--ds-duration-fast) var(--ds-easing-standard),
              transform var(--ds-duration-fast) var(--ds-easing-standard);
}
.ds-agent-card:hover {
  border-color: var(--ds-border-visible);
  transform: translateY(-1px);
  box-shadow: var(--ds-shadow-raised);
}
.ds-agent-card--active {
  border-left: 3px solid var(--ds-brand);
  border-color: var(--ds-brand-dim);
}
.ds-agent-card--idle {
  border-left: 3px solid var(--ds-text-subtle);
  opacity: 0.85;
}

.ds-agent-card__header {
  display: flex;
  align-items: center;
  gap: var(--ds-space-3);
  margin-bottom: var(--ds-space-3);
}
.ds-agent-card__info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ds-agent-card__name {
  font-weight: var(--ds-font-weight-semibold);
  color: var(--ds-heading);
  font-size: var(--ds-font-size-base);
  line-height: var(--ds-leading-tight);
}
.ds-agent-card__model {
  font-size: var(--ds-font-size-xs);
}
.ds-agent-card__role {
  font-size: var(--ds-font-size-xs);
  color: var(--ds-text-muted);
  margin-bottom: var(--ds-space-2);
}
.ds-agent-card__meta {
  display: flex;
  gap: var(--ds-space-3);
  font-size: var(--ds-font-size-xs);
  color: var(--ds-text-subtle);
  flex-wrap: wrap;
}
.ds-agent-card__meta span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* Progress ring de contexto */
.ds-ctx-ring {
  position: relative;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}
.ds-ctx-ring svg { transform: rotate(-90deg); }
.ds-ctx-ring__value {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.5625rem;
  font-weight: var(--ds-font-weight-bold);
  font-family: var(--ds-font-mono);
  color: var(--ds-text-muted);
}

/* Agent avatar */
.ds-agent-avatar {
  position: relative;
  border-radius: var(--ds-radius-full);
  overflow: hidden;
  flex-shrink: 0;
  background: var(--ds-surface-overlay);
}
.ds-agent-avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ds-agent-avatar__dot {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  border-radius: var(--ds-radius-full);
  border: 2px solid var(--ds-surface);
}

/* ── Agent Modal / Popup ────────────────────────────────────────────── */
.ds-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--ds-space-4);
  animation: ds-fade-in var(--ds-duration-fast) var(--ds-easing-decelerate);
}
@keyframes ds-fade-in { from { opacity: 0; } to { opacity: 1; } }

.ds-modal {
  background: var(--ds-surface);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-lg);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--ds-shadow-overlay);
  animation: ds-modal-enter var(--ds-duration-normal) var(--ds-easing-spring);
}
@keyframes ds-modal-enter {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.ds-modal-header {
  display: flex;
  align-items: center;
  gap: var(--ds-space-3);
  padding: var(--ds-space-4) var(--ds-space-4) var(--ds-space-3);
  border-bottom: 1px solid var(--ds-border);
}
.ds-modal-name {
  font-size: var(--ds-font-size-lg);
  font-weight: var(--ds-font-weight-bold);
  color: var(--ds-heading);
  line-height: var(--ds-leading-tight);
  margin-bottom: 2px;
}
.ds-modal-role {
  font-size: var(--ds-font-size-xs);
  color: var(--ds-text-muted);
  display: flex;
  align-items: center;
}
.ds-modal-body {
  padding: var(--ds-space-3) var(--ds-space-4) var(--ds-space-4);
}
.ds-modal-bio {
  font-size: var(--ds-font-size-sm);
  color: var(--ds-text);
  line-height: var(--ds-leading-relaxed);
  margin-bottom: var(--ds-space-3);
  padding-bottom: var(--ds-space-3);
  border-bottom: 1px solid var(--ds-border);
}
.ds-modal-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ds-space-3);
  font-size: var(--ds-font-size-xs);
  color: var(--ds-text-muted);
  margin-bottom: var(--ds-space-2);
}
.ds-modal-meta span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ==========================================================================
   SERVICE TILE
   ========================================================================== */
.ds-service-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--ds-space-2);
}
.ds-service-card {
  position: relative;
}
/* Pulse dot animation */
.ds-pulse {
  animation: ds-pulse-ring 2s ease-out infinite;
}
.ds-pulse--ok {
  animation: ds-pulse-ok 2s ease-out infinite;
}
.ds-pulse--warn {
  animation: ds-pulse-warn 2s ease-out infinite;
}
@keyframes ds-pulse-ok {
  0%, 100% { box-shadow: 0 0 4px var(--ds-ok); }
  50% { box-shadow: 0 0 12px var(--ds-ok), 0 0 20px rgba(34,197,94,0.3); }
}
@keyframes ds-pulse-warn {
  0%, 100% { box-shadow: 0 0 4px var(--ds-warn); }
  50% { box-shadow: 0 0 12px var(--ds-warn), 0 0 20px rgba(251,191,36,0.3); }
}
.ds-service-tile {
  display: flex;
  align-items: center;
  gap: var(--ds-space-3);
  background: var(--ds-surface-raised);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md);
  padding: var(--ds-space-3);
  font-size: var(--ds-font-size-sm);
  transition: border-color var(--ds-duration-fast) var(--ds-easing-standard);
}
.ds-service-tile:hover {
  border-color: var(--ds-border-visible);
}
.ds-service-tile__icon {
  flex-shrink: 0;
  color: var(--ds-text-muted);
}
.ds-service-tile__name {
  font-weight: var(--ds-font-weight-medium);
  color: var(--ds-text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ds-service-tile__kind {
  font-size: var(--ds-font-size-xs);
  color: var(--ds-text-subtle);
}

/* Health bar horizontal */
.ds-health-bar {
  height: 4px;
  background: var(--ds-surface-overlay);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin-top: 6px;
}
.ds-health-bar__fill {
  height: 100%;
  border-radius: var(--radius-pill);
  transition: width var(--ds-duration-slow) var(--ds-easing-standard);
}

/* ==========================================================================
   ALERT BANNER
   ========================================================================== */
.ds-alert {
  display: flex;
  align-items: flex-start;
  gap: var(--ds-space-3);
  border: 1px solid;
  border-radius: var(--ds-radius-md);
  padding: var(--ds-space-3) var(--ds-space-4);
  font-size: var(--ds-font-size-sm);
  transition: opacity var(--ds-duration-fast) var(--ds-easing-standard);
}
.ds-alert--danger {
  background: var(--ds-danger-dim);
  border-color: var(--ds-danger);
  color: var(--ds-danger);
}
.ds-alert--warn {
  background: var(--ds-warn-dim);
  border-color: var(--ds-warn);
  color: var(--ds-warn);
}
.ds-alert--info {
  background: var(--ds-info-dim);
  border-color: var(--ds-info);
  color: var(--ds-info);
}
.ds-alert__icon {
  flex-shrink: 0;
  margin-top: 1px;
  color: inherit;
}
.ds-alert__body { flex: 1; min-width: 0; }
.ds-alert__title {
  font-weight: var(--ds-font-weight-bold);
  font-size: var(--ds-font-size-sm);
  margin-bottom: 2px;
  line-height: var(--ds-leading-tight);
  color: inherit;
}
.ds-alert__text {
  font-size: var(--ds-font-size-sm);
  line-height: var(--ds-leading-normal);
  opacity: 0.85;
  color: inherit;
}
.ds-alert__action {
  font-size: var(--ds-font-size-xs);
  color: inherit;
  opacity: 0.75;
  margin-top: 4px;
  font-weight: var(--ds-font-weight-semibold);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ==========================================================================
   SPARKLINE
   ========================================================================== */
.ds-sparkline {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 48px;
  padding: 0 2px;
}
.ds-sparkline__bar {
  position: relative;
  flex: 1;
  background: var(--ds-brand);
  border-radius: 2px 2px 0 0;
  min-height: 3px;
  cursor: pointer;
  transition: opacity var(--ds-duration-instant) var(--ds-easing-standard);
}
.ds-sparkline__bar:hover { opacity: 0.6; }

/* Tooltip en hover */
.ds-sparkline__bar[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ds-surface-overlay);
  color: var(--ds-text);
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-semibold);
  padding: 2px 6px;
  border-radius: var(--ds-radius-sm);
  white-space: nowrap;
  z-index: var(--z-tooltip);
  pointer-events: none;
  border: 1px solid var(--ds-border-visible);
  box-shadow: var(--ds-shadow-overlay);
}

/* ==========================================================================
   QUEUE ITEM
   ========================================================================== */
.ds-queue-item {
  display: flex;
  align-items: center;
  gap: var(--ds-space-3);
  padding: var(--ds-space-3) 0;
  border-top: 1px solid var(--ds-border);
  font-size: var(--ds-font-size-sm);
}
.ds-queue-item:first-child { border-top: 0; padding-top: 0; }
.ds-queue-item__priority {
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-bold);
  padding: 2px 6px;
  border-radius: var(--ds-radius-sm);
  background: var(--ds-danger-dim);
  color: var(--ds-danger);
  flex-shrink: 0;
}
.ds-queue-item__title { flex: 1; color: var(--ds-text); }
.ds-queue-item__site { color: var(--ds-text-muted); font-size: var(--ds-font-size-xs); }
.ds-queue-item__note {
  color: var(--ds-text-subtle);
  font-size: var(--ds-font-size-xs);
  margin-left: auto;
}

/* ==========================================================================
   SECTION TITLE
   ========================================================================== */
.ds-section-title {
  font-size: var(--ds-font-size-xs);
  color: var(--ds-text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: var(--ds-font-weight-bold);
  margin: var(--ds-space-5) 0 var(--ds-space-2);
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
}
.ds-section-title:first-child { margin-top: 0; }

/* ==========================================================================
   LAYOUT GRIDS
   ========================================================================== */
.ds-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--ds-space-4); }
.ds-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--ds-space-4); }
.ds-grid-asym { display: grid; grid-template-columns: 1.5fr 1fr; gap: var(--ds-space-4); }
.ds-grid-stack { display: flex; flex-direction: column; gap: var(--ds-space-4); }

/* ==========================================================================
   HERO
   ========================================================================== */
.ds-hero {
  background: linear-gradient(135deg, var(--ds-brand-dim) 0%, transparent 60%);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-lg);
  padding: var(--ds-space-5);
  margin-bottom: var(--ds-space-5);
}
.ds-hero__greeting {
  font-size: var(--ds-font-size-lg);
  font-weight: var(--ds-font-weight-bold);
  color: var(--ds-heading);
  margin: 0 0 4px 0;
  line-height: var(--ds-leading-tight);
}
.ds-hero__summary {
  font-size: var(--ds-font-size-sm);
  color: var(--ds-text-muted);
  margin: 0;
  line-height: var(--ds-leading-normal);
}
.ds-hero__meta {
  display: flex;
  gap: var(--ds-space-2);
  align-items: center;
  flex-wrap: wrap;
}

/* ==========================================================================
   TOAST
   ========================================================================== */
.ds-toast-container {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.ds-toast {
  background: var(--ds-surface-overlay);
  border: 1px solid var(--ds-border-visible);
  color: var(--ds-text);
  padding: var(--ds-space-2) var(--ds-space-4);
  border-radius: var(--ds-radius-md);
  font-size: var(--ds-font-size-sm);
  pointer-events: auto;
  box-shadow: var(--ds-shadow-overlay);
  opacity: 0;
  transform: translateY(8px);
  transition: all var(--ds-duration-fast) var(--ds-easing-standard);
}
.ds-toast--visible { opacity: 1; transform: translateY(0); }

/* ── Toast variants (severidad) ────────────────────────────────────────── */
.ds-toast--success { border-color: var(--ds-ok); background: var(--ds-ok-dim); }
.ds-toast--error   { border-color: var(--ds-danger); background: var(--ds-danger-dim); }
.ds-toast--warn    { border-color: var(--ds-warn); background: var(--ds-warn-dim); }

/* ── Badge de atajo de teclado en tabs ────────────────────────────────── */
.ds-kbd-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  margin-left: 6px;
  border-radius: 3px;
  background: var(--ds-surface-raised);
  border: 1px solid var(--ds-border);
  color: var(--ds-text-subtle);
  font-size: 0.5625rem;
  font-family: var(--ds-font-mono);
  font-weight: 600;
  line-height: 1;
}

/* ==========================================================================
   ECOSYSTEM CARDS (vista ecosistema)
   ========================================================================== */
.ds-eco-header {
  background: linear-gradient(135deg, var(--ds-brand-dim), var(--ds-surface));
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-lg);
  padding: var(--ds-space-4) var(--ds-space-5);
  margin-bottom: var(--ds-space-4);
}
.ds-eco-header__title {
  font-size: var(--ds-font-size-xl);
  font-weight: var(--ds-font-weight-bold);
  color: var(--ds-heading);
  margin: 0 0 var(--ds-space-2) 0;
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
}
.ds-eco-update {
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
  font-size: 0.6875rem;
  color: var(--ds-text-muted);
  flex-wrap: wrap;
}
.ds-eco-update__item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.ds-eco-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--ds-space-2);
  margin-bottom: var(--ds-space-2);
}
.ds-eco-card {
  background: var(--ds-surface);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md);
  padding: var(--ds-space-3) var(--ds-space-4);
  transition: border-color var(--ds-duration-fast) var(--ds-easing-standard),
              transform var(--ds-duration-fast) var(--ds-easing-standard);
}
.ds-eco-card:hover {
  border-color: var(--ds-border-visible);
  transform: translateY(-1px);
  box-shadow: var(--ds-shadow-raised);
}
.ds-eco-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--ds-space-2);
  margin-bottom: var(--ds-space-2);
}
.ds-eco-card__name {
  font-weight: var(--ds-font-weight-semibold);
  color: var(--ds-heading);
  font-size: var(--ds-font-size-md);
  line-height: var(--ds-leading-tight);
}
.ds-eco-card__domain {
  display: block;
  font-size: var(--ds-font-size-xs);
  color: var(--ds-text-muted);
  font-weight: var(--ds-font-weight-normal);
  font-family: var(--ds-font-mono);
  margin-top: 2px;
}
.ds-eco-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ds-space-2);
  font-size: var(--ds-font-size-xs);
  color: var(--ds-text-muted);
  margin-bottom: var(--ds-space-2);
}
.ds-eco-card__meta span {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.ds-eco-card__products {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: var(--ds-space-2);
}
.ds-eco-card__note {
  font-size: var(--ds-font-size-xs);
  color: var(--ds-text-subtle);
  line-height: var(--ds-leading-normal);
  margin-bottom: var(--ds-space-1);
}
.ds-eco-card__alert {
  font-size: var(--ds-font-size-xs);
  font-weight: var(--ds-font-weight-semibold);
  color: var(--ds-danger);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: var(--ds-space-1);
  padding: var(--ds-space-1) var(--ds-space-2);
  background: var(--ds-danger-dim);
  border-radius: var(--ds-radius-sm);
}
.ds-eco-card__audit {
  font-size: 0.625rem;
  color: var(--ds-text-subtle);
  margin-top: var(--ds-space-2);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ==========================================================================
   INFRA CARDS (subdominios y dominios en vista infra)
   ========================================================================== */
.ds-infra-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: var(--ds-space-2);
  margin-bottom: var(--ds-space-3);
}
.ds-infra-card {
  background: var(--ds-surface);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md);
  padding: var(--ds-space-3);
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color var(--ds-duration-fast) var(--ds-easing-standard);
}
.ds-infra-card:hover {
  border-color: var(--ds-border-visible);
}
.ds-infra-card__top {
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
}
.ds-infra-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.ds-infra-card__name {
  font-weight: var(--ds-font-weight-semibold);
  font-size: 0.8125rem;
  color: var(--ds-brand);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ds-infra-card__name:hover {
  text-decoration: underline;
}
.ds-infra-card__row {
  display: flex;
  align-items: baseline;
  gap: var(--ds-space-1);
  font-size: 0.6875rem;
}
.ds-infra-card__label {
  color: var(--ds-text-subtle);
  font-weight: 600;
  min-width: 36px;
  flex-shrink: 0;
}
.ds-infra-card__value {
  color: var(--ds-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==========================================================================
   METRICAS-WEB (vista SEO, AEO & CRO)
   ========================================================================== */
/* Cabecera */
.ds-mw-header {
  background: linear-gradient(135deg, var(--ds-surface-raised), var(--ds-surface));
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-lg);
  padding: var(--ds-space-4) var(--ds-space-5);
  margin-bottom: var(--ds-space-3);
}
.ds-mw-title {
  font-size: var(--ds-font-size-xl);
  font-weight: var(--ds-font-weight-bold);
  color: var(--ds-heading);
  margin: 0 0 var(--ds-space-2) 0;
  line-height: 1.2;
}
.ds-mw-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ds-space-2) var(--ds-space-4);
  font-size: 0.6875rem;
  color: var(--ds-text-muted);
}
.ds-mw-meta__item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

/* Filtros */
.ds-mw-filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ds-space-3);
  margin-bottom: var(--ds-space-3);
  padding: var(--ds-space-3) var(--ds-space-4);
  background: var(--ds-surface);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md);
}
.ds-mw-filter-group {
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
}
.ds-mw-filter-label {
  font-size: 0.75rem;
  font-weight: var(--ds-font-weight-semibold);
  color: var(--ds-text);
  white-space: nowrap;
}

/* Secciones */
.ds-mw-section {
  margin-top: var(--ds-space-4) !important;
}
.ds-mw-heading {
  font-size: 1.125rem !important;
  margin-bottom: var(--ds-space-3) !important;
}
.ds-mw-subtitle {
  font-size: 0.6875rem;
  color: var(--ds-text-subtle);
  margin: 0 0 var(--ds-space-2) 0;
  font-style: italic;
}

/* Empty state */
.ds-mw-empty {
  text-align: center;
  padding: var(--ds-space-5) var(--ds-space-4);
  background: var(--ds-surface);
  border: 1px dashed var(--ds-border);
  border-radius: var(--ds-radius-md);
}
.ds-mw-empty__icon {
  color: var(--ds-text-muted);
  margin-bottom: var(--ds-space-2);
}
.ds-mw-empty__title {
  font-size: 0.875rem;
  font-weight: var(--ds-font-weight-semibold);
  color: var(--ds-text);
  margin: 0 0 4px 0;
}
.ds-mw-empty__text {
  font-size: 0.6875rem;
  color: var(--ds-text-subtle);
  margin: 0;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}

/* Project cards */
.ds-mw-project-card {
  background: var(--ds-surface);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md);
  padding: var(--ds-space-3) var(--ds-space-4);
  margin-bottom: var(--ds-space-2);
  transition: border-color var(--ds-duration-fast);
}
.ds-mw-project-card:hover {
  border-color: var(--ds-border-visible);
}
.ds-mw-project-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ds-space-2);
  margin-bottom: var(--ds-space-2);
  flex-wrap: wrap;
}
.ds-mw-project-card__name {
  font-size: 0.9375rem;
  font-weight: var(--ds-font-weight-bold);
  color: var(--ds-heading);
  margin: 0;
  letter-spacing: 0.02em;
}
.ds-mw-project-card__badges {
  display: flex;
  gap: var(--ds-space-1);
  flex-wrap: wrap;
}
.ds-mw-project-card__metrics {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ds-space-3);
  margin-bottom: var(--ds-space-2);
}
.ds-mw-metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 70px;
  padding: var(--ds-space-1) var(--ds-space-2);
  background: var(--ds-surface-raised);
  border-radius: var(--ds-radius-sm);
}
.ds-mw-metric__label {
  font-size: 0.5625rem;
  color: var(--ds-text-subtle);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.ds-mw-metric__value {
  font-size: 0.9375rem;
  font-weight: var(--ds-font-weight-bold);
  color: var(--ds-text);
  font-family: var(--ds-font-mono);
}
.ds-mw-project-card__aeo {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ds-space-2);
  padding-top: var(--ds-space-2);
  border-top: 1px solid var(--ds-border);
}
.ds-mw-submetric {
  display: flex;
  align-items: center;
  gap: var(--ds-space-1);
  font-size: 0.6875rem;
}
.ds-mw-submetric__label {
  color: var(--ds-text-muted);
  white-space: nowrap;
}
.ds-mw-submetric__value {
  font-weight: 600;
  color: var(--ds-text);
  font-family: var(--ds-font-mono);
}
.ds-mw-submetric__chip {
  margin-left: 2px;
}

/* Chips row (CRO status, Pipeline) */
.ds-mw-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ds-space-2);
  align-items: center;
  padding: var(--ds-space-2) var(--ds-space-3);
  background: var(--ds-surface);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md);
  margin-top: var(--ds-space-2);
}
.ds-mw-chips-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--ds-text-muted);
  margin-right: var(--ds-space-1);
}

/* Responsive */
@media (max-width: 780px) {
  .ds-kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .ds-grid-2, .ds-grid-3, .ds-grid-asym { grid-template-columns: 1fr; }
  .ds-kpi__value { font-size: var(--ds-font-size-2xl); }
  .ds-agent-grid { grid-template-columns: 1fr; }
  .ds-infra-grid { grid-template-columns: 1fr; }
}

/* Detail links in section headings */
.met-kpi-group__link,
.ds-mw-back {
  font-size: 0.6875rem;
  font-weight: 400;
  color: var(--ds-brand);
  text-decoration: none;
  margin-left: auto;
  white-space: nowrap;
}
.met-kpi-group__link:hover,
.ds-mw-back:hover {
  text-decoration: underline;
}
.ds-mw-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: var(--ds-space-3);
  font-size: 0.75rem;
}

@media (max-width: 600px) {
  .ds-mw-project-card__metrics { justify-content: center; }
  .ds-mw-filters { flex-direction: column; }
}

@media (max-width: 480px) {
  .ds-kpi-grid { grid-template-columns: 1fr 1fr; gap: var(--ds-space-2); }
  .ds-kpi { padding: var(--ds-space-3); }
  .ds-kpi__value { font-size: var(--ds-font-size-xl); }
}

/* ==========================================================================
   AGENTES (vista mapa-agentes)
   ========================================================================== */
.ds-ag-header {
  background: linear-gradient(135deg, var(--ds-surface-raised), var(--ds-surface));
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-lg);
  padding: var(--ds-space-4) var(--ds-space-5);
  margin-bottom: var(--ds-space-4);
}
.ds-ag-header__title {
  font-size: var(--ds-font-size-xl);
  font-weight: var(--ds-font-weight-bold);
  color: var(--ds-heading);
  margin: 0 0 var(--ds-space-2) 0;
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
}
.ds-ag-header__meta {
  display: flex;
  align-items: center;
  gap: var(--ds-space-3);
  font-size: 0.6875rem;
  color: var(--ds-text-muted);
  flex-wrap: wrap;
}
.ds-ag-header__stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.ds-ag-area {
  margin-bottom: var(--ds-space-4);
}
.ds-ag-area__header {
  display: flex;
  align-items: baseline;
  gap: var(--ds-space-2);
  margin-bottom: var(--ds-space-2);
}
.ds-ag-area__title {
  font-size: 1rem;
  font-weight: var(--ds-font-weight-bold);
  color: var(--ds-heading);
  margin: 0;
}
.ds-ag-area__count {
  font-size: 0.6875rem;
  color: var(--ds-text-muted);
}
.ds-ag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--ds-space-2);
}
.ds-ag-card {
  background: var(--ds-surface);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md);
  padding: 10px var(--ds-space-3);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.ds-ag-card:hover {
  border-color: var(--ds-border-visible);
  box-shadow: var(--ds-shadow-raised);
}
.ds-ag-card__main {
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
}
.ds-ag-card__icon {
  font-size: 1.25rem;
  flex-shrink: 0;
  width: 28px;
  text-align: center;
}
.ds-ag-card__info {
  flex: 1;
  min-width: 0;
}
.ds-ag-card__name {
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--ds-text);
  display: flex;
  align-items: center;
}
.ds-ag-card__rol {
  font-size: 0.625rem;
  color: var(--ds-text-subtle);
  margin-top: 1px;
}
.ds-ag-card__meta {
  font-size: 0.5625rem;
  color: var(--ds-text-muted);
  padding-left: 36px;
  font-style: italic;
}

/* Section spacing (infra, metricas-web, etc.) */
.ds-section-heading {
  margin-bottom: var(--ds-space-3);
}
