*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --colour-bg: #f5f0eb;
  --colour-panel: #ffffff;
  --colour-text: #2c3e50;
  --colour-accent: #7d5a3c;
  --colour-accent-hover: #654a30;
  --colour-border: #e0d6cc;
  --colour-muted: #8a8480;
  --colour-success: #2e7d32;
  --colour-error: #c62828;
  --colour-seeded: #b8860b;
  --colour-public: #2e8b7e;
  --colour-private: #888888;
  --panel-width: 380px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--colour-bg);
  color: var(--colour-text);
  height: 100vh;
  overflow: hidden;
  line-height: 1.5;
}

/* ── Map ── */

#map {
  position: fixed;
  inset: 0;
  z-index: 1;
}

.map-overlay {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 5;
  background: var(--colour-panel);
  padding: 1rem 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
  text-align: center;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.map-overlay p {
  margin: 0;
  font-weight: 500;
}

/* ── Panel ── */

.panel {
  position: fixed;
  top: 12px;
  left: 12px;
  bottom: 12px;
  width: var(--panel-width);
  background: var(--colour-panel);
  z-index: 10;
  overflow-y: auto;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}

.panel.hidden {
  transform: translateX(calc(-100% - 24px));
}

.panel-header {
  padding: 1.25rem 1.5rem 1rem;
  flex-shrink: 0;
}

.panel-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.panel-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--colour-accent);
  text-decoration: none;
}

.auth-btn {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--colour-accent);
  text-decoration: none;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--colour-border);
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}

.auth-btn:hover {
  background: var(--colour-bg);
}

#panel-nav {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

#panel-nav a {
  color: var(--colour-muted);
  text-decoration: none;
  font-size: 0.875rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}

#panel-nav a:hover {
  background: var(--colour-bg);
  color: var(--colour-text);
}

#panel-nav a.active {
  background: var(--colour-accent);
  color: white;
}

#panel-content {
  padding: 1.5rem;
  flex: 1;
}

#ad-container {
  padding: 0.75rem 1.5rem;
  flex-shrink: 0;
  border-top: 1px solid var(--colour-border);
  background: var(--colour-panel);
  position: sticky;
  bottom: 0;
}

/* ── Panel toggle (mobile) ── */

#panel-toggle {
  display: none;
  position: fixed;
  bottom: 1.5rem;
  left: 1.5rem;
  z-index: 20;
  background: var(--colour-accent);
  color: white;
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  font-size: 1.25rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* ── Buttons ── */

.btn {
  display: inline-block;
  padding: 0.6rem 1.25rem;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background 0.15s, opacity 0.15s;
  line-height: 1.4;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--colour-accent);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--colour-accent-hover);
}

.btn-secondary {
  background: var(--colour-bg);
  color: var(--colour-text);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--colour-border);
}

.btn-danger {
  background: var(--colour-error);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: #a12020;
}

/* ── Forms ── */

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  color: var(--colour-text);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--colour-border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--colour-text);
  background: white;
  margin-bottom: 1rem;
  transition: border-color 0.15s;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--colour-accent);
  box-shadow: 0 0 0 2px rgba(125, 90, 60, 0.15);
}

.required {
  color: var(--colour-error);
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  cursor: pointer;
  font-weight: normal;
}

.toggle-label input[type="checkbox"] {
  width: auto;
  margin: 0;
}

fieldset {
  border: 1px solid var(--colour-border);
  border-radius: 6px;
  padding: 1rem;
  margin-bottom: 1rem;
}

legend {
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0 0.25rem;
}

.location-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.location-inputs label {
  font-size: 0.8rem;
  color: var(--colour-muted);
}

