/* Layout: full-height map with a side panel on desktop, bottom sheet on phones. */
:root {
  --bg: #f4f6f2;
  --panel: #ffffff;
  --ink: #1d2a22;
  --muted: #5c6b61;
  --line: #dde3dc;
  --accent: #2f6b45;      /* crop green */
  --accent-ink: #ffffff;
  --soil: #8a5a33;        /* soil brown, secondary */
  --warn: #a5671a;
  --chip: #eaf0e8;
  --font-ui: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-head: "Barlow Semi Condensed", "Barlow", system-ui, sans-serif;
  --font-data: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121814; --panel: #19211c; --ink: #e4ebe5; --muted: #9aaa9f; --line: #2c3830;
    --accent: #5fae7a; --accent-ink: #0d1a12; --soil: #c98f5f; --warn: #e0a24f; --chip: #223028;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121814; --panel: #19211c; --ink: #e4ebe5; --muted: #9aaa9f; --line: #2c3830;
  --accent: #5fae7a; --accent-ink: #0d1a12; --soil: #c98f5f; --warn: #e0a24f; --chip: #223028;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font-ui); }
#app { display: grid; grid-template-columns: 380px 1fr; height: 100%; }
#panel { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto;
  padding-block: 18px 32px; padding-left: max(18px, env(safe-area-inset-left, 0px)); padding-right: 18px;
  display: flex; flex-direction: column; gap: 18px; min-width: 0; }
#map { height: 100%; min-height: 300px; }
header h1 { font: 700 24px/1.1 var(--font-head); margin: 0; letter-spacing: .2px; text-wrap: balance; }
header p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.step { display: flex; flex-direction: column; gap: 10px; }
.step h2 { font: 600 13px/1 var(--font-ui); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0;
  display: flex; align-items: center; gap: 8px; }
