:root {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --surface-alt: #f5f8fb;
  --ink: #1a2332;
  --ink-soft: #354a60;
  --muted: #6b7c93;
  --line: #e0e8f0;
  --line-strong: #c8d5e2;
  --accent: #0b6b75;
  --accent-dark: #074f57;
  --accent-light: #0e8c9a;
  --accent-soft: #ddf0f2;
  --accent-mid: #b3dde2;
  --danger: #c5382e;
  --danger-soft: #fdf0ef;
  --danger-border: #f5b8b4;
  --ok: #1d7a44;
  --ok-soft: #e3f5eb;
  --ok-border: #a8dbb9;
  --shadow-sm: 0 1px 3px rgba(26, 35, 50, 0.05), 0 4px 12px rgba(26, 35, 50, 0.04);
  --shadow: 0 2px 8px rgba(26, 35, 50, 0.06), 0 8px 28px rgba(26, 35, 50, 0.07);
  --shadow-lg: 0 8px 32px rgba(26, 35, 50, 0.10), 0 2px 8px rgba(26, 35, 50, 0.05);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 24px;
  --sidebar-w: 248px;
}

*, *::before, *::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

img, canvas {
  max-width: 100%;
}

/* ─── HEADER ─────────────────────────────────────────────── */

.app-header {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #063d44 0%, #0b6b75 55%, #0e8a96 100%);
  color: white;
}

.app-header::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 20% 50%, rgba(255,255,255,0.06) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(255,255,255,0.04) 0%, transparent 40%);
  pointer-events: none;
}

.app-header::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 48px;
  background: var(--bg);
  clip-path: ellipse(55% 100% at 50% 100%);
}

.header-inner {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: clamp(32px, 5vw, 56px) 0 clamp(72px, 9vw, 100px);
}

.header-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.22);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #c8f0f3;
}

h1 {
  margin: 0 0 12px;
  max-width: 20ch;
  font-size: clamp(1.65rem, 2.4vw + 0.6rem, 2.7rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0;
  font-size: clamp(1.2rem, 1.1vw + 0.85rem, 1.6rem);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
}

p {
  margin: 12px 0 0;
}

.lead {
  margin: 0 0 18px;
  max-width: 56ch;
  font-size: clamp(1rem, 0.4vw + 0.85rem, 1.1rem);
  color: #caeaed;
  line-height: 1.55;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.meta-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  color: rgba(255,255,255,0.7);
}

.meta-sep {
  width: 1px;
  height: 14px;
  background: rgba(255,255,255,0.3);
}

/* ─── LAYOUT ─────────────────────────────────────────────── */

.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: 28px;
  width: min(1180px, calc(100% - 40px));
  margin: clamp(-56px, -5vw, -36px) auto 72px;
}

/* ─── SIDEBAR ────────────────────────────────────────────── */

.sidebar {
  position: sticky;
  top: 20px;
  align-self: start;
  padding: 16px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,0.8);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
}

.sidebar-nav::before {
  content: "";
  position: absolute;
  left: 23px;
  top: 20px;
  bottom: 20px;
  width: 2px;
  background: var(--line);
  z-index: 0;
}

.nav-item {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  transition: background 0.14s, color 0.14s;
}

.nav-item:hover {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.nav-item.active {
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-weight: 600;
}

.step-dot {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--line-strong);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  transition: background 0.14s, border-color 0.14s, color 0.14s;
  flex-shrink: 0;
}

.nav-item.active .step-dot {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.nav-item:hover .step-dot {
  border-color: var(--accent-mid);
}

.step-label {
  line-height: 1.3;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* ─── SURVEY ─────────────────────────────────────────────── */

.survey {
  display: grid;
  gap: 20px;
  min-width: 0;
}

.section-block {
  padding: clamp(22px, 3vw, 36px);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--line);
  min-width: 0;
}

.section-heading {
  margin-bottom: 20px;
}

.section-heading h2 {
  margin-top: 6px;
}

.section-kicker {
  display: inline-block;
  padding: 8px 11px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.section-desc {
  margin: 0 0 20px;
  color: var(--ink-soft);
}

.notice {
  margin-top: 20px;
  padding: 14px 18px;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--accent-soft);
  color: var(--ink-soft);
  font-size: 0.9rem;
  line-height: 1.55;
}

/* ─── DEMOGRAPHY GRID ────────────────────────────────────── */

.field-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

/* ─── QUESTION CARDS ─────────────────────────────────────── */

.stack {
  display: grid;
  gap: 16px;
}

.question-card {
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  min-width: 0;
  overflow: hidden;
}

/* label.question-card (textarea wrappers) keep their own padding */
label.question-card {
  padding: 18px 20px;
}

.question-legend {
  margin: 0;
  padding: 16px 20px 12px;
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--ink);
}

