/* Lab app — layout estilo Complexity Studio (Series Temporales) */
html.lab-light,
html.lab-light body {
  --lab-bg: #f0f4f8;
  --lab-card: #ffffff;
  --lab-border: #e2e8f0;
  --lab-text: #1e293b;
  --lab-muted: #64748b;
  --lab-blue: #6CAED1;
  --lab-blue-dark: #4a9bb8;
  --lab-green: #10B981;
  --lab-gold-start: #e8c468;
  --lab-gold-end: #d4a853;
  background: var(--lab-bg);
  color: var(--lab-text);
}

.lab-app {
  min-height: 100vh;
  padding: 1.25rem 1.5rem 2rem;
}

.lab-app-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.lab-app-header h1 {
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 2.5vw, 1.75rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--lab-text);
}

.lab-app-header h1 span {
  color: var(--lab-blue);
}

.lab-app-header .subtitle {
  font-size: 0.9rem;
  color: var(--lab-muted);
  margin-top: 4px;
  max-width: 520px;
}

.lab-hint-box {
  background: #fff;
  border: 1px solid var(--lab-border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--lab-muted);
  max-width: 280px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.lab-dashboard {
  display: grid;
  grid-template-columns: 280px 1fr 260px;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 1100px) {
  .lab-dashboard { grid-template-columns: 1fr; }
}

.lab-card {
  background: var(--lab-card);
  border: 1px solid var(--lab-border);
  border-radius: 14px;
  padding: 1rem 1.1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.lab-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--lab-text);
}

.lab-card-title .step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--lab-blue);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
}

.lab-card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.lab-card-header-row .lab-card-title {
  margin-bottom: 0;
}

/* Left — config */
.upload-box {
  border: 2px dashed #b8d9ea;
  border-radius: 12px;
  padding: 1.25rem 1rem;
  text-align: center;
  background: #f8fbfd;
  margin-bottom: 1rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.upload-box:hover {
  border-color: var(--lab-blue);
  background: #f0f8fc;
}

.upload-box p {
  font-size: 12px;
  color: var(--lab-muted);
  margin-bottom: 10px;
}

.upload-box input { display: none; }

.upload-box.is-dragover {
  border-color: var(--lab-blue);
  background: #e8f4fa;
}

.upload-box.is-loading {
  opacity: 0.75;
  pointer-events: none;
}

.upload-box.is-loading .btn-select-file::after {
  content: "…";
}

.upload-box--locked {
  cursor: not-allowed;
  background: #f3f4f6;
  border-color: #d1d5db;
}

.upload-box--locked:hover {
  border-color: #d1d5db;
  background: #f3f4f6;
}

.upload-box--locked .btn-select-file {
  background: #9ca3af;
  cursor: not-allowed;
}

.upload-box__lock-msg {
  display: none;
  margin-top: 8px;
  font-size: 11px;
  font-weight: 600;
  color: #6b7280;
}

.upload-box--locked .upload-box__lock-msg {
  display: block;
}

.file-loaded[data-status="error"] {
  color: #dc2626;
}

.file-loaded[data-status="warn"] {
  color: #d97706;
}

.file-loaded[data-status="loading"] {
  color: var(--lab-blue-dark);
}

.btn-select-file {
  display: inline-block;
  padding: 8px 16px;
  background: var(--lab-blue);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.form-field {
  margin-bottom: 12px;
}

.form-field label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--lab-muted);
  margin-bottom: 5px;
}

.form-field select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--lab-border);
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
  color: var(--lab-text);
  appearance: auto;
}

.file-loaded {
  font-size: 11px;
  color: var(--lab-green);
  margin-top: 8px;
  font-family: ui-monospace, monospace;
}

/* Center — visualization */
.stats-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

@media (max-width: 900px) {
  .stats-row { grid-template-columns: repeat(3, 1fr); }
}

.stat-pill {
  background: #fff;
  border: 1px solid var(--lab-border);
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
}

.stat-pill .label {
  display: block;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--lab-muted);
  margin-bottom: 2px;
}

.stat-pill .value {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--lab-blue);
}

:root {
  --viz-viewport-height: clamp(300px, 38vh, 460px);
}

@media (max-width: 1100px) {
  :root {
    --viz-viewport-height: clamp(280px, 42vw, 400px);
  }
}

@media (max-width: 640px) {
  :root {
    --viz-viewport-height: clamp(260px, 48vw, 340px);
  }
}

.lab-card--main .viz-area {
  border: 2px dashed #e2e8f0;
  border-radius: 12px;
  height: var(--viz-viewport-height);
  min-height: var(--viz-viewport-height);
  max-height: var(--viz-viewport-height);
  position: relative;
  background: #fafbfc;
  overflow: hidden;
}

.lab-card--main .viz-area canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.cohesion-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 4px;
}

