/*
 * The booking dialog on the solution pages (packhouses.html, co-ops.html), with booking.js. Every rule is copied
 * from styles.css, where the home page keeps its own copy, so the form looks the same on every page;
 * tests/pages.test.js fails if a rule here drifts from its original in styles.css.
 * No inline styles anywhere (the CSP allows only same-origin style sheets).
 */

:root {
  /* The booking sheet's glass, as it reads over the dimmed page: the pinned footer's band matches it. */
  --bk-band: 242, 239, 231;

  /* Stacked layout unit: one pixel of the 390 x 844 phone mock, within 0.9 and 1.45 (the Close button's padding). */
  --p: clamp(0.9px, min(calc(100vw / 390), calc(100vh / 760)), 1.45px);
}
@supports (height: 100svh) {
  :root {
    --p: clamp(0.9px, min(calc(100vw / 390), calc(100svh / 760)), 1.45px);
  }
}

dialog {
  color: var(--ink);
}

.btn-glass {
  padding: 0 calc(18 * var(--p));
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink);
  border-color: rgba(255, 255, 255, 0.8);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
  box-shadow: 0 8px 24px -12px rgba(40, 50, 30, 0.35);
}

.btn-glass:hover {
  background: rgba(255, 255, 255, 0.72);
  transform: translateY(-1px);
}

.btn-glass:active {
  transform: translateY(0);
  background: rgba(255, 255, 255, 0.64);
}

.bk-privacy a {
  color: var(--green-deep);
  font-weight: 500;
  text-underline-offset: 2px;
}

.bk-close:active {
  transform: scale(0.94);
}

/* ---------------------------------------------------------------- booking dialog */

.booking {
  position: fixed;
  width: min(480px, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  margin: auto;
  --bk-x: 34px;
  --bk-bottom: 28px;
  padding: 34px var(--bk-x) 0;
  overflow: auto;
  overscroll-behavior: contain;
  /* Fields scrolled into view stop above the sticky footer (its height is measured by app.js). */
  scroll-padding-bottom: var(--bk-footer, 150px);
  border-radius: 26px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  background: rgba(252, 249, 243, 0.88);
  -webkit-backdrop-filter: blur(24px) saturate(150%);
  backdrop-filter: blur(24px) saturate(150%);
  box-shadow: 0 50px 120px -30px rgba(20, 30, 15, 0.55);
}

.booking::backdrop {
  background: rgba(30, 36, 28, 0.28);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.bk-close {
  position: absolute;
  right: 20px;
  top: 18px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(20, 32, 26, 0.07);
  color: var(--ink-2);
  cursor: pointer;
}

/* A 44 px touch target around the 30 px circle. */
.bk-close::after {
  content: "";
  position: absolute;
  inset: -7px;
}

.bk-close svg {
  width: 14px;
  height: 14px;
}

.bk-close:hover {
  background: rgba(20, 32, 26, 0.12);
  color: var(--ink);
}

.bk-title:focus {
  outline: none;
}

.bk-title {
  font-weight: 640;
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: -0.02em;
  padding-right: 36px;
}

.bk-lede {
  margin-top: 10px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink-2);
}

.field {
  margin-top: 16px;
}

.field:first-child {
  margin-top: 22px;
}

.field label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  line-height: 1.3;
}

.field-optional {
  font-weight: 500;
  color: var(--ink-2);
  margin-left: 4px;
}

.field input,
.field textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 0 14px;
  height: 46px;
  border-radius: 12px;
  border: 1px solid rgba(20, 32, 26, 0.14);
  background: #fff;
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 400;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.field textarea {
  height: auto;
  min-height: 74px;
  padding: 12px 14px;
  line-height: 1.45;
  resize: vertical;
}

.field input::placeholder,
.field textarea::placeholder {
  /* The mock's 0.38 is raised so the example text reaches 4.5:1 on white. */
  color: rgba(20, 32, 26, 0.6);
  opacity: 1;
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(44, 122, 49, 0.22);
}

.field input[aria-invalid="true"],
.field textarea[aria-invalid="true"] {
  border-color: #b3261e;
}

.field input[aria-invalid="true"]:focus,
.field textarea[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px rgba(179, 38, 30, 0.18);
}

.field-error {
  margin-top: 6px;
  font-size: 12.5px;
  line-height: 1.4;
  font-weight: 500;
  color: #a1221b;
}

/* The honeypot: not rendered at all (bots that read the HTML still see the field and fill it). */
.hp {
  display: none;
}

/*
 * The privacy line, any failure message and "Request a call" stay pinned to the bottom of the sheet while the
 * fields scroll. The band and its soft top fade appear only when the sheet scrolls (.is-scrollable, set by
 * app.js); the fade goes once the last field is in view (.at-end).
 */
.bk-footer {
  position: sticky;
  bottom: 0;
  z-index: 1;
  margin: 0 calc(-1 * var(--bk-x));
  padding: 16px var(--bk-x) var(--bk-bottom);
}

