/* ───────────────────────────────────────────────────────────
   CHS / Sheltering Wings Pre-Screen Application Form
   Minimalist professional styling — mobile-first
   CSS variables at top for easy rebranding
   ─────────────────────────────────────────────────────────── */

:root {
  /* Brand colors — tweak here to recolor the whole form */
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: #dbeafe;

  /* Neutrals */
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-text-subtle: #94a3b8;
  --color-border: #e2e8f0;
  --color-border-strong: #cbd5e1;
  --color-bg: #f8fafc;
  --color-card: #ffffff;
  --color-input-bg: #ffffff;
  --color-input-focus-bg: #ffffff;

  /* Semantic */
  --color-error: #dc2626;
  --color-error-bg: #fef2f2;
  --color-success: #059669;
  --color-note-bg: #fef9c3;
  --color-note-border: #fde68a;
  --color-priority-bg: #ecfeff;
  --color-priority-border: #67e8f9;

  /* Spacing scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.06), 0 2px 4px -2px rgb(0 0 0 / 0.04);
  --shadow-focus: 0 0 0 3px rgb(37 99 235 / 0.15);

  /* Border radii */
  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
}

/* ───────────── Reset & base ───────────── */

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

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

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.55;
  color: var(--color-text);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ───────────── Layout ───────────── */

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
}

@media (min-width: 640px) {
  .container { padding: var(--space-10) var(--space-6); }
}

/* ───────────── Header ───────────── */

.form-header {
  margin-bottom: var(--space-8);
}

.eyebrow {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 var(--space-2);
}

.form-header h1 {
  font-size: var(--text-2xl);
  font-weight: 700;
  margin: 0 0 var(--space-3);
  line-height: 1.2;
  letter-spacing: -0.02em;
}

@media (min-width: 640px) {
  .form-header h1 { font-size: var(--text-3xl); }
}

.intro {
  color: var(--color-text-muted);
  margin: 0 0 var(--space-5);
}

.priority-note {
  background: var(--color-priority-bg);
  border: 1px solid var(--color-priority-border);
  border-radius: var(--radius);
  padding: var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text);
  margin-bottom: var(--space-5);
}

.priority-note strong { color: var(--color-text); }

/* ───────────── Sections ───────────── */

.form-section {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-5);
  box-shadow: var(--shadow-sm);
}

@media (min-width: 640px) {
  .form-section { padding: var(--space-8); }
}

.form-section h2 {
  font-size: var(--text-xl);
  font-weight: 600;
  margin: 0 0 var(--space-6);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border);
  letter-spacing: -0.01em;
}

.form-section h3 {
  font-size: var(--text-lg);
  font-weight: 600;
  margin: 0 0 var(--space-3);
  letter-spacing: -0.01em;
}

.section-intro {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: 0 0 var(--space-5);
  line-height: 1.6;
}

/* ───────────── Fields ───────────── */

.field {
  margin-bottom: var(--space-6);
}

.field:last-child { margin-bottom: 0; }

label, legend {
  display: block;
  font-weight: 500;
  font-size: var(--text-sm);
  color: var(--color-text);
  margin-bottom: var(--space-2);
  padding: 0;
  line-height: 1.5;
}

legend { margin-bottom: var(--space-3); }

fieldset {
  border: 0;
  padding: 0;
  margin: 0;
}

.req {
  color: var(--color-error);
  font-weight: 600;
  margin-left: 2px;
}

.optional {
  color: var(--color-text-subtle);
  font-weight: 400;
  font-size: var(--text-xs);
  margin-left: 2px;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="date"],
textarea,
select {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-family: inherit;
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-input-bg);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
input[type="date"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-primary);
  background: var(--color-input-focus-bg);
  box-shadow: var(--shadow-focus);
}

input[type="date"] {
  font-family: inherit;
  min-height: 44px;
}

textarea {
  resize: vertical;
  min-height: 100px;
  line-height: 1.55;
}

/* Error state */
input.error,
textarea.error,
select.error,
.field.error input[type="text"],
.field.error input[type="email"],
.field.error input[type="tel"],
.field.error input[type="date"],
.field.error textarea {
  border-color: var(--color-error);
  background: var(--color-error-bg);
}

.error-message {
  color: var(--color-error);
  font-size: var(--text-sm);
  margin-top: var(--space-2);
  display: none;
}

.error-message:not(:empty) { display: block; }

