/* La Escuadra · Ferreterías del Bajío (marca ficticia) */
:root {
  --fondo: #0B0D10;
  --superficie: #12151A;
  --superficie-2: #1A1E25;
  --borde: rgba(255, 255, 255, .07);
  --acento: #FB923C;
  --acento-texto: #1A0D02;
  --acento-2: #38BDF8;
  --c1: #FB923C;
  --c2: #38BDF8;
  --c3: #A3E635;
  --c4: #C084FC;
  --c5: #FACC15;
  --sube: #4ADE80;
  --baja: #F87171;
}

.envoltura { max-width: 1360px; margin: 0 auto; padding: 24px 32px 0; display: grid; gap: 18px; }

/* Encabezado */
.encabezado { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px 24px; flex-wrap: wrap; padding-top: 4px; }
.titulo { display: grid; gap: 8px; }
.marca { display: flex; align-items: center; gap: 9px; font-size: 13.5px; }
.marca span:last-child { color: var(--suave); }
.marca-logo { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--acento); color: var(--acento-texto); box-shadow: 0 6px 18px -6px var(--acento); }
.titulo h1 { font-size: clamp(26px, 3vw, 34px); font-weight: 600; }
.controles { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.segmento { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--superficie); border: 1px solid var(--borde); }
.segmento button { height: 32px; padding: 0 13px; border: 0; border-radius: 7px; background: transparent; color: var(--suave); font-size: 13.5px; font-weight: 500; white-space: nowrap; transition: background .2s, color .2s; }
.segmento button:hover { color: var(--texto); }
.segmento button[aria-checked="true"] { background: var(--superficie-2); color: var(--texto); box-shadow: 0 1px 0 rgba(255, 255, 255, .06) inset, 0 2px 8px rgba(0, 0, 0, .35); }
.selector { width: auto; height: 40px; appearance: none; padding-right: 36px; background-color: var(--superficie); background-image: linear-gradient(45deg, transparent 50%, var(--suave) 50%), linear-gradient(135deg, var(--suave) 50%, transparent 50%); background-position: calc(100% - 19px) 50%, calc(100% - 14px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.vivo { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--borde); background: var(--superficie); color: var(--suave); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; transition: border-color .2s, color .2s; }
.vivo:hover { color: var(--texto); border-color: color-mix(in srgb, var(--texto) 18%, transparent); }
.vivo-punto { width: 7px; height: 7px; border-radius: 50%; background: var(--sube); box-shadow: 0 0 0 0 color-mix(in srgb, var(--sube) 60%, transparent); animation: pulso-vivo 2s ease-out infinite; }
.vivo.cargando .vivo-punto { background: var(--acento); }
.vivo.cargando .vivo-icono { animation: qa-girar .8s linear infinite; }
@keyframes pulso-vivo { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--sube) 55%, transparent); } 100% { box-shadow: 0 0 0 8px transparent; } }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi { padding: 16px 18px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; inset: 0 0 auto; height: 1px; background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--acento) 50%, transparent), transparent); opacity: .6; }
.kpi-cabeza { display: flex; align-items: center; gap: 8px; }
.kpi-icono { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; flex: none; color: var(--acento); background: color-mix(in srgb, var(--acento) 12%, transparent); }
.kpi-valor { font-size: 30px; font-weight: 600; letter-spacing: -.035em; line-height: 1.15; justify-self: start; white-space: nowrap; }
.kpi-valor.sk { border-radius: 8px; }
.kpi-pie { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; min-height: 32px; }
.kpi-var { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 12.5px; color: var(--tenue); min-width: 0; }
.kpi-var.sk { width: 130px; height: 20px; }
.kpi-chispa { flex: none; }
.chispa path { fill: none; stroke: var(--acento); stroke-width: 1.6; stroke-linejoin: round; opacity: .85; stroke-dasharray: 400; stroke-dashoffset: 400; animation: trazar 1.2s var(--ease) .2s forwards; }
@keyframes trazar { to { stroke-dashoffset: 0; } }
.variacion { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 7px; border-radius: 6px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.variacion.sube { color: var(--sube); background: color-mix(in srgb, var(--sube) 12%, transparent); }
.variacion.baja { color: var(--baja); background: color-mix(in srgb, var(--baja) 12%, transparent); }
.variacion .icono { width: 13px; height: 13px; }
.invertido { transform: scaleY(-1); }

/* Rejilla de tarjetas */
.rejilla { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.t-linea { grid-column: span 2; }
.t-calor { grid-column: span 2; }
.t-productos { grid-column: 1 / -1; }
.panel { padding: 18px 18px 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-content: start; min-width: 0; }
.panel-cabeza { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.panel-cabeza h2 { font-size: 15px; font-weight: 600; letter-spacing: -.015em; }
.panel-sub { font-size: 12.5px; color: var(--suave); margin-top: 3px; min-height: 18px; }
.cuerpo-grafica { min-width: 0; position: relative; }
.leyenda-linea { display: flex; gap: 14px; font-size: 12px; color: var(--suave); }
.leyenda-linea span { display: inline-flex; align-items: center; gap: 6px; }
.leyenda-linea span::before { content: ""; width: 14px; height: 0; border-top: 2px solid var(--acento); }
.leyenda-linea .ll-previo::before { border-top: 2px dashed var(--tenue); }

/* Elementos SVG */
.grafica { display: block; overflow: visible; touch-action: pan-y; }
line.rejilla { stroke: rgba(255, 255, 255, .06); stroke-width: 1; }
line.rejilla.base { stroke: rgba(255, 255, 255, .14); }
.eje { fill: var(--tenue); font-size: 11px; font-family: var(--mono); }
.linea { fill: none; stroke: var(--acento); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.linea-previa { fill: none; stroke: var(--tenue); stroke-width: 1.5; stroke-dasharray: 4 4; opacity: .8; }
.grafica.animada .area { animation: qa-aparecer .9s ease .4s both; }
.grafica.animada .linea-previa { animation: qa-aparecer .6s ease .1s both; }
.guia { stroke: rgba(255, 255, 255, .25); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0; transition: opacity .15s; }
.punto-guia { fill: var(--fondo); stroke: var(--acento); stroke-width: 2.5; opacity: 0; transition: opacity .15s; }
.grafica.con-guia .guia, .grafica.con-guia .punto-guia { opacity: 1; }

.barra { fill: var(--acento); transform-box: fill-box; transform-origin: 50% 100%; transition: fill-opacity .2s, filter .2s; }
.grafica.animada .barra { animation: crecer .8s var(--ease) both; }
@keyframes crecer { from { transform: scaleY(0); } to { transform: none; } }
.barra-grupo { cursor: pointer; outline: none; }
.barra-grupo:hover .barra, .barra-grupo:focus-visible .barra { filter: brightness(1.15); }
.barra-grupo:focus-visible .barra { stroke: #fff; stroke-width: 2; }
.barra-grupo.atenuada .barra { fill: var(--superficie-2); stroke: rgba(255, 255, 255, .08); }
.barra-grupo.atenuada .valor-barra { fill: var(--tenue); }
.valor-barra { fill: var(--texto); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.grafica.animada .valor-barra { animation: qa-aparecer .4s ease both; }
.nombre-barra { fill: var(--suave); font-size: 12.5px; }
.var-barra { font-size: 11.5px; font-weight: 600; font-family: var(--mono); }
.var-barra.sube { fill: var(--sube); }
.var-barra.baja { fill: var(--baja); }

.dona-caja { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; justify-content: center; }
.dona { flex: none; }
.dona-fondo { fill: none; stroke: var(--superficie-2); }
.tramo { fill: none; cursor: pointer; transition: stroke-width .2s var(--ease), opacity .2s; }
.dona .tramo { stroke-linecap: butt; }
.dona.enfocada .tramo:not(.activo) { opacity: .35; }
.dona .tramo.activo { stroke-width: 30; }
.dona-valor { fill: var(--texto); font-size: 22px; font-weight: 600; letter-spacing: -.03em; }
.dona-etq { fill: var(--suave); font-size: 11.5px; }
.leyenda { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; flex: 1; min-width: 180px; }
.leyenda li { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto auto; align-items: center; gap: 8px; font-size: 13px; }
.leyenda-punto { width: 9px; height: 9px; border-radius: 3px; flex: none; display: inline-block; }
.leyenda-nombre { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leyenda-pct { color: var(--suave); font-size: 12px; }
.leyenda-valor { font-weight: 600; min-width: 62px; text-align: right; }

.celda { fill: var(--acento); transition: stroke .15s; cursor: pointer; }
.celda:hover { stroke: #fff; stroke-width: 1.5; }
.celda.cerrado { fill: var(--superficie-2); cursor: default; }
.grafica.animada .celda { animation: celda-entra .45s var(--ease) both; }
@keyframes celda-entra { from { opacity: 0; } to { opacity: 1; } }
.calor-leyenda { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--tenue); margin-top: 12px; flex-wrap: wrap; }
.calor-escala { width: 90px; height: 8px; border-radius: 99px; background: linear-gradient(90deg, color-mix(in srgb, var(--acento) 12%, transparent), var(--acento)); }
.cerrado-muestra { width: 12px; height: 8px; border-radius: 3px; background: var(--superficie-2); margin-left: 8px; }

.sk-barras { height: 250px; display: flex; align-items: flex-end; justify-content: space-around; padding: 26px 8% 50px; gap: 10%; }
.sk-barras .sk { flex: 1; border-radius: 7px; }

/* Tabla de productos */
.tabla-scroll { overflow-x: auto; margin: 0 -18px -16px; }
.tabla { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 720px; }
.tabla th { text-align: left; font-weight: 500; font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; font-family: var(--mono); color: var(--tenue); padding: 10px 18px; border-bottom: 1px solid var(--borde); white-space: nowrap; }
.tabla td { padding: 11px 18px; border-bottom: 1px solid var(--borde); white-space: nowrap; }
.tabla tbody tr:last-child td { border-bottom: 0; }
.tabla tbody tr { transition: background .15s; }
.tabla tbody tr:hover { background: rgba(255, 255, 255, .025); }
.tabla .der { text-align: right; }
.tabla .rango { color: var(--tenue); font-size: 12px; width: 40px; }
.tabla .fuerte { font-weight: 600; }
.producto { display: grid; }
.producto strong { font-weight: 500; }
.producto span { font-size: 11.5px; color: var(--tenue); }
.cat { display: inline-flex; align-items: center; gap: 7px; color: var(--suave); }
.progreso { width: 160px; height: 6px; border-radius: 99px; background: var(--superficie-2); overflow: hidden; }
.progreso span { display: block; height: 100%; width: var(--w); border-radius: inherit; background: var(--c); animation: llenar .9s var(--ease) both; }
@keyframes llenar { from { width: 0; } }

/* Tooltip */
.tip {
  position: fixed; left: 0; top: 0; z-index: 1200; pointer-events: none; min-width: 180px; max-width: 260px;
  padding: 10px 12px; border-radius: 10px; background: rgba(20, 24, 31, .96); border: 1px solid rgba(255, 255, 255, .1);
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, .7); font-size: 12.5px; color: var(--texto);
  opacity: 0; transition: opacity .12s; backdrop-filter: blur(8px);
}
.tip.visible { opacity: 1; }
.tip-titulo { font-weight: 600; margin-bottom: 6px; }
.tip-titulo::first-letter { text-transform: uppercase; }
.tip-fila { display: grid; grid-template-columns: 8px 1fr auto; align-items: center; gap: 8px; padding: 2px 0; color: var(--suave); }
.tip-fila strong { color: var(--texto); font-weight: 600; }
.tip-punto { width: 8px; height: 8px; border-radius: 2px; }
.tip-pie { margin-top: 6px; padding-top: 6px; border-top: 1px solid rgba(255, 255, 255, .08); color: var(--tenue); font-size: 11.5px; }

/* Responsive */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rejilla { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .t-linea, .t-calor { grid-column: 1 / -1; }
}
@media (max-width: 700px) {
  .envoltura { padding: 18px 16px 0; gap: 14px; }
  .rejilla { grid-template-columns: minmax(0, 1fr); }
  .controles { width: 100%; }
  .segmento { flex: 1 1 100%; }
  .segmento button { flex: 1; }
  .selector { flex: 1 1 0; min-width: 0; }
  .kpi { padding: 14px; }
  .kpi-valor { font-size: 21px; }
  .kpi-chispa { display: none; }
  .kpi-var .vs { display: none; }
  .panel { padding: 16px 14px 14px; }
  .tabla-scroll { margin: 0 -14px -14px; }
  .leyenda { min-width: 0; width: 100%; flex: none; }
  .dona-caja { flex-direction: column; }
  .selector, .vivo { flex: 1 1 100%; }
  .vivo { justify-content: center; }
}
