/* ---------------------------------------------------------
   geoprint — topographic survey station
   Typography: Fraunces (display) + JetBrains Mono (data/ui)
   Palette: coal/forest ground, topo-green ink, clay accents
   --------------------------------------------------------- */

:root {
  --bg:          #0a0c09;
  --bg-raised:   #11140f;
  --bg-sunk:     #070906;
  --surface:     #161a12;
  --surface-2:   #1d2217;
  --border:      #2a2f22;
  --border-hi:   #3e4632;
  --border-bri:  #5a6641;

  --ink:         #e6e4d3;
  --ink-2:       #b5b2a0;
  --muted:       #807c69;
  --muted-2:     #4f4d40;

  --topo:        #9dc85f;        /* primary contour green */
  --topo-deep:   #466d24;
  --topo-glow:   rgba(157, 200, 95, 0.18);
  --clay:        #d08a52;        /* "currently editing" warm */
  --clay-deep:   #6b3f1d;
  --ink-red:     #e06a5a;

  --font-display: "Fraunces", Georgia, serif;
  --font-mono:    "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --rail-w: 56px;
  --topbar-h: 58px;
  --footer-h: 26px;
  --right-w: 520px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 12px/1.45 var(--font-mono);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr var(--footer-h);
  height: 100vh;
}

/* subtle grain overlay everywhere */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.035;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.6'/></svg>");
  mix-blend-mode: overlay;
}

/* -------------------- topbar -------------------- */

.topbar {
  display: grid;
  grid-template-columns: 280px 1fr auto;
  gap: 18px;
  align-items: center;
  padding: 0 16px;
  background: linear-gradient(180deg, #0f1210 0%, #0a0c09 100%);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 10;
}
.topbar::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--topo-deep) 50%, transparent);
  opacity: 0.55;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  font-size: 26px;
  color: var(--topo);
  line-height: 1;
  text-shadow: 0 0 16px var(--topo-glow);
  transform: translateY(-1px);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text h1 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 24px;
  letter-spacing: -0.02em;
  margin: 0;
  font-variation-settings: "opsz" 96;
}
.brand-text .sub {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
  margin-top: 2px;
}

/* readout (center of topbar) */
.readout {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(90px, auto);
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--bg-sunk);
  height: 38px;
  overflow: hidden;
}
.readout-cell {
  padding: 3px 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-right: 1px solid var(--border);
  min-width: 0;
}
.readout-cell:last-child { border-right: none; }
.readout-cell.wide { min-width: 280px; }
.readout-label {
  font-size: 8.5px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--muted);
}
.readout-value {
  font-size: 12px;
  color: var(--ink);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-feature-settings: "tnum" 1, "ss01" 1;
}
.readout-value.accent { color: var(--topo); }
.readout-value.warn   { color: var(--clay); }

.actions {
  display: flex;
  gap: 6px;
}

/* -------------------- buttons -------------------- */

button {
  font: inherit;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.12s;
}
button:disabled { opacity: 0.35; cursor: not-allowed; }

.actions button {
  padding: 8px 14px;
  background: transparent;
  border: 1px solid var(--border-hi);
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 10.5px;
  font-weight: 500;
}
.actions button.ghost:hover:not(:disabled) {
  border-color: var(--border-bri);
  background: var(--surface);
}
.actions button.primary {
  background: var(--topo-deep);
  border-color: var(--topo);
  color: #0a0c09;
}
.actions button.primary:hover:not(:disabled) {
  background: var(--topo);
  transform: translateY(-1px);
  box-shadow: 0 2px 14px var(--topo-glow);
}

/* -------------------- main grid -------------------- */

main {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr var(--right-w);
  min-height: 0;
}

/* -------------------- tool rail -------------------- */

.tool-rail {
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0;
  gap: 6px;
  position: relative;
  z-index: 5;
}
.tool-rail::after {
  /* thin contour-line accent down the inside edge */
  content: "";
  position: absolute;
  right: 0;
  top: 0; bottom: 0;
  width: 1px;
  background-image: linear-gradient(to bottom, transparent, var(--border) 10%, var(--border) 90%, transparent);
}

