:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #38bdf8;
  --primary-dark: #0ea5e9;
  --accent: #22d3ee;
  --success: #4ade80;
  --warning: #fbbf24;
  --danger: #f87171;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Navbar */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
}

.brand-icon {
  font-size: 22px;
}

.nav-links {
  display: flex;
  gap: 4px;
}

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  transition: all 0.2s;
}

.nav-link:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.nav-link.active {
  color: var(--primary);
  background: rgba(56, 189, 248, 0.1);
}

/* Main */
.main-content {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 4px;
}

.page-header p {
  color: var(--text-muted);
  font-size: 14px;
}

/* Stats cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.stat-label {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
}

/* Charts */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.chart-card h3 {
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 12px;
  color: var(--text-muted);
}

.chart-wide {
  grid-column: 1 / -1;
}

.chart-container {
  height: 360px;
}

/* Search */
.search-box {
  display: flex;
  gap: 8px;
}

.search-box input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.search-box input:focus {
  border-color: var(--primary);
}

.search-box button,
.btn-secondary {
  padding: 10px 18px;
  background: var(--primary);
  color: #0f172a;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

.search-box button:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text);
}

.btn-secondary:hover {
  background: #475569;
}

.filter-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.filter-row select {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}

/* Query page */
.query-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.query-search {
  margin-bottom: 12px;
}

.query-result-info {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 12px;
}

/* Table */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  background: var(--bg-card);
  padding: 12px 14px;
  text-align: left;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-table tr:hover td {
  background: var(--bg-hover);
}

.btn-link {
  color: var(--primary);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  padding: 0;
}

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

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 16px;
}

.pagination button {
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}

.pagination button:hover {
  background: var(--bg-hover);
}

.pagination button.active {
  background: var(--primary);
  color: #0f172a;
  border-color: var(--primary);
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}

.modal.open {
  display: flex;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 640px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
}

.detail-grid {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 8px 16px;
  font-size: 14px;
  margin-bottom: 16px;
}

.detail-label {
  color: var(--text-muted);
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag {
  background: rgba(56, 189, 248, 0.15);
  color: var(--primary);
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 12px;
}

/* Map layout */
.map-layout {
  display: flex;
  height: calc(100vh - 56px - 40px);
  margin: -24px;
  max-width: none;
}

.map-sidebar {
  width: 360px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.search-panel {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.search-panel h3 {
  font-size: 15px;
  margin-bottom: 12px;
}

.map-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.map-actions button {
  flex: 1;
  font-size: 13px;
  padding: 8px;
}

.search-result-info {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.result-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.result-item {
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  border: 1px solid transparent;
  margin-bottom: 4px;
  transition: all 0.15s;
}

.result-item:hover {
  background: var(--bg-hover);
}

.result-item.active {
  border-color: var(--primary);
  background: rgba(56, 189, 248, 0.08);
}

.result-item .item-name {
  font-weight: 500;
  margin-bottom: 2px;
}

.result-item .item-meta {
  color: var(--text-muted);
  font-size: 12px;
}

.map-container {
  flex: 1;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
}

/* Footer */
.footer {
  text-align: center;
  padding: 10px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* Leaflet overrides */
.leaflet-popup-content-wrapper {
  border-radius: 8px !important;
  font-family: inherit;
}

.leaflet-popup-content {
  margin: 12px 14px !important;
  font-size: 13px;
  line-height: 1.5;
}

.popup-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.popup-meta {
  color: #64748b;
  font-size: 12px;
}

.popup-area {
  margin-top: 4px;
  color: #0ea5e9;
  font-size: 12px;
}

/* Highlight marker */
.marker-highlight {
  filter: hue-rotate(200deg) saturate(3);
  transform: scale(1.3);
}

/* Responsive */
@media (max-width: 900px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .charts-grid {
    grid-template-columns: 1fr;
  }

  .map-layout {
    flex-direction: column;
    height: auto;
  }

  .map-sidebar {
    width: 100%;
    max-height: 300px;
  }

  .map-container {
    height: 60vh;
  }
}
