/* ==========================================================================
   Project drawer — right-hand panel with the enquiry form (v4 styling:
   teal header, square fields like the case cards, pill buttons).

   Built on <dialog> + showModal(), which gives focus trapping, an inert
   background, Escape-to-close and ::backdrop for free. The slide-in uses
   @starting-style + transition-behavior: allow-discrete, so no JS drives
   the animation; browsers without that support simply show the panel
   without a slide.

   Contents
     1. Panel & animation
     2. Header / body / footer
     3. Form fields
     4. Choice groups (checkbox, radio, consent)
     5. File upload
     6. Validation & status
     7. Mobile (fullscreen)
   ========================================================================== */


/* 1. Panel & animation ===================================================== */

.drawer {
  position: fixed;
  inset: 0 0 0 auto;             /* pin to the right edge */
  z-index: 50;
  width: min(540px, 100%);
  max-width: none;
  max-height: none;
  height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--bg);
  color: var(--ink);
  box-shadow: -24px 0 60px rgba(2, 78, 88, 0.16);
  overflow: hidden;

  /* Closed state */
  translate: 100% 0;
  transition:
    translate 420ms cubic-bezier(0.32, 0.72, 0, 1),
    display 420ms allow-discrete,
    overlay 420ms allow-discrete;
}

.drawer[open] {
  translate: 0 0;
}

/* Entry animation start point. */
@starting-style {
  .drawer[open] {
    translate: 100% 0;
  }
}

.drawer::backdrop {
  background: rgba(2, 78, 88, 0);
  transition:
    background 420ms ease,
    display 420ms allow-discrete,
    overlay 420ms allow-discrete;
}

.drawer[open]::backdrop {
  background: rgba(2, 78, 88, 0.42);
  backdrop-filter: blur(2px);
}

@starting-style {
  .drawer[open]::backdrop {
    background: rgba(2, 78, 88, 0);
  }
}

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

/* Stops the page behind the drawer from scrolling. */
.has-drawer {
  overflow: hidden;
}

.drawer__panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* The form sits between the panel and the scrolling body, so it has to be a
   flex item AND a flex container itself. Without `min-height: 0` it grows to
   its content height, which pushes the submit footer off-screen and stops
   .drawer__body from ever scrolling. */
.form {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}


/* 2. Header / body / footer ================================================ */

.drawer__head {
  flex: none;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 26px var(--gutter) 24px;
  background: var(--teal);
  color: #FFFFFF;
}

.drawer__head .eyebrow {
  color: var(--lime);
}

.drawer__title {
  margin: 10px 0 0;
  font-family: var(--font-display);
  font-size: 27px;
  line-height: 1.15;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: #FFFFFF;
  text-wrap: balance;
}

.drawer__close {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1.5px solid rgba(255, 255, 255, 0.45);
  border-radius: 999px;
  background: transparent;
  color: #FFFFFF;
  cursor: pointer;
  transition: background-color var(--ease), color var(--ease), border-color var(--ease);
}

.drawer__close:hover {
  background: var(--lime);
  border-color: var(--lime);
  color: var(--teal);
}

.drawer__body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 26px var(--gutter) 32px;
}

.drawer__intro {
  margin-bottom: 26px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink-muted);
}

.drawer__foot {
  flex: none;
  padding: 18px var(--gutter);
  border-top: 1px solid var(--border);
  background: var(--bg-sunken);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
}

.drawer__foot .btn {
  flex: 1 1 auto;
  text-align: center;
  border: 0;
  cursor: pointer;
  font-family: inherit;
}

.drawer__legend {
  font-size: 12.5px;
  color: var(--ink-subtle);
}


/* 3. Form fields =========================================================== */

.field {
  margin-bottom: 20px;
}

.field__label {
  display: block;
  margin-bottom: 7px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

/* The asterisk is decorative — the legend in the footer explains it and the
   inputs carry `required`, so screen readers already announce it. */
.field__req {
  color: var(--teal);
}

.field__hint {
  margin-top: 6px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-subtle);
}

.field__input,
.field__select,
.field__textarea {
  width: 100%;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 15.5px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg-raised);
  /* --ink-subtle clears the 3:1 non-text contrast floor against the panel
     background; the original --border-soft would not. */
  border: 1px solid var(--ink-subtle);
  border-radius: 0;
  transition: border-color var(--ease), box-shadow var(--ease);
}