.cohesion-stat {
  background: #f8fafc;
  border: 1px solid var(--lab-border);
  border-radius: 10px;
  padding: 8px 10px;
}

.cohesion-stat .label {
  display: block;
  font-size: 11px;
  color: var(--lab-muted);
  margin-bottom: 2px;
}

.cohesion-stat .value {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 800;
  color: var(--lab-blue);
}

.centrality-metric-field {
  margin-bottom: 10px;
}

.centrality-metric-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--lab-muted);
  display: block;
  margin-bottom: 4px;
}

.centrality-metric-field select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--lab-border);
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
}

.priority-heatmap-wrap {
  overflow-x: auto;
  margin-bottom: 8px;
}

.priority-heatmap {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.priority-heatmap th,
.priority-heatmap td {
  border: 1px solid var(--lab-border);
  padding: 4px 6px;
  text-align: center;
}

.priority-heatmap th:first-child,
.priority-heatmap td:first-child {
  text-align: left;
  font-weight: 600;
  min-width: 90px;
}

.likert-cell {
  font-weight: 700;
  min-width: 36px;
}

.layer-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}

.layer-overlap-wrap {
  overflow-x: auto;
  margin-bottom: 8px;
}

.layer-overlap-table th {
  font-size: 10px;
  max-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.zoom-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 5;
}

.zoom-controls button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--lab-border);
  border-radius: 8px;
  background: rgba(255,255,255,0.95);
  font-size: 16px;
  font-weight: 700;
  color: var(--lab-text);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  line-height: 1;
}

.zoom-controls button:hover {
  border-color: var(--lab-blue);
  color: var(--lab-blue);
}

#main-graph {
  cursor: grab;
}

#main-graph:active {
  cursor: grabbing;
}

.viz-mode-controls {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  gap: 6px;
  z-index: 5;
}

.viz-mode-controls button {
  padding: 6px 12px;
  border: 1px solid var(--lab-border);
  border-radius: 8px;
  background: rgba(255,255,255,0.95);
  font-size: 12px;
  font-weight: 600;
  color: var(--lab-text);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.viz-mode-controls button.active {
  border-color: var(--lab-blue);
  background: rgba(108,174,209,0.15);
  color: var(--lab-blue-dark);
}

.viz-mode-controls button:hover {
  border-color: var(--lab-blue);
}

.viz-nav-controls {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.viz-nav-controls button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--lab-border);
  border-radius: 8px;
  background: rgba(255,255,255,0.95);
  font-size: 12px;
  font-weight: 700;
  color: var(--lab-text);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  line-height: 1;
}

.viz-nav-controls button:hover:not(:disabled) {
  border-color: var(--lab-blue);
  color: var(--lab-blue);
}

.viz-nav-controls button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.viz-restart-btn {
  position: absolute;
  bottom: 10px;
  right: 10px;
  z-index: 5;
  padding: 8px 14px;
  border: 1px solid var(--lab-border);
  border-radius: 8px;
  background: rgba(255,255,255,0.95);
  font-size: 13px;
  font-weight: 600;
  color: var(--lab-text);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

.viz-mode-controls[hidden],
.viz-restart-btn[hidden] {
  display: none !important;
}

.community-legend:empty {
  display: none;
}

.viz-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--lab-muted);
  font-size: 13px;
  text-align: center;
  padding: 2rem;
  pointer-events: none;
}

.viz-placeholder.hidden { display: none; }

.secondary-viz {
  margin-top: 1rem;
  border-top: 1px solid var(--lab-border);
  padding-top: 1rem;
}

.secondary-viz h3 {
  font-size: 12px;
  font-weight: 700;
  color: var(--lab-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}

.secondary-viz canvas { max-height: 200px; }

#chart-resilience {
  max-height: 220px;
  margin: 4px 0 0 2px;
}

.secondary-table {
  width: 100%;
  font-size: 12px;
  border-collapse: collapse;
}

.secondary-table th,
.secondary-table td {
  padding: 7px 10px;
  text-align: left;
  border-bottom: 1px solid var(--lab-border);
}

.secondary-table th {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--lab-muted);
}

.territory-map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 6px;
}

.territory-tile {
  padding: 10px 6px;
  border-radius: 8px;
  text-align: center;
  font-size: 10px;
  font-weight: 600;
  border: 1px solid var(--lab-border);
}

.resilience-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.resilience-compare canvas {
  height: 140px;
  border: 1px solid var(--lab-border);
  border-radius: 8px;
  background: #fafbfc;
}

