/* ==========================================================================
   FORM.CSS — /kata-kata (the birthday message submission form)
   ==========================================================================
   Mobile-first. Base rules are the phone layout; the @media blocks at the
   bottom add breathing room on wider screens.

   Colors come from warm.css (--canvas, --ink, --accent, --honey…). Spacing,
   radii, motion curves and the font come from tokens.css.
   ========================================================================== */


/* A11y helper: hides an element visually but keeps it available to screen
   readers and to <label for>. Used on the real file <input>. */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}


/* --------------------------------------------------------------------------
   TOP BAR
   -------------------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-5);
  max-width: 720px;
  margin: 0 auto;
}
.topbar-logo {
  height: 24px;
  width: auto;
  display: block;
  /* The logo art is near-white; on a light canvas it would vanish, so in
     light mode we darken it to the warm ink color using a filter. In dark
     mode it stays as-is. */
  filter: none;
}
:root:not([data-theme="dark"]) .topbar-logo {
  /* invert the light logo to dark for the cream canvas */
  filter: brightness(0) saturate(100%) invert(13%) sepia(8%) saturate(900%) hue-rotate(1deg);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .topbar-logo { filter: none; }
}


/* --------------------------------------------------------------------------
   PAGE + STAGE
   The stage stacks the form panel and the thank-you panel in the SAME grid
   cell, so we can crossfade between them with no layout jump.
   -------------------------------------------------------------------------- */
.form-page {
  padding: var(--space-4) var(--space-5) var(--space-11);
  max-width: 620px;
  margin: 0 auto;
}
.stage {
  display: grid;
  grid-template-areas: "stack";
}
.panel {
  grid-area: stack; /* every panel occupies the one shared cell */
}

/* Crossfade: the inactive panel is faded, slightly scaled, blurred, and
   click-through. Blur masks the crossfade so the two panels read as one
   smooth transformation instead of two things overlapping (a trick from
   the design-engineering playbook). */
.panel {
  transition:
    opacity var(--dur-slow) var(--ease-out),
    transform var(--dur-slow) var(--ease-out),
    filter var(--dur-slow) var(--ease-out);
}
.panel-thanks {
  opacity: 0;
  transform: scale(0.98);
  filter: blur(6px);
  pointer-events: none;
}
/* When the stage switches to the "thanks" state (set by form.js on a
   successful submit), swap which panel is present. */
.stage[data-state="thanks"] .panel-form {
  opacity: 0;
  transform: scale(0.98);
  filter: blur(6px);
  pointer-events: none;
}
.stage[data-state="thanks"] .panel-thanks {
  opacity: 1;
  transform: scale(1);
  filter: blur(0);
  pointer-events: auto;
}


/* --------------------------------------------------------------------------
   HEADER COPY
   -------------------------------------------------------------------------- */
.eyebrow {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--honey);          /* honey used as a rare, small flourish */
  margin: var(--space-6) 0 var(--space-3);
}
.form-heading {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.1rem, 9vw, 3rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 0 0 var(--space-4);
}
.form-lede {
  font-family: var(--font-serif); /* Lora — prose only */
  font-size: 1.05rem;
  line-height: 1.6;
  color: var(--ink-muted);
  max-width: 40ch;
  margin: 0 0 var(--space-8);
}


/* --------------------------------------------------------------------------
   FORM FIELDS
   Considered focus: the label shifts to green and the input grows a soft
   green ring. Only color/shadow transition — no layout movement.
   -------------------------------------------------------------------------- */
.message-form { display: flex; flex-direction: column; gap: var(--space-6); }

.field { display: flex; flex-direction: column; gap: var(--space-2); }

.field-label {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink-soft);
  transition: color var(--dur-base) var(--ease-out);
}
.field-optional {
  font-weight: 500;
  font-size: 0.8rem;
  color: var(--ink-faint);
  margin-left: var(--space-1);
}

.field-input {
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  width: 100%;
  transition:
    border-color var(--dur-base) var(--ease-out),
    box-shadow var(--dur-base) var(--ease-out),
    background-color var(--dur-base) var(--ease-out);
  /* remove the browser's own focus outline; we provide a stronger, on-brand
     ring below (still fully keyboard-visible). */
  outline: none;
}
.field-input::placeholder { color: var(--ink-faint); }

.field-textarea {
  resize: vertical;
  min-height: 120px;
  line-height: 1.55;
  /* Same font as the Name field (Plus Jakarta, inherited from .field-input)
     so both fields read consistently while typing. */
}

