/* ==========================================================================
   Comparador de tarifas — PagarMenosLuz
   --------------------------------------------------------------------------
   Extiende el sistema visual de styles.css. No redefine tokens de marca:
   reutiliza --blue-*, --yellow-*, --cyan-400, --ink, --muted, --radius y las
   sombras ya existentes. Se carga SIEMPRE después de styles.css.
   ========================================================================== */

/* --------------------------------------------------------------------------
   El atributo `hidden` tiene que ganar SIEMPRE.

   El navegador oculta [hidden] con una regla `display:none` de su hoja de
   estilos, que tiene la prioridad más baja de todas: en cuanto una clase
   nuestra declara `display:grid` o `display:flex`, el elemento se ve aunque
   el JavaScript lo haya marcado como oculto.

   Sin esta regla, el bloque "Calculando tu comparativa…" era visible desde que
   cargaba la página y no se iba nunca, y lo mismo les pasaba a los campos de
   excedentes, a la potencia P2 y al panel de resultados.
   -------------------------------------------------------------------------- */
[hidden] {
  display: none !important;
}

:root {
  /* Escala z semántica, para no volver a escribir 999 en ninguna parte. */
  --z-sticky: 30;
  --z-overlay: 60;
  --z-dialog: 70;

  /* Curva de salida exponencial: rápida al principio, asentamiento suave. */
  --ease-out-quint: cubic-bezier(0.22, 1, 0.36, 1);
}

/* --------------------------------------------------------------------------
   Cabecera de la página
   -------------------------------------------------------------------------- */

.cmp-hero {
  background: linear-gradient(160deg, var(--blue-950) 0%, var(--blue-900) 62%, var(--blue-800) 100%);
  color: var(--white);
  padding: clamp(38px, 6vw, 66px) 0 clamp(56px, 8vw, 92px);
}

.cmp-hero h1 {
  max-width: 15ch;
  margin: 0;
  font-size: clamp(2.1rem, 5.4vw, 3.4rem);
  font-weight: 600;
  line-height: 1.02;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.cmp-hero h1 em {
  color: var(--yellow-400);
  font-style: normal;
}

.cmp-hero p {
  max-width: 56ch;
  margin: 16px 0 0;
  color: rgba(255, 255, 255, 0.88);
  font-size: clamp(1rem, 2.6vw, 1.16rem);
  line-height: 1.6;
  text-wrap: pretty;
}

.cmp-hero-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  margin: 26px 0 0;
  padding: 0;
  list-style: none;
}

.cmp-hero-facts li {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.94rem;
  font-weight: 500;
}

.cmp-hero-facts svg {
  width: 19px;
  height: 19px;
  color: var(--cyan-400);
  flex: 0 0 auto;
}

/* --------------------------------------------------------------------------
   Panel principal. Solapa el hero para que la herramienta sea lo primero
   que el ojo encuentra al bajar.
   -------------------------------------------------------------------------- */

.cmp-main {
  background: #f4f7fb;
  padding: 0 0 clamp(48px, 7vw, 84px);
}

.cmp-panel {
  position: relative;
  margin-top: clamp(-72px, -6vw, -44px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: var(--card-shadow);
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   Progreso por pasos
   -------------------------------------------------------------------------- */

.cmp-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
}

.cmp-step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px 12px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  transition:
    color 200ms var(--ease-out-quint),
    border-color 200ms var(--ease-out-quint),
    background-color 200ms var(--ease-out-quint);
}

.cmp-step[aria-disabled="true"] {
  cursor: not-allowed;
}

.cmp-step__num {
  display: grid;
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 999px;
  background: #e4ecf8;
  color: #53617a;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  transition:
    background-color 200ms var(--ease-out-quint),
    color 200ms var(--ease-out-quint);
}

.cmp-step__num svg {
  width: 14px;
  height: 14px;
  stroke-width: 2.6;
}

.cmp-step.is-active {
  border-bottom-color: var(--blue-700);
  background: var(--white);
  color: var(--blue-950);
}

.cmp-step.is-active .cmp-step__num {
  background: var(--blue-700);
  color: var(--white);
}

.cmp-step.is-done {
  color: var(--blue-800);
}

.cmp-step.is-done .cmp-step__num {
  background: #d8f3e2;
  color: #10743f;
}

.cmp-step__label {
  min-width: 0;
}

@media (max-width: 620px) {
  .cmp-step__label {
    display: none;
  }

  .cmp-steps {
    justify-items: center;
  }

  .cmp-step {
    justify-content: center;
    padding-inline: 4px;
  }
}