/* ───────────── Options (radio + checkbox) ───────────── */

.options {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.options.inline {
  flex-direction: row;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.option {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-card);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
  font-weight: 400;
  font-size: var(--text-base);
  line-height: 1.5;
  margin: 0;
}

.option:hover {
  border-color: var(--color-border-strong);
  background: var(--color-bg);
}

.options.inline .option {
  flex: 0 1 auto;
  min-width: 100px;
  justify-content: center;
}

.option input[type="radio"],
.option input[type="checkbox"] {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin: 2px 0 0 0;
  accent-color: var(--color-primary);
  cursor: pointer;
}

.option input[type="radio"]:checked + *,
.option input[type="checkbox"]:checked + * {
  font-weight: 500;
}

/* Selected option visual feedback */
.option:has(input:checked) {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

/* ───────────── Conditional reveal ───────────── */

.conditional {
  margin-top: var(--space-3);
  padding-left: var(--space-4);
  border-left: 3px solid var(--color-primary-light);
  animation: revealIn 0.2s ease;
}

@keyframes revealIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ───────────── Notes ───────────── */

.note {
  background: var(--color-note-bg);
  border: 1px solid var(--color-note-border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text);
  margin: var(--space-3) 0 0;
  line-height: 1.5;
}

/* ───────────── Character counter ───────────── */

.char-counter {
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
  text-align: right;
  margin-top: var(--space-1);
}

.char-counter.warning { color: #d97706; }
.char-counter.danger { color: var(--color-error); }

/* ───────────── Interview question (Section 7) ───────────── */

.interview-question {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-5);
  background: var(--color-bg);
  margin-bottom: var(--space-5);
}

.interview-question h3 {
  margin-bottom: var(--space-3);
  color: var(--color-primary);
}

.interview-question .prompt {
  font-size: var(--text-base);
  margin: 0 0 var(--space-3);
  font-style: italic;
  color: var(--color-text);
  line-height: 1.5;
}

.interview-question .hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: 0 0 var(--space-5);
  padding: var(--space-2) var(--space-3);
  background: var(--color-card);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--color-primary);
  line-height: 1.5;
}

/* ───────────── Response toggle ───────────── */

.response-toggle {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  padding: var(--space-1);
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.toggle-option {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  transition: background-color 0.15s, color 0.15s;
  margin: 0;
}

.toggle-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-option:has(input:checked) {
  background: var(--color-primary);
  color: white;
}

/* ───────────── Video placeholder (legacy from Delivery 1) ───────────── */

.video-placeholder {
  padding: var(--space-10) var(--space-4);
  background: var(--color-card);
  border: 2px dashed var(--color-border-strong);
  border-radius: var(--radius);
  text-align: center;
  color: var(--color-text-subtle);
  font-size: var(--text-sm);
  font-style: italic;
}

/* ───────────── Video Recorder (Record mode) ───────────── */

.recorder {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);
}

.recorder-permission {
  text-align: center;
  padding: var(--space-4) var(--space-2);
}

.recorder-permission p {
  margin: 0 0 var(--space-3);
  color: var(--color-text-muted);
}

.recorder-hint {
  font-size: var(--text-sm);
  color: var(--color-text-subtle);
  margin-top: var(--space-3) !important;
}

.btn-recorder {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s;
  margin: var(--space-1);
}