/* Focus: label turns green, field gets a green border + soft ring. */
.field:focus-within .field-label { color: var(--accent-text); }
.field-input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--honey-soft); /* soft halo; honey-soft is a warm neutral tint */
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}

/* Invalid state (only applied after we've validated, via .is-invalid) */
.field.is-invalid .field-input {
  border-color: var(--alert);
}
.field.is-invalid .field-label { color: var(--alert); }


/* --------------------------------------------------------------------------
   VALIDATION MESSAGE + CHARACTER COUNTER
   Errors appear helpfully (gentle slide+fade in), not punitively.
   -------------------------------------------------------------------------- */
.field-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}
.field-error {
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--alert);
  margin: 0;
  /* entrance: only revealed when JS removes [hidden]; animate in gently */
  animation: field-error-in var(--dur-base) var(--ease-out) both;
}
@keyframes field-error-in {
  from { opacity: 0; transform: translateY(-3px); }
  to   { opacity: 1; transform: translateY(0); }
}
.char-count {
  font-family: var(--font-body);
  font-size: 0.8rem;
  color: var(--ink-faint);
  white-space: nowrap;
  transition: color var(--dur-base) var(--ease-out);
  margin-left: auto;
}
.char-count.is-near { color: var(--honey); }
.char-count.is-over { color: var(--alert); }


/* --------------------------------------------------------------------------
   PHOTO DROPZONE (empty state)
   -------------------------------------------------------------------------- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  text-align: center;
  padding: var(--space-8) var(--space-5);
  background: var(--surface-2);
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  color: var(--ink-muted);
  cursor: pointer;
  transition:
    border-color var(--dur-base) var(--ease-out),
    background-color var(--dur-base) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}
.dropzone:active { transform: scale(0.99); }
.dropzone-icon { color: var(--ink-muted); transition: color var(--dur-base) var(--ease-out); }
.dropzone-text { font-family: var(--font-body); font-weight: 600; font-size: 0.95rem; color: var(--ink-soft); }
.dropzone-hint { font-family: var(--font-body); font-size: 0.8rem; color: var(--ink-faint); }

@media (hover: hover) and (pointer: fine) {
  .dropzone:hover { border-color: var(--accent); background: var(--surface); }
  .dropzone:hover .dropzone-icon { color: var(--accent-text); }
}
/* keyboard focus on the hidden input styles the visible dropzone label */
#photo:focus-visible + .dropzone {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}
/* drag-over highlight (desktop drag-and-drop) */
.dropzone.is-dragover {
  border-color: var(--accent);
  border-style: solid;
  background: var(--surface);
}


/* --------------------------------------------------------------------------
   PHOTO PREVIEW (chosen state) + REAL UPLOAD PROGRESS
   -------------------------------------------------------------------------- */
.photo-preview {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  /* entrance when a photo is picked */
  animation: preview-in var(--dur-base) var(--ease-out) both;
}
@keyframes preview-in {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}
.photo-preview-frame {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface-2);
  aspect-ratio: 4 / 3;
}
.photo-preview-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* While uploading, the photo stays FULLY VISIBLE — we don't dim it. A slim
   determinate bar along the bottom edge shows real progress (driven by the
   actual bytes uploaded — see form.js setting the fill width). No dark veil,
   no "0%": the filling green bar is the whole indicator. A soft shadow above
   the bar keeps it legible even over a light photo. */
.upload-veil {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 5px;
  background: rgba(8, 19, 15, 0.30); /* faint track under the fill */
}
.upload-veil::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 5px;
  height: 28px;
  background: linear-gradient(to top, rgba(8, 19, 15, 0.28), transparent);
  pointer-events: none;
}
.upload-bar-fill {
  height: 100%;
  width: 0%; /* set from real upload progress in form.js */
  background: var(--pine-300);
  transition: width var(--dur-fast) linear;
}

.photo-preview-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.photo-name {
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--ink-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.photo-remove {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--ink-muted);
  background: none;
  border: none;
  padding: 4px 6px;
  cursor: pointer;
  flex: 0 0 auto;
  transition: color var(--dur-base) var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .photo-remove:hover { color: var(--alert); }
}


/* --------------------------------------------------------------------------
   SUBMIT BUTTON — a real state machine, not just "disabled".
   The label crossfades (with a light blur) between "Kirim ucapan" and
   "Mengirim…". Green pill matching the rest of the site's buttons.
   -------------------------------------------------------------------------- */