.step h2 b { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > input[type=text] { flex: 1 1 160px; min-width: 0; }
/* Search with suggestions */
.search { flex-wrap: nowrap; align-items: flex-start; }
.search-box { position: relative; flex: 1 1 auto; min-width: 0; }
.search-box input { width: 100%; }
.suggest { position: absolute; z-index: 2000; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px; list-style: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 18px rgba(0,0,0,.18); max-height: 320px; overflow-y: auto; }
.suggest li { padding: 8px 10px; border-radius: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.suggest li b { font-weight: 500; }
.suggest li span { font-size: 12px; color: var(--muted); }
.suggest li:hover, .suggest li[aria-selected="true"] { background: var(--chip); }
input[type=text], input[type=number], select {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
input[type=number] { width: 80px; }
button, .btn { font: 500 14px/1 var(--font-ui); color: var(--ink); background: var(--chip); border: 1px solid var(--line);
  border-radius: 6px; padding: 9px 12px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: var(--accent); }
button:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible, label.file:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; padding: 12px 16px; font-size: 15px; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
label.file { position: relative; overflow: hidden; }
label.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.hint a { color: var(--accent); }
.field-info { font-family: var(--font-data); font-size: 13px; color: var(--muted); }
.opt { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; }
.opt label { font-size: 14px; }
.status { font-size: 14px; padding: 10px 12px; border-radius: 6px; background: var(--chip); }
.status.err { color: var(--warn); }
.summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.summary div { background: var(--bg); border-radius: 6px; padding: 8px 10px; }
.summary dt { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.summary dd { margin: 2px 0 0; font: 500 14px/1.3 var(--font-data); font-variant-numeric: tabular-nums; }
.sensor { border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.sensor h3 { margin: 0; font: 700 17px/1.2 var(--font-head); display: flex; align-items: center; gap: 8px; }
.badge { display: inline-grid; place-items: center; min-width: 26px; height: 26px; border-radius: 50%; color: #fff;
  font: 700 13px/1 var(--font-ui); border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.35); }
.sensor .coords { font: 13px var(--font-data); color: var(--muted); }
.sensor ul { margin: 0; padding-left: 18px; font-size: 14px; }
.sensor .row button, .sensor .row .btn { padding: 6px 9px; font-size: 13px; }
.notes { font-size: 13px; color: var(--muted); margin: 0; padding-left: 18px; }
.legend { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.ramp { height: 10px; border-radius: 3px; }
.legend .ends { display: flex; justify-content: space-between; font-family: var(--font-data); color: var(--muted); }
.sensor-pin { background: none; border: none; }
.sensor-pin span { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; color: #fff;
  font: 700 14px/1 var(--font-ui); border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.5); }
.vertex-pin { width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }
.leaflet-container { font-family: var(--font-ui); background: var(--bg); }
#drawbar { position: absolute; z-index: 1000; left: 50%; transform: translateX(-50%);
  top: calc(12px + env(safe-area-inset-top, 0px)); background: var(--panel); color: var(--ink); border-radius: 8px;
  padding: 8px 12px; box-shadow: 0 2px 10px rgba(0,0,0,.25); font-size: 14px; max-width: calc(100% - 120px); text-align: center; }
#mapwrap { position: relative; min-width: 0; }
footer { font-size: 12px; color: var(--muted); margin-top: auto; }
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 52vh 1fr; }
  #mapwrap { order: 1; }
  #panel { order: 2; border-right: 0; border-top: 1px solid var(--line); padding-right: max(16px, env(safe-area-inset-right, 0px));
    padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }
  #drawbar { max-width: calc(100% - 80px); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* v2 additions */
.subopts { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; padding: 10px 12px; border-radius: 6px; background: var(--bg); }
.subopts .full { grid-column: 1 / -1; }
.subopts input[type=text] { width: 100%; }
.unit { color: var(--muted); font-size: 13px; margin-left: 4px; }
.tag { display: inline-block; font: 500 11px/1 var(--font-ui); letter-spacing: .06em; text-transform: uppercase; padding: 4px 6px; border-radius: 4px; background: var(--chip); color: var(--muted); }
.pivot-hint { font-size: 13px; color: var(--muted); }
.ndvi-meta { font: 13px/1.4 var(--font-data); color: var(--muted); }
#sceneRow { grid-template-columns: 1fr; }
#sceneSel { width: 100%; min-width: 0; }
.pin-label { font: 600 13px/1.2 var(--font-ui); width: max-content; max-width: 240px; white-space: normal; }

/* NDVI timeline */
.timeline { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border-radius: 6px; background: var(--bg); }
.tl-controls { flex-wrap: nowrap; }
.tl-controls input[type=range] { flex: 1 1 auto; min-width: 0; accent-color: var(--accent); }
.tl-controls button { padding: 7px 10px; }
.tl-date { font: 500 14px/1.3 var(--font-data); font-variant-numeric: tabular-nums; }
.tl-date .tag { margin-left: 6px; }
.tl-chart { width: 100%; height: auto; display: block; }
.tl-chart text { font: 10px var(--font-data); fill: var(--muted); }
.tl-chart .grid { stroke: var(--line); stroke-width: 1; }
.tl-chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.tl-chart .pt { fill: var(--accent); cursor: pointer; }
.tl-chart .todo { fill: var(--line); cursor: pointer; }
.tl-chart .cur { stroke: var(--soil); stroke-width: 1.5; stroke-dasharray: 3 3; }
.tl-chart .pt.sel, .tl-chart .todo.sel { fill: var(--soil); }
.tl-foot { justify-content: space-between; }
.tl-foot button { padding: 6px 9px; font-size: 13px; }
.leaflet-image-layer { image-rendering: pixelated; }

/* Map key: legend for the soil map and NDVI, on the map itself */
.map-key { background: var(--panel); color: var(--ink); border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,.3);
  max-width: min(320px, calc(100vw - 32px)); font-size: 14px; line-height: 1.35; }
.map-key .fold { display: flex; justify-content: space-between; width: 100%; gap: 8px; padding: 8px 12px; border: 0; background: none;
  color: inherit; font: 600 14px/1.2 var(--font-ui); cursor: pointer; min-height: 36px; }