.btn-recorder:hover:not(:disabled) {
  background: var(--color-primary-hover, #1d4ed8);
}

.btn-recorder:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-recorder.rec-stop {
  background: #dc2626;
}

.btn-recorder.rec-stop:hover:not(:disabled) {
  background: #b91c1c;
}

.recorder-stage {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.recorder-preview-wrap {
  /* Wrapper enforces the size box; iOS Safari can't escape this even when
     the video stream has different intrinsic dimensions. */
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: #000;
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
  /* 3:4 portrait — works for selfie video on phones (most common use case)
     and stays reasonable on desktop too. */
  aspect-ratio: 3 / 4;
}

/* Wider/landscape on desktop where the camera is usually 16:9 webcam */
@media (min-width: 768px) {
  .recorder-preview-wrap {
    aspect-ratio: 4 / 3;
    max-width: 480px;
  }
}

/* Fallback for browsers without aspect-ratio support (older iOS Safari < 15.4) */
@supports not (aspect-ratio: 1) {
  .recorder-preview-wrap {
    height: 0;
    padding-bottom: 133.33%; /* 3:4 portrait */
  }
  @media (min-width: 768px) {
    .recorder-preview-wrap {
      padding-bottom: 75%; /* 4:3 landscape */
    }
  }
}

.recorder-preview {
  /* Absolutely positioned inside the wrapper so it can't push out */
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  background: #000;
}

.recorder-status {
  text-align: center;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-weight: 500;
  min-height: 1.4em;
}

.recorder-status.error {
  color: #dc2626;
}

.recorder-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
}

.recorder-progress,
.upload-progress {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.recorder-progress-fill,
.upload-progress-fill {
  height: 8px;
  background: var(--color-primary);
  border-radius: 4px;
  width: 0%;
  transition: width 0.2s ease;
}

.recorder-progress-fill ~ .recorder-progress-label,
.upload-progress-fill ~ .upload-progress-label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-align: center;
}

.recorder-progress,
.upload-progress {
  background: var(--color-bg, #f8fafc);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
}

.recorder-progress-label,
.upload-progress-label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-align: center;
  margin-top: var(--space-1);
}

.recorder-saved,
.upload-saved {
  background: #ecfdf5;
  border: 1px solid #6ee7b7;
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  color: #065f46;
  font-size: var(--text-sm);
}

.recorder-saved p,
.upload-saved p {
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.recorder-saved .btn-recorder,
.upload-saved .btn-recorder {
  background: transparent;
  color: #065f46;
  border: 1px solid #6ee7b7;
  padding: var(--space-1) var(--space-2);
  margin: 0;
  font-size: var(--text-xs, 0.8125rem);
}

.recorder-saved .btn-recorder:hover,
.upload-saved .btn-recorder:hover {
  background: #d1fae5;
}

/* ───────────── Video Uploader (Upload mode) ───────────── */

.uploader {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);
}

.upload-instructions {
  margin: 0 0 var(--space-3);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.upload-input {
  display: block;
  width: 100%;
  padding: var(--space-2);
  font-size: var(--text-sm);
  background: white;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: var(--space-3);
}

.upload-input::file-selector-button {
  margin-right: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: var(--text-sm);
  cursor: pointer;
}

.upload-input::file-selector-button:hover {
  background: var(--color-primary-hover, #1d4ed8);
}

.upload-status {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  min-height: 1.4em;
  margin-bottom: var(--space-2);
}

.upload-status.error {
  color: #dc2626;
}

/* ───────────── Three-mode toggle (Record / Upload / Write) ───────────── */

.response-toggle.three-mode .toggle-option {
  font-size: var(--text-sm);
}

@media (max-width: 480px) {
  .response-toggle.three-mode {
    flex-direction: column;
  }
  .recorder-controls {
    flex-direction: column;
    align-items: stretch;
  }
  .btn-recorder {
    justify-content: center;
  }
}

/* ───────────── Declaration checkbox ───────────── */

.declaration {
  margin-top: var(--space-8);
  padding: var(--space-5);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.declaration .option {
  border: 0;
  background: none;
  padding: 0;
  align-items: flex-start;
}

.declaration .option:hover {
  background: none;
}

.declaration .option:has(input:checked) {
  border: 0;
  background: none;
}

.declaration .option span {
  font-size: var(--text-sm);
  line-height: 1.5;
}

/* ───────────── Submit button ───────────── */

.submit-btn {
  display: block;
  width: 100%;
  padding: var(--space-4) var(--space-6);
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: 600;
  color: white;
  background: var(--color-primary);
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.05s ease;
  letter-spacing: 0.01em;
  min-height: 52px;
}

.submit-btn:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.submit-btn:active:not(:disabled) {
  transform: translateY(1px);
}

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

.submit-note {
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin: var(--space-3) 0 0;
}

/* ───────────── Footer ───────────── */

.form-footer {
  text-align: center;
  padding: var(--space-8) var(--space-4) var(--space-4);
  color: var(--color-text-muted);
}

.form-footer p {
  margin: 0 0 var(--space-2);
}

.form-footer small {
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
}

/* ───────────── Accessibility focus visible (keyboard only) ───────────── */

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ───────────── Reduced motion ───────────── */

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ───────────── Resume uploader (Section 1) ───────────── */

.resume-uploader {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3);
}

.resume-uploader .upload-input {
  margin-bottom: var(--space-2);
}

.field-hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: var(--space-1) 0 var(--space-2);
}
