/* ── CSS Custom Properties (theme variables) ─────────────────────────────── */
:root {
  --w-primary:        #1a56db;
  --w-primary-hover:  #1447c0;
  --w-bg:             #ffffff;
  --w-surface:        #f9fafb;
  --w-border:         #e5e7eb;
  --w-text:           #111827;
  --w-text-muted:     #6b7280;
  --w-radius:         8px;
  --w-font:           system-ui, -apple-system, sans-serif;
  --w-error:          #dc2626;
}

/* ── Theme: dark ─────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --w-primary:        #3b82f6;
  --w-primary-hover:  #60a5fa;
  --w-bg:             #111827;
  --w-surface:        #1f2937;
  --w-border:         #374151;
  --w-text:           #f9fafb;
  --w-text-muted:     #9ca3af;
}

/* ── Base ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--w-font);
  background: var(--w-bg);
  color: var(--w-text);
  padding: 1.5rem 1rem 2rem;
  font-size: 1rem;
  line-height: 1.6;
}

main { max-width: 640px; margin: 0 auto; }

h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.75rem; }
h2 { font-size: 1.2rem; font-weight: 600; margin-bottom: 0.5rem; }
h3 { font-size: 1.05rem; font-weight: 600; margin-bottom: 0.4rem; }

/* ── Disclaimer ──────────────────────────────────────────────────────────── */
.disclaimer {
  font-size: 0.85rem;
  color: var(--w-text-muted);
  margin-bottom: 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--w-surface);
  border-radius: var(--w-radius);
  border-left: 3px solid var(--w-primary);
}

/* ── Survey form ─────────────────────────────────────────────────────────── */
.survey-form { display: flex; flex-direction: column; gap: 1rem; }

/* ── Question card (article) ─────────────────────────────────────────────── */
article {
  background: var(--w-surface);
  border: 1px solid var(--w-border);
  border-radius: var(--w-radius);
  padding: 1.25rem 1.25rem 0.75rem;
  transition: border-color 0.2s;
}

article footer {
  display: none;
  font-size: 0.8rem;
  color: var(--w-error);
  padding: 0.5rem 0 0.25rem;
  align-items: center;
  gap: 0.35rem;
}

article footer::before {
  content: "⚠";
  font-size: 0.9em;
}

article.invalid {
  border-color: var(--w-error);
}

article.invalid footer { display: flex; }

/* ── Fieldset / legend ───────────────────────────────────────────────────── */
fieldset {
  border: none;
  padding: 0;
}

legend {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
  color: var(--w-text);
  line-height: 1.4;
}

legend small {
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--w-text-muted);
  display: block;
  margin-top: 0.2rem;
}

/* ── Radio & Checkbox labels ─────────────────────────────────────────────── */
label {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.45rem 0;
  cursor: pointer;
  font-size: 0.92rem;
  color: var(--w-text);
  line-height: 1.4;
}

label input[type="radio"],
label input[type="checkbox"] {
  flex-shrink: 0;
  margin-top: 0.15rem;
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--w-primary);
  cursor: pointer;
}

/* ── Pain scale — horizontal layout ─────────────────────────────────────── */
.pain-scale-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.25rem;
}

.pain-scale-wrap input[type="radio"] { display: none; }

.pain-scale-wrap label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 1.5px solid var(--w-border);
  border-radius: var(--w-radius);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.pain-scale-wrap input[type="radio"]:checked + label {
  background: var(--w-primary);
  border-color: var(--w-primary);
  color: #fff;
}

.pain-scale-wrap label:hover {
  border-color: var(--w-primary);
  color: var(--w-primary);
}

