:root {
  /* Valterra Platinum brand palette: deep teal + slate blue-grey */
  --brand-900: #00343a;
  --brand-700: #005661;
  --brand-600: #007681;
  --brand-500: #0a8a94;
  --brand-400: #3fa3ab;
  --accent: #7e96a1;      /* slate blue-grey (logo secondary) */
  --accent-light: #97abb4;
  --bg: #f3f5f6;
  --surface: #ffffff;
  --text: #16282b;
  --text-muted: #5e7177;
  --border: #dde5e7;
  --danger: #c0392b;
  --success: #007681;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 40px -12px rgba(0, 52, 58, 0.18);
  --shadow-sm: 0 2px 10px -4px rgba(0, 52, 58, 0.15);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(1200px 500px at 100% -10%, rgba(0, 118, 129, 0.12), transparent 60%),
    radial-gradient(900px 500px at -10% 0%, rgba(126, 150, 161, 0.14), transparent 55%);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.page {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: clamp(1rem, 4vw, 3rem) clamp(1rem, 4vw, 2rem);
}

/* ---------- Entry view switching (landing vs survey) ---------- */
/* The inline head script adds `has-survey` to <html> only when the link carries ?survey=<key>. */
#landing { display: none; }
#survey-shell { display: none; }
html:not(.has-survey) #landing { display: flex; }
html.has-survey #survey-shell { display: block; }

/* ---------- Generic landing page ---------- */
.landing {
  min-height: 100vh;
  flex-direction: column;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: clamp(1rem, 4vw, 2rem);
}
.landing__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0 1.5rem;
}
.landing__logo { height: 40px; width: auto; }
.landing__signin {
  display: inline-flex;
  align-items: center;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--brand-700);
  text-decoration: none;
  padding: 0.5rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
.landing__signin:hover { color: var(--brand-600); border-color: var(--brand-400); transform: translateY(-1px); }

.landing__hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(1.5rem, 6vw, 4rem) 0;
  max-width: 760px;
}
.landing__eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--brand-600);
}
.landing__title {
  font-size: clamp(1.9rem, 5vw, 3rem);
  line-height: 1.1;
  margin: 0.6rem 0 1rem;
  color: var(--brand-900);
}
.landing__lead {
  font-size: clamp(1rem, 2.2vw, 1.2rem);
  color: var(--text-muted);
  max-width: 60ch;
}
.landing__link {
  color: var(--brand-700, #007681);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid currentColor;
}
.landing__link:hover,
.landing__link:focus-visible { color: var(--brand-600, #005661); }

.landing__cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.1rem;
  margin-top: 2.25rem;
}
.landing__card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.4rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
}
.landing__card-title { font-size: 1.1rem; color: var(--brand-900); }
.landing__card-text { color: var(--text-muted); font-size: 0.95rem; }
.landing__card-cta { margin-top: 0.6rem; }

.landing__footer {
  padding: 1.5rem 0 0.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

@media (max-width: 640px) {
  .landing__cards { grid-template-columns: 1fr; }
}

/* ---------- Survey card ---------- */
.survey {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.survey__header {
  position: relative;
  padding: clamp(1.5rem, 4vw, 2.5rem);
  background: var(--surface);
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

/* Teal accent strip echoing the brand colour */
.survey__header::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 5px;
  background: linear-gradient(90deg, var(--brand-600), var(--accent));
}

/* Header top row: brand logo on the left, optional accreditation badge on the right. */
.survey__header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
}
.survey__header-top .brand { margin-bottom: 0; }

/* Top Employer (or similar) accreditation badge, right-aligned in the header. */
.survey__badge {
  height: clamp(45px, 9.8vw, 67px);
  width: auto;
  display: block;
  flex: 0 0 auto;
}
.survey__badge[hidden] { display: none; }

.brand {
  display: flex;
  align-items: center;
  margin-bottom: 1.25rem;
}

.brand__logo {
  height: auto;
  width: clamp(170px, 45%, 220px);
  display: block;
}

.survey__title {
  font-size: clamp(1.5rem, 4vw, 2.1rem);
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 0.75rem;
  color: var(--brand-700);
}

.survey__intro {
  color: var(--text-muted);
  font-size: 0.98rem;
  max-width: 60ch;
}

.survey__progress {
  margin-top: 1.5rem;
  height: 8px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  overflow: hidden;
}

.survey__progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand-600), var(--brand-400));
  transition: width 0.35s ease;
}

