:root {
  --bg: #07070a;
  --card: #111116;
  --card2: #17171e;
  --ink: #f4f2ee;
  --muted: #8c8a93;
  --line: rgba(255, 255, 255, 0.09);
  --lima: #c6f432;
  --verde: #3ee08f;
  --teal: #19c6c1;
  --ok: #3ee08f;
  --warn: #ffb020;
  --bad: #ff4d5e;
  --info: #7b9cff;
  --grad: linear-gradient(120deg, var(--lima), var(--verde) 55%, var(--teal));
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
h1, h2, .nivel { text-wrap: balance; }
p, li, .rasgo p, .consejo { text-wrap: pretty; }
h1, .sub, .lote .m, .alerta p { overflow-wrap: anywhere; }
:focus-visible { outline: 2px solid var(--verde); outline-offset: 2px; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 "Inter Tight", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh; -webkit-tap-highlight-color: transparent; overflow-x: hidden;
}
body::before {
  content: ""; position: fixed; inset: -20vh -20vw auto; height: 70vh; pointer-events: none; z-index: -1; filter: blur(30px);
  background: radial-gradient(40% 50% at 30% 40%, rgba(198, 244, 50, 0.14), transparent 70%),
    radial-gradient(40% 50% at 70% 30%, rgba(25, 198, 193, 0.16), transparent 70%);
}
.wrap { max-width: 980px; margin: 0 auto; padding: 18px 16px 90px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.logo { font-weight: 800; letter-spacing: -0.02em; font-size: 20px; color: var(--ink); text-decoration: none; white-space: nowrap; }
.logo b { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
h1 { font-size: clamp(30px, 7.5vw, 50px); line-height: 1.02; letter-spacing: -0.03em; margin: 0 0 10px; font-weight: 800; }
h1 em, h2 em { font: italic 400 1.08em "Instrument Serif", Georgia, serif; letter-spacing: 0; }
h2 { font-size: 20px; letter-spacing: -0.02em; margin: 0 0 12px; }
h3 { font-size: 16px; margin: 16px 0 6px; }
.sub { color: var(--muted); margin: 0 0 22px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
a { color: var(--verde); }
.btn {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-weight: 600; border-radius: 14px; padding: 12px 18px;
  color: #0b0b0e; background: var(--grad); display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; text-decoration: none; white-space: nowrap;
  transition-property: transform, opacity, filter, border-color; transition-duration: 140ms; transition-timing-function: var(--ease-out);
}
.btn:active:not(:disabled) { transform: scale(0.97); }
@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) { filter: brightness(1.08); }
  .btn.ghost:hover:not(:disabled) { border-color: rgba(255, 255, 255, 0.22); filter: none; }
  .lote:hover { transform: translateY(-2px); }
  .chip:hover:not(.on):not(:disabled) { border-color: rgba(255, 255, 255, 0.25); }
  .agregar:hover { border-color: rgba(62, 224, 143, 0.75); background-color: rgba(62, 224, 143, 0.04); }
}
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.ghost { background: var(--card2); color: var(--ink); border: 1px solid var(--line); }
.btn.small { min-height: 36px; padding: 7px 12px; border-radius: 10px; font-size: 14px; }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid rgba(255, 77, 94, 0.35); }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 13px; width: 100%; outline: none; min-height: 46px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: rgba(62, 224, 143, 0.6); }
input[type="checkbox"] { width: 20px; min-height: 20px; height: 20px; accent-color: var(--verde); }
label.campo { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
.titulo { all: unset; cursor: text; overflow-wrap: anywhere; border-radius: 8px; }
.titulo:focus-visible { outline: 2px solid var(--verde); outline-offset: 4px; }
.enlace {
  appearance: none; background: none; border: 0; padding: 0; font: inherit; color: var(--verde); text-decoration: underline;
  cursor: pointer; position: relative;
}
.enlace::after { content: ""; position: absolute; inset: -10px -4px; }
label.check { display: flex; gap: 10px; align-items: center; font-size: 15px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 18px; margin-bottom: 14px; min-width: 0; }
.err { color: var(--bad); min-height: 1.4em; margin: 8px 0 0; font-size: 14px; }
.hidden { display: none !important; }
.cols { display: grid; grid-template-columns: 1fr; gap: 14px; }
.cols > .card { margin-bottom: 0; }
@media (min-width: 860px) { .cols { grid-template-columns: 1fr 1fr; } }

/* inicio */
.hero { text-align: center; margin: 6vh auto 0; max-width: 620px; }
.hero .logo { font-size: clamp(44px, 14vw, 72px); display: inline-block; margin-bottom: 16px; }
.hero form { display: grid; gap: 10px; max-width: 440px; margin: 0 auto; }
.rasgos { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin-top: 44px; text-align: left; }
.rasgo { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px; }
.rasgo b { display: block; margin-bottom: 4px; }
.rasgo p { margin: 0; color: var(--muted); font-size: 14px; }
.recientes { margin: 0 auto 0; display: grid; gap: 8px; max-width: 440px; }
.recientes .btn { white-space: normal; overflow-wrap: anywhere; }
/* quien vuelve ve primero sus espacios; crear otro queda debajo, más discreto */
.hero form.otro { margin-top: 28px; }
.hero form.otro > .small { text-align: left; }
.tabla td, .kpi .v, .grid3 b { font-variant-numeric: tabular-nums; }

/* kpis */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; min-width: 0; }
.kpi .v { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 13px; }
.kpi .d { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* lotes */
.lotes { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.lote {
  display: block; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px 14px 14px 18px;
  color: var(--ink); text-decoration: none; position: relative; overflow: hidden; min-width: 0;
}
.lote::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--c, var(--muted)); }
.lote { transition-property: transform, border-color; transition-duration: 180ms; transition-timing-function: var(--ease-out); }
.lote:hover { border-color: rgba(62, 224, 143, 0.35); }
.lote:active { transform: scale(0.985); }
.lote .n { font-weight: 700; font-size: 17px; overflow-wrap: anywhere; }
.lote .m { color: var(--muted); font-size: 13px; }
.lote .fila { display: flex; gap: 14px; margin-top: 10px; flex-wrap: wrap; font-size: 14px; }
.lote .fila b { font-variant-numeric: tabular-nums; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip {
  font-size: 12px; border-radius: 999px; padding: 3px 9px; background: var(--card2); border: 1px solid var(--line); color: var(--ink); cursor: pointer; font-family: inherit;
  transition-property: background-color, color, border-color, transform; transition-duration: 150ms; transition-timing-function: ease;
}
/* chips tocables: 40 px de alto en el teléfono sin agrandar el dibujo */
button.chip { position: relative; font-variant-numeric: tabular-nums; }
button.chip::after { content: ""; position: absolute; inset: -9px -2px; }
button.chip:active:not(:disabled) { transform: scale(0.95); }
button.chip:disabled { opacity: 0.35; cursor: default; }
.chips:has(button.chip) { row-gap: 14px; }
.volver {
  display: inline-block; max-width: 100%; line-height: 40px; text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: top;
}
.chip.on { background: var(--ink); color: #0b0b0e; }
.chips.filtro { margin: 0 0 12px; }
.chip.alto { border-color: rgba(255, 77, 94, 0.5); color: #ff8f9a; }
.chip.moderado { border-color: rgba(255, 176, 32, 0.5); color: #ffc95e; }
.chip.info { border-color: rgba(123, 156, 255, 0.5); color: #a9bdff; }
.pasos { list-style: none; counter-reset: paso; margin: 0; padding: 0; display: grid; gap: 14px; }
.pasos li { counter-increment: paso; display: grid; grid-template-columns: 32px 1fr; column-gap: 12px; }
.pasos li::before {
  content: counter(paso); grid-row: span 2; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--card2); border: 1px solid var(--line); color: var(--verde); font-weight: 800; font-size: 14px;
}
.pasos span { color: var(--muted); font-size: 14px; }
.agregar {
  transition-property: transform, border-color, background-color; transition-duration: 160ms; transition-timing-function: var(--ease-out);
}
.agregar:active { transform: scale(0.985); }
.agregar { display: grid; place-items: center; min-height: 120px; border: 1px dashed rgba(62, 224, 143, 0.4); border-radius: 18px; color: var(--verde); text-decoration: none; font-weight: 600; }

/* estado */
.nivel { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: 24px; letter-spacing: -0.02em; }
.punto { width: 12px; height: 12px; border-radius: 50%; background: var(--c, var(--muted)); box-shadow: 0 0 12px var(--c, transparent); flex: none; }
.s-bueno { --c: var(--ok); } .s-atencion { --c: var(--warn); } .s-critico { --c: var(--bad); }
.s-sin, .s-espera, .s-fin { --c: var(--muted); } .s-inicio { --c: var(--info); }

/* campañas anteriores */
.campanas { display: grid; gap: 10px; }
.campana { background: var(--card2); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.campana .t { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: baseline; margin-bottom: 8px; }

/* ventana para cerrar la campaña: entra con un leve zoom, el fondo se oscurece */
.dialogo {
  width: min(440px, calc(100% - 32px)); max-height: calc(100dvh - 32px); overflow: auto; padding: 20px; border-radius: 20px;
  background: var(--card); color: var(--ink); border: 1px solid var(--line); box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  transition-property: opacity, transform, display, overlay; transition-duration: 200ms; transition-timing-function: var(--ease-out);
  transition-behavior: allow-discrete;
}
.dialogo::backdrop { background: rgba(0, 0, 0, 0.6); transition: opacity 200ms ease-out; }
@starting-style { .dialogo[open] { opacity: 0; transform: scale(0.96); } .dialogo[open]::backdrop { opacity: 0; } }
.dialogo h2 { margin-bottom: 10px; }

/* mapa */
.mapa { height: 340px; border-radius: 14px; overflow: hidden; background: #0d0d12; z-index: 0; }
.mapa.alto { height: min(62vh, 560px); }
@media (max-width: 600px) { .mapa.chico { height: 230px; } } /* en el panel del teléfono importan más las tarjetas */
.leaflet-container { font: inherit; background: #0d0d12; }
.leaflet-control-attribution { font-size: 10px; }
.leyenda { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.leyenda .barra { flex: 1; height: 8px; border-radius: 99px; background: linear-gradient(90deg, #a50026, #f46d43, #fee08b, #a6d96a, #1a9850, #006837); }
.herramientas { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; align-items: center; }
.mapa-guia { position: relative; }
.guia {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 500; pointer-events: none;
  background: rgba(7, 7, 10, 0.82); backdrop-filter: blur(6px); color: var(--ink); font-size: 13px; font-weight: 600;
  padding: 7px 12px; border-radius: 16px; border: 1px solid var(--line); width: max-content; max-width: calc(100% - 96px);
  text-align: center; text-wrap: balance; font-variant-numeric: tabular-nums;
}
.guia:empty { display: none; }
.guia.carga { top: auto; bottom: 10px; display: flex; align-items: center; gap: 8px; }
.guia.carga[hidden] { display: none; }
.vertice.nuevo { animation: pon 180ms var(--ease-out); }
@keyframes pon { from { transform: scale(0.5); opacity: 0; } }
.vertice { margin: 9px; width: 14px; height: 14px; box-shadow: 0 0 0 4px rgba(198, 244, 50, 0.18); border-radius: 50%; background: var(--lima); border: 2px solid #0b0b0e; }

/* sugerencia de fecha de siembra: entra con la vista y sale al descartarla */
.card.sat { border-color: rgba(123, 156, 255, 0.4); background: linear-gradient(180deg, rgba(123, 156, 255, 0.07), transparent 70%), var(--card); }
.card.sat { transition-property: opacity, transform; transition-duration: 150ms; transition-timing-function: var(--ease-out); }
.card.sat.sale { opacity: 0; transform: translateY(-6px) scale(0.98); }

/* alertas */
.alerta { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; background: var(--card2); }
.alerta.alto { border-color: rgba(255, 77, 94, 0.45); }
.alerta.moderado { border-color: rgba(255, 176, 32, 0.45); }
.alerta .t { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.alerta .t b { font-size: 15px; }
.alerta .ci { font-style: italic; color: var(--muted); font-size: 13px; }
.alerta p { margin: 6px 0 0; font-size: 14px; }
.etq { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; border-radius: 6px; padding: 2px 7px; }
.etq.alto { background: rgba(255, 77, 94, 0.18); color: #ff8f9a; }
.etq.moderado { background: rgba(255, 176, 32, 0.18); color: #ffc95e; }
.etq.bajo { background: rgba(62, 224, 143, 0.12); color: var(--verde); }

/* pronóstico */
.pron { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin-top: 12px; }
.pron > div { text-align: center; background: var(--card2); border-radius: 12px; padding: 8px 2px; font-size: 12px; min-width: 0; }
.pron .tt { font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.pron .muted { font-variant-numeric: tabular-nums; }
.pron .ll { font-weight: 700; font-size: 14px; color: #7fd8ff; }
.pron .bar { height: 34px; display: flex; align-items: flex-end; justify-content: center; margin: 4px 0; }
.pron .bar i { width: 10px; border-radius: 4px 4px 0 0; background: #4fb7ff; display: block; min-height: 2px; }

/* gráficos */
svg.graf { width: 100%; height: auto; display: block; overflow: visible; }
svg.graf text { fill: var(--muted); font-size: 11px; font-family: inherit; }

/* informe */
.informe h2 { font-size: 16px; margin: 16px 0 6px; }
.informe h2:first-child { margin-top: 0; }
.informe p, .informe li { font-size: 15px; }
.informe ul { padding-left: 20px; margin: 6px 0; }

/* zafra */
.tabla { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabla th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 6px 6px; border-bottom: 1px solid var(--line); }
.tabla td { padding: 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tabla input { min-height: 36px; padding: 6px 8px; border-radius: 8px; }
.tabla .num { width: 72px; }
.tabla .nombre { min-width: 104px; max-width: 180px; overflow-wrap: anywhere; line-height: 1.25; }
.tabla .nombre input { min-width: 96px; }
.tabla .nombre .small { font-size: 12px; margin-top: 2px; }
@media (max-width: 420px) {
  .card { padding: 14px; }
  .tabla td, .tabla th { padding: 6px 4px; }
  .tabla .num { width: 56px; }
  .tabla .nombre { min-width: 92px; }
}
.guardado { transition: opacity 400ms ease; }
.guardado.ok { color: var(--verde); }
.desliza { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.barras { display: grid; gap: 10px; }
.barras .b { display: grid; grid-template-columns: 110px 1fr 90px; gap: 10px; align-items: center; font-size: 14px; }
.barras .b .p { height: 14px; border-radius: 99px; background: var(--card2); overflow: hidden; }
.barras .b .p i { display: block; height: 100%; background: #3b3b47; border-radius: 99px; }
.barras .b.cuello .p i { background: var(--grad); }
.barras .b .v { text-align: right; font-variant-numeric: tabular-nums; }
.consejo { border-left: 3px solid var(--verde); padding: 4px 0 4px 12px; margin: 12px 0; }

.progreso { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; margin: 8px 0 14px; }
.giro { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--verde); border-radius: 50%; animation: giro 0.8s linear infinite; flex: none; }
@keyframes giro { to { transform: rotate(360deg); } }
.aviso {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: #0b0b0e;
  padding: 10px 16px; border-radius: 12px; font-weight: 600; z-index: 2000; max-width: calc(100% - 32px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);
  transition-property: transform, opacity; transition-duration: 220ms; transition-timing-function: var(--ease-out);
}
@starting-style { .aviso { opacity: 0; transform: translate(-50%, 16px); } }
.aviso.sale { opacity: 0; transform: translate(-50%, 16px); transition-duration: 150ms; }
.pie { color: var(--muted); font-size: 12px; margin-top: 30px; text-align: center; }

/* barra de avance real (imágenes procesadas de n) */
.avance { height: 4px; border-radius: 99px; background: var(--card2); overflow: hidden; margin: -6px 0 14px; }
.avance i { display: block; height: 100%; background: var(--grad); transform-origin: left; transform: scaleX(var(--p, 0)); transition: transform 300ms var(--ease-out); }

/* esqueleto mientras carga el lote */
.esq { border-radius: 20px; background: var(--card); border: 1px solid var(--line); margin-bottom: 14px; position: relative; overflow: hidden; }
.esq::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.04), transparent); animation: brillo 1.4s linear infinite;
}
@keyframes brillo { to { transform: translateX(100%); } }

/* entrada de cada vista: las tarjetas llegan escalonadas */
@keyframes entra { from { opacity: 0; transform: translateY(10px); } }
.entra > * { animation: entra 320ms var(--ease-out) backwards; }
.entra > :nth-child(2) { animation-delay: 40ms; } .entra > :nth-child(3) { animation-delay: 80ms; }
.entra > :nth-child(4) { animation-delay: 120ms; } .entra > :nth-child(5) { animation-delay: 160ms; }
.entra > :nth-child(6) { animation-delay: 200ms; } .entra > :nth-child(n + 7) { animation-delay: 240ms; }
.lotes.entra > * { animation-delay: calc(var(--i, 0) * 45ms); }

/* la curva observada se dibuja una vez al abrir el lote */
@keyframes traza { from { stroke-dashoffset: var(--largo); } }
.graf .trazo { stroke-dasharray: var(--largo); animation: traza 900ms var(--ease-in-out) 150ms backwards; }
.graf .obs { animation: entra 260ms var(--ease-out) backwards; animation-delay: calc(200ms + var(--i, 0) * 50ms); transform-box: fill-box; }
.leaflet-image-layer { animation: aparece 250ms ease-out; }
@keyframes aparece { from { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .entra > *, .graf .obs { animation: aparece 200ms ease-out backwards; animation-delay: 0ms !important; }
  .graf .trazo { animation: none; }
  .esq::after { animation: none; }
  .aviso, .aviso.sale { transform: translateX(-50%); }
  @starting-style { .aviso { transform: translateX(-50%); } }
  .lote:hover, .lote:active, .btn:active, button.chip:active { transform: none; }
  .card.sat.sale { transform: none; }
  .vertice.nuevo { animation: none; }
  .agregar:active { transform: none; }
  @starting-style { .dialogo[open] { transform: none; } }
}

.solo-impresion { display: none; }
@media print {
  @page { margin: 14mm; }
  body { background: #fff; color: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body::before, .top .btns, .noimprimir, .mapa, .guia, .volver, .chips, .sat .btns, .filtro, #prog, .avance { display: none !important; }
  .wrap { padding: 0; max-width: none; }
  .card, .kpi, .rasgo, .alerta, .pron > div { border-color: #ccc; background: #fff !important; break-inside: avoid; }
  .muted, .sub, .alerta .ci { color: #444; }
  .logo { color: #000; }
  .logo b { color: #127a4a; background: none; }
  [data-tipo] { display: none; }
  a { color: #000; text-decoration: none; }
  .solo-impresion { display: block; }
  .mapa-impreso { width: 60%; max-height: 300px; object-fit: contain; image-rendering: pixelated; border: 1px solid #ccc; border-radius: 8px; }
  .mapa-impreso:not([src]) { display: none; }
  /* la curva está dibujada para fondo oscuro: en papel, líneas y textos grises */
  svg.graf text { fill: #444; }
  svg.graf [stroke^="rgba(255,255,255"] { stroke: #9a9a9a; }
  svg.graf path[fill^="rgba(62,224,143"] { fill: rgba(62, 160, 100, 0.15); }
  .informe p, .informe li { font-size: 13px; }
  h1 { font-size: 28px; }
}
