/* ============================================================
   Neural Frontier — layers.css
   Estilos para el contenido de capas: estados, gráficos, badges
   ============================================================ */

/* ========== Estados de capa ========== */
.layer-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px 12px;
  flex-direction: column;
}

.layer-state[hidden] { display: none; }

/* Loading */
.layer-loading {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

/* Spinner kept for legacy sections (news, geo map loading) */
.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Skeleton row — used inside layer panels */
.lp-skeleton {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0;
}
.lp-sk-line {
  height: 13px;
  border-radius: var(--r-xs);
  background: linear-gradient(90deg, var(--border) 25%, var(--border-subtle) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s infinite;
}
.lp-sk-line--short { width: 40%; }
.lp-sk-line--med   { width: 65%; }
.lp-sk-block {
  height: 120px;
  border-radius: var(--r-md);
  background: linear-gradient(90deg, var(--border) 25%, var(--border-subtle) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s infinite;
}

/* Error */
.layer-error {
  color: var(--c-neg);
  font-size: 0.84rem;
  text-align: center;
}

.layer-error span {
  font-size: 1.4rem;
}

/* Empty */
.layer-empty {
  color: var(--text-muted);
}

/* Signal dot — replaces colored emoji circles */
.signal-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  vertical-align: middle;
  margin-right: 4px;
}

/* ========== Badge de métrica ========== */
.metric-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: var(--r-sm);
  font-size: 0.78rem;
  font-weight: var(--fw-bold);
  flex-shrink: 0;
  margin-left: auto;
  letter-spacing: 0.01em;
}

.metric-badge--neutral {
  background-color: var(--border);
  color: var(--text-muted);
}

.metric-badge--colored {
  background-color: color-mix(in srgb, var(--badge-color) 15%, transparent);
  color: var(--badge-color);
  border: 1px solid color-mix(in srgb, var(--badge-color) 30%, transparent);
}

/* Fallback para navegadores sin color-mix */
@supports not (color: color-mix(in srgb, red 15%, transparent)) {
  .metric-badge--colored {
    background-color: rgba(99, 102, 241, 0.12);
    color: var(--badge-color);
  }
}

/* ========== Contenedor de gráficos ========== */
.layer-charts {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-top: 12px;
}

.layer-charts[hidden] { display: none; }

/* ========== Chart section ========== */
.chart-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chart-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chart-section-title {
  font-size: 0.82rem;
  font-weight: var(--fw-semibold);
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

.chart-wrap {
  position: relative;
  height: 180px;
  width: 100%;
}

.chart-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}

/* ========== Layer 6 — grid de valoración ========== */
.val-charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding-top: 12px;
}

/* ROE ocupa el ancho completo */
.chart-section--full {
  grid-column: 1 / -1;
}

/* ========== Botón de búsqueda — estado loading ========== */
.search-btn.loading {
  pointer-events: none;
  opacity: 0.7;
}

.search-btn.loading svg {
  animation: spin 0.8s linear infinite;
}

/* ========== Vista toggle (tabla/gráfico) ========== */
.view-toggle {
  display: flex;
  gap: 6px;
  padding: 12px 0 10px;
}

.view-btn {
  padding: 5px 14px;
  font-size: 0.8rem;
  font-weight: var(--fw-semibold);
  font-family: var(--font-family);
  border-radius: var(--radius-sm);
  background-color: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color var(--transition), color var(--transition), border-color var(--transition);
}

.view-btn.active {
  background-color: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

/* ========== Tabla de riesgo Markowitz ========== */
.risk-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin-top: 4px;
}

.risk-table thead th {
  text-align: left;
  padding: 8px 10px;
  font-size: 0.74rem;
  font-weight: var(--fw-bold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

.risk-table tbody td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-subtle);
  font-variant-numeric: tabular-nums;
}

.risk-table tbody tr:last-child td {
  border-bottom: none;
}

.risk-table .interval-label {
  color: var(--text-secondary);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
}

/* ========== Sección blocks en Capa 3 ========== */
.section-block {
  padding: 12px 0 8px;
  border-top: 1px solid var(--border-subtle);
}

.section-block:first-child {
  border-top: none;
  padding-top: 0;
}

