* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: Arial, Helvetica, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
  width: 100%;
}

.controls {
  border-right: 1px solid #d9d9d9;
  padding: 1rem;
  overflow: hidden;
  background: #fafafa;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.controls h1 {
  margin: 0 0 0.25rem;
  font-size: 1.2rem;
}

.subtitle {
  margin: 0 0 1rem;
  color: #555;
  font-size: 0.95rem;
}

.control-group {
  margin-bottom: 0;
}

.control-group label {
  display: block;
  margin-bottom: 0.4rem;
  font-weight: 600;
}

#pin-filter-select {
  border-color: #9ab7d9;
  background: #f7fbff;
}

#school-search-btn {
  min-width: 72px;
}

.inline-controls {
  display: flex;
  gap: 0.5rem;
}

input[type="text"],
select,
button {
  border: 1px solid #bdbdbd;
  border-radius: 6px;
  font-size: 0.92rem;
}

input[type="text"],
select {
  width: 100%;
  padding: 0.5rem 0.6rem;
}

button {
  padding: 0.5rem 0.7rem;
  cursor: pointer;
  background: #fff;
}

button:hover {
  background: #f0f0f0;
}

#status-message {
  margin: 0;
  font-size: 0.9rem;
  color: #333;
}

.legend-group {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #ffffff;
  padding: 0.55rem 0.6rem;
}

.legend-title {
  margin: 0 0 0.35rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: #2f3b47;
}

.marker-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.84rem;
  color: #2f3b47;
}

.marker-legend li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.legend-dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  display: inline-block;
}

.legend-dot-no-issue {
  background: #2a9d8f;
  border: 1px solid #0f5d53;
}

.legend-dot-issue {
  background: #d7263d;
  border: 1px solid #8a1222;
}

.nearby-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
}

.nearby-section h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.nearby-summary {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: #3d4a57;
  background: #edf4fb;
  border: 1px solid #d0e2f5;
  border-radius: 6px;
  padding: 0.45rem 0.55rem;
}

.nearby-list-scroll {
  min-height: 0;
  overflow-y: auto;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 0.5rem;
  background: #fdfdfd;
}

.utility-links {
  margin-top: 0.25rem;
  padding-top: 0.75rem;
  border-top: 1px solid #e1e1e1;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.utility-links a,
.utility-links button {
  font-size: 0.9rem;
  color: #0b63c9;
  text-decoration: underline;
  background: transparent;
  border: 0;
  padding: 0;
}

.utility-links button {
  cursor: pointer;
}

.utility-links a:hover,
.utility-links button:hover {
  color: #084a94;
}

#nearby-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#nearby-list li {
  border: 1px solid #e2e2e2;
  background: #fff;
  border-radius: 8px;
  padding: 0.5rem;
}

#nearby-list button {
  width: 100%;
  text-align: left;
  border: 0;
  padding: 0;
  background: transparent;
}

#nearby-list .distance {
  color: #666;
  font-size: 0.85rem;
  margin-top: 0.2rem;
}

.map-section {
  min-width: 0;
}

#map {
  width: 100%;
  height: 100%;
}

.camera-popup-table {
  border-collapse: collapse;
  min-width: 300px;
  max-width: 420px;
}

.camera-popup-table th,
.camera-popup-table td {
  border: 1px solid #d9d9d9;
  padding: 0.35rem 0.45rem;
  font-size: 0.84rem;
  text-align: left;
  vertical-align: top;
}

.camera-popup-table th {
  background: #f5f5f5;
  width: 42%;
}

.camera-popup-table strong {
  color: #8a1222;
}

.popup-actions {
  margin-top: 0.6rem;
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.popup-actions a {
  color: #0b63c9;
  font-size: 0.86rem;
  text-decoration: underline;
}

.popup-actions a:hover {
  color: #084a94;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1200;
}

.modal-overlay.hidden {
  display: none;
}

.modal-card {
  width: min(700px, 100%);
  max-height: calc(100vh - 2rem);
  background: #fff;
  border-radius: 10px;
  border: 1px solid #d9d9d9;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
  overflow: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid #e7e7e7;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.08rem;
}

.modal-header button {
  white-space: nowrap;
}

.modal-body {
  padding: 1rem;
  font-size: 0.95rem;
  line-height: 1.45;
}

.modal-body p {
  margin-top: 0;
}

.modal-body a {
  color: #0b63c9;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid #2375d8;
  outline-offset: 1px;
}

@media (max-width: 900px), (hover: none) and (pointer: coarse) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: 100dvh;
  }

  .controls {
    border-right: 0;
    border-bottom: 1px solid #d9d9d9;
    padding: 0.9rem;
    gap: 0.65rem;
    max-height: 46dvh;
    overflow-y: auto;
  }

  .controls h1 {
    font-size: 1.28rem;
  }

  .subtitle {
    font-size: 1rem;
    margin-bottom: 0.8rem;
  }

  .control-group label {
    font-size: 0.98rem;
  }

  input[type="text"],
  select,
  button {
    font-size: 1rem;
    min-height: 44px;
  }

  #status-message {
    font-size: 0.95rem;
  }

  .nearby-section {
    flex: 0 0 auto;
  }

  .nearby-list-scroll {
    max-height: 30dvh;
  }

  .inline-controls {
    flex-direction: column;
  }

  .modal-card {
    max-height: calc(100vh - 1rem);
  }
}

@media (max-width: 600px) {
  .controls {
    max-height: 52dvh;
  }

  .controls h1 {
    font-size: 1.2rem;
  }

  .nearby-list-scroll {
    max-height: 24dvh;
  }

  .camera-popup-table {
    min-width: 240px;
    max-width: 290px;
  }
}
