/*
 * Facilities letting-value calculator ([nettl_edu_lettings_calculator]).
 *
 * Transparent background and currentColor outlines so the widget follows
 * whatever Kadence row/section it sits in. Colours come from the Kadence
 * global palette / button variables, never hard-coded brand values.
 * Selectors are one class deep (two where they must beat the theme's bare
 * button/input rules) so the theme can still override.
 *
 * Responsive rules are container queries on .nettl-calc, not media queries:
 * the shortcode can sit in a column of any width, so the widget reacts to
 * its own width rather than the viewport's.
 */

.nettl-calc {
  --nettl-calc-line: 1.5px;
  --nettl-calc-tap: 2.5rem; /* 40px minimum touch target */
  --nettl-calc-band: color-mix(in srgb, currentColor 12%, transparent);

  background: transparent;
  color: inherit;
  font: inherit;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  container-type: inline-size;
}

.nettl-calc *,
.nettl-calc *::before,
.nettl-calc *::after {
  box-sizing: border-box;
}

/* ---- Rows -------------------------------------------------------------- */

.nettl-calc__row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "facility stepper";
  align-items: center;
  gap: 0.75rem;
  min-height: 3.5rem;
  padding: 0.5rem 1rem 0.5rem 0.75rem;
  border-radius: 0.75rem;
}

.nettl-calc__row:nth-child(even) {
  background: var(--nettl-calc-band);
}

.nettl-calc__facility {
  grid-area: facility;
  display: flex;
  align-items: center;
  min-width: 0;
}

/* ---- Custom checkbox --------------------------------------------------- */

.nettl-calc .nettl-calc__check {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: 0 0 auto;
  width: 1.75rem;
  height: 1.75rem;
  margin: 0.375rem; /* 1.75rem + margins = 40px hit area, via the label overlap below */
  padding: 0;
  border: var(--nettl-calc-line) solid currentColor;
  border-radius: 0.5rem;
  background: transparent;
  color: inherit;
  cursor: pointer;
  box-shadow: none;
}

.nettl-calc .nettl-calc__check::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 46%;
  width: 0.4rem;
  height: 0.75rem;
  border: solid currentColor;
  border-width: 0 2px 2px 0;
  transform: translate(-50%, -50%) rotate(45deg) scale(0);
  transition: transform 0.12s ease-out;
}

.nettl-calc .nettl-calc__check:checked::before {
  transform: translate(-50%, -50%) rotate(45deg) scale(1);
}

/* The label reaches back over the checkbox's margin so the whole 40px area toggles it. */
.nettl-calc__name {
  /* Block (not flex) so long words can shrink and wrap instead of overflowing into the stepper. */
  display: block;
  min-width: 0;
  min-height: var(--nettl-calc-tap);
  padding-block: 0.6rem;
  margin-inline-start: calc(-1 * var(--nettl-calc-tap));
  padding-inline-start: calc(var(--nettl-calc-tap) + 0.75rem);
  /* Hyphenate where the language allows; break-word is only a last resort for words wider than the row. */
  hyphens: auto;
  overflow-wrap: break-word;
  line-height: 1.25;
  cursor: pointer;
}

/* ---- Info tooltip ------------------------------------------------------ */

.nettl-calc .nettl-calc__info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: var(--nettl-calc-tap);
  height: var(--nettl-calc-tap);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  box-shadow: none;
  cursor: pointer;
  opacity: 0.8;
}

.nettl-calc .nettl-calc__info:hover,
.nettl-calc .nettl-calc__info[aria-expanded="true"] {
  background: var(--nettl-calc-band);
  color: inherit;
  opacity: 1;
}

.nettl-calc__tip {
  position: absolute;
  z-index: 10;
  top: calc(100% - 0.25rem);
  inset-inline: 3.5rem auto;
  max-width: 22rem;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  background: var(--global-palette9, Canvas);
  color: var(--global-palette3, CanvasText);
  font-size: 0.9rem;
  line-height: 1.4;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.3);
}

.nettl-calc__tip[hidden] {
  display: none;
}

/* ---- Quantity stepper -------------------------------------------------- */

.nettl-calc__stepper {
  grid-area: stepper;
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 0.75rem;
}

.nettl-calc .nettl-calc__step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: var(--nettl-calc-tap);
  height: var(--nettl-calc-tap);
  margin: 0;
  padding: 0;
  border: var(--nettl-calc-line) solid currentColor;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  box-shadow: none;
  cursor: pointer;
}

.nettl-calc .nettl-calc__step:hover:not(:disabled) {
  background: var(--nettl-calc-band);
  color: inherit;
}

