:root {
  --green-900: #1b4332;
  --green-700: #2d6a4f;
  --green-500: #40916c;
  --blue-600: #1d6fa5;
  --bg: #f4f7f5;
  --panel-bg: #ffffff;
  --text: #1f2933;
  --text-muted: #61707d;
  --border: #dde5ea;
  --accent: var(--green-700);
  --sidebar-w: 360px;
}

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

html, body { height: 100%; }

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

#app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--panel-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  box-shadow: 2px 0 12px rgba(0,0,0,.06);
}

.sb-header { padding: 18px 18px 10px; background: linear-gradient(135deg, var(--green-900), var(--green-700)); color: #fff; }
.sb-title-row { display: flex; justify-content: space-between; align-items: flex-start; }
.sb-header h1 { font-size: 1.35rem; line-height: 1.2; letter-spacing: .2px; }
.sb-header .uf { font-size: .8em; opacity: .85; font-weight: 500; }
.subtitle { font-size: .85rem; opacity: .9; margin-top: 2px; }

.sb-tabs { display: flex; border-bottom: 1px solid var(--border); background: #fbfdfc; }
.tab {
  flex: 1; padding: 11px 6px; border: none; background: none;
  font-size: .88rem; font-weight: 600; color: var(--text-muted);
  cursor: pointer; border-bottom: 3px solid transparent;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.sb-body { flex: 1; overflow-y: auto; padding: 14px; overscroll-behavior: contain; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
h2, h3 { color: var(--green-900); margin: 14px 0 6px; font-size: 1rem; }
#tab-about p, #tab-about li { font-size: .86rem; line-height: 1.55; color: var(--text); }
#tab-about ul { padding-left: 18px; margin-bottom: 8px; }
#tab-about a { color: var(--blue-600); }
.hint { margin-top: 10px; color: var(--text-muted); font-style: italic; }

/* City chips */
.city-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip {
  padding: 6px 11px; font-size: .8rem; font-weight: 600;
  border: 1px solid var(--border); border-radius: 999px;
  background: #fff; color: var(--text-muted); cursor: pointer;
  transition: all .15s ease;
}
.chip:hover { border-color: var(--green-500); color: var(--green-700); }
.chip.active { background: var(--green-700); border-color: var(--green-700); color: #fff; }
.chip.destaque { border-color: var(--green-500); }

/* City info card */
.city-info h2 { margin-top: 0; font-size: 1.15rem; }
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px; margin: 10px 0 14px;
}
.stat {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px;
}
.stat .label { font-size: .68rem; text-transform: uppercase; letter-spacing: .6px; color: var(--text-muted); }
.stat .value { font-size: 1.05rem; font-weight: 700; color: var(--green-900); }
.city-info p.desc, .city-info li { font-size: .86rem; line-height: 1.55; margin-bottom: 8px; }
.city-info ul.tourist { padding-left: 18px; }
.badge {
  display: inline-block; font-size: .68rem; font-weight: 700; text-transform: uppercase;
  background: var(--green-500); color: #fff; border-radius: 6px; padding: 3px 8px;
  margin-bottom: 6px; letter-spacing: .5px;
}

/* Search */
#search-input {
  width: 100%; padding: 10px 12px; font-size: .92rem;
  border: 1px solid var(--border); border-radius: 10px; outline: none;
}
#search-input:focus { border-color: var(--green-500); box-shadow: 0 0 0 3px rgba(64,145,108,.15); }
.search-results { list-style: none; margin-top: 8px; }
.search-results li {
  padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: .86rem;
  border: 1px solid transparent;
}
.search-results li:hover { background: var(--bg); border-color: var(--border); }
.search-results .kind { color: var(--text-muted); font-size: .75rem; }
.search-results li b { color: var(--green-900); }

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

.poi-pin {
  width: 26px; height: 26px; border-radius: 50%;
  background: #fff; border: 2px solid #e9c46a;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; line-height: 1; box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.locality-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #6d597a; border: 2px solid #fff; box-shadow: 0 0 3px rgba(0,0,0,.5);
}
.city-tooltip { font-weight: 700; }
#map { width: 100%; height: 100%; background: #aad3df; }

.map-fab {
  position: absolute; right: 12px; bottom: 110px; z-index: 800;
}
.icon-btn {
  width: 38px; height: 38px; border: none; border-radius: 10px;
  background: var(--panel-bg); color: var(--text);
  font-size: 1.15rem; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg); }

.map-topbar {
  position: absolute; top: 10px; left: 10px; right: 10px; z-index: 900;
  display: flex; gap: 8px; align-items: center;
}
.topbar-title {
  flex: 1; background: var(--panel-bg); border-radius: 10px;
  padding: 8px 12px; font-weight: 700; font-size: .9rem; color: var(--green-900);
  box-shadow: 0 2px 8px rgba(0,0,0,.18); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Legend */
.legend {
  position: absolute; left: 12px; bottom: 14px; z-index: 800;
  background: var(--panel-bg); border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,.2);
  max-width: 240px; overflow: hidden;
}
.legend-toggle {
  width: 100%; padding: 9px 14px; border: none; background: none;
  font-weight: 700; font-size: .82rem; color: var(--green-900); cursor: pointer; text-align: left;
}
.legend-body { padding: 2px 14px 10px; font-size: .78rem; }
.legend.collapsed .legend-body { display: none; }
.legend-item { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; user-select: none; }
.legend-item.off { opacity: .4; text-decoration: line-through; }
.swatch { width: 20px; height: 4px; border-radius: 2px; flex-shrink: 0; }
.swatch.dot { width: 12px; height: 12px; border-radius: 50%; }
.swatch.poly { height: 10px; }

.status-bar {
  position: absolute; top: 60px; left: 50%; transform: translateX(-50%); z-index: 850;
  background: rgba(27,67,50,.92); color: #fff; padding: 7px 16px;
  border-radius: 999px; font-size: .82rem; box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.only-mobile { display: none !important; }

/* Leaflet popup polish */
.leaflet-popup-content-wrapper { border-radius: 12px; }
.popup-title { font-weight: 700; color: var(--green-900); font-size: .95rem; margin-bottom: 2px; }
.popup-kind { font-size: .72rem; text-transform: uppercase; letter-spacing: .5px; color: var(--green-500); font-weight: 700; }
.popup-meta { font-size: .8rem; color: var(--text-muted); margin-top: 4px; }
.popup-meta a { color: var(--blue-600); }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  #app { position: relative; }
  #map-wrap { position: fixed; inset: 0; }
  .only-mobile { display: inline-flex !important; }
  .desktop-only { display: none !important; }
  .map-topbar .icon-btn { flex-shrink: 0; }

  #sidebar {
    position: fixed; inset: 0 0 auto 0; width: 100%;
    min-width: 0; max-height: 62dvh; height: auto;
    border-right: none; border-bottom: 1px solid var(--border);
    border-radius: 0 0 18px 18px;
    transform: translateY(calc(-100% - 24px)); transition: transform .25s ease;
    box-shadow: 0 6px 20px rgba(0,0,0,.25);
  }
  #sidebar.open { transform: translateY(0); }
  .sb-header { padding: 12px 16px 8px; }
  .sb-header h1 { font-size: 1.1rem; }
  .sb-body { padding: 10px 12px 18px; max-height: calc(62dvh - 110px); }
  .legend { left: 10px; right: auto; bottom: 90px; max-width: 210px; }
}

@media (min-width: 821px) {
  .map-topbar { display: none; }
}
