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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #1c1917;
  color: #fafaf0;
}

#app {
  display: flex;
  height: 100vh;
  position: relative;
}

/* ── Map ── */
#map {
  flex: 1;
  height: 100%;
}

/* ── Right column (controls + date panel) ── */
#right-col {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  width: 200px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ctrl-btn {
  background: #292524;
  border: 1px solid #44403c;
  color: #fafaf0;
  padding: 7px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.15s;
}
.ctrl-btn:hover  { background: #3a3330; }
.ctrl-btn.active { background: #e07b54; border-color: #e07b54; color: #1c1917; }

/* ── Date range panel ── */
#date-panel {
  background: #292524;
  border: 1px solid #44403c;
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#date-panel-title {
  font-size: 11px;
  font-weight: 600;
  color: #a8a29e;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#date-presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.preset-btn {
  background: #1c1917;
  border: 1px solid #44403c;
  color: #a8a29e;
  padding: 5px 0;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  text-align: center;
  transition: background 0.15s;
}
.preset-btn:hover  { background: #292524; color: #fafaf0; }
.preset-btn.active { background: #e07b54; border-color: #e07b54; color: #1c1917; font-weight: 600; }

#date-custom {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.date-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.date-row label {
  font-size: 11px;
  color: #a8a29e;
  width: 28px;
  flex-shrink: 0;
}

.date-input {
  flex: 1;
  background: #1c1917;
  border: 1px solid #44403c;
  color: #fafaf0;
  padding: 4px 6px;
  border-radius: 5px;
  font-size: 12px;
  width: 100%;
  color-scheme: dark;
}
.date-input:focus { outline: none; border-color: #e07b54; }

/* ── Crime type filter panel ── */
#filter-panel {
  background: #292524;
  border: 1px solid #44403c;
  border-radius: 10px;
  overflow: hidden;
}

#filter-toggle {
  width: 100%;
  background: none;
  border: none;
  color: #fafaf0;
  padding: 9px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
#filter-toggle:hover { background: #3a3330; }

#filter-toggle-arrow {
  font-size: 10px;
  color: #a8a29e;
  transition: transform 0.15s;
}
#filter-panel.open #filter-toggle-arrow { transform: rotate(180deg); }

#filter-body {
  display: none;
  padding: 6px 10px 10px;
  border-top: 1px solid #44403c;
}
#filter-panel.open #filter-body { display: block; }

#filter-quick {
  display: flex;
  gap: 6px;
  margin-bottom: 7px;
}

.filter-quick-btn {
  flex: 1;
  background: #1c1917;
  border: 1px solid #44403c;
  color: #a8a29e;
  padding: 3px 0;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
}
.filter-quick-btn:hover { background: #3a3330; color: #fafaf0; }

#filter-list {
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
#filter-list::-webkit-scrollbar { width: 4px; }
#filter-list::-webkit-scrollbar-track { background: transparent; }
#filter-list::-webkit-scrollbar-thumb { background: #44403c; border-radius: 2px; }

.filter-item {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  padding: 2px 2px;
  border-radius: 4px;
}
.filter-item:hover { background: #3a3330; }

.filter-item input[type="checkbox"] {
  accent-color: #e07b54;
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  cursor: pointer;
}

.filter-item-label {
  font-size: 12px;
  color: #d6d0cb;
  line-height: 1.3;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Side panel (desktop only) ── */
#panel {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
  width: 280px;
  max-height: calc(66.67vh - 24px);
  background: #292524;
  border: 1px solid #44403c;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#panel-header {
  padding: 12px 14px 10px;
  border-bottom: 1px solid #44403c;
  flex-shrink: 0;
}

#panel-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: #fafaf0;
  margin-bottom: 2px;
}

#panel-count {
  font-size: 12px;
  color: #a8a29e;
}

#panel-list {
  overflow-y: auto;
  flex: 1;
}

#panel-list::-webkit-scrollbar { width: 4px; }
#panel-list::-webkit-scrollbar-track { background: transparent; }
#panel-list::-webkit-scrollbar-thumb { background: #44403c; border-radius: 2px; }