.survey__progress-label {
  margin-top: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ---------- Questions ---------- */
.questions {
  padding: clamp(1rem, 4vw, 1.75rem) clamp(1.5rem, 4vw, 2.5rem);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.question {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.1rem 1.15rem;
  background: var(--surface);
  /* fieldsets default to min-width:min-content, which can prevent the inner
     grids (esp. the 11-column NPS row) from shrinking on narrow screens */
  min-width: 0;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.question.is-answered {
  border-color: rgba(0, 118, 129, 0.45);
  background: rgba(0, 118, 129, 0.035);
}

.question.is-invalid {
  border-color: var(--danger);
  background: rgba(192, 57, 43, 0.04);
}

.question__head {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}

.question__num {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  border-radius: 7px;
  background: var(--brand-600);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
}

.question__text {
  font-size: 0.98rem;
  font-weight: 500;
  color: var(--text);
}

.question__required {
  color: var(--danger);
  margin-left: 2px;
}

/* ---------- Scale options ---------- */
.scale {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.4rem;
}

.scale__option {
  position: relative;
}

.scale__option input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.scale__label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  text-align: center;
  height: 100%;
  min-height: 64px;
  padding: 0.55rem 0.35rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  transition: all 0.18s ease;
  user-select: none;
}

.scale__dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border);
  transition: all 0.18s ease;
}

.scale__option input:hover + .scale__label,
.scale__label:hover {
  border-color: var(--brand-400);
  color: var(--brand-700);
}

.scale__option input:focus-visible + .scale__label {
  outline: 3px solid rgba(0, 118, 129, 0.35);
  outline-offset: 2px;
}

.scale__option input:checked + .scale__label {
  border-color: var(--brand-500);
  background: var(--brand-500);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.scale__option input:checked + .scale__label .scale__dot {
  border-color: #fff;
  background: #fff;
}

/* ---------- NPS 0-10 ---------- */
.nps {
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  gap: 0.35rem;
}

.nps__option input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.nps__label {
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-muted);
  background: var(--surface);
  transition: all 0.18s ease;
  user-select: none;
}

.nps__label:hover {
  border-color: var(--brand-400);
  color: var(--brand-700);
}

.nps__option input:focus-visible + .nps__label {
  outline: 3px solid rgba(0, 118, 129, 0.35);
  outline-offset: 2px;
}

