/* ===== Find My Item ===== */
* { box-sizing: border-box; }

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.12);
}

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

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

/* ===== Top bar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 1100;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-icon { font-size: 22px; }
.brand h1 { font-size: 18px; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.auth-user { display: flex; align-items: center; gap: 8px; }
.radius-control { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); }
.radius-control select {
  font: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
.user-name { font-size: 14px; color: var(--text-muted); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Buttons ===== */
.btn {
  font: inherit;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: var(--surface); color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: #eff6ff; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-block { display: block; width: 100%; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ===== Map ===== */
main { flex: 1; position: relative; min-height: 0; }
#map { position: absolute; inset: 0; }

.pick-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}
.pick-banner .btn-ghost { color: #cbd5e1; }
.pick-banner .btn-ghost:hover { color: #fff; }

.legend {
  position: absolute;
  bottom: 24px;
  left: 12px;
  z-index: 1000;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  display: flex;
  gap: 14px;
  font-size: 13px;
  box-shadow: var(--shadow);
}
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; flex-shrink: 0; }
.dot-lost { background: rgba(220, 38, 38, 0.35); border: 1px solid var(--danger); }
.dot-found { background: rgba(22, 163, 74, 0.35); border: 1px solid var(--success); }
.dot-search { background: rgba(37, 99, 235, 0.15); border: 1px solid var(--primary); }
.dot-stale { background: rgba(100, 116, 139, 0.2); border: 1px dashed var(--text-muted); }

.legend-title { font-weight: 700; font-size: 12.5px; margin-bottom: 4px; }
.legend-row { display: flex; align-items: center; gap: 6px; margin: 4px 0; max-width: 260px; line-height: 1.3; }
.legend-swatch { flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; }
.legend-swatch.state-bubble-sample {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 10px; font-weight: 700;
}
.legend-swatch.heat-sample {
  width: 14px; height: 14px; border-radius: 50%;
  background: radial-gradient(circle, #dc2626 0%, #f59e0b 55%, transparent 80%);
}

/* ===== Map overlay controls ===== */
.view-toggle {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1000;
  display: flex;
  gap: 6px;
  background: var(--surface);
  padding: 6px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.view-toggle .btn { padding: 6px 10px; font-size: 13px; }

.center-me-btn {
  position: absolute;
  bottom: 24px;
  right: 12px;
  z-index: 1000;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 18px;
  cursor: pointer;
}
.center-me-btn:hover { background: #f1f5f9; }

/* ===== Filters ===== */
.filter-panel {
  position: absolute;
  top: 58px;
  left: 12px;
  z-index: 1000;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  width: 260px;
  max-width: calc(100vw - 24px);
  max-height: 70vh;
  overflow-y: auto;
}
.filter-section { margin-bottom: 12px; }
.filter-section-title { font-size: 12.5px; font-weight: 700; margin-bottom: 6px; }
.filter-time-row { display: flex; flex-wrap: wrap; gap: 6px; }
.filter-time-row .btn { padding: 5px 9px; font-size: 12px; }
.filter-categories-grid { display: flex; flex-direction: column; gap: 4px; }
.filter-checkbox { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.filter-checkbox input { margin: 0; }

/* Leaflet state-count bubble marker (background/shadow color set inline per-bubble) */
.state-bubble {
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-size: 12.5px;
  text-align: center;
  border: 2px solid #fff;
  transition: transform 0.15s;
}
.state-bubble:hover { transform: scale(1.08); }
.state-bubble-pop { animation: bubblePop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes bubblePop {
  from { transform: scale(0.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ===== Map loading overlay ===== */
.map-loading {
  position: absolute;
  inset: 0;
  z-index: 1500;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  color: var(--text-muted);
  font-size: 14px;
  transition: opacity 0.4s;
}
.map-loading::before {
  content: "";
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  animation: mapSpin 0.8s linear infinite;
}
@keyframes mapSpin { to { transform: rotate(360deg); } }
.map-loading-done { opacity: 0; pointer-events: none; }

/* ===== Search results panel ===== */
.results-panel {
  position: absolute;
  top: 12px;
  right: 12px;
  bottom: 12px;
  width: 320px;
  max-width: calc(100vw - 24px);
  z-index: 1000;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  overflow-y: auto;
}
.results-head { display: flex; align-items: center; justify-content: space-between; }
.results-head h3 { margin: 0; font-size: 15.5px; }
.result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.result-item:last-child { border-bottom: none; }
@media (max-width: 560px) {
  .results-panel { top: auto; max-height: 45%; }
}

/* ===== Modals ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 2000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 4vh 16px;
  overflow-y: auto;
}
.modal {
  position: relative;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 440px;
  padding: 24px;
  margin-bottom: 4vh;
}
.modal-wide { max-width: 620px; }
.modal h2 { margin: 0 0 16px; font-size: 20px; }
.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  font-size: 26px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
}
.modal-close:hover { color: var(--text); }

/* ===== Forms ===== */
.field { margin-bottom: 14px; flex: 1; }
.field-row { display: flex; gap: 14px; flex-wrap: wrap; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%;
  font: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
.field input + input { margin-top: 6px; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  border-color: var(--primary);
}
fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 0 0 14px;
}
legend { font-size: 13px; font-weight: 700; padding: 0 6px; }
.hint { font-size: 12.5px; color: var(--text-muted); margin: 2px 0 10px; }

/* ===== Dynamic question/answer pairs ===== */
.qa-pair {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
  background: var(--bg);
}
.qa-pair-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.qa-pair-head label { font-size: 13px; font-weight: 600; }
.qa-pair-head .qa-remove { padding: 2px 8px; font-size: 12px; }
.qa-pair input { margin-bottom: 6px; }
.qa-pair input:last-child { margin-bottom: 0; }
#btn-post-add-question, #btn-edit-add-question { margin-top: 4px; }
.error { color: var(--danger); font-size: 13.5px; margin: 8px 0; }
.hidden { display: none !important; }
.switch-auth { font-size: 13.5px; text-align: center; color: var(--text-muted); margin-top: 14px; }
.switch-auth a { color: var(--primary); }
.forgot-link { display: inline-block; margin-top: 6px; font-size: 12.5px; color: var(--primary); text-decoration: none; }
.forgot-link:hover { text-decoration: underline; }
.pick-status { display: block; font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }
.pick-status.is-set { color: var(--success); font-weight: 600; }

/* ===== Item detail ===== */
.item-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.item-head h2 { margin: 0; }
.badge {
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.badge-lost { background: #fee2e2; color: var(--danger); }
.badge-match { background: #fef3c7; color: #b45309; }
.badge-claimed { background: #dbeafe; color: var(--primary-dark); }
.badge-resolved { background: #dcfce7; color: var(--success); }
.badge-expired { background: #e2e8f0; color: var(--text-muted); }
.badge-verified { background: #dbeafe; color: var(--primary-dark); text-transform: none; letter-spacing: 0; }
.item-meta { font-size: 13px; color: var(--text-muted); margin: 0 0 12px; }
.item-meta a { color: var(--primary); text-decoration: none; }
.item-meta a:hover { text-decoration: underline; }
.item-desc { font-size: 14.5px; line-height: 1.5; margin: 0 0 16px; }
.item-photo {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: 12px;
  background: var(--bg);
}
.unlock-box {
  border: 1px dashed var(--primary);
  background: #eff6ff;
  border-radius: var(--radius);
  padding: 14px;
}
.unlock-box h3 { margin: 0 0 4px; font-size: 15px; }
.reveal-box {
  border: 1px solid var(--success);
  background: #f0fdf4;
  border-radius: var(--radius);
  padding: 14px;
}
.reveal-box h3 { margin: 0 0 8px; font-size: 15px; color: var(--success); }
.reveal-box p { margin: 6px 0; font-size: 14.5px; }
.reveal-contact {
  font-weight: 700;
  font-size: 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  word-break: break-all;
}
.unlock-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.unlock-actions .btn { flex: 1; min-width: 140px; }
.owner-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; align-items: flex-end; }
.owner-actions .field { margin-bottom: 0; min-width: 180px; }

/* ===== Profile ===== */
.avatar { border-radius: 50%; object-fit: cover; flex-shrink: 0; background: var(--bg); }
.avatar-lg { width: 64px; height: 64px; }
.avatar-row { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.public-profile-head { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.public-profile-head .item-head { margin-bottom: 2px; }
.danger-zone {
  border-color: var(--danger);
  margin-top: 18px;
}
.danger-zone legend { color: var(--danger); }
.profile-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 14px 0;
  text-align: center;
}
.profile-stats div {
  background: var(--bg);
  border-radius: 8px;
  padding: 10px 4px;
}
.profile-stats strong { display: block; font-size: 18px; }
.profile-stats span { font-size: 11.5px; color: var(--text-muted); }
.profile-stat-clickable { cursor: pointer; transition: background 0.15s; }
.profile-stat-clickable:hover { background: #e2e8f0; }
.success { color: var(--success); font-size: 13.5px; margin: 8px 0; }

/* ===== Stats ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
}
.stat-tile {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}
.stat-tile strong { display: block; font-size: 24px; color: var(--primary); }
.stat-tile span { font-size: 12.5px; color: var(--text-muted); }

/* ===== Share ===== */
.share-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

/* ===== Admin ===== */
.admin-tabs { display: flex; gap: 8px; margin: 12px 0; }

/* ===== Notifications ===== */
.notif-btn { position: relative; }
.notif-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--danger);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}
.notif-row {
  display: flex;
  gap: 10px;
  padding: 12px 8px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  border-radius: 8px;
}
.notif-row:hover { background: var(--bg); }
.notif-row:last-child { border-bottom: none; }
.notif-row.notif-unread { background: #eff6ff; }
.notif-row.notif-unread:hover { background: #e0edff; }
.notif-icon { font-size: 20px; flex-shrink: 0; }
.notif-body { font-size: 13.5px; line-height: 1.4; }
.notif-time { display: block; font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

/* ===== My items list ===== */
.my-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.my-item:last-child { border-bottom: none; }
.my-item-info { flex: 1; min-width: 160px; }
.my-item-info strong { font-size: 14.5px; }
.my-item-info span { display: block; font-size: 12.5px; color: var(--text-muted); }
.my-item-actions { display: flex; gap: 6px; }
.empty-note { color: var(--text-muted); font-size: 14px; text-align: center; padding: 20px 0; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  z-index: 3000;
  box-shadow: var(--shadow);
  max-width: 90vw;
  text-align: center;
}

/* ===== Marker popups ===== */
.leaflet-popup-content { font-family: inherit; font-size: 13.5px; }
.leaflet-popup-content-wrapper {
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.leaflet-popup-tip { box-shadow: var(--shadow); }
.leaflet-tooltip {
  font-family: inherit;
  font-size: 12.5px;
  border-radius: 8px;
  border: none;
  box-shadow: var(--shadow);
}
.popup-title { font-weight: 700; font-size: 14.5px; margin-bottom: 2px; }
.popup-cat { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.popup-link { color: var(--primary); font-size: 13px; cursor: pointer; text-decoration: underline; }

@media (max-width: 560px) {
  .brand h1 { font-size: 16px; }
  .btn { font-size: 13px; padding: 7px 10px; }
  .user-name { display: none; }
  .legend { max-width: 70vw; }
  .profile-stats { grid-template-columns: repeat(2, 1fr); }
}
