:root {
  --bg: #0b1110;
  --panel: #131b1a;
  --panel2: #1a2423;
  --border: #2c3c38;
  --text: #eef6f2;
  --muted: #8aa39b;
  --accent: #34d399;
  --ac: #22c55e;
  --dc: #38bdf8;
  --hpc: #c084fc;
  --tent: #fbbf24;
  --free: #22c55e;
  --taken: #ef4444;
  --partial: #f59e0b;
  --unknown: #eab308;
  --inactive: #64748b;
  --price: #34d399;
  --font: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1000;
  min-height: 0;
}

.sidebar-header {
  padding: 1.05rem 1rem 0.85rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 1.08rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.sidebar-header p {
  font-size: 0.76rem;
  color: var(--muted);
  margin-top: 0.28rem;
  line-height: 1.35;
}

.tabs {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.65rem;
}

.tab {
  flex: 1;
  padding: 0.42rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
}

.tab.active {
  background: rgba(52, 211, 153, 0.14);
  border-color: var(--accent);
  color: var(--accent);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
}

.stat {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
}

.stat .num {
  font-size: 1.2rem;
  font-weight: 700;
}

.stat .label {
  font-size: 0.66rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat.live .num { color: var(--free); }
.stat.loc .num { color: #e2e8f0; }
.stat.sites .num { color: #94a3b8; }
.stat.taken .num { color: var(--taken); }
.stat.price .num { color: var(--price); }

.filters {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.search-box input,
.filters select {
  width: 100%;
  padding: 0.52rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  font-size: 0.84rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.32rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel2);
  font-size: 0.74rem;
  cursor: pointer;
  user-select: none;
}

.chip input { accent-color: var(--accent); }
.chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.chip .dot.ac { background: var(--ac); }
.chip .dot.dc { background: var(--dc); }
.chip .dot.hpc { background: var(--hpc); }
.chip .dot.tent { background: var(--tent); }
.chip .dot.free { background: var(--free); }
.chip .dot.price { background: var(--price); }

.results {
  flex: 1;
  overflow-y: auto;
  padding: 0.55rem 0.7rem 0.8rem;
}

.result {
  padding: 0.6rem 0.65rem;
  border: 1px solid var(--border);
  background: var(--panel2);
  border-radius: 8px;
  margin-bottom: 0.4rem;
  cursor: pointer;
}

.result:hover,
.result.active { border-color: var(--accent); }

.result strong {
  display: block;
  font-size: 0.82rem;
  margin-bottom: 0.15rem;
}

.result span {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
}

.result .meta {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.35rem;
}

.result .badge { display: inline-block; }

.badge {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.12rem 0.35rem;
  border-radius: 4px;
}

.badge.ac { background: rgba(34, 197, 94, 0.18); color: #86efac; }
.badge.dc { background: rgba(56, 189, 248, 0.18); color: #7dd3fc; }
.badge.hpc { background: rgba(192, 132, 252, 0.2); color: #e9d5ff; }
.badge.tent { background: rgba(251, 191, 36, 0.16); color: #fde68a; }
.badge.price { background: rgba(52, 211, 153, 0.16); color: #6ee7b7; }
.badge.occ.free { background: rgba(34, 197, 94, 0.18); color: #86efac; }
.badge.occ.partial { background: rgba(245, 158, 11, 0.18); color: #fcd34d; }
.badge.occ.taken { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }
.badge.occ.unknown, .badge.occ.none { background: rgba(234, 179, 8, 0.16); color: #fde68a; }
.badge.occ.inactive { background: rgba(100, 116, 139, 0.22); color: #cbd5e1; }

.sidebar-footer {
  padding: 0.7rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--muted);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem 0.5rem;
  align-items: center;
}
.sidebar-footer #updatedAt { grid-column: 1 / -1; }

.btn {
  padding: 0.38rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  font-size: 0.74rem;
  cursor: pointer;
}

.btn:hover { background: var(--border); }

.btn-accent {
  background: rgba(52, 211, 153, 0.18);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 650;
}

.btn-accent:hover { background: rgba(52, 211, 153, 0.28); }

.btn.icon {
  padding: 0.38rem 0.45rem;
  flex-shrink: 0;
}

.btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

.trip-panel {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.trip-intro {
  font-size: 0.74rem;
  color: var(--muted);
  line-height: 1.4;
}

.trip-form {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.field input,
.field select,
.field output {
  width: 100%;
  padding: 0.48rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  font-size: 0.84rem;
}

.field output {
  display: block;
  font-weight: 650;
  color: var(--accent);
}

.field-row {
  display: flex;
  gap: 0.35rem;
}

.field-row input { flex: 1; }

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.field-grid-3 {
  grid-template-columns: 1fr 1fr;
}

.field-full {
  grid-column: 1 / -1;
}

.trip-pref {
  grid-column: 1 / -1;
  width: fit-content;
}

.trip-actions {
  display: flex;
  gap: 0.45rem;
  margin-top: 0.15rem;
}

.trip-actions .btn-accent { flex: 1; }

.trip-error {
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  font-size: 0.76rem;
}

.trip-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
}

.trip-stat {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.35rem;
  text-align: center;
}

.trip-stat span {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent);
}

.trip-stat small {
  font-size: 0.58rem;
  color: var(--muted);
  text-transform: uppercase;
}

.trip-stops {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.trip-stop {
  display: flex;
  gap: 0.55rem;
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--border);
  background: var(--panel2);
  border-radius: 8px;
  text-align: left;
  color: inherit;
  cursor: pointer;
}

.trip-stop.ok { cursor: default; border-color: rgba(52, 211, 153, 0.35); }

.trip-stop:hover:not(.ok) { border-color: var(--accent); }

.trip-stop-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #f59e0b;
  color: #1e293b;
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.trip-stop-body strong {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 0.12rem;
}

.trip-stop-body span {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
}

.trip-stop .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.3rem;
}

.trip-gmaps {
  display: block;
  text-align: center;
  text-decoration: none;
  margin-top: 0.25rem;
}

#map.pick-mode { cursor: crosshair; }

#panelMap {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

#panelMap[hidden] {
  display: none !important;
}

#map { position: relative; width: 100%; height: 100vh; }

.loading {
  position: fixed;
  inset: 0;
  background: rgba(11, 17, 16, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  font-size: 0.95rem;
}

.loading.hidden { display: none; }

.leaflet-popup-content-wrapper {
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

.popup-title { font-weight: 650; font-size: 0.92rem; margin: 0.2rem 0 0.25rem; }
.popup-desc { font-size: 0.8rem; color: #334155; line-height: 1.4; }
.popup-meta { font-size: 0.72rem; color: #64748b; margin-top: 0.25rem; }
.popup-points { margin-top: 0.45rem; width: 100%; border-collapse: collapse; font-size: 0.72rem; }
.popup-points th { text-align: left; color: #64748b; font-weight: 600; padding: 0.15rem 0.3rem 0.25rem 0; }
.popup-points td { padding: 0.12rem 0.3rem 0.12rem 0; color: #1e293b; }
.popup-link { display: inline-block; margin-top: 0.45rem; font-size: 0.75rem; color: #047857; }
.popup-meta a { color: #047857; }
.st {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 0.28rem;
  vertical-align: middle;
}
.st.free { background: #16a34a; }
.st.taken { background: #dc2626; }
.st.unknown { background: #ca8a04; }
.st.inactive { background: #64748b; }

.legend {
  position: absolute;
  left: 12px;
  bottom: 28px;
  z-index: 500;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.7rem;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  background: rgba(19, 27, 26, 0.88);
  border: 1px solid var(--border);
  font-size: 0.68rem;
  color: var(--muted);
}
.legend .dot,
.legend i.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.28rem;
  vertical-align: middle;
}
.legend .dot.free { background: var(--free); }
.legend .dot.partial { background: var(--partial); }
.legend .dot.taken { background: var(--taken); }
.legend .dot.unknown { background: var(--unknown); }
.legend .dot.inactive { background: var(--inactive); }

.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large { background: rgba(52, 211, 153, 0.22); }

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background: rgba(16, 185, 129, 0.9);
  color: #fff;
  font-weight: 650;
}

.geo-btn {
  position: absolute;
  right: 12px;
  bottom: 28px;
  z-index: 500;
}

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 46vh; border-right: none; border-bottom: 1px solid var(--border); }
  #map { height: 54vh; }
}
