:root {
  --verde: #2e7d32;
  --verde-osc: #1b5e20;
  --verde-claro: #e8f5e9;
  --fondo: #f6f8f5;
  --tarjeta: #ffffff;
  --texto: #1d2420;
  --texto-suave: #5b665e;
  --borde: #d5ddd6;
  --error: #b3261e;
  --aviso: #8a5a00;
  --ok: #1e7b34;
  /* Colores de las pasadas (definidos por el usuario) */
  --p-izq: #d32f2f;
  --p-cen: #2e9e3e;
  --p-der: #1e5bd6;
  --p-suma: #f2c200;
  --interp: #9e9e9e;
  /* Escala de CV */
  --cv-bueno: #2e9e3e;
  --cv-medio: #e0a800;
  --cv-malo: #d32f2f;
  --radio: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  -webkit-tap-highlight-color: transparent;
}

.acerca p { margin: 6px 0; }
.acerca a { color: var(--verde); }

main { padding: 12px 16px calc(var(--alto-nav, 64px) + 12px); max-width: 960px; margin: 0 auto; }
section.pantalla { display: none; }
section.pantalla.activa { display: block; }
/* Pantallas que ocupan exactamente el alto disponible, sin desplazamiento */
section.pantalla.llena.activa {
  display: flex; flex-direction: column; gap: 6px;
  height: calc(var(--alto-vista, 100dvh) - var(--alto-nav, 64px) - 24px); min-height: 280px;
}