.field__textarea {
  min-height: 132px;
  resize: vertical;
}

.field__select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-muted) 50%),
                    linear-gradient(135deg, var(--ink-muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) calc(50% + 2px), calc(100% - 14px) calc(50% + 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 40px;
}

.field__input:hover,
.field__select:hover,
.field__textarea:hover {
  border-color: var(--teal);
}

.field__row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0 18px;
}


/* 4. Choice groups ========================================================= */

.group {
  margin: 0 0 20px;
  padding: 0;
  border: 0;
}

.group__legend {
  padding: 0;
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

.group__options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 8px 16px;
}

.choice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14.5px;
  line-height: 1.45;
  color: var(--ink-muted);
  cursor: pointer;
}

.choice input {
  flex: none;
  width: 19px;
  height: 19px;
  margin: 1px 0 0;
  accent-color: var(--teal);
  cursor: pointer;
}

/* RODO consent sits apart from the rest of the form. */
.consent {
  margin-top: 26px;
  padding: 16px 18px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-left: 4px solid var(--lime);
}

.consent .choice {
  font-size: 13.5px;
  line-height: 1.55;
}

/* --ink-muted rather than --ink-subtle: at 12.5px on the sunken background
   the subtle tone lands at 4.58:1, uncomfortably close to the 4.5 floor. */
.consent__note {
  margin-top: 10px;
  padding-left: 29px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--ink-muted);
}


/* 5. File upload =========================================================== */

.upload {
  margin-bottom: 20px;
}

.upload__control {
  display: block;
  padding: 18px;
  text-align: center;
  border: 1px dashed var(--ink-subtle);
  background: var(--bg-raised);
  font-size: 14px;
  color: var(--ink-muted);
  cursor: pointer;
  transition: border-color var(--ease), background-color var(--ease);
}

.upload__control:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.upload input[type='file'] {
  /* Visually hidden, but still focusable so the keyboard reaches it — the
     styled label is its visible affordance. */
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.upload input[type='file']:focus-visible + .upload__control {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.upload__list {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.upload__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: var(--bg-sunken);
  font-size: 13px;
  color: var(--ink-muted);
}

.upload__name {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload__size {
  flex: none;
  color: var(--ink-subtle);
  font-variant-numeric: tabular-nums;
}

.upload__remove {
  flex: none;
  margin: -6px -8px -6px 0;
  padding: 6px 8px;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  color: var(--teal);
  cursor: pointer;
}

.upload__remove:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.upload__remove:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 0;
}


/* 6. Validation & status =================================================== */

.field__error {
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.45;
  /* 5.9:1 on the panel background. */
  color: #B3261E;
}

.field__input[aria-invalid='true'],
.field__select[aria-invalid='true'],
.field__textarea[aria-invalid='true'] {
  border-color: #B3261E;
  box-shadow: 0 0 0 1px #B3261E;
}

.form__status {
  margin-bottom: 20px;
  padding: 14px 16px;
  font-size: 14.5px;
  line-height: 1.55;
}

.form__status:empty {
  display: none;
}

.form__status[data-state='error'] {
  background: #FBEAE8;
  border: 1px solid #B3261E;
  color: #8C1D18;
}

.form__status[data-state='ok'] {
  background: var(--lime);
  border: 1px solid var(--teal);
  color: var(--teal-ink);
}

/* Sending state */
.form[data-sending='true'] {
  opacity: 0.6;
  pointer-events: none;
}


/* 7. Mobile (fullscreen) =================================================== */

@media (max-width: 640px) {
  .drawer {
    inset: 0;
    width: 100%;
    height: 100dvh;
    box-shadow: none;
  }

  .drawer__head {
    padding: 18px var(--gutter) 16px;
  }

  .drawer__title {
    font-size: 23px;
  }

  .drawer__body {
    padding: 22px var(--gutter) 28px;
  }

  .drawer__foot {
    /* Clears the iOS home indicator. */
    padding-bottom: max(18px, env(safe-area-inset-bottom));
  }

  .field__row {
    grid-template-columns: minmax(0, 1fr);
  }
}
