/* =========================================================================
   Hyred tracking form — design system
   ========================================================================= */

:root {
  color-scheme: light dark;

  /* Brand. #28ce73 is too light to carry white text (≈1.8:1), so the primary
     button pairs the brand green with a near-black green ink instead, and a
     darker green is reserved for green-on-white text. */
  --brand: #28ce73;
  --brand-hover: #22b162;
  --brand-ink: #04301b;
  --brand-text: #0b6d3d;
  --brand-soft: #e8faf0;

  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --text: #0f1720;
  --text-muted: #5b6672;
  --text-faint: #8b949e;
  --border: #e2e7ec;
  --border-strong: #cbd3db;
  --field-bg: #ffffff;

  --danger: #c1392b;
  --danger-soft: #fdecea;
  --focus-ring: 0 0 0 3px rgba(40, 206, 115, 0.32);

  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 32, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 32, 0.08);
  --shadow-lg: 0 16px 48px rgba(15, 23, 32, 0.14);

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --maxw: 780px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c222b;
    --text: #e6edf3;
    --text-muted: #9aa5b1;
    --text-faint: #6e7781;
    --border: #2a313a;
    --border-strong: #3a424d;
    --field-bg: #0f141a;

    --brand-text: #4ade8e;
    --brand-soft: #10281c;
    --danger: #ff7b6b;
    --danger-soft: #2d1614;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.6);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header ---------------------------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(150%) blur(10px);
  border-bottom: 1px solid var(--border);
}

.site-header__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.logo img {
  height: 26px;
  width: auto;
  display: block;
}

/* ---------- Progress -------------------------------------------------- */

.progress {
  height: 3px;
  background: var(--border);
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  width: 0%;
  background: var(--brand);
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Layout ---------------------------------------------------- */

.page {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 32px 20px 120px;
}

.page-intro {
  margin-bottom: 28px;
}

.page-intro h1 {
  margin: 0 0 6px;
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.page-intro p {
  margin: 0;
  color: var(--text-muted);
  max-width: 56ch;
}

/* ---------- Sections -------------------------------------------------- */

.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
  overflow: hidden;
}

.section__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 22px 0;
}

.section__num {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-text);
  font-size: 0.78rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.section__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 620;
  letter-spacing: -0.01em;
}

.section__hint {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.section__body {
  padding: 16px 22px 22px;
  display: grid;
  gap: 16px;
}

/* ---------- Grid ------------------------------------------------------ */

.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr));
}

.grid--3 {
  --cols: 3;
}

.grid--postal {
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr);
}

@media (max-width: 640px) {
  .grid,
  .grid--postal {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---------- Fields ---------------------------------------------------- */

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
  /* Fields sit in a stretched grid row. Without this, a field with no error
     line (e.g. "Addition") stretches its own rows to match the taller
     neighbours and the input grows into a giant box. */
  align-content: start;
}

/* The hint and error lines are <p>: drop the UA's 1em margins, which otherwise
   open a big gap between a field and its message. */
.field > p {
  margin: 0;
}

.field > label {
  font-size: 0.85rem;
  font-weight: 550;
  color: var(--text);
}

.req {
  color: var(--danger);
  margin-left: 2px;
}

.optional {
  color: var(--text-faint);
  font-weight: 400;
  margin-left: 4px;
  font-size: 0.78rem;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="search"],
select,
textarea {
  width: 100%;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--field-bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 10px 12px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  appearance: none;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

select {
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%235b6672' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  cursor: pointer;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-faint);
}

/* A select still sitting on its empty placeholder option should read as a
   placeholder, not as a chosen value. */
select:has(option[value=""]:checked) {
  color: var(--text-faint);
}

select option {
  color: var(--text);
}

input:hover:not(:disabled),
select:hover:not(:disabled),
textarea:hover:not(:disabled) {
  border-color: var(--text-faint);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--focus-ring);
}

/* Border and message only — filling every empty field with pink turns a normal
   "you missed some fields" state into a wall of red. */
.field--invalid input,
.field--invalid select,
.field--invalid textarea {
  border-color: var(--danger);
}

.field--invalid input:focus-visible,
.field--invalid select:focus-visible,
.field--invalid textarea:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 22%, transparent);
}

