: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 { margin-left: auto; color: #fff; font-size: 13px; opacity: 0.95; }
.topbar-who + .topbar-link { margin-left: 14px; }
#proto-badge + .topbar-who { margin-left: 16px; }

/* Embedded in the SageStack hub: the hub header already shows the signed-in email and a
 * Sign out button, so this line only repeats them. The rest of the topbar stays — the
 * title, the BETA badge and the Admin link are not duplicated anywhere in the hub, and
 * the Admin link is the only route to admin.html. Push the Admin link to the right in
 * its place, since #auth-who was the flex item carrying `margin-left: auto`. */
.framed #auth-who { display: none; }
.framed #auth-who + .topbar-link { margin-left: auto; }

/* ---- 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: 340px;
  flex: 0 0 340px;
  overflow-y: auto;
  background: var(--bg);
  border-right: 1px solid var(--line);
  padding: 14px;
}

/* Draggable divider so the sidebar (and its result tables) can be widened.
   Shows an always-visible grip so it reads as a handle. */
#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 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 {
  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 label, label.btn { cursor: pointer; }
.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; }
/* "Save to projectai" is a real action, not a de-emphasized one — the ghost grey
   read as disabled. Keep the ghost frame, take the normal text colour. (The
   genuinely-disabled state still greys out via .btn:disabled's opacity.) */
#save-projectai, #btn-sites-projectai { color: var(--text); }
.btn.active { outline: 2px solid var(--green-light); }
/* Optional-feature elements (data-feature=...) are hidden by app.js when the deployment
   has the feature off. Belt and braces against any later display rule on .btn. */
[hidden] { display: none !important; }

.file-label { display: block; font-size: 12px; color: #6c6862; }
.file-label input { display: block; margin-top: 6px; font-size: 12px; }

.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;
}
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 0; }
fieldset legend { font-size: 12px; color: #6c6862; padding: 0 4px; }
fieldset label { display: inline-block; font-size: 13px; margin-right: 10px; }

.check-field { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-top: 12px; cursor: pointer; }
.check-field input { width: auto; margin: 0; }
.muted-note { color: #8a857d; }

.status { font-size: 12px; color: #6c6862; margin: 6px 0 0; }

.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); } }

#explorer { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; margin-bottom: 12px; }
#explorer .field { margin: 0; }
#explorer .field:first-child { grid-column: 1 / -1; }

#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.id, table.results td.rank { text-align: center; font-weight: 600; }

.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-item + .legend-item { margin-top: 8px; }
.legend-title { font-weight: 600; margin-bottom: 4px; }
.legend-bar { height: 10px; width: 140px; border: 1px solid #999; border-radius: 2px; }
.legend-labels { display: flex; justify-content: space-between; margin-top: 2px; color: #555; }
.legend-cats { display: flex; flex-direction: column; gap: 3px; }
.legend-cat { display: flex; align-items: center; }
.legend-swatch { display: inline-block; width: 12px; height: 12px; border: 1px solid #999; border-radius: 2px; margin-right: 6px; }

.rank-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }
.site-label { font-weight: 700; color: #222; text-shadow: 0 0 3px #fff, 0 0 3px #fff; }

/* ---- Results tabs (reference-app layout) ------------------------------ */
.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, .res-subtab {
  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, .res-subtab.active {
  background: #fff; border-bottom-color: #fff; font-weight: 600; color: var(--green);
}
.res-subtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.res-view { min-height: 20px; }
.res-desc {
  background: #f6f5f2; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; margin: 0 0 10px; font-size: 12px; color: #555;
}
#res-controls { margin-bottom: 10px; }

/* DOI + "User Generated" stamps overlaid on the map */
.res-stamp {
  background: rgba(255,255,255,0.9); border: 1px solid var(--line); border-radius: 6px;
  padding: 3px 8px; font-size: 11px; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.res-doi a { color: var(--green); }

/* Rank number badge on each polygon (circled, like the reference app) */
.rank-label.leaflet-tooltip {
  background: #fff; color: #222; border: 2px solid #333; border-radius: 50%;
  width: 24px; height: 24px; line-height: 20px; text-align: center;
  font-weight: 700; padding: 0; box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.rank-label.leaflet-tooltip::before { display: none; }  /* drop the tooltip pointer */

/* HSI/GBI raster toggles */
.res-toggles { display: flex; flex-direction: column; gap: 4px; }
.res-toggle { font-size: 13px; display: flex; align-items: center; gap: 6px; cursor: pointer; }

/* ---- Results Tables tab ------------------------------------------------ */
.res-rankmetric { max-width: 280px; margin: 0 0 12px; }
.res-tablebar { display: flex; justify-content: flex-end; margin: 6px 0; }
.res-search { font-size: 13px; color: #555; }
.res-search input { margin-left: 6px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; }
.res-tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table.dtable { border-collapse: collapse; width: 100%; font-size: 13px; }
table.dtable th, table.dtable td { padding: 6px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
table.dtable th { background: #f0efeb; position: sticky; top: 0; cursor: pointer; user-select: none; }
table.dtable th:first-child, table.dtable td:first-child,
table.dtable th:nth-child(2), table.dtable td:nth-child(2) { text-align: center; }
table.dtable tbody tr:hover { background: #faf9f6; }
.col-q {
  display: inline-block; width: 14px; height: 14px; line-height: 14px; text-align: center;
  border-radius: 50%; background: #4a90d9; color: #fff; font-size: 10px; cursor: help;
}
.sort-arrow { color: var(--green); font-size: 10px; }
.res-entries { font-size: 12px; color: #6c6862; margin: 8px 0 4px; }

/* Release label, lower-right corner. Above the Leaflet panes (z-index <= 1000),
   below the sign-in overlay (2000). Opens the change log (changelog.js). */
#version {
  position: fixed; right: 8px; bottom: 6px; z-index: 1500;
  font: inherit; font-size: 10px; color: #6c6862; opacity: 0.8;
  background: none; border: 0; padding: 0; cursor: pointer;
}
#version:hover, #version:focus-visible { text-decoration: underline; opacity: 1; }

#changelog {
  position: fixed; right: 8px; bottom: 24px; z-index: 1500;
  width: 320px; max-height: 60vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  padding: 10px 14px; font-size: 12px; color: var(--text);
}
#changelog.hidden { display: none; }
#changelog h3 { margin: 0 0 8px; font-size: 14px; color: var(--green); }
#changelog .cl-entry + .cl-entry { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; }
#changelog .cl-head { display: flex; justify-content: space-between; font-weight: 600; }
#changelog .cl-date { color: #6c6862; font-weight: 400; }
#changelog ul { margin: 4px 0 0; padding-left: 18px; }
#changelog li { margin: 2px 0; }
