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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #222636;
  --border: #2e3350;
  --accent: #4f7ef8;
  --accent-dim: #2a3f7a;
  --text: #e2e6f0;
  --text-dim: #7a82a0;
  --tag-bg: #1e2640;
  --tag-text: #8fa8f8;
  --green: #3ecf8e;
  --orange: #f59e0b;
  --red: #f87171;
  --purple: #a78bfa;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 14px;
}

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}
header h1 { font-size: 15px; font-weight: 600; color: var(--text); letter-spacing: 0.01em; }
.header-source-link {
  display: flex; align-items: center; gap: 4px; color: var(--text-dim);
  font-size: 11px; opacity: 0.5; transition: opacity 0.15s, color 0.15s; flex-shrink: 0;
  text-decoration: none;
}
.header-source-link:hover { opacity: 1; color: var(--accent); }
.header-info {
  display: flex; gap: 12px; align-items: center;
  align-self: stretch;
  border-left: 1px solid var(--border); padding-left: 16px;
}
.header-info span { font-size: 12px; color: var(--text-dim); }
.header-info strong { color: var(--text); }
header .meta { display: flex; gap: 12px; margin-left: auto; align-items: center; }

/* ── Drop zone ── */
/* ── Drop screen ── */
#drop-screen { flex: 1; display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; padding: 60px 24px; position: relative; }
.drop-layout { display: flex; flex-direction: column; align-items: center; gap: 0; margin: auto; }
.drop-title { font-size: 32px; font-weight: 300; color: var(--text-dim); letter-spacing: -0.01em; margin-bottom: 12px; }
.drop-title span { font-weight: 700; color: var(--text); }
.drop-tagline { font-size: 14px; color: var(--text-dim); text-align: center; max-width: 520px; line-height: 1.6; margin-bottom: 40px; }
.drop-cols { display: flex; flex-direction: row; gap: 16px; align-items: flex-start; }
.drop-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 28px;
}
.drop-box {
  width: 380px; flex-shrink: 0;
  border: 2px dashed var(--border);
  display: flex; flex-direction: column; gap: 14px;
}
.drop-box.drag-over { border-color: var(--accent); background: rgba(79,126,248,0.04); }
.drop-load-title {
  font-size: 13px; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.url-row { display: flex; gap: 8px; }
.url-row input {
  flex: 1; min-width: 0; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 13px; outline: none;
  transition: border-color 0.15s;
}
.url-row input:focus { border-color: var(--accent); }
.url-row input::placeholder { color: var(--text-dim); }
.btn-load { white-space: nowrap; }
.drop-divider {
  display: flex; align-items: center; gap: 10px; color: var(--text-dim); font-size: 12px;
}
.drop-divider::before, .drop-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.drop-file-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
}
.drop-hint { font-size: 11px; color: var(--text-dim); text-align: center; }

.btn {
  padding: 8px 18px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text); font-size: 13px;
  cursor: pointer; transition: background 0.15s, border-color 0.15s; font-family: inherit;
}
.btn:hover { background: var(--accent-dim); border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #3d6de0; }
#file-input { display: none; }

/* ── Schemas panel ── */
.drop-schemas { width: 420px; flex-shrink: 0; }
.drop-schemas-title {
  font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-dim); margin-bottom: 20px;
}
#schema-items { display: flex; flex-direction: column; gap: 24px; overflow-y: auto; flex: 1; padding-right: 4px; }
#schema-items::-webkit-scrollbar { width: 4px; }
#schema-items::-webkit-scrollbar-track { background: transparent; }
#schema-items::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.schema-group { display: flex; flex-direction: column; gap: 10px; }
.schema-provider {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-dim); margin-bottom: 2px;
}
.schema-btns { display: flex; flex-direction: column; gap: 8px; }
.schema-item-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  width: 100%; padding: 13px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface2);
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
  font-family: inherit; text-align: left;
}
.schema-item-btn:hover { background: var(--accent-dim); border-color: var(--accent); }
.schema-item-name { font-size: 14px; font-weight: 600; color: var(--text); }
.schema-item-desc { font-size: 12px; color: var(--text-dim); }

/* ── Main 3-column layout ── */
#main { flex: 1; display: none; overflow: hidden; }
#main.visible { display: flex; }