.field__error {
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--danger);
}

.field__error:empty {
  display: none;
}

.field__hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ---------- File upload ----------------------------------------------- */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 26px 18px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-text);
}

.dropzone:focus-within {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--focus-ring);
}

.dropzone__icon {
  color: var(--text-muted);
}

.dropzone:hover .dropzone__icon,
.dropzone.is-dragover .dropzone__icon {
  color: var(--brand-text);
}

.dropzone__text {
  font-size: 0.92rem;
  font-weight: 550;
}

.dropzone__meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.upload {
  display: grid;
  min-width: 0;
  gap: 8px;
  padding: 14px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.upload--done {
  grid-template-columns: 36px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  background: var(--surface);
  color: var(--text);
}

.upload__icon {
  padding: 8px;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--brand-text);
}

.upload__file {
  min-width: 0;
}

.upload__filename {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.upload__size {
  display: block;
  margin-top: 3px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.upload__row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.85rem;
}

.upload__name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.88rem;
}

.upload__pct {
  flex: none;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.upload__track {
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
}

.upload__bar {
  height: 100%;
  width: 0%;
  background: var(--brand);
  transition: width 0.2s ease;
}

.btn--sm {
  padding: 5px 10px;
  font-size: 0.8rem;
}

.upload .btn--sm {
  justify-self: start;
}

.upload--done .btn--sm {
  padding: 8px 12px;
  min-height: 38px;
  text-decoration: none;
  white-space: normal;
}

.upload__actions svg {
  flex: none;
}

.upload__actions {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  min-width: 0;
  gap: 8px;
}

@media (max-width: 560px) {
  .upload__actions {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .upload__actions .btn--sm {
    min-width: 0;
    width: 100%;
    justify-self: stretch;
  }

  .upload__actions svg {
    display: none;
  }
}

/* Honeypot — hidden from people, reachable by naive bots. */
.hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* ---------- Segmented control (gender) -------------------------------- */

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--field-bg);
  font-size: 0.95rem;
  font-weight: 550;
  cursor: pointer;
  transition: all 0.15s;
}

.segmented label:hover {
  border-color: var(--text-faint);
}

.segmented input:checked + label {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-text);
  box-shadow: inset 0 0 0 1px var(--brand);
}

.segmented input:focus-visible + label {
  box-shadow: var(--focus-ring);
}

/* ---------- Buttons --------------------------------------------------- */

.btn {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius);
  padding: 11px 18px;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s, transform 0.06s;
  white-space: nowrap;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--brand);
  color: var(--brand-ink);
}

.btn--primary:hover:not(:disabled) {
  background: var(--brand-hover);
}

.btn--secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn--secondary:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--text-faint);
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 8px 12px;
}

.btn--ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.btn--danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--border-strong);
}

.btn--danger:hover:not(:disabled) {
  background: var(--danger-soft);
  border-color: var(--danger);
}

.btn--block {
  width: 100%;
}

.btn--lg {
  padding: 14px 22px;
  font-size: 1rem;
}

/* Language switcher in the header */
.lang-select {
  padding: 7px 30px 7px 10px;
  font-size: 0.85rem;
  border-radius: 8px;
  background-color: transparent;
  border-color: var(--border);
  width: auto;
  max-width: 190px;
}

/* ---------- Submit bar ------------------------------------------------ */

