/* ============================================================
   Forbys — Dashboard analítico (Fase 2)
   Usa tokens de tokens.css. Soporte dark/light automático.
   ============================================================ */

/* ── Contenedor principal ─────────────────────────────────────── */
.dashboard-container {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}

/* ── Banda de insights (Fase 3) ───────────────────────────────── */
.insights-banner {
  display: flex;
  gap: var(--space-4);
  align-items: flex-start;
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--primary) 8%, var(--bg-elev)),
    var(--bg-elev));
  border: 1px solid color-mix(in srgb, var(--primary) 22%, var(--border));
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-sm);
}
.insights-icon {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
}
.insights-icon-muted {
  background: var(--bg-subtle);
  color: var(--text-muted);
}
.insights-content {
  flex: 1;
  min-width: 0;
}
.insights-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.insights-text {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  margin: 0;
}
.insights-meta {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
}
.insights-actions {
  flex-shrink: 0;
}
.insights-banner-muted {
  background: var(--bg-elev);
  border-color: var(--border);
}
.insights-banner-muted .insights-text { color: var(--text-muted); }

/* Mobile */
@media (max-width: 640px) {
  .insights-banner { flex-direction: column; gap: var(--space-2); }
  .insights-actions { align-self: flex-end; }
}

/* ── Toolbar ──────────────────────────────────────────────────── */
.dashboard-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.dashboard-toolbar .dashboard-select {
  min-width: 220px;
  max-width: 320px;
}
.dashboard-filtros {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.dashboard-filtros .date-wrap { width: 150px; }
.dashboard-actions {
  margin-left: auto;
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.dashboard-toggle-compare {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.dashboard-toggle-compare input { margin: 0; }

/* ── Empty state del dashboard ────────────────────────────────── */
.dashboard-empty {
  text-align: center;
  padding: var(--space-12) var(--space-4);
  color: var(--text-muted);
  background: var(--bg-elev);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
}
.dashboard-empty svg {
  width: 48px;
  height: 48px;
  color: var(--text-subtle);
  margin-bottom: var(--space-3);
}
.dashboard-empty h3 {
  font-size: 18px;
  color: var(--text);
  margin: 0 0 var(--space-2) 0;
}
.dashboard-empty p { margin: 0; font-size: 14px; }

/* ── Grid de widgets (override de Gridstack) ──────────────────── */
.grid-stack { min-height: 200px; }
.grid-stack > .grid-stack-item > .grid-stack-item-content {
  inset: 0 !important;
  background: transparent !important;
  overflow: hidden !important;
}

/* ── Wrapper común de widget ──────────────────────────────────── */
.widget {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
  position: relative;
  box-shadow: var(--shadow-sm);
}
.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  gap: var(--space-2);
}
.widget-drag-handle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: grab;
  flex: 1;
  min-width: 0;
}
.widget-drag-handle:active { cursor: grabbing; }
.widget-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.widget-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition);
}

/* Badge de anomalías en el header (Fase 3) */
.widget-anomaly-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--danger-bg);
  color: var(--danger);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  margin-left: 6px;
  flex-shrink: 0;
}
.widget-anomaly-badge svg { width: 11px; height: 11px; stroke-width: 2.5; }

/* Celda de pivot que cae en rango de outlier */
.pivot-cell-anomaly {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 2px solid color-mix(in srgb, var(--danger) 50%, transparent) !important;
  color: var(--danger);
  font-weight: 700;
  position: relative;
}
.widget:hover .widget-actions { opacity: 1; }
.widget-actions .btn-icon { width: 24px; height: 24px; }
.widget-body {
  flex: 1;
  padding: var(--space-3);
  overflow: hidden;
  position: relative;
  min-height: 0;
}