.booking.is-scrollable .bk-footer {
  background: rgb(var(--bk-band));
}

.bk-footer::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  height: 28px;
  background: linear-gradient(to bottom, rgba(var(--bk-band), 0), rgb(var(--bk-band)));
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.booking.is-scrollable:not(.at-end) .bk-footer::before {
  opacity: 1;
}

.bk-privacy {
  margin-top: 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--ink-2);
}

.bk-failure {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(179, 38, 30, 0.08);
  color: #8c1d17;
  font-size: 13.5px;
  line-height: 1.45;
  font-weight: 500;
}

.bk-failure a {
  font-weight: 600;
}

.btn-block {
  display: flex;
  width: 100%;
  height: 52px;
  margin-top: 16px;
  font-size: 16px;
}

.btn-block:hover {
  transform: none;
}

.spinner {
  display: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}

.is-sending .spinner {
  display: block;
}

.is-sending.btn {
  cursor: progress;
  opacity: 0.92;
}

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

.bk-done {
  display: grid;
  justify-items: center;
  text-align: center;
  padding: 18px 8px var(--bk-bottom);
}

.bk-done[hidden],
.bk-view[hidden] {
  display: none;
}

.bk-check {
  width: 64px;
  height: 64px;
}

.bk-check-ring {
  stroke: var(--green);
  stroke-width: 2;
  stroke-dasharray: 151;
  stroke-dashoffset: 151;
  animation: draw 0.7s 0.05s var(--ease) forwards;
}

.bk-check-tick {
  stroke: var(--green);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 34;
  stroke-dashoffset: 34;
  animation: draw 0.45s 0.55s var(--ease) forwards;
}

@keyframes draw {
  to {
    stroke-dashoffset: 0;
  }
}

.bk-done-text {
  margin-top: 18px;
  max-width: 300px;
  font-size: 20px;
  line-height: 1.35;
  font-weight: 600;
  letter-spacing: -0.012em;
}

.bk-done-text:focus {
  outline: none;
}

.bk-done .btn {
  margin-top: 26px;
  min-width: 140px;
}

/* Dialog entrance (where supported). */
.booking[open] {
  opacity: 1;
  transform: none;
  transition:
    opacity 0.35s var(--ease),
    transform 0.45s var(--ease);
}

@starting-style {
  .booking[open] {
    opacity: 0;
    transform: translate3d(0, 14px, 0) scale(0.985);
  }
}

/* Phones: the booking form is a bottom sheet. */
@media (max-width: 560px) {
  /* --vv-height and --kb come from app.js (visualViewport): with the on-screen keyboard open the sheet sits above
     it and shrinks to what is visible, so "Request a call" stays on screen. */
  .booking {
    width: 100%;
    --bk-x: 22px;
    --bk-bottom: max(22px, env(safe-area-inset-bottom));
    max-height: calc(var(--vv-height, 100dvh) - 12px);
    margin: auto 0 var(--kb, 0px);
    padding: 28px var(--bk-x) 0;
    border-radius: 26px 26px 0 0;
    border-bottom: 0;
  }

  @starting-style {
    .booking[open] {
      opacity: 1;
      transform: translate3d(0, 40%, 0);
    }
  }

  .bk-title {
    font-size: 25px;
  }
}

/* Short screens: a tighter rhythm so more of the form shows above the pinned button; inputs stay 44 px. */
@media (max-height: 700px) {
  .booking {
    padding-top: 24px;
  }

  .bk-close {
    top: 14px;
  }

  .bk-title {
    font-size: 23px;
  }

  .bk-lede {
    margin-top: 6px;
    font-size: 14.5px;
    line-height: 1.45;
  }

  .field {
    margin-top: 10px;
  }

  .field:first-child {
    margin-top: 16px;
  }

  .field input,
  .field textarea {
    margin-top: 4px;
    height: 44px;
  }

  .field textarea {
    height: 64px;
    min-height: 64px;
    padding: 9px 14px;
  }

  .field-error {
    margin-top: 4px;
  }

  .bk-footer {
    padding-top: 12px;
  }

  .bk-privacy {
    font-size: 12px;
  }

  .btn-block {
    height: 48px;
    margin-top: 10px;
  }
}

/* iOS zooms into inputs under 16 px. */
@media (pointer: coarse) {
  .field input,
  .field textarea {
    font-size: 16px;
  }
}

/* ---------------------------------------------------------------- reduced motion */

@media (prefers-reduced-motion: reduce) {
  .bk-check-ring,
  .bk-check-tick {
    animation: none;
    stroke-dashoffset: 0;
  }

  .spinner {
    animation-duration: 2.4s;
  }

  @starting-style {
    .booking[open] {
      transform: none;
    }
  }
}

@media (prefers-reduced-transparency: reduce) {
  .btn-glass,
  .booking {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: #fbf8f2;
  }
}
