:root {
  --terracotta: #b5533c;
  --terracotta-dark: #8e3f2d;
  --olive: #6b7a4f;
  --cream: #faf6ee;
  --cream-dark: #f0e9d8;
  --ink: #2b2620;
  --ink-soft: #6b6255;
  --border: #e2d9c4;
}

* { box-sizing: border-box; }

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

#app {
  display: flex;
  height: 100vh;
  width: 100%;
}

/* Sidebar */
#sidebar {
  width: 340px;
  min-width: 340px;
  background: var(--cream);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: margin-left 0.25s ease;
}

.sidebar-header {
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--cream-dark);
}

.sidebar-header h1 {
  margin: 0 0 4px;
  font-size: 1.25rem;
  color: var(--terracotta-dark);
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0 0 12px;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.subtitle a {
  color: var(--olive);
}

#search {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  margin-bottom: 8px;
  background: #fff;
}

#region-filter {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  background: #fff;
  color: var(--ink);
}

.count {
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--ink-soft);
}

#borgo-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

#borgo-list li {
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.88rem;
}

#borgo-list li:hover {
  background: var(--cream-dark);
}

#borgo-list li.active {
  background: #efe0d1;
  border-left: 3px solid var(--terracotta);
  padding-left: 15px;
}

#borgo-list .name {
  font-weight: 600;
  display: block;
}

#borgo-list .meta {
  color: var(--ink-soft);
  font-size: 0.76rem;
}

#borgo-list .empty {
  padding: 20px 18px;
  color: var(--ink-soft);
  font-size: 0.85rem;
  cursor: default;
}

/* Map */
#map-wrap {
  position: relative;
  flex: 1;
  height: 100%;
}

#map {
  position: absolute;
  inset: 0;
}

#sidebar-toggle {
  display: none;
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 5;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 1.1rem;
  cursor: pointer;
}

.key-banner {
  background: var(--terracotta);
  color: #fff;
  padding: 10px 16px;
  font-size: 0.85rem;
  text-align: center;
}

.key-banner code {
  background: rgba(255,255,255,0.2);
  padding: 1px 5px;
  border-radius: 4px;
}

.key-banner a {
  color: #fff;
  font-weight: 600;
  margin-left: 8px;
}

/* MapLibre popup styling */
.maplibregl-popup-content {
  font-family: inherit;
  padding: 0;
  border-radius: 12px;
  overflow: hidden;
}

.borgo-popup .maplibregl-popup-close-button {
  color: #fff;
  font-size: 1.1rem;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
  right: 4px;
  top: 2px;
}

.popup-image {
  display: block;
  width: 100%;
  height: 140px;
  object-fit: cover;
}

.popup-body {
  padding: 12px 14px 14px;
}

.popup-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--terracotta-dark);
  margin: 0 0 4px;
}

.popup-meta {
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin: 0 0 6px;
}

.popup-excerpt {
  font-size: 0.85rem;
  color: var(--ink);
  margin: 0 0 10px;
  line-height: 1.35;
}

.popup-link {
  font-size: 0.82rem;
  color: var(--olive);
  font-weight: 600;
  text-decoration: none;
}

.popup-link:hover {
  text-decoration: underline;
}

@media (max-width: 760px) {
  #sidebar {
    position: absolute;
    z-index: 4;
    height: 100%;
    margin-left: -340px;
    box-shadow: 2px 0 12px rgba(0,0,0,0.15);
  }

  #sidebar.open {
    margin-left: 0;
  }

  #sidebar-toggle {
    display: block;
  }
}
