/* AgroPrecisión APM — estilos
   Autor: Álvaro Puentes Molina · SENA */
:root {
  --sena: #39a900;
  --sena-dark: #2c8200;
  --ink: #17251c;
  --ink-2: #4a5a50;
  --ink-3: #7b8a80;
  --bg: #f3f6f2;
  --surface: #ffffff;
  --surface-2: #f7faf6;
  --line: #dfe7dc;
  --nav: #0f2418;
  --nav-2: #173323;
  --nav-ink: #cfe3d3;
  --warn: #c0392b;
  --amber: #e6a01e;
  --info: #1f6fa8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 36, 24, .06), 0 4px 16px rgba(15, 36, 24, .08);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
}
:root[data-theme="dark"] {
  --ink: #e4efe6; --ink-2: #b4c6b9; --ink-3: #85998b;
  --bg: #0d1611; --surface: #142019; --surface-2: #18271e; --line: #26392d;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e4efe6; --ink-2: #b4c6b9; --ink-3: #85998b;
    --bg: #0d1611; --surface: #142019; --surface-2: #18271e; --line: #26392d;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 14px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Estructura ---------- */
.app { display: grid; grid-template-columns: 216px 1fr; grid-template-rows: 56px 1fr; height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; padding: 0 16px; background: var(--nav); color: #fff; border-bottom: 3px solid var(--sena); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.brand svg { flex: none; }
.brand b { font-size: 16px; letter-spacing: .2px; display: block; line-height: 1.1; }
.brand small { color: #9fc4a8; font-size: 11px; display: block; }
.ctx { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.ctx label { color: #9fc4a8; font-size: 12px; white-space: nowrap; }
.ctx select { background: var(--nav-2); color: #fff; border: 1px solid #2c4a37; border-radius: 8px; padding: 6px 10px; max-width: 420px; width: 100%; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.pill { font-size: 11px; padding: 3px 8px; border-radius: 99px; background: rgba(57, 169, 0, .18); color: #bfe8a8; white-space: nowrap; }
.pill.warn { background: rgba(230, 160, 30, .2); color: #ffd58a; }
.icon-btn { background: transparent; border: 1px solid #2c4a37; color: #dfeee3; border-radius: 8px; padding: 6px 9px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.icon-btn:hover { background: var(--nav-2); }

.side { background: var(--nav); color: var(--nav-ink); display: flex; flex-direction: column; overflow-y: auto; padding: 10px 8px; }
.side a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--nav-ink); text-decoration: none; cursor: pointer; font-size: 13.5px; }
.side a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.side a:hover { background: var(--nav-2); color: #fff; }
.side a.active { background: var(--sena); color: #fff; font-weight: 600; }
.side a.active svg { opacity: 1; }
.side .sep { height: 1px; background: #23402e; margin: 8px 6px; }
.side .credit { margin-top: auto; padding: 12px 8px 4px; font-size: 11px; color: #8fb39a; border-top: 1px solid #23402e; }
.side .credit b { color: #dfeee3; display: block; font-size: 12px; }

.main { display: flex; min-height: 0; min-width: 0; position: relative; }
#map { flex: 1; min-width: 0; background: #dfe7dc; }
.panel { width: 400px; flex: none; background: var(--surface); border-left: 1px solid var(--line); overflow-y: auto; display: flex; flex-direction: column; }
.panel.wide { width: min(980px, 68%); }
.panel.full { width: 100%; border-left: 0; }
.main.nomap #map { display: none; }
.main.nomap .panel { width: 100%; border-left: 0; }

/* ---------- Panel ---------- */
.ph { padding: 16px 18px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 5; }
.ph h2 { margin: 0; font-size: 18px; }
.ph p { margin: 4px 0 0; color: var(--ink-2); font-size: 12.5px; }
.pb { padding: 14px 18px 24px; display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.card h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-2); }
.card h4 { margin: 0 0 6px; font-size: 14px; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.kpi span { display: block; font-size: 11px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .4px; }
.kpi b { font-size: 20px; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--ink-2); font-size: 11px; margin-left: 2px; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; }
.btn:hover { border-color: var(--sena); }
.btn.primary { background: var(--sena); border-color: var(--sena); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--sena-dark); }
.btn.danger { color: var(--warn); }
.btn.danger:hover { border-color: var(--warn); }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }

.list { display: flex; flex-direction: column; gap: 6px; }
.item { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 9px 11px; cursor: pointer; display: flex; gap: 10px; align-items: center; }
.item:hover { border-color: var(--sena); }
.item.sel { border-color: var(--sena); box-shadow: inset 3px 0 0 var(--sena); }
.item .t { font-weight: 600; }
.item .s { font-size: 12px; color: var(--ink-3); }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; display: inline-block; }

.tree .client { margin-bottom: 10px; }
.tree .client > .hd { display: flex; align-items: center; gap: 8px; font-weight: 700; padding: 6px 2px; }
.tree .farm { margin-left: 12px; border-left: 2px solid var(--line); padding-left: 10px; margin-bottom: 6px; }
.tree .farm > .hd { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--ink-2); padding: 4px 0; }
.tree .hd .acts { margin-left: auto; display: flex; gap: 4px; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap; }
.tag.ok { background: rgba(57, 169, 0, .12); color: var(--sena-dark); border-color: rgba(57, 169, 0, .3); }

table.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.tbl th { text-align: left; font-weight: 600; color: var(--ink-2); border-bottom: 2px solid var(--line); padding: 6px 8px; white-space: nowrap; }
table.tbl td { border-bottom: 1px solid var(--line); padding: 6px 8px; vertical-align: top; }
table.tbl td.n, table.tbl th.n { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl tr:hover td { background: var(--surface-2); }
.tblwrap { overflow-x: auto; }

.legend { display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
.legend div { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.hist { width: 100%; height: 90px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.field input, .field select, .field textarea { border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: var(--surface); width: 100%; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid rgba(57, 169, 0, .35); border-color: var(--sena); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.hint { font-size: 12px; color: var(--ink-3); }
.empty { text-align: center; padding: 22px 10px; color: var(--ink-3); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty b { color: var(--ink-2); display: block; margin-bottom: 4px; }

/* ---------- Modal y avisos ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(8, 20, 12, .55); display: none; align-items: center; justify-content: center; z-index: 3000; padding: 16px; }
.modal-bg.show { display: flex; }
.modal { background: var(--surface); border-radius: 12px; width: min(560px, 100%); max-height: 92vh; overflow: auto; box-shadow: var(--shadow); }
.modal.lg { width: min(820px, 100%); }
.modal .mh { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal .mh h3 { margin: 0; font-size: 16px; flex: 1; }
.modal .mb { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.modal .mf { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--nav); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 4000; box-shadow: var(--shadow); font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; border-left: 4px solid var(--sena); max-width: 90vw; }
.toast.show { opacity: 1; }
.toast.err { border-left-color: var(--warn); }
.busy { position: fixed; inset: 0; background: rgba(8, 20, 12, .35); z-index: 3500; display: none; align-items: center; justify-content: center; color: #fff; font-weight: 600; }
.busy.show { display: flex; }
.busy div { background: var(--nav); padding: 14px 20px; border-radius: 10px; border-left: 4px solid var(--sena); }

.map-hint { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 1200; max-width: calc(100% - 140px); flex-wrap: wrap; background: var(--nav); color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); display: none; gap: 10px; align-items: center; }
.map-hint.show { display: flex; }
.map-hint button { background: var(--sena); color: #fff; border: 0; border-radius: 6px; padding: 4px 10px; cursor: pointer; }
.map-hint button.ghost { background: transparent; border: 1px solid #3c6b4c; }

.leaflet-container { font-family: var(--font); }
.leaflet-popup-content { font-size: 12.5px; }
.ll-legend { background: rgba(255, 255, 255, .95); color: #17251c; padding: 8px 10px; border-radius: 8px; box-shadow: var(--shadow); font-size: 12px; max-width: 220px; }
.ll-legend b { display: block; margin-bottom: 4px; }
.ll-coords { background: rgba(15, 36, 24, .85); color: #fff; padding: 3px 8px; border-radius: 6px; font: 11px var(--mono); }
.field-label { background: transparent; border: 0; box-shadow: none; color: #fff; font-weight: 700; font-size: 12px; text-shadow: 0 0 3px #000, 0 0 6px #000; }
.field-label::before { display: none; }

/* ---------- Reporte ---------- */
.report { background: #fff; color: #17251c; max-width: 900px; margin: 0 auto; padding: 28px 32px; border: 1px solid var(--line); border-radius: 10px; }
.report header { display: flex; align-items: center; gap: 14px; border-bottom: 3px solid var(--sena); padding-bottom: 12px; margin-bottom: 16px; }
.report header h1 { margin: 0; font-size: 20px; }
.report header p { margin: 2px 0 0; color: #4a5a50; font-size: 12px; }
.report h2 { font-size: 15px; margin: 18px 0 8px; color: #0f2418; border-left: 4px solid var(--sena); padding-left: 8px; }
.report .rgrid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 18px; align-items: start; }
.report svg.rmap { width: 100%; height: auto; border: 1px solid #dfe7dc; border-radius: 8px; background: #f7faf6; }
.report footer { margin-top: 22px; padding-top: 10px; border-top: 1px solid #dfe7dc; font-size: 11px; color: #4a5a50; display: flex; justify-content: space-between; gap: 10px; }
.report table.tbl td, .report table.tbl th { color: #17251c; border-color: #dfe7dc; }

/* ---------- Acerca de ---------- */
.about-hero { background: linear-gradient(135deg, #0f2418 0%, #1c4a2c 60%, #2c8200 100%); color: #fff; border-radius: 12px; padding: 22px; display: flex; gap: 16px; align-items: center; }
.about-hero h2 { margin: 0; font-size: 22px; }
.about-hero p { margin: 4px 0 0; color: #cfe8d5; }

@media print {
  body { background: #fff; }
  .app > .topbar, .side, #map, .noprint, .ph { display: none !important; }
  .app { display: block; height: auto; }
  .main, .panel, .pb { display: block !important; width: 100% !important; overflow: visible !important; padding: 0 !important; border: 0 !important; }
  .report { border: 0; padding: 0; max-width: none; }
  .report h2 { break-after: avoid; }
  table { break-inside: auto; } tr { break-inside: avoid; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; height: auto; min-height: 100vh; }
  .topbar { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .brand { min-width: 0; }
  .ctx { order: 3; flex-basis: 100%; }
  .side { flex-direction: row; overflow-x: auto; padding: 6px; gap: 2px; }
  .side a { flex: none; padding: 7px 9px; font-size: 12.5px; }
  .side .sep, .side .credit { display: none; }
  .main { flex-direction: column; }
  #map { height: 46vh; flex: none; }
  .panel, .panel.wide { width: 100%; border-left: 0; border-top: 1px solid var(--line); }
  .grid3 { grid-template-columns: 1fr 1fr; }
}