/* ── Sidebar (col 1) ── */
#sidebar {
  width: 240px; flex-shrink: 0;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface); overflow: hidden;
}
.sidebar-title { padding: 14px 14px 10px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim); flex-shrink: 0; }
.sidebar-header { padding: 0 14px 10px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.sidebar-header .search-wrap { position: relative; }
.sidebar-header input {
  width: 100%; padding: 7px 10px 7px 32px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font-size: 13px; outline: none; transition: border-color 0.15s;
}
.sidebar-header input:focus { border-color: var(--accent); }
.sidebar-header input::placeholder { color: var(--text-dim); }
.search-icon {
  position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  color: var(--text-dim); pointer-events: none;
}
.layer-count { font-size: 11px; color: var(--text-dim); margin-top: 8px; padding: 0 2px; }
#layer-list { overflow-y: auto; flex: 1; }
#layer-list::-webkit-scrollbar { width: 5px; }
#layer-list::-webkit-scrollbar-track { background: transparent; }
#layer-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.layer-item {
  padding: 10px 14px; cursor: pointer;
  border-bottom: 1px solid var(--border); transition: background 0.1s;
}
.layer-item:hover { background: var(--surface2); }
.layer-item.active { background: var(--accent-dim); border-left: 3px solid var(--accent); padding-left: 11px; }
.layer-item .name { font-size: 13px; font-weight: 500; color: var(--text); word-break: break-all; }
.layer-item .badges { display: flex; gap: 5px; margin-top: 5px; flex-wrap: wrap; }
.badge {
  font-size: 10px; padding: 2px 6px; border-radius: 4px;
  background: var(--tag-bg); color: var(--tag-text);
  border: 1px solid var(--border); white-space: nowrap;
}
.badge.geom { color: var(--green); }
.badge.zoom { color: var(--orange); }
.badge.fields { color: var(--purple); }

/* ── Detail panel (col 2) ── */
#detail {
  width: 340px; flex-shrink: 0;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border); overflow: hidden;
}
#detail-scroll { flex: 1; overflow-y: auto; padding: 20px; }
#detail-scroll::-webkit-scrollbar { width: 6px; }
#detail-scroll::-webkit-scrollbar-track { background: transparent; }
#detail-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
#detail .empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; color: var(--text-dim); gap: 10px;
}
#detail .empty svg { opacity: 0.3; }
.detail-title { font-size: 18px; font-weight: 700; margin-bottom: 6px; word-break: break-all; }
.detail-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 20px; }
.section-title {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-dim); margin-bottom: 10px;
}
.fields-grid { display: flex; flex-direction: column; gap: 8px; }
.field-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; transition: border-color 0.15s;
}
.field-card:hover { border-color: var(--accent-dim); }
.field-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.field-name { font-size: 13px; font-weight: 600; color: var(--accent); font-family: 'SF Mono', 'Fira Code', monospace; }
.field-type {
  font-size: 11px; color: var(--text-dim); font-family: 'SF Mono', 'Fira Code', monospace;
  background: var(--bg); padding: 2px 6px; border-radius: 4px; border: 1px solid var(--border);
}
.field-count { margin-left: auto; font-size: 11px; color: var(--text-dim); }
.field-values { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.value-tag {
  font-size: 11px; padding: 3px 8px; border-radius: 5px;
  background: var(--tag-bg); color: var(--tag-text);
  border: 1px solid var(--border); font-family: 'SF Mono', 'Fira Code', monospace;
  cursor: pointer; transition: border-color 0.15s, background 0.15s, color 0.15s;
  user-select: none;
}
.value-tag:hover { border-color: var(--accent); }
.value-tag.selected { background: var(--accent); border-color: var(--accent); color: #fff; }
.no-values { font-size: 12px; color: var(--text-dim); font-style: italic; }

/* ── Map container (col 3) ── */
#map-container { flex: 1; position: relative; overflow: hidden; }
#map { width: 100%; height: 100%; background: var(--bg); }
.map-no-tiles {
  width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-dim); gap: 12px; text-align: center; padding: 40px;
}
.map-no-tiles svg { opacity: 0.25; }
.map-no-tiles p { font-size: 13px; line-height: 1.6; }

/* Geocoder */
#geocoder-bar {
  position: absolute; top: 12px; right: 12px; z-index: 10;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4); backdrop-filter: blur(8px);
  width: 240px;
}
#geocoder-bar svg { color: var(--text-dim); flex-shrink: 0; }
#geocoder-input {
  background: none; border: none; outline: none;
  color: var(--text); font-size: 13px; flex: 1; font-family: inherit;
}
#geocoder-input::placeholder { color: var(--text-dim); }
#geocoder-results {
  display: none; list-style: none; width: 100%;
  border-top: 1px solid var(--border); margin: 4px -10px -6px; padding: 4px 0;
}
#geocoder-results.open { display: block; }
#geocoder-results li {
  padding: 7px 10px; font-size: 12px; cursor: pointer; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background 0.1s;
}
#geocoder-results li:hover, #geocoder-results li.active { background: var(--surface2); }