.section-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
  font-weight: var(--fw-bold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

.section-note {
  font-size: 0.72rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
}

/* ========== Grid de gauges Beta ========== */
.gauges-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

/* Usar subgrid o auto-layout para 4+3 */
.gauges-grid > .beta-gauge-wrap:nth-child(5) {
  grid-column: 1;
}

.beta-gauge-wrap {
  min-width: 0;
}

.beta-gauge-svg {
  width: 100%;
  height: auto;
  overflow: visible;
}

/* Fullscreen: una sola fila de 7, gauges más compactos */
.lp-body .gauges-grid {
  grid-template-columns: repeat(7, 1fr);
  gap: 24px;
}
.lp-body .gauges-grid > .beta-gauge-wrap:nth-child(5) {
  grid-column: auto;
}

/* ========== Tracking Error grid ========== */
.te-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.te-item {
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.te-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: var(--fw-semibold);
}

.te-value {
  font-size: 1rem;
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
}

.te-sublabel {
  font-size: 0.68rem;
  font-weight: var(--fw-medium);
}

/* ========== N-Selector ========== */
.n-selector {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.n-btn {
  padding: 3px 10px;
  font-size: 0.74rem;
  font-weight: var(--fw-semibold);
  font-family: var(--font-family);
  border-radius: 5px;
  border: 1px solid var(--border);
  background-color: var(--bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color 150ms, color 150ms, border-color 150ms;
}

.n-btn.active {
  background-color: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

/* ========== Scatter grid ========== */
.scatter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.scatter-label {
  font-size: 0.78rem;
  font-weight: var(--fw-semibold);
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-align: center;
}

/* ========== ISG Gauge ========== */
.isg-gauge-row {
  display: flex;
  justify-content: center;
  padding: 8px 0 4px;
}

.isg-gauge-wrap {
  max-width: 320px;
  width: 100%;
}

.isg-gauge-svg {
  width: 100%;
  height: auto;
  overflow: visible;
}

.isg-ted-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin: 8px 0;
}

.isg-ted-note[hidden] { display: none; }

/* ========== ISG Componentes ========== */
.isg-components {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 4px;
}

.isg-comp-row {
  display: grid;
  grid-template-columns: 90px 1fr 60px 70px;
  align-items: center;
  gap: 10px;
}

.isg-comp-label {
  font-size: 0.78rem;
  font-weight: var(--fw-semibold);
  color: var(--text-secondary);
  white-space: nowrap;
}

.isg-comp-bar-wrap {
  background-color: var(--bg);
  border-radius: var(--r-xs);
  height: 8px;
  overflow: hidden;
}

.isg-comp-bar {
  height: 100%;
  border-radius: var(--r-xs);
  transition: width 400ms ease;
  min-width: 4px;
}

.isg-comp-z {
  font-size: 0.75rem;
  font-weight: var(--fw-semibold);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.isg-comp-val {
  font-size: 0.78rem;
  font-weight: var(--fw-bold);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ========== Accordion card expandida — altura dinámica ========== */
.layer-card .card-accordion {
  max-height: 0;
  overflow: hidden;
  transition: max-height 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Override de cards.css — transición para rich layers */
.layer-card[data-layer="1"] .card-accordion,
.layer-card[data-layer="2"] .card-accordion,
.layer-card[data-layer="3"] .card-accordion,
.layer-card[data-layer="4"] .card-accordion,
.layer-card[data-layer="5"] .card-accordion,
.layer-card[data-layer="6"] .card-accordion {
  transition: max-height 600ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========== Separador accordion ========== */
.accordion-content {
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
  margin-top: 4px;
}

/* ========== Fullscreen panel — charts grid ========== */
.lp-body .layer-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
}

/* Last chart spans full width if there's an odd number */
.lp-body .layer-charts .chart-section:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.lp-body .chart-wrap {
  height: 300px;
}

/* ISG: the two data charts side by side, gauge and components full-width */
.lp-body #isg-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
}
.lp-body #isg-gauge-wrap,
.lp-body #isg-components,
.lp-body .isg-data-note {
  grid-column: 1 / -1;
}

/* val-charts-grid already has its own 2-col grid; preserve it */
.lp-body .val-charts-grid {
  grid-template-columns: 1fr 1fr;
  gap: 28px;
}

/* ========== Responsive ========== */
@media (max-width: 900px) {
  .val-charts-grid {
    grid-template-columns: 1fr;
  }
  .chart-section--full {
    grid-column: auto;
  }
  .lp-body .layer-charts,
  .lp-body #isg-charts,
  .lp-body .val-charts-grid {
    grid-template-columns: 1fr;
  }
  .lp-body .layer-charts .chart-section:last-child:nth-child(odd),
  .lp-body #isg-gauge-wrap,
  .lp-body #isg-components,
  .lp-body .isg-data-note {
    grid-column: auto;
  }
}

@media (max-width: 768px) {
  .chart-wrap {
    height: 160px;
  }
  .lp-body .chart-wrap {
    height: 220px;
  }
}

/* ============================================================
   Capa 4 — RAE / RDA
   ============================================================ */

.rae-selector-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.rae-selector-label {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.rae-event-select {
  flex: 1;
  min-width: 220px;
  padding: 6px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-primary);
  font-size: 12px;
  font-family: 'Syne', sans-serif;
  cursor: pointer;
  outline: none;
}

.rae-event-select:focus {
  border-color: var(--accent);
}

.rae-info-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.rae-info-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rae-info-signal {
  grid-column: span 2;
}

@media (max-width: 500px) {
  .rae-info-signal { grid-column: span 1; }
}

.rae-info-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.rae-info-value {
  font-size: 13px;
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
}

.rae-info-value.rae-mono {
  font-size: 16px;
  font-weight: var(--fw-bold);
  letter-spacing: -0.02em;
}

.rae-no-window {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px;
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
}

.rae-no-window span { font-size: 28px; }

.rae-history-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 8px;
}

@media (max-width: 500px) {
  .rae-history-grid { grid-template-columns: 1fr; }
}

.rae-hist-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color 0.15s;
}

.rae-hist-card:hover { border-color: var(--accent); }

.rae-hist-type { font-size: 18px; flex-shrink: 0; }

.rae-hist-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.rae-hist-date {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rae-hist-surprise {
  font-size: 10px;
  font-weight: var(--fw-semibold);
}

.rae-hist-val {
  font-size: 11px;
  font-weight: var(--fw-bold);
  white-space: nowrap;
  text-align: right;
}