/* ── Estados (loading / error) ────────────────────────────────── */
.widget-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--bg-elev) 70%, transparent);
  z-index: 2;
  font-size: 12px;
  color: var(--text-muted);
}
.widget-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 100%;
  color: var(--danger);
  padding: var(--space-4);
  gap: var(--space-2);
  font-size: 13px;
}
.widget-error svg { color: var(--danger); }
.widget-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-subtle);
  font-size: 13px;
  font-style: italic;
}

/* ── KPI card ─────────────────────────────────────────────────── */
.widget--kpi .widget-body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 4px;
}
.kpi-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.kpi-value {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text);
  word-break: break-all;
}
.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  margin-top: 2px;
}
.kpi-delta-positive { color: var(--success); }
.kpi-delta-negative { color: var(--danger); }
.kpi-delta-neutral  { color: var(--text-muted); }
.kpi-delta-sub {
  display: block;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Time series / Histogram (Chart.js container) ─────────────── */
.widget-chart {
  position: relative;
  width: 100%;
  height: 100%;
}

/* ── Heatmap calendar ─────────────────────────────────────────── */
.heatmap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  height: 100%;
}
.heatmap-grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 1fr);
  gap: 3px;
  flex: 1;
  min-height: 0;
}
.heatmap-cell {
  border-radius: 3px;
  background: var(--bg-subtle);
  cursor: default;
  min-width: 0;
  min-height: 0;
}
.heatmap-cell-0 { background: var(--bg-subtle); }
.heatmap-cell-1 { background: color-mix(in srgb, var(--primary) 25%, var(--bg-subtle)); }
.heatmap-cell-2 { background: color-mix(in srgb, var(--primary) 50%, var(--bg-subtle)); }
.heatmap-cell-3 { background: color-mix(in srgb, var(--primary) 75%, var(--bg-subtle)); }
.heatmap-cell-4 { background: var(--primary); }
.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
  justify-content: flex-end;
}
.heatmap-legend-cell {
  width: 12px;
  height: 12px;
  border-radius: 2px;
}

/* ── Pivot table ──────────────────────────────────────────────── */
.pivot-wrap {
  overflow: auto;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.pivot-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.pivot-table th,
.pivot-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  white-space: nowrap;
}
.pivot-table thead th {
  background: var(--bg-subtle);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}
.pivot-table tbody th {
  background: var(--bg-subtle);
  font-weight: 600;
  text-align: left;
  position: sticky;
  left: 0;
  z-index: 1;
}
.pivot-table tbody td {
  font-family: var(--font-mono);
  text-align: right;
  color: var(--text);
}
.pivot-table tfoot th,
.pivot-table tfoot td {
  background: var(--bg-subtle);
  font-weight: 700;
  font-family: var(--font-mono);
  text-align: right;
  border-top: 2px solid var(--border-strong);
}
.pivot-table tfoot th { text-align: left; }

/* ── Anomaly list ─────────────────────────────────────────────── */
.anomaly-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  height: 100%;
  overflow-y: auto;
}
.anomaly-card {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: 13px;
}
.anomaly-card-title {
  font-weight: 600;
  color: var(--text);
}
.anomaly-card-meta {
  color: var(--text-muted);
  font-size: 11.5px;
}
.anomaly-card-value {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
}
.anomaly-card-zscore {
  display: inline-block;
  margin-left: 6px;
  background: var(--danger-bg);
  color: var(--danger);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
}
.anomaly-card a {
  font-size: 11.5px;
  color: var(--primary);
  text-decoration: none;
}
.anomaly-card a:hover { text-decoration: underline; }

/* ── Panel lateral "Agregar widget" ───────────────────────────── */
.widget-panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 99;
  display: flex;
  justify-content: flex-end;
}
[data-theme="dark"] .widget-panel-overlay { background: rgba(0,0,0,0.55); }

.widget-panel {
  position: fixed;
  right: var(--space-4);
  top: var(--space-6);
  width: 380px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 96px);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.widget-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}
