/*
 * Interfaz de campo. Tres decisiones que mandan sobre todo lo demás:
 *
 *  - Alto contraste y tipografía grande: esto se usa a pleno sol, de pie y con
 *    prisa. Un gris elegante sobre blanco no se lee en la calle a mediodía.
 *  - Objetivos táctiles de 56 px o más: se opera con una mano, a veces con
 *    guantes o con el teléfono mojado.
 *  - Ningún color escrito directo en un componente. Todo por token, como pide
 *    el manual de identidad (§6.1).
 *
 * LA REGLA QUE PARECE UN ERROR Y NO LO ES (manual §2.2): los botones naranjas
 * llevan texto NEGRO. El naranja de marca da 2.81:1 contra blanco y reprueba
 * AA; contra negro da 6.20:1 y pasa. De ahí se siguen las otras dos:
 *
 *   · el naranja de marca NUNCA es color de texto — para eso está
 *     --marca-texto, que es el mismo naranja oscurecido hasta 4.76:1;
 *   · lo mismo aplica al ámbar de estado: --ambar da 3.12:1 sobre blanco, así
 *     que colorea bordes e indicadores, y el texto ámbar usa --ambar-texto.
 *
 * `test/identidad.test.ts` mide estos contrastes en cada corrida. Si alguien
 * pinta texto con un token de relleno, la prueba lo dice antes que un usuario.
 */

:root {
  /* Marca — manual de identidad §2.1 */
  --marca: #F57604;         /* relleno: fondos, barras, botones primarios */
  --marca-texto: #B75803;   /* única variante permitida para texto naranja */
  --marca-oscuro: #8A4202;  /* hover, presionado, bordes de piezas naranjas */
  --marca-suave: #FEF0E3;   /* fondos de sección */

  /* Neutros — manual §2.1 */
  --tinta: #1A1A1A;
  --gris-texto: #4A4A4A;
  --gris-borde: #E0E0E0;
  --blanco: #FFFFFF;

  /* Estado — manual §2.1. No son decorativos: comunican información. */
  --verde: #1B7F3B;   /* al corriente · pagado · verificado */
  --ambar: #B8860B;   /* advertencia · por vencer */
  --rojo: #C0392B;    /* mora · crítico · vencido */

  /* Derivados. No vienen del manual: son los fondos tenues y la variante de
     texto que el manual no fija pero que la regla de contraste obliga. */
  --ambar-texto: #8A5A00;
  --verde-fondo: #E8F5EE;
  --ambar-fondo: #FFF9E8;  /* con #FFF4D6 el borde ámbar se quedaba en 2.97:1 */
  --rojo-fondo: #FDEAEA;

  --fondo: var(--marca-suave);
  --radio: 8px;   /* manual §6.2 */
  --toque: 56px;  /* el manual pide 48; en campo se queda en 56 */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--fondo);
  color: var(--tinta);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

/* Barra superior ---------------------------------------------------------- */

.barra {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) 14px 12px;
  background: var(--marca);
  color: var(--tinta);
}