.rail-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  align-items: center;
}
.rail-divider {
  width: 70%;
  margin: 6px auto;
  position: relative;
  display: flex;
  justify-content: center;
}
.rail-divider::before,
.rail-divider::after {
  content: "";
  flex: 1;
  border-top: 1px dashed var(--border-hi);
  transform: translateY(50%);
}
.rail-divider span {
  font-size: 8px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--muted-2);
  padding: 0 4px;
}
.rail-spacer { flex: 1; }

.tool-btn {
  position: relative;
  width: 42px;
  height: 42px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink-2);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.tool-btn svg { width: 22px; height: 22px; color: inherit; fill: currentColor; }
.tool-btn svg [stroke] { stroke: currentColor; }
.tool-btn kbd {
  position: absolute;
  bottom: 2px;
  right: 3px;
  font-size: 8px;
  line-height: 1;
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-weight: 500;
}
.tool-btn:hover:not(:disabled) {
  color: var(--ink);
  border-color: var(--border-hi);
  background: var(--surface);
}
.tool-btn.active {
  color: var(--topo);
  border-color: var(--topo);
  background: rgba(157, 200, 95, 0.08);
  box-shadow: inset 0 0 0 1px var(--topo-deep), 0 0 16px var(--topo-glow);
}
.tool-btn.active kbd { color: var(--topo); }
.tool-btn.danger:hover:not(:disabled) {
  color: var(--ink-red);
  border-color: var(--ink-red);
  background: rgba(224, 106, 90, 0.08);
}

.basemap { flex-direction: column; gap: 2px; padding: 4px 0; }
.rail-minibtn {
  font-family: var(--font-mono);
  font-size: 8.5px;
  letter-spacing: 0.2em;
  font-weight: 500;
  padding: 4px 0;
  width: 42px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.rail-minibtn.active {
  color: var(--topo);
  border-color: var(--topo-deep);
  background: rgba(157, 200, 95, 0.07);
}

/* -------------------- map pane -------------------- */

#pane-map {
  position: relative;
  min-width: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-sunk);
}
#map {
  position: absolute;
  inset: 0;
}
.leaflet-container {
  background: #1a1d1a !important;
  font-family: var(--font-mono) !important;
  cursor: default;
}
/* Default "MAP" style uses Carto Voyager, tinted dusk-dark to match the
   app aesthetic. Toggled off for DARK and SAT basemaps. */
.leaflet-tile-pane {
  filter: brightness(0.55) saturate(0.6) contrast(1.05) hue-rotate(-4deg);
  transition: filter 0.25s ease;
}
.basemap-dark .leaflet-tile-pane,
.basemap-sat  .leaflet-tile-pane {
  filter: none;
}
.leaflet-container.drawing-cursor { cursor: crosshair; }
.leaflet-container.dragging-shape { cursor: grabbing; }
.leaflet-control-attribution {
  background: rgba(10,12,9,0.75) !important;
  color: var(--muted-2) !important;
  font-size: 10px;
  border: 1px solid var(--border);
}
.leaflet-control-attribution a { color: var(--topo) !important; }
.leaflet-control-zoom a {
  background: var(--bg-raised) !important;
  color: var(--ink) !important;
  border: 1px solid var(--border) !important;
  font-family: var(--font-mono);
}
.leaflet-control-zoom a:hover { border-color: var(--topo-deep) !important; color: var(--topo) !important; }
.leaflet-interactive:focus { outline: none; }

.map-hint {
  position: absolute;
  top: 14px;
  left: 14px;
  padding: 8px 14px;
  background: rgba(10, 12, 9, 0.9);
  border: 1px solid var(--border-hi);
  border-left: 2px solid var(--topo);
  color: var(--ink);
  font-size: 11px;
  z-index: 500;
  pointer-events: none;
  max-width: calc(100% - 28px);
  backdrop-filter: blur(4px);
  transform: translateY(-6px);
  opacity: 0;
  transition: transform 0.18s, opacity 0.18s;
}
.map-hint.show { opacity: 1; transform: translateY(0); }
.map-hint .hint-k {
  color: var(--topo);
  font-weight: 500;
  letter-spacing: 0.05em;
}