.location-buttons {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.location-buttons .btn {
  flex: 1;
  font-size: 0.8rem;
  padding: 0.4rem 0.5rem;
}

/* ── Messages ── */

.message {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.message.error {
  background: #fce4e4;
  color: var(--colour-error);
  border: 1px solid #f5c6c6;
}

.message.success {
  background: #e8f5e9;
  color: var(--colour-success);
  border: 1px solid #c8e6c9;
}

/* ── Welcome ── */

.welcome h2 {
  margin-bottom: 0.75rem;
  font-size: 1.25rem;
}

.welcome > p {
  color: var(--colour-muted);
  margin-bottom: 1.5rem;
}

.welcome-features {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.feature {
  padding: 1rem;
  background: var(--colour-bg);
  border-radius: 8px;
}

.feature strong {
  display: block;
  color: var(--colour-accent);
  margin-bottom: 0.25rem;
}

.feature p {
  font-size: 0.875rem;
  color: var(--colour-muted);
  margin: 0;
}

.welcome-cta {
  font-size: 0.9rem;
}

.welcome-cta a:not(.btn) {
  color: var(--colour-accent);
}

.welcome-hint {
  font-size: 0.8rem;
  color: var(--colour-muted);
  margin-top: 0.75rem;
}

.welcome-hint a {
  color: var(--colour-accent);
}

/* ── Info banners ── */

.info-banner {
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-radius: 6px;
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
  color: var(--colour-text);
}

.info-banner p {
  margin: 0 0 0.5rem;
}

.info-banner p:last-child {
  margin-bottom: 0;
}

.info-banner a {
  color: var(--colour-accent);
  font-weight: 500;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

/* ── Auth forms ── */

.auth-form h2 {
  margin-bottom: 1rem;
}

.auth-switch {
  margin-top: 1rem;
  font-size: 0.875rem;
  color: var(--colour-muted);
}

.auth-switch a {
  color: var(--colour-accent);
}

/* ── Grave list ── */

.my-graves h2 {
  margin-bottom: 1rem;
}

.grave-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.grave-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--colour-bg);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 0.5rem;
}

.grave-item:hover {
  background: var(--colour-border);
}

.grave-item-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.grave-item-info strong {
  font-size: 0.9rem;
}

.grave-cemetery {
  font-size: 0.8rem;
  color: var(--colour-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Badges ── */

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

.badge-public {
  background: #e0f2f1;
  color: var(--colour-public);
}

.badge-private {
  background: #f0f0f0;
  color: var(--colour-private);
}

.badge-seeded {
  background: #fff8e1;
  color: var(--colour-seeded);
}

.badge-verified {
  background: #e8f5e9;
  color: var(--colour-success);
}

.badge-local {
  background: #fff3e0;
  color: #e65100;
}

.badge-shared {
  background: #e3f2fd;
  color: #1565c0;
}

/* ── Grave detail ── */

.grave-detail h2 {
  margin-bottom: 0.5rem;
}

.back-link {
  display: inline-block;
  font-size: 0.875rem;
  color: var(--colour-muted);
  text-decoration: none;
  margin-bottom: 0.75rem;
}

.back-link:hover {
  color: var(--colour-accent);
}

.detail-row {
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.detail-actions {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--colour-border);
}

/* ── Filter bar ── */

.filter-bar {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.filter-pill {
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--colour-border);
  border-radius: 20px;
  background: white;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--colour-text);
}

.filter-pill.active {
  background: var(--colour-accent);
  color: white;
  border-color: var(--colour-accent);
}

.filter-pill:hover:not(.active) {
  background: var(--colour-bg);
}

/* ── Explore ── */

.explore h2 {
  margin-bottom: 0.75rem;
}

.community-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  font-weight: normal;
  color: var(--colour-muted);
  margin-bottom: 0.75rem;
  cursor: pointer;
}

.community-toggle input {
  width: auto;
  margin: 0;
}

.explore-count {
  font-size: 0.8rem;
  color: var(--colour-muted);
  margin-bottom: 0.5rem;
}

.grave-item-badges {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.badge-category {
  background: #f3e5f5;
  color: #7b1fa2;
}

/* ── About ── */

.about h2 {
  margin-bottom: 0.75rem;
  font-size: 1.25rem;
}

.about > p {
  color: var(--colour-muted);
  margin-bottom: 1.5rem;
}

/* ── Autocomplete ── */

.autocomplete-container {
  position: relative;
}

#cemetery-suggestions {
  position: absolute;
  top: calc(100% - 1rem);
  left: 0;
  right: 0;
  background: white;
  border: 1px solid var(--colour-border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: 5;
  max-height: 200px;
  overflow-y: auto;
}

#cemetery-suggestions:empty {
  display: none;
}

.suggestion {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  border-bottom: 1px solid var(--colour-border);
}

.suggestion:last-child {
  border-bottom: none;
}

.suggestion:hover {
  background: var(--colour-bg);
}

.suggestion strong {
  display: block;
  font-size: 0.85rem;
}

.suggestion span {
  font-size: 0.75rem;
  color: var(--colour-muted);
}

/* ── Add grave ── */

.add-grave h2 {
  margin-bottom: 1rem;
}

/* ── Loading ── */

.loading {
  text-align: center;
  color: var(--colour-muted);
  padding: 2rem 0;
}

.loading::before {
  content: '';
  display: block;
  width: 24px;
  height: 24px;
  margin: 0 auto 0.75rem;
  border: 3px solid var(--colour-border);
  border-top-color: var(--colour-accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

.empty-state {
  color: var(--colour-muted);
  margin-bottom: 1rem;
}

/* ── Map markers ── */

.grave-marker {
  background: none !important;
  border: none !important;
}

.marker-popup strong {
  display: block;
  margin-bottom: 0.25rem;
}

.marker-popup p {
  font-size: 0.8rem;
  color: #666;
  margin: 0 0 0.5rem;
}

.marker-popup a {
  font-size: 0.8rem;
  color: var(--colour-accent);
}

/* ── Ad placeholder ── */

.ad-placeholder {
  background: var(--colour-bg);
  border: 1px dashed var(--colour-border);
  border-radius: 6px;
  padding: 1rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--colour-muted);
  min-height: 60px;
}

/* ── Mobile responsive ── */

@media (max-width: 640px) {
  .panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    height: 60vh;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
    transition: transform 0.3s ease;
    will-change: transform;
  }

  .panel.dragging {
    transition: none !important;
  }

  .panel[data-state="peek"] {
    transform: translateY(var(--peek-offset, calc(65vh - 72px)));
  }

  .panel[data-state="expanded"] {
    transform: translateY(0);
  }

  .panel[data-state="hidden"] {
    transform: translateY(100%);
  }

  .panel-header {
    text-align: center;
    padding-top: 0.75rem;
    cursor: grab;
    -webkit-user-select: none;
    user-select: none;
  }

  .panel-header::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: var(--colour-border);
    border-radius: 2px;
    margin: 0 auto 0.75rem;
  }

  #panel-nav {
    justify-content: center;
  }

  #panel-toggle {
    display: none !important;
  }

  #ad-container {
    position: sticky;
    bottom: 0;
    border-radius: 0;
  }

  .panel {
    overflow: hidden;
  }

  #panel-content {
    overflow-y: auto;
    min-height: 0;
  }

  .leaflet-bottom {
    bottom: 10px !important;
  }

  .location-buttons {
    flex-direction: column;
  }
}