.question-card > .option-list {
  padding: 4px 20px 16px;
}

.question-card > .hint {
  margin: 0;
  padding: 0 20px 4px;
}

.question-card > .text-field {
  padding: 0 20px 16px;
}

.option-list {
  display: grid;
  gap: 6px;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
  color: var(--ink-soft);
  user-select: none;
}

.option:hover {
  background: rgba(11, 107, 117, 0.06);
}

.option:has(input:checked) {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.option input[type="radio"],
.option input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  background: white;
  border: 2px solid var(--line-strong);
  cursor: pointer;
  transition: border-color 0.14s, background 0.14s, box-shadow 0.14s;
}

.option input[type="radio"] {
  border-radius: 50%;
}

.option input[type="radio"]:checked {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: inset 0 0 0 4px white;
}

.option input[type="checkbox"] {
  border-radius: 6px;
}

.option input[type="checkbox"]:checked {
  border-color: var(--accent);
  background: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2 6l3 3 5-6' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E");
  background-size: 12px;
  background-position: center;
  background-repeat: no-repeat;
}

.option input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.option span {
  font-size: 0.9rem;
  line-height: 1.45;
}

/* ─── OCAI ───────────────────────────────────────────────── */

.ocai-list {
  display: grid;
  gap: 16px;
}

.ocai-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: clip;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.ocai-card.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(197, 56, 46, 0.08);
}

.ocai-card header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-alt);
}

.ocai-card header > div {
  flex: 1 1 180px;
  min-width: 0;
}

.ocai-card header h3 {
  margin-top: 5px;
  font-size: 0.97rem;
  color: var(--ink);
}

.ocai-card .section-kicker {
  font-size: 0.68rem;
  padding: 8px 13px;
  margin: 0;
}

.sum-badge {
  flex: 0 0 auto;
  align-self: flex-start;
  padding: 5px 13px;
  border-radius: 999px;
  border: 1.5px solid var(--line-strong);
  background: white;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transition: background 0.14s, border-color 0.14s, color 0.14s;
}

.sum-badge.valid {
  border-color: var(--ok-border);
  background: var(--ok-soft);
  color: var(--ok);
}

.sum-badge.invalid {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}

.ocai-options {
  display: grid;
}

.ocai-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  grid-template-areas:
    "letter text"
    ".      control";
  column-gap: 14px;
  row-gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
}

.ocai-row:first-child {
  border-top: none;
}

.ocai-row:hover {
  background: rgba(11, 107, 117, 0.03);
}

.ocai-text {
  grid-area: text;
  min-width: 0;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--ink-soft);
  align-self: center;
}

.ocai-buttons {
  grid-area: control;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding-bottom: 2px;
}

.ocai-btn-label {
  cursor: pointer;
}

.ocai-btn-label input[type="radio"] {
  display: none;
}

.ocai-btn-label span {
  display: block;
  min-width: 38px;
  padding: 5px 6px;
  text-align: center;
  border: 1.5px solid var(--line-strong);
  border-radius: 7px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.1s, border-color 0.1s, color 0.1s;
  user-select: none;
}

