/* RAÍZ-SAR AI — map-first interface. Plain CSS custom properties; no build step. */
:root {
  --basalt: #1d2428;        /* panels */
  --basalt-2: #262f34;      /* raised controls */
  --line: #36434a;
  --sand: #ece3d2;          /* primary text on panels */
  --sand-dim: #b4ab99;      /* secondary text */
  --zone: #e2a33b;          /* candidate zones (ochre) */
  --nogo: #e2654f;          /* excluded / no-go */
  --sar: #6db3df;           /* radar evidence */
  --rain: #4bb3ae;          /* precipitation */
  --future: #86c06c;        /* AI-generated future scenario only */
  --seed: #f4d35e;          /* proposed seed deposition */
  --focus: #f4d35e;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(8, 12, 14, 0.35);
  --panel-w: 380px;
  --top-h: 60px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1b2226; color: var(--sand);
  font-family: "Archivo", system-ui, sans-serif; font-size: 15px; line-height: 1.45; font-variant-numeric: tabular-nums; }
h1, h2, h3 { font-stretch: 112%; font-weight: 700; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.05rem; } h3 { font-size: 0.95rem; }
p { margin: 0.35rem 0; }
a { color: var(--sar); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -60px; z-index: 50; background: var(--focus); color: #111; padding: 8px 12px; border-radius: 6px; }
.skip:focus { top: 8px; }

#map { position: fixed; inset: 0; }

/* Top bar */
.topbar { position: fixed; top: 0; left: 0; right: 0; height: var(--top-h); z-index: 20; display: flex; align-items: center; gap: 16px;
  padding: 0 16px; background: rgba(29, 36, 40, 0.94); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 170px; }
.brand-mark { width: 28px; height: 28px; color: var(--zone); }
.brand-name { display: block; font-stretch: 118%; font-weight: 800; font-size: 1rem; }
.brand-place { display: block; font-size: 0.8rem; color: var(--sand-dim); }
.steps { flex: 1; overflow-x: auto; }
.steps ol { display: flex; gap: 4px; list-style: none; margin: 0; padding: 0; }
.steps button { display: flex; align-items: center; gap: 8px; border: 1px solid transparent; background: none; color: var(--sand-dim);
  font: inherit; font-weight: 600; padding: 7px 12px; border-radius: 999px; cursor: pointer; white-space: nowrap; min-height: 40px; }
.steps button .n { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid currentColor; font-size: 0.75rem; }
.steps button:hover:not([aria-disabled="true"]) { color: var(--sand); border-color: var(--line); }
.steps button[aria-current="step"] { color: #1b2226; background: var(--zone); }
.steps button[aria-current="step"] .n { border-color: #1b2226; }
.steps button[aria-disabled="true"] { opacity: 0.45; cursor: help; }
.steps button.done .n { background: var(--sand-dim); color: #1b2226; border-color: transparent; }
.status { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; max-width: 300px; }
.pill { font-size: 0.75rem; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--sand-dim); white-space: nowrap; }
.pill.ok { color: var(--future); border-color: rgba(134, 192, 108, 0.5); }
.pill.warn { color: var(--zone); border-color: rgba(226, 163, 59, 0.6); }
.pill.bad { color: var(--nogo); border-color: rgba(226, 101, 79, 0.6); }

/* Contextual panel */
.panel { position: fixed; top: calc(var(--top-h) + 12px); left: 12px; bottom: 12px; width: var(--panel-w); z-index: 15;
  display: flex; flex-direction: column; background: rgba(29, 36, 40, 0.96); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); transition: transform 220ms ease; }
.panel.collapsed { transform: translateX(calc(-100% + 46px)); }
.panel.collapsed .panel-body, .panel.collapsed h1 { visibility: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 6px 18px; }
.panel-body { overflow-y: auto; padding: 4px 18px 18px; flex: 1;
  -webkit-mask-image: linear-gradient(to bottom, #000 94%, transparent); mask-image: linear-gradient(to bottom, #000 94%, transparent); }
.lead { color: var(--sand-dim); font-size: 0.9rem; }
.block { border-top: 1px solid var(--line); padding: 12px 0; }
.block:first-child { border-top: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 0.85rem; margin: 6px 0; }
.kv dt { color: var(--sand-dim); } .kv dd { margin: 0; }
.note { font-size: 0.8rem; color: var(--sand-dim); }
.warnline { font-size: 0.85rem; color: var(--zone); }
.errline { font-size: 0.85rem; color: var(--nogo); }
details > summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.explain { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--line);
  background: none; color: var(--sand-dim); font: inherit; font-size: 0.75rem; cursor: help; margin-left: 4px; }
.glossary { font-size: 0.85rem; color: var(--sand-dim); margin: 4px 0 8px; }

/* Controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--basalt-2); color: var(--sand); font: inherit; font-weight: 600;
  cursor: pointer; transition: transform 120ms, border-color 120ms, background 120ms; }
.btn:hover:not(:disabled) { border-color: var(--sand-dim); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn.primary { background: var(--zone); color: #1b2226; border-color: var(--zone); }
.btn.quiet { background: none; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn[aria-pressed="true"] { border-color: var(--zone); color: var(--zone); }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; background: none; border: 1px solid var(--line); border-radius: 8px; color: var(--sand); cursor: pointer; }
.icon-btn svg { width: 18px; height: 18px; }
label { display: block; font-size: 0.85rem; color: var(--sand-dim); margin: 8px 0 3px; }
input, select { width: 100%; min-height: 38px; padding: 6px 9px; background: #151b1e; color: var(--sand); border: 1px solid var(--line);
  border-radius: 7px; font: inherit; }
input[type="range"] { padding: 0; accent-color: var(--zone); }
input[type="radio"], input[type="checkbox"] { width: auto; min-height: 0; accent-color: var(--zone); }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin: 6px 0; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--zone); }
.choice .t { font-weight: 600; color: var(--sand); }
.choice .d { font-size: 0.8rem; color: var(--sand-dim); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: none; border: 0; color: var(--sand-dim); font: inherit; font-weight: 600; padding: 8px 12px; min-height: 40px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--zone); color: #1b2226; }

table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
th, td { text-align: left; padding: 5px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--sand-dim); font-weight: 600; }
td.num, th.num { text-align: right; }
.chart { position: relative; height: 190px; margin-top: 8px; }

.zone-item { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; margin: 6px 0; }
.zone-item > div:first-child { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; align-items: center; }
.zone-item > div:first-child .note { grid-column: 1 / -1; }
.zone-item.no_go { border-color: rgba(226, 101, 79, 0.6); }
.zone-item input { min-height: 32px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 6px; }
.badge { display: inline-block; font-size: 0.72rem; padding: 1px 7px; border-radius: 999px; border: 1px solid currentColor; margin-left: 4px; white-space: nowrap; }
.b-observed { color: var(--sar); } .b-derived { color: #9fd0c9; } .b-modeled { color: #d9c08f; } .b-ai { color: var(--future); }
.b-illustrative { color: var(--zone); } .b-unknown { color: var(--sand-dim); border-style: dashed; } .b-sim { color: var(--nogo); border-style: dashed; }

/* Legend + provenance */
.legend { position: fixed; right: 12px; bottom: 34px; z-index: 14; width: 300px; max-height: 45vh; overflow-y: auto;
  background: rgba(29, 36, 40, 0.94); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; font-size: 0.8rem; box-shadow: var(--shadow); }
.legend h2 { font-size: 0.85rem; margin-bottom: 4px; }
.legend .li { display: flex; gap: 8px; align-items: flex-start; margin: 5px 0; }
.legend .src { color: var(--sand-dim); }
.legend:empty { display: none; }
.map-tools { position: fixed; right: 12px; top: calc(var(--top-h) + 12px); z-index: 14; display: flex; gap: 6px; }
.tool { min-height: 38px; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: rgba(29, 36, 40, 0.94);
  color: var(--sand); font: inherit; font-weight: 600; cursor: pointer; }
.tool[aria-pressed="true"] { border-color: var(--zone); color: var(--zone); }
.tool-seg { background: rgba(29, 36, 40, 0.94); }
.tool-seg[hidden] { display: none; }
.tool-seg button { min-height: 38px; color: var(--sand); }
.maplibregl-ctrl-attrib { font-family: "Archivo", system-ui, sans-serif; }
.maplibregl-ctrl-top-right { top: calc(var(--top-h) + 58px); }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 40; background: var(--basalt); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: min(560px, 92vw); }

/* Guided tour */
.tour { position: fixed; inset: 0; z-index: 60; background: rgba(10, 14, 16, 0.55); display: grid; place-items: center; }
.tour[hidden] { display: none; }
.tour-card { background: var(--basalt); border: 1px solid var(--line); border-radius: 12px; padding: 22px; width: min(440px, 92vw); box-shadow: var(--shadow); }
.tour-count { color: var(--sand-dim); font-size: 0.8rem; margin: 0 0 4px; }

/* Before/after comparison */
.compare-dates { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* AR overlay */
#ar-overlay { position: fixed; inset: 0; z-index: 80; background: #000; }
#ar-overlay[hidden] { display: none; }
#ar-container { position: absolute; inset: 0; }
#ar-container a-scene { position: absolute !important; inset: 0; width: 100% !important; height: 100% !important; }
.ar-top { position: absolute; z-index: 90; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; gap: 12px; padding: 12px;
  background: linear-gradient(rgba(10, 14, 16, 0.9), transparent); }
.ar-top p { font-size: 0.85rem; }
.ar-hud { position: absolute; z-index: 90; left: 0; right: 0; bottom: 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px;
  background: linear-gradient(transparent, rgba(10, 14, 16, 0.92)); }
.ar-hud p { font-size: 0.85rem; flex: 1 1 260px; }

#print-area { display: none; }
@media print {
  body { overflow: visible; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; color: #000; background: #fff; padding: 12mm; font-size: 10.5pt; }
  #print-area th, #print-area td { border-bottom: 1px solid #999; color: #000; }
  #print-area .watermark { border: 2px solid #000; padding: 4px 8px; font-weight: 700; display: inline-block; }
}

@media (max-width: 1100px) { :root { --panel-w: 340px; } .status { display: none; } }
@media (max-width: 900px) {
  :root { --top-h: 104px; }
  .topbar { flex-wrap: wrap; height: var(--top-h); padding: 8px 12px; gap: 6px; }
  .steps { flex-basis: 100%; order: 3; }
  .steps button .label { display: none; }
  .panel { top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 46dvh; max-height: 46dvh; border-radius: 14px 14px 0 0; }
  .panel.collapsed { transform: translateY(calc(100% - 52px)); }
  .legend { display: none; }
  .map-tools { top: calc(var(--top-h) + 8px); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
.seg.wrap { flex-wrap: wrap; }

/* NISAR evidence panel: before/after radar images, class overlay and measurements */
.nisar-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
.nisar-pair figure { margin: 0; }
.nisar-pair figcaption { font-size: 0.78rem; color: var(--sand-dim); margin-top: 4px; }
.nisar-img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #0d1114; border-radius: 6px; image-rendering: pixelated; display: block; }
.nisar-stack { position: relative; }
.nisar-stack .nisar-img + .nisar-img { position: absolute; inset: 0; background: transparent; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; margin: 0 2px 0 6px; }
table.metrics { width: 100%; border-collapse: collapse; font-size: 0.78rem; margin: 6px 0; }
table.metrics th, table.metrics td { border-bottom: 1px solid var(--line); padding: 4px 3px; text-align: left; vertical-align: top; }
@media (max-width: 480px) { .nisar-pair { grid-template-columns: 1fr; } table.metrics { display: block; overflow-x: auto; } }

/* Shared growth + event timeline controls */
.timeline { margin: 8px 0; }
.timeline input[type=range] { width: 100%; }

/* One bounded page per step; extensive material is opened deliberately. */
.panel-body { position: relative; overflow: hidden; min-height: 0; display: flex; flex-direction: column; mask-image: none; -webkit-mask-image: none; }
.panel-head { flex-shrink: 0; }
.panel-viewport { flex: 1; min-height: 0; overflow: hidden; }
.panel-pages { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-shrink: 0; }
.panel-pages:empty { min-height: 0; }
.panel-measure { position: absolute; inset: 0 18px auto; visibility: hidden; pointer-events: none; }
.detail-launch { width: 100%; min-height: 44px; margin: 6px 0; justify-content: space-between; }
.detail-launch::after { content: "↗"; }
.detail-dialog { width: min(760px,94vw); max-height: 88dvh; border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--basalt); color: var(--sand); box-shadow: var(--shadow); }
.detail-dialog::backdrop { background: rgba(8,15,18,.55); }
.detail-head { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.detail-head h2 { font-size: 1.05rem; }
.detail-body { padding: 14px 18px; overflow: auto; max-height: calc(88dvh - 82px); }
.detail-body table { display: block; max-width: 100%; overflow-x: auto; }
.legend { display: flex; flex-wrap: wrap; gap: 5px; width: auto; max-width: min(620px,calc(100vw - 440px)); max-height: none; overflow: visible; background: transparent; border: 0; box-shadow: none; padding: 0; }
.key-chip { display: inline-flex; gap: 6px; align-items: center; padding: 6px 10px; border-radius: 20px; background: rgba(245,241,229,.94); color: #27333a; font: 12px "Archivo",sans-serif; }
.key-chip i { width: 9px; height: 9px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); }
.key-more { cursor: pointer; border: 1px solid #697570; min-height: 32px; }
.source-key .li { display: flex; gap: 8px; margin: 10px 0; }
.source-key .src { color: var(--sand-dim); font-size: .8rem; }
.tool[hidden] { display: none; }
@media (max-width:900px) { .legend { display: flex; bottom: calc(46vh + 10px); right: 10px; max-width: 92vw; } .legend > .key-chip:not(button) { display: none; } .map-tools { max-width: calc(100vw - 20px); flex-wrap: wrap; justify-content: flex-end; } }

/* Territorial controls reuse the workflow panel; the map keeps its full viewport. */
.territory-controls { border-bottom: 1px solid var(--line); padding-bottom: 12px; }
.territory-controls > summary { font-weight: 700; cursor: pointer; padding: 8px 0; }
.territory-controls > label { display: block; margin-top: 8px; font-size: .82rem; }
.territory-controls > select, .territory-controls > input { width: 100%; min-height: 44px; }
.territory-places { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.territory-places .btn { min-height: 44px; padding: 6px 9px; }
.territory-layers { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px; }
.territory-check { display: flex; align-items: center; gap: 7px; min-height: 44px; font-size: .82rem; }
.territory-check input { accent-color: var(--zone); width: 18px; height: 18px; flex-shrink: 0; }
.territory-inspect { overflow-wrap: anywhere; border-left: 2px solid var(--sar); padding-left: 8px; }
@media (max-width: 480px) { .territory-layers { grid-template-columns: 1fr; } }

/* Area overview counters */
.counters { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin: 8px 0; }
.counter { display: flex; flex-direction: column; gap: 2px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; }
.counter-v { font-size: 1.35rem; font-weight: 800; line-height: 1.1; }
.counter-l { font-size: 0.75rem; color: var(--sand-dim); }
