/* ==========================================================================
   FTTH Field Diag - Estilos Técnicos Industriales & Animaciones SVG
   Mobile-First (360px+), Modo Oscuro de Alto Contraste, Accesible (WCAG)
   ========================================================================== */

:root {
  color-scheme: dark;
  --bg-deep: #020617;
  --bg-panel: #0f172a;
  --bg-elevated: #1e293b;
  --border-subtle: #334155;
  --accent-cyan: #22d3ee;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;
  --target-min: 44px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background-color: var(--bg-deep);
  color: #f8fafc;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  scroll-padding-bottom: calc(9.5rem + env(safe-area-inset-bottom, 0px));
  -webkit-tap-highlight-color: rgba(34, 211, 238, 0.2);
}

body {
  margin: 0;
  min-height: 100dvh;
  background-color: var(--bg-deep);
  background-image: radial-gradient(circle at 50% 0%, rgba(14, 165, 233, 0.08), transparent 55%);
  overflow-wrap: break-word;
}

h1, h2, h3 {
  text-wrap: balance;
}

p, li {
  text-wrap: pretty;
}

/* Garantizar objetivos táctiles cómodos (>= 44x44px) en toda la app */
:where(button, [role="button"], select, input:not([type="checkbox"], [type="radio"])) {
  min-block-size: var(--target-min);
  min-inline-size: var(--target-min);
}

/* Evitar que elementos flex impidan encogerse en 360px */
.flex-shrink-safe {
  min-inline-size: 0;
}

/* Garantiza ocultamiento determinista sin colisiones con flex/inline-flex */
.hidden,
[hidden] {
  display: none !important;
}

/* Safe-area padding para móviles con notch o barra de gestos */
.safe-top {
  padding-top: max(0.5rem, env(safe-area-inset-top, 0px));
}

.safe-bottom {
  padding-bottom: max(0.5rem, env(safe-area-inset-bottom, 0px));
  padding-left: max(0.5rem, env(safe-area-inset-left, 0px));
  padding-right: max(0.5rem, env(safe-area-inset-right, 0px));
}

/* ==========================================================================
   Visor SVG y Animaciones Técnicas (LEDs, VFL, Hotspots)
   ========================================================================== */

.ftth-svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 310px;
  border-radius: 0.75rem;
  user-select: none;
  touch-action: manipulation;
}

.svg-hotspot {
  cursor: pointer;
  outline: none;
}

.svg-hotspot:focus-visible circle:nth-of-type(3) {
  stroke: #ffffff;
  stroke-width: 3;
}

.svg-hotspot.is-selected circle:nth-of-type(3) {
  stroke: #22d3ee;
  stroke-width: 2.6;
}

.hotspot-pulse {
  transform-box: fill-box;
  transform-origin: center;
  animation: hotspotPulse 2.4s ease-in-out infinite;
}

@keyframes hotspotPulse {
  0%, 100% {
    opacity: 0.25;
    transform: scale(0.95);
  }
  50% {
    opacity: 0.75;
    transform: scale(1.12);
  }
}

/* Parpadeo LED PON (sincronizando / falla) */
.led-blink {
  animation: ledBlink 0.75s steps(2, start) infinite;
}

@keyframes ledBlink {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.12;
  }
}

/* Oscilación irregular LED PON (OT-103 atenuación límite) */
.led-oscillate {
  animation: ledOscillate 2.2s ease-in-out infinite;
}

@keyframes ledOscillate {
  0%, 28%, 55%, 100% {
    opacity: 1;
  }
  38%, 46% {
    opacity: 0.15;
  }
  72% {
    opacity: 0.35;
  }
}

/* Fuga láser rojo VFL */
.vfl-leak-outer {
  transform-box: fill-box;
  transform-origin: center;
  animation: vflLeakOuter 1s ease-in-out infinite;
}

.vfl-leak-inner {
  transform-box: fill-box;
  transform-origin: center;
  animation: vflLeakInner 0.55s ease-in-out infinite alternate;
}

.vfl-pulse-core {
  animation: ledBlink 0.5s ease-in-out infinite alternate;
}

.vfl-beam-flow {
  animation: vflBeamDash 0.8s linear infinite;
}

@keyframes vflLeakOuter {
  0%, 100% {
    opacity: 0.28;
    transform: scale(0.88);
  }
  50% {
    opacity: 0.78;
    transform: scale(1.22);
  }
}

@keyframes vflLeakInner {
  0% {
    opacity: 0.8;
    transform: scale(0.92);
  }
  100% {
    opacity: 1;
    transform: scale(1.15);
  }
}

@keyframes vflBeamDash {
  from {
    stroke-dashoffset: 22;
  }
  to {
    stroke-dashoffset: 0;
  }
}

/* ==========================================================================
   Consola Digital / Instrumento LCD
   ========================================================================== */

.lcd-screen {
  background: linear-gradient(180deg, #040b18 0%, #091428 100%);
  border: 1px solid #1e293b;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.75);
}

.tool-btn {
  transition: border-color 140ms ease, background-color 140ms ease, transform 100ms ease;
}

.tool-btn:active {
  transform: scale(0.97);
}

.tool-btn.is-active {
  border-color: var(--accent-cyan);
  background-color: rgba(34, 211, 238, 0.14);
  box-shadow: 0 0 0 1px rgba(34, 211, 238, 0.45), 0 0 14px rgba(34, 211, 238, 0.18);
  color: #ecfeff;
}

.zone-tab.is-active {
  background-color: #0e7490;
  border-color: #22d3ee;
  color: #ffffff;
}

/* Animación sutil para alertas/penalizaciones en HUD */
.hud-flash-red {
  animation: flashRed 0.7s ease-out;
}

@keyframes flashRed {
  0% {
    background-color: rgba(239, 68, 68, 0.45);
  }
  100% {
    background-color: transparent;
  }
}

/* ==========================================================================
   Modales Nativos <dialog> (Modern Web Guidance)
   ========================================================================== */

dialog.tech-dialog {
  width: min(calc(100% - 1.5rem), 30rem);
  max-height: calc(100dvh - 2rem);
  margin: auto;
  padding: 0;
  border: 1px solid #334155;
  border-radius: 1rem;
  background-color: #0f172a;
  color: #f8fafc;
  box-shadow: 0 24px 56px rgba(0, 0, 0, 0.75);
}

dialog.tech-dialog[open] {
  display: flex;
  flex-direction: column;
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background-color: rgba(2, 6, 23, 0.8);
  backdrop-filter: blur(4px);
  overflow: hidden;
  overscroll-behavior: contain;
}

/* Tarjeta de opción de diagnóstico accesible */
.repair-option-label {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  min-block-size: 48px;
  cursor: pointer;
}

.repair-option-label:has(input:checked) {
  border-color: #22d3ee;
  background-color: rgba(34, 211, 238, 0.12);
}

/* Respeto por preferencias de movimiento reducido */
@media (prefers-reduced-motion: reduce) {
  .hotspot-pulse,
  .led-blink,
  .led-oscillate,
  .vfl-leak-outer,
  .vfl-leak-inner,
  .vfl-pulse-core,
  .vfl-beam-flow {
    animation: none;
  }
}
