:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --border: #d7dde6;
  --text: #1a2634;
  --muted: #5c6f82;
  --accent: #1368ce;
  --accent-strong: #0c4f9f;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.app-shell {
  display: grid;
  grid-template-columns: 380px 1fr;
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.controls {
  min-width: 0;
  overflow: auto;
  overflow-x: hidden;
  padding: 14px;
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, #f9fbff 0%, #eef4fa 100%);
}

.controls h1 {
  margin: 0 0 6px;
  font-size: 22px;
}

.intro {
  max-width: 34rem;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
}

.panel h2 {
  margin: 0 0 8px;
  font-size: 15px;
}

.panel.small li {
  font-size: 12px;
  line-height: 1.35;
  margin-bottom: 4px;
}

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0 4px;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

input[type="range"] {
  width: 100%;
}

button {
  min-width: 0;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

button.primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-strong);
  font-weight: 600;
}

button.primary:hover {
  background: var(--accent-strong);
}

/* Generate while a run is in flight: app.js swaps the label to "Generating…"
   and adds .busy synchronously on click, so the press registers before the
   first status update. The trailing dot spinner reuses the map-busy-spin
   keyframes (defined near .map-busy-spinner below). */
button.primary.busy {
  cursor: progress;
}

button.primary.busy::after {
  content: "";
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-left: 8px;
  vertical-align: -1px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: map-busy-spin 0.7s linear infinite;
}

button.secondary {
  width: 100%;
  margin-top: 6px;
  color: var(--muted);
}

.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.checkbox input {
  width: auto;
}

.compose-mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.mode-btn {
  border: none;
  border-radius: 0;
  background: #fff;
  color: var(--muted);
  font-weight: 600;
}

.mode-btn.active {
  background: var(--accent);
  color: #fff;
}

.mode-btn + .mode-btn {
  border-left: 1px solid var(--border);
}

.shape-list {
  margin-top: 8px;
}

.shape-list-empty {
  font-size: 12px;
  color: var(--muted);
}

.shape-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  margin-bottom: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 12px;
}

.shape-row-editing {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.shape-badge {
  flex: none;
  width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 50%;
  font-weight: 700;
  color: #fff;
}

.shape-badge-add {
  background: #2f6b2f;
}

.shape-badge-subtract {
  background: #c0392b;
}

.shape-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shape-btn {
  flex: none;
  padding: 3px 7px;
  font-size: 11px;
}

.shape-style-toggle {
  color: #a03024;
  border-color: #d8a39d;
}

.shape-delete {
  color: var(--muted);
}

/* Single-shape edit handles (Leaflet divIcon markers). */
.edit-handle {
  box-sizing: border-box;
  border-radius: 3px;
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  cursor: grab;
}

.edit-handle:active {
  cursor: grabbing;
}

.edit-handle-rotate {
  border-radius: 50%;
  border-color: #1368ce;
  background: #eaf3ff;
}

.results {
  margin-top: 8px;
}

.result-item {
  width: 100%;
  margin-bottom: 6px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 12px;
  line-height: 1.3;
}

.result-title {
  overflow-wrap: anywhere;
}

.result-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.result-actions button {
  padding: 6px 8px;
  font-size: 12px;
}

.hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.status {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
  white-space: pre-wrap;
  min-height: 44px;
  background: #f9fcff;
}

.summary {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.slider-row input[type="range"] {
  flex: 1;
}

.slider-row input[type="number"] {
  width: 64px;
}

.mode-banner {
  border-left: 3px solid #9aa7b1;
  background: #f2f5f7;
  color: #4a5560;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 4px;
  margin-bottom: 12px;
}

.mode-banner-ok {
  border-left-color: #5a9c59;
  background: #eef6ee;
  color: #41603f;
}

.option-hint {
  margin: 2px 0 12px 22px;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-row .status {
  flex: 1;
}

.status-log-toggle {
  font-size: 12px;
  padding: 2px 8px;
}

.status-log {
  border: 1px solid #d9dee2;
  border-radius: 6px;
  margin-top: 6px;
  padding: 6px 10px;
  font-size: 12px;
  max-height: 140px;
  overflow-y: auto;
}

.status-log-line {
  padding: 1px 0;
}

.status-log-warning {
  background: #fdf3e3;
  color: #a05a00;
  border-radius: 4px;
  padding: 2px 6px;
  margin: 2px 0;
}

input:disabled {
  opacity: 0.55;
}

.leaflet-draw-toolbar a.topoprint-draw-ellipse {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3E%3Cellipse cx='15' cy='15' rx='9' ry='6' fill='none' stroke='%23333' stroke-width='3'/%3E%3C/svg%3E") !important;
  background-position: center center !important;
  background-repeat: no-repeat !important;
  background-size: 24px 24px !important;
}

.leaflet-draw-toolbar a.topoprint-draw-ellipse::before {
  content: none;
}

.leaflet-crosshair {
  cursor: crosshair;
}

.hidden {
  display: none;
}

.map-area {
  position: relative;
  min-width: 0;
}

#map {
  width: 100%;
  height: 100%;
}

/* Busy indicator: fixed to the map corner while a selection/preview recompute
   or border probe runs. Reference-counted in app.js so overlapping tasks do
   not clear it early. pointer-events:none keeps the map fully interactive. */
.map-busy {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 1200;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 16px;
  background: rgba(26, 38, 52, 0.88);
  color: #f6f8fb;
  font-size: 12px;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

/* .map-busy declares display:flex after the .hidden utility, so it would win on
   source order alone; this higher-specificity rule keeps .hidden authoritative. */
.map-busy.hidden {
  display: none;
}

.map-busy-spinner {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid rgba(246, 248, 251, 0.35);
  border-top-color: #f6f8fb;
  animation: map-busy-spin 0.7s linear infinite;
}

@keyframes map-busy-spin {
  to { transform: rotate(360deg); }
}

.viewer-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: #14171c;
  display: flex;
  flex-direction: column;
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: #1d2229;
  color: #e8ecf1;
}

.viewer-title {
  font-weight: 600;
}

.viewer-stale {
  background: #fdf3e3;
  color: #a05a00;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 12px;
}

.viewer-toolbar .viewer-download {
  margin-left: auto;
}

.viewer-canvas-host {
  flex: 1;
  min-height: 0;
}

.viewer-canvas-host canvas {
  display: block;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 48vh 52vh;
  }

  .controls {
    width: 100vw;
    max-width: 100vw;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .map-area {
    width: 100vw;
    max-width: 100vw;
  }
}

@media (max-width: 520px) {
  .row {
    grid-template-columns: 1fr;
  }

  .row button {
    width: 100%;
  }
}
