/* DNAPZ Portal — "Dusk to Dawn" (see DESIGN.md).
   A violet-night canvas carrying ~85% of every surface, with a single warm
   Dawn Glow accent rationed to the primary action, one accent word per
   heading, and result states. Token names are kept stable so this file stays
   diffable against aa-portal; only the values and type ramp moved. */

:root {
  /* neutrals — the night ramp. Elevation = a lighter surface, not a shadow. */
  --night:      #0a0912;  /* deepest base — footer floor, inputs, page floor */
  --bg:         #100e1d;  /* Dark — the primary page background */
  --bg-frame:   #0a0912;  /* Night — overlays and sticky table heads */
  --calm:       #1a1730;  /* alternating section surface, modal panel */
  --surface-solid: #221d3d; /* lifted card surface, violet-tinted */

  /* brand */
  --accent:      #8b85ff;  /* Periwinkle Violet — links, focus, active state */
  --accent-deep: #6d63e6;  /* Violet Deep — pressed */
  --glow:        #f7b787;  /* Dawn Glow — primary CTA, accent word, results */
  --glow-soft:   #ffcfa8;  /* Dawn Soft — hover, success text */

  /* text — three levels by role: ink → body → muted. Muted is the floor. */
  --ink:      #f4f2fb;  /* headings and emphasis (never pure #fff) */
  --ink-warm: #d9d6ea;  /* body paragraphs and nav — the baseline */
  --ink-dim:  #b9b4cc;  /* captions, metadata; never go dimmer than this */
  --ink-mute: var(--ink-dim);

  /* functional only — errors need to read as distinct from the Dawn Glow */
  --danger: #ff8fa0;

  --line:       rgba(255, 255, 255, 0.10);
  --line-soft:  rgba(255, 255, 255, 0.08);
  --line-hi:    rgba(139, 133, 255, 0.38);
  --surface:    rgba(34, 29, 61, 0.72);
  --surface-hi: rgba(34, 29, 61, 0.92);

  /* glows signal active/selected state — never ambient decoration */
  --glow-dawn:   0 0 30px rgba(247, 183, 135, 0.15);
  --glow-violet: 0 0 24px rgba(139, 133, 255, 0.15);

  --font-display: "Gabarito", "Figtree", "Noto Sans Thai", sans-serif;
  --font-body: "Figtree", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --r-sm: 0.5rem;
  --r-md: 0.75rem;
  --r-lg: 1rem;
  --r-xl: 1.5rem;
  --r-full: 9999px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  margin: 0;
  min-height: 100%;
  background: var(--bg);  /* fallback before image loads */
}
body {
  margin: 0;
  min-height: 100%;
  background: transparent; /* let .aurora show through */
  color: var(--ink-warm);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  position: relative;
  overflow-x: hidden;
  accent-color: var(--accent);  /* checkboxes/radios take violet, not UA blue */
}
a { color: inherit; text-decoration: none; }

/* Focus is always Periwinkle Violet, everywhere. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ambient backdrop — the photo survives as texture, washed to violet-night
   so the canvas reads as #100e1d rather than as the photograph's own palette */
.aurora {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-color: var(--bg);
  overflow: hidden;
}
.aurora::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: image-set(
    url("/assets/bg.webp") type("image/webp"),
    url("/assets/bg.jpg") type("image/jpeg")
  );
  background-image: -webkit-image-set(
    url("/assets/bg.webp") type("image/webp"),
    url("/assets/bg.jpg") type("image/jpeg")
  );
  background-position: center top;
  background-size: cover;
  background-repeat: no-repeat;
  filter: saturate(0.55) brightness(0.5);
}
.aurora::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    /* dawn breaking high on the right — the canvas's one warm note */
    radial-gradient(52% 38% at 80% 2%, rgba(247, 183, 135, 0.13), transparent 70%),
    /* twilight violet lifting the mid-field so the base never reads gray */
    radial-gradient(72% 56% at 16% 34%, rgba(139, 133, 255, 0.12), transparent 74%),
    /* the violet-night wash that owns the page */
    linear-gradient(
      180deg,
      rgba(16, 14, 29, 0.90) 0%,
      rgba(16, 14, 29, 0.93) 42%,
      rgba(10, 9, 18, 0.97) 100%
    );
}
/* mobile: smaller image for bandwidth */
@media (max-width: 640px) {
  .aurora::before {
    background-image: image-set(
      url("/assets/bg-mid.webp") type("image/webp"),
      url("/assets/bg.jpg") type("image/jpeg")
    );
    background-image: -webkit-image-set(
      url("/assets/bg-mid.webp") type("image/webp"),
      url("/assets/bg.jpg") type("image/jpeg")
    );
  }
}
/* orbs now decorative only — stripped, the backdrop does the glow work */
.orb { display: none; }

/* topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 960px;
  margin: 0 auto;
  padding: 28px clamp(20px, 5vw, 40px);
}

/* The Logo Exception — the wordmark is the one sanctioned gradient text:
   warm ink → Dawn Glow, the dusk-to-dawn arc itself. Nothing else may. */
.brand {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
  background: linear-gradient(100deg, var(--ink) 12%, var(--glow) 88%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.brand-sub {
  font-family: var(--font-body);
  color: var(--ink-dim);
  -webkit-text-fill-color: var(--ink-dim);  /* opt out of the wordmark gradient */
  font-weight: 600;
  font-size: 0.75rem;
  line-height: 1.4;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-left: 8px;
}

.nav-link {
  font-size: 0.875rem;
  color: var(--ink-dim);
  transition: color 0.2s;
}
.nav-link:hover { color: var(--ink); }

/* shell */
.shell {
  max-width: 640px;
  margin: 0 auto;
  padding: clamp(40px, 10vh, 100px) clamp(20px, 5vw, 40px) 60px;
}

/* hero */
.hero { margin-bottom: 3rem; }
.headline {
  font-family: var(--font-display);
  font-size: clamp(2.75rem, 6vw, 4.5rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-wrap: balance;
  margin: 0 0 1rem;
}
/* The Accent-Word Rule — one solid Dawn Glow word per heading, max. */
.headline .accent { color: var(--glow); }
.lede {
  margin: 0;
  color: var(--ink-warm);
  font-size: 1.125rem;
  line-height: 1.65;
  max-width: 42ch;
  text-wrap: pretty;
}

/* link list */
.links { display: flex; flex-direction: column; gap: 10px; }

.group { display: contents; }
.group-head {
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 2rem 0 0.5rem;
}
.group-head:first-child { margin-top: 0; }

/* Solid tinted Surface + hairline. No decorative glass (The One-Glass Rule),
   no drop shadow (The Glow-Not-Shadow Rule). */
.card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 1.125rem 1.5rem;
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  background: var(--surface);
  transition: background 0.2s, border-color 0.2s, transform 0.15s, box-shadow 0.2s;
}
.card:hover {
  background: var(--surface-hi);
  border-color: var(--line-hi);
  transform: translateY(-3px);
  box-shadow: var(--glow-violet);
}

.card-body { min-width: 0; }
.card-title {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
  margin: 0;
}
.card-desc {
  font-size: 0.9375rem;
  color: var(--ink-dim);
  margin: 4px 0 0;
  line-height: 1.5;
  text-wrap: pretty;
}

.card-arrow {
  flex-shrink: 0;
  color: var(--ink-dim);
  font-size: 1.125rem;
  transition: color 0.2s, transform 0.2s;
}
.card:hover .card-arrow { color: var(--ink); transform: translate(2px, -2px); }

.skel {
  height: 72px;
  border-radius: var(--r-xl);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.5; } }

.empty {
  padding: 3rem 1.25rem;
  text-align: center;
  color: var(--ink-dim);
  border: 1px dashed var(--line);
  border-radius: var(--r-xl);
  font-size: 0.9375rem;
}

/* footer */
.foot {
  max-width: 640px;
  margin: 60px auto 32px;
  padding: 0 clamp(20px, 5vw, 40px);
  color: var(--ink-dim);
  font-size: 0.8125rem;
}

/* ── admin ───────────────────────────────────── */

.admin-shell {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px clamp(20px, 5vw, 40px) 80px;
}
.admin-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
}
.admin-head h1 {
  font-family: var(--font-display);
  font-size: clamp(1.875rem, 4vw, 2.25rem);
  font-weight: 700;
  color: var(--ink);
  line-height: 1.1;
  letter-spacing: -0.01em;
  text-wrap: balance;
  margin: 0;
}
.admin-head-actions { display: flex; gap: 8px; }