/* -------------------- right pane (viewer + panel) -------------------- */

#pane-right {
  display: grid;
  grid-template-rows: 320px 1fr;
  min-height: 0;
  background: var(--bg);
}

#viewer {
  position: relative;
  border-bottom: 1px solid var(--border);
  background: radial-gradient(ellipse at 30% 20%, #1b2114 0%, #06080a 70%);
  overflow: hidden;
}
#viewer::before {
  /* cross-hair ref grid */
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(157,200,95,0.05) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(157,200,95,0.05) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(ellipse at center, black 40%, transparent 80%);
}
#viewer-canvas { display: block; width: 100%; height: 100%; }

.floating-chip {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 6px 10px;
  background: rgba(10,12,9,0.86);
  border: 1px solid var(--border-hi);
  font-size: 10.5px;
  color: var(--ink-2);
  z-index: 3;
  font-family: var(--font-mono);
}
.viewer-corner {
  position: absolute;
  top: 10px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  z-index: 4;
}
.viewer-icon-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 12, 9, 0.72);
  border: 1px solid var(--border-hi);
  color: var(--ink-2);
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.viewer-icon-btn svg { width: 16px; height: 16px; }
.viewer-icon-btn .ic-collapse { display: none; }
#viewer.is-fullscreen .viewer-icon-btn .ic-expand { display: none; }
#viewer.is-fullscreen .viewer-icon-btn .ic-collapse { display: block; }
.viewer-icon-btn:hover {
  color: var(--topo);
  border-color: var(--topo-deep);
  background: rgba(157, 200, 95, 0.08);
}

/* -------- loading overlay -------- */

.viewer-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: radial-gradient(ellipse at center, rgba(10,12,9,0.55), rgba(10,12,9,0.92) 75%);
  backdrop-filter: blur(2px);
  z-index: 3;
  color: var(--topo);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.viewer-loading.show { opacity: 1; pointer-events: auto; }
.reticle { width: 72px; height: 72px; color: var(--topo); }
.reticle .r-outer { transform-origin: 50% 50%; animation: spin-cw 3.4s linear infinite; }
.reticle .r-inner { transform-origin: 50% 50%; animation: spin-ccw 5.1s linear infinite; }
@keyframes spin-cw { to { transform: rotate(360deg); } }
@keyframes spin-ccw { to { transform: rotate(-360deg); } }

.loading-phase {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--topo);
}
.loading-detail {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  font-feature-settings: "tnum" 1;
  min-height: 14px;
}

/* -------- fullscreen -------- */

#viewer.is-fullscreen {
  position: fixed !important;
  inset: 0 !important;
  z-index: 10000;
  width: 100vw !important;
  height: 100vh !important;
  border: none;
  background: radial-gradient(ellipse at 30% 20%, #1b2114 0%, #06080a 75%);
}
#viewer.is-fullscreen::before {
  background-size: 60px 60px;
  mask-image: radial-gradient(ellipse at center, black 50%, transparent 90%);
}
#viewer.is-fullscreen .viewer-corner {
  top: 18px; right: 22px;
}

/* -------------------- panel -------------------- */

#panel {
  overflow: auto;
  padding: 4px 0 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-hi) transparent;
}
#panel::-webkit-scrollbar { width: 6px; }
#panel::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 1px; }

.panel-section {
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--border);
}
.panel-section:last-child { border-bottom: none; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0 10px;
  font-size: 9.5px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--muted);
}
.section-header::after {
  content: "";
  flex: 1;
  border-bottom: 1px dashed var(--border-hi);
  margin-left: 10px;
  order: 2;
}
.section-title { order: 1; font-weight: 500; color: var(--ink-2); }
.section-count { order: 3; color: var(--muted-2); font-size: 10px; letter-spacing: 0.14em; }
.section-chevron { order: 3; color: var(--muted); transition: transform 0.2s; }
details[open] .section-chevron { transform: rotate(180deg); }

details > summary { cursor: pointer; list-style: none; user-select: none; }
details > summary::-webkit-details-marker { display: none; }

