:root {
  --bg: #0f1115;
  --panel: #171a21;
  --border: #2a2e38;
  --text: #e7e9ee;
  --muted: #9aa1ad;
  --accent: #4f8cff;
  --input-bg: #0d0f14;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden {
  display: none !important;
}

.overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-card h1 {
  font-size: 1.2rem;
  margin: 0;
}

.login-card p {
  color: var(--muted);
  margin: 0;
  font-size: 0.9rem;
}

.login-card input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 1rem;
}

.login-card button {
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 1rem;
  cursor: pointer;
}

.error {
  color: #ff6b6b;
  font-size: 0.85rem;
  min-height: 1.2em;
}

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.sidebar h1 {
  font-size: 1.05rem;
  margin: 0 0 4px 0;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-group label {
  font-size: 0.8rem;
  color: var(--muted);
}

.filter-group select {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.9rem;
}

.legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--muted);
}

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

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--muted);
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0;
}

.secondary-btn {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

.secondary-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.sidebar-toggle {
  display: none;
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1200;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

.map-wrap {
  position: relative;
}

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

.map-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 17, 21, 0.35);
  z-index: 550;
  pointer-events: none;
}

.spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.error-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 600;
  background: #3a1f22;
  border: 1px solid #ff6b6b;
  color: #ffd4d4;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 90%;
}

.error-banner .link-btn {
  color: #ffd4d4;
  text-decoration: underline;
  flex-shrink: 0;
}

.empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 400;
  color: var(--muted);
  font-size: 0.95rem;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 8px;
  pointer-events: none;
}

.detail-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 340px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 20px;
  overflow-y: auto;
  z-index: 500;
}

.close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  font-size: 1rem;
}

.detail-panel h2 {
  margin: 0 24px 4px 0;
  font-size: 1.1rem;
}

.detail-panel .muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.detail-row {
  margin-top: 14px;
  font-size: 0.9rem;
}

.detail-row .label {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: block;
  margin-bottom: 2px;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.photo-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.history-item {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: 8px;
  font-size: 0.82rem;
}

.history-item .when {
  color: var(--muted);
  font-size: 0.75rem;
}

.maps-link {
  display: inline-block;
  margin-top: 14px;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --panel: #ffffff;
    --border: #e1e4ea;
    --text: #1a1d23;
    --muted: #666d7a;
    --input-bg: #f0f1f4;
  }
}

@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar-toggle {
    display: block;
  }

  .sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 85%;
    max-width: 300px;
    /* Above Leaflet's default control pane z-index (1000) so the sidebar isn't
       poked through by the zoom control when both are visible. */
    z-index: 1200;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.35);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .map-wrap {
    grid-column: 1;
  }

  .detail-panel {
    width: 100%;
    max-width: none;
  }
}
