* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #1c2430;
}

body {
  display: flex;
  height: 100vh;
}

#sidebar {
  width: 320px;
  flex: 0 0 320px;
  padding: 20px;
  overflow-y: auto;
  background: #f7f9fb;
  border-right: 1px solid #e1e6ec;
}

#map {
  flex: 1;
  height: 100%;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* The collapse toggle is a mobile-only affordance; hidden on wide screens. */
#panel-toggle {
  display: none;
}

h1 {
  margin: 0;
  font-size: 22px;
}

.sub {
  margin: 4px 0 18px;
  color: #5b6776;
  font-size: 13px;
}

.mode-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}

.mode-btn {
  flex: 1;
  padding: 8px;
  border: 1px solid #cdd5df;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.mode-btn.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

label {
  display: block;
  margin: 10px 0;
  font-size: 13px;
  font-weight: 600;
  color: #364152;
}

input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 8px 10px;
  border: 1px solid #cdd5df;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 400;
}

.hint {
  margin: 4px 0 0;
  font-size: 12px;
  color: #7a8696;
  font-weight: 400;
}

.options {
  margin: 12px 0;
}

.options summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: #364152;
}

button#submit {
  width: 100%;
  margin-top: 8px;
  padding: 11px;
  border: none;
  border-radius: 6px;
  background: #16a34a;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

button#submit:disabled {
  background: #9bbfa9;
  cursor: progress;
}

#status {
  margin-top: 18px;
}

.bar {
  height: 8px;
  background: #e1e6ec;
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  background: #2563eb;
  transition: width 0.25s ease;
}

#status-text {
  margin: 8px 0 4px;
  font-size: 13px;
  color: #364152;
}

#counters {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  gap: 12px;
  font-size: 13px;
  color: #5b6776;
}

#counters span {
  font-weight: 700;
  color: #1c2430;
}

.error {
  margin-top: 14px;
  padding: 10px;
  border-radius: 6px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  font-size: 13px;
}

.note {
  margin-top: 22px;
  font-size: 12px;
  color: #94732a;
  background: #fefce8;
  border: 1px solid #fde68a;
  border-radius: 6px;
  padding: 8px 10px;
}

.hidden {
  display: none;
}

/* --- Mobile: controls collapse into a panel over a full-screen map -------- */
@media (max-width: 768px) {
  body {
    flex-direction: column;
    height: 100vh; /* fallback for browsers without dynamic-viewport units */
    height: 100dvh;
  }

  #sidebar {
    width: 100%;
    flex: 0 0 auto;
    max-height: 58vh;
    max-height: 58dvh;
    padding: 14px 16px;
    border-right: none;
    border-bottom: 1px solid #e1e6ec;
  }

  #map {
    flex: 1 1 auto;
    height: auto;
    min-height: 35vh; /* fallback for browsers without dynamic-viewport units */
    min-height: 35dvh;
  }

  #panel-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border: 1px solid #cdd5df;
    border-radius: 6px;
    background: #fff;
    color: #364152;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.2s ease;
  }

  /* Collapsed: hand the whole viewport to the map, keeping only the header. */
  body.panel-collapsed #sidebar {
    max-height: none;
    overflow: visible;
  }

  body.panel-collapsed #sidebar > :not(.panel-header) {
    display: none;
  }

  body.panel-collapsed #panel-toggle {
    transform: rotate(180deg);
  }

  /* 16px text stops iOS Safari from auto-zooming when an input gains focus. */
  input {
    font-size: 16px;
  }

  .mode-btn {
    min-height: 44px;
    padding: 10px;
  }

  /* Enlarge the Options disclosure's hit area for touch. */
  .options summary {
    padding: 10px 0;
  }
}