#models-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.model-row {
  display: grid;
  grid-template-columns: 10px 1fr auto auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.model-row:hover { border-color: var(--border-hi); }
.model-row.active {
  border-color: var(--topo);
  background: rgba(157, 200, 95, 0.06);
  box-shadow: inset 2px 0 0 var(--topo);
}
.model-row .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted-2);
}
.model-row.active .dot { background: var(--topo); box-shadow: 0 0 10px var(--topo-glow); }
.model-row input.name {
  background: transparent;
  border: none;
  color: var(--ink);
  font: 12px var(--font-mono);
  outline: none;
  padding: 2px 0;
  min-width: 0;
}
.model-row input.name:focus { color: var(--topo); }
.model-row .meta {
  color: var(--muted);
  font-size: 10px;
  font-feature-settings: "tnum" 1;
  white-space: nowrap;
}
.model-row button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 3px 8px;
  font-size: 9.5px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}
.model-row button:hover:not(:disabled) { color: var(--ink); border-color: var(--border-bri); }
.model-row button.rm:hover:not(:disabled) { color: var(--ink-red); border-color: var(--ink-red); }

/* -------------------- params form -------------------- */

.params {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}
.params .full { grid-column: 1 / -1; }
.params label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.params label .hint {
  text-transform: none;
  letter-spacing: 0.02em;
  font-size: 9.5px;
  color: var(--muted-2);
}
.params input[type="number"],
.params input[type="text"],
.params select {
  background: var(--bg-sunk);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 6px 8px;
  font: 12px var(--font-mono);
  outline: none;
  transition: border-color 0.12s;
  min-width: 0;
}
.params input:focus,
.params select:focus {
  border-color: var(--topo-deep);
  box-shadow: 0 0 0 1px var(--topo-deep);
}

.params .empty {
  color: var(--muted-2);
  font-style: italic;
  font-size: 11px;
  padding: 6px 0;
}

/* -------------------- footer -------------------- */

footer {
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  background: var(--bg-raised);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.05em;
}
footer a { color: var(--ink-2); text-decoration: none; }
footer a:hover { color: var(--topo); }
footer .foot-sep { color: var(--muted-2); }

/* -------------------- drawing / leaflet overlays -------------------- */

.draw-preview {
  /* temp polygon while drawing */
  stroke: var(--clay);
  fill: rgba(208, 138, 82, 0.12);
  stroke-dasharray: 6 4;
  stroke-width: 1.5;
  animation: march 0.9s linear infinite;
}
@keyframes march {
  to { stroke-dashoffset: -20; }
}

.shape-path {
  stroke: var(--topo-deep);
  stroke-width: 1.5;
  fill: rgba(157, 200, 95, 0.05);
  transition: stroke 0.12s, fill 0.12s;
}
.shape-path.hover { stroke: var(--topo); fill: rgba(157, 200, 95, 0.1); }
.shape-path.selected {
  stroke: var(--topo);
  stroke-width: 2;
  fill: rgba(157, 200, 95, 0.13);
}
.shape-path.editing { stroke: var(--clay); }

.vertex-handle {
  fill: var(--bg);
  stroke: var(--topo);
  stroke-width: 1.5;
  transition: fill 0.1s, transform 0.1s;
  cursor: grab;
}
.vertex-handle:hover { fill: var(--topo); }
.vertex-handle.dragging { fill: var(--clay); stroke: var(--clay); cursor: grabbing; }

.mid-handle {
  fill: var(--bg);
  stroke: var(--topo-deep);
  stroke-width: 1;
  stroke-dasharray: 2 2;
  opacity: 0.5;
  cursor: copy;
}
.mid-handle:hover { opacity: 1; stroke: var(--topo); }

/* -------------------- responsive niceties -------------------- */

@media (max-width: 1200px) {
  :root { --right-w: 460px; }
  .readout-cell.wide { min-width: 220px; }
}
@media (max-width: 1000px) {
  .readout-cell { padding: 3px 10px; }
  .readout-cell.wide { min-width: 160px; }
}