/* Right — methods */
.method-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 11px 14px;
  margin-bottom: 8px;
  border: 1px solid var(--lab-border);
  border-radius: 10px;
  background: #f8fafc;
  font-size: 13px;
  font-weight: 600;
  color: var(--lab-text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.method-btn:hover {
  background: #fff;
  border-color: #b8d9ea;
}

.method-btn.active {
  background: #fff;
  border-color: var(--lab-blue);
  box-shadow: 0 0 0 2px rgba(108,174,209,0.2);
}

.method-btn small {
  display: block;
  font-weight: 400;
  font-size: 11px;
  color: var(--lab-muted);
  margin-top: 2px;
}

.btn-generar {
  width: 100%;
  margin-top: 12px;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--lab-green);
  color: #fff;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.btn-generar:hover { filter: brightness(1.05); }

.btn-informe-ia {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--lab-gold-start), var(--lab-gold-end));
  color: #1a1a1a;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.btn-informe-ia:hover { filter: brightness(1.03); }

.demo-strip {
  background: #fef9e7;
  border-bottom: 1px solid #f0e4b8;
  padding: 8px 1.5rem;
  text-align: center;
  font-size: 12px;
  color: #78716c;
}

.demo-strip a { color: var(--lab-blue-dark); font-weight: 600; }

.analysis-desc {
  font-size: 12px;
  color: var(--lab-muted);
  margin-bottom: 12px;
  line-height: 1.5;
  padding: 8px 10px;
  background: #f8fafc;
  border-radius: 8px;
}

.legend-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--lab-muted);
}

.analysis-progress {
  margin-top: 10px;
  padding: 0 14px;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  border-radius: 10px;
  border: 1px solid transparent;
  background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
  transition:
    opacity 0.35s ease,
    max-height 0.4s ease,
    padding 0.35s ease,
    margin 0.35s ease,
    border-color 0.35s ease;
}

.analysis-progress.is-active {
  padding: 11px 14px 12px;
  max-height: 56px;
  opacity: 1;
  border-color: var(--lab-border);
  box-shadow: 0 1px 4px rgba(37, 99, 235, 0.06);
}

.analysis-progress__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 12px;
}

.analysis-progress__label {
  font-weight: 600;
  color: var(--lab-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.analysis-progress__pct {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 11px;
  color: var(--lab-blue);
  flex-shrink: 0;
}

.analysis-progress__track {
  height: 5px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.analysis-progress__fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--lab-blue) 0%, #6CAED1 55%, #10B981 100%);
  transition: width 0.22s ease-out;
  position: relative;
}

.analysis-progress.is-active .analysis-progress__fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.45) 50%,
    transparent 100%
  );
  animation: analysis-progress-shimmer 1.6s ease-in-out infinite;
}

@keyframes analysis-progress-shimmer {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(120%); }
}

.btn-generar:disabled {
  opacity: 0.62;
  cursor: wait;
  transform: none;
}

.legend-bar span::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

.legend-size::before { background: var(--lab-blue); }
.legend-community::before { background: linear-gradient(90deg, #6CAED1, #10B981, #8B5CF6); }
.legend-edge::before { background: #94a3b8; height: 3px; border-radius: 2px; }

.community-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-top: 10px;
  padding: 10px 12px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid var(--lab-border);
}

.community-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--lab-text);
}

.community-legend .legend-title {
  display: block;
  width: 100%;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--lab-muted);
  font-weight: 700;
  margin-bottom: 4px;
}

.community-legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(30,41,59,0.2);
  font-style: normal;
}

.diffusion-controls {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.diffusion-controls button {
  padding: 6px 12px;
  border: 1px solid var(--lab-border);
  border-radius: 6px;
  background: #fff;
  font-size: 12px;
  cursor: pointer;
}

.interaction-hint {
  font-size: 12px;
  color: var(--lab-muted);
  margin-bottom: 10px;
  line-height: 1.5;
}

.selection-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
  min-height: 28px;
}

.chip {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: #e0f2fe;
  color: #0369a1;
}

.chip--danger {
  background: #fee2e2;
  color: #b91c1c;
}

.chip--gold {
  background: #fef3c7;
  color: #92400e;
}

.chip-muted {
  font-size: 11px;
  color: var(--lab-muted);
  font-style: italic;
}

.resilience-summary {
  font-size: 13px;
  margin-bottom: 10px;
  padding: 10px 12px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid var(--lab-border);
}

.impact-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  background: #fee2e2;
  color: #b91c1c;
  font-weight: 800;
}

.btn-clear-selection {
  margin-bottom: 12px;
  padding: 6px 14px;
  border: 1px solid var(--lab-border);
  border-radius: 8px;
  background: #fff;
  font-size: 12px;
  cursor: pointer;
  color: var(--lab-muted);
}

.btn-clear-selection:hover {
  border-color: #DC2626;
  color: #DC2626;
}

.ai-preview-overlay {
  position: relative;
}

.ai-preview-overlay::after {
  content: "Disponible en Pro";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.85);
  font-weight: 800;
  color: #8B5CF6;
  border-radius: 10px;
}
