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

/* ── Tokens de diseño ────────────────────────────────────────────────── */
:root {
  /* Colores primarios */
  --c-primary:      #1a5276;
  --c-primary-dark: #154360;
  --c-primary-light:#d6eaf8;
  --c-action:       #1e8449;
  --c-action-dark:  #196f3d;

  /* Superficies */
  --c-bg:     #f0f4f8;
  --c-surface: #ffffff;
  --c-border:  #d0d9e3;
  --c-border-focus: #1a5276;

  /* Texto */
  --c-text:     #1a202c;
  --c-text-sub: #4a5568;
  --c-text-dim: #718096;

  /* Estados */
  --c-error:   #c0392b;
  --c-error-bg:#fdf3f2;
  --c-success: #1e8449;

  /* Espaciado — sistema 8dp */
  --s-1:  4px;
  --s-2:  8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;
  --s-10:40px;

  /* Radios */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;

  /* Sombras */
  --shadow-card: 0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-btn:  0 1px 2px rgba(0,0,0,.12);
}

/* ── Base ────────────────────────────────────────────────────────────── */
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.55;
  background: var(--c-bg);
  color: var(--c-text);
  min-height: 100dvh;
  /* Elimina el delay de 300ms en tablet */
  touch-action: manipulation;
}

#app {
  max-width: 860px;
  margin: 0 auto;
  padding: var(--s-6) var(--s-5) var(--s-10);
}

/* ── Pantallas ────────────────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: block; animation: fadeIn 0.18s ease-out; }
.hidden { display: none !important; }

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

@media (prefers-reduced-motion: reduce) {
  .screen.active { animation: none; }
}

/* ── Indicador de pasos ────────────────────────────────────────────────*/
.steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  margin-bottom: var(--s-6);
}
.step-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--c-border);
  transition: background 0.2s, transform 0.2s;
}
.step-dot.done    { background: var(--c-primary-light); }
.step-dot.active  { background: var(--c-primary); transform: scale(1.35); }

/* ── Cabecera ─────────────────────────────────────────────────────────── */
.app-header {
  text-align: center;
  padding-bottom: var(--s-6);
  border-bottom: 1px solid var(--c-border);
  margin-bottom: var(--s-6);
}
.app-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--c-primary);
  letter-spacing: -0.3px;
}
.app-header .subtitle {
  font-size: 15px;
  color: var(--c-text-sub);
  margin-top: var(--s-1);
}

/* ── Títulos de sección ───────────────────────────────────────────────── */
h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--c-primary);
  margin-bottom: var(--s-5);
  letter-spacing: -0.2px;
}
h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--c-primary);
  margin: var(--s-5) 0 var(--s-3);
  padding-bottom: var(--s-2);
  border-bottom: 1px solid var(--c-border);
}

/* ── Tarjetas de formulario (pantalla 1) ──────────────────────────────── */
.form-grid {
  display: grid;
  gap: var(--s-3);
}

.btn-form {
  display: flex;
  align-items: flex-start;
  flex-direction: column;
  width: 100%;
  padding: var(--s-5) var(--s-5);
  background: var(--c-surface);
  color: var(--c-text);
  border: 2px solid var(--c-border);
  border-radius: var(--r-md);
  font-size: 16px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  /* Franja de color izquierda */
  border-left: 4px solid var(--c-primary);
}
.btn-form:hover {
  border-color: var(--c-primary);
  box-shadow: 0 4px 12px rgba(26,82,118,.15);
}
.btn-form:active {
  transform: scale(0.985);
  box-shadow: var(--shadow-btn);
}
.btn-form .form-title {
  color: var(--c-primary);
  font-size: 16px;
  font-weight: 700;
}
.btn-form .form-sub {
  display: block;
  margin-top: var(--s-1);
  font-size: 13px;
  font-weight: 400;
  color: var(--c-text-sub);
}

/* ── Botones de acción ────────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 var(--s-8);
  margin-top: var(--s-5);
  background: var(--c-action);
  color: white;
  border: none;
  border-radius: var(--r-md);
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-btn);
  transition: background 0.15s, transform 0.1s, box-shadow 0.1s;
  letter-spacing: 0.1px;
}
.btn-primary:hover:not(:disabled) {
  background: var(--c-action-dark);
}
.btn-primary:active:not(:disabled) {
  transform: scale(0.97);
  box-shadow: none;
}
.btn-primary:disabled {
  background: #a0aec0;
  cursor: not-allowed;
  box-shadow: none;
}
/* Focus visible (accesibilidad teclado) */
.btn-primary:focus-visible {
  outline: 3px solid var(--c-primary);
  outline-offset: 3px;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 var(--s-8);
  margin-top: var(--s-5);
  background: var(--c-surface);
  color: var(--c-text-sub);
  border: 2px solid var(--c-border);
  border-radius: var(--r-md);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, transform 0.1s;
}
.btn-secondary:hover {
  border-color: var(--c-text-sub);
  color: var(--c-text);
}
.btn-secondary:active {
  transform: scale(0.97);
}
.btn-secondary:focus-visible {
  outline: 3px solid var(--c-primary);
  outline-offset: 3px;
}

.row-btns {
  display: flex;
  gap: var(--s-3);
  flex-wrap: wrap;
  align-items: center;
}