.titulo-app { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.titulo-app > div { flex: 1; }
.titulo-app .btn-info + .btn-info { margin-left: -2px; }
.titulo-app b { display: block; font-size: 18px; color: var(--verde-osc); }
.titulo-app small { color: var(--texto-suave); }
.btn-info { flex: none; width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--verde);
  background: #fff; color: var(--verde); font: italic 700 16px Georgia, serif; cursor: pointer; }

nav.pestanas {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: #fff; border-top: 1px solid var(--borde);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.pestanas button {
  flex: 1; border: 0; background: none; padding: 8px 2px 10px;
  font: inherit; font-size: 12px; color: var(--texto-suave);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
nav.pestanas button svg { width: 24px; height: 24px; }
nav.pestanas button.activa { color: var(--verde); font-weight: 600; }

.tarjeta {
  background: var(--tarjeta); border: 1px solid var(--borde);
  border-radius: var(--radio); padding: 12px; margin-bottom: 12px;
}
.tarjeta h2 { font-size: 16px; margin: 0 0 8px; }
.tarjeta h3 { font-size: 14px; margin: 12px 0 6px; color: var(--texto-suave); }

label.campo { display: block; margin-bottom: 10px; }
label.campo > span { display: block; font-size: 13px; color: var(--texto-suave); margin-bottom: 3px; }
input[type=text], input[type=number], input[type=date], select {
  width: 100%; font: inherit; padding: 9px 10px;
  border: 1px solid var(--borde); border-radius: 8px; background: #fff; color: var(--texto);
}
input:focus, select:focus { outline: 2px solid var(--verde); outline-offset: -1px; border-color: var(--verde); }
input.invalido { border-color: var(--error); background: #fff4f3; }
.fila { display: flex; gap: 10px; }
.fila > * { flex: 1; min-width: 0; }

.ayuda { font-size: 13px; color: var(--texto-suave); margin: 4px 0 0; }
.error-txt { font-size: 12px; color: var(--error); min-height: 0; }
.aviso { background: #fff7e0; border: 1px solid #f0d58a; color: var(--aviso);
  border-radius: 8px; padding: 8px 10px; font-size: 14px; margin-bottom: 10px; }
.aviso.error { background: #fdecea; border-color: #f2b8b5; color: var(--error); }

button.btn {
  font: inherit; border-radius: 8px; padding: 9px 14px; cursor: pointer;
  border: 1px solid var(--verde); background: var(--verde); color: #fff;
}
button.btn.sec { background: #fff; color: var(--verde); }
button.btn.peligro { border-color: var(--error); background: #fff; color: var(--error); }
button.btn:disabled { opacity: .5; }
.botones { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.segmentado { display: flex; border: 1px solid var(--verde); border-radius: 8px; overflow: hidden; }
.segmentado button { flex: 1; border: 0; background: #fff; color: var(--verde); padding: 8px; font: inherit; }
.segmentado button.activa { background: var(--verde); color: #fff; }

/* Tira horizontal de cajas: misma disposición que en el campo */
.cabecera-cajas { display: flex; align-items: center; gap: 10px; }
.cabecera-cajas .ayuda { flex: 1; margin: 0; }
button.btn.chico { padding: 5px 10px; font-size: 14px; }
.tira-cajas {
  flex: 1; min-height: 0;
  display: flex; gap: 3px; overflow-x: auto; overscroll-behavior-x: contain;
  padding: 4px 2px 8px; background: var(--tarjeta); border: 1px solid var(--borde); border-radius: var(--radio);
}
.nota-cajas { margin: 0; font-size: 12px; }
.col-caja { flex: 0 0 46px; display: flex; flex-direction: column; }
.col-caja .barra-cont {
  flex: 1; min-height: 40px; display: flex; align-items: flex-end; justify-content: center;
  border-bottom: 2px solid #9aa59d; position: relative;
}
.col-caja .barra { width: 78%; background: var(--p-cen); border-radius: 3px 3px 0 0; min-height: 0; }
.col-caja.interpolada .barra { background: var(--interp); opacity: .6; }
.col-caja.sin-dato .barra-cont::after {
  content: ""; position: absolute; left: 15%; right: 15%; bottom: 2px; height: 3px; background: var(--error);
}
.col-caja .num { text-align: center; font-weight: 700; font-size: 14px; margin-top: 4px; }
.col-caja .pos { text-align: center; font-size: 12px; letter-spacing: -.3px; color: var(--texto-suave); margin-bottom: 3px; white-space: nowrap; }
.col-caja input { text-align: center; padding: 8px 1px; font-size: 15px; border-radius: 6px; }
.col-caja.interpolada input { border-style: dashed; }
.col-caja.interpolada input::placeholder { color: var(--interp); }
.col-caja.seleccionada .num { color: var(--verde); }
.col-caja.seleccionada .barra-cont { background: var(--verde-claro); border-radius: 4px 4px 0 0; }
.instalar { border-color: var(--verde); background: var(--verde-claro); }

/* Gráficos */
.grafico { width: 100%; display: block; touch-action: pan-y; }
.grafico text { font-size: 11px; fill: var(--texto-suave); font-family: inherit; }
.leyenda { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--texto-suave); margin-top: 4px; }
.leyenda i { display: inline-block; width: 12px; height: 12px; border-radius: 2px; vertical-align: -2px; margin-right: 4px; }

/* Resultados grandes */
.resultados { display: flex; gap: 10px; }
.resultados .dato { flex: 1; background: var(--verde-claro); border-radius: 8px; padding: 8px 10px; }
.resultados .dato .etq { font-size: 12px; color: var(--texto-suave); }
.resultados .dato .val { font-size: 26px; font-weight: 700; }
.resultados .dato .val small { font-size: 14px; font-weight: 400; }
.resultados .dato.mal { background: #fdecea; }
.resultados .dato.mal .val { color: var(--error); }
.resultados .dato.bien .val { color: var(--ok); }
.resultados .dato.medio { background: #fff4cc; }
.resultados .dato.medio .val { color: #8a6400; }
.cv-bueno { color: var(--ok); font-weight: 600; }
.cv-medio { color: #8a6400; font-weight: 600; }
.cv-malo { color: var(--error); font-weight: 600; }
#res-detalle { margin: 0; font-size: 12px; min-height: 1.4em; }

.control-ancho { display: flex; align-items: center; gap: 8px; }
.ancho-bloque { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.control-ancho input[type=range] { width: 100%; accent-color: var(--verde); height: 28px; margin: 0; }
.control-ancho button { flex: none; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--verde);
  background: #fff; color: var(--verde); font-size: 22px; line-height: 1; }
.ancho-valor { font-size: 18px; font-weight: 700; text-align: center; }

/* Pasadas */
.controles-pasadas { display: flex; flex-direction: column; gap: 6px; }
.controles-pasadas .resultados .dato { padding: 4px 10px; }
.controles-pasadas .resultados .dato .etq, .controles-pasadas .resultados .dato .val { white-space: nowrap; }
.controles-pasadas .resultados .dato .val { font-size: 22px; }
.contenedor-grafico { flex: 1; min-height: 120px; position: relative; }
.contenedor-grafico svg { position: absolute; inset: 0; width: 100%; height: 100%; }
#p-pasadas .leyenda { margin: 0; font-size: 11px; }
#res-mitades { margin: 0; font-size: 12px; }

/* Celular apaisado: todo más compacto, los controles en una sola línea */
@media (orientation: landscape) and (max-height: 560px) {
  main { padding-top: 6px; padding-bottom: calc(var(--alto-nav, 44px) + 6px); }
  section.pantalla.llena.activa { height: calc(var(--alto-vista, 100dvh) - var(--alto-nav, 44px) - 12px); min-height: 220px; gap: 4px; }
  nav.pestanas button { flex-direction: row; justify-content: center; gap: 6px; padding: 5px 2px; font-size: 13px; }
  nav.pestanas button svg { width: 20px; height: 20px; }
  .controles-pasadas { flex-direction: row; align-items: center; gap: 10px; }
  .controles-pasadas .segmentado button { padding: 6px 10px; }
  .controles-pasadas .control-ancho { flex: 1; }
  .control-ancho button { width: 34px; height: 34px; font-size: 20px; }
  .ancho-valor { font-size: 15px; }
  .controles-pasadas .resultados .dato { padding: 2px 8px; }
  .controles-pasadas .resultados .dato .etq { font-size: 11px; }
  .controles-pasadas .resultados .dato .val { font-size: 18px; }
  .nota-cajas { display: none; }
  .col-caja input { padding: 5px 1px; }
  .col-caja .pos { margin-bottom: 1px; }
}

.lista-ensayos { list-style: none; margin: 0; padding: 0; }
.lista-ensayos li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--borde); }
.lista-ensayos li .info { flex: 1; min-width: 0; }
.lista-ensayos li .info b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lista-ensayos li .info small { color: var(--texto-suave); }

table.tabla { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tabla th, table.tabla td { padding: 4px 6px; border-bottom: 1px solid var(--borde); text-align: right; }
table.tabla th:first-child, table.tabla td:first-child { text-align: left; }
table.tabla tr.ok td { color: var(--ok); }

details summary { cursor: pointer; color: var(--verde); margin: 4px 0; }
.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  background: #323232; color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 14px;
  opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 20; }
.toast.ver { opacity: 1; }

/* ===== Selector de módulo y módulo Recomendación y costos ===== */
.selector-modulo { margin-bottom: 12px; }
.selector-modulo button { font-size: 14px; padding: 7px 6px; }
.etq-campo { display: block; font-size: 13px; color: var(--texto-suave); margin: 4px 0 3px; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; margin: 0 0 10px; }
label.check input { margin-top: 3px; }
.dosis-p .dato { background: var(--verde-claro); border-radius: 8px; padding: 6px 10px; }
.dosis-p .dato .etq { font-size: 12px; color: var(--texto-suave); }
.dosis-p .dato .val { font-size: 26px; font-weight: 700; display: inline-block; margin-right: 8px; }
.dosis-p .dato .val small { font-size: 14px; font-weight: 400; }
.dosis-p .explica { font-size: 13px; margin: 4px 2px 12px; }
small.eq { color: var(--texto-suave); font-size: 12px; }
.fuente { font-size: 11px; }
.tabla-desliza { overflow-x: auto; margin: 0 -6px; }
/* Tabla de precios compacta: entra en el ancho de un celular sin desplazarse */
.tabla-fert { font-size: 12px; }
.tabla-fert td, .tabla-fert th { vertical-align: middle; padding: 4px 3px; }
.tabla-fert th { font-size: 11px; line-height: 1.2; }
.tabla-fert td:first-child { line-height: 1.25; }
.tabla-fert td.grado { text-align: center; white-space: nowrap; font-size: 11px; }
.tabla-fert input.precio { width: 44px; padding: 4px 2px; text-align: right; font-size: 13px; }
.tabla-fert th.costo { white-space: nowrap; }
.tabla-fert button.quitar { margin-top: 3px; padding: 2px 8px; font-size: 12px; }
.opcion.mejor { border: 2px solid var(--verde); }
.opcion-cab { display: flex; justify-content: space-between; align-items: baseline; }
.opcion-cab .total { font-size: 20px; font-weight: 700; color: var(--verde-osc); }
.opcion ul.items { list-style: none; margin: 6px 0 0; padding: 0; }
.opcion ul.items li { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--borde); flex-wrap: wrap; }
.opcion ul.items .prod { flex-basis: 100%; }
.opcion ul.items .cant { font-weight: 700; }
.opcion ul.items .costo { color: var(--texto-suave); font-size: 14px; flex: 1; }

/* ===== Informe (PDF) ===== */
.barra-informe { display: flex; gap: 8px; justify-content: space-between; }
.nota-imprimir { margin: 6px 0 10px; }
.informe { background: #fff; color: #111; border: 1px solid var(--borde); border-radius: var(--radio);
  padding: 16px; font-size: 13px; line-height: 1.35; overflow-x: auto; }
.inf-cab { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start;
  border-bottom: 2px solid var(--verde); padding-bottom: 6px; margin-bottom: 10px; }
.inf-cab h1 { font-size: 18px; margin: 0; color: var(--verde-osc); }
.inf-cab p { margin: 2px 0 0; color: #444; }
.inf-app { text-align: right; font-size: 11px; color: #555; }
.informe h2 { font-size: 14px; margin: 14px 0 6px; color: var(--verde-osc); border-bottom: 1px solid #ddd; padding-bottom: 2px; }
.informe h3 { font-size: 13px; margin: 10px 0 4px; }
.informe .bloque { break-inside: avoid; page-break-inside: avoid; }
.inf-datos { border-collapse: collapse; margin: 4px 0; }
.inf-datos th { text-align: left; font-weight: 400; color: #555; padding: 2px 12px 2px 0; vertical-align: top; }
.inf-datos td { padding: 2px 0; }
.inf-tabla, .inf-pesos { border-collapse: collapse; width: 100%; margin: 6px 0; font-size: 12px; }
.inf-tabla th, .inf-tabla td, .inf-pesos th, .inf-pesos td { border: 1px solid #ccc; padding: 3px 5px; text-align: left; vertical-align: top; }
.inf-tabla th { background: #f1f5f1; }
.inf-pesos td { text-align: center; }
.inf-pesos th { background: #f1f5f1; width: 40px; }
.inf-pesos td.interp { color: #888; font-style: italic; }
.inf-graf { width: 100%; height: auto; display: block; margin: 4px 0; }
.informe .nota { font-size: 11px; color: #555; margin: 4px 0; }
.inf-pie { margin-top: 16px; border-top: 1px solid #ddd; padding-top: 6px; font-size: 10px; color: #666; }

@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; }
  nav.pestanas, .toast, .barra-informe, .nota-imprimir { display: none !important; }
  section.pantalla:not(#p-informe) { display: none !important; }
  main { padding: 0 !important; max-width: none; }
  .informe { border: 0; padding: 0; border-radius: 0; overflow: visible; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Ayuda */
.ayuda-texto details { border-top: 1px solid var(--borde); padding: 6px 0; }
.ayuda-texto summary { font-weight: 600; padding: 4px 0; }
.ayuda-texto ol, .ayuda-texto ul { padding-left: 20px; margin: 6px 0; }
.ayuda-texto li { margin-bottom: 6px; font-size: 14px; }
.ayuda-texto h3 { margin: 10px 0 4px; }

/* Botón para cambiar de módulo, al principio de cada barra de pestañas */
nav.pestanas button.cambiar-modulo { flex: 0.8; color: var(--verde-osc); border-right: 1px solid var(--borde); background: var(--verde-claro); }
nav.pestanas button.cambiar-modulo .flecha { font-size: 20px; line-height: 24px; font-weight: 700; }