.nps__option input:checked + .nps__label {
  border-color: var(--brand-500);
  background: var(--brand-500);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.nps__ends {
  display: flex;
  justify-content: space-between;
  margin-top: 0.55rem;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* ---------- Open text ---------- */
.open-text {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.9rem;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.open-text:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(0, 118, 129, 0.18);
}

.char-count {
  display: block;
  text-align: right;
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

/* ---------- Multiple choice (multi-select) ---------- */
.choice__hint {
  margin: 0 0 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.choice {
  display: grid;
  gap: 0.5rem;
}

.choice__option {
  position: relative;
}

.choice__option input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.choice__label {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.choice__box {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  border-radius: 5px;
  border: 2px solid var(--border);
  transition: all 0.18s ease;
}

.choice__option input:hover + .choice__label,
.choice__label:hover {
  border-color: var(--brand-400);
  color: var(--brand-700);
}

.choice__option input:focus-visible + .choice__label {
  outline: 3px solid rgba(0, 118, 129, 0.35);
  outline-offset: 2px;
}

.choice__option input:checked + .choice__label {
  border-color: var(--brand-500);
  background: rgba(0, 118, 129, 0.08);
  color: var(--brand-700);
}

.choice__option input:checked + .choice__label .choice__box {
  border-color: var(--brand-500);
  background: var(--brand-500);
  box-shadow: inset 0 0 0 3px #fff;
}

.choice__option input:disabled + .choice__label {
  opacity: 0.5;
  cursor: not-allowed;
}

.optional-tag {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 1px 8px;
  border-radius: 999px;
  margin-left: 0.5rem;
}

.error-msg {
  display: none;
  margin-top: 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--danger);
}

.question.is-invalid .error-msg {
  display: block;
}

/* ---------- Actions ---------- */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0 clamp(1.5rem, 4vw, 2.5rem) 1.25rem;
}

.btn {
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 0.8rem 1.5rem;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: transform 0.12s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn--primary {
  background: var(--brand-600);
  color: #fff;
  flex: 1;
  min-width: 200px;
  box-shadow: var(--shadow-sm);
}

.btn--primary:hover {
  background: var(--brand-700);
}

.btn--ghost {
  background: transparent;
  color: var(--brand-700);
  border-color: var(--border);
}

.btn--ghost:hover {
  border-color: var(--brand-400);
  background: rgba(0, 118, 129, 0.06);
}

.form-note {
  min-height: 1.2rem;
  padding: 0 clamp(1.5rem, 4vw, 2.5rem) 1.5rem;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--danger);
}

/* ---------- Thank you ---------- */
.thank-you {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(2rem, 6vw, 3.5rem);
  text-align: center;
  animation: fade-in 0.4s ease;
}

.thank-you__icon {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  margin: 0 auto 1.25rem;
  border-radius: 50%;
  background: rgba(0, 118, 129, 0.12);
  color: var(--success);
}

.thank-you h2 {
  font-size: 1.6rem;
  margin-bottom: 0.6rem;
}

.thank-you p {
  color: var(--text-muted);
  max-width: 46ch;
  margin: 0 auto 1.5rem;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Loading / error state cards ---------- */
.state-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(2rem, 6vw, 3.5rem);
  text-align: center;
}

.brand--center {
  justify-content: center;
  margin-bottom: 1.25rem;
}

.state-card__title {
  font-size: 1.5rem;
  color: var(--brand-700);
  margin-bottom: 0.5rem;
}

.state-card__msg {
  color: var(--text-muted);
  max-width: 46ch;
  margin: 0 auto;
}

/* Loading variant: centred spinner above the message so slow loads clearly read as "working".
   Scoped with :not([hidden]) so the flex layout never overrides the `hidden` attribute (which the
   scripts toggle to show/hide the card) — otherwise the spinner would stay visible after load. */
.state-card--loading:not([hidden]) {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.state-card__spinner {
  width: 38px;
  height: 38px;
  border: 3px solid var(--border);
  border-top-color: var(--brand-600, #007681);
  border-radius: 50%;
  animation: pv-spin 0.8s linear infinite;
}
@keyframes pv-spin { to { transform: rotate(360deg); } }

/* Shimmer skeleton for content that is still loading (e.g. per-card stats). */
.skeleton {
  display: block;
  border-radius: 6px;
  background: linear-gradient(90deg, rgba(15, 41, 66, 0.06) 25%, rgba(15, 41, 66, 0.12) 37%, rgba(15, 41, 66, 0.06) 63%);
  background-size: 400% 100%;
  animation: pv-shimmer 1.4s ease infinite;
}
@keyframes pv-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  .state-card__spinner { animation-duration: 1.8s; }
  .skeleton { animation: none; }
}

/* ---------- Footer ---------- */
.page__footer {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.footer__link {
  color: var(--brand-700, #007681);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid currentColor;
}
.footer__link:hover,
.footer__link:focus-visible { color: var(--brand-600, #005661); }

/* ---------- Responsive ---------- */
@media (min-width: 620px) {
  .scale__label { font-size: 0.78rem; }
}

@media (max-width: 560px) {
  .scale {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }
  .scale__label {
    flex-direction: row;
    justify-content: flex-start;
    gap: 0.7rem;
    min-height: 0;
    padding: 0.7rem 0.9rem;
    font-size: 0.9rem;
  }
  .nps {
    grid-template-columns: repeat(6, 1fr);
  }
  .nps__label {
    aspect-ratio: auto;
    padding: 0.6rem 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
