/* ==========================================================================
   Estilos específicos de cada vista.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Encabezado de sección
   -------------------------------------------------------------------------- */
.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.section-head__title {
  font-size: var(--text-lg);
  font-weight: 660;
  letter-spacing: -0.03em;
}

.section-head__text {
  font-size: var(--text-sm);
  color: var(--text-muted);
  max-width: 62ch;
}

/* --------------------------------------------------------------------------
   Panel: tarjetas de métrica
   -------------------------------------------------------------------------- */
.kpi {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  background: var(--surface-1);
  overflow: hidden;
  transition: border-color var(--duration-base) var(--ease),
              transform var(--duration-base) var(--ease);
}

.kpi:hover {
  border-color: var(--border-default);
  transform: translateY(-2px);
}

/* Filo superior de color: identifica la métrica de un vistazo. */
.kpi::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--kpi-accent, var(--brand-gradient));
  opacity: 0.9;
}

.kpi__label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 620;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.kpi__label svg {
  width: 14px;
  height: 14px;
}

.kpi__value {
  font-size: var(--text-xl);
  font-weight: 680;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.kpi__meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.kpi--revenue    { --kpi-accent: linear-gradient(90deg, var(--success), var(--brand-3)); }
.kpi--pending    { --kpi-accent: linear-gradient(90deg, var(--warning), #f97316); }
.kpi--orders     { --kpi-accent: var(--brand-gradient); }
.kpi--stock      { --kpi-accent: linear-gradient(90deg, var(--brand-3), var(--status-shipped)); }

/* --------------------------------------------------------------------------
   Gráficos
   -------------------------------------------------------------------------- */
/* El SVG escala con el ancho manteniendo su proporción, para que el grosor de trazo
   y el tamaño de las etiquetas no se deformen. */
.chart {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart__area {
  fill: url(#chartGradient);
}

.chart__line {
  fill: none;
  stroke: var(--brand-1);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart__grid {
  stroke: var(--border-subtle);
  stroke-width: 1;
  stroke-dasharray: 3 5;
}

.chart__axis-label {
  fill: var(--text-muted);
  font-size: 10px;
  font-family: var(--font-mono);
}

.chart__dot {
  fill: var(--bg-base);
  stroke: var(--brand-1);
  stroke-width: 2;
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease);
}

.chart__hit {
  fill: transparent;
  cursor: crosshair;
}

.chart__hit:hover + .chart__dot,
.chart__hit:focus-visible + .chart__dot {
  opacity: 1;
}

.chart__empty {
  fill: var(--text-muted);
  font-size: 12px;
}

/* Distribución por estado */
.distribution {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.distribution__row {
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
}

.distribution__track {
  height: 7px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  overflow: hidden;
}

.distribution__fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--bar-color, var(--brand-1));
  transform-origin: left;
  animation: grow-x var(--duration-slow) var(--ease-out) backwards;
  animation-delay: calc(var(--i, 0) * 60ms);
}

@keyframes grow-x {
  from { transform: scaleX(0); }
}

.distribution__value {
  font-variant-numeric: tabular-nums;
  font-weight: 620;
  color: var(--text-secondary);
  min-width: 2ch;
  text-align: right;
}

/* Ranking de productos */
.rank {
  display: flex;
  flex-direction: column;
}

.rank__row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-subtle);
}

.rank__row:last-child {
  border-bottom: none;
}

.rank__pos {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border-radius: var(--radius-xs);
  background: var(--surface-3);
  font-size: var(--text-xs);
  font-weight: 680;
  color: var(--text-secondary);
}

.rank__row:first-child .rank__pos {
  background: var(--brand-gradient);
  color: #fff;
}

.rank__body {
  min-width: 0;
  flex: 1;
}

.rank__name {
  font-size: var(--text-sm);
  font-weight: 560;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rank__meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.rank__value {
  font-size: var(--text-sm);
  font-weight: 620;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Catálogo
   -------------------------------------------------------------------------- */
.product {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--surface-1);
  transition: border-color var(--duration-base) var(--ease),
              transform var(--duration-base) var(--ease),
              box-shadow var(--duration-base) var(--ease);
}

.product:hover {
  border-color: var(--border-default);
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.product__top {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}

/* Marca visual determinista: mismo SKU, mismo color, sin necesidad de imágenes. */
.product__glyph {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  background: linear-gradient(140deg,
    hsl(var(--glyph-hue, 250) 72% 58%),
    hsl(calc(var(--glyph-hue, 250) + 42) 76% 48%));
  color: #fff;
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 18px -10px hsl(var(--glyph-hue, 250) 72% 50%);
}

.product__name {
  font-size: var(--text-sm);
  font-weight: 620;
  letter-spacing: -0.01em;
}

.product__sku {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.product__desc {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.6em;
}

.product__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: auto;
  padding-top: var(--space-3);
  border-top: 1px solid var(--border-subtle);
}

.product__price {
  font-size: var(--text-md);
  font-weight: 680;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.product__actions {
  display: flex;
  gap: var(--space-2);
}

/* --------------------------------------------------------------------------
   Pedidos: raíl de ciclo de vida
   -------------------------------------------------------------------------- */
.lifecycle {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.lifecycle__step {
  position: relative;
  display: flex;
  gap: var(--space-3);
  padding-bottom: var(--space-4);
}

.lifecycle__step:last-child {
  padding-bottom: 0;
}

/* Línea que une los hitos. */
.lifecycle__step:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 24px;
  bottom: 0;
  width: 2px;
  background: var(--border-subtle);
}

.lifecycle__step[data-done="true"]:not(:last-child)::before {
  background: color-mix(in srgb, var(--step-color, var(--brand-1)) 55%, transparent);
}

.lifecycle__marker {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid var(--border-default);
  background: var(--surface-solid);
  color: var(--text-muted);
}

.lifecycle__marker svg {
  width: 12px;
  height: 12px;
}

.lifecycle__step[data-done="true"] .lifecycle__marker {
  border-color: var(--step-color, var(--brand-1));
  background: var(--step-color, var(--brand-1));
  color: #fff;
}

.lifecycle__step[data-current="true"] .lifecycle__marker {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--step-color, var(--brand-1)) 22%, transparent);
}

.lifecycle__label {
  font-size: var(--text-sm);
  font-weight: 560;
  color: var(--text-secondary);
}

.lifecycle__step[data-done="true"] .lifecycle__label {
  color: var(--text-primary);
  font-weight: 600;
}

.lifecycle__time {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Líneas del pedido */
.line-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--surface-1);
}

.line-item__body {
  min-width: 0;
  flex: 1;
}

.line-item__name {
  font-size: var(--text-sm);
  font-weight: 560;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.line-item__meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.line-item__total {
  font-size: var(--text-sm);
  font-weight: 640;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.totals {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--surface-2);
}

.totals__row {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.totals__row--grand {
  padding-top: var(--space-2);
  border-top: 1px dashed var(--border-default);
  font-size: var(--text-md);
  font-weight: 680;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.totals__row span:last-child {
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   Arquitectura
   -------------------------------------------------------------------------- */
.layer {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--surface-1);
  transition: border-color var(--duration-base) var(--ease),
              transform var(--duration-base) var(--ease);
}

.layer:hover {
  border-color: color-mix(in srgb, var(--layer-color, var(--brand-1)) 45%, transparent);
  transform: translateY(-3px);
}

.layer::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background: var(--layer-color, var(--brand-1));
}

.layer__index {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--layer-color, var(--brand-1));
}

.layer__name {
  font-size: var(--text-base);
  font-weight: 640;
  letter-spacing: -0.02em;
}

.layer__text {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  line-height: 1.55;
}

.layer__items {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: auto;
  padding-top: var(--space-3);
  border-top: 1px solid var(--border-subtle);
}

.layer__dep {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Consola de trazas de red */
.console {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: color-mix(in srgb, var(--bg-base) 60%, var(--surface-1));
  overflow: hidden;
}

.console__head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--surface-1);
}

.console__dots {
  display: flex;
  gap: 6px;
}

.console__dots i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border-strong);
}

