/* ============ Base ============ */
:root {
  /* Paleta verde → azul (referencia #05F904 → #028B6A → #001EE2, ajustada a contraste AA) */
  --verde: #00753F;
  --verde-vivo: #05C853;
  --petroleo: #006774;
  --azul: #1238D6;
  --azul-vivo: #2E5BFF;
  --degradado: linear-gradient(100deg, var(--verde) 0%, var(--petroleo) 50%, var(--azul) 100%);
  --fondo: #EEF5F4;
  --fondo-2: #E3EAF6;
  --superficie: #FFFFFF;
  --texto: #171C26;
  --texto-2: #4E5768;
  --borde: #D9DCE2;
  --acento: #1238D6;
  --acento-txt: #FFFFFF;
  --sombra: 0 10px 30px rgba(20, 28, 45, .14), 0 2px 6px rgba(20, 28, 45, .08);
  --radio: 14px;
  --fuente: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --etq-max: 120px;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  font-family: var(--fuente);
  color: var(--texto);
  background: #EEF4F5;
  background:
    radial-gradient(70% 55% at 0% 100%, rgba(5, 200, 83, .10) 0%, transparent 70%),
    radial-gradient(70% 55% at 100% 0%, rgba(46, 91, 255, .10) 0%, transparent 70%),
    radial-gradient(120% 80% at 50% 40%, #FAFCFC 0%, var(--fondo) 55%, var(--fondo-2) 100%);
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh; overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
.saltar { position: absolute; left: -999px; top: 8px; z-index: 50; background: var(--superficie); padding: 8px 12px; border-radius: 8px; }
.saltar:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--azul); outline-offset: 2px; }

