:root {
  --color-primary: #ff8f48;
  --color-primary-dark: #e9762c;
  --color-primary-deep: #b84f0c;
  --color-secondary: #003463;
  --color-bg-light: #fff5ee;
  --color-bg-white: #fffffe;

  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --emerald: #10b981;
  --red: #dc2626;

  --shadow-rest: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lift: 0 12px 28px -24px rgba(0, 52, 99, 0.8);
  --shadow-card: 0 24px 60px -28px rgba(15, 23, 42, 0.35);
  --shadow-cta: 0 10px 15px -3px rgba(255, 143, 72, 0.3), 0 4px 6px -4px rgba(255, 143, 72, 0.3);
}

* { box-sizing: border-box; }

html { font-size: 15px; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: Kanit, "Sarabun", "Noto Sans Thai", system-ui, sans-serif;
  font-weight: 400;
  line-height: 1.7;
  color: var(--slate-800);
  background: var(--slate-50);
}

h1, h2, h3 { margin: 0; line-height: 1.35; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }

.wrap { width: 100%; max-width: 48rem; margin: 0 auto; padding: 0 1rem; }
.wrap--wide { max-width: 80rem; }

/* ── Header ─────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--slate-200);
}
.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: 3.75rem;
}
.site-header img { height: 2.5rem; width: auto; display: block; }
.header-tag {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-secondary);
  background: rgba(0, 52, 99, 0.05);
  border: 1px solid rgba(0, 52, 99, 0.12);
  border-radius: 999px;
  padding: 0.25rem 0.875rem;
  white-space: nowrap;
}

/* ── Hero (dark interior band) ──────────────────────── */
.hero {
  position: relative;
  overflow: hidden;
  background: var(--color-secondary);
  color: #fff;
  padding: 2.75rem 0 4.5rem;
}
.hero::before,
.hero::after {
  content: "";
  position: absolute;
  pointer-events: none;
}
.hero::before {
  inset: -40% auto auto -20%;
  width: 70%;
  aspect-ratio: 1;
  background: radial-gradient(circle, rgba(255, 143, 72, 0.32), transparent 65%);
}
.hero::after {
  inset: auto -15% -60% auto;
  width: 60%;
  aspect-ratio: 1;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.1), transparent 65%);
}
.hero .wrap { position: relative; }
.hero-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.85);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  padding: 0.375rem 1rem;
  backdrop-filter: blur(6px);
}
.hero-pill::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--color-primary);
}
.hero h1 {
  margin-top: 1rem;
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  font-weight: 700;
}
.hero h1 em { font-style: normal; color: var(--color-primary); }
.hero-lead {
  margin-top: 0.75rem;
  max-width: 38rem;
  color: rgba(255, 255, 255, 0.8);
  font-size: 1.0625rem;
}
.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  margin-top: 1.25rem;
  font-size: 0.9375rem;
  color: rgba(255, 255, 255, 0.7);
}
.hero-meta span { display: inline-flex; align-items: center; gap: 0.375rem; }
.hero-meta svg { color: var(--color-primary); }

/* ── Main + cards ───────────────────────────────────── */
main { flex: 1; }
.overlap { margin-top: -2.5rem; padding-bottom: 3rem; position: relative; }
@media (max-width: 559px) { .wrap.overlap { padding-inline: 5px; } }

.card {
  background: #fff;
  border: 1px solid var(--slate-200);
  border-radius: 1.5rem;
  box-shadow: var(--shadow-lift);
  padding: 1.5rem;
}
.card + .card { margin-top: 1.25rem; }
@media (min-width: 640px) { .card { padding: 2rem; border-radius: 2rem; } }

/* ── Step progress ──────────────────────────────────── */
.card.progress { padding: 1rem 1.25rem; border-radius: 1.25rem; }
.progress-text {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.625rem;
  font-size: 0.875rem;
  color: var(--slate-500);
}
.progress-text strong { font-size: 1rem; font-weight: 600; color: var(--color-secondary); }
.progress-bar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.375rem; margin: 0.625rem 0 0; padding: 0; list-style: none; }
.progress-bar li { height: 0.375rem; border-radius: 999px; background: var(--slate-200); transition: background-color 0.2s; }
.progress-bar li.is-done { background: var(--color-secondary); }
.progress-bar li.is-current { background: var(--color-primary); }
.page { margin-top: 1.25rem; }
#survey { scroll-margin-top: 4.75rem; }
.section-head h2:focus { outline: none; }