/* Breadcrumb */
#map-breadcrumb {
  position: absolute; top: 12px; left: 12px;
  background: rgba(26,29,39,0.88); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 12px;
  font-size: 12px; align-items: center; gap: 5px;
  z-index: 10; backdrop-filter: blur(8px); white-space: nowrap;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}
.bc-sep { color: var(--text-dim); opacity: 0.4; padding: 0 1px; }
.bc-layer { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; }
.bc-layer.clickable { color: var(--text-dim); cursor: pointer; transition: color 0.15s; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; text-decoration-color: rgba(122,130,160,0.6); }
.bc-layer.clickable:hover { color: var(--text); text-decoration-color: var(--text); }
.bc-layer.current { color: var(--text); }
.bc-filter { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; color: var(--accent); }

.bc-zoom { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; color: var(--text-dim); }
.bc-zoom span { color: var(--text); }
.bc-zoom-sep { color: var(--text-dim); opacity: 0.25; padding: 0 6px; font-size: 14px; }

/* Bounds alert */
#map-bounds-alert {
  position: absolute; bottom: 48px; left: 50%; transform: translateX(-50%);
  background: rgba(79,126,248,0.95); color: #fff;
  border-radius: 10px; padding: 10px 14px;
  font-size: 12px; display: none; align-items: center; gap: 10px;
  z-index: 10; backdrop-filter: blur(8px); white-space: nowrap;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
}
#map-bounds-alert svg { flex-shrink: 0; }
#map-bounds-alert span { line-height: 1.4; white-space: normal; max-width: 220px; }

/* Zoom alert */
#map-zoom-alert {
  position: absolute; bottom: 48px; left: 50%; transform: translateX(-50%);
  background: rgba(245,158,11,0.95); color: #1a1000;
  border-radius: 10px; padding: 10px 14px;
  font-size: 12px; display: none; align-items: center; gap: 10px;
  z-index: 10; backdrop-filter: blur(8px); white-space: nowrap;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
}
#map-zoom-alert svg { flex-shrink: 0; }
#map-zoom-alert span { line-height: 1.4; white-space: normal; max-width: 220px; }
#map-zoom-alert button {
  background: rgba(0,0,0,0.15); border: none; color: inherit; cursor: pointer;
  border-radius: 6px; padding: 4px 10px; font-size: 11px; font-weight: 600;
  font-family: inherit; flex-shrink: 0; transition: background 0.15s;
}
#map-zoom-alert button:hover { background: rgba(0,0,0,0.25); }

/* Reset button */
#reset-btn { font-size: 12px; padding: 5px 12px; }

/* Lang select */
.lang-select {
  padding: 4px 8px; font-size: 11px; font-weight: 600;
  letter-spacing: 0.05em; cursor: pointer; appearance: none;
  -webkit-appearance: none; text-align: center;
}

