/* BinPin — app.css (light theme, green accent, dark mode via prefers-color-scheme) */

:root {
  --accent: #3fa34d;
  --accent-strong: #2f8340;
  --accent-soft: #e6f4e9;
  --danger: #d14545;
  --danger-soft: #fbeaea;
  --info: #2e7dd1;
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-2: #f0f2f0;
  --text: #1e2a20;
  --muted: #64716a;
  --border: #dbe2dc;
  --shadow: 0 4px 18px rgba(20, 40, 25, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #4fbf60;
    --accent-strong: #3fa34d;
    --accent-soft: #1d3323;
    --danger: #e06666;
    --danger-soft: #3a2222;
    --bg: #141815;
    --surface: #1d231e;
    --surface-2: #262d27;
    --text: #e6ece7;
    --muted: #98a59c;
    --border: #333c35;
    --shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }
/* Author display rules (e.g. .menu { display: flex }) override the UA's [hidden] style;
   this guard keeps the hidden attribute authoritative everywhere. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

/* ------------------------------------------------------------ top bar */

.topbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.06);
  position: relative;
  z-index: 1100;
}
/* Identity on the first row, tools on the second. Pages without tools use one row. */
.topbar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.topbar-tools { border-top: 1px solid var(--border); padding-top: 8px; }
.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  white-space: nowrap;
}
.brand-name { font-size: 1.15rem; font-weight: 700; }
/* Brand mark reuses favicon.svg, so the logo has one source of truth. The
   pin sits inside its square viewBox with side bearing, hence the height
   slightly over 1em to optically match the wordmark. */
.brand-mark {
  height: 1.3em;
  width: auto;
  vertical-align: -0.24em;
  margin-right: 1px;
}
.tagline { font-size: 0.78rem; color: var(--muted); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* city search */
.search-box { position: relative; }
.search-input {
  width: 200px;
  padding: 6px 10px;
}
.search-results {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  min-width: 240px;
  max-height: 320px;
  overflow-y: auto;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 1200;
}
.search-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.search-item:hover,
.search-item.active { background: var(--surface-2); }
.search-item-name { font-weight: 600; }
.search-item-context { font-size: 0.8rem; color: var(--muted); }
@media (max-width: 640px) {
  .search-input { width: 100%; }
  .search-box { width: 100%; }
}

/* filter chips */
.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}
.chip:not(.active) .chip-dot { opacity: 0.35; }
.chip-dot {
  width: 11px; height: 11px;
  border-radius: 50%;
  display: inline-block;
  flex: none;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}
.chip-bg { font-weight: 600; }
.chip-en { font-size: 0.72rem; color: var(--muted); }
.chip-retry { color: var(--danger); border-color: var(--danger); }

/* ------------------------------------------------------------ buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent-strong); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.92); background: var(--danger); }
.btn-danger-outline { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger-outline:hover { background: var(--danger-soft); }
.btn-block { width: 100%; }
.btn-small { padding: 4px 10px; font-size: 0.8rem; }
.btn.armed { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; box-shadow: 0 0 0 3px var(--accent-soft); }

/* busy spinner */
.busy { position: relative; color: transparent !important; }
.busy::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px; height: 14px;
  border: 2px solid rgba(128, 128, 128, 0.4);
  border-top-color: currentcolor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  color: var(--text);
}
.btn-primary.busy::after, .btn-danger.busy::after { color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.linklike {
  border: none;
  background: none;
  color: var(--accent-strong);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

/* ------------------------------------------------------------ user menu */

/* The score sits outside the button, to the left of the avatar. */
.user-menu { position: relative; display: flex; align-items: center; gap: 8px; }
/* Avatar-only trigger: no label, no caret — the name lives in the menu it opens. */
.user-btn {
  padding: 0;
  border-radius: 50%;
  border: none;
  background: none;
  line-height: 0;
}
.user-btn:hover { background: none; }
.user-btn:hover .user-avatar { background: var(--accent-strong); }
.user-btn:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 700;
  flex: none;
}
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 1200;
  display: flex;
  flex-direction: column;
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
}
.menu-head { display: flex; flex-direction: column; gap: 1px; padding: 6px 10px 8px; }
.menu-head-name { font-weight: 700; font-size: 0.9rem; }
.menu-head-email { font-size: 0.78rem; color: var(--muted); overflow-wrap: anywhere; }
.menu-item:hover { background: var(--surface-2); }
.menu-item-danger { color: var(--danger); }
.menu-sep { height: 1px; background: var(--border); margin: 4px 6px; }

