:root {
  --ink: #1b1f24;
  --muted: #6b7280;
  --border: #e2e5e9;
  --bg: #f7f8fa;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --neutral-claimed: #4b5563;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body, #app {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

#app {
  display: flex;
  flex-direction: column;
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  z-index: 1000;
}

#topbar-left { display: flex; align-items: center; gap: 10px; }
#topbar h1 { font-size: 16px; margin: 0; font-weight: 700; }
.cycle-badge {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
}
#topbar-right { display: flex; align-items: center; gap: 12px; font-size: 14px; }

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

.hidden { display: none !important; }

.ghost-btn, .link-btn, .primary-btn, .secondary-btn, .danger-btn {
  font-family: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 14px;
  padding: 8px 14px;
}

.ghost-btn {
  background: #fff;
  border-color: var(--border);
  color: var(--ink);
}
.ghost-btn.small { padding: 4px 8px; font-size: 13px; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  font-size: 13px;
  text-decoration: underline;
}

.primary-btn {
  background: var(--accent);
  color: #fff;
  width: 100%;
  margin-top: 14px;
  font-weight: 600;
}
.primary-btn:hover { background: var(--accent-dark); }

.secondary-btn {
  background: #eef2ff;
  color: var(--accent-dark);
  width: 100%;
  margin-top: 10px;
  font-weight: 600;
}

.danger-btn {
  background: #fee2e2;
  color: var(--danger-dark);
  width: 100%;
  margin-top: 14px;
  font-weight: 600;
}
.danger-btn:hover { background: #fecaca; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 22, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  width: 90%;
  max-width: 360px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.modal h2 { margin-top: 0; font-size: 18px; }
.muted { color: var(--muted); font-size: 13px; }
.muted.small { font-size: 12px; margin-top: 4px; }

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-top: 12px;
  margin-bottom: 4px;
}

input[type="text"], input[type="tel"], input[type="file"] {
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 14px;
  font-family: inherit;
}

.error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 10px;
}

.result-box {
  margin-top: 10px;
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  white-space: pre-wrap;
  max-height: 160px;
  overflow-y: auto;
}

/* Side panel (admin) */
.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 340px;
  max-width: 92vw;
  background: #fff;
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(0,0,0,0.08);
  z-index: 1500;
  overflow-y: auto;
  padding: 16px;
}
.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.side-panel-header h2 { margin: 0; font-size: 16px; }

details {
  border-top: 1px solid var(--border);
  padding: 10px 0;
}
summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}

/* Address search */
#address-search.panel {
  position: fixed;
  top: 68px;
  right: 12px;
  z-index: 900;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.08);
  width: 280px;
  max-width: calc(100vw - 24px);
}
#address-search-row { display: flex; gap: 6px; }
#address-search-row input[type="text"] { flex: 1; padding: 7px 9px; }
#address-search-row button { padding: 6px 9px; flex: none; }
#address-search-results {
  margin-top: 6px;
  max-height: 220px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
}
.address-result-row {
  padding: 8px 4px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.address-result-row:last-child { border-bottom: none; }
.address-result-row:hover { background: var(--bg); }
.address-result-empty {
  padding: 8px 4px;
  font-size: 13px;
  color: var(--muted);
}
.search-marker {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px var(--accent), 0 2px 6px rgba(0,0,0,0.45);
}

/* Legend */
#legend.panel {
  position: fixed;
  left: 12px;
  bottom: 20px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  z-index: 900;
  box-shadow: 0 4px 14px rgba(0,0,0,0.08);
  max-width: 240px;
}
#legend .legend-title { font-weight: 700; margin-bottom: 6px; }
#legend .legend-row { display: flex; align-items: center; gap: 8px; margin: 3px 0; cursor: pointer; }
#legend .legend-swatch { width: 12px; height: 12px; border-radius: 50%; flex: none; }
#legend .legend-row.dimmed { opacity: 0.35; }

/* Map label styles */
.sa1-label {
  background: transparent;
  border: none;
  box-shadow: none;
  font-weight: 700;
  font-size: 11px;
  color: #1b1f24;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff;
  white-space: nowrap;
}
.sa1-label.mine { font-size: 13px; }
.nickname-label {
  background: transparent;
  border: none;
  box-shadow: none;
  font-size: 10px;
  color: #111;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff;
  white-space: nowrap;
}

.leaflet-popup-content { font-size: 13px; min-width: 180px; }
.leaflet-popup-content h3 { margin: 0; font-size: 14px; }
.popup-header-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}
.popup-map-link {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
  flex: none;
}
.popup-map-link:hover { text-decoration: underline; }
.popup-row { margin: 2px 0; color: var(--muted); }
.popup-actions { margin-top: 10px; display: flex; gap: 6px; }
.popup-actions button {
  flex: 1;
  padding: 6px 8px;
  font-size: 13px;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: pointer;
}
.popup-actions .reserve-btn { background: var(--accent); color: #fff; border-color: var(--accent); }
.popup-actions .release-btn { background: #fee2e2; color: var(--danger-dark); border-color: #fecaca; }

.cp-marker {
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

@media (max-width: 640px) {
  #topbar h1 { display: none; }
  #legend.panel { max-width: 70vw; }
}
