:root {
  --green: #2e9e4f;
  --amber: #e8a33d;
  --red: #d64545;
  --closed: #5f6368;
  --unknown: #9aa0a6;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1f2328;
  --muted: #6b7280;
  --border: #e3e6ea;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
header h1 { font-size: 1.15rem; margin: 0; }

.legend { display: flex; gap: 0.4rem; }
.chip {
  font-size: 0.72rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  color: #fff;
  white-space: nowrap;
}
.chip.green { background: var(--green); }
.chip.amber { background: var(--amber); }
.chip.red { background: var(--red); }
.chip.closed { background: var(--closed); }

.locate-btn {
  font-size: 0.8rem;
  padding: 0.35rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #1a56db;
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.locate-btn:hover { background: #164bc0; }
.locate-btn:disabled { opacity: 0.6; cursor: default; }

.locate-status { font-size: 0.75rem; color: var(--muted); }

.nearest-badge {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #1a56db;
  background: rgba(26, 86, 219, 0.12);
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  margin-left: 0.35rem;
  vertical-align: middle;
}

.status { margin-left: auto; font-size: 0.8rem; color: var(--muted); }

main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 360px;
  min-height: 0;
}

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

#sidebar {
  background: var(--panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 1rem;
}
#sidebar h2 { font-size: 0.95rem; margin: 0.5rem 0; }

#library-list { list-style: none; margin: 0; padding: 0; }
.lib-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.4rem;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.lib-item:hover { background: var(--bg); }
.lib-item.active { border-color: var(--border); background: var(--bg); }

.dot {
  width: 12px; height: 12px; border-radius: 50%;
  flex: 0 0 auto;
}
.dot.green { background: var(--green); }
.dot.amber { background: var(--amber); }
.dot.red { background: var(--red); }
.dot.closed { background: var(--closed); }
.dot.unknown { background: var(--unknown); }

.lib-meta { flex: 1; min-width: 0; }
.lib-name { font-size: 0.85rem; font-weight: 600; }
.lib-sub { font-size: 0.75rem; color: var(--muted); }

.bar {
  height: 6px;
  border-radius: 999px;
  background: #eceef1;
  margin-top: 4px;
  overflow: hidden;
}
.bar > span { display: block; height: 100%; }
.bar.green > span { background: var(--green); }
.bar.amber > span { background: var(--amber); }
.bar.red > span { background: var(--red); }

.muted { color: var(--muted); font-size: 0.78rem; }

/* Busyness graph modal overlay */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.overlay[hidden] { display: none; }

.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.overlay-dialog {
  position: relative;
  z-index: 1;
  width: min(640px, 100%);
  background: var(--panel);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  padding: 1.25rem 1.5rem 1rem;
}
.overlay-dialog h2 { margin: 0 2rem 0.75rem 0; font-size: 1rem; }
.overlay-dialog canvas { width: 100% !important; }

.overlay-close {
  position: absolute;
  top: 0.6rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0.1rem 0.3rem;
  border-radius: 6px;
}
.overlay-close:hover { background: var(--bg); color: var(--ink); }

footer {
  padding: 0.5rem 1rem;
  background: var(--panel);
  border-top: 1px solid var(--border);
}
footer p { margin: 0; }

/* Map markers (HTML elements placed by Mapbox GL) */
.lib-marker {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2.5px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  padding: 0;
  transition: width 0.15s, height 0.15s, border-width 0.15s;
}
/* Zoomed in, when the library's building is coloured instead */
.lib-marker.small {
  width: 10px;
  height: 10px;
  border-width: 2px;
}
.user-marker {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #1a56db;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px rgba(26, 86, 219, 0.35);
}

/* Shown in place of the map when no Mapbox token is configured */
.map-message {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 1.5rem;
  text-align: center;
  color: var(--muted);
}

/* Popup content */
.mapboxgl-popup-content { padding: 0.75rem 1rem; border-radius: 8px; }
.popup-title { font-weight: 700; margin-bottom: 0.25rem; }
.popup-stat { font-size: 0.85rem; margin: 0.15rem 0; }
.popup-actions { margin-top: 0.5rem; display: flex; gap: 0.5rem; }
.popup-actions a {
  font-size: 0.78rem;
  text-decoration: none;
  color: #1a56db;
}

@media (max-width: 820px) {
  main { grid-template-columns: 1fr; grid-template-rows: 55% 45%; }
  #sidebar { border-left: none; border-top: 1px solid var(--border); }
}
