/* ============ WiGLE Explorer — dark dashboard theme ============ */
:root {
  --bg: #0b0f14;
  --bg-2: #10161e;
  --bg-3: #161e28;
  --border: #232d3a;
  --text: #dbe4ee;
  --text-dim: #8496ab;
  --accent: #38bdf8;
  --accent-2: #22d3ee;
  --good: #4ade80;
  --radius: 10px;
  --mono: "SF Mono", "Cascadia Code", Consolas, monospace;
}

* { 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, Inter, sans-serif;
  font-size: 14px;
}

.hidden { display: none !important; }
.mono { font-family: var(--mono); font-size: 12px; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; border-radius: 8px; border: 1px solid transparent;
  font-size: 14px; font-weight: 600; cursor: pointer; color: var(--text);
  background: var(--bg-3); transition: all .15s ease;
}
.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn-primary { background: linear-gradient(135deg, #0284c7, #0891b2); color: #fff; }
.btn-primary:hover { filter: brightness(1.15); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-3); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; margin-top: 8px; }

.icon-btn {
  background: none; border: none; color: var(--text); font-size: 18px;
  cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.icon-btn:hover { background: var(--bg-3); }

/* ---------------- Dropzone ---------------- */
.dropzone {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, #11202f 0%, var(--bg) 70%);
  transition: opacity .25s ease;
}
.dropzone.dragging { outline: 3px dashed var(--accent); outline-offset: -14px; }
.dropzone-card {
  max-width: 560px; text-align: center; padding: 48px 40px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.dropzone-icon { font-size: 52px; margin-bottom: 10px; }
.dropzone-card h1 { font-size: 28px; margin-bottom: 12px; }
.dropzone-card p { color: var(--text-dim); line-height: 1.55; }
.dropzone-actions { display: flex; gap: 12px; justify-content: center; margin: 26px 0 16px; }
.dropzone-hint { font-size: 11.5px; color: #5a6a7d !important; }

/* ---------------- File staging (combine CSVs) ---------------- */
.staging {
  margin-top: 6px; padding: 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg);
  animation: fadeUp .25s ease;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.staging-list { display: flex; flex-direction: column; gap: 6px; max-height: 180px; overflow-y: auto; }
.staging-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 8px;
  background: var(--bg-3); border: 1px solid var(--border);
  animation: fadeUp .2s ease;
}
.staging-file {
  flex: 1; text-align: left; font-size: 12.5px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.staging-count { color: var(--accent); font-size: 11.5px; white-space: nowrap; }
.staging-remove {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 12px; padding: 2px 6px; border-radius: 4px;
}
.staging-remove:hover { color: #f87171; background: rgba(248,113,113,.1); }

.staging-footer {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border);
}
.staging-total { color: var(--text-dim); font-size: 11.5px; }
.staging-btns { display: flex; gap: 8px; align-items: center; }

/* ---------------- Toasts ---------------- */
.toasts {
  position: fixed; right: 18px; bottom: 18px; z-index: 2000;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  padding: 11px 16px; border-radius: 10px; max-width: 360px;
  background: var(--bg-3); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); color: var(--text);
  font-size: 12.5px; line-height: 1.5;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
  opacity: 0; transform: translateY(10px);
  transition: opacity .25s ease, transform .25s ease;
}
.toast.show { opacity: 1; transform: none; }
.toast-error { border-left-color: #f87171; }
.toast-warn { border-left-color: #fbbf24; }
.toast b { color: var(--accent); }

/* ---------------- App shell ---------------- */
.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--bg-2);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand-icon { font-size: 20px; }
.brand-name { font-weight: 700; font-size: 16px; }
.dataset-name { color: var(--text-dim); font-size: 12px; font-family: var(--mono); }

.search-wrap { flex: 1; position: relative; max-width: 640px; margin: 0 auto; }
#globalSearch {
  width: 100%; padding: 9px 90px 9px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font-size: 13.5px; outline: none;
}
#globalSearch:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56,189,248,.15); }
.search-count {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  font-family: var(--mono); font-size: 11.5px; color: var(--accent);
}
.topbar-actions { display: flex; gap: 8px; white-space: nowrap; }

.main { display: flex; flex: 1; min-height: 0; }

/* ---------------- Sidebar ---------------- */
.sidebar {
  width: 250px; flex-shrink: 0; overflow-y: auto;
  background: var(--bg-2); border-right: 1px solid var(--border);
  padding: 16px; display: flex; flex-direction: column; gap: 18px;
  transition: margin-left .2s ease;
}
.sidebar.collapsed { margin-left: -250px; }
.side-section h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-dim); margin-bottom: 8px;
}
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.type-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg); cursor: pointer; font-size: 12px; user-select: none;
  transition: all .12s ease;
}
.type-chip .dot { width: 9px; height: 9px; border-radius: 50%; }
.type-chip .count { font-family: var(--mono); font-size: 10.5px; color: var(--text-dim); }
.type-chip.active { border-color: var(--chip-color, var(--accent)); background: rgba(56,189,248,.08); }
.type-chip.active .count { color: var(--text); }

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

