* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}

#map {
  position: fixed;
  inset: 0;
}

.panel {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 1000;
  width: 260px;
  max-width: calc(100vw - 20px);
  background: rgba(255, 255, 255, 0.95);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid #e3e3e3;
}

.panel.collapsed .panel-body,
.panel.collapsed .panel-header {
  border-bottom: none;
}

.panel.collapsed .panel-body {
  display: none;
}

.panel-body {
  padding: 10px 12px 12px;
}

.field-label {
  display: block;
  font-size: 12px;
  color: #555;
  margin: 8px 0 3px;
}

.field-label:first-child {
  margin-top: 0;
}

select,
input[type="text"] {
  width: 100%;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 15px;
  background: #fff;
}

input[type="range"] {
  width: 100%;
}

.area-label {
  font-size: 13px;
  color: #b71c1c;
  font-weight: 600;
  margin-top: 4px;
  min-height: 16px;
}

.btn-row {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.btn-row.right {
  justify-content: flex-end;
}

button {
  padding: 8px 12px;
  border: 1px solid #bbb;
  border-radius: 6px;
  background: #f5f5f5;
  font-size: 14px;
  cursor: pointer;
}

button:hover {
  background: #ececec;
}

button.danger {
  color: #b71c1c;
  border-color: #d8a0a0;
}

.icon-btn {
  padding: 2px 10px;
  font-size: 16px;
  line-height: 1.2;
}

.status {
  font-size: 12px;
  color: #666;
  margin-top: 8px;
  min-height: 14px;
}

dialog {
  border: none;
  border-radius: 10px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  width: 420px;
  max-width: calc(100vw - 24px);
  padding: 16px;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

/* The edit dialog previews live on the map: dock it to the left edge so it
   does not cover the screen-centre anchored overlay, and keep the map
   undimmed so the preview stays visible. */
#edit-dialog {
  margin: auto auto auto 16px;
}

#edit-dialog::backdrop {
  background: transparent;
}

dialog h3 {
  margin: 0 0 10px;
}

.scale-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.scale-row input[type="range"] {
  flex: 1;
}

.scale-row input[type="number"] {
  width: 80px;
  padding: 6px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
}

input[type="color"] {
  width: 60px;
  height: 34px;
  padding: 2px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
}

button.primary {
  background: #d32f2f;
  border-color: #d32f2f;
  color: #fff;
}

button.primary:hover {
  background: #b71c1c;
}

button.full-width {
  width: 100%;
  margin-top: 10px;
}

.mode-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  max-width: calc(100vw - 20px);
}

.mode-bar[hidden] {
  display: none; /* author display:flex above would otherwise beat the UA [hidden] rule */
}

.mode-bar span {
  font-size: 13px;
}

/* Small screens and touch devices in landscape (which exceed the width breakpoint). */
@media (max-width: 600px), (pointer: coarse) and (max-height: 500px) {
  .mode-bar {
    bottom: auto;
    top: 12px;
    /* left:50% + translateX caps shrink-to-fit width at ~50vw; anchor both edges instead */
    left: 10px;
    right: 10px;
    transform: none;
    justify-content: center;
    flex-wrap: wrap;
  }
}

.search-row {
  display: flex;
  gap: 6px;
}

.search-row input {
  flex: 1;
}

.results {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  max-height: 45vh;
  overflow-y: auto;
}

.results li {
  padding: 9px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  margin-bottom: 6px;
  cursor: pointer;
}

.results li:hover {
  background: #f3f3f3;
}

.results .res-name {
  font-weight: 600;
}

.results .res-detail {
  font-size: 12px;
  color: #666;
}

@media (max-width: 600px), (pointer: coarse) and (max-height: 500px) {
  .panel {
    top: auto;
    right: 10px;
    bottom: 12px;
    left: 10px;
    width: auto;
  }
}