/* --------------------------------------------------------------------------
   Paneles de paso
   -------------------------------------------------------------------------- */

.cmp-pane {
  display: none;
  padding: clamp(20px, 3.4vw, 34px);
}

.cmp-pane.is-active {
  display: block;
  animation: cmp-pane-in 320ms var(--ease-out-quint) both;
}

@keyframes cmp-pane-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.cmp-pane h2 {
  margin: 0;
  color: var(--blue-950);
  font-size: clamp(1.35rem, 3.2vw, 1.75rem);
  font-weight: 600;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.cmp-pane__intro {
  max-width: 62ch;
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.55;
  text-wrap: pretty;
}

.cmp-fieldset {
  margin: 26px 0 0;
  padding: 0;
  border: 0;
}

.cmp-fieldset > legend {
  padding: 0;
  color: var(--blue-950);
  font-size: 1rem;
  font-weight: 600;
}

.cmp-fieldset__hint {
  margin: 4px 0 14px;
  color: var(--muted);
  font-size: 0.88rem;
}

.cmp-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.cmp-grid--three {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

/* --------------------------------------------------------------------------
   Campos
   -------------------------------------------------------------------------- */

.cmp-field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.cmp-field > span,
.cmp-field__label {
  color: #46536b;
  font-size: 0.86rem;
  font-weight: 600;
}

.cmp-field small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.4;
}

.cmp-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.cmp-field input[type="text"],
.cmp-field input[type="tel"],
.cmp-field input[type="email"],
.cmp-field input[type="number"],
.cmp-field select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 0 14px;
  background: var(--white);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  outline: none;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.cmp-field select {
  cursor: pointer;
  appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M6 8l4 4 4-4' stroke='%23045bd8' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 20px 20px;
}

.cmp-input-wrap input {
  padding-right: 52px;
}

.cmp-unit {
  position: absolute;
  right: 14px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
  pointer-events: none;
}

.cmp-field input:focus,
.cmp-field select:focus {
  border-color: var(--blue-700);
  box-shadow: 0 0 0 4px rgba(4, 91, 216, 0.12);
}

.cmp-field input[aria-invalid="true"] {
  border-color: #b42318;
}

.cmp-field input[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 4px rgba(180, 35, 24, 0.12);
}

.cmp-field-error {
  color: #b42318;
  font-size: 0.8rem;
  font-weight: 500;
}

.cmp-field-error:empty {
  display: none;
}

/* Control segmentado — para elecciones de 2 a 4 opciones cortas. */
.cmp-segmented {
  display: flex;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  background: #f4f8ff;
}

.cmp-segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.cmp-segmented label {
  flex: 1 1 0;
  min-height: 40px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  padding: 0 10px;
  color: #46536b;
  font-size: 0.88rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition:
    background-color 180ms var(--ease-out-quint),
    color 180ms var(--ease-out-quint);
}

.cmp-segmented input:checked + label {
  background: var(--blue-700);
  color: var(--white);
}

.cmp-segmented input:focus-visible + label {
  outline: 2px solid var(--blue-700);
  outline-offset: 2px;
}

/* Casillas de extras */
.cmp-check {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 11px;
  padding: 13px 14px;
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  background: var(--white);
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background-color 160ms ease;
}

.cmp-check:hover {
  border-color: rgba(4, 91, 216, 0.34);
  background: #fbfdff;
}

.cmp-check input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--blue-700);
}

.cmp-check strong {
  display: block;
  color: var(--blue-950);
  font-size: 0.92rem;
  font-weight: 600;
}

.cmp-check span {
  color: var(--muted);
  font-size: 0.83rem;
  line-height: 1.45;
}

.cmp-check-list {
  display: grid;
  gap: 10px;
}

/* Zona plegable de opciones avanzadas */
.cmp-disclosure {
  margin-top: 18px;
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  background: #fbfdff;
  overflow: hidden;
}

.cmp-disclosure > summary {
  position: relative;
  padding: 14px 44px 14px 15px;
  color: var(--blue-950);
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 600;
  list-style: none;
}

.cmp-disclosure > summary::-webkit-details-marker {
  display: none;
}

.cmp-disclosure > summary::after {
  position: absolute;
  top: 50%;
  right: 17px;
  width: 8px;
  height: 8px;
  border-right: 1.6px solid var(--blue-700);
  border-bottom: 1.6px solid var(--blue-700);
  content: "";
  transform: translateY(-70%) rotate(45deg);
  transition: transform 180ms var(--ease-out-quint);
}

