:root {
  --primary: #005085;
  --primary-hover: #003c64;
  --primary-light: #e8f3f9;
  --accent: #00a896;
  --accent-light: #e6f7f5;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  --bg-page: #f8fafc;
  --card-bg: #ffffff;
  --card-shadow: 0 4px 20px -2px rgba(0, 80, 133, 0.08), 0 2px 6px -1px rgba(0, 0, 0, 0.04);
  --success: #10b981;
  --gold: #f59e0b;
  --danger: #ef4444;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --font-family: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

body {
  font-family: var(--font-family);
  background: var(--bg-page);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Background gradient aesthetic */
.bg-decor {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 380px;
  background: linear-gradient(135deg, #003459 0%, #005085 45%, #0077b6 100%);
  clip-path: ellipse(150% 100% at 50% 0%);
  z-index: -1;
  pointer-events: none;
}

.bg-pattern {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  opacity: 0.07;
  background-image: radial-gradient(#ffffff 1.5px, transparent 1.5px);
  background-size: 24px 24px;
}

.page-wrapper {
  max-width: 820px;
  margin: 0 auto;
  padding: 32px 20px 80px 20px;
}

/* Header Branding */
.form-header {
  text-align: center;
  color: #ffffff;
  margin-bottom: 24px;
  padding: 8px 0;
}

.trust-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.3px;
  margin-bottom: 14px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.trust-badge svg {
  width: 16px;
  height: 16px;
  fill: #38bdf8;
  flex-shrink: 0;
}

.form-header h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
  line-height: 1.25;
}

.form-header .sub-title {
  font-size: 1.05rem;
  opacity: 0.92;
  font-weight: 400;
  max-width: 600px;
  margin: 0 auto 12px auto;
  line-height: 1.4;
}

.header-note {
  background: rgba(255, 255, 255, 0.95);
  color: var(--text-main);
  padding: 16px 20px;
  border-radius: var(--radius-md);
  margin-top: 18px;
  box-shadow: var(--card-shadow);
  text-align: left;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  border-left: 4px solid var(--accent);
}

.header-note-icon {
  color: var(--accent);
  flex-shrink: 0;
  margin-top: 2px;
}

.header-note p {
  font-size: 0.92rem;
  color: #334155;
  margin: 0;
  line-height: 1.5;
}

/* Form Container Card */
.form-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow);
  padding: 36px 32px;
  border: 1px solid var(--border);
  position: relative;
}

/* Multi-Step Progress Bar */
.step-progress-wrapper {
  margin-bottom: 32px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.step-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 0.88rem;
}

.step-counter-text {
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-light);
  padding: 3px 10px;
  border-radius: 9999px;
  font-size: 0.82rem;
}

.step-title-text {
  font-weight: 600;
  color: var(--text-muted);
}

.progress-bar-bg {
  width: 100%;
  height: 8px;
  background: #e2e8f0;
  border-radius: 9999px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #005085 0%, #00a896 100%);
  border-radius: 9999px;
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Step Switching Visibility & Animations */
.form-step {
  display: none;
  animation: slideFadeIn 0.3s ease-out forwards;
}

.form-step.active {
  display: block;
}

@keyframes slideFadeIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.step-header-wrap {
  margin-bottom: 24px;
}

.section-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.section-num {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
  border-radius: 50%;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.section-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.3;
}

.section-help {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-left: 38px;
  line-height: 1.4;
}

/* Questions */
.question-group {
  margin-bottom: 24px;
  padding: 12px;
  border-radius: var(--radius-md);
  transition: background-color 0.2s, box-shadow 0.2s;
}

.question-group.has-error {
  background-color: #fef2f2;
  border: 1.5px solid #fca5a5;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
  animation: shake 0.35s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.question-label {
  display: block;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 10px;
  line-height: 1.4;
}

.question-label .req {
  color: var(--danger);
  margin-left: 2px;
}

/* Modern 1-5 Rating Component */
.rating-pill-container {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: 100%;
}

.rating-pill {
  position: relative;
  height: 48px;
}

.rating-pill input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  z-index: 2;
}

.rating-pill label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: var(--bg-page);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
}

.rating-pill label:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.rating-pill input[type="radio"]:checked + label {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 80, 133, 0.28);
}

.rating-legend {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  padding: 0 4px;
  font-size: 0.78rem;
  color: var(--text-light);
  font-weight: 500;
}

/* Textarea & Inputs */
.form-textarea, .form-input {
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text-main);
  background: #ffffff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  min-height: 48px;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.form-textarea:focus, .form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 80, 133, 0.12);
}

.form-textarea {
  min-height: 140px;
  resize: vertical;
}

.textarea-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--text-light);
}

/* Chips / Tag Selector for Treatments */
.chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.chip-item {
  position: relative;
}

.chip-item input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  z-index: 2;
}

.chip-item label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg-page);
  border: 1.5px solid var(--border);
  border-radius: 9999px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.chip-item label:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

.chip-item input[type="checkbox"]:checked + label {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 168, 150, 0.25);
}

.chip-counter {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.other-input-wrap {
  margin-top: 10px;
  display: none;
  animation: fadeIn 0.3s ease;
}

.other-input-wrap.active {
  display: block;
}

/* Toggle Yes/No Segmented Buttons */
.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  max-width: 320px;
  width: 100%;
}

.segment-option {
  position: relative;
  height: 48px;
}

.segment-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  z-index: 2;
}

.segment-option label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 100%;
  background: var(--bg-page);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.segment-option label:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.segment-option input[type="radio"]:checked + label {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 80, 133, 0.25);
}

/* 2-Column Grid for patient details */
.input-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.confidential-callout {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--primary-light);
  color: var(--primary);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 16px;
  line-height: 1.4;
}