.section-head { display: flex; gap: 0.875rem; align-items: flex-start; margin-bottom: 1.25rem; }
.step {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.875rem;
  background: rgba(255, 143, 72, 0.12);
  color: var(--color-primary-deep);
  font-weight: 700;
}
.section-head h2 { font-size: 1.25rem; font-weight: 700; color: var(--color-secondary); }
.section-head p { font-size: 0.9375rem; color: var(--slate-500); }

/* ── Form controls ──────────────────────────────────── */
.grid-2 { display: grid; gap: 1rem; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.span-2 { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 0.375rem; }
.field > label,
.field > .label { font-size: 0.9375rem; font-weight: 600; color: var(--slate-700); }
.req { color: var(--color-primary-deep); margin-left: 0.125rem; }
.opt { font-weight: 400; color: var(--slate-500); font-size: 0.8125rem; margin-left: 0.25rem; }

.input,
.select,
.textarea {
  width: 100%;
  min-height: 2.875rem;
  border: 1px solid var(--slate-200);
  background: var(--slate-50);
  border-radius: 0.875rem;
  padding: 0.5rem 0.875rem;
  font-size: 1rem;
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
}
.textarea { min-height: 6rem; resize: vertical; line-height: 1.7; }
/* iOS zooms into any field under 16px on focus */
@media (pointer: coarse) {
  .input, .select, .textarea, .ts-wrapper .ts-control, .ts-control input { font-size: 16px; }
}
.select {
  appearance: none;
  padding-right: 2.5rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none' stroke='%2364748b' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.875rem center;
}
.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  background-color: #fff;
  box-shadow: 0 0 0 4px rgba(255, 143, 72, 0.12);
}
.field.invalid .input,
.field.invalid .select { border-color: var(--red); background-color: #fff; }
.error-text { display: none; font-size: 0.8125rem; color: var(--red); }
.invalid > .error-text,
.invalid .error-text { display: block; }

/* Department picker (Tom Select) */
.ts-wrapper.select { padding: 0; border: 0; background: none; min-height: 0; box-shadow: none; }
.ts-wrapper .ts-control {
  min-height: 2.875rem;
  align-items: center;
  border: 1px solid var(--slate-200);
  background: var(--slate-50) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none' stroke='%2364748b' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 0.875rem center;
  border-radius: 0.875rem;
  padding: 0.5rem 2.5rem 0.5rem 0.875rem;
  font-size: 1rem;
  line-height: 1.7;
  box-shadow: none;
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
}
.ts-wrapper.single .ts-control::after { display: none; }
.ts-wrapper .ts-control > .item { padding: 0; border: 0; border-radius: 0; background: none; }
.ts-wrapper.single .ts-control,
.ts-wrapper.single .ts-control input { cursor: pointer; }
.ts-wrapper.single.input-active .ts-control input { cursor: text; }
.ts-wrapper.focus .ts-control {
  border-color: var(--color-primary);
  background-color: #fff;
  box-shadow: 0 0 0 4px rgba(255, 143, 72, 0.12);
}
.ts-wrapper.dropdown-active .ts-control { border-radius: 0.875rem; }
.ts-control input { font-size: 1rem; }
.ts-control input::placeholder { color: var(--slate-500); }
.field.invalid .ts-control { border-color: var(--red); background-color: #fff; }
.ts-dropdown {
  margin-top: 0.375rem;
  border: 1px solid var(--slate-200);
  border-radius: 0.875rem;
  box-shadow: var(--shadow-card);
  overflow: hidden;
  font-size: 0.9375rem;
  color: var(--slate-800);
}
.ts-dropdown .ts-dropdown-content { max-height: 20rem; padding-bottom: 0.25rem; }
.ts-dropdown .optgroup-header {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 0.625rem 0.875rem 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-secondary);
  background: #fff;
}
.ts-dropdown .option,
.ts-dropdown .no-results { padding: 0.5rem 0.875rem; }
.ts-dropdown .active { background: var(--color-bg-light); color: var(--slate-800); }
.ts-dropdown .selected { font-weight: 600; }
.dept-opt { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.dept-code { margin-left: 0.375rem; font-size: 0.8125rem; font-weight: 400; color: var(--slate-500); }
.dept-done {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
  padding: 0 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: #047857;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-radius: 999px;
}
.dept-status { font-size: 0.8125rem; color: var(--slate-500); }
.dept-status strong { font-weight: 600; color: #047857; }
.dept-status svg { vertical-align: -1px; }

/* Overall choice cards */
.choices { display: grid; gap: 0.75rem; }
@media (min-width: 640px) { .choices { grid-template-columns: repeat(3, 1fr); } }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  height: 100%;
  padding: 1rem 1.125rem;
  border: 2px solid var(--slate-200);
  border-radius: 1.25rem;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.choice label:hover { border-color: rgba(255, 143, 72, 0.4); transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.choice .dot {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  margin-bottom: 0.25rem;
}
.choice strong { font-size: 1.0625rem; font-weight: 700; color: var(--color-secondary); }
.choice small { font-size: 0.875rem; color: var(--slate-500); line-height: 1.55; }
.choice input:checked + label { border-color: var(--color-primary); background: var(--color-bg-light); }
.choice input:focus-visible + label { box-shadow: 0 0 0 4px rgba(255, 143, 72, 0.25); }
.dot--enough { background: var(--emerald); }
.dot--partial { background: #f59e0b; }
.dot--notEnough { background: var(--red); }

/* Equipment rows */
.items { display: flex; flex-direction: column; gap: 0.75rem; }
.item {
  border: 1px solid var(--slate-200);
  border-radius: 1.25rem;
  padding: 1rem;
  background: #fff;
  transition: border-color 0.15s, background-color 0.15s;
}
.item.answered { border-color: rgba(0, 52, 99, 0.12); background: #fffcfa; }
.item.invalid { border-color: var(--red); }
.item-head { display: flex; gap: 0.75rem; align-items: center; }
.icon-well {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.875rem;
  background: linear-gradient(135deg, rgba(255, 143, 72, 0.14), rgba(0, 52, 99, 0.08));
  color: var(--color-secondary);
}
.item-title { font-weight: 600; color: var(--color-secondary); line-height: 1.4; }
.item-hint { font-size: 0.8125rem; color: var(--slate-500); line-height: 1.5; }

.seg {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin: 0.875rem 0 0;
  padding: 0;
  border: 0;
}
@media (min-width: 560px) { .seg { grid-template-columns: repeat(4, 1fr); } }
.seg legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--slate-200);
  border-radius: 999px;
  background: var(--slate-50);
  font-size: 0.9375rem;
  font-weight: 500;
  text-align: center;
  line-height: 1.35;
  text-wrap: balance;
  position: relative;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, color 0.15s;
}
.seg label:hover { border-color: rgba(255, 143, 72, 0.4); }
.seg input:focus-visible + label { box-shadow: 0 0 0 4px rgba(255, 143, 72, 0.25); }
.seg input:checked + label { font-weight: 600; }
/* Corner check badge: out of the text flow, so it never causes a wrap */
.seg input:checked + label::after {
  content: "";
  position: absolute;
  top: -0.375rem;
  right: -0.125rem;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid #fffcfa;
  border-radius: 50%;
  background: var(--badge, var(--slate-600)) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / 0.625rem no-repeat;
}
.seg input[value="ok"]:checked + label { --badge: #059669; background: #ecfdf5; border-color: var(--emerald); color: #047857; }
.seg input[value="short"]:checked + label { --badge: var(--red); background: #fef2f2; border-color: var(--red); color: #b91c1c; }
.seg input[value="broken"]:checked + label { --badge: #d97706; background: #fffbeb; border-color: #f59e0b; color: #b45309; }
.seg input[value="na"]:checked + label { background: var(--slate-600); border-color: var(--slate-600); color: #fff; }

.item-extra { display: none; gap: 0.75rem; margin-top: 0.875rem; }
.item.needs-detail .item-extra { display: grid; }
@media (min-width: 560px) { .item-extra { grid-template-columns: 9rem 1fr; } }
.item-extra .need-field[hidden] + .field { grid-column: 1 / -1; }
.item-extra .field > label { font-size: 0.875rem; font-weight: 500; color: var(--slate-600); }

/* Urgency chips */
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips label {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0.375rem 1.125rem;
  border: 1px solid rgba(0, 52, 99, 0.2);
  border-radius: 999px;
  background: rgba(0, 52, 99, 0.04);
  color: var(--color-secondary);
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.chips input:checked + label { background: var(--color-secondary); border-color: var(--color-secondary); color: #fff; }
.chips input:focus-visible + label { box-shadow: 0 0 0 4px rgba(0, 52, 99, 0.25); }

/* ── Buttons ────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.875rem;
  padding: 0.625rem 1.5rem;
  border-radius: 999px;
  border: 0;
  font-weight: 600;
  font-size: 1rem;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s, background-color 0.15s, box-shadow 0.15s, color 0.15s;
}
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px rgba(255, 143, 72, 0.3); }
.btn-primary { background: var(--color-primary); color: #fff; box-shadow: var(--shadow-cta); }
.btn-primary:hover { background: var(--color-primary-dark); transform: translateY(-2px); }
.btn-primary:disabled { opacity: 0.6; cursor: wait; transform: none; }
.btn-outline { background: #fff; color: var(--color-primary-deep); border: 2px solid rgba(255, 143, 72, 0.25); }
.btn-outline:hover { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.btn-soft { background: rgba(0, 52, 99, 0.05); color: var(--color-secondary); border: 1px solid rgba(0, 52, 99, 0.2); }
.btn-soft:hover { background: rgba(0, 52, 99, 0.1); }
.btn-sm { min-height: 2.5rem; padding: 0.375rem 1rem; font-size: 0.9375rem; }

.form-nav {
  display: flex;
  flex-direction: column-reverse;
  gap: 0.75rem;
  align-items: stretch;
  margin-top: 1.25rem;
}
@media (min-width: 640px) {
  .form-nav { flex-direction: row; align-items: center; justify-content: space-between; }
}
.form-nav p { font-size: 0.875rem; color: var(--slate-500); text-align: center; }
.form-nav-btns { display: flex; gap: 0.75rem; margin-left: auto; }
.form-nav-btns .btn { flex: 1; white-space: nowrap; }
@media (min-width: 640px) { .form-nav-btns .btn { flex: none; } }

.alert {
  display: none;
  margin-top: 1.25rem;
  padding: 0.875rem 1.125rem;
  border-radius: 1rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  font-size: 0.9375rem;
}
.alert.show { display: block; }

/* ── Thank-you ──────────────────────────────────────── */
.done { text-align: center; padding: 2.5rem 1.5rem; }
.done-icon {
  display: grid;
  place-items: center;
  width: 4.5rem;
  height: 4.5rem;
  margin: 0 auto 1.25rem;
  border-radius: 50%;
  background: #ecfdf5;
  color: var(--emerald);
  box-shadow: 0 0 0 8px rgba(16, 185, 129, 0.08);
}
.done h2 { font-size: 1.5rem; font-weight: 700; color: var(--color-secondary); }
.done p { margin-top: 0.5rem; color: var(--slate-600); }
.done .btn { margin-top: 1.5rem; }

/* ── Footer ─────────────────────────────────────────── */
.site-footer { background: var(--color-secondary); color: #cbd5e1; padding: 2rem 0; font-size: 0.875rem; }
.site-footer .wrap { display: flex; flex-direction: column; gap: 1rem; align-items: flex-start; }
@media (min-width: 640px) {
  .site-footer .wrap { flex-direction: row; align-items: center; justify-content: space-between; }
}
.site-footer img { height: 2.5rem; width: auto; filter: brightness(0) invert(1); }
.site-footer strong { color: var(--color-primary); font-weight: 600; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .btn-primary:hover, .choice label:hover { transform: none; }
}