.console__dots i:nth-child(1) { background: color-mix(in srgb, var(--danger) 65%, transparent); }
.console__dots i:nth-child(2) { background: color-mix(in srgb, var(--warning) 65%, transparent); }
.console__dots i:nth-child(3) { background: color-mix(in srgb, var(--success) 65%, transparent); }

.console__title {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.console__body {
  max-height: 340px;
  overflow-y: auto;
  padding: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.75;
}

.trace {
  display: grid;
  grid-template-columns: 62px 52px minmax(0, 1fr) auto;
  gap: var(--space-3);
  align-items: baseline;
  padding: 3px var(--space-3);
  border-radius: var(--radius-xs);
  animation: reveal var(--duration-base) var(--ease-out);
}

.trace:hover {
  background: var(--surface-2);
}

.trace__method {
  font-weight: 700;
  color: var(--text-secondary);
}

.trace__status {
  font-weight: 700;
  color: var(--status-color, var(--success));
}

.trace[data-ok="false"] {
  --status-color: var(--danger);
}

.trace__path {
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trace__time {
  color: var(--text-muted);
  text-align: right;
}

/* Máquina de estados */
.state-machine {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.state-node {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--surface-1);
}

.state-node__arrow {
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.state-node__terminal {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-style: italic;
}

/* Pasos del escenario guiado */
.sim-step {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--surface-1);
  animation: reveal var(--duration-base) var(--ease-out) backwards;
  animation-delay: calc(var(--i, 0) * 90ms);
}

.sim-step__num {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--brand-gradient);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: 700;
}

.sim-step__op {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 620;
  color: var(--text-primary);
}

.sim-step__text {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.sim-step__ms {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
}

@media (max-width: 620px) {
  .distribution__row {
    grid-template-columns: 100px minmax(0, 1fr) auto;
  }

  .trace {
    grid-template-columns: 52px 44px minmax(0, 1fr);
  }

  .trace__time {
    display: none;
  }
}