.confidential-callout svg {
  flex-shrink: 0;
}

/* Wizard Navigation Wrap */
.wizard-nav-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 36px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  gap: 12px;
}

.btn-wizard {
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 700;
  padding: 14px 28px;
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.22s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
}

.btn-prev {
  background: var(--bg-page);
  border: 1.5px solid var(--border);
  color: var(--text-main);
}

.btn-prev:hover {
  background: #ffffff;
  border-color: var(--primary);
  color: var(--primary);
}

.btn-next {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(0, 80, 133, 0.28);
  margin-left: auto;
}

.btn-next:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(0, 80, 133, 0.35);
}

.btn-submit {
  background: linear-gradient(135deg, #005085 0%, #00a896 100%);
  color: #ffffff;
  box-shadow: 0 6px 20px rgba(0, 168, 150, 0.32);
  margin-left: auto;
}

.btn-submit:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(0, 168, 150, 0.42);
}

.btn-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Success Screen */
.success-screen {
  display: none;
  text-align: center;
  padding: 48px 16px;
  animation: fadeIn 0.4s ease;
}

.success-icon-wrap {
  width: 76px;
  height: 76px;
  background: #dcfce7;
  color: #16a34a;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px auto;
  box-shadow: 0 8px 20px rgba(22, 163, 74, 0.2);
}

.success-screen h2 {
  font-size: 1.6rem;
  color: var(--text-main);
  margin-bottom: 12px;
  line-height: 1.3;
}

.success-screen p {
  color: var(--text-muted);
  max-width: 480px;
  margin: 0 auto 24px auto;
  font-size: 0.95rem;
  line-height: 1.5;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--bg-page);
  border: 1.5px solid var(--border);
  padding: 12px 24px;
  border-radius: 9999px;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  font-size: 0.95rem;
}

.btn-secondary:hover {
  background: #ffffff;
  border-color: var(--primary);
  color: var(--primary);
}

/* Footer note */
.page-footer {
  text-align: center;
  margin-top: 28px;
  color: var(--text-light);
  font-size: 0.82rem;
  padding: 0 10px;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================
   📱 COMPREHENSIVE MOBILE OPTIMIZATIONS (< 640px)
   ========================================================== */
@media (max-width: 640px) {
  .bg-decor {
    height: 280px;
  }

  .page-wrapper {
    padding: 16px 12px 60px 12px;
  }

  .form-header {
    margin-bottom: 18px;
    padding: 4px 0;
  }

  .trust-badge {
    font-size: 0.78rem;
    padding: 5px 12px;
    margin-bottom: 10px;
  }

  .form-header h1 {
    font-size: 1.45rem;
    line-height: 1.25;
    margin-bottom: 6px;
  }

  .form-header .sub-title {
    font-size: 0.9rem;
    line-height: 1.35;
    margin-bottom: 10px;
  }

  .header-note {
    padding: 12px 14px;
    margin-top: 14px;
    gap: 10px;
    border-radius: 8px;
  }

  .header-note p {
    font-size: 0.85rem;
    line-height: 1.45;
  }

  .form-card {
    padding: 22px 16px;
    border-radius: 14px;
  }

  .step-progress-wrapper {
    margin-bottom: 24px;
    padding-bottom: 16px;
  }

  .section-title-wrap {
    gap: 8px;
    margin-bottom: 6px;
  }

  .section-num {
    width: 24px;
    height: 24px;
    font-size: 0.75rem;
  }

  .section-title {
    font-size: 1.1rem;
  }

  .section-help {
    margin-left: 0;
    margin-top: 4px;
    font-size: 0.84rem;
  }

  .question-group {
    padding: 8px 4px;
    margin-bottom: 16px;
  }

  .question-label {
    font-size: 0.92rem;
    margin-bottom: 8px;
  }

  /* 1-5 Scale: perfect touch-friendly grid on all mobile widths */
  .rating-pill-container {
    gap: 6px;
  }

  .rating-pill {
    height: 44px;
  }

  .rating-pill label {
    font-size: 1rem;
    border-radius: 8px;
  }

  .rating-legend {
    font-size: 0.72rem;
    margin-top: 4px;
  }

  /* Inputs prevent iOS auto-zoom */
  .form-textarea, .form-input {
    font-size: 16px;
    padding: 10px 14px;
    border-radius: 8px;
  }

  .form-textarea {
    min-height: 110px;
  }

  /* Treatment Chips */
  .chips-container {
    gap: 6px;
  }

  .chip-item label {
    padding: 7px 12px;
    font-size: 0.82rem;
  }

  /* Full-width Yes/No */
  .segmented-control {
    max-width: 100%;
    gap: 8px;
  }

  .segment-option {
    height: 44px;
  }

  .segment-option label {
    font-size: 0.9rem;
    border-radius: 8px;
  }

  /* Patient Details Grid */
  .input-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .confidential-callout {
    font-size: 0.8rem;
    padding: 8px 12px;
    margin-bottom: 14px;
  }

  /* Wizard Navigation Buttons */
  .wizard-nav-wrap {
    margin-top: 24px;
    padding-top: 18px;
    flex-direction: row;
  }

  .btn-wizard {
    padding: 13px 20px;
    font-size: 0.92rem;
    border-radius: 12px;
  }

  .btn-prev {
    flex: 1;
  }

  .btn-next, .btn-submit {
    flex: 2;
  }

  .success-screen {
    padding: 32px 10px;
  }

  .success-screen h2 {
    font-size: 1.35rem;
  }

  .btn-secondary {
    width: 100%;
    padding: 14px 20px;
    border-radius: 12px;
  }
}