.cmp-disclosure[open] > summary::after {
  transform: translateY(-25%) rotate(225deg);
}

.cmp-disclosure__body {
  padding: 0 15px 16px;
  border-top: 1px solid var(--line);
}

.cmp-disclosure__body > * + * {
  margin-top: 14px;
}

/* --------------------------------------------------------------------------
   Subida de factura
   -------------------------------------------------------------------------- */

.cmp-upload input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.cmp-upload label {
  display: grid;
  min-height: 148px;
  place-items: center;
  gap: 4px;
  border: 1px dashed #8fb1dd;
  border-radius: var(--radius);
  padding: 22px;
  background: linear-gradient(180deg, rgba(32, 211, 255, 0.07), rgba(255, 255, 255, 0)), #f8fbff;
  text-align: center;
  cursor: pointer;
  transition:
    border-color 180ms ease,
    background-color 180ms ease;
}

.cmp-upload label:hover,
.cmp-upload.is-dragover label {
  border-color: var(--blue-700);
  background: #f1f7ff;
}

.cmp-upload input:focus-visible + label {
  outline: 2px solid var(--blue-700);
  outline-offset: 2px;
}

.cmp-upload svg {
  width: 34px;
  height: 34px;
  color: var(--blue-700);
}

.cmp-upload strong {
  color: var(--blue-950);
}

.cmp-upload span {
  color: var(--muted);
  font-size: 0.88rem;
}

.cmp-upload-status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  min-height: 22px;
  color: var(--blue-800);
  font-size: 0.9rem;
  font-weight: 500;
}

.cmp-upload-status.is-error {
  color: #b42318;
}

.cmp-upload-status.is-ok {
  color: #10743f;
}

/* --------------------------------------------------------------------------
   Pie de cada paso
   -------------------------------------------------------------------------- */

.cmp-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.cmp-actions .btn {
  flex: 1 1 200px;
}

.cmp-actions .cmp-back {
  flex: 0 0 auto;
  min-height: 48px;
  padding: 0 8px;
  background: none;
  border: 0;
  color: var(--blue-700);
  font-weight: 600;
}

.cmp-actions .cmp-back:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* --------------------------------------------------------------------------
   Estado de carga
   -------------------------------------------------------------------------- */

.cmp-loading {
  display: grid;
  place-items: center;
  gap: 14px;
  padding: clamp(40px, 8vw, 76px) 20px;
  text-align: center;
}

.cmp-spinner {
  width: 38px;
  height: 38px;
  border: 3px solid #dbe5f4;
  border-top-color: var(--blue-700);
  border-radius: 999px;
  animation: cmp-spin 720ms linear infinite;
}

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

.cmp-loading p {
  margin: 0;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   Resultados
   --------------------------------------------------------------------------
   Jerarquía deliberada: la mejor oferta es un panel oscuro a ancho completo,
   el resto una lista compacta y escaneable. No es una parrilla de tarjetas
   iguales: la primera opción es la respuesta, las demás son el contexto.
   -------------------------------------------------------------------------- */

.cmp-results {
  padding: clamp(20px, 3.4vw, 34px);
}

.cmp-winner {
  display: grid;
  gap: 22px;
  border-radius: var(--radius);
  padding: clamp(22px, 3.6vw, 34px);
  background: linear-gradient(150deg, var(--blue-950) 0%, var(--blue-900) 100%);
  color: var(--white);
}

.cmp-winner__tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: start;
  min-height: 30px;
  border-radius: 999px;
  padding: 0 13px;
  background: var(--yellow-400);
  color: var(--blue-950);
  font-size: 0.8rem;
  font-weight: 600;
}

.cmp-winner__tag svg {
  width: 15px;
  height: 15px;
  stroke-width: 2.4;
}

.cmp-winner__name {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2.1rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
  text-wrap: balance;
}

.cmp-winner__tarifa {
  margin: 6px 0 0;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.96rem;
}

.cmp-winner__figures {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  padding-top: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
}

.cmp-figure dt {
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.84rem;
  font-weight: 500;
}

