:root {
  --green: #06c755;      /* LINE green */
  --green-dark: #04a445;
  --teal: #0e7c66;
  --bg: #f2f4f6;
  --card: #ffffff;
  --text: #1f2933;
  --text-muted: #7b8794;
  --border: #e1e5ea;
  --danger: #e0245e;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  /* safe-area สำหรับจอมีติ่ง (iPhone notch / home indicator) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tap: 48px;           /* ขนาด touch target ขั้นต่ำ */
  --app-max: 480px;      /* ความกว้างสูงสุด (โฟกัสมือถือ) */
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
    "Noto Sans Thai", "Sarabun", Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;  /* กัน iOS ปรับขนาดฟอนต์เอง */
  overflow-x: hidden;              /* กันเลื่อนแนวนอน */
}

/* ---------- app container: จำกัดกว้าง + จัดกึ่งกลางบนจอใหญ่ ---------- */
.screen {
  min-height: 100dvh;              /* dvh = เต็มจอจริงบนมือถือ (กัน address bar เด้ง) */
  max-width: var(--app-max);
  margin: 0 auto;
  background: var(--bg);
}
@media (min-width: 481px) {
  body { background: #e4e8ec; }
  .screen { box-shadow: 0 0 24px rgba(0,0,0,0.08); }
}
.hidden { display: none !important; }

#loading, #error-screen, #success-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 24px;
  padding-top: calc(32px + var(--safe-top));
  padding-bottom: calc(32px + var(--safe-bottom));
  gap: 12px;
}

.spinner {
  width: 42px; height: 42px;
  border: 4px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.icon-badge {
  width: 72px; height: 72px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 38px; color: #fff; font-weight: 700;
}
.icon-badge.success { background: var(--green); }
.icon-badge.error { background: var(--danger); }

/* ---------- header ---------- */
.app-header {
  background: linear-gradient(135deg, var(--green), var(--teal));
  color: #fff;
  padding: 20px 18px 22px;
  padding-top: calc(20px + var(--safe-top));
  position: sticky; top: 0; z-index: 1100;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: rgba(255,255,255,0.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 700;
}
.brand h1 { margin: 0; font-size: 20px; font-weight: 700; }
.brand-sub { font-size: 13px; opacity: 0.85; }

.profile {
  display: flex; align-items: center; gap: 8px;
  margin-top: 14px;
  background: rgba(255,255,255,0.15);
  padding: 6px 12px; border-radius: 999px;
  width: fit-content;
  font-size: 14px;
}
.profile img { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; }

/* ---------- form ---------- */
/* เว้นล่างเผื่อปุ่มลงทะเบียนแบบ sticky ไม่ให้บังเนื้อหา */
form { padding: 16px 14px calc(96px + var(--safe-bottom)); }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card-title {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 700;
  color: var(--teal);
  display: flex; align-items: center; gap: 8px;
}
.card-title::before {
  content: "";
  width: 4px; height: 16px;
  background: var(--green);
  border-radius: 2px;
}

.field { display: block; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field-label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field-label em { color: var(--danger); font-style: normal; }
.field-hint { display: block; font-size: 12px; color: var(--text-muted); margin-top: 4px; }

input[type="text"], input[type="tel"], input[type="date"], textarea {
  width: 100%;
  min-height: var(--tap);          /* touch target */
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 16px;                 /* ≥16px กัน iOS ซูมตอนโฟกัส */
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--green);
}
input:invalid:not(:placeholder-shown) { border-color: var(--danger); }
textarea { resize: vertical; }

/* radio pills */
.radio-row { display: flex; gap: 8px; }
.radio-pill {
  flex: 1;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  min-height: var(--tap);
  padding: 10px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  transition: all 0.15s;
}
.radio-pill input { position: absolute; opacity: 0; }
.radio-pill:has(input:checked) {
  border-color: var(--green);
  background: rgba(6,199,85,0.08);
  color: var(--green-dark);
  font-weight: 600;
}

/* switch toggle */
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  min-height: var(--tap);
  cursor: pointer;
}
.switch-row .field-label { margin-bottom: 0; }
.switch-row input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch {
  width: 46px; height: 27px;
  background: #cfd6dd;
  border-radius: 999px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.switch::after {
  content: "";
  position: absolute; top: 3px; left: 3px;
  width: 21px; height: 21px;
  background: #fff; border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.switch-row input:checked + .switch { background: var(--green); }
.switch-row input:checked + .switch::after { transform: translateX(19px); }

.conditional { margin-top: 12px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  min-height: var(--tap);
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-secondary { background: #e4e8ec; color: var(--text); }
.btn-outline {
  background: #fff; color: var(--teal);
  border: 1.5px solid var(--green);
  width: 100%;
}
.geo-icon { font-size: 18px; }
#geo-map {
  width: 100%;
  height: 220px;
  margin-top: 10px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  overflow: hidden;
}

/* ปุ่มลงทะเบียนติดขอบล่าง — กดง่ายด้วยนิ้วโป้ง */
.submit-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: var(--app-max);
  margin: 0 auto;
  padding: 10px 14px calc(10px + var(--safe-bottom));
  background: linear-gradient(to top, var(--card) 70%, rgba(255,255,255,0));
  z-index: 1100;   /* ต้องเหนือ Leaflet map (z-index ภายในสูงถึง ~1000) */
}
#submit-btn { box-shadow: 0 4px 12px rgba(6,199,85,0.35); }