.date-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.date-grid label { font-size: 11px; color: var(--text-dim); }
.date-grid input { margin-top: 3px; font-size: 12px; }

.slider-row { display: flex; align-items: center; gap: 10px; }
.slider-row input[type=range] { flex: 1; accent-color: var(--accent); }
.slider-labels {
  display: flex; justify-content: space-between;
  font-family: var(--mono); font-size: 9.5px; color: #5a6a7d; margin-top: 2px;
}

.check-row { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 12.5px; }
.check-row input { accent-color: var(--accent); }

.filter-summary { color: var(--text-dim); line-height: 1.5; padding-top: 6px; border-top: 1px solid var(--border); }

/* ---------------- Content ---------------- */
.content { flex: 1; display: flex; flex-direction: column; min-width: 0; padding: 14px; gap: 12px; overflow: hidden; }

.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stat-card {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px;
}
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); }
.stat-value { font-size: 22px; font-weight: 700; margin-top: 4px; font-family: var(--mono); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tab {
  padding: 8px 18px; background: none; border: none; color: var(--text-dim);
  font-size: 13.5px; font-weight: 600; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-panel { display: none; flex: 1; min-height: 0; flex-direction: column; gap: 8px; }
.tab-panel.active { display: flex; }

/* ---------------- Map ---------------- */
.map-toolbar { display: flex; align-items: center; gap: 14px; }
.map-hint { font-size: 12px; color: var(--text-dim); font-family: var(--mono); margin-left: auto; }

/* ---------------- City lookup ---------------- */
.city-search { position: relative; width: 240px; }
#citySearch {
  width: 100%; padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font-size: 12.5px; outline: none;
}
#citySearch:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56,189,248,.15); }
.city-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 1500;
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 36px rgba(0,0,0,.6); overflow: hidden;
}
.city-result {
  padding: 9px 12px; cursor: pointer; font-size: 12px; line-height: 1.4;
  border-bottom: 1px solid #1a2330;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.city-result:last-child { border-bottom: none; }
.city-result:hover, .city-result.hl { background: rgba(56,189,248,.1); }
.city-result .cr-type { color: var(--text-dim); font-size: 10.5px; font-family: var(--mono); }
.city-empty { padding: 9px 12px; font-size: 12px; color: var(--text-dim); }
#map {
  flex: 1; min-height: 320px; border-radius: var(--radius);
  border: 1px solid var(--border); z-index: 1; background: #0d1117;
}
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--bg-3); color: var(--text); border: 1px solid var(--border);
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
}
.leaflet-popup-content { font-size: 12.5px; line-height: 1.6; margin: 10px 14px; }
.leaflet-popup-content b { color: var(--accent); }
.leaflet-popup-content .pop-grid { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-family: var(--mono); font-size: 11.5px; }
.leaflet-popup-content .pop-k { color: var(--text-dim); }

.marker-dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.85);
  box-shadow: 0 0 6px rgba(0,0,0,.6);
}

/* ---------------- Charts ---------------- */
.charts-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  flex: 1; min-height: 0; overflow-y: auto; padding-bottom: 8px;
}
.chart-card {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; min-height: 260px;
  display: flex; flex-direction: column;
}
.chart-card h4 { font-size: 13px; color: var(--text-dim); margin-bottom: 8px; }
.chart-card canvas { flex: 1; min-height: 0; }

/* ---------------- Table ---------------- */
.table-wrap {
  flex: 1; min-height: 0; overflow: auto;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-2);
}
#dataTable { width: 100%; border-collapse: collapse; font-size: 12.5px; }
#dataTable th {
  position: sticky; top: 0; z-index: 2; text-align: left;
  background: var(--bg-3); padding: 9px 12px; cursor: pointer;
  border-bottom: 1px solid var(--border); white-space: nowrap; user-select: none;
}
#dataTable th:hover { color: var(--accent); }
#dataTable th .arrow { font-size: 10px; color: var(--accent); }
#dataTable td {
  padding: 7px 12px; border-bottom: 1px solid #1a2330;
  font-family: var(--mono); font-size: 11.5px; white-space: nowrap;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis;
}
#dataTable tbody tr { cursor: pointer; }
#dataTable tbody tr:hover { background: rgba(56,189,248,.07); }
.tt { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }

.table-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 2px 4px;
}
.table-note { font-size: 12px; color: var(--text-dim); }

/* ---------------- Scrollbars ---------------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #2a3646; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #37485e; }

/* ---------------- Responsive ---------------- */
@media (max-width: 900px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .brand-name { display: none; }
  .sidebar { position: absolute; z-index: 500; height: calc(100% - 53px); margin-left: 0; box-shadow: 8px 0 24px rgba(0,0,0,.5); }
  .sidebar.collapsed { margin-left: -260px; }
}
