:root {
  --green-600: #1f7a3d;
  --green-700: #175c2e;
  --green-50: #eef8f0;
  --red-500: #d9483a;
  --red-50: #fbeae8;
  --amber-500: #d98c1f;
  --amber-50: #fdf3e3;
  --gray-900: #1c2126;
  --gray-700: #40484f;
  --gray-500: #6b7480;
  --gray-300: #d7dce0;
  --gray-100: #f4f6f7;
  --white: #ffffff;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(20, 30, 20, 0.12);
  font-size: 16px;
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

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

body { display: flex; flex-direction: column; }

button, input, select, textarea { font-family: inherit; font-size: 1rem; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 0.65rem 1.25rem;
  background: linear-gradient(135deg, var(--green-700), var(--green-600));
  color: var(--white);
  box-shadow: var(--shadow);
  position: relative;
  z-index: 20;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 0.65rem; }
.brand-icon { font-size: 1.9rem; }
.brand h1 { font-size: 1.15rem; margin: 0; line-height: 1.2; }
.tagline { margin: 0; font-size: 0.78rem; opacity: 0.85; }

.header-actions { display: flex; align-items: center; gap: 0.5rem; }
#admin-badge {
  font-size: 0.75rem;
  background: rgba(255,255,255,0.15);
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
}

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.05s ease;
}
.btn:active { transform: translateY(1px); }
.btn-block { width: 100%; }
.btn-primary { background: var(--green-600); color: var(--white); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--green-50); color: var(--green-700); border: 1px solid var(--green-600); }
.btn-secondary:hover { background: #e0f2e4; }
.btn-ghost { background: rgba(255,255,255,0.14); color: var(--white); border: 1px solid rgba(255,255,255,0.4); }
.btn-ghost:hover { background: rgba(255,255,255,0.22); }
.btn-danger { background: var(--red-50); color: var(--red-500); border: 1px solid var(--red-500); }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  flex: 1;
  min-height: 0;
}

.sidebar {
  background: var(--white);
  border-right: 1px solid var(--gray-300);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-section {
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--gray-100);
}
.sidebar-section h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--gray-700); margin: 0 0 0.6rem; }
.hint { font-size: 0.8rem; color: var(--gray-500); margin: 0 0 0.6rem; }

.sidebar-section label {
  display: block;
  font-size: 0.78rem;
  color: var(--gray-700);
  font-weight: 600;
  margin-bottom: 0.55rem;
}
.sidebar-section select, .sidebar-section input {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  background: var(--white);
}

.stat-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.stat-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--gray-300);
  background: var(--white);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.stat-card:hover { border-color: var(--green-600); box-shadow: var(--shadow); }
.stat-card.active { border-color: var(--green-600); background: var(--green-50); box-shadow: var(--shadow); }
.stat-card-value { font-size: 1.3rem; font-weight: 700; color: var(--gray-900); }
.stat-card-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--gray-500); }
.stat-card-reported .stat-card-value { color: var(--red-500); }
.stat-card-progress .stat-card-value { color: var(--amber-500); }
.stat-card-cleaned .stat-card-value { color: var(--green-700); }

.stat-detail {
  margin-top: 0.7rem;
  padding: 0.6rem 0.7rem;
  background: var(--gray-100);
  border-radius: 8px;
  font-size: 0.78rem;
  color: var(--gray-700);
}
.stat-detail.hidden { display: none; }
.stat-detail h3 { margin: 0 0 0.35rem; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--gray-500); }
.stat-detail-row { display: flex; justify-content: space-between; padding: 0.15rem 0; }
.stat-detail-row + h3 { margin-top: 0.55rem; }

.teams-list { display: flex; flex-direction: column; gap: 0.5rem; }
.team-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
}
.team-row-info { display: flex; flex-direction: column; min-width: 0; }
.team-row-name { font-size: 0.8rem; font-weight: 600; color: var(--gray-900); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-row-count { font-size: 0.7rem; color: var(--gray-500); }
.team-row .btn { font-size: 0.72rem; padding: 0.35rem 0.55rem; white-space: nowrap; text-decoration: none; }
.team-row-empty { font-size: 0.7rem; color: var(--gray-500); }

.list-section { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.report-list { overflow-y: auto; flex: 1; }

.report-card {
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  padding: 0.6rem;
  margin-bottom: 0.6rem;
  cursor: pointer;
  display: flex;
  gap: 0.6rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.report-card:hover { border-color: var(--green-600); box-shadow: var(--shadow); }
.report-card { position: relative; }
.report-card img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; flex-shrink: 0; background: var(--gray-100); }
.report-card-body { min-width: 0; }
.report-card-desc { font-size: 0.82rem; margin: 0 0 0.3rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.report-card-meta { display: flex; gap: 0.35rem; flex-wrap: wrap; align-items: center; }

.count-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--gray-900);
  color: var(--white);
}
.team-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: #e6f0fb;
  color: #1d5ba8;
}

.empty-note { color: var(--gray-500); font-size: 0.85rem; padding: 0.5rem 0; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
}
.badge-reported { background: var(--red-50); color: var(--red-500); }
.badge-in_progress { background: var(--amber-50); color: var(--amber-500); }
.badge-cleaned { background: var(--green-50); color: var(--green-700); }
.badge-low { background: var(--gray-100); color: var(--gray-700); }
.badge-medium { background: var(--amber-50); color: var(--amber-500); }
.badge-high { background: var(--red-50); color: var(--red-500); }

