* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #222;
  background-color: #f4f6f8;
  line-height: 1.5;
}

header {
  background-color: #1a365d;
  color: #fff;
  padding: 1.25rem 1.5rem;
  border-bottom: 3px solid #0066cc;
}

header h1 {
  font-size: 1.35rem;
  margin-bottom: 0.35rem;
}

header p {
  font-size: 0.9rem;
  color: #cbd5e0;
}

header p.disclaimer {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 0.78rem;
  color: #fbd38d;
}

.container {
  display: flex;
  flex-direction: column;
  max-width: 1480px;
  margin: 1rem auto;
  padding: 0 1rem;
  gap: 1.25rem;
}

@media (max-width: 479px) {
  .form-row {
    flex-direction: column;
    gap: 0;
  }
}

@media (max-width: 959px) {
  #map {
    min-height: 340px;
  }
}

@media (min-width: 960px) {
  .container {
    flex-direction: row;
    align-items: flex-start;
  }
  .form-section {
    width: 520px;
    flex-shrink: 0;
  }
  .map-section {
    flex-grow: 1;
    position: sticky;
    top: 1rem;
    height: calc(100vh - 5rem);
  }
  .map-hint-mobile {
    display: none;
  }
  .map-hint-desktop {
    display: block;
  }
}

.card {
  background: #fff;
  padding: 1.25rem;
  border: 1px solid #dcdfe4;
  border-radius: 6px;
  margin-bottom: 1.25rem;
  scroll-margin-top: 1rem;
}

.card h2 {
  font-size: 1.05rem;
  color: #1a365d;
  margin-bottom: 0.75rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid #e2e8f0;
}

.form-group {
  margin-bottom: 0.85rem;
}

.form-row {
  display: flex;
  gap: 0.75rem;
}

.form-group.half {
  flex: 1;
}

.combobox-group {
  position: relative;
}

.combobox-list {
  position: absolute;
  z-index: 20;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 0.25rem;
  max-height: 260px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.12);
  list-style: none;
  padding: 0.25rem;
}

.combobox-option {
  padding: 0.6rem 0.65rem;
  border-radius: 4px;
  font-size: 0.9rem;
  color: #2d3748;
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.combobox-option:hover,
.combobox-option.active {
  background: #ebf4ff;
  color: #2b6cb0;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: normal;
  cursor: pointer;
  min-height: 44px;
}

.checkbox-group input[type="checkbox"] {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: #2d3748;
  margin-bottom: 0.25rem;
}

.req {
  color: #e53e3e;
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 0.6rem 0.5rem;
  font-size: 16px;
  border: 1px solid #cbd5e0;
  border-radius: 4px;
  background: #fff;
  font-family: inherit;
}

input[readonly] {
  background-color: #edf2f7;
  color: #4a5568;
}

/* Coordinates are an auto-filled confirmation readout, not the primary
   input in the pin sheet — de-emphasize relative to Category/Notes. */
.pin-coords-row {
  margin-bottom: 0.6rem;
}

.pin-coords-row label {
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #a0aec0;
  margin-bottom: 0.15rem;
}

.pin-coords-row input[readonly] {
  font-size: 0.8rem;
  padding: 0.35rem 0.5rem;
  border-style: dashed;
  color: #718096;
  background-color: transparent;
  /* Purely an auto-filled confirmation readout — not meant to be tapped,
     so keep it out of the tab/focus path (avoids iOS zoom-on-focus too). */
  pointer-events: none;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #3182ce;
  box-shadow: 0 0 0 2px rgba(49, 130, 206, 0.2);
}

.help-text {
  font-size: 0.8rem;
  color: #718096;
  margin-bottom: 0.75rem;
}

.prompt-text {
  font-size: 0.85rem;
  color: #718096;
  padding: 0.5rem 0;
}

.role-question-set {
  padding-top: 0.5rem;
  scroll-margin-top: 1rem;
}

.map-hint-desktop {
  display: none;
}

.pin-entry-box {
  background-color: #f7fafc;
  border: 1px dashed #cbd5e0;
  border-radius: 6px;
  padding: 0.85rem;
  margin-bottom: 1rem;
  color: inherit;
  /* Override the UA default of position:absolute;inset:0;margin:auto so a
     non-modal <dialog> (desktop, forced open) sits inline in normal flow. */
  position: static;
  inset: auto;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
}

dialog#pinModal:not([open]) {
  display: none;
}