/* ============ Barra superior ============ */
.barra::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--degradado); }
.barra {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 16px 8px;
  position: relative; z-index: 5;
}
.marca { display: flex; align-items: center; gap: 10px; min-width: 0; }
.marca-icono {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: linear-gradient(145deg, var(--verde-vivo), var(--petroleo) 50%, var(--azul));
  box-shadow: inset 0 0 0 3px #CBD2DC;
}
.barra h1 { font-size: 1.05rem; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
.sub { margin: 1px 0 0; font-size: .74rem; color: var(--texto-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52vw; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid transparent;
  font-weight: 600; font-size: .9rem; white-space: nowrap;
  transition: transform .15s ease, background-color .15s ease;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 16px; height: 16px; fill: currentColor; }
.btn-primario { background: var(--azul); background-image: var(--degradado); color: var(--acento-txt); box-shadow: 0 4px 14px rgba(18, 56, 214, .22); }
.btn-sec { background: var(--superficie); border-color: var(--borde); color: var(--texto); }
.btn-sec:disabled { opacity: .45; cursor: default; }
.btn-texto { background: none; border: 0; color: var(--texto-2); font-size: .78rem; text-decoration: underline; padding: 10px 4px; min-height: 40px; }

/* ============ Escenario ============ */
.escenario { position: relative; flex: 1; min-height: 0; overflow: hidden; -webkit-user-select: none; user-select: none; }
#lienzo { position: absolute; top: 0; left: 0; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; -webkit-touch-callout: none; }
#lienzo:active { cursor: grabbing; }
.lineas { position: absolute; top: 0; left: 0; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.lineas line { stroke-width: 1.4; stroke-linecap: round; transition: opacity .2s; }
.lineas circle { transition: opacity .2s; }

.etiquetas { position: absolute; top: 0; left: 0; inset: 0; pointer-events: none; }
#etiquetas:not(.lista) { visibility: hidden; }
.etiqueta {
  --c: #333;
  position: absolute; left: 0; top: 0;
  pointer-events: auto;
  display: flex; align-items: center; gap: 6px;
  max-width: var(--etq-max);
  min-height: 32px; padding: 5px 9px 5px 7px;
  background: rgba(255,255,255,.94);
  border: 1px solid #D5D9E0;
  border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
  border-left: 4px solid var(--c);
  border-radius: 9px;
  box-shadow: 0 2px 8px rgba(20,28,45,.10);
  font-size: .72rem; font-weight: 600; line-height: 1.15; text-align: left;
  color: var(--texto);
  will-change: transform;
  transition: opacity .25s ease, box-shadow .15s ease;
}
.etiqueta::before { content: ""; width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--c); }
@media (hover: hover) { .etiqueta:hover { box-shadow: 0 4px 14px rgba(20,28,45,.18); } .btn-primario:hover { filter: brightness(1.08) saturate(1.05); } }
.etiqueta:active { transform-origin: center; filter: brightness(.96); }
.etiqueta.der { flex-direction: row; }
.etiqueta.izq { border-left-width: 1px; border-right: 4px solid var(--c); flex-direction: row-reverse; text-align: right; padding: 5px 7px 5px 9px; }
.etiqueta.oculta { opacity: 0; pointer-events: none; }
.etiqueta .num { display: none; }

.marcador {
  position: absolute; left: 0; top: 0; width: 26px; height: 26px; margin: -13px 0 0 -13px;
  border-radius: 50%; border: 3px solid var(--c, #1238D6); pointer-events: none; opacity: 0;
  transition: opacity .3s;
}
.marcador.activo { opacity: 1; animation: pulso 1.6s ease-out infinite; }
@keyframes pulso {
  0% { box-shadow: 0 0 0 0 rgba(18, 56, 214, .45); box-shadow: 0 0 0 0 color-mix(in srgb, var(--c, #1238D6) 55%, transparent); }
  100% { box-shadow: 0 0 0 16px transparent; }
}

/* Carga */
.cargando { position: absolute; top: 0; right: 0; bottom: 0; left: 0; display: grid; place-content: center; justify-items: center; gap: 14px; color: var(--texto-2); font-size: .9rem; transition: opacity .35s; }
.cargando.fuera { opacity: 0; pointer-events: none; }
.cargando-tel { width: 64px; height: 128px; border-radius: 14px; background: linear-gradient(110deg, #E2E5EA 30%, #F4F5F7 50%, #E2E5EA 70%); background-size: 200% 100%; animation: brillo 1.2s linear infinite; box-shadow: inset 0 0 0 4px #D3D7DE; }
@keyframes brillo { to { background-position: -200% 0; } }

/* ============ Pie ============ */
.pie { position: relative; z-index: 5; padding: 4px 0 max(6px, env(safe-area-inset-bottom)); }
.leyenda {
  display: flex; gap: 6px; overflow-x: auto; padding: 4px 16px; scrollbar-width: none;
  -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; scroll-snap-type: x proximity;
  /* desvanecido en los bordes: indica que la fila se puede deslizar */
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 28px), transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 28px), transparent 100%);
}
.chip { scroll-snap-align: start; }
.leyenda::-webkit-scrollbar { display: none; }
.chip {
  --c: #333;
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--borde); background: var(--superficie);
  font-size: .78rem; font-weight: 600; color: var(--texto);
}
.chip::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.chip[aria-pressed="true"] { background: var(--c); color: #fff; border-color: var(--c); }
.chip[aria-pressed="true"]::before { background: #fff; }
.pie-fila { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 0 16px; }
.pista { margin: 0; font-size: .74rem; color: var(--texto-2); }

/* ============ Popup ============ */
.fondo-popup { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 20; background: rgba(15, 20, 30, .18); }
.popup {
  --c: #1238D6;
  position: fixed; z-index: 21; left: 0; right: 0; bottom: 0;
  max-height: 66vh; max-height: 66dvh; display: flex;
  transition: transform .2s ease; flex-direction: column;
  background: var(--superficie); border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 30px rgba(20,28,45,.18);
  border-top: 5px solid var(--c);
  padding-bottom: env(safe-area-inset-bottom);
  animation: subir .28s cubic-bezier(.2,.8,.2,1);
}
@keyframes subir { from { transform: translateY(30px); opacity: 0; } }
.pp-agarre { width: 40px; height: 4px; border-radius: 4px; background: #CDD1D8; margin: 8px auto 0; box-shadow: 0 0 0 10px transparent; }
.pp-cabeza, .pp-agarre { touch-action: none; }
.pp-cabeza { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 8px 16px 6px; }
.pp-cat { display: inline-block; font-size: .7rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--c); }
.popup h2 { margin: 2px 0 0; font-size: 1.12rem; line-height: 1.25; letter-spacing: -.01em; }
.pp-cerrar { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--borde); background: #F4F5F7; display: grid; place-items: center; }
.pp-cerrar svg { width: 18px; height: 18px; stroke: var(--texto); stroke-width: 2.4; stroke-linecap: round; fill: none; }
.pp-cuerpo { overflow-y: auto; -webkit-overflow-scrolling: touch; -webkit-user-select: text; user-select: text; padding: 0 16px 14px; overscroll-behavior: contain; }
.pp-cuerpo h3 { margin: 8px 0 2px; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--texto-2); }
.pp-cuerpo p { margin: 0; font-size: .92rem; line-height: 1.38; }
.gamas { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 5px; }
.gamas li { display: grid; grid-template-columns: 74px 1fr; align-items: center; gap: 8px; font-size: .86rem; line-height: 1.3; }
.gamas .g-et { display: flex; align-items: center; gap: 5px; font-weight: 700; font-size: .74rem; color: var(--texto-2); }
.gamas .barras { display: inline-flex; gap: 2px; }
.gamas .barras i { width: 5px; height: 12px; border-radius: 2px; background: #D8DCE3; }
.gamas .barras i.on { background: var(--c); }
.frase { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: #F3F5F9; border: 1px solid #DCE1E8; background: color-mix(in srgb, var(--c) 9%, #fff); border: 1px solid color-mix(in srgb, var(--c) 25%, transparent); }
.frase-et { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--c); }
.frase p { margin-top: 3px !important; font-weight: 600; font-style: italic; }
.pp-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 16px 12px; border-top: 1px solid #ECEEF1; }
.pp-paso { font-size: .8rem; color: var(--texto-2); font-weight: 600; }

/* ============ Vista 2D ============ */
.vista2d { position: absolute; top: 0; right: 0; bottom: 0; left: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; overscroll-behavior: contain; -webkit-user-select: none; user-select: none; padding: 8px 12px 16px; }
.v2-telefonos { display: flex; justify-content: center; align-items: flex-start; gap: 18px; padding: 6px 0 10px; }
.v2-tel { position: relative; width: 112px; transition: transform .45s cubic-bezier(.2,.8,.2,1); }
.v2-tel svg { width: 100%; height: auto; display: block; overflow: visible; }
.v2-tel figcaption { text-align: center; font-size: .7rem; color: var(--texto-2); margin-top: 4px; }
.v2-punto { position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%; border: 3px solid var(--c); opacity: 0; pointer-events: none; }
.v2-punto.activo { opacity: 1; animation: pulso 1.6s ease-out infinite; }
.v2-lista { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; max-width: 560px; margin: 0 auto; }
.vista2d .etiqueta { position: relative; transform: none !important; max-width: none; width: 100%; min-height: 40px; font-size: .8rem; }
.vista2d .etiqueta.izq { border-right-width: 1px; border-left-width: 4px; flex-direction: row; text-align: left; padding: 5px 9px 5px 7px; }
.vista2d .etiqueta.oculta { display: none; }
.v2-grupo { grid-column: 1 / -1; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; margin: 6px 0 0; }

body.modo-2d #lienzo, body.modo-2d .lineas, body.modo-2d .marcador, body.modo-2d #etiquetas { display: none; }

.aviso { position: absolute; left: 12px; right: 12px; top: 12px; z-index: 6; background: #FFF6E5; border: 1px solid #F0D49B; color: #5B4210; padding: 10px 12px; border-radius: 10px; font-size: .82rem; }

/* ============ Pantallas angostas ============ */
@media (max-width: 420px) {
  .barra { padding-left: 12px; padding-right: 12px; }
  .barra h1 { font-size: .98rem; }
  .sub { max-width: 46vw; font-size: .7rem; }
  .marca-icono { width: 26px; height: 26px; }
  #btn-recorrido { padding: 0 12px; font-size: .84rem; }
  #btn-recorrido .largo { display: none; }
}
@media (min-width: 421px) { #btn-recorrido .corto { display: none; } }

/* ============ Escritorio ============ */
/* Celular en horizontal: barra compacta y popup lateral */
@media (orientation: landscape) and (max-height: 520px) and (min-width: 560px) {
  .barra { padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: 2px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .sub { display: none; }
  .btn { min-height: 38px; }
  .pista { display: none; }
  .pie { display: flex; align-items: center; gap: 6px; padding-bottom: max(2px, env(safe-area-inset-bottom)); padding-right: max(12px, env(safe-area-inset-right)); }
  .leyenda { flex: 1; min-width: 0; padding-left: max(16px, env(safe-area-inset-left)); }
  .pie-fila { flex: none; padding: 0; }
  .chip { min-height: 32px; }
  .popup {
    left: auto; top: max(8px, env(safe-area-inset-top)); bottom: max(8px, env(safe-area-inset-bottom)); right: max(8px, env(safe-area-inset-right));
    width: min(380px, 50vw); max-height: none; border-radius: 16px; border-top: 0; border-left: 6px solid var(--c);
    animation-name: entrar;
  }
  .pp-agarre { display: none; }
  .fondo-popup { background: transparent; }
  .v2-telefonos { gap: 18px; }
  .v2-tel { width: 90px; }
  .v2-lista { grid-template-columns: repeat(3, 1fr); }
}
@keyframes entrar { from { transform: translateX(24px); opacity: 0; } }

@media (min-width: 900px) {
  .barra { padding: 16px 28px 8px; }
  .barra h1 { font-size: 1.3rem; }
  .sub { font-size: .85rem; max-width: none; }
  .etiqueta { font-size: .86rem; min-height: 36px; padding: 6px 12px 6px 9px; }
  .etiqueta.izq { padding: 6px 9px 6px 12px; }
  .popup {
    left: auto; right: 24px; top: 88px; bottom: auto; width: 400px; max-height: calc(100dvh - 120px);
    border-radius: 18px; border-top: 0; border-left: 6px solid var(--c);
    box-shadow: var(--sombra); animation-name: entrar;
  }
  .pp-agarre { display: none; }
  .pp-cabeza { padding-top: 16px; }
  .fondo-popup { background: transparent; }
  .leyenda { justify-content: center; -webkit-mask-image: none; mask-image: none; flex-wrap: wrap; }
  .pie-fila { justify-content: center; gap: 24px; }
  .v2-telefonos { gap: 40px; }
  .v2-tel { width: 170px; }
  .v2-lista { grid-template-columns: repeat(3, 1fr); max-width: 820px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
.sin-js { padding: 20px; text-align: center; }