.cmp-figure dd {
  margin: 5px 0 0;
  font-size: clamp(1.5rem, 3.4vw, 1.95rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1;
}

.cmp-figure--saving dd {
  color: var(--yellow-400);
}

.cmp-winner__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.cmp-winner__actions .btn {
  flex: 1 1 190px;
}

/* Lista del resto de tarifas */
.cmp-rest {
  margin-top: 30px;
}

.cmp-rest h3 {
  margin: 0 0 4px;
  color: var(--blue-950);
  font-size: 1.08rem;
  font-weight: 600;
}

.cmp-rest > p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

.cmp-rows {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cmp-row {
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  background: var(--white);
  overflow: hidden;
}

.cmp-row > summary {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto 22px;
  align-items: center;
  gap: 12px;
  padding: 14px 15px;
  cursor: pointer;
  list-style: none;
}

.cmp-row > summary::-webkit-details-marker {
  display: none;
}

.cmp-row:hover {
  border-color: rgba(4, 91, 216, 0.3);
}

.cmp-row__pos {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.cmp-row__name {
  min-width: 0;
  color: var(--blue-950);
  font-weight: 600;
  line-height: 1.25;
}

.cmp-row__name small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cmp-row__total {
  color: var(--blue-950);
  font-size: 1.06rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cmp-row__total span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 500;
  text-align: right;
}

.cmp-row__chevron {
  width: 8px;
  height: 8px;
  justify-self: center;
  border-right: 1.6px solid var(--blue-700);
  border-bottom: 1.6px solid var(--blue-700);
  transform: translateY(-2px) rotate(45deg);
  transition: transform 180ms var(--ease-out-quint);
}

.cmp-row[open] .cmp-row__chevron {
  transform: translateY(1px) rotate(225deg);
}

.cmp-breakdown {
  margin: 0;
  padding: 4px 15px 16px;
  border-top: 1px solid var(--line);
}

.cmp-breakdown div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 0;
  font-size: 0.88rem;
}

.cmp-breakdown div + div {
  border-top: 1px solid #eef3fa;
}

.cmp-breakdown dt {
  color: var(--muted);
}

.cmp-breakdown dd {
  margin: 0;
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cmp-breakdown div.is-total dt,
.cmp-breakdown div.is-total dd {
  color: var(--blue-950);
  font-weight: 600;
}

/* Entrada escalonada de las filas. El contenido es visible por defecto:
   la animación solo lo enriquece, nunca condiciona que se vea. */
@media (prefers-reduced-motion: no-preference) {
  .cmp-row {
    animation: cmp-row-in 380ms var(--ease-out-quint) both;
    animation-delay: calc(var(--cmp-i, 0) * 45ms);
  }
}

@keyframes cmp-row-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* --------------------------------------------------------------------------
   Avisos
   -------------------------------------------------------------------------- */

.cmp-note {
  display: flex;
  gap: 11px;
  margin-top: 24px;
  border: 1px solid #dce7f6;
  border-radius: var(--radius);
  padding: 14px 15px;
  background: #f7faff;
  color: #46536b;
  font-size: 0.84rem;
  line-height: 1.55;
}

.cmp-note svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  margin-top: 1px;
  color: var(--blue-700);
}

.cmp-note strong {
  color: var(--blue-950);
}

.cmp-alert {
  display: flex;
  gap: 11px;
  margin-top: 18px;
  border: 1px solid #f3c7c2;
  border-radius: var(--radius);
  padding: 14px 15px;
  background: #fdf4f3;
  color: #8a2018;
  font-size: 0.9rem;
  line-height: 1.5;
}

.cmp-alert svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  margin-top: 1px;
}

.cmp-alert[hidden] {
  display: none;
}

/* --------------------------------------------------------------------------
   Privacidad (reutiliza el patrón de index.html)
   -------------------------------------------------------------------------- */

.cmp-privacy {
  display: grid;
  gap: 12px;
  margin-top: 22px;
}

/* Trampa para bots: fuera de la vista, fuera del foco y fuera del árbol de
   accesibilidad. Un humano nunca la rellena. */
.cmp-hp {
  position: absolute !important;
  left: -9999px !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   Accesibilidad y preferencias
   -------------------------------------------------------------------------- */

.cmp-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .cmp-pane.is-active,
  .cmp-row {
    animation: none;
  }

  .cmp-spinner {
    animation-duration: 2.4s;
  }

  .cmp-step,
  .cmp-step__num,
  .cmp-segmented label,
  .cmp-row__chevron,
  .cmp-disclosure > summary::after {
    transition-duration: 1ms;
  }
}

/* Confirmación de que la comparativa queda en el expediente del cliente.
   Aparece solo cuando el CRM confirma el adjunto: prometer algo que no ha
   pasado es peor que no decir nada. */
.cmp-winner__saved {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.88rem;
}

.cmp-winner__saved[hidden] {
  display: none;
}

.cmp-winner__saved svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  color: var(--yellow-400);
  stroke-width: 2.4;
}
