:root {
  --bg: #0b121c;
  --panel: #121b28;
  --panel-alt: #172334;
  --border: #243449;
  --text: #e6edf6;
  --muted: #8fa3bd;
  --accent: #f5b041;
  --cop: #3ee9fd;
  --criminal: #ef4444;
  --civilian: #34d399;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }

.topbar {
  height: 54px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 16px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-badge {
  background: var(--accent);
  color: #0b121c;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 4px;
}
.brand h1 { font-size: 15px; font-weight: 600; white-space: nowrap; }

.tabs { display: flex; gap: 6px; }
.tab-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); background: var(--panel-alt); }
.tab-btn.active { color: #0b121c; background: var(--accent); }
.topbar-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }

.tab-panel { display: none; height: calc(100vh - 54px); overflow-y: auto; }
.tab-panel.active { display: block; }
#map-tab { overflow: hidden; }

.map-layout { display: flex; height: 100%; position: relative; }

.sidebar {
  width: 320px;
  min-width: 280px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  z-index: 500;
}
.sidebar.collapsed { display: none; }

.sidebar-section { padding: 12px; border-bottom: 1px solid var(--border); }
.buildings-section { flex: 1; display: flex; flex-direction: column; overflow: hidden; border-bottom: none; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 8px;
}

.mini-actions { display: flex; gap: 4px; }
.mini-btn {
  background: var(--panel-alt);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 11px;
  cursor: pointer;
}
.mini-btn:hover { color: var(--text); border-color: var(--accent); }

.search-input, .select-input {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
}
.search-input:focus, .select-input:focus { border-color: var(--accent); }

.layer-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  max-height: 250px;
  overflow-y: auto;
}
.layer-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 7px;
  font-size: 11.5px;
  cursor: pointer;
  user-select: none;
}
.layer-item.off { opacity: 0.45; }
.layer-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.layer-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layer-count { color: var(--muted); font-size: 10.5px; }

.building-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 5px; }
.building-item {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.building-item:hover { border-color: var(--accent); }
.building-item-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.building-item-title { font-size: 13px; font-weight: 600; }
.building-item-size { font-size: 10.5px; color: var(--accent); background: rgba(245, 176, 65, 0.12); padding: 1px 6px; border-radius: 4px; }
.building-item-sub { font-size: 11px; color: var(--muted); margin-top: 3px; }

.map-container { flex: 1; position: relative; background: #0b121c; }
#map { width: 100%; height: 100%; background: #0b121c; }

.sidebar-toggle {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 600;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 16px;
}
.sidebar-toggle:hover { border-color: var(--accent); }

.coords-hud {
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 600;
  background: rgba(18, 27, 40, 0.88);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--muted);
  font-family: monospace;
}

/* Leaflet overrides */
.leaflet-container { background: #0b121c !important; }
.leaflet-control-zoom { margin-left: 12px !important; margin-top: 56px !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel) !important;
  color: var(--text) !important;
  border: 1px solid var(--border);
}
.leaflet-popup-content { margin: 12px 14px; font-size: 12.5px; line-height: 1.45; min-width: 210px; }
.popup-title { font-size: 14px; font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.popup-meta { font-size: 11.5px; color: var(--muted); margin-bottom: 6px; }
.popup-rewards { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.reward-chip {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
}

.district-label {
  color: rgba(230, 237, 246, 0.45);
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-shadow: 0 2px 6px rgba(0,0,0,0.85);
  pointer-events: none;
  white-space: nowrap;
}

.bldg-pin {
  background: #f5b041;
  color: #0b121c;
  border: 2px solid #fff;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 11px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.65);
}

/* Content Tabs */
.content-wrap { max-width: 1260px; margin: 0 auto; padding: 24px 20px 48px; }
.page-intro { margin-bottom: 20px; }
.page-intro h2 { font-size: 22px; margin-bottom: 6px; }
.page-intro p { color: var(--muted); font-size: 14px; }

.roles-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-bottom: 20px; }
.role-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
}
.role-civilian { border-top: 3px solid var(--civilian); }
.role-cop { border-top: 3px solid var(--cop); }
.role-criminal { border-top: 3px solid var(--criminal); }

.role-header { margin-bottom: 12px; }
.role-tag { font-size: 11px; font-weight: 800; letter-spacing: 0.08em; }
.role-civilian .role-tag { color: var(--civilian); }
.role-cop .role-tag { color: var(--cop); }
.role-criminal .role-tag { color: var(--criminal); }
.role-header h3 { font-size: 17px; margin-top: 2px; }

.role-card ul { padding-left: 18px; display: flex; flex-direction: column; gap: 8px; font-size: 13.5px; line-height: 1.5; color: #d3deec; }
.role-card ul ul { margin-top: 5px; }

.sub-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-bottom: 20px; }
.info-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
}
.info-panel h3 { font-size: 16px; margin-bottom: 12px; color: var(--accent); }
.stack-list { display: flex; flex-direction: column; gap: 8px; }
.stack-row {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 12px;
  font-size: 13px;
}

.buffs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.buff-card {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}
.buff-card h4 { font-size: 14px; margin-bottom: 4px; color: var(--text); }
.buff-card p { font-size: 12.5px; color: var(--muted); line-height: 1.45; }

/* Database Tab */
.db-controls { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.db-stats { font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
.db-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.db-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.db-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 5px; }
.db-card h4 { font-size: 14px; color: var(--text); }
.db-badge { font-size: 10.5px; background: var(--panel-alt); border: 1px solid var(--border); color: var(--accent); padding: 2px 6px; border-radius: 4px; white-space: nowrap; }
.db-card p { font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.db-id { font-family: monospace; font-size: 11px; color: #647b96; margin-top: 6px; }

@media (max-width: 820px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; }
  .topbar-meta { display: none; }
  .sidebar { position: absolute; left: 0; top: 0; bottom: 0; width: 290px; }
  .db-controls { grid-template-columns: 1fr; }
}