.pin-modal-handle {
  display: none;
}

.pin-modal-header {
  display: none;
}

@media (max-width: 959px) {
  dialog#pinModal[open] {
    position: fixed;
    inset: auto 0 0 0;
    margin: 0;
    width: 100%;
    max-width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    border: none;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 24px rgba(15, 23, 42, 0.25);
    animation: pinSheetUp 0.22s ease-out;
  }

  dialog#pinModal::backdrop {
    background: rgba(15, 23, 42, 0.45);
  }

  .pin-modal-handle {
    display: block;
    width: 36px;
    height: 4px;
    background: #cbd5e0;
    border-radius: 2px;
    margin: 0 auto 0.75rem;
  }

  .pin-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
  }

  .pin-modal-header strong {
    font-size: 0.95rem;
    color: #1a365d;
  }

  .pin-modal-close {
    background: #edf2f7;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
    color: #4a5568;
    cursor: pointer;
  }
}

@keyframes pinSheetUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.secondary-btn {
  width: 100%;
  background-color: #319795;
  color: #fff;
  border: none;
  padding: 0.6rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
}

.secondary-btn:hover {
  background-color: #285e61;
}

.pin-inventory-header {
  font-size: 0.85rem;
  color: #2d3748;
  margin-bottom: 0.5rem;
}

.pin-list-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 240px;
  overflow-y: auto;
}

.pin-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  background: #edf2f7;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  font-size: 0.82rem;
  border-left: 4px solid #3182ce;
  cursor: pointer;
}

.pin-item:hover {
  background: #e2e8f0;
}