/* ── Formulario de datos del paciente ─────────────────────────────────── */
.field-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

/* En tablet (≥580px) ponemos 2 columnas para campos cortos */
@media (min-width: 580px) {
  .field-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 var(--s-4);
  }
}

label.field-label {
  display: block;
  margin-bottom: var(--s-4);
  font-size: 14px;
  font-weight: 600;
  color: var(--c-text);  /* contraste alto — antes era var(--gris) */
  letter-spacing: 0.1px;
}

label.field-label span.required {
  color: var(--c-error);
  margin-left: 2px;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="date"],
input[type="number"] {
  display: block;
  width: 100%;
  padding: 13px var(--s-4);
  margin-top: var(--s-1);
  font-size: 17px;
  font-family: inherit;
  color: var(--c-text);
  background: var(--c-surface);
  border: 2px solid var(--c-border);
  border-radius: var(--r-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
  /* Mínimo 44px de altura para touch */
  min-height: 50px;
}
input:focus {
  border-color: var(--c-border-focus);
  box-shadow: 0 0 0 3px rgba(26,82,118,.12);
  outline: none;
}
input::placeholder { color: var(--c-text-dim); }

.check-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  font-size: 16px;
  font-weight: 500;
  color: var(--c-text);
  padding: var(--s-3) 0;
  cursor: pointer;
  /* Área táctil generosa */
  min-height: 44px;
}
.check-row input[type="checkbox"] {
  width: 24px; height: 24px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--c-primary);
}

/* ── Pantalla de documento ────────────────────────────────────────────── */
.doc-wrapper { position: relative; }

/* Sombra que indica que hay más contenido al hacer scroll */
.doc-wrapper::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 40px;
  background: linear-gradient(to top, rgba(255,255,255,.95), transparent);
  border-radius: 0 0 var(--r-sm) var(--r-sm);
  pointer-events: none;
  transition: opacity 0.2s;
}
.doc-wrapper.scrolled-end::after { opacity: 0; }

.doc-scroll {
  height: 420px;
  overflow-y: scroll;
  background: var(--c-surface);
  border: 2px solid var(--c-border);
  border-radius: var(--r-sm);
  padding: var(--s-5);
  font-size: 15px;
  line-height: 1.75;
  scroll-behavior: smooth;
  /* Scroll suave en iOS */
  -webkit-overflow-scrolling: touch;
}
.doc-scroll .sec-heading {
  font-weight: 700;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--c-primary);
  margin: var(--s-5) 0 var(--s-2);
}
.doc-scroll .sec-heading:first-child { margin-top: 0; }
.doc-scroll .sec-line { margin-bottom: var(--s-1); color: var(--c-text); }
.doc-scroll hr { border: none; border-top: 1px solid var(--c-border); margin: var(--s-4) 0; }

.read-confirm {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  font-size: 16px;
  font-weight: 500;
  color: var(--c-text);
  padding: var(--s-4);
  margin-top: var(--s-3);
  background: var(--c-primary-light);
  border-radius: var(--r-sm);
  cursor: pointer;
  /* Touch target generoso */
  min-height: 54px;
}
.read-confirm input[type="checkbox"] {
  width: 26px; height: 26px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--c-primary);
}

/* ── Pantalla de firma ────────────────────────────────────────────────── */
.sign-instructions {
  font-size: 15px;
  color: var(--c-text-sub);
  margin-bottom: var(--s-4);
  padding: var(--s-3) var(--s-4);
  background: var(--c-primary-light);
  border-radius: var(--r-sm);
}

#sig-canvas {
  display: block;
  width: 100%;
  height: 300px;
  border: 2px dashed var(--c-primary);
  border-radius: var(--r-md);
  background: var(--c-surface);
  margin-bottom: var(--s-5);
  touch-action: none;
  cursor: crosshair;
  box-shadow: inset 0 1px 4px rgba(0,0,0,.05);
}

/* ── Estado de envío ──────────────────────────────────────────────────── */
.status-box {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-top: var(--s-4);
  padding: var(--s-4) var(--s-5);
  background: var(--c-primary-light);
  border-left: 4px solid var(--c-primary);
  border-radius: var(--r-sm);
  font-size: 15px;
  color: var(--c-primary);
  font-weight: 500;
}
.status-box::before {
  content: '';
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--c-primary);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .status-box::before { animation: none; }
}

/* ── Pantallas de confirmación y error ────────────────────────────────── */
.result-card {
  text-align: center;
  padding: var(--s-10) var(--s-6);
  background: var(--c-surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  max-width: 520px;
  margin: var(--s-6) auto;
}

.result-icon {
  width: 72px; height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto var(--s-5);
  font-size: 32px;
  font-weight: 700;
}
.result-icon.ok  { background: #d4efdf; color: var(--c-success); }
.result-icon.err { background: #fde8e8; color: var(--c-error); }

.result-card h2 {
  font-size: 22px;
  margin-bottom: var(--s-3);
  color: var(--c-text);
}
.result-card p {
  font-size: 15px;
  color: var(--c-text-sub);
  line-height: 1.65;
  margin-bottom: var(--s-4);
}
.result-card .doc-id {
  display: inline-block;
  font-family: monospace;
  font-size: 13px;
  background: var(--c-bg);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  color: var(--c-text-sub);
  word-break: break-all;
}