.submit-bar {
  position: sticky;
  bottom: 0;
  margin: 22px -20px -120px;
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(150%) blur(10px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  justify-content: space-between;
  flex-wrap: wrap;
}

.submit-bar__status {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 0;
}

.submit-bar .btn {
  flex: 0 0 auto;
}

@media (max-width: 560px) {
  .submit-bar {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .submit-bar__status {
    text-align: center;
  }
}

/* ---------- Notices --------------------------------------------------- */

.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 0.88rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  margin-bottom: 18px;
}

.notice--brand {
  background: var(--brand-soft);
  border-color: color-mix(in srgb, var(--brand) 35%, transparent);
  color: var(--text);
}

.notice--error {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
  color: var(--danger);
}

.notice svg {
  flex: none;
  margin-top: 1px;
}

/* ---------- Result / success ----------------------------------------- */

.result {
  text-align: center;
  padding: 8px 0 4px;
}

.result__icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-text);
  display: grid;
  place-items: center;
  margin: 0 auto 16px;
}

.result h2 {
  margin: 0 0 6px;
  font-size: 1.3rem;
  letter-spacing: -0.01em;
}

.result p {
  margin: 0 auto 20px;
  color: var(--text-muted);
  max-width: 46ch;
}

.copy-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.copy-row input {
  flex: 1 1 auto;
  font-family: var(--mono);
  font-size: 0.88rem;
  background: var(--surface-2);
  cursor: pointer;
  min-width: 0;
}

@media (max-width: 480px) {
  .copy-row {
    flex-direction: column;
  }
}

.result__actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 18px;
  flex-wrap: wrap;
}

/* ---------- Summary (read-back of a submitted record) ----------------- */

.summary {
  display: grid;
  grid-template-columns: minmax(120px, 34%) minmax(0, 1fr);
  gap: 0;
  font-size: 0.9rem;
}

.summary dt {
  color: var(--text-muted);
  padding: 7px 0;
  border-top: 1px solid var(--border);
}

.summary dd {
  margin: 0;
  padding: 7px 0;
  border-top: 1px solid var(--border);
  word-break: break-word;
}

.summary dt:first-of-type,
.summary dt:first-of-type + dd {
  border-top: none;
}

/* ---------- Utility --------------------------------------------------- */

.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;
}

[hidden] {
  display: none !important;
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.site-footer {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 28px 20px 40px;
  color: var(--text-faint);
  font-size: 0.8rem;
  text-align: center;
}

.site-footer a {
  color: var(--text-muted);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* =========================================================================
   Admin
   ========================================================================= */

.admin-page {
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.admin-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.admin-toolbar__search {
  flex: 1 1 260px;
  min-width: 0;
}

.login-card {
  max-width: 380px;
  margin: 10vh auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 28px;
  display: grid;
  gap: 16px;
}

.login-card h1 {
  margin: 0;
  font-size: 1.2rem;
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow-x: auto;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  white-space: nowrap;
}

table.data th,
table.data td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

table.data th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--text-muted);
  position: sticky;
  top: 0;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

table.data tbody tr:hover {
  background: var(--surface-2);
}

table.data tbody tr:last-child td {
  border-bottom: none;
}

.code-pill {
  font-family: var(--mono);
  font-size: 0.8rem;
  background: var(--brand-soft);
  color: var(--brand-text);
  padding: 2px 7px;
  border-radius: 5px;
  text-decoration: none;
}

.code-pill:hover {
  text-decoration: underline;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-muted);
}

/* ---------- Revision history ------------------------------------------ */

.link-button {
  background: none;
  border: none;
  padding: 2px 0 0;
  font: inherit;
  font-size: 0.72rem;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: underline;
}

.link-button:hover {
  color: var(--brand-text);
}

.revision {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: var(--surface-2);
}

.revision + .revision {
  margin-top: 12px;
}

.revision__head {
  font-size: 0.82rem;
  font-weight: 620;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* A value that differs from the revision below it. */
.revision .is-changed {
  color: var(--brand-text);
  font-weight: 560;
}

.revision .was {
  color: var(--text-faint);
  font-weight: 400;
  font-size: 0.82rem;
}

#history-panel .section__head {
  display: flex;
  align-items: center;
}