.submit-btn {
  position: relative;
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: #fff;
  padding: 15px 26px;
  cursor: pointer;
  box-shadow: var(--shadow-accent);
  transition:
    background var(--dur-base) var(--ease-out),
    transform var(--dur-fast) var(--ease-out),
    opacity var(--dur-base) var(--ease-out);
}
.submit-btn:active { transform: scale(var(--press-scale)); }
@media (hover: hover) and (pointer: fine) {
  .submit-btn:hover { background: var(--pine-400); }
}
.submit-btn:disabled { cursor: default; }

.submit-btn-inner {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  /* label crossfade uses blur to mask the swap between words */
  transition: filter var(--dur-base) var(--ease-out), opacity var(--dur-base) var(--ease-out);
}
.submit-btn.is-sending .submit-btn-inner { filter: blur(2px); opacity: 0.75; }

.submit-btn-dot {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 26px; height: 26px;
  border-radius: var(--radius-pill);
  background: #fff;
  color: var(--accent);
  transition: transform var(--dur-base) var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .submit-btn:hover .submit-btn-dot { transform: rotate(45deg); }
}

.form-error {
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--alert);
  background: var(--alert-soft);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin: 0;
  animation: field-error-in var(--dur-base) var(--ease-out) both;
}


/* --------------------------------------------------------------------------
   THANK-YOU PANEL
   -------------------------------------------------------------------------- */
.panel-thanks {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding-top: var(--space-10);
}
.thanks-mark {
  display: grid;
  place-items: center;
  width: 60px; height: 60px;
  border-radius: 50%;
  color: var(--accent-text);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  margin-bottom: var(--space-6);
}
.thanks-heading {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.8rem, 7vw, 2.4rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 0 0 var(--space-4);
}
.thanks-lede {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  line-height: 1.6;
  color: var(--ink-muted);
  max-width: 42ch;
  margin: 0 0 var(--space-7);
}
.thanks-actions { display: flex; flex-wrap: wrap; gap: var(--space-5); align-items: center; }

.text-btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--accent-text);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: none;
  border-bottom: 1.5px solid transparent;
  transition: border-color var(--dur-base) var(--ease-out);
}
.text-btn-quiet { color: var(--ink-muted); }
@media (hover: hover) and (pointer: fine) {
  .text-btn:hover { border-color: currentColor; }
}


/* --------------------------------------------------------------------------
   PAGE-ENTER STAGGER
   The heading, lede, each field, and the button rise+fade in on load, one
   just after the previous — draws the eye down through the form in reading
   order. Plays once. (Durations use the --dur tokens, which collapse to 0ms
   under reduced motion, so this flattens automatically; the reduced-motion
   block below also strips the movement to be safe.)
   -------------------------------------------------------------------------- */
.panel-form > .eyebrow,
.panel-form > .form-heading,
.panel-form > .form-lede,
.message-form > .field,
.message-form > .submit-btn {
  animation: enter-rise var(--dur-slow) var(--ease-out) both;
}
@keyframes enter-rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.panel-form > .eyebrow      { animation-delay: 0ms; }
.panel-form > .form-heading { animation-delay: 50ms; }
.panel-form > .form-lede    { animation-delay: 100ms; }
.message-form > .field:nth-of-type(1) { animation-delay: 150ms; }
.message-form > .field:nth-of-type(2) { animation-delay: 200ms; }
.message-form > .field:nth-of-type(3) { animation-delay: 250ms; }
.message-form > .submit-btn { animation-delay: 300ms; }

@media (prefers-reduced-motion: reduce) {
  .panel-form > .eyebrow,
  .panel-form > .form-heading,
  .panel-form > .form-lede,
  .message-form > .field,
  .message-form > .submit-btn,
  .photo-preview,
  .field-error,
  .form-error {
    animation: none;
    transform: none;
    opacity: 1;
  }
  .panel { transition: opacity var(--dur-base) var(--ease-out); }
  .panel-thanks, .stage[data-state="thanks"] .panel-form { transform: none; filter: none; }
}


/* --------------------------------------------------------------------------
   WIDER SCREENS
   -------------------------------------------------------------------------- */
@media (min-width: 640px) {
  .form-page { padding-top: var(--space-6); }
  .topbar-logo { height: 26px; }
  .form-lede { font-size: 1.15rem; }
}
