:root {
  --green: #2f7d32;
  --green-dark: #245f27;
  --ink: #16211a;
  --muted: #5d6b62;
  --line: #dfe5e0;
  --bg: #f6f8f6;
  --panel-w: 380px;
}

* { box-sizing: border-box; }

/* A `display` rule on an element beats the user-agent's `[hidden]` style, so
 * anything given `display: flex` below would ignore its hidden attribute --
 * which left the loading spinner permanently on screen. Settle it globally. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ------------------------------------------------------------- top bar */
.topbar {
  height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; letter-spacing: -0.01em; }
.brand-mark {
  width: 18px; height: 18px; border-radius: 5px;
  background: linear-gradient(140deg, #4caf50, var(--green-dark));
}
.quota {
  font-size: 13px; color: var(--muted);
  background: var(--bg); border: 1px solid var(--line);
  padding: 4px 10px; border-radius: 999px;
}

/* -------------------------------------------------------------- layout */
.layout {
  display: flex;
  height: calc(100% - 56px);
}
.panel {
  width: var(--panel-w);
  flex: 0 0 var(--panel-w);
  padding: 22px 20px;
  overflow-y: auto;
  background: #fff;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.mapwrap { position: relative; flex: 1; min-width: 0; }
#map { position: absolute; inset: 0; }

@media (max-width: 820px) {
  .layout { flex-direction: column-reverse; }
  .panel { width: 100%; flex: 1 1 auto; border-right: 0; border-top: 1px solid var(--line); }
  .mapwrap { flex: 0 0 46vh; }
}

/* --------------------------------------------------------------- steps */
h1 { font-size: 24px; line-height: 1.25; margin: 0 0 8px; letter-spacing: -0.02em; }
h2 { font-size: 18px; margin: 0 0 10px; letter-spacing: -0.01em; }
.sub { color: var(--muted); margin: 0 0 16px; }
.note { color: var(--muted); font-size: 13px; margin-top: 16px; }
.chosen { font-weight: 600; margin: 0 0 4px; }

input[type=text] {
  width: 100%; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 9px;
  font: inherit; background: #fff;
}
input[type=text]:focus { outline: 2px solid var(--green); outline-offset: 1px; border-color: transparent; }

button { font: inherit; cursor: pointer; border-radius: 9px; }
button:disabled { opacity: .45; cursor: not-allowed; }

.primary {
  width: 100%; margin-top: 10px; padding: 11px 14px;
  background: var(--green); color: #fff; border: 0; font-weight: 600;
}
.primary:hover:not(:disabled) { background: var(--green-dark); }

.ghost {
  padding: 9px 13px; background: #fff; color: var(--ink);
  border: 1px solid var(--line); font-weight: 500;
}
.ghost:hover { border-color: #b9c4bc; }

.link {
  background: none; border: 0; color: var(--muted);
  text-decoration: underline; padding: 6px 0; font-size: 13px; text-align: left;
}

.row { display: flex; gap: 8px; align-items: center; }
.row .primary { margin-top: 0; }

.opt {
  display: flex; gap: 9px; align-items: flex-start;
  margin-top: 14px; font-size: 13.5px; cursor: pointer;
}
.opt input { margin-top: 3px; flex: none; }

/* The tips switch, at the very top of the panel. Small, because it is a
 * preference and not a step. */
.tiptoggle {
  display: flex; align-items: center; gap: 8px;
  margin: -4px 0 14px; padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  font-size: 13px; color: var(--muted); cursor: pointer;
}
.tiptoggle input { flex: none; accent-color: var(--green); }
.opt small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }

/* ------------------------------------------------------ model + pins */
.models {
  margin-top: 12px; padding: 11px 13px 12px;
  border: 1px solid var(--line); border-radius: 11px; background: #fbfcfb;
}
.models label {
  display: block; font-size: 12.5px; font-weight: 600;
  color: var(--muted); margin-bottom: 5px;
}
.models select {
  width: 100%; padding: 9px 10px; font: inherit; font-size: 14px;
  color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: 9px;
}
.models .sub { margin: 7px 0 0; font-size: 12.5px; }

.pins {
  margin-top: 12px; padding: 11px 13px 2px;
  border: 1px solid #ffd54f; border-radius: 11px; background: #fffdf5;
}
.pin-count { margin: 0 0 10px; font-size: 13.5px; font-weight: 550; }

/* ------------------------------------------------------------- map rail */
/*
 * The editing modes live on the map, not in the panel below it. They are used
 * while looking at the lawn, and the panel had grown long enough that reaching
 * them meant scrolling away from the thing being edited.
 */
.maprail {
  position: absolute; top: 96px; right: 10px; z-index: 3;
  display: flex; flex-direction: column; gap: 6px;
}
.railbtn {
  width: 54px; padding: 7px 2px 5px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font: inherit; font-size: 10.5px; font-weight: 600; line-height: 1;
  color: #1f2d24; background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(0, 0, 0, 0.16); border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.22);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.railbtn svg { width: 22px; height: 22px; }
.railbtn:active { background: #eef2ee; }
.railbtn[aria-pressed="true"] { background: #1b5e20; border-color: #14401a; color: #fff; }

/* The sub-tools sit indented, so it reads as "inside lawn mode". */
.railsub {
  display: flex; flex-direction: column; gap: 5px;
  margin-left: 10px; padding-left: 7px; border-left: 2px solid rgba(255, 255, 255, 0.85);
}
.railbtn.sub { width: 46px; font-size: 9.5px; }
.railbtn.sub svg { width: 19px; height: 19px; }
.railundo { margin-top: 4px; }
.railundo:disabled { opacity: .4; cursor: not-allowed; }
#mode-move[aria-pressed="true"] { background: #1565c0; border-color: #0d47a1; }
#tool-add[aria-pressed="true"]   { background: #2e7d32; border-color: #1b5e20; }
#tool-erase[aria-pressed="true"] { background: #c62828; border-color: #8e0000; }

/* Layers sits opposite the editing tools: what you are LOOKING at on one
 * side, what you are CHANGING on the other. */
.maprail-left { right: auto; left: 10px; }

/* The source list hangs off the Layers button rather than sitting in the
 * rail's flex column, which would stretch the rail to the width of the
 * longest source name. */
.layerlist {
  position: absolute; top: 58px; left: 0; width: 212px; max-width: 60vw;
  display: flex; flex-direction: column; gap: 2px; padding: 5px;
  background: rgba(255, 255, 255, .97);
  border: 1px solid rgba(0, 0, 0, .16); border-radius: 11px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, .26);
}
.layerlist button {
  text-align: left; padding: 8px 10px; font: inherit; font-size: 13px;
  background: none; border: 0; border-radius: 8px; color: var(--ink);
  display: flex; align-items: baseline; gap: 6px;
}
.layerlist button:hover { background: #eef2ee; }
.layerlist button[aria-checked="true"] { background: #1b5e20; color: #fff; font-weight: 600; }
/* "View only" is said in the list, not after choosing: picking a source and
 * then being told it cannot be measured from is a wasted step. */
.layerlist .viewonly { font-size: 11px; opacity: .72; margin-left: auto; white-space: nowrap; }

@media (max-width: 700px) {
  .maprail { top: 88px; right: 8px; }
  .maprail-left { right: auto; left: 8px; }
}

/* ---------------------------------------------------------- coach marks */
/*
 * A tip, pointed at the control it is about.
 *
 * Every button on this map is an unlabelled icon on a photograph, and two of
 * the decisions here (which picture the AI is shown, that only some pictures
 * can be sent to it at all) are invisible in the interface. The arrow is the
 * part that matters: "press Layers" is useless if Layers is one of nine icons.
 */
.coach {
  position: absolute; z-index: 6; width: 268px; max-width: min(78vw, 268px);
  padding: 13px 14px 11px;
  background: #fff; color: var(--ink);
  border: 1px solid rgba(0, 0, 0, .14); border-radius: 13px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .28);
}
.coach-title { margin: 0 0 5px; font-size: 13.5px; font-weight: 680; letter-spacing: -0.01em; }
.coach-text { margin: 0 0 11px; font-size: 13px; line-height: 1.45; color: #33413a; }
.coach-ok {
  width: 100%; padding: 8px 12px; font-weight: 600; font-size: 13.5px;
  background: var(--green); color: #fff; border: 0;
}
.coach-ok:hover { background: var(--green-dark); }

/* Drawn as a rotated square so the border and shadow carry round the point. */
.coach-arrow {
  position: absolute; width: 13px; height: 13px;
  background: #fff; border: 1px solid rgba(0, 0, 0, .14);
  transform: rotate(45deg);
}
.coach-arrow.at-left  { left: -7px;  border-right: 0; border-top: 0; }
.coach-arrow.at-right { right: -7px; border-left: 0;  border-bottom: 0; }

/* ------------------------------------------------------- imagery source */
.imagery {
  margin-top: 12px; padding: 11px 13px 12px;
  border: 1px solid var(--line); border-radius: 11px; background: #fbfcfb;
}
.imagery label {
  display: block; font-size: 12.5px; font-weight: 600;
  color: var(--muted); margin-bottom: 5px;
}
.imagery select {
  width: 100%; padding: 9px 10px; font: inherit; font-size: 14px;
  color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: 9px;
}
.imagery .sub { margin: 7px 0 0; font-size: 12.5px; }
.imagery input[type=range] { width: 100%; margin: 2px 0 0; accent-color: var(--green); }

/* --------------------------------------------------------- edge editing */
.edgepanel {
  margin-top: 12px; padding: 12px 13px;
  border: 1px solid var(--line); border-radius: 11px; background: #fbfcfb;
}
.edge-info { margin: 0 0 10px; font-size: 13.5px; color: var(--muted); }
.edge-info.active { color: var(--ink); font-weight: 550; }
.edge-readout { display: flex; align-items: baseline; gap: 9px; margin-bottom: 4px; }
.edge-readout span { font-size: 22px; font-weight: 650; letter-spacing: -0.02em; }
.edge-readout small { color: var(--muted); font-size: 12px; }
.edgepanel input[type=range] { width: 100%; margin: 4px 0 2px; accent-color: var(--green); }
.edgepanel .sub { font-size: 12.5px; margin: 6px 0 12px; }
/* Corner editing sits below the slider: available, but not competing with the
 * extend control for the eye. Extending is the operation that keeps the
 * surveyed bearings, so it stays the obvious one. */
.edge-secondary { width: 100%; margin-bottom: 10px; font-size: 13.5px; }

/* ---------------------------------------------------------- candidates */
.candidates { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 7px; }
.candidates button {
  width: 100%; text-align: left; padding: 11px 12px;
  background: #fff; border: 1px solid var(--line);
}
.candidates button:hover { border-color: var(--green); background: #f4faf4; }
.candidates .addr { display: block; font-weight: 550; }
.candidates .meta { display: block; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.pill {
  display: inline-block; font-size: 11px; font-weight: 600;
  padding: 1px 7px; border-radius: 999px; margin-right: 6px;
  background: #e8f3e9; color: var(--green-dark);
}
.pill.grey { background: #eef0ee; color: var(--muted); }

/* -------------------------------------------------------------- result */
.result {
  border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; margin-bottom: 14px; background: #f4faf4;
}
.result-figure { font-size: 34px; font-weight: 680; letter-spacing: -0.03em; line-height: 1.1; }
.result-figure small { font-size: 15px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.result-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }

.statusline { font-size: 13.5px; color: var(--muted); min-height: 20px; margin-bottom: 10px; }
.statusline.warn { color: #a35b00; }
.statusline.error { color: #b3261e; }

.tools { display: flex; flex-wrap: wrap; gap: 8px; }
.tools .primary { width: auto; margin-top: 0; flex: 1 1 100%; }
.tools .ghost { flex: 1 1 0; }

.exports { display: flex; gap: 8px; margin-top: 14px; }
.exports .ghost { flex: 1; }

.help { margin-top: 16px; font-size: 13.5px; color: var(--muted); }
.help summary { cursor: pointer; color: var(--ink); font-weight: 550; }
.help ul { margin: 8px 0 0; padding-left: 18px; display: grid; gap: 4px; }
kbd {
  font: inherit; font-size: 12px; background: #eef0ee;
  border: 1px solid var(--line); border-radius: 4px; padding: 0 4px;
}

.debug { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); margin-top: 16px; }
.disclaimer { margin: auto 0 0; padding-top: 20px; font-size: 12px; color: var(--muted); }

.fatal {
  border: 1px solid #f0d0cc; background: #fdf5f4;
  border-radius: 12px; padding: 16px;
}
.fatal h2 { color: #b3261e; }

/* --------------------------------------------------------- map chrome */
.hint {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(22, 33, 26, .88); color: #fff;
  padding: 9px 15px; border-radius: 999px; font-size: 13.5px; font-weight: 500;
  max-width: 82%; text-align: center; pointer-events: none; z-index: 3;
}
.overlay {
  position: absolute; inset: 0; z-index: 4;
  background: rgba(246, 248, 246, .82);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
}
.overlay p { margin: 0; font-weight: 550; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid #cfd8d1; border-top-color: var(--green);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* ------------------------------------------------------------- printing */
.printblock { display: none; }
@media print {
  .topbar, .panel, .hint, .overlay, .mapboxgl-ctrl,
  .maprail, .coach, .layerlist { display: none !important; }
  .layout { display: block; height: auto; }
  .mapwrap { position: relative; height: 62vh; page-break-after: avoid; }
  .printblock { display: block; padding: 18px 4px; font-size: 13px; }
  .printblock h1 { font-size: 20px; margin: 0 0 6px; }
  .print-figure { font-size: 26px; font-weight: 700; margin: 10px 0; }
  .print-foot { color: #666; font-size: 11px; margin-top: 18px; }
}

/* Brush width, indented under the brush it belongs to. */
.railsize {
  display: flex; flex-direction: column; gap: 5px;
  margin-top: 4px; padding-top: 5px;
  border-top: 2px solid rgba(255, 255, 255, 0.85);
}