.nettl-calc .nettl-calc__step:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.nettl-calc .nettl-calc__qty {
  appearance: textfield;
  -moz-appearance: textfield;
  width: 3.5rem;
  height: var(--nettl-calc-tap);
  margin: 0;
  padding: 0 0.25rem;
  border: var(--nettl-calc-line) solid currentColor;
  border-radius: 0.6rem;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: center;
  box-shadow: none;
}

.nettl-calc .nettl-calc__qty::-webkit-outer-spin-button,
.nettl-calc .nettl-calc__qty::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ---- Focus ------------------------------------------------------------- */

.nettl-calc .nettl-calc__check:focus-visible,
.nettl-calc .nettl-calc__info:focus-visible,
.nettl-calc .nettl-calc__step:focus-visible,
.nettl-calc .nettl-calc__qty:focus-visible,
.nettl-calc .nettl-calc__cta:focus-visible {
  outline: 3px solid currentColor;
  outline-offset: 2px;
}

/* ---- Total box --------------------------------------------------------- */

.nettl-calc__result {
  margin-top: 1.5rem;
  padding: 2rem 1.5rem;
  border: var(--nettl-calc-line) solid currentColor;
  border-radius: 1.5rem;
  text-align: center;
}

.nettl-calc__result-label {
  margin: 0;
  font-size: 0.9rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.nettl-calc__total {
  position: relative;
  margin: 0.75rem 0 1.25rem;
  font-size: clamp(2.5rem, 9vw, 4.5rem);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

/* Only the final total is announced; the animated figure is aria-hidden. */
.nettl-calc__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---- CTA (Kadence button styling) -------------------------------------- */

.nettl-calc .nettl-calc__cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  min-height: var(--nettl-calc-tap);
  max-width: 100%;
  background: var(--global-palette-btn-bg, var(--global-palette1));
  color: var(--global-palette-btn, var(--global-palette9));
  text-decoration: none;
  cursor: pointer;
}

.nettl-calc .nettl-calc__cta:hover,
.nettl-calc .nettl-calc__cta:focus {
  background: var(--global-palette-btn-bg-hover, var(--global-palette2, var(--global-palette-btn-bg)));
  color: var(--global-palette-btn-hover, var(--global-palette-btn, var(--global-palette9)));
}

.nettl-calc__cta-icon {
  flex: 0 0 auto;
  transition: transform 0.15s ease-out;
}

.nettl-calc__cta:hover .nettl-calc__cta-icon {
  transform: translateX(3px);
}

/* ---- Progressive enhancement ------------------------------------------- */

/* Steppers and tooltip icons need JS; before it runs, show the plain list. */
.nettl-calc:not(.is-enhanced) .nettl-calc__stepper,
.nettl-calc:not(.is-enhanced) .nettl-calc__info {
  display: none;
}

/* ---- Narrow ------------------------------------------------------------ */

/*
 * The one compact breakpoint: the widget's own width, not the viewport's.
 * CSS can't read var() in a query condition, so the wide layout is the
 * default and everything compact is overridden here, keeping the value in one place.
 */
@container (max-width: 377px) {
  .nettl-calc__row {
    gap: 0.5rem;
    padding: 0.375rem 0.5rem;
  }

  .nettl-calc__stepper {
    gap: 0.375rem;
  }

  .nettl-calc .nettl-calc__qty {
    width: 2.75rem;
    padding: 0;
  }

  .nettl-calc .nettl-calc__check {
    margin: 0.375rem 0.25rem;
  }

  .nettl-calc__name {
    padding-inline-start: calc(var(--nettl-calc-tap) + 0.25rem);
  }

  /* The icon is centred in its 40px target, so tuck the empty edge in to save width. */
  .nettl-calc .nettl-calc__info {
    margin-inline-start: -0.5rem;
  }

  .nettl-calc__tip {
    inset-inline: 0.75rem;
  }

  .nettl-calc__result {
    padding: 1.5rem 1rem;
  }
}

/* Too narrow for name and stepper side by side: drop the stepper onto its own line, under the name. */
@container (max-width: 26rem) {
  .nettl-calc__row {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "facility"
      "stepper";
    row-gap: 0.25rem;
    padding-bottom: 0.625rem;
  }

  /* Checkbox (1.75rem + 0.25rem margins) plus the label overlap puts the name text at 2.5rem. */
  .nettl-calc__stepper {
    justify-self: start;
    margin-inline-start: var(--nettl-calc-tap);
  }
}

@media (prefers-reduced-motion: reduce) {
  .nettl-calc .nettl-calc__check::before,
  .nettl-calc__cta-icon {
    transition: none;
  }
}
