:root {
  --green: #075e4e;
  --green-light: #84a69c;
  --accent: #d29f59;
  --bg: #f4f3f0;
  --panel: #ffffff;
  --line: #d9d6cf;
  --text: #23211e;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--green);
  color: #fff;
  padding: 10px 18px;
}
#topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
#topbar .muted { opacity: 0.7; font-weight: 400; }
#proto-badge {
  margin-left: auto;
  background: var(--accent);
  color: #2a1d05;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 4px 10px;
  border-radius: 999px;
}
.topbar-link { color: #fff; font-size: 13px; margin-left: 14px; text-decoration: underline; }
.topbar-who { color: #fff; font-size: 13px; opacity: 0.95; }
#proto-badge + .topbar-who { margin-left: 16px; }

/* ---- Sign-in overlay ---- */
#auth-overlay {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  background: var(--green);
  background-image: linear-gradient(135deg, var(--green), #0a3a30);
}
.auth-card {
  background: #fff; border-radius: 14px; padding: 28px 26px; width: 360px; max-width: 92vw;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
}
.auth-card h2 { margin: 0 0 4px; font-size: 20px; color: var(--green); }
.auth-sub { margin: 0 0 18px; font-size: 13px; color: #6c6862; }
.auth-card input[type="email"], .auth-card input[type="text"], #auth-code {
  width: 100%; font: inherit; font-size: 15px; padding: 10px 12px; margin-bottom: 10px;
  border: 1px solid var(--line); border-radius: 8px;
}
#auth-code { letter-spacing: 4px; text-align: center; }
.auth-card .btn-primary { width: 100%; padding: 10px; font-size: 14px; }
.auth-trust { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #444; margin: 2px 0 12px; cursor: pointer; }
.auth-trust input { width: auto; }
.auth-msg { font-size: 13px; color: #6c6862; margin: 12px 0 0; min-height: 1em; }
.auth-msg.err { color: #b3261e; }

#layout { flex: 1; display: flex; min-height: 0; }

#sidebar {
  width: 360px;
  flex: 0 0 360px;
  overflow-y: auto;
  background: var(--bg);
  border-right: 1px solid var(--line);
  padding: 14px;
}

/* Draggable divider so the sidebar can be widened. */
#resizer {
  flex: 0 0 10px;
  cursor: col-resize;
  background: var(--line);
  transition: background 0.15s;
  position: relative;
}
#resizer::after {
  content: "⋮";
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 20px; line-height: 1; color: #7a756c; pointer-events: none;
}
#resizer:hover, body.resizing #resizer { background: var(--green-light); }
#resizer:hover::after, body.resizing #resizer::after { color: #fff; }
body.resizing { cursor: col-resize; user-select: none; }
body.resizing #map { pointer-events: none; }

#map { flex: 1; min-width: 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.panel-head h2 { margin: 0; }
.panel h2 { font-size: 14px; margin: 0 0 8px; color: var(--green); }
.hint { font-size: 12px; color: #6c6862; margin: 0 0 10px; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.btn-row.tight { gap: 6px; margin-bottom: 0; }
.btn {
  font: inherit; font-size: 13px; padding: 7px 12px;
  border: 1px solid var(--line); background: #fff; border-radius: 8px; cursor: pointer;
}
.btn:hover { background: #f0efeb; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:disabled:hover { background: #fff; }
.btn.active { outline: 2px solid var(--green-light); }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #2a1d05; font-weight: 600; width: 100%; }
.btn-primary:hover { filter: brightness(0.96); }
.btn-ghost { color: #8a857d; }
.grow { flex: 1; min-width: 0; }
input.grow { font: inherit; font-size: 13px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; }

.field { display: block; font-size: 13px; margin: 10px 0 0; }
.field input, .field select {
  display: block; width: 100%; margin-top: 4px;
  font: inherit; font-size: 13px; padding: 6px 8px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.status { font-size: 12px; color: #6c6862; margin: 6px 0 0; }

/* ---- Nested site / scenario editor ---------------------------------- */
#sites { display: flex; flex-direction: column; gap: 10px; }

.site {
  border: 1px solid var(--line);
  border-left: 4px solid var(--site-color, var(--green));
  border-radius: 8px;
  background: #fdfcfa;
}
.site-head {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; cursor: pointer; user-select: none;
}
.site-head .twisty { color: #8a857d; font-size: 11px; width: 12px; }
.site-head .site-name { font-weight: 600; font-size: 13px; flex: 1; min-width: 0; }
.site-head .site-name[contenteditable] { outline: none; cursor: text; border-bottom: 1px dashed transparent; }
.site-head .site-name[contenteditable]:hover, .site-head .site-name[contenteditable]:focus { border-bottom-color: var(--line); }
.site-body { padding: 4px 10px 10px; display: none; }
.site.open .site-body { display: block; }
.site.open .twisty { transform: rotate(90deg); }

.icon-btn {
  border: none; background: none; cursor: pointer; color: #8a857d;
  font-size: 13px; padding: 2px 5px; border-radius: 5px;
}
.icon-btn:hover { background: #eceae4; color: #b3261e; }

/* A drawable feature group (boundary / existing / a scenario's new infrastructure). */
.fgroup { border-top: 1px solid var(--line); padding: 8px 0 4px; }
.fgroup:first-child { border-top: none; }
.fgroup-head { display: flex; align-items: center; gap: 6px; margin-bottom: 5px; }
.fgroup-title { font-size: 12px; font-weight: 600; color: var(--green); flex: 1; }
.fgroup-title[contenteditable] { outline: none; cursor: text; }
.fgroup-count { font-size: 11px; color: #8a857d; }
.draw-row { display: flex; gap: 5px; flex-wrap: wrap; }
.draw-btn {
  font: inherit; font-size: 12px; padding: 3px 8px;
  border: 1px solid var(--line); background: #fff; border-radius: 6px; cursor: pointer;
}
.draw-btn:hover { background: #f0efeb; }
.draw-btn.active { background: var(--green); color: #fff; border-color: var(--green); }
.draw-btn.clear { color: #b3261e; margin-left: auto; }
.draw-btn.upload { color: var(--green); }

/* Import: projection prompt + the confirmation toast it ends with. */
.modal-back {
  position: fixed; inset: 0; z-index: 1500;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20, 24, 22, 0.45);
}
.modal-card {
  background: #fff; border-radius: 12px; padding: 20px 22px; width: 440px; max-width: 92vw;
  box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}
.modal-card h3 { margin: 0 0 6px; font-size: 16px; color: var(--green); }
.modal-card .btn-row { margin: 14px 0 0; }
.modal-choice {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; padding: 5px 2px; cursor: pointer;
}
.modal-choice input { width: auto; }
.modal-input {
  width: 100%; font: inherit; font-size: 12px; padding: 7px 9px; margin: 4px 0 2px;
  border: 1px solid var(--line); border-radius: 8px;
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(12px);
  z-index: 1600; max-width: 80vw;
  background: var(--green); color: #fff; font-size: 13px;
  padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  opacity: 0; pointer-events: none; transition: opacity 0.18s, transform 0.18s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.scenarios { margin-top: 6px; }
.scenarios-head { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 4px; }
.scenarios-head .lbl { font-size: 12px; font-weight: 600; color: #6c6862; }
.scenario {
  border: 1px dashed var(--line); border-radius: 6px; padding: 6px 8px; margin-top: 6px; background: #fff;
}
.scenario-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.scenario-name { font-size: 12px; font-weight: 600; flex: 1; }
.scenario-name[contenteditable] { outline: none; cursor: text; }

.empty-note { font-size: 12px; color: #8a857d; padding: 6px 2px; }

/* The colour a group draws in on the map, beside its name. */
.swatch {
  display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex: 0 0 auto;
  border: 1px solid rgba(0, 0, 0, 0.3);
}

/* ---- Progress + results --------------------------------------------- */
.progress { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 13px; }
.progress.hidden { display: none; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--green);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#results-table { font-size: 12px; overflow-x: auto; }
table.results { border-collapse: collapse; width: 100%; }
table.results th, table.results td { border: 1px solid var(--line); padding: 4px 7px; text-align: right; white-space: nowrap; }
table.results th { background: #f0efeb; text-align: center; position: sticky; top: 0; }
table.results td.lbl { text-align: left; }

.legend { background: rgba(255,255,255,0.92); padding: 8px 10px; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.3); font-size: 11px; color: var(--text); }
.legend-title { font-weight: 600; margin-bottom: 4px; }
.legend-bar { height: 10px; width: 100%; border: 1px solid #999; border-radius: 2px; }
.legend-labels { display: flex; justify-content: space-between; margin-top: 2px; color: #555; }

.res-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.res-title { font-weight: 700; color: var(--green); }
.res-tabs { display: flex; gap: 4px; margin-left: auto; }
.res-tab {
  border: 1px solid var(--line); background: #f0efeb; color: var(--text);
  border-radius: 8px 8px 0 0; padding: 5px 12px; font-size: 13px; cursor: pointer;
}
.res-tab.active { background: #fff; border-bottom-color: #fff; font-weight: 600; color: var(--green); }
.res-view { min-height: 20px; }
.res-desc { background: #f6f5f2; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 8px 0; font-size: 12px; color: #555; }

/* Draw-mode banner over the map so the user knows what they're drawing into. */
#draw-banner {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  z-index: 1000; background: var(--green); color: #fff;
  padding: 6px 14px; border-radius: 999px; font-size: 13px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3); display: none; align-items: center; gap: 10px;
}
#draw-banner.show { display: flex; }
#draw-banner button { border: none; background: rgba(255,255,255,0.25); color: #fff; border-radius: 6px; padding: 2px 8px; cursor: pointer; font: inherit; font-size: 12px; }

/* "Site 1 · Scenario 2" over each drawn scenario. */
.scen-label {
  font-size: 11px; font-weight: 600; padding: 2px 6px;
  background: rgba(255, 255, 255, 0.9); border: 1px solid #999; border-radius: 4px;
}
.scen-label::before { display: none; }

/* Results integrity warning: the maps and the table disagree. Deliberately loud — the failure it
   reports looks like a normal result set until you notice a scenario is showing another's map. */
.res-warn {
  font-size: 12px; line-height: 1.45;
  color: #7a1c14; background: #fdecea;
  border: 1px solid #f0b8b1; border-left: 4px solid #b3261e;
  border-radius: 6px; padding: 8px 10px; margin: 0 0 10px;
}
tr.row-warn td { background: #fdecea; }