.widget-panel-title { font-weight: 600; font-size: 14px; }
.widget-panel-body {
  padding: var(--space-3);
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.widget-panel-item {
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.widget-panel-item.is-disabled {
  opacity: 0.5;
  pointer-events: none;
}
.widget-panel-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.widget-panel-item-name { font-weight: 600; font-size: 13px; color: var(--text); }
.widget-panel-item-desc { font-size: 12px; color: var(--text-muted); margin-bottom: var(--space-2); }
.widget-panel-sugerencias {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.widget-panel-sugerencia {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  cursor: pointer;
  transition: background var(--transition);
}
.widget-panel-sugerencia:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}
.widget-panel-sugerencia svg { color: var(--primary); }
.widget-panel-no-disponible {
  font-size: 11.5px;
  font-style: italic;
  color: var(--warning);
}

/* ── Mobile ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .dashboard-toolbar { flex-direction: column; align-items: stretch; }
  .dashboard-actions { margin-left: 0; }
  .grid-stack > .grid-stack-item {
    width: 100% !important;
    left: 0 !important;
    position: relative !important;
    transform: none !important;
  }
}


/* ── Builder visual de validación (Task 11) ─────────────────────────── */
.val-tabs {
  display: flex;
  border-bottom: 1px solid var(--border, #2a2f38);
  margin-bottom: 12px;
}
.val-tab-btn {
  background: transparent;
  border: none;
  padding: 8px 14px;
  color: var(--text-muted, #888);
  font-size: 13px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.val-tab-btn.active {
  color: var(--text, #eee);
  border-bottom-color: var(--primary, #2c5fd6);
  font-weight: 600;
}

.bloques-cadena {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  padding: 12px;
  background: var(--bg-subtle, #161a22);
  border: 1px solid var(--border, #2a2f38);
  border-radius: 8px;
  margin-bottom: 10px;
}
.bloque {
  position: relative;
  background: var(--bg, #1a1f28);
  border: 1px solid var(--border, #3a414f);
  border-radius: 6px;
  padding: 8px 10px;
  display: flex; flex-direction: column; gap: 4px;
  min-width: 90px;
}
.bloque-separador { border-style: dashed; }
.bloque-eliminar {
  position: absolute; top: 2px; right: 4px;
  background: transparent; border: none;
  color: var(--text-muted, #888);
  font-size: 14px; cursor: pointer; padding: 0; line-height: 1;
}
.bloque-tipo {
  font-size: 10px; text-transform: uppercase;
  color: var(--text-muted, #888); letter-spacing: .5px;
}
.bloque-char, .bloque-cantidad {
  width: 60px; text-align: center;
  font-family: var(--mono, monospace);
}
.bloques-agregar { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-bloque-add {
  background: var(--bg, #1a1f28);
  border: 1px solid var(--border, #2a2f38);
  padding: 6px 10px; border-radius: 6px;
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; cursor: pointer;
  color: var(--text, #ddd);
}
.btn-bloque-add:hover { border-color: var(--primary, #2c5fd6); }
.bloque-icono {
  display: inline-block; width: 18px; height: 18px;
  background: var(--bg-subtle, #161a22);
  border-radius: 4px; text-align: center; line-height: 18px;
  font-family: var(--mono, monospace); font-weight: 700;
}

.regex-preview {
  margin-top: 12px; padding: 10px;
  background: var(--bg-subtle, #161a22);
  border-radius: 6px;
}
.regex-monospace {
  font-family: var(--mono, monospace); font-size: 13px;
  color: var(--success, #4ade80);
  background: var(--bg, #0e1217);
  padding: 8px 10px; border-radius: 4px;
  margin-top: 4px; word-break: break-all;
}
.regex-test {
  padding-top: 8px;
  border-top: 1px solid var(--border, #2a2f38);
}


/* ── Tab Ejemplos: lista de cards (Task 12) ─────────────────────────── */
.ejemplos-header {
  font-size: 11px;
  color: var(--text-muted, #888);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 10px;
}
.ejemplo-card {
  display: flex; gap: 14px; padding: 14px;
  background: var(--bg-subtle, #161a22);
  border: 1px solid var(--border, #2a2f38);
  border-radius: 8px;
  margin-bottom: 10px;
}
.ejemplo-desact { border-color: var(--warning, #f5c267); }
.ejemplo-icon {
  width: 48px; height: 48px;
  background: var(--bg, #1a1f28);
  border: 1px solid var(--border, #2a2f38);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted, #888);
  flex-shrink: 0;
}
.ejemplo-info { flex: 1; min-width: 0; }
.ejemplo-nombre {
  font-weight: 600; font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ejemplo-meta {
  font-size: 12px; color: var(--text-muted, #888);
  margin-top: 4px;
}
.ejemplo-badges {
  display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap;
}
.badge-ok {
  background: rgba(34,197,94,.15); color: var(--success, #4ade80);
  padding: 3px 8px; border-radius: 4px; font-size: 11px;
}
.badge-off {
  background: rgba(120,120,120,.15); color: var(--text-muted, #888);
  padding: 3px 8px; border-radius: 4px; font-size: 11px;
}
.badge-warn {
  background: rgba(234,179,8,.15); color: var(--warning, #f5c267);
  padding: 3px 8px; border-radius: 4px; font-size: 11px;
}
.ejemplo-acciones {
  display: flex; gap: 4px;
  align-items: flex-start;
}
.btn-block { width: 100%; padding: 14px; justify-content: center; }
.btn-block:disabled { opacity: .5; cursor: not-allowed; }


/* ── Modal Agregar ejemplo (Task 13) ────────────────────────────────── */
.modal-lg { max-width: 900px; width: 95%; }

.upload-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
}
.upload-card {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 30px 20px;
  border: 2px dashed var(--primary, #2c5fd6);
  border-radius: 8px;
  cursor: pointer;
  background: var(--bg-subtle, #161a22);
  color: var(--primary, #2c5fd6);
  text-align: center;
  transition: background .12s;
}
.upload-card:hover { background: rgba(44,95,214,.08); }
.upload-icon {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
}
.upload-title { font-weight: 600; font-size: 13px; }

.loading-large {
  text-align: center; padding: 40px;
  color: var(--text-muted, #888);
}
.spinner-md {
  width: 32px; height: 32px;
  border: 3px solid var(--border, #2a2f38);
  border-top-color: var(--primary, #2c5fd6);
  border-radius: 50%;
  margin: 0 auto;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.ejemplo-split {
  display: grid; grid-template-columns: 1fr 1fr; gap: 18px;
  max-height: 60vh; overflow: hidden;
}
.preview-doc {
  background: var(--bg-subtle, #161a22);
  border: 1px solid var(--border, #2a2f38);
  border-radius: 6px;
  min-height: 400px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.preview-doc img, .preview-doc embed {
  max-width: 100%; max-height: 500px;
  object-fit: contain;
}
.campos-correccion {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 60vh; overflow-y: auto;
  padding-right: 6px;
}
.campo-correccion {
  background: var(--bg-subtle, #161a22);
  border: 1px solid var(--border, #2a2f38);
  border-radius: 6px;
  padding: 10px 12px;
}
.campo-label {
  font-size: 11px; color: var(--text-muted, #888);
  text-transform: uppercase; letter-spacing: .3px;
  margin-bottom: 6px;
}
.campo-conf { font-size: 11px; margin-top: 4px; }
.conf-alta  { border-color: var(--success, #4ade80); }
.conf-alta  .campo-conf { color: var(--success, #4ade80); }
.conf-media { border-color: var(--warning, #f5c267); }
.conf-media .campo-conf { color: var(--warning, #f5c267); }
.conf-baja  { border-color: var(--danger,  #ef4444); }
.conf-baja  .campo-conf { color: var(--danger,  #ef4444); }

@media (max-width: 720px) {
  .ejemplo-split { grid-template-columns: 1fr; max-height: none; }
  .upload-grid   { grid-template-columns: 1fr; }
}