.map-key .key-body { max-height: min(46vh, 420px); overflow-y: auto; padding: 0 12px 10px; display: flex; flex-direction: column; gap: 12px; }
.map-key h3 { font: 600 13px/1.2 var(--font-ui); letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; }
.map-key ul { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.map-key li { display: flex; align-items: flex-start; gap: 8px; }
.map-key li .rng { font: 13px var(--font-data); min-width: 58px; color: var(--muted); }
.map-key li.cur { font-weight: 600; }
.map-key .sw, .ident .sw { flex: none; display: inline-block; width: 16px; height: 16px; border-radius: 3px; border: 1px solid rgba(0,0,0,.25); vertical-align: -3px; margin-top: 1px; }
.map-key .bar { position: relative; height: 12px; border-radius: 3px; }
.map-key .bar .mark { position: absolute; top: -4px; width: 3px; height: 20px; margin-left: -1.5px; background: var(--ink); border: 1px solid var(--panel); border-radius: 2px; }
.map-key .ends { display: flex; justify-content: space-between; font: 12px var(--font-data); color: var(--muted); margin-top: 2px; }
.map-key .note { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.map-key .pct { font: 13px var(--font-data); color: var(--muted); }
.map-key .desc, .ident .desc { font-size: 13px; color: var(--muted); }
.map-key .link { border: 0; background: none; padding: 6px 0 0; color: var(--accent); font: 500 13px var(--font-ui); cursor: pointer; text-decoration: underline; }
.map-key .wms-legend { display: block; background: #fff; border-radius: 4px; padding: 4px; max-width: 100%; }
.ident { font-size: 14px; line-height: 1.5; }
@media (max-width: 760px) { .map-key .key-body { max-height: 24vh; } .map-key { font-size: 13px; } }

/* Sensor spots moved by hand */
.sensor-pin { cursor: grab; }
.sensor-pin.moved span { border-style: dashed; }
.sensor.moved h3 .tag { margin-left: 6px; vertical-align: middle; }

/* Irrigation blocks */
.sub-h { font: 600 13px/1.2 var(--font-ui); letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin: 6px 0 0; }
.block-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.block-list li { display: flex; align-items: center; gap: 8px; }
.block-list .sw { flex: none; width: 14px; height: 14px; border-radius: 3px; }
.block-list input { flex: 1 1 auto; min-width: 0; }
.block-list .ha { font: 13px var(--font-data); color: var(--muted); white-space: nowrap; }
.block-list button { padding: 6px 9px; font-size: 13px; }
.block-label { font: 700 13px/1 var(--font-ui); background: rgba(255,255,255,.85); border: 0; box-shadow: none; padding: 3px 6px; }
.block-label::before { display: none; }
.need { margin: 0; padding: 10px 12px; border-radius: 6px; background: var(--chip); border-left: 3px solid var(--accent); font-size: 14px; }
.need b { font-weight: 600; }
#drawbar { display: flex; flex-direction: column; align-items: center; gap: 8px; }
#drawbar[hidden] { display: none; }
.drawbar-acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.drawbar-acts button { padding: 7px 10px; font-size: 13px; }
@media (max-width: 760px) {
  #drawbar { left: 52px; right: 52px; transform: none; max-width: none; padding: 6px 8px; font-size: 13px; gap: 6px; }
  .drawbar-acts { flex-wrap: nowrap; }
  .drawbar-acts button { padding: 6px 8px; font-size: 12px; }
}
/* Return on investment */
.subopts [hidden] { display: none; }
.roi-out { display: flex; flex-direction: column; gap: 8px; }
.roi-out p { margin: 0; font-size: 14px; }
.roi-table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
.roi-table th, .roi-table td { padding: 6px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.roi-table tbody th { text-align: left; font-weight: 400; color: var(--muted); }
.roi-table thead th { font-weight: 600; }
.roi-table td:nth-child(3), .roi-table thead th:nth-child(3) { background: var(--chip); }
.roi-headline { padding: 10px 12px; border-radius: 6px; background: var(--chip); border-left: 3px solid var(--accent); }
/* Tabs: probe placement / return on investment */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; border-radius: 0; padding: 10px 8px; color: var(--muted); font-weight: 600; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
#panel[data-tab="roi"] > section.step:not(#roiStep) { display: none; }
#panel[data-tab="place"] > #roiStep { display: none; }
/* Block rows in step 1 */
.blocks-box { display: flex; flex-direction: column; gap: 8px; }
.blocks-box summary { cursor: pointer; font-weight: 600; font-size: 14px; padding: 4px 0; }
.blocks-box[open] summary { margin-bottom: 8px; }
.blocks-box > * + * { margin-top: 8px; }
.block-list li { flex-wrap: nowrap; }
.block-list li input { width: 0; flex: 1 1 90px; }
.block-list li button { white-space: nowrap; flex: none; }
.block-list li .ha { min-width: 56px; text-align: right; }
.block-list button.primary-lite { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.block-list .row-name { flex: 1 1 90px; font-size: 14px; padding: 8px 0; }

/* Papicons (js/icons.js): inline, text colour, a little larger than the text. */
.ico { width: 1.15em; height: 1.15em; flex: none; display: block; }
button *, .btn > svg, .btn > span { pointer-events: none; } /* clicks land on the button itself, which the click handlers read */
.tl-controls button[data-icon="chevronLeft"], .tl-controls button[data-icon="chevronRight"] { padding: 7px 8px; }
.tabs button { display: inline-flex; align-items: center; gap: 6px; }

/* Start choice: install new probes / check installed probes */
#panel { counter-reset: step; }
.step h2 b::before { counter-increment: step; content: counter(step); }
#panel[data-mode=""] > :is(.tabs, section.step, #modeBar) { display: none; }
#panel:not([data-mode=""]) > #modePick { display: none; }
#panel[data-mode="new"] [data-only="check"], #panel[data-mode="check"] [data-only="new"] { display: none !important; }
.mode-pick { display: flex; flex-direction: column; gap: 10px; }
.mode-pick h2 { font: 700 20px/1.2 var(--font-head); margin: 4px 0 2px; }
.mode-opt { display: flex; align-items: flex-start; gap: 12px; text-align: left; padding: 14px; line-height: 1.35; background: var(--panel); border: 1.5px solid var(--line); border-radius: 10px; }
.mode-opt:hover { border-color: var(--accent); background: var(--chip); }
.mode-opt b { display: block; font: 700 17px/1.2 var(--font-head); margin-bottom: 3px; }
.mode-opt span span { color: var(--muted); font-size: 14px; font-weight: 400; }
.mode-ico { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); }
.mode-ico .ico { width: 20px; height: 20px; }
.mode-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-radius: 8px; background: var(--chip); font-weight: 600; font-size: 14px; }
.mode-bar #modeName { display: inline-flex; align-items: center; gap: 6px; }
.link { border: 0; background: none; padding: 4px 0; color: var(--accent); font: 500 14px var(--font-ui); cursor: pointer; text-decoration: underline; }
.missing .link { font-size: 13px; padding: 0; }

/* Installed probes and their check */
.pk { flex: none; display: inline-block; width: 14px; height: 14px; transform: rotate(45deg); border-radius: 2px; background: #6b7a70; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.35); }
.pk.sev0 { background: #3f9a52; } .pk.sev1 { background: #e0a02a; } .pk.sev2 { background: #d0453a; }
.probe-pin { background: none; border: 0; cursor: grab; display: grid; place-items: center; }
.probe-pin .pk { width: 18px; height: 18px; border-width: 3px; box-shadow: 0 1px 4px rgba(0,0,0,.55); }
.probe-label { font: 600 12px/1.1 var(--font-ui); padding: 2px 5px; }
.rec-pin { background: none; border: 0; }
.rec-pin span { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: rgba(255,255,255,.85); border: 3px solid var(--accent); color: #1d2a22; font: 700 12px/1 var(--font-ui); box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.rec-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2.5px solid var(--accent); background: #fff; }
.probe-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.probe-list li { display: flex; align-items: center; gap: 8px; }
.probe-list li input { width: 0; flex: 1 1 90px; }
.probe-list .ha { font: 12px var(--font-data); color: var(--muted); white-space: nowrap; }
.probe-list button { padding: 6px 7px; flex: none; }
.check-headline { margin: 0; padding: 10px 12px; border-radius: 6px; background: var(--chip); border-left: 3px solid var(--accent); font-size: 14px; }
.check-key { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); }
.check-key span { display: inline-flex; align-items: center; gap: 6px; }
.check-key .pk { width: 10px; height: 10px; border-width: 1.5px; }
.sensor.check.sev1 { border-left: 4px solid #e0a02a; } .sensor.check.sev2 { border-left: 4px solid #d0453a; } .sensor.check.sev0 { border-left: 4px solid #3f9a52; }
.sensor.check h3 .pk { margin: 0 4px 0 2px; }
.tag.v-good { background: #3f9a52; color: #fff; } .tag.v-look { background: #e0a02a; color: #1d2a22; } .tag.v-move { background: #d0453a; color: #fff; }
.suggest { margin: 0; font-weight: 600; font-size: 14px; }
.missing { margin: 0; padding-left: 18px; font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
.sensor .reason { width: 100%; font-size: 14px; }