.ocai-btn-label:hover span {
  border-color: var(--accent-mid);
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.ocai-btn-label input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.ocai-btn-label:has(input:disabled) {
  cursor: not-allowed;
}

.ocai-btn-label:has(input:disabled) span {
  opacity: 0.28;
  pointer-events: none;
}

.letter {
  grid-area: letter;
  align-self: start;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.ocai-row[data-type="A"] .letter { background: #ddf0f2; color: #0b6b75; }
.ocai-row[data-type="B"] .letter { background: #f5ece0; color: #8a5010; }
.ocai-row[data-type="C"] .letter { background: #faeaea; color: #8a2828; }
.ocai-row[data-type="D"] .letter { background: #eaedf1; color: #465570; }


/* ─── TEXTAREA ───────────────────────────────────────────── */

textarea {
  width: 100%;
  min-height: 112px;
  resize: vertical;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: white;
  font-size: 0.95rem;
  line-height: 1.55;
  transition: border-color 0.12s, box-shadow 0.12s;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 107, 117, 0.16);
}

.text-field {
  display: grid;
  gap: 8px;
}

.text-field > span {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.4;
}

.hint {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ─── ACTIONS / BUTTONS ──────────────────────────────────── */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: white;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(11, 107, 117, 0.28);
  transition: background 0.14s, box-shadow 0.14s, transform 0.08s;
}

.primary-button:hover {
  background: var(--accent-dark);
  box-shadow: 0 6px 18px rgba(11, 107, 117, 0.34);
}

.primary-button:active {
  transform: translateY(1px);
  box-shadow: 0 2px 8px rgba(11, 107, 117, 0.22);
}

.primary-button:disabled {
  opacity: 0.58;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  padding: 12px 20px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: white;
  color: var(--ink-soft);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.secondary-button:hover {
  background: var(--surface-alt);
  border-color: var(--accent-mid);
  color: var(--accent-dark);
}

/* ─── STATUS MESSAGES ────────────────────────────────────── */

.error-summary {
  margin-top: 18px;
  padding: 14px 18px;
  border: 1.5px solid var(--danger-border);
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  display: grid;
  gap: 6px;
  font-size: 0.9rem;
  line-height: 1.5;
}

.submit-status {
  margin-top: 18px;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  line-height: 1.55;
}

.submit-status.is-error {
  border: 1.5px solid var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}

.submit-status.is-loading {
  border: 1.5px solid var(--accent-mid);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.submit-status strong {
  display: block;
  margin-bottom: 3px;
  font-weight: 700;
}

/* ─── SUCCESS SCREEN ─────────────────────────────────────── */

.success-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg);
  display: grid;
  place-items: center;
  padding: 24px;
  animation: fadeIn 0.35s ease;
}

.success-card {
  max-width: 480px;
  width: 100%;
  padding: 52px 44px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--line);
  text-align: center;
}

.success-icon {
  margin-bottom: 24px;
  animation: popIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.1s both;
}

.success-card h2 {
  margin-bottom: 12px;
  font-size: 1.75rem;
  color: var(--accent-dark);
}

.success-card p {
  margin: 0 0 10px;
  color: var(--ink-soft);
  font-size: 1rem;
  line-height: 1.6;
}

.success-note {
  color: var(--muted) !important;
  font-size: 0.875rem !important;
  margin-top: 16px;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popIn {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ─── TABLET + MOBILE NAV (≤ 980px) ─────────────────────── */

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
    width: min(1180px, calc(100% - 32px));
    gap: 16px;
  }

  .sidebar {
    display: none;
  }
}

/* ─── MOBILE (≤ 640px) ───────────────────────────────────── */

@media (max-width: 640px) {
  :root {
    --radius: 14px;
    --radius-sm: 8px;
  }

  body {
    font-size: 15px;
  }

  .header-inner {
    width: calc(100% - 32px);
    padding-top: 28px;
    padding-bottom: clamp(64px, 16vw, 80px);
  }

  h1 {
    font-size: 1.65rem;
  }

  .layout {
    margin-top: -40px;
    gap: 10px;
    width: calc(100% - 24px);
    margin-bottom: 32px;
  }

  .section-block {
    padding: 16px 14px;
    border-radius: var(--radius-sm);
  }

  .section-heading {
    margin-bottom: 14px;
  }

  .ocai-card header {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 12px 14px;
    gap: 8px;
  }

  /* OCAI buttons: full-width grid across both columns */
  .ocai-row {
    grid-template-areas:
      "letter text"
      "control control";
    padding: 12px 14px;
    column-gap: 10px;
    row-gap: 10px;
  }

  .ocai-buttons {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    flex-wrap: unset;
  }

  .ocai-btn-label span {
    min-width: 0;
    width: 100%;
    padding: 7px 2px;
    font-size: 0.8rem;
    border-radius: 6px;
  }

  label.question-card {
    padding: 14px;
  }

  .question-legend {
    padding: 14px 14px 10px;
  }

  .question-card > .option-list {
    padding: 2px 14px 12px;
  }

  .question-card > .hint {
    padding: 0 14px 2px;
  }

  .question-card > .text-field {
    padding: 0 14px 14px;
  }

  .option {
    padding: 10px 8px;
  }

  .actions {
    flex-direction: column;
    align-items: stretch;
  }

  .primary-button,
  .secondary-button {
    justify-content: center;
    width: 100%;
  }

  .success-card {
    padding: 36px 20px;
  }

  .success-card h2 {
    font-size: 1.4rem;
  }
}

/* ─── REDUCED MOTION ─────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    scroll-behavior: auto !important;
  }
}
