/*
 * AcreageMap — illustrated property map.
 *
 * The chrome deliberately stays quiet: warm paper, thin rules, serif for
 * anything map-ish (titles, measurements) and sans for controls. The map
 * itself is drawn on canvas; its palette lives in src/map/style.ts and the
 * hex values here are kept in sync with it by hand.
 */

:root {
  /* paper + ink */
  --paper: #efe7d6;
  --paper-deep: #e5dbc6;
  --panel: #f8f4ea;
  --panel-edge: #d8cdb4;
  --ink: #2f2a22;
  --muted: #7d7361;
  --line: #cec2a9;

  /* map-ish accents, mirrored in src/map/style.ts */
  --green: #4a6b4f;
  --green-soft: #b9c9a4;
  --brown: #8a7a5c;
  --blue: #3a6ea5;
  --red: #a5432f;
  --amber: #b8862f;

  --font-sans: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-serif: Georgia, 'Iowan Old Style', 'Palatino Linotype', 'Book Antiqua', serif;

  --radius: 6px;
  --shadow: 0 2px 10px rgba(47, 42, 34, 0.13);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--ink);
  background: var(--paper);
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ---- app shell ---------------------------------------------------------- */

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
}

.stage {
  position: relative;
  flex: 1;
  min-width: 0;
}

/*
 * The cursor names the mode. Select is a plain arrow — the map is a document
 * you point at — and only the tools that *put something down* get the crosshair
 * that promises precision. A grab hand appears when the map is actually about
 * to be dragged: space held, or a pan under way.
 */
.map {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;      /* we handle pan/zoom ourselves */
  cursor: default;
}
.map.is-pan-ready { cursor: grab; }
.map.is-panning { cursor: grabbing; }
.map.is-drawing { cursor: crosshair; }
.map.is-picking { cursor: crosshair; }

/* ---- top bar ------------------------------------------------------------ */

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  height: 46px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-edge);
  flex: none;
}

.topbar h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.topbar .spacer { flex: 1; }

.topbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-sep {
  width: 1px;
  height: 22px;
  background: var(--line);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  background: var(--panel);
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.3;
}
.btn:hover { background: #fffdf6; border-color: var(--line); }
.btn:active { background: var(--paper-deep); }
.btn[aria-pressed='true'],
.btn.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(47, 42, 34, 0.07); }
.btn.danger { color: var(--red); }
.btn.primary {
  background: var(--green);
  border-color: var(--green);
  color: #fbf8f0;
}
.btn.primary:hover { background: #3f5c44; }
.btn.small { padding: 3px 7px; font-size: 12px; }

.btn.danger-solid {
  background: var(--red);
  border-color: var(--red);
  color: #fff3ee;
}
.btn.danger-solid:hover { background: #8e3927; }

.topbar-note {
  padding: 3px 8px;
  border: 1px dashed var(--line);
  border-radius: 99px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---- File menu ---------------------------------------------------------- */

.menu { position: relative; }
.menu > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary::after { content: ' ▾'; opacity: 0.6; }
.menu[open] > summary { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 5px);
  z-index: 30;
  min-width: 208px;
  padding: 5px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.menu-item {
  display: block;
  width: 100%;
  padding: 6px 9px;
  border: none;
  border-radius: 5px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}
.menu-item:hover { background: rgba(47, 42, 34, 0.08); }
.menu-item.danger { color: var(--red); }
.menu-item:disabled { color: var(--muted); opacity: 0.55; cursor: default; }
.menu-item:disabled:hover { background: transparent; }
.menu-sep { height: 1px; margin: 5px 4px; background: var(--line); }

/* ---- right-click menu --------------------------------------------------- */

/* A transparent sheet so the next click anywhere dismisses the menu — including
   a click on the map, which would otherwise select something while the menu for
   the last thing was still open. */
.context-scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
}
.context-menu {
  position: fixed;
  right: auto;
  top: 0;
  left: 0;
  z-index: 41;
  min-width: 190px;
}
.context-title {
  padding: 4px 9px 6px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
  font-family: var(--font-serif);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

/* ---- left palette ------------------------------------------------------- */

.palette {
  width: 186px;
  flex: none;
  overflow-y: auto;
  padding: 10px 8px 24px;
  background: var(--panel);
  border-right: 1px solid var(--panel-edge);
}
.palette.is-hidden { display: none; }

.palette-group + .palette-group { margin-top: 14px; }

.palette-group h3 {
  margin: 0 0 5px;
  font-family: var(--font-serif);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
/* The whole heading is the fold control — a 9px caret is not a target. */
.group-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  padding: 2px 4px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  text-align: left;
  cursor: pointer;
}
.group-toggle:hover { background: rgba(47, 42, 34, 0.06); color: var(--ink); }
.group-toggle .caret { font-size: 9px; opacity: 0.75; }
.group-toggle .count { margin-left: auto; opacity: 0.7; font-variant-numeric: tabular-nums; }
.palette-group.is-collapsed + .palette-group { margin-top: 6px; }

.kind-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 7px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.kind-btn:hover { background: rgba(47, 42, 34, 0.06); }
.kind-btn.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}
.kind-btn .swatch {
  flex: none;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid rgba(47, 42, 34, 0.25);
}
.kind-btn .hint {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
}
.kind-btn.is-active .hint { color: rgba(239, 231, 214, 0.7); }

.palette-hint {
  margin: 16px 4px 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
}
.palette-hint.warn {
  padding: 8px 9px;
  border: 1px solid var(--amber);
  border-radius: var(--radius);
  background: rgba(184, 134, 47, 0.12);
  color: var(--ink);
}

/* ---- layer strip -------------------------------------------------------- */

.layers {
  display: flex;
  align-items: center;
  gap: 4px;
}

.layer-chip {
  display: inline-flex;
  align-items: center;
  padding: 0 4px 0 2px;
  border: 1px solid var(--panel-edge);
  border-radius: 99px;
  background: var(--panel);
  font-size: 13px;
}
.layer-chip .layer-eye,
.layer-chip .layer-name {
  border: none;
  background: transparent;
  cursor: pointer;
  color: inherit;
  font: inherit;
}
.layer-chip .layer-eye {
  display: flex;
  align-items: center;
  padding: 5px 5px 5px 7px;
}
.layer-chip .layer-name { padding: 4px 7px 4px 3px; border-radius: 99px; }
/* Whether the underlay is held inside the property line. Small and quiet: it
   only matters while tracing, and only to whoever is doing the tracing. */
.layer-clip {
  padding: 2px 6px;
  margin-right: 2px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}
.layer-clip:hover { color: var(--ink); border-color: var(--ink); }
.layer-clip.is-on { background: rgba(47, 42, 34, 0.1); color: var(--ink); }
button.layer-name:hover { background: rgba(47, 42, 34, 0.08); }
.layer-chip .dot {
  width: 9px;
  height: 9px;
  border-radius: 99px;
  background: var(--muted);
  box-shadow: 0 0 0 1px rgba(47, 42, 34, 0.2);
}
.layer-chip.is-hidden .dot { background: transparent; }
.layer-chip[data-role='underlay'] .dot { background: var(--brown); }
/* Not a drawing target, so it never takes the active-layer treatment. */
.layer-chip[data-role='underlay'] { border-style: dashed; }
.layer-chip[data-role='existing'] .dot { background: var(--green); }
.layer-chip[data-role='planned'] .dot { background: var(--blue); }
.layer-chip[data-role='removed'] .dot { background: var(--muted); }
.layer-chip.is-hidden {
  opacity: 0.45;
  text-decoration: line-through;
}
/* The layer being drawn into. */
.layer-chip.is-target {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
  font-weight: 600;
}

/* ---- inspector ---------------------------------------------------------- */

.inspector {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 264px;
  max-height: calc(100% - 88px);
  overflow-y: auto;
  padding: 12px 13px 14px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.inspector:empty { display: none; }

.inspector h2 {
  margin: 0 0 2px;
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 600;
}

.inspector .sub {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--muted);
}

.field { margin-bottom: 9px; }
.field label {
  display: block;
  margin-bottom: 3px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.field input[type='text'],
.field textarea,
.field select {
  width: 100%;
  padding: 5px 7px;
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  background: #fffdf6;
}
.field input[type='number'] {
  width: 100%;
  padding: 5px 7px;
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  background: #fffdf6;
}
.field textarea { resize: vertical; min-height: 54px; }
.field input[type='range'] { width: 100%; }

.field-hint {
  margin: 3px 0 0;
  font-size: 11px;
  line-height: 1.4;
  color: var(--muted);
}

.field-row { display: flex; gap: 8px; }
.field-row .field { flex: 1; }

.inspector .notes {
  margin: 0 0 10px;
  padding: 7px 9px;
  background: rgba(47, 42, 34, 0.045);
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.readout {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 3px 0;
  font-family: var(--font-serif);
  font-size: 13px;
  border-bottom: 1px dotted var(--line);
}
.readout span:last-child { color: var(--muted); }

.inspector-actions {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}

/* ---- status bar (scale + readout) --------------------------------------- */

.status {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  align-items: flex-end;
  gap: 14px;
  padding: 7px 11px;
  background: rgba(248, 244, 234, 0.9);
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-family: var(--font-serif);
  font-size: 12px;
  pointer-events: auto;
}

.scalebar { display: flex; flex-direction: column; gap: 3px; }
.scalebar .bar {
  height: 7px;
  border: 1px solid var(--ink);
  border-top: none;
  background: repeating-linear-gradient(
    to right, var(--ink) 0 var(--tick), transparent var(--tick) calc(var(--tick) * 2)
  );
}
.scalebar .label { text-align: center; letter-spacing: 0.04em; }

.status .coords {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 116px;
  padding-bottom: 1px;
}

.zoom-controls { display: flex; gap: 2px; }
.zoom-controls .btn { font-family: var(--font-sans); }

/* ---- overlays ----------------------------------------------------------- */

#modal:empty { display: none; }

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(47, 42, 34, 0.42);
  z-index: 40;
}

.card {
  width: min(420px, calc(100vw - 32px));
  padding: 20px 22px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(47, 42, 34, 0.3);
}
.card h2 {
  margin: 0 0 4px;
  font-family: var(--font-serif);
  font-size: 19px;
}
.card p { margin: 0 0 14px; color: var(--muted); }
.card .row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.card .error { color: var(--red); }

/* A stack of answers, each carrying its own consequence. */
.choices { display: flex; flex-direction: column; gap: 8px; }
.choice {
  display: block;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  background: #fffdf6;
  text-align: left;
  cursor: pointer;
}
.choice:hover { border-color: var(--ink); background: #fff; }
.choice-label { display: block; font-weight: 600; }
.choice-hint {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  padding: 8px 16px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 99px;
  box-shadow: var(--shadow);
  z-index: 45;
}

.banner {
  padding: 5px 14px;
  background: var(--amber);
  color: #2b2313;
  font-size: 13px;
  text-align: center;
  flex: none;
}
.banner.error { background: var(--red); color: #fff3ee; }
/* Banners live in #modal, which is outside the layout flow, so they position
   themselves rather than pushing the map down. */
.banner.floating {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 35;
  box-shadow: var(--shadow);
}

.fatal-screen {
  display: grid;
  place-items: center;
  height: 100vh;
  padding: 20px;
  background: var(--paper);
}
.fatal-card {
  max-width: 460px;
  padding: 24px 26px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
}
.fatal-card h2 { margin: 0 0 10px; font-family: var(--font-serif); }
.fatal-card p { margin: 0 0 8px; color: var(--muted); }

/* ---- narrow screens ----------------------------------------------------- */

@media (max-width: 700px) {
  .palette {
    position: absolute;
    z-index: 20;
    top: 0;
    bottom: 0;
    box-shadow: var(--shadow);
  }
  .inspector { top: auto; bottom: 12px; right: 12px; left: 12px; width: auto; max-height: 42%; }
  .status { bottom: auto; top: 12px; }
  .topbar h1 { display: none; }
}