.panel-item {
  padding: 10px 14px;
  border-bottom: 1px solid #1c1917;
  cursor: pointer;
  transition: background 0.1s;
}
.panel-item:hover    { background: #3a3330; }
.panel-item.selected { background: #1c1917; border-left: 3px solid #e07b54; }

.panel-item-title {
  font-size: 13px;
  font-weight: 500;
  color: #fafaf0;
  margin-bottom: 3px;
}

.panel-item-meta {
  font-size: 11px;
  color: #a8a29e;
  line-height: 1.5;
}

.panel-item-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  margin-top: 4px;
  text-transform: uppercase;
}

.badge-police { background: #1e3a5f; color: #60a5fa; }
.badge-user   { background: #3b1f1f; color: #e07b54; }

/* ── Description panel (bottom-centre) ── */
#desc-panel {
  display: none;
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  width: min(520px, calc(100vw - 340px));
  max-height: 40vh;
  background: #292524;
  border: 1px solid #44403c;
  border-radius: 10px;
  flex-direction: column;
  overflow: hidden;
}

#desc-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 8px;
  border-bottom: 1px solid #44403c;
  flex-shrink: 0;
}

#desc-panel-header h3 {
  font-size: 13px;
  font-weight: 600;
  color: #fafaf0;
}

#desc-panel-close {
  background: none;
  border: none;
  color: #a8a29e;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
}
#desc-panel-close:hover { color: #fafaf0; }

#desc-panel-body {
  overflow-y: auto;
  flex: 1;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.6;
  color: #d6d0cb;
}
#desc-panel-body::-webkit-scrollbar { width: 4px; }
#desc-panel-body::-webkit-scrollbar-track { background: transparent; }
#desc-panel-body::-webkit-scrollbar-thumb { background: #44403c; border-radius: 2px; }

@media (max-width: 640px) {
  #desc-panel { display: none !important; }
}

/* ── Mobile floating card ── */
#mobile-card {
  display: none;
  position: absolute;
  bottom: 24px;
  left: 12px;
  right: 12px;
  z-index: 20;
  background: #292524;
  border: 1px solid #44403c;
  border-radius: 10px;
  padding: 14px;
}

#mobile-card-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: #a8a29e;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}

#mobile-card-title {
  font-size: 14px;
  font-weight: 600;
  color: #fafaf0;
  margin-bottom: 6px;
  padding-right: 24px;
}

#mobile-card-meta {
  font-size: 12px;
  color: #a8a29e;
  line-height: 1.6;
}

/* ── Group detail panel (bottom-left, 1/3 height) ── */
#group-panel {
  display: none;
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 10;
  width: 280px;
  height: calc(33.33vh - 18px);
  background: #292524;
  border: 1px solid #44403c;
  border-radius: 10px;
  flex-direction: column;
  overflow: hidden;
}

#group-panel-header {
  padding: 10px 14px 8px;
  border-bottom: 1px solid #44403c;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#group-panel-header h3 {
  font-size: 13px;
  font-weight: 600;
  color: #fafaf0;
}

#group-panel-close {
  background: none;
  border: none;
  color: #a8a29e;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
}
#group-panel-close:hover { color: #fafaf0; }

#group-panel-list {
  overflow-y: auto;
  flex: 1;
}
#group-panel-list::-webkit-scrollbar { width: 4px; }
#group-panel-list::-webkit-scrollbar-track { background: transparent; }
#group-panel-list::-webkit-scrollbar-thumb { background: #44403c; border-radius: 2px; }

/* ── Responsive ── */
@media (max-width: 640px) {
  #panel { display: none; }
  #group-panel { display: none !important; }
  #mobile-card { display: block; }
  #right-col { top: 8px; right: 8px; }
  .ctrl-btn { padding: 6px 10px; font-size: 12px; }
  #date-panel { min-width: 0; }
}

/* ── MapLibre popup overrides ── */
.maplibregl-popup-content {
  background: #292524;
  color: #fafaf0;
  border: 1px solid #44403c;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.maplibregl-popup-tip { display: none; }
.maplibregl-popup-close-button { color: #a8a29e; font-size: 16px; }
