@font-face {
  font-family: 'Figtree';
  src: url('fonts/figtree.woff2') format('woff2');
  font-weight: 300 900;
  font-display: swap;
}

:root {
  --bg: #F5F3EC;
  --surface: #FFFFFF;
  --surface-2: #EDEAE0;
  --ink: #17231D;
  --ink-2: #4A5650;
  --ink-3: #6E7872;
  --line: #D9D5C8;
  --green: #1F4D3A;
  --green-2: #2E6B51;
  --green-soft: #E3EEE7;
  --magenta: #B8245C;
  --magenta-soft: #F8E4EC;
  --amber: #9A5B00;
  --amber-soft: #FBEFD9;
  --red: #B42318;
  --red-soft: #FDE8E6;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(23, 35, 29, .06), 0 2px 8px rgba(23, 35, 29, .05);
  --tap: 52px;
  --font: 'Figtree', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
.num, .tabular { font-variant-numeric: tabular-nums; }

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--green); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  display: flex; align-items: center; gap: 10px;
}
.topbar .back {
  width: 44px; height: 44px; border-radius: 12px; border: 0; background: rgba(255,255,255,.12);
  display: grid; place-items: center; color: #fff; cursor: pointer; flex: none;
}
.topbar .title { flex: 1; min-width: 0; }
.topbar .title strong { display: block; font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title span { display: block; font-size: 13px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .logo { width: 36px; height: 36px; flex: none; }
.net {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600;
  padding: 6px 10px; border-radius: 999px; background: rgba(255,255,255,.14); border: 0; color: #fff; cursor: pointer; flex: none;
}
.net .dot { width: 8px; height: 8px; border-radius: 50%; background: #9BE3A8; }
.net.off .dot { background: #F5B971; }

.banner-demo {
  background: var(--amber-soft); color: var(--amber); font-size: 14px; font-weight: 600;
  padding: 8px 14px; text-align: center; border-bottom: 1px solid #F0DDB5;
}

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

/* ---------- Tarjetas y secciones ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; border: 1px solid #ECE8DC; }
.card h2 { font-size: 16px; font-weight: 700; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.card h2 .step { width: 26px; height: 26px; border-radius: 50%; background: var(--green-soft); color: var(--green); display: grid; place-items: center; font-size: 14px; flex: none; }
.section-label { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); margin: 22px 4px 10px; }
.muted { color: var(--ink-3); font-size: 14px; }
.hint { color: var(--ink-3); font-size: 14px; margin-top: 6px; }

/* ---------- Formularios ---------- */
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field > label, .field > .label { display: block; font-weight: 600; font-size: 15px; margin-bottom: 6px; }
.field .req { color: var(--magenta); }
input[type=text], input[type=email], input[type=number], input[type=url], input[type=password], select, textarea {
  width: 100%; min-height: var(--tap); padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--line); background: #fff; font-size: 17px; outline: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--green-2); box-shadow: 0 0 0 3px rgba(46, 107, 81, .18); }
.invalid input, .invalid select, input.invalid { border-color: var(--red) !important; }
.err { color: var(--red); font-size: 14px; margin-top: 6px; font-weight: 500; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg button {
  min-height: var(--tap); border-radius: var(--radius-sm); border: 1.5px solid var(--line); background: #fff;
  font-weight: 700; font-size: 17px; cursor: pointer;
}
.seg button[aria-pressed=true] { background: var(--green); border-color: var(--green); color: #fff; }

.stepper { display: grid; grid-template-columns: var(--tap) 1fr var(--tap); gap: 8px; align-items: center; }
.stepper button {
  height: var(--tap); border-radius: var(--radius-sm); border: 1.5px solid var(--line); background: var(--surface-2);
  font-size: 26px; font-weight: 600; cursor: pointer; line-height: 1; touch-action: manipulation;
}
.stepper button:active { background: var(--line); }
.stepper input { text-align: center; font-weight: 700; font-size: 20px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 12px 18px; border-radius: var(--radius-sm); border: 0;
  font-weight: 700; font-size: 17px; cursor: pointer; text-decoration: none; touch-action: manipulation;
}
.btn.block { width: 100%; }
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:active { background: #173B2C; }
.btn.accent { background: var(--magenta); color: #fff; }
.btn.ghost { background: var(--surface-2); color: var(--ink); }
.btn.outline { background: #fff; color: var(--green); border: 1.5px solid var(--green); }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.fab-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, rgba(245,243,236,0));
}
.fab-bar .inner { max-width: 720px; margin: 0 auto; display: flex; gap: 10px; }
.fab-bar .btn { flex: 1; box-shadow: 0 4px 14px rgba(31, 77, 58, .25); }

/* ---------- Listas ---------- */
.visit {
  display: block; background: var(--surface); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px;
  text-decoration: none; color: inherit; box-shadow: var(--shadow); border: 1px solid #ECE8DC; border-left: 5px solid var(--magenta);
}
.visit.closed { border-left-color: var(--green-2); }
.visit.void { border-left-color: var(--line); opacity: .7; }
.visit .top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.visit .name { font-weight: 700; font-size: 17px; }
.visit .sub { color: var(--ink-3); font-size: 14px; }
.visit .meta { display: flex; gap: 14px; margin-top: 10px; font-size: 14px; color: var(--ink-2); flex-wrap: wrap; }
.visit .meta b { color: var(--ink); }

.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: 999px; white-space: nowrap; }
.chip.open { background: var(--magenta-soft); color: var(--magenta); }
.chip.closed { background: var(--green-soft); color: var(--green); }
.chip.pending { background: var(--amber-soft); color: var(--amber); }
.chip.synced { background: var(--green-soft); color: var(--green-2); }
.chip.void { background: var(--surface-2); color: var(--ink-3); }

.plant {
  display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--surface-2);
}
.plant:first-child { border-top: 0; }
.plant .n { width: 38px; height: 38px; border-radius: 10px; background: var(--green-soft); color: var(--green); display: grid; place-items: center; font-weight: 800; flex: none; }
.plant .info { flex: 1; min-width: 0; }
.plant .info .t { font-weight: 700; }
.plant .info .d { font-size: 13px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 44px; height: 44px; border-radius: 10px; border: 0; background: var(--surface-2); display: grid; place-items: center; cursor: pointer; color: var(--ink-2); flex: none; }
.icon-btn.del { background: var(--red-soft); color: var(--red); }

/* ---------- Contador y resultados ---------- */
.counter { display: flex; align-items: center; gap: 14px; }
.counter .big { font-size: 44px; font-weight: 800; line-height: 1; color: var(--green); font-variant-numeric: tabular-nums; }
.counter .lbl { font-size: 14px; color: var(--ink-2); }

.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.summary-grid div { min-width: 0; }
.summary-grid .k { font-size: 13px; color: var(--ink-3); }
.summary-grid .v { font-weight: 700; }

.result { border-radius: var(--radius-sm); padding: 14px; background: var(--surface-2); margin-bottom: 10px; }
.result .k { font-size: 14px; color: var(--ink-2); font-weight: 600; }
.result .v { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.result .f { font-size: 13px; color: var(--ink-3); margin-top: 2px; }
.result.main { background: var(--green); color: #fff; }
.result.main .k, .result.main .f { color: rgba(255,255,255,.8); }
.result.flp { background: var(--magenta); color: #fff; }
.result.flp .k, .result.flp .f { color: rgba(255,255,255,.85); }
.result.flp .v { font-size: 34px; }

.breakdown { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
.breakdown td { padding: 6px 0; border-top: 1px solid var(--line); }
.breakdown td:last-child { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

.toggle-row { display: flex; align-items: center; gap: 14px; cursor: pointer; }
.toggle-row .txt { flex: 1; }
.toggle-row .txt b { display: block; font-size: 17px; }
.switch { position: relative; width: 60px; height: 34px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .15s; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + .track { background: var(--green-2); }
.switch input:checked + .track::after { transform: translateX(26px); }
.switch input:focus-visible + .track { outline: 3px solid rgba(46,107,81,.35); outline-offset: 2px; }

/* ---------- Fotos y GPS ---------- */
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo button { position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; border-radius: 8px; border: 0; background: rgba(0,0,0,.55); color: #fff; display: grid; place-items: center; cursor: pointer; }
.photo .badge { position: absolute; left: 4px; bottom: 4px; font-size: 11px; font-weight: 700; background: rgba(0,0,0,.55); color: #fff; padding: 2px 6px; border-radius: 6px; }
.add-photo { aspect-ratio: 1; border-radius: 10px; border: 2px dashed var(--line); background: #fff; display: grid; place-items: center; text-align: center; font-size: 13px; font-weight: 700; color: var(--green); cursor: pointer; padding: 6px; }
.gps { display: flex; align-items: center; gap: 10px; font-size: 14px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.gps.ok { background: var(--green-soft); color: var(--green); }
.gps.warn { background: var(--amber-soft); color: var(--amber); }
.gps .grow { flex: 1; min-width: 0; }
.gps button { border: 0; background: rgba(0,0,0,.06); border-radius: 8px; padding: 8px 10px; font-weight: 700; font-size: 13px; cursor: pointer; color: inherit; }

/* ---------- Estadíos (formulario de planta) ---------- */
.stage { display: grid; grid-template-columns: 1fr 172px; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--surface-2); }
.stage:first-child { border-top: 0; }
.stage .nm { font-weight: 700; font-size: 16px; }
.stage .nm small { display: block; font-weight: 500; color: var(--ink-3); font-size: 12px; }
.stage .stepper { grid-template-columns: 48px 1fr 48px; gap: 6px; }
.stage .stepper button { height: 48px; }
.stage .stepper input { min-height: 48px; padding: 8px 4px; }
.plant-total { display: flex; justify-content: space-between; align-items: center; font-weight: 700; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--green-soft); color: var(--green); margin-top: 8px; }

/* ---------- Estados vacíos, diálogos, toasts ---------- */
.empty { text-align: center; padding: 36px 20px; color: var(--ink-2); }
.empty svg { color: var(--ink-3); margin-bottom: 10px; }
.empty b { display: block; font-size: 18px; color: var(--ink); margin-bottom: 4px; }

.lock { display: flex; gap: 10px; align-items: flex-start; background: var(--green-soft); color: var(--green); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 14px; font-weight: 600; margin-bottom: 14px; }

dialog { border: 0; border-radius: 18px; padding: 0; width: min(92vw, 440px); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(23, 35, 29, .5); }
dialog .dlg { padding: 20px; }
dialog h3 { margin: 0 0 8px; font-size: 19px; }
dialog p { margin: 0 0 18px; color: var(--ink-2); }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 15px;
  opacity: 0; transition: all .2s; z-index: 50; max-width: 90vw; text-align: center; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); border: 1px solid #ECE8DC; }
.stat .v { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12px; color: var(--ink-3); font-weight: 600; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button { flex: 1; min-height: 42px; border-radius: 999px; border: 1.5px solid var(--line); background: #fff; font-weight: 700; font-size: 14px; cursor: pointer; }
.tabs button[aria-pressed=true] { background: var(--ink); color: #fff; border-color: var(--ink); }

@media (min-width: 600px) {
  main { padding-top: 22px; }
  .photos { grid-template-columns: repeat(4, 1fr); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- v1.1: alta de productor/lote, finca completa, avisos ---------- */
.label-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.label-row > label { font-weight: 600; font-size: 15px; }
.link-btn { display: inline-flex; align-items: center; gap: 4px; background: none; border: 0; color: var(--green); font-weight: 700; font-size: 15px; padding: 8px 4px; min-height: 40px; cursor: pointer; white-space: nowrap; }
.link-btn svg { width: 18px; height: 18px; }
.link-btn:disabled { color: var(--ink-3); opacity: .6; cursor: not-allowed; }
.seg.seg3 { grid-template-columns: repeat(3, 1fr); }
.seg.seg3 button { font-size: 15px; padding: 0 6px; }
.note { background: var(--green-soft); color: var(--green); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; line-height: 1.45; }
.warn-txt { color: var(--amber); font-size: 14px; font-weight: 600; margin-top: 6px; }
.warn-txt:empty { display: none; }
dialog .dlg { max-height: 88vh; overflow-y: auto; }

/* ---------- v1.2: tablas por estadío y proyección semanal ---------- */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-top: 8px; }
.stage-tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.stage-tbl th { text-align: right; font-size: 12px; font-weight: 700; color: var(--ink-3); padding: 6px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.stage-tbl th:first-child, .stage-tbl td:first-child { text-align: left; padding-left: 0; }
.stage-tbl td { text-align: right; padding: 7px 4px; border-top: 1px solid var(--line); white-space: nowrap; }
.stage-tbl td:first-child { white-space: normal; }
.stage-tbl tr.zero td { color: var(--ink-3); }
.stage-tbl tr.tot td { border-top: 2px solid var(--ink-3); font-weight: 700; }
.weeks { width: 100%; border-collapse: collapse; font-size: 14px; }
.weeks th { font-size: 12px; font-weight: 700; color: var(--ink-3); text-align: right; padding: 4px; border-bottom: 1px solid var(--line); }
.weeks th:first-child { text-align: left; }
.weeks td { padding: 6px 4px; border-top: 1px solid var(--line); text-align: right; white-space: nowrap; }
.weeks td:first-child { text-align: left; font-weight: 700; width: 56px; }
.weeks td small { color: var(--ink-3); font-weight: 600; }
.weeks td.bar { width: 40%; text-align: left; }
.weeks td.bar span { display: block; height: 10px; border-radius: 6px; background: var(--green-2); }
.weeks td.flp { color: var(--magenta); font-weight: 700; }
.weeks tr.now td:first-child { color: var(--magenta); }
.weeks tr.det td { border-top: 0; padding-top: 0; font-size: 12px; color: var(--ink-3); white-space: normal; text-align: left; }


/* v1.3 · captura fotográfica estandarizada */
.photo-guide { background:var(--green-soft); border:1px solid #c9ddcf; border-radius:12px; padding:12px 14px; font-size:14px; line-height:1.55; }
.plant-photo-preview { margin-top:12px; }
.plant-photo-frame { position:relative; width:min(100%,360px); margin:auto; aspect-ratio:3/4; overflow:hidden; border-radius:14px; background:var(--surface-2); }
.plant-photo-frame img { width:100%; height:100%; object-fit:cover; display:block; }
.plant-photo-guide-overlay { position:absolute; inset:8% 12%; border:2px dashed rgba(255,255,255,.85); border-radius:45% 45% 18% 18%; box-shadow:0 0 0 999px rgba(0,0,0,.08); pointer-events:none; }
.photo-missing,.photo-ok { padding:14px; border-radius:10px; text-align:center; font-weight:700; font-size:14px; }
.photo-missing { background:var(--amber-soft); color:var(--amber); }
.photo-ok { background:var(--green-soft); color:var(--green); }

/* =========================================================
   v1.4 · Inteligencia de Campo · portada general
   ========================================================= */

/* Ícono general de la plataforma en la barra superior */
.topbar-brand {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(255,255,255,.12);
  color: #fff;
  display: grid;
  place-items: center;
  flex: none;
}
.topbar-brand svg { width: 25px; height: 25px; }

/* Portada / selector de cultivos */
.portal {
  min-height: calc(100dvh - 220px);
  display: flex;
  flex-direction: column;
}
.portal-content { width: 100%; }
.portal-label { margin-top: 4px; }

.crop-card {
  width: 100%;
  min-height: 94px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid #ECE8DC;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: left;
  cursor: pointer;
  appearance: none;
  transition: transform .12s, background .12s, border-color .12s;
}
.crop-card:hover { border-color: var(--line); }
.crop-card:active {
  transform: scale(.99);
  background: var(--surface-2);
}
.crop-card:focus-visible {
  outline: 3px solid rgba(46,107,81,.28);
  outline-offset: 2px;
}

.crop-logo {
  width: 64px;
  height: 64px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--green);
}
.crop-logo .logo,
.crop-logo svg {
  width: 48px;
  height: 48px;
}

.crop-info {
  flex: 1;
  min-width: 0;
}
.crop-info strong {
  display: block;
  font-size: 20px;
  line-height: 1.2;
  font-weight: 800;
  color: var(--ink);
}
.crop-info span {
  display: block;
  margin-top: 3px;
  font-size: 13px;
  line-height: 1.35;
  color: var(--ink-3);
}
.crop-info small {
  display: inline-block;
  margin-top: 7px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  color: var(--magenta);
}
.crop-arrow {
  flex: none;
  padding: 0 4px;
  font-size: 32px;
  line-height: 1;
  font-weight: 300;
  color: var(--ink-3);
}

/* Créditos generales de la plataforma */
.portal-footer {
  margin-top: auto;
  padding: 52px 12px 2px;
  text-align: center;
  color: var(--ink-3);
  font-size: 11px;
  line-height: 1.45;
}
.portal-footer::before {
  content: '';
  display: block;
  width: 42px;
  height: 1px;
  margin: 0 auto 12px;
  background: var(--line);
}
.portal-footer strong {
  display: block;
  margin-top: 1px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-2);
}
.portal-footer span {
  display: block;
  max-width: 390px;
  margin: 5px auto 0;
}

@media (min-width: 600px) {
  .crop-card { padding: 16px 18px; }
}

/* Identidad del módulo activo en la barra superior */
.topbar-module-logo {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 10px;
  background: var(--green);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.topbar-module-logo .logo,
.topbar-module-logo svg {
  width: 30px;
  height: 30px;
}