/* ------------------------------------------------------------ map page */

main.map-main { flex: 1; position: relative; min-height: 0; }
#map { position: absolute; inset: 0; }
#map.adding { cursor: crosshair; }

.map-pill {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  max-width: min(92vw, 480px);
  text-align: center;
}

/* bin markers */
.binpin-dot-wrap { background: none; border: none; }
.binpin-dot {
  display: block;
  width: 100%; height: 100%;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}
.binpin-dot.dot-pending { opacity: 0.55; border: 2px dashed #444; }
.binpin-dot.dot-flagged { opacity: 0.7; border: 2px dashed var(--danger); }
.binpin-dot.dot-draft {
  background: var(--accent);
  border: 2px solid #fff;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(63, 163, 77, 0.55); }
  50% { box-shadow: 0 0 0 9px rgba(63, 163, 77, 0); }
}

/* popup */
.leaflet-popup-content-wrapper { border-radius: var(--radius); }
.binpin-popup .leaflet-popup-content { margin: 14px 16px; font-family: var(--font); }
.popup { display: flex; flex-direction: column; gap: 8px; min-width: 210px; }
.popup-title { font-weight: 700; font-size: 0.98rem; }
.popup-district { color: #667; font-size: 0.8rem; margin-top: -6px; }
.popup-badges { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.badge {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  color: #fff;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 0.74rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
.badge b { font-size: 0.8rem; }
.badge-small { padding: 1px 8px; margin: 1px 2px 1px 0; }
.status {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.status-verified { background: #e6f4e9; color: #2f8340; }
.status-pending { background: #fdf3d7; color: #8a6d1a; }
.status-flagged, .status-rejected { background: #fbeaea; color: #b73535; }
.status-approved { background: #e6f4e9; color: #2f8340; }
.popup-votes { font-size: 0.85rem; display: flex; gap: 6px; }
.vote-yes { color: #2f8340; font-weight: 600; }
.vote-no { color: #b73535; font-weight: 600; }
.vote-sep { color: #999; }
.popup-note { font-style: italic; font-size: 0.85rem; color: #555; background: #f5f7f5; border-radius: 6px; padding: 6px 8px; }
.popup-byline { font-size: 0.76rem; color: #778; }
.popup-login { font-size: 0.83rem; color: #556; }
/* Shown in place of the vote buttons when the user is outside the confirm radius. */
.popup-too-far {
  font-size: 0.83rem;
  color: #8a6100;
  background: #fdf4e0;
  border: 1px solid #f0d79a;
  border-radius: 6px;
  padding: 6px 8px;
}
.popup-actions { display: flex; gap: 8px; }
.btn-vote { flex: 1; font-size: 0.85rem; padding: 6px 8px; }
.btn-yes { background: #e6f4e9; border-color: #3fa34d; color: #2f8340; }
.btn-yes:hover { background: #d6ecdb; }
.btn-no { background: #fbeaea; border-color: #d14545; color: #b73535; }
.btn-no:hover { background: #f6dcdc; }

/* ------------------------------------------------------------ cards & forms */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card-head, .section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.card-title { margin: 0; font-size: 1.05rem; }
.muted { color: var(--muted); font-size: 0.85rem; margin: 4px 0; }

.add-card {
  position: fixed;
  left: 16px;
  bottom: 44px;
  z-index: 1150;
  width: min(360px, calc(100vw - 32px));
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.form { display: flex; flex-direction: column; gap: 12px; }
.form-row { display: flex; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.input {
  font: inherit;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
textarea.input { resize: vertical; }
.form-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 0.85rem;
}

.type-checks { display: flex; flex-direction: column; gap: 4px; }
.type-check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
}
.type-check:hover { background: var(--surface-2); }
.type-check input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ------------------------------------------------------------ modal */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 25, 18, 0.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: min(400px, 100%);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 20px;
  outline: none;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-title { margin: 0; font-size: 1.15rem; }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; background: var(--surface-2); border-radius: var(--radius-sm); padding: 4px; }
.tab {
  flex: 1;
  border: none;
  background: none;
  font: inherit;
  font-weight: 600;
  padding: 7px 0;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
}
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

.account-info { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0 0 16px; font-size: 0.92rem; }
.account-info dt { color: var(--muted); }
.account-info dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.danger-zone {
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.danger-title { margin: 0; font-size: 0.9rem; color: var(--danger); }

/* ------------------------------------------------------------ toasts */

.toasts {
  position: fixed;
  bottom: 48px;
  right: 16px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(340px, calc(100vw - 32px));
}
.toast {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--info);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 10px 14px;
  font-size: 0.88rem;
  cursor: pointer;
  animation: toast-in 0.25s ease-out;
}
.toast-success { border-left-color: var(--accent); }
.toast-error { border-left-color: var(--danger); }
.toast-out { opacity: 0; transform: translateY(6px); transition: opacity 0.3s, transform 0.3s; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ------------------------------------------------------------ footer */

.footer {
  padding: 5px 14px;
  font-size: 0.74rem;
  color: var(--muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
  text-align: center;
  position: relative;
  z-index: 1100;
}

/* ------------------------------------------------------------ admin page */

.admin-main {
  flex: 1;
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 20px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.guard-card { text-align: center; max-width: 380px; margin: 60px auto; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.section-body { min-height: 40px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { color: var(--muted); font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em; }
.table tr:last-child td { border-bottom: none; }
.row-pending { background: color-mix(in srgb, var(--accent-soft) 55%, transparent); }
.cell-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.cell-votes { white-space: nowrap; }
.empty { text-align: center; padding: 14px 0; }

.import-stats { display: flex; gap: 14px; margin: 12px 0; flex-wrap: wrap; }
.stat {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.stat b { font-size: 1.3rem; color: var(--accent-strong); }
.stat span { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.import-errors summary { cursor: pointer; color: var(--danger); font-weight: 600; font-size: 0.88rem; }
.import-errors ul { font-size: 0.84rem; color: var(--muted); }

/* ------------------------------------------------------------ points & badges */

.points-pill {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.points-pill:hover,
.points-pill:focus-visible {
  background: var(--accent-strong);
  color: #fff;
}

.badge-chips { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.badge-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.76rem;
  font-weight: 600;
  white-space: nowrap;
}
/* Icon-only variant for dense rows, where the name lives in the tooltip. */
.badge-chip-icon { padding: 2px 6px; font-size: 0.9rem; }

/* leaderboard */
.leaderboard-table .num { text-align: right; }
.leaderboard-table .rank { width: 3rem; font-size: 1rem; font-variant-numeric: tabular-nums; }
.leaderboard-table .points { font-weight: 700; color: var(--accent-strong); white-space: nowrap; }
.leaderboard-table .is-me { background: color-mix(in srgb, var(--accent-soft) 55%, transparent); }
.leaderboard-table .is-me td { font-weight: 600; }

.badge-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}
.badge-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  /* Unearned badges read as goals rather than achievements. */
  opacity: 0.55;
}
.badge-card.earned { opacity: 1; background: var(--surface); border-color: var(--accent); }
.badge-card-icon { font-size: 1.5rem; line-height: 1; }
.badge-card-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.badge-card-text .muted { margin: 0; font-size: 0.78rem; }
.badge-card-tick { margin-left: auto; color: var(--accent-strong); font-weight: 700; }

/* ------------------------------------------------------------ responsive */

@media (max-width: 720px) {
  .topbar { padding: 6px 10px; gap: 8px; }
  .tagline { display: none; }
  /* Chips take their own line and scroll sideways rather than stacking. */
  .chips { width: 100%; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }
  .chip { flex: none; }
  .chip-en { display: none; }
  .btn { font-size: 0.84rem; padding: 6px 10px; }
  .add-card {
    left: 8px;
    right: 8px;
    bottom: 34px;
    width: auto;
  }
  .toasts { bottom: 40px; left: 16px; right: 16px; max-width: none; }
}