.pin-item.hazard { border-left-color: #e53e3e; }
.pin-item.queue { border-left-color: #dd6b20; }
.pin-item.hub { border-left-color: #38a169; }

.pin-item-info {
  flex-grow: 1;
  margin-right: 0.5rem;
}

.pin-item-category {
  font-weight: bold;
  color: #1a202c;
}

.pin-item-coords {
  font-size: 0.75rem;
  color: #718096;
}

.pin-item-notes {
  margin-top: 0.15rem;
  color: #4a5568;
}

.pin-item-actions button {
  background: transparent;
  border: 1px solid #cbd5e0;
  color: #e53e3e;
  padding: 0.15rem 0.4rem;
  font-size: 0.75rem;
  border-radius: 3px;
  cursor: pointer;
}

.pin-item-actions button:hover {
  background: #fed7d7;
}

.empty-pins-msg {
  font-size: 0.8rem;
  color: #a0aec0;
  font-style: italic;
  padding: 0.5rem 0;
}

button[type="submit"] {
  width: 100%;
  background-color: #2b6cb0;
  color: #fff;
  border: none;
  padding: 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  margin-top: 0.75rem;
}

button[type="submit"]:hover {
  background-color: #2c5282;
}

.status-box {
  display: none;
  margin-top: 0.75rem;
  padding: 0.6rem;
  border-radius: 4px;
  font-size: 0.85rem;
}

.status-box.success {
  display: block;
  background: #c6f6d5;
  color: #22543d;
  border: 1px solid #9ae6b4;
}

.status-box.error {
  display: block;
  background: #fed7d7;
  color: #742a2a;
  border: 1px solid #feb2b2;
}

.map-section {
  display: flex;
  flex-direction: column;
  min-height: 540px;
  scroll-margin-top: 1rem;
}

/* Map Toolbar & Visual Mark Legend */
.map-toolbar {
  background: #fff;
  padding: 0.75rem 0.85rem;
  border: 1px solid #dcdfe4;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.map-toolbar-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 0.85rem;
  color: #1a365d;
  cursor: pointer;
  list-style: none;
  min-height: 44px;
}

.map-toolbar-summary::-webkit-details-marker {
  display: none;
}

.summary-caret {
  transition: transform 0.15s ease;
  color: #718096;
}

.map-toolbar[open] .summary-caret {
  transform: rotate(180deg);
}

@media (min-width: 960px) {
  .map-toolbar-summary {
    display: none;
  }
}

.basemap-selector-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.basemap-selector-row select {
  flex-grow: 1;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
}

.map-legend {
  padding-top: 0.45rem;
  border-top: 1px solid #edf2f7;
}

.legend-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
}

.boundary-row-header {
  margin-top: 0.5rem;
  padding-top: 0.35rem;
  border-top: 1px dashed #e2e8f0;
}

.legend-title {
  font-size: 0.8rem;
  color: #2d3748;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.legend-hint {
  font-size: 0.72rem;
  color: #718096;
}

.legend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.5rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  background: #f7fafc;
  padding: 0.45rem 0.6rem;
  border: 1px solid #e2e8f0;
  border-radius: 5px;
  cursor: pointer;
  user-select: none;
  min-height: 44px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.legend-item:hover {
  background: #edf2f7;
  border-color: #cbd5e0;
}

.legend-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  cursor: pointer;
}

.legend-item.static-legend {
  cursor: default;
  background: #fff;
}

.legend-label {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  line-height: 1.25;
}

.legend-label small {
  font-size: 0.7rem;
  color: #718096;
}

/* Pixel-Matched Marks */
.mark-preview {
  display: inline-block;
  flex-shrink: 0;
}

/* MS Polygon Mark */
.ms-mark {
  width: 20px;
  height: 20px;
  background-color: rgba(49, 130, 206, 0.2);
  border: 2px solid #2b6cb0;
  border-radius: 3px;
}

/* HS Dashed Polygon Mark */
.hs-mark {
  width: 20px;
  height: 20px;
  background-color: rgba(229, 62, 62, 0.2);
  border: 2px dashed #c53030;
  border-radius: 3px;
}

/* Hub Stop CircleMarker Mark */
.hub-mark {
  width: 14px;
  height: 14px;
  background-color: #38a169;
  border: 2px solid #276749;
  border-radius: 50%;
  margin: 3px;
}

/* NCC County Boundary Mark */
.ncc-mark {
  width: 20px;
  height: 20px;
  background-color: rgba(107, 70, 193, 0.08);
  border: 2px solid #6b46c1;
  border-radius: 3px;
}

/* State of DE Boundary Mark */
.state-mark {
  width: 20px;
  height: 20px;
  background-color: rgba(45, 55, 72, 0.06);
  border: 2px solid #2d3748;
  border-radius: 3px;
}

/* Observation Pin Marks */
.pin-marks-group {
  display: flex;
  gap: 3px;
  align-items: center;
}

.pin-mark {
  width: 10px;
  height: 10px;
  border: 1.5px solid #ffffff;
  box-shadow: 0 0 0 1px #a0aec0;
  border-radius: 50%;
}

.pin-mark.red { background-color: #e53e3e; }
.pin-mark.orange { background-color: #dd6b20; }
.pin-mark.green { background-color: #38a169; }

.legend-item.dimmed .mark-preview {
  opacity: 0.25;
}

.legend-item.dimmed .legend-label {
  color: #a0aec0;
}

#map {
  flex-grow: 1;
  min-height: 520px;
  border: 1px solid #dcdfe4;
  border-radius: 0 0 6px 6px;
  background-color: #e5e9ec;
}

footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.8rem;
  color: #718096;
}