/* ── MapLibre dark theme ── */
.maplibregl-popup-content {
  background: var(--surface) !important; color: var(--text) !important;
  border: 1px solid var(--border) !important; border-radius: 8px !important;
  font-size: 12px !important; padding: 10px 12px !important;
  max-width: 380px !important; max-height: 340px !important; overflow-y: auto !important;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6) !important; font-family: inherit !important;
}
.maplibregl-popup-close-button { color: var(--text-dim) !important; font-size: 16px !important; padding: 4px 8px !important; }
.maplibregl-popup-close-button:hover { color: var(--text) !important; background: transparent !important; }
.maplibregl-popup-tip { border-top-color: var(--border) !important; }
.popup-layer-name {
  font-weight: 600; font-size: 12px; margin-bottom: 7px;
  color: var(--accent); font-family: 'SF Mono', 'Fira Code', monospace;
  padding-bottom: 6px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: opacity 0.15s;
}
.popup-layer-name:hover { opacity: 0.7; }
.popup-attrs { display: flex; flex-direction: column; gap: 5px; }
.popup-attr { display: flex; align-items: center; gap: 8px; }
.popup-attr-key { color: var(--text-dim); font-size: 11px; flex-shrink: 0; min-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.popup-empty { color: var(--text-dim); font-style: italic; }
.popup-picker {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.popup-picker-title {
  width: 100%; font-size: 10px; font-weight: 600; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--text-dim); margin-bottom: 4px;
}
.popup-picker-btn {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 4px;
  color: var(--text-dim); font-size: 10px; font-family: 'SF Mono', 'Fira Code', monospace;
  padding: 2px 7px; cursor: pointer; white-space: nowrap;
}
.popup-picker-btn:hover { border-color: var(--accent); color: var(--text); }
.popup-picker-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.maplibregl-ctrl-group { background: var(--surface) !important; border: 1px solid var(--border) !important; border-radius: 8px !important; box-shadow: 0 2px 10px rgba(0,0,0,0.4) !important; overflow: hidden; }
.maplibregl-ctrl-group button { background-color: var(--surface) !important; color: var(--text) !important; border: none !important; border-bottom: 1px solid var(--border) !important; }
.maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1) opacity(0.7); }
.maplibregl-ctrl-group button:hover .maplibregl-ctrl-icon { filter: invert(1) opacity(1); }
.maplibregl-ctrl-group button:last-child { border-bottom: none !important; }
.maplibregl-ctrl-group button:hover { background-color: var(--surface2) !important; }
.maplibregl-ctrl-attrib { background: rgba(26,29,39,0.8) !important; color: var(--text-dim) !important; }
.maplibregl-ctrl-attrib a { color: var(--text-dim) !important; }

/* ── Help modal ── */
#help-modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.help-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.65); backdrop-filter: blur(4px);
}
.help-dialog {
  position: relative; z-index: 1;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; width: 92%; max-width: 860px;
  max-height: 86vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7);
}
.help-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.help-header h2 { font-size: 15px; font-weight: 600; }
.help-close {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  padding: 4px; border-radius: 6px; display: flex; transition: color 0.15s;
}
.help-close:hover { color: var(--text); }
.help-body {
  flex: 1; display: flex; overflow: hidden;
}
.help-body-left {
  flex: 1; overflow-y: auto; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 8px;
  border-right: 1px solid var(--border);
}
.help-body-left::-webkit-scrollbar { width: 5px; }
.help-body-left::-webkit-scrollbar-track { background: transparent; }
.help-body-left::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.help-body-right {
  width: 300px; flex-shrink: 0; overflow-y: auto;
  padding: 14px 16px; display: flex; flex-direction: column; gap: 14px;
}
.help-body-right::-webkit-scrollbar { width: 5px; }
.help-body-right::-webkit-scrollbar-track { background: transparent; }
.help-body-right::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.help-section {
  display: flex; gap: 14px; align-items: flex-start;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px;
}
.help-icon { color: var(--accent); flex-shrink: 0; margin-top: 1px; }
.help-section-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 3px; }
.help-section-body { font-size: 12px; color: var(--text-dim); line-height: 1.6; }
.help-footer {
  padding: 12px 16px; border-top: 1px solid var(--border); flex-shrink: 0;
  display: flex; justify-content: flex-end;
}
.help-open-btn { font-size: 12px; padding: 5px 12px; }
.help-screenshot { display: flex; flex-direction: column; gap: 6px; }
.help-screenshot img {
  width: 100%; border-radius: 8px; border: 1px solid var(--border); display: block;
  cursor: zoom-in; transition: opacity 0.15s;
}
.help-screenshot img:hover { opacity: 0.85; }
.help-screenshot figcaption {
  font-size: 11px; color: var(--text-dim); text-align: center; line-height: 1.4;
}

/* ── Lightbox ── */
#lightbox {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.88); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  cursor: zoom-out;
}
#lightbox img {
  max-width: 92vw; max-height: 90vh;
  border-radius: 10px; border: 1px solid var(--border);
  box-shadow: 0 24px 80px rgba(0,0,0,0.8);
}

/* ── Toast ── */
#error-toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #3b1f1f; border: 1px solid var(--red); color: var(--red);
  padding: 10px 20px; border-radius: 8px; font-size: 13px;
  display: none; z-index: 100;
}
