:root {
  --red: #b30400;
  --blue: #387dc5;
  --green: #497818;
  --ink: #2b2620;
  --paper: #faf6ee;
  --line: #ddd3bf;
}

* { box-sizing: border-box; }

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

#topbar {
  padding: 14px 20px 10px;
  border-bottom: 3px solid var(--red);
  background: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
}
#topbar h1 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--red);
  letter-spacing: 0.5px;
}
.subtitle {
  margin: 2px 0 0;
  font-size: 0.9rem;
  color: #7a6f5c;
}

#menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  padding: 0;
}
#menu-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--ink);
}

#tancar-menu {
  display: none;
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  color: #999;
}

#sidebar-overlay {
  display: none;
}

#layout {
  display: flex;
  height: calc(100vh - 66px);
}

#sidebar {
  width: 300px;
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  padding: 12px;
  overflow-y: auto;
}

#cercador {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.95rem;
  margin-bottom: 10px;
}

.filtres {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}
.filtre {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.existent .dot { background: var(--red); }
.desapareguda .dot { background: var(--blue); }
.miscelania .dot { background: var(--green); }

#llista {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 55vh;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  padding-top: 6px;
}

.item {
  padding: 6px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.87rem;
  line-height: 1.25;
  display: flex;
  gap: 6px;
  align-items: baseline;
}
.item:hover { background: #f1ead9; }
.item .num { color: #999; font-size: 0.78rem; min-width: 22px; }
.item.existent .num { color: var(--red); }
.item.desapareguda .num { color: var(--blue); }
.item.miscelania .num { color: var(--green); }

#sense-posicio-wrap {
  margin-top: 10px;
  font-size: 0.85rem;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}
#sense-posicio-wrap summary {
  cursor: pointer;
  color: #7a6f5c;
}
#sense-posicio-llista .item { cursor: default; }
#sense-posicio-llista .item:hover { background: none; }

#mapa-wrap {
  flex: 1;
  position: relative;
}
#mapa {
  width: 100%;
  height: 100%;
  background: #eee6d2;
}

.leaflet-container { font-family: inherit; }

.pin-existent, .pin-desapareguda, .pin-miscelania {
  border-radius: 50%;
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.35);
}
.pin-existent { background: var(--red); }
.pin-desapareguda { background: var(--blue); }
.pin-miscelania { background: var(--green); }

#panell {
  position: fixed;
  top: 0;
  right: 0;
  width: 340px;
  max-width: 90vw;
  height: 100%;
  background: #fff;
  box-shadow: -4px 0 18px rgba(0,0,0,0.18);
  z-index: 1000;
  padding: 20px;
  overflow-y: auto;
  transition: transform 0.25s ease;
}
#panell.oculte {
  transform: translateX(100%);
  pointer-events: none;
}
#tancar-panell {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  color: #999;
}
#tancar-panell:hover { color: var(--ink); }

.panell-etiqueta {
  display: inline-block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 8px;
  border-radius: 10px;
  color: #fff;
  margin-bottom: 8px;
}
.panell-etiqueta.existent { background: var(--red); }
.panell-etiqueta.desapareguda { background: var(--blue); }
.panell-etiqueta.miscelania { background: var(--green); }

.panell-contingut h2 {
  margin: 4px 0 2px;
  font-size: 1.25rem;
}
.panell-num { color: #999; font-size: 0.85rem; margin-bottom: 14px; }

.camp {
  margin-bottom: 14px;
}
.camp label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #a09480;
  margin-bottom: 3px;
}
.camp .valor {
  font-size: 0.95rem;
  white-space: pre-wrap;
}
.camp .buit {
  color: #bbb;
  font-style: italic;
  font-size: 0.88rem;
}

.fotos {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.fotos img {
  width: 100%;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.ajuda-edicio {
  margin-top: 20px;
  padding: 10px 12px;
  background: #f6f1e6;
  border-radius: 8px;
  font-size: 0.78rem;
  color: #8a7d64;
}
code {
  background: #eee2c8;
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 0.85em;
}

@media (max-width: 800px) {
  #menu-toggle { display: flex; }

  #layout { position: relative; }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 84%;
    max-width: 340px;
    height: 100%;
    z-index: 1200;
    box-shadow: 2px 0 18px rgba(0,0,0,0.25);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    padding-top: 44px;
  }
  #sidebar.oberta { transform: translateX(0); }

  #tancar-menu { display: block; }

  #sidebar-overlay.oberta {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(20, 16, 8, 0.4);
    z-index: 1100;
  }

  #mapa-wrap { height: 100%; }
}
