/* ==========================================================================
   components.css: reusable UI pieces (no page-specific layout here)
   Layer: components

   Contents
   1. Buttons (.btn + variants, sizes, arrow, sheen, loading spinner)
   2. Link, icons, icon tile, chip, badge, stars, eyebrow, section head
   3. Card
   4. Form controls (.field, .check, .form__*, .form-success, lead form grid)
   5. Dialog shell (.dialog, backdrop, entry/exit)
   6. Reveal system (hidden states only under html.reveal-ready, all motion
      inside prefers-reduced-motion: no-preference)

   Hover effects are wrapped in (hover: hover). Motion (translate/scale/keyframes)
   is wrapped in (prefers-reduced-motion: no-preference). Colors come from tokens, except a few literal values in this file (a sheen highlight, a
   glass border and two transparent backdrops).
   ========================================================================== */

@layer components {
  /* ---- 1. Buttons ---- */
  .btn {
    position: relative;
    isolation: isolate;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    min-block-size: 3.25rem;
    padding-inline: 1.6rem;
    padding-block: 0.7rem;
    border: 0;
    border-radius: var(--r-md);
    font-size: 1rem;
    font-weight: 650;
    font-stretch: 96%;
    letter-spacing: 0.005em;
    line-height: 1;
    text-align: center;
    text-decoration: none;
    text-wrap: balance;
    transition:
      background-color var(--dur-2) var(--ease-out),
      color var(--dur-2) var(--ease-out),
      border-color var(--dur-2) var(--ease-out),
      box-shadow var(--dur-2) var(--ease-out);
  }

  .btn .icon {
    inline-size: 1.15em;
    block-size: 1.15em;
  }

  .btn--primary {
    overflow: hidden;
    background: var(--color-action);
    color: var(--white);
    box-shadow: var(--shadow-action);
  }

  /* Diagonal sheen: sweeps once on hover, invisible otherwise. */
  .btn--primary::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: linear-gradient(105deg, transparent 35%, rgb(255 255 255 / 0.32) 50%, transparent 65%);
    translate: -120% 0;
    pointer-events: none;
  }

  .btn--light {
    background: var(--white);
    color: var(--ink-900);
    box-shadow: var(--shadow-md);
  }

  .btn--dark {
    background: var(--ink-800);
    color: var(--white);
    box-shadow: var(--shadow-sm);
  }

  .btn--ghost {
    background: transparent;
    color: inherit;
    border: 1.5px solid currentColor;
    border: 1.5px solid color-mix(in srgb, currentColor 40%, transparent);
  }

  .btn--sm {
    min-block-size: 2.75rem;
    padding-inline: 1.1rem;
    font-size: 0.9375rem;
  }

  .btn--lg {
    min-block-size: 3.625rem;
    padding-inline: 1.8rem;
    font-size: 1.0625rem;
  }

  .btn--block {
    inline-size: 100%;
  }

  /* Arrow glyph inside buttons: nudges right on hover (see hover block below). */
  .btn__arrow {
    transition: translate var(--dur-2) var(--ease-out);
  }

  .btn:focus-visible {
    outline-offset: 3px;
  }

  .btn:disabled,
  .btn[aria-disabled="true"] {
    opacity: 0.6;
    pointer-events: none;
    box-shadow: none;
  }

  /* Loading: spinner before the label, no pointer events, dimmed. */
  .btn.is-loading {
    opacity: 0.7;
    pointer-events: none;
  }

  .btn.is-loading::before {
    content: "";
    flex: none;
    inline-size: 1em;
    block-size: 1em;
    border-radius: 50%;
    border: 2px solid transparent;
    border: 2px solid color-mix(in srgb, currentColor 30%, transparent);
    border-block-start-color: currentColor;
  }

  @media (prefers-reduced-motion: no-preference) {
    .btn {
      transition:
        background-color var(--dur-2) var(--ease-out),
        color var(--dur-2) var(--ease-out),
        border-color var(--dur-2) var(--ease-out),
        box-shadow var(--dur-2) var(--ease-out),
        translate var(--dur-2) var(--ease-out),
        scale var(--dur-1) var(--ease-out);
    }

    .btn:active:not(:disabled) {
      translate: 0 0;
      scale: 0.985;
    }

    .btn.is-loading::before {
      animation: spin 800ms linear infinite;
    }
  }

  @media (hover: hover) {
    .btn--primary:hover:not(:disabled) {
      background: var(--color-action-hover);
      translate: 0 -2px;
    }

    .btn--primary:hover::after {
      animation: btn-sheen 700ms var(--ease-out) 1;
    }

    .btn--light:hover:not(:disabled) {
      translate: 0 -2px;
      box-shadow: var(--shadow-lg);
    }

    .btn--dark:hover:not(:disabled) {
      background: var(--ink-700);
      translate: 0 -2px;
    }

    .btn--ghost:hover:not(:disabled) {
      border-color: currentColor;
      background: color-mix(in srgb, currentColor 8%, transparent);
    }

    .btn:hover .btn__arrow {
      translate: 0.25rem 0;
    }
  }

  @media (hover: hover) and (prefers-reduced-motion: reduce) {
    .btn--primary:hover::after {
      animation: none;
    }
  }

  /* ---- 2. Link, icons, tiles, chips, badges, stars, eyebrow, section head ---- */
  .link {
    color: var(--color-accent);
    font-weight: 600;
    text-decoration: none;
    background-image: linear-gradient(currentColor, currentColor);
    background-size: 100% 1px;
    background-position: 0 100%;
    background-repeat: no-repeat;
    padding-block-end: 0.1em;
    transition: background-size var(--dur-2) var(--ease-out);
  }

  @media (hover: hover) {
    .link {
      background-size: 0% 1px;
    }

    .link:hover {
      background-size: 100% 1px;
    }
  }

  @media (hover: none) {
    .link {
      background-size: 100% 1px;
    }
  }

  .icon {
    display: inline-block;
    flex: none;
    inline-size: 1.25em;
    block-size: 1.25em;
    vertical-align: -0.2em;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .icon--fill {
    fill: currentColor;
    stroke: none;
  }

  .icon-tile {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    inline-size: 3.25rem;
    block-size: 3.25rem;
    border-radius: var(--r-md);
    background: var(--tile-bg, var(--sand-100));
    color: var(--tile-fg, var(--terracotta-600));
  }

  .icon-tile .icon {
    inline-size: 1.5rem;
    block-size: 1.5rem;
  }

  .chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 0.9rem;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--r-pill);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: var(--fs-sm);
    font-weight: 600;
    line-height: 1.3;
  }

  .chip .icon {
    color: var(--color-accent);
    inline-size: 1em;
    block-size: 1em;
  }

  .badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    padding: 0.3rem 0.6rem;
    border-radius: var(--r-xs);
    background: var(--sand-200);
    color: var(--ink-900);
    font-size: var(--fs-xs);
    font-weight: 700;
    letter-spacing: 0.08em;
    line-height: 1.1;
    text-transform: uppercase;
  }

  .badge--red {
    background: var(--red-600);
    color: var(--white);
  }

  .badge--glass {
    background: var(--scrim-ink-62);
    border: 1px solid rgb(255 255 255 / 0.26);
    color: var(--white);
  }

  .stars {
    display: inline-flex;
    gap: 0.12rem;
    font-size: 1rem;
    color: var(--amber-400);
  }

  .stars .icon {
    inline-size: 1em;
    block-size: 1em;
    vertical-align: -0.1em;
  }

  .eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    margin-block-end: 1rem;
    color: var(--color-accent);
    font-size: var(--fs-eyebrow);
    font-weight: 650;
    letter-spacing: var(--tracking-eyebrow);
    line-height: 1.2;
    text-transform: uppercase;
  }

  .eyebrow__ridge {
    inline-size: 0.875rem;
    block-size: 0.5rem;
    color: currentColor;
    stroke-width: 2;
    vertical-align: middle;
  }

  .section-head {
    margin-block-end: clamp(2.5rem, 5vw, 4rem);
  }

  .section-head--center {
    max-inline-size: 46rem;
    margin-inline: auto;
    text-align: center;
  }

  .section-head--center .eyebrow {
    justify-content: center;
  }

  .section-title {
    margin: 0;
  }

  .section-lead {
    max-inline-size: 60ch;
    margin-block-start: 1.1rem;
    color: var(--color-text-muted);
    font-size: var(--fs-lead);
    line-height: 1.55;
    text-wrap: pretty;
  }

  .section-head--center .section-lead {
    margin-inline: auto;
    text-wrap: balance;
  }

  /* ---- 3. Card ---- */
  .card {
    position: relative;
    padding: clamp(1.25rem, 2.5vw, 1.75rem);
    border: 1px solid var(--color-border);
    border-radius: var(--r-lg);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    color: var(--color-text);
    transition:
      box-shadow var(--dur-3) var(--ease-out),
      background-color var(--dur-2) var(--ease-out);
  }

  /* ---- 4. Form controls ---- */
  .lead-form {
    display: grid;
    gap: 0.85rem;
  }

  .form__row {
    display: grid;
    gap: 0.85rem;
  }

  @media (min-width: 30rem) {
    .form__row {
      grid-template-columns: 1fr 1fr;
    }
  }

  .field {
    display: grid;
    align-content: start;
    gap: 0.4rem;
    min-inline-size: 0;
  }

  .field__label {
    color: var(--color-text);
    font-size: var(--fs-sm);
    font-weight: 620;
    line-height: 1.3;
  }

  .field__required {
    margin-inline-start: 0.1em;
    color: var(--red-600);
    font-weight: 700;
  }

  .field__control {
    appearance: none;
    display: block;
    inline-size: 100%;
    min-block-size: 3.25rem;
    padding: 0.8rem 1rem;
    border: 1.5px solid var(--sand-300);
    border-radius: var(--r-sm);
    background: var(--white);
    color: var(--ink-900);
    font-size: 1rem;
    line-height: 1.4;
    transition:
      border-color var(--dur-1) var(--ease-out),
      box-shadow var(--dur-1) var(--ease-out);
  }

  .field__control::placeholder {
    color: var(--color-placeholder);
    opacity: 1;
  }

  textarea.field__control {
    min-block-size: 6.875rem;
    resize: vertical;
  }

  .field__control--select {
    padding-inline-end: 2.8rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%231b3352' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-position: right 1rem center;
    background-repeat: no-repeat;
    background-size: 1rem;
    cursor: pointer;
  }

  .field__control:focus {
    border-color: var(--ink-700);
    outline: 3px solid var(--color-focus);
    outline-offset: 2px;
  }

  .field__control:disabled {
    opacity: 0.6;
    cursor: not-allowed;
  }

  /* Native :user-invalid marks fields the user has touched; JS adds aria-invalid after interaction. */
  .field__control:is(:user-invalid, [aria-invalid="true"]) {
    border-color: var(--danger-600);
  }

  /* Valid after interaction: subtle green check on name and phone only. */
  :is([name="name"], [name="phone"]):user-valid {
    border-color: var(--success-600);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%231f7a4d' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
    background-position: right 1rem center;
    background-repeat: no-repeat;
    background-size: 1.125rem;
    padding-inline-end: 2.8rem;
  }

  .field__error {
    display: flex;
    align-items: flex-start;
    gap: 0.4rem;
    margin: 0.35rem 0 0;
    color: var(--error-text, var(--danger-600));
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.35;
  }

  /* Alert glyph: a 14px mask in currentColor, so it takes the error colour on light and dark cards. */
  .field__error::before {
    content: "";
    flex: none;
    inline-size: 0.875rem;
    block-size: 0.875rem;
    margin-block-start: 0.1em;
    background-color: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='9' fill='none' stroke='black' stroke-width='2.2'/%3E%3Cpath d='M12 7.5v5.5M12 16.3v.1' stroke='black' stroke-width='2.6' stroke-linecap='round'/%3E%3C/svg%3E")
      center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='9' fill='none' stroke='black' stroke-width='2.2'/%3E%3Cpath d='M12 7.5v5.5M12 16.3v.1' stroke='black' stroke-width='2.6' stroke-linecap='round'/%3E%3C/svg%3E")
      center / contain no-repeat;
  }

  .field--check {
    gap: 0.35rem;
  }

  .check {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    color: var(--color-text-muted);
    font-size: var(--fs-xs);
    line-height: 1.45;
    cursor: pointer;
  }

  .check input[type="checkbox"] {
    flex: none;
    inline-size: 1.375rem;
    block-size: 1.375rem;
    margin: 0;
    accent-color: var(--red-600);
    cursor: pointer;
  }

  .form__status {
    margin: 0;
    padding: 0.85rem 1rem;
    border-inline-start: 4px solid var(--danger-600);
    border-radius: var(--r-sm);
    background: var(--danger-100);
    color: var(--ink-900);
    font-size: var(--fs-sm);
    font-weight: 550;
    line-height: 1.45;
  }

  /* Empty status line: no box and no grid gap (position absolute takes it out of the form's grid flow).
     Keep the markup as <div class="form__status" ...></div> on one line with NO whitespace inside: whitespace makes
     it non-empty and the box shows. */
  .form__status:empty {
    position: absolute;
    padding: 0;
    border: 0;
    margin: 0;
  }

  /* Shown only by the inline safety net in index.html (html[data-js-failed]) when the JavaScript did not run. */
  .form__fallback {
    display: none;
    color: var(--color-text-muted);
    font-size: var(--fs-sm);
  }

  html[data-js-failed] .form__fallback {
    display: block;
  }

  .form__fallback a {
    font-weight: 700;
    white-space: nowrap;
  }

  .form__noscript {
    color: var(--color-text-muted);
    font-size: var(--fs-sm);
  }

  .form__noscript a {
    font-weight: 700;
  }

  .form__legal {
    padding: 0.9rem 1rem;
    border-radius: var(--r-sm);
    background: var(--sand-100);
    color: var(--color-text-muted);
    font-size: var(--fs-xs);
    line-height: 1.55;
  }

  .form__legal a {
    color: var(--color-accent);
    font-weight: 600;
  }

  .form-success {
    display: grid;
    justify-items: start;
    gap: 0.75rem;
    padding: clamp(1.25rem, 3vw, 2rem);
    border: 1px solid var(--success-600);
    border-radius: var(--r-lg);
    background: var(--success-100);
    /* Self-contained light scheme: the panel can sit inside a dark section (the hero), so it re-declares
       the text tokens instead of inheriting the dark-surface ones. */
    --color-text: var(--ink-800);
    --color-heading: var(--ink-900);
    --color-text-muted: var(--ink-muted-light);
    color: var(--color-text);
    outline: none;
  }

  .form-success:focus-visible {
    outline: 3px solid var(--color-focus);
    outline-offset: 3px;
  }

  .form-success__badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    padding: 0.35rem 0.75rem;
    border-radius: var(--r-pill);
    background: var(--success-600);
    color: var(--white);
    font-size: var(--fs-xs);
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
  }

  .form-success__title {
    color: var(--ink-900);
    font-size: var(--fs-h3);
  }

  .form-success__text {
    color: var(--ink-800);
  }

  .form-success__call {
    color: var(--ink-800);
    font-weight: 700;
  }

  .form-success__call a {
    white-space: nowrap;
    color: var(--red-700);
    text-decoration: underline;
    text-underline-offset: 0.15em;
  }

  /* ---- 5. Dialog shell ---- */
  .dialog {
    display: none;
    flex-direction: column;
    inline-size: 100%;
    max-inline-size: min(55rem, calc(100vw - 2rem));
    max-block-size: calc(100vh - 2rem);
    max-block-size: calc(100dvh - 2rem);
    margin: auto;
    padding: 0;
    border: 0;
    border-radius: var(--r-xl);
    background: var(--paper);
    color: var(--color-text);
    box-shadow: var(--shadow-xl);
    overflow: auto;
    overscroll-behavior: contain;
    opacity: 0;
    transition:
      opacity var(--dur-1) var(--ease-out),
      display var(--dur-1) allow-discrete,
      overlay var(--dur-1) allow-discrete;
  }

  .dialog[open] {
    display: flex;
    opacity: 1;
    @starting-style {
      opacity: 0;
    }
  }

  .dialog::backdrop {
    background: rgb(7 15 28 / 0);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    transition:
      background-color var(--dur-2) var(--ease-out),
      display var(--dur-2) allow-discrete,
      overlay var(--dur-2) allow-discrete;
  }

  .dialog[open]::backdrop {
    background: var(--scrim-ink-70);
    @starting-style {
      background: rgb(7 15 28 / 0);
    }
  }

  @media (prefers-reduced-motion: no-preference) {
    .dialog {
      translate: 0 0;
      scale: 1;
      transition:
        opacity var(--dur-2) var(--ease-out),
        translate var(--dur-2) var(--ease-out),
        scale var(--dur-2) var(--ease-out),
        display var(--dur-2) allow-discrete,
        overlay var(--dur-2) allow-discrete;
    }

    .dialog:not([open]) {
      translate: 0 1rem;
      scale: 0.98;
    }

    .dialog[open] {
      @starting-style {
        translate: 0 1rem;
        scale: 0.98;
      }
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .dialog,
    .dialog::backdrop {
      transition-duration: 100ms;
    }
  }

  /* Phones: dialogs become full-screen sheets. */
  @media (max-width: 39.9375rem) {
    .dialog {
      inset: 0;
      max-inline-size: 100vw;
      max-block-size: 100vh;
      max-block-size: 100dvh;
      block-size: 100vh;
      block-size: 100dvh;
      border-radius: 0;
    }
  }

  .dialog__close {
    display: inline-grid;
    flex: none;
    place-items: center;
    inline-size: 2.75rem;
    block-size: 2.75rem;
    border-radius: 50%;
    background: var(--sand-100);
    color: var(--ink-900);
    transition: background-color var(--dur-1) var(--ease-out);
  }

  .dialog__close .icon {
    inline-size: 1.25rem;
    block-size: 1.25rem;
  }

  @media (hover: hover) {
    .dialog__close:hover {
      background: var(--sand-200);
    }
  }

  /* ---- 6. Reveal system ----
     Content is visible by default (no JS, reduced motion). Hidden pre-states only
     apply once JS has added html.reveal-ready, and only with motion allowed. */
  @media (prefers-reduced-motion: no-preference) {
    [data-reveal] {
      transition-property: opacity, translate, scale, clip-path;
      transition-duration: var(--dur-4);
      transition-timing-function: var(--ease-out);
      transition-delay: calc(min(var(--i, 0), 5) * var(--stagger));
    }

    .reveal-ready [data-reveal]:not(.is-in) {
      opacity: 0;
      translate: 0 1.75rem;
    }

    .reveal-ready [data-reveal="left"]:not(.is-in) {
      translate: -28px 0;
    }

    .reveal-ready [data-reveal="right"]:not(.is-in) {
      translate: 1.75rem 0;
    }

    .reveal-ready [data-reveal="scale"]:not(.is-in) {
      scale: 0.94;
    }

    .reveal-ready [data-reveal="fade"]:not(.is-in) {
      translate: none;
    }

    /* Image wipe: the frame opens top to bottom, the picture settles from 1.12. */
    .reveal-ready [data-reveal="clip"]:not(.is-in) {
      opacity: 1;
      translate: none;
      clip-path: inset(0 0 100% 0);
    }

    .reveal-ready [data-reveal="clip"]:not(.is-in) img {
      scale: 1.12;
    }

    [data-reveal="clip"].is-in {
      clip-path: inset(-3rem);
    }

    [data-reveal="clip"] img {
      transition: scale var(--dur-4) var(--ease-out);
      transition-delay: calc(min(var(--i, 0), 5) * var(--stagger));
    }
  }
}

/* Keyframes live at the top level of the layer so the references above resolve. */
@layer components {
  @keyframes spin {
    to {
      transform: rotate(360deg);
    }
  }

  @keyframes btn-sheen {
    from {
      translate: -120% 0;
    }

    to {
      translate: 120% 0;
    }
  }
}