/* ---------- Map ---------- */
.main-content {
  overflow-y: auto;
  background: var(--gray-100);
  padding: 1.25rem;
}
#map {
  width: 100%;
  max-width: 900px;
  height: 420px;
  margin: 0 auto;
  border-radius: 12px;
  box-shadow: var(--shadow);
  cursor: crosshair;
}

.leaflet-popup-content { margin: 0.7rem 0.8rem; min-width: 220px; }
.popup-img { width: 100%; max-height: 150px; object-fit: cover; border-radius: 6px; margin-bottom: 0.5rem; }
.popup-desc { font-size: 0.85rem; margin: 0.3rem 0; }
.popup-meta { font-size: 0.72rem; color: var(--gray-500); margin: 0.2rem 0 0.5rem; }
.popup-badges { display: flex; gap: 0.3rem; margin-bottom: 0.4rem; flex-wrap: wrap; }
.popup-admin { margin-top: 0.5rem; border-top: 1px solid var(--gray-100); padding-top: 0.5rem; display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.popup-admin select, .popup-admin input { flex: 1; min-width: 100px; padding: 0.3rem; border-radius: 6px; border: 1px solid var(--gray-300); }
.popup-admin button { font-size: 0.75rem; padding: 0.3rem 0.5rem; }
.popup-share { margin-top: 0.5rem; font-size: 0.75rem; padding: 0.3rem 0.6rem; }

.popup-gallery { display: flex; gap: 0.35rem; overflow-x: auto; margin-bottom: 0.5rem; }
.popup-gallery img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.popup-submissions { margin: 0.3rem 0; font-size: 0.78rem; }
.popup-submissions summary { cursor: pointer; color: var(--green-700); font-weight: 600; }
.popup-submission-item { padding: 0.4rem 0; border-top: 1px solid var(--gray-100); }
.popup-submission-item:first-child { border-top: none; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 25, 20, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--white);
  border-radius: 12px;
  padding: 1.5rem;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}
.modal-small { max-width: 340px; }
.modal-camera { max-width: 520px; }
.share-options { display: flex; flex-direction: column; gap: 0.55rem; }
.share-options a { text-decoration: none; text-align: center; }
.modal h2 { margin: 0 0 0.3rem; font-size: 1.1rem; }
.modal-coords { font-size: 0.75rem; color: var(--gray-500); margin: 0 0 1rem; }
.modal-close {
  position: absolute;
  top: 0.7rem; right: 0.8rem;
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--gray-500);
  line-height: 1;
}

#report-form label, #admin-form label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 0.85rem;
}
#report-form input[type=text], #report-form input[type=file],
#report-form textarea, #report-form select, #admin-form input {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.5rem;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
}
#report-form textarea { resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }

.image-preview-wrap { margin: 0 0 0.85rem; }
.image-preview-wrap.hidden { display: none; }
#image-preview { width: 100%; max-height: 260px; object-fit: contain; background: #000; border-radius: 8px; display: block; margin-bottom: 0.5rem; }
#take-photo-btn { margin-bottom: 0.85rem; }
#pick-on-map-btn { margin: -0.4rem 0 1rem; }

.camera-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 0.85rem;
}
.camera-viewport video, .camera-viewport canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.camera-viewport canvas.hidden, .camera-viewport video.hidden { display: none; }
.camera-controls { display: flex; flex-direction: column; gap: 0.5rem; }
.camera-controls .hidden { display: none; }

.form-error {
  background: var(--red-50);
  color: var(--red-500);
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  font-size: 0.8rem;
  margin-bottom: 0.85rem;
}
.form-error.hidden { display: none; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--gray-900);
  color: var(--white);
  padding: 0.65rem 1.1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  z-index: 2000;
  box-shadow: var(--shadow);
}
.toast.hidden { display: none; }
.toast.toast-error { background: var(--red-500); }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  /* The map is small now, so there's no reason to carve the viewport into
     fixed panes — let the whole page flow and scroll naturally instead. */
  html, body { overflow: auto; }
  .layout { display: block; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--gray-300); overflow: visible; }
  .main-content { overflow: visible; }
  #map { height: 260px; }
  .topbar { padding: 0.6rem 0.8rem; }
  .brand h1 { font-size: 1rem; }
  .form-row { grid-template-columns: 1fr; }
  .list-section { flex: none; min-height: auto; }
  .report-list { flex: none; overflow-y: visible; }
}

@media (prefers-color-scheme: dark) {
  html, body { background: #14181b; color: #e7ebee; }
  .sidebar, .modal { background: #1c2226; color: #e7ebee; }
  .sidebar-section { border-color: #2a3136; }
  .sidebar-section select, .sidebar-section input,
  #report-form input, #report-form textarea, #report-form select, #admin-form input {
    background: #232a2f; border-color: #333c42; color: #e7ebee;
  }
  .report-card { border-color: #333c42; }
  .empty-note, .hint, .modal-coords { color: #9aa4ab; }
  .main-content { background: #14181b; }
  .stat-card { background: #1c2226; border-color: #333c42; }
  .stat-card.active { background: #1f2e22; border-color: var(--green-600); }
  .stat-card-value { color: #e7ebee; }
  .stat-detail { background: #232a2f; color: #c7cfd4; }
  .popup-submission-item { border-color: #333c42; }
  .team-row { border-color: #333c42; }
  .team-row-name { color: #e7ebee; }
}