.barra h1 {
  flex: 1;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.volver {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.12);
  color: var(--tinta);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.estado { display: flex; gap: 6px; align-items: center; }

.chip {
  border: 0;
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.chip-linea { background: rgba(0, 0, 0, 0.12); color: var(--tinta); }
.chip-linea.sin-linea { background: var(--blanco); color: var(--ambar-texto); }
.chip-cola { background: var(--blanco); color: var(--tinta); cursor: pointer; }

/* Vistas ------------------------------------------------------------------ */

main { padding: 16px 14px calc(28px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }

.vista[hidden] { display: none; }

h2 { margin: 0 0 4px; font-size: 1.3rem; }
h3 { margin: 0 0 8px; font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--gris-texto); }

.intro, .nota { margin: 0 0 16px; color: var(--gris-texto); }
.ayuda { margin: 8px 0 0; font-size: 0.85rem; color: var(--gris-texto); }
.vacio { padding: 24px; text-align: center; color: var(--gris-texto); background: var(--blanco); border-radius: var(--radio); }

.bloque {
  background: var(--blanco);
  border: 1px solid var(--gris-borde);
  border-radius: var(--radio);
  padding: 16px;
  margin-bottom: 14px;
}

.bloque-tenue { background: transparent; border-style: dashed; }

/* Tarjetas del inicio ----------------------------------------------------- */

.tarjeta {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--blanco);
  border: 1px solid var(--gris-borde);
  border-left: 5px solid var(--marca);
  border-radius: var(--radio);
  padding: 18px;
  margin-bottom: 12px;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.tarjeta-cliente { border-left-color: var(--marca-oscuro); }
.tarjeta-titulo { display: block; font-size: 1.15rem; font-weight: 650; }
.tarjeta-detalle { display: block; color: var(--gris-texto); margin-top: 3px; }
.tarjeta-dato { display: block; margin-top: 10px; font-weight: 650; color: var(--marca-texto); }

/* Listas ------------------------------------------------------------------ */

.lista { list-style: none; margin: 0 0 16px; padding: 0; }

.lista li {
  background: var(--blanco);
  border: 1px solid var(--gris-borde);
  border-radius: var(--radio);
  margin-bottom: 8px;
  overflow: hidden;
}

.lista button.fila {
  display: block;
  width: 100%;
  min-height: var(--toque);
  text-align: left;
  background: none;
  border: 0;
  padding: 14px 16px;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.fila-nombre { display: block; font-weight: 600; }
.fila-detalle { display: block; font-size: 0.88rem; color: var(--gris-texto); margin-top: 2px; }
.fila-dato { display: block; font-size: 0.88rem; margin-top: 4px; font-variant-numeric: tabular-nums; }

.lista-ruta { counter-reset: parada; }
.lista-ruta li { display: flex; align-items: stretch; }
.orden-numero {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  background: var(--fondo);
  font-weight: 700;
  color: var(--gris-texto);
  font-variant-numeric: tabular-nums;
}

/* Botones ----------------------------------------------------------------- */

.boton {
  display: block;
  width: 100%;
  min-height: var(--toque);
  border: 1px solid var(--marca-texto);
  border-radius: var(--radio);
  background: var(--blanco);
  color: var(--marca-texto);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  padding: 14px;
  margin-top: 10px;
}

.boton-principal { background: var(--marca); color: var(--tinta); border-color: var(--marca-oscuro); }
.boton-secundario { border-style: dashed; }
.boton-texto { border: 0; background: none; color: var(--gris-texto); font-weight: 500; }
.boton:disabled { opacity: 0.45; cursor: not-allowed; }

.opciones { display: grid; gap: 8px; }

.opcion {
  min-height: var(--toque);
  border: 1px solid var(--gris-borde);
  border-radius: var(--radio);
  background: var(--blanco);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 12px;
}

.opcion[aria-pressed="true"] { background: var(--marca); color: var(--tinta); border-color: var(--marca-oscuro); }

/* Campos ------------------------------------------------------------------ */

.campo { display: block; margin-bottom: 8px; }
.campo span { display: block; font-size: 0.88rem; color: var(--gris-texto); margin-bottom: 6px; }

.campo input, .campo textarea, .campo-select {
  width: 100%;
  min-height: var(--toque);
  padding: 12px;
  border: 1px solid var(--gris-borde);
  border-radius: var(--radio);
  font: inherit;
  background: var(--blanco);
  color: var(--tinta);
}

.campo textarea { min-height: 80px; resize: vertical; }

/* GPS --------------------------------------------------------------------- */

.gps {
  border: 1px solid var(--gris-borde);
  border-radius: var(--radio);
  padding: 14px;
  background: var(--fondo);
  font-variant-numeric: tabular-nums;
}

.gps-estado { margin: 0; color: var(--gris-texto); }
.gps-coordenada { margin: 0 0 4px; font-weight: 650; font-size: 1.05rem; }
.gps-precision { margin: 0; font-size: 0.9rem; }
.gps.buena { background: var(--verde-fondo); border-color: var(--verde); }
.gps.regular { background: var(--ambar-fondo); border-color: var(--ambar); }
.gps.mala { background: var(--rojo-fondo); border-color: var(--rojo); }

/* Galería ----------------------------------------------------------------- */

.galeria { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.galeria figure { margin: 0; position: relative; }
.galeria img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; display: block; }

.galeria .quitar {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 0;
  background: var(--rojo);
  color: var(--blanco);
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
}

/* Siguiente punto --------------------------------------------------------- */

.siguiente {
  background: var(--marca);
  color: var(--tinta);
  border-radius: var(--radio);
  padding: 20px;
  margin-bottom: 16px;
}

.siguiente-etiqueta { margin: 0; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.09em; }
.siguiente-nombre { margin: 4px 0 2px; font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.siguiente-direccion { margin: 0; font-size: 0.92rem; }
.siguiente-datos { display: flex; gap: 18px; margin-top: 14px; }
.dato-fuerte { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.siguiente .boton { background: var(--blanco); color: var(--marca-texto); border-color: var(--blanco); }

.ritmo {
  border-radius: var(--radio);
  padding: 12px 14px;
  margin-bottom: 16px;
  font-weight: 600;
  background: var(--blanco);
  border: 1px solid var(--gris-borde);
}

.ritmo.lenta { background: var(--ambar-fondo); border-color: var(--ambar); color: var(--ambar-texto); }

/* Pinpad ------------------------------------------------------------------ */

.vista-pinpad { max-width: 420px; margin: 0 auto; }
.pinpad { text-align: center; }
.pinpad-titulo { font-size: 1.35rem; font-weight: 700; margin: 8px 0 2px; }
.pinpad-detalle { margin: 0 0 20px; color: var(--gris-texto); }

.pinpad-puntos { display: flex; justify-content: center; gap: 16px; margin: 18px 0 26px; }

.punto {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--marca-oscuro);
  background: transparent;
}

.punto.lleno { background: var(--marca); }

.teclado { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.tecla {
  min-height: 68px;
  border: 1px solid var(--gris-borde);
  border-radius: var(--radio);
  background: var(--blanco);
  font: inherit;
  font-size: 1.6rem;
  font-weight: 600;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.tecla:active { background: var(--fondo); }
.tecla-tenue, .tecla-entrar { font-size: 0.95rem; }
.tecla-entrar { background: var(--marca); color: var(--tinta); border-color: var(--marca-oscuro); }

.pinpad-mensaje { min-height: 1.5em; margin: 16px 0 0; font-weight: 650; color: var(--rojo); }

.pinpad-resultado { text-align: center; padding-top: 20px; }
.resultado-icono { font-size: 3.4rem; margin: 0; }
.resultado-mensaje { font-size: 1.15rem; font-weight: 650; margin: 8px 0 20px; }

.resultado-orden {
  background: var(--verde-fondo);
  border: 1px solid var(--verde);
  border-radius: var(--radio);
  padding: 16px;
  margin-bottom: 20px;
}

.orden-etiqueta { margin: 0; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--gris-texto); }
.orden-acciones { margin: 4px 0 10px; font-weight: 700; font-size: 1.05rem; }
.orden-ticket { margin: 0; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.2rem; font-weight: 700; }

/* Varios ------------------------------------------------------------------ */

.error {
  margin: 12px 0 0;
  padding: 12px;
  border-radius: var(--radio);
  background: var(--rojo-fondo);
  border: 1px solid var(--rojo);
  color: var(--rojo);
  font-weight: 600;
}

.aviso {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--tinta);
  color: var(--blanco);
  padding: 13px 20px;
  border-radius: 999px;
  font-weight: 600;
  z-index: 50;
  max-width: 92vw;
  text-align: center;
}

.etiqueta-cola {
  display: inline-block;
  margin-top: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--ambar-fondo);
  color: var(--ambar-texto);
  font-size: 0.78rem;
  font-weight: 700;
}

@media (prefers-reduced-motion: no-preference) {
  .aviso { animation: aparecer 0.18s ease-out; }
  @keyframes aparecer { from { opacity: 0; transform: translate(-50%, 8px); } }
}

/* Agenda -------------------------------------------------------------------
   Módulo AGENDA (mandato de Dirección, 01-sep-2026). Solo tokens ya
   declarados arriba — la regla de identidad (§2.2) no se repite dos veces. */

.agenda-filtros { display: flex; gap: 8px; margin-bottom: 12px; }
.agenda-filtros .campo-select { margin: 0; }

.agenda-fila {
  padding: 12px 14px;
}
.agenda-fila-encabezado { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.agenda-hora { font-weight: 700; font-variant-numeric: tabular-nums; }
.agenda-fila-detalle { font-size: 0.88rem; color: var(--gris-texto); margin-top: 4px; }
.agenda-fila-nota { font-size: 0.85rem; color: var(--gris-texto); margin-top: 2px; font-style: italic; }

.agenda-estado {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--fondo);
  color: var(--gris-texto);
}
.agenda-estado-confirmed, .agenda-estado-reminder_sent { background: var(--verde-fondo); color: var(--verde); }
.agenda-estado-arrived, .agenda-estado-in_progress { background: var(--ambar-fondo); color: var(--ambar-texto); }
.agenda-estado-completed { background: var(--verde-fondo); color: var(--verde); }
.agenda-estado-no_show, .agenda-estado-cancelled { background: var(--rojo-fondo); color: var(--rojo); }

.agenda-acciones { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.boton-chico {
  width: auto;
  min-height: 40px;
  padding: 8px 12px;
  margin-top: 0;
  font-size: 0.85rem;
}