/* Buttons are fully rounded. Padding is scaled down from the design's
   1rem/2.25rem for the dense admin toolbar; page-level actions get it back. */
.btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: transparent;
  color: var(--ink);
  padding: 0.625rem 1.25rem;
  border-radius: var(--r-full);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s, box-shadow 0.2s;
}
.btn:hover { background: rgba(255, 255, 255, 0.05); }
.btn:active { border-color: var(--accent-deep); background: rgba(109, 99, 230, 0.18); }
/* The Dawn Rationing Rule — this is the only element that gets the glow. */
.btn-primary {
  background: var(--glow);
  color: var(--night);
  border-color: var(--glow);
}
.btn-primary:hover {
  background: var(--glow-soft);
  border-color: var(--glow-soft);
  box-shadow: var(--glow-dawn);
}
.btn-primary:active { background: var(--glow); box-shadow: none; transform: translateY(1px); }
.btn-ghost { background: transparent; border-color: var(--line-soft); color: var(--ink-dim); }
.btn-ghost:hover { color: var(--ink); border-color: var(--line); }
.btn-danger { color: var(--danger); border-color: rgba(255, 143, 160, 0.28); }
.btn-danger:hover { background: rgba(255, 143, 160, 0.08); }

.admin-list { display: flex; flex-direction: column; gap: 8px; }

.row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 0.875rem 1.125rem;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.row:hover { border-color: var(--line-hi); background: var(--surface-hi); }
.row-grip {
  color: var(--ink-dim);
  font-size: 1rem;
  cursor: grab;
  user-select: none;
}
.row-grip:active { cursor: grabbing; }
.row.dragging { opacity: 0.4; }
.row.drop-target { border-color: var(--accent); box-shadow: var(--glow-violet); }
.row.is-hidden { opacity: 0.55; }
.row.is-hidden .t { text-decoration: line-through; text-decoration-color: var(--ink-dim); }
.badge {
  display: inline-block;
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: var(--r-full);
  background: rgba(139, 133, 255, 0.16);
  color: var(--ink-dim);
  vertical-align: middle;
  margin-left: 8px;
  transform: translateY(-2px);
}
.row-body .t {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.9375rem;
  line-height: 1.3;
  color: var(--ink);
}
.row-body .u {
  color: var(--ink-dim);
  font-size: 0.8125rem;
  margin-top: 2px;
  word-break: break-all;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}
.row-body .c {
  color: var(--ink-dim);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 4px;
}
.row-actions { display: flex; gap: 6px; }

/* login */
.login-card {
  max-width: 380px;
  margin: 18vh auto 0;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
}
.login-card h2 {
  font-family: var(--font-display);
  margin: 0 0 6px;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
}
.login-card p { margin: 0 0 1.5rem; color: var(--ink-dim); font-size: 0.9375rem; }
.login-card .btn-primary { padding: 0.875rem 2.25rem; }

/* form fields */
.field { display: block; margin-bottom: 1rem; }
.field label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}
.field input, .field textarea, .field select {
  width: 100%;
  padding: 0.8rem 1.25rem;
  background: var(--night);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.9375rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field input::placeholder, .field textarea::placeholder {
  color: var(--ink-dim);  /* Muted is the floor — placeholders stay AA-legible */
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--glow-violet);
}
/* a pill textarea reads wrong — the one shape deviation from the input spec */
.field textarea { resize: vertical; min-height: 80px; border-radius: var(--r-lg); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .form-row { grid-template-columns: 1fr; } }

/* modal — the scrim is the one sanctioned frosted surface (One-Glass Rule) */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(10, 9, 18, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 100;
  animation: fadeIn 0.15s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%;
  max-width: 480px;
  background: var(--calm);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  padding: 2rem;
}
.modal h3 {
  font-family: var(--font-display);
  margin: 0 0 1.5rem;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 1.5rem; }

/* toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-solid);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0.7rem 1.25rem;
  border-radius: var(--r-full);
  font-size: 0.875rem;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.err { color: var(--danger); border-color: rgba(255, 143, 160, 0.4); }

.error {
  color: var(--danger);
  font-size: 0.8125rem;
  margin-top: 8px;
  min-height: 18px;
}

/* ── forms ───────────────────────────────────── */

/* tabs — an active nav state, so it takes violet, not the rationed glow */
.tabs {
  display: flex;
  gap: 4px;
  margin: -8px 0 20px;
  border-bottom: 1px solid var(--line);
}
.tab {
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--ink-dim);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 10px 14px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--ink); border-bottom-color: var(--accent); }

/* public form page */
.shell-form { max-width: 560px; }
/* Display is reserved for the portal hero. A form's title is user-supplied
   and belongs on the Heading step so long titles stay sane. */
.shell-form .headline {
  font-size: clamp(1.875rem, 4vw, 3rem);
  line-height: 1.1;
  letter-spacing: -0.01em;
}
.public-form {
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  background: var(--surface);
  padding: 2rem;
}
.public-form .field input,
.public-form .field textarea,
.public-form .field select { padding: 1rem 1.5rem; font-size: 1rem; }
.public-form .btn-primary { padding: 1rem 2.25rem; }
.field-help {
  font-size: 0.8125rem;
  color: var(--ink-dim);
  margin: -2px 0 8px;
  line-height: 1.45;
}
.req { color: var(--danger); }

/* honeypot — off-screen rather than display:none so bots still see it */
.hp {
  position: absolute !important;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9375rem;
  color: var(--ink-warm);
  cursor: pointer;
  padding: 7px 0;
}
.choice input { width: 16px; height: 16px; accent-color: var(--accent); flex-shrink: 0; }
.choice-group { display: flex; flex-direction: column; gap: 2px; }

/* form builder */
.modal-wide { max-width: 720px; max-height: 88vh; overflow-y: auto; }

/* Never nest cards — the builder is a hairline-divided region, not a box,
   so the field rows below are the only card level inside the modal. */
.builder {
  border: none;
  border-top: 1px solid var(--line);
  background: none;
  padding: 1.5rem 0 0;
  margin-top: 1.5rem;
}
.builder-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.field-row {
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  padding: 0.875rem;
  background: var(--surface);
}
.field-row-top {
  display: grid;
  grid-template-columns: 1fr 140px auto auto auto auto;
  gap: 8px;
  align-items: center;
}
.field-row input[type="text"],
.field-row .fr-label,
.field-row .fr-options,
.field-row .fr-ph,
.field-row select {
  width: 100%;
  padding: 0.5rem 0.9rem;
  background: var(--night);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.8125rem;
}
.field-row .fr-options,
.field-row .fr-ph { margin-top: 8px; }
.field-row input:focus, .field-row select:focus {
  outline: none;
  border-color: var(--accent);
}
.fr-req { white-space: nowrap; font-size: 0.8125rem; color: var(--ink-dim); padding: 0; }
.fr-move { padding: 0.45rem 0.75rem; }
.fr-move:disabled { opacity: 0.3; cursor: default; }
.field-row .btn-danger { padding: 0.45rem 0.8rem; }

@media (max-width: 620px) {
  .field-row-top { grid-template-columns: 1fr 1fr; }
  .fr-req { grid-column: 1 / -1; }
}

/* responses */
.resp-body { min-height: 80px; }
.resp-count {
  margin: 0 0 10px;
  font-size: 0.8125rem;
  color: var(--ink-dim);
  letter-spacing: 0.02em;
}
.resp-scroll {
  overflow-x: auto;
  max-height: 55vh;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.resp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.resp-table th, .resp-table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.resp-table th {
  position: sticky;
  top: 0;
  background: var(--night);
  color: var(--ink-dim);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.resp-table tr:last-child td { border-bottom: none; }
.resp-when { color: var(--ink-dim); font-size: 0.8125rem; }

/* Every animation gets a reduced-motion fallback. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .card:hover, .row:hover { transform: none; }
  .card:hover .card-arrow { transform: none; }
}