/* ── Number input ────────────────────────────────────────────────────────── */
input[type="number"] {
  width: 120px;
  padding: 0.45rem 0.75rem;
  border: 1.5px solid var(--w-border);
  border-radius: var(--w-radius);
  font-size: 1rem;
  background: var(--w-bg);
  color: var(--w-text);
  appearance: textfield;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { opacity: 1; }

input[type="number"]:focus {
  outline: none;
  border-color: var(--w-primary);
}

/* ── Pain image ──────────────────────────────────────────────────────────── */
.pain-image-label { flex-direction: column; align-items: flex-start; }
.pain-image-label img { border-radius: 6px; max-width: 100%; width: 240px; }

/* ── Hidden follow-up questions ──────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Submit button ───────────────────────────────────────────────────────── */
.btn-submit {
  margin-top: 0.5rem;
  padding: 0.8rem 2rem;
  background: var(--w-primary);
  color: #fff;
  border: none;
  border-radius: var(--w-radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: background 0.2s;
}

.btn-submit:hover { background: var(--w-primary-hover); }
.btn-submit:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Loading spinner ─────────────────────────────────────────────────────── */
.loading-article {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem;
  background: var(--w-surface);
  border: 1px solid var(--w-border);
  border-radius: var(--w-radius);
  color: var(--w-text-muted);
}

.spinner {
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--w-border);
  border-top-color: var(--w-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Results section ─────────────────────────────────────────────────────── */
.results-section {
  margin-top: 1rem;
  padding: 1.25rem;
  background: var(--w-surface);
  border: 1px solid var(--w-border);
  border-radius: var(--w-radius);
}

.results-section h3 { margin-top: 1rem; }
.results-section p { margin-bottom: 0.75rem; }
.results-section ol, .results-section ul {
  padding-left: 1.5rem;
  margin-bottom: 0.75rem;
}

/* ── Consultation form ───────────────────────────────────────────────────── */
.consultation-section {
  margin-top: 1rem;
  padding: 1.25rem;
  background: var(--w-surface);
  border: 1px solid var(--w-border);
  border-radius: var(--w-radius);
}

.form-field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 1rem; }
.form-field label { font-size: 0.9rem; font-weight: 500; padding: 0; }

.form-field input[type="text"],
.form-field input[type="tel"] {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--w-border);
  border-radius: var(--w-radius);
  font-size: 0.95rem;
  background: var(--w-bg);
  color: var(--w-text);
  transition: border-color 0.2s;
}

.form-field input:focus {
  outline: none;
  border-color: var(--w-primary);
}

.privacy-label {
  font-size: 0.8rem;
  color: var(--w-text-muted);
  flex-direction: row;
  align-items: center;
  margin-bottom: 1rem;
}

.privacy-label a { color: var(--w-primary); }

/* ── File upload section ─────────────────────────────────────────────────── */
.file-upload-section {
  margin-top: 1rem;
  padding: 1.25rem;
  background: var(--w-surface);
  border: 1px dashed var(--w-border);
  border-radius: var(--w-radius);
}

.file-upload-section h3 { margin-bottom: 0.5rem; }
.file-upload-section p { font-size: 0.85rem; color: var(--w-text-muted); margin-bottom: 0.75rem; }

.file-input-wrap { display: flex; flex-direction: column; gap: 0.5rem; }

input[type="file"] {
  font-size: 0.9rem;
  padding: 0.4rem 0;
  color: var(--w-text);
}

.btn-upload {
  padding: 0.6rem 1.25rem;
  background: var(--w-primary);
  color: #fff;
  border: none;
  border-radius: var(--w-radius);
  font-size: 0.9rem;
  cursor: pointer;
  width: fit-content;
  transition: background 0.2s;
}

.btn-upload:hover { background: var(--w-primary-hover); }
.btn-upload:disabled { opacity: 0.6; cursor: not-allowed; }

.upload-status {
  font-size: 0.85rem;
  margin-top: 0.4rem;
}
.upload-status.success { color: #16a34a; }
.upload-status.error   { color: var(--w-error); }

/* ── Error message ───────────────────────────────────────────────────────── */
.form-error {
  font-size: 0.85rem;
  color: var(--w-error);
  margin-top: 0.5rem;
}

/* ── Success message ─────────────────────────────────────────────────────── */
.success-message { text-align: center; padding: 1rem 0; }
.success-message p { color: var(--w-text-muted); margin-top: 0.5rem; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  body { padding: 1rem 0.75rem 2rem; }
  h1 { font-size: 1.25rem; }
  .pain-scale-wrap label { width: 2.2rem; height: 2.2rem; font-size: 0.85rem; }
}
