/* Contact modal (<dialog>) and its form.
   Written mobile first: the default is the phone layout (full screen, big touch
   targets); from 641px up it becomes a centered card over a dimmed page. */

html.modal-open { overflow: hidden; }

.contact-dialog { position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: var(--bg); color: var(--text); overflow-y: auto; overscroll-behavior: contain; }
/* Fade + rise in, fade + sink out. Pure CSS: the closed state is the starting point,
   [open] is the end, @starting-style gives the entry its "from", and allow-discrete
   keeps the dialog on screen (display/overlay) until the exit transition ends.
   Browsers without these features simply open and close without animating. */
.contact-dialog { opacity: 0; transform: translateY(16px);
  transition: opacity .25s ease, transform .3s cubic-bezier(.2,.7,.2,1), overlay .3s allow-discrete, display .3s allow-discrete; }
.contact-dialog[open] { opacity: 1; transform: none; }
@starting-style { .contact-dialog[open] { opacity: 0; transform: translateY(16px); } }

.contact-dialog::backdrop { background: rgba(0,0,0,0); -webkit-backdrop-filter: blur(0); backdrop-filter: blur(0);
  transition: background .3s ease, backdrop-filter .3s ease, overlay .3s allow-discrete, display .3s allow-discrete; }
.contact-dialog[open]::backdrop { background: rgba(0,0,0,0.6); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
html[data-theme="light"] .contact-dialog[open]::backdrop { background: rgba(0,0,0,0.35); }
@starting-style { .contact-dialog[open]::backdrop { background: rgba(0,0,0,0); -webkit-backdrop-filter: blur(0); backdrop-filter: blur(0); } }

@media (prefers-reduced-motion: reduce) {
  .contact-dialog, .contact-dialog::backdrop { transition: none; }
}

.cf-inner { position: relative; min-height: 100%; padding: 22px 20px calc(24px + env(safe-area-inset-bottom)); }
.cf-close { position: absolute; top: 10px; right: 12px; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border-strong); border-radius: 50%; background: var(--surface); color: var(--text); font-size: 20px; cursor: pointer; transition: border-color .2s, color .2s; }
.cf-close:hover { border-color: var(--accent); color: var(--accent-ink); }

.cf-kicker { margin: 0 0 10px; font-size: 13px; color: var(--text-muted); }
.cf-kicker .kw { color: var(--accent-ink); }
.contact-dialog h2 { font-size: clamp(30px, 8.5vw, 44px); font-weight: 700; line-height: 1.02; letter-spacing: -0.035em; }
.contact-dialog h2:focus { outline: none; }
.cf-lead { margin: 10px 0 20px; font-size: 15.5px; line-height: 1.5; color: var(--text-body); }

/* Fields */
#contact-form { display: flex; flex-direction: column; gap: 14px; }
.cf-field label { display: block; margin-bottom: 5px; font-size: 14px; font-weight: 500; color: var(--text); }
.cf-optional { font-weight: 400; color: var(--text-muted); }
.cf-field input, .cf-field textarea { display: block; width: 100%; min-height: 46px; padding: 11px 14px; font: inherit;
  font-size: 16px; /* 16px keeps iOS from zooming in on focus */
  color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 2px; transition: border-color .2s, box-shadow .2s; }
/* Starts around 4 lines and grows with the text (field-sizing), up to a limit; older browsers keep rows=4 + manual resize */
.cf-field textarea { min-height: 112px; max-height: 45vh; field-sizing: content; resize: vertical; line-height: 1.5; }
.cf-field input:hover, .cf-field textarea:hover { border-color: var(--text-muted); }
.cf-field input:focus, .cf-field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cf-field [aria-invalid="true"] { border-color: var(--danger); }
.cf-field [aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--danger-soft); }
.cf-error { margin: 7px 0 0; font-size: 13.5px; line-height: 1.4; color: var(--danger); }
.cf-error:empty { display: none; }
.cf-hint { margin: 7px 0 0; font-size: 13.5px; line-height: 1.4; color: var(--text-body); }
.cf-hint:empty { display: none; }
.cf-hint-apply { padding: 0; border: 0; background: none; font: inherit; font-weight: 600; color: var(--accent-ink); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.cf-hint-apply:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cf-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 5px; }
.cf-label-row label { margin-bottom: 0; }
.cf-counter { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.cf-counter.is-over { color: var(--danger); }

/* Honeypot: off screen, out of the tab order and hidden from screen readers */
.cf-hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

/* Turnstile widget: space reserved (65px) so the button doesn't jump when it appears */
.cf-turnstile { min-height: 65px; }

/* Submit + status */
.cf-actions .btn-primary { width: 100%; justify-content: center; }
.cf-actions .btn-primary[disabled] { opacity: .75; cursor: progress; transform: none; box-shadow: none; }
.cf-spin { animation: cf-spin .9s linear infinite; }
@keyframes cf-spin { to { transform: rotate(360deg); } }
.cf-status { margin: -4px 0 0; font-size: 14px; line-height: 1.5; color: var(--text-body); }
.cf-status:empty { display: none; }
.cf-status.is-error { color: var(--danger); }

/* Sent */
.cf-done { display: flex; flex-direction: column; align-items: flex-start; }
.cf-done[hidden] { display: none; }
.cf-done-icon { font-size: 52px; color: var(--accent-ink); margin: 8px 0 16px; }
.cf-done .cf-done-text { margin-bottom: 4px; }
.cf-done-to { margin: 0 0 14px; font-size: 16px; font-weight: 600; color: var(--accent-ink); overflow-wrap: anywhere; }
.cf-done-check { margin: 0 0 22px; font-size: 14px; color: var(--text-muted); }
.cf-done .btn-outline { margin-top: 4px; }

button.btn-primary, button.btn-outline { cursor: pointer; }
.cf-close:focus-visible, .contact-dialog .btn-primary:focus-visible, .contact-dialog .btn-outline:focus-visible,
[data-open-contact]:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* Tablet and desktop: centered card */
@media (min-width: 641px) {
  .contact-dialog { inset: 0; width: min(560px, calc(100% - 48px)); height: fit-content; max-height: calc(100dvh - 48px); margin: auto;
    border: 1px solid var(--border-strong); border-radius: 6px; box-shadow: 0 24px 60px rgba(0,0,0,0.45); }
  .cf-inner { min-height: 0; padding: 36px 40px 34px; }
  .cf-field textarea { min-height: 140px; }
  #contact-form { gap: 16px; }
  .cf-close { top: 16px; right: 16px; width: 40px; height: 40px; font-size: 18px; }
  .cf-actions .btn-primary { width: auto; }
}
