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

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #111; color: #e8e8e8; overflow: hidden; height: 100dvh; }

#map { position: absolute; inset: 0; }

/* ── Modal ── */
#key-modal {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.85);
  display: flex; align-items: center; justify-content: center;
}
#key-modal.hidden { display: none; }

.modal-box {
  background: #1e2027; border: 1px solid #333; border-radius: 10px;
  padding: 28px 32px; width: min(420px, 92vw);
}
.modal-box h2 { font-size: 1.15rem; margin-bottom: 8px; color: #fff; }
.modal-box p  { font-size: .85rem; color: #aaa; margin-bottom: 16px; line-height: 1.5; }
.modal-box a  { color: #5aacff; text-decoration: none; }
.modal-box a:hover { text-decoration: underline; }
.modal-box input {
  width: 100%; padding: 10px 12px; border-radius: 6px;
  border: 1px solid #444; background: #111; color: #fff;
  font-size: .9rem; margin-bottom: 12px; outline: none;
}
.modal-box input:focus { border-color: #5aacff; }
.modal-box button {
  width: 100%; padding: 10px; border-radius: 6px; border: none;
  background: #2563eb; color: #fff; font-size: .9rem; font-weight: 600;
  cursor: pointer; transition: background .15s;
}
.modal-box button:hover { background: #1d4ed8; }

/* ── Panel ── */
#panel {
  position: absolute; top: 12px; left: 12px; z-index: 100;
  width: 264px; background: #1e2027cc; backdrop-filter: blur(10px);
  border: 1px solid #333; border-radius: 10px; overflow: hidden;
}
#panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid #2a2d38;
}
.panel-title { font-weight: 700; font-size: .95rem; letter-spacing: .5px; }
.header-btns { display: flex; align-items: center; gap: 2px; }

#warn-btn {
  background: none; border: none; color: #f59e0b; cursor: pointer;
  padding: 2px 5px; border-radius: 4px; line-height: 1;
  display: flex; align-items: center;
}
#warn-btn:hover { background: #ffffff15; }
#warn-btn svg { width: 15px; height: 15px; }

#panel-toggle {
  background: none; border: none; color: #aaa; font-size: 1.1rem;
  cursor: pointer; line-height: 1; padding: 2px 4px; border-radius: 4px;
}
#panel-toggle:hover { background: #ffffff15; color: #fff; }

#warn-popup {
  padding: 8px 14px; border-bottom: 1px solid #5a4200;
  background: #2a2206; font-size: .7rem; color: #c9a84c; line-height: 1.5;
}
#warn-popup.hidden { display: none; }

#panel-body {
  padding: 12px 14px 14px;
  max-height: calc(100dvh - 90px);
  overflow-y: auto;
}
#panel-body.collapsed { display: none; }

.section-label {
  font-size: .62rem; font-weight: 700; letter-spacing: 1.3px;
  color: #888; margin: 8px 0 5px; text-transform: uppercase;
  border-top: 1px solid #2a2d38; padding-top: 8px;
}
.section-label:first-child { border-top: none; padding-top: 0; margin-top: 0; }

.layer-row {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; padding: 3px 2px; font-size: .83rem; color: #ddd;
  user-select: none;
}
.layer-row input[type=checkbox] { width: 15px; height: 15px; accent-color: #2563eb; cursor: pointer; flex-shrink: 0; }
.layer-row span:last-child { flex: 1; }

/* ── Dots ── */
.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot-nats     { background: linear-gradient(135deg, #ef4444 50%, #60a5fa 50%); }
.dot-frz      { background: #ef4444; }
.dot-danger   { background: #f97316; }
.dot-military { background: #64748b; }
.dot-parks    { background: #22c55e; }
.dot-royal    { background: #a855f7; }
.dot-sssi     { background: #06b6d4; }
.dot-forestry { background: #4d7c0f; }

.layer-row-outer {
  display: flex; align-items: center; gap: 4px;
}
.layer-row-outer .layer-row { flex: 1; }

.layer-note {
  font-size: .7rem; color: #888; margin: 1px 0 4px 23px; line-height: 1.4;
}
.layer-note a { color: #5aacff; text-decoration: none; }
.layer-note a:hover { text-decoration: underline; }

/* ── Style row ── */
.style-row { display: flex; gap: 6px; margin-top: 4px; }
.style-btn {
  flex: 1; padding: 6px 4px; border-radius: 6px; border: 1px solid #333;
  background: #2a2d38; color: #aaa; font-size: .75rem; cursor: pointer;
  transition: all .15s;
}
.style-btn:hover { background: #34384a; color: #fff; }
.style-btn.active { background: #2563eb; border-color: #2563eb; color: #fff; }

/* ── Toggle rows (3D, Hillshade) ── */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 7px; padding: 2px 1px; font-size: .82rem; color: #ccc;
}
.hint { font-size: .68rem; color: #888; }

.switch { position: relative; display: inline-block; width: 36px; height: 20px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute; inset: 0; border-radius: 20px;
  background: #2a2d38; border: 1px solid #444;
  transition: background .2s, border-color .2s; cursor: pointer;
}
.switch input:checked ~ .switch-track { background: #2563eb; border-color: #2563eb; }
.switch-thumb {
  position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: #888; transition: transform .2s, background .2s;
}
.switch input:checked ~ .switch-track .switch-thumb { transform: translateX(16px); background: #fff; }

/* ── Load data ── */
.layer-select {
  width: 100%; margin-top: 5px; padding: 7px 8px; border-radius: 6px;
  border: 1px solid #333; background: #2a2d38; color: #ccc;
  font-size: .75rem; cursor: pointer; appearance: none; outline: none;
}
.layer-select:focus { border-color: #555; }

.load-btn {
  padding: 7px 10px; border-radius: 6px;
  border: 1px solid #333; background: #2a2d38;
  color: #ccc; font-size: .75rem; cursor: pointer; white-space: nowrap;
  transition: background .15s;
}
.load-btn:hover { background: #34384a; color: #fff; }
.load-btn-full { display: block; width: 100%; margin-top: 5px; text-align: center; }

/* ── Progress bar ── */
.progress-bar {
  height: 4px; border-radius: 2px; background: #2a2d38;
  overflow: hidden; margin-bottom: 4px;
}
.progress-bar.hidden { display: none; }
.progress-fill {
  height: 100%; border-radius: 2px;
  background: linear-gradient(90deg, #f59e0b, #ef4444);
  width: 0%; transition: width .2s ease;
}

/* ── NATS type filter grid ── */
.nats-type-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 2px 4px; margin: 3px 0 3px 22px;
}
.type-cell { display: flex; align-items: center; gap: 2px; }
.type-check {
  display: flex; align-items: center; gap: 3px; flex: 1;
  font-size: .7rem; cursor: pointer; user-select: none; color: #999;
}
.type-check input[type=checkbox] { width: 11px; height: 11px; cursor: pointer; flex-shrink: 0; }
.tc-r   { color: #ef4444; font-weight: 600; }
.tc-ctr { color: #facc15; font-weight: 600; }
.tc-cta { color: #60a5fa; font-weight: 600; }
.tc-ras { color: #818cf8; font-weight: 600; }
.tc-tmz { color: #c084fc; font-weight: 600; }

.info-btn {
  width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0;
  border: none; background: none;
  color: #888; cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
  transition: color .15s;
}
.info-btn:hover { color: #5aacff; }
.info-btn.active { color: #5aacff; }
.info-btn svg { width: 13px; height: 13px; }

.type-all-row {
  display: flex; gap: 6px; margin: 4px 0 2px 22px;
}
.type-all-btn {
  flex: 1; padding: 4px 6px; border-radius: 5px;
  border: 1px solid #333; background: #2a2d38;
  color: #bbb; font-size: .68rem; cursor: pointer;
  transition: background .15s, color .15s;
}
.type-all-btn:hover { background: #34384a; color: #fff; }

.type-info-box {
  margin: 4px 0 4px 22px; padding: 6px 8px; border-radius: 5px;
  background: #1a1d24; border: 1px solid #2a2d38;
  font-size: .7rem; color: #aaa; line-height: 1.45;
}
.type-info-box.hidden { display: none; }

.data-links {
  margin-top: 7px; font-size: .68rem; color: #888; line-height: 1.9;
}
.data-links a { color: #5aacff; text-decoration: none; }
.data-links a:hover { text-decoration: underline; }

/* ── Locate button (inside panel) ── */
#locate-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; margin-top: 4px; padding: 8px 8px; border-radius: 6px;
  border: 1px solid #333; background: #2a2d38;
  color: #ccc; font-size: .83rem; cursor: pointer; text-align: left;
  transition: background .15s, color .15s, border-color .15s;
}
#locate-btn:hover { background: #34384a; color: #fff; }
#locate-btn.locating { color: #2563eb; border-color: #2563eb44; animation: btn-pulse 1s infinite; }
#locate-btn.tracking { color: #2563eb; border-color: #2563eb55; background: #1a2f5a88; }
#locate-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

@keyframes btn-pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

/* ── Location dot marker ── */
.location-dot { position: relative; width: 22px; height: 22px; }
.location-pulse {
  position: absolute; inset: 0; border-radius: 50%;
  background: rgba(37,99,235,.35);
  animation: loc-pulse 2.2s ease-out infinite;
}
.location-center {
  position: absolute; top: 4px; left: 4px;
  width: 14px; height: 14px; border-radius: 50%;
  background: #2563eb; border: 2.5px solid #fff;
  box-shadow: 0 1px 5px rgba(0,0,0,.55);
}
@keyframes loc-pulse {
  0%   { transform: scale(.5); opacity: 1; }
  100% { transform: scale(2.8); opacity: 0; }
}

/* ── Popup ── */
#popup {
  position: absolute; bottom: 30px; right: 12px; z-index: 100;
  width: min(280px, calc(100vw - 24px));
  background: #1e2027ee; backdrop-filter: blur(10px);
  border: 1px solid #333; border-radius: 10px; padding: 14px 16px;
}
#popup.hidden { display: none; }
#popup-close {
  position: absolute; top: 10px; right: 12px;
  background: none; border: none; color: #999; font-size: .85rem;
  cursor: pointer; line-height: 1;
}
#popup-close:hover { color: #fff; }
#popup-body h3 { font-size: .9rem; margin-bottom: 6px; color: #fff; padding-right: 20px; }
#popup-body p  { font-size: .8rem; color: #aaa; line-height: 1.5; margin-bottom: 4px; }
#popup-body .tag {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: .7rem; font-weight: 600; margin-top: 6px;
}
.tag-nats-r   { background: #7f1d1d; color: #fca5a5; }
.tag-nats-d   { background: #7c2d12; color: #fdba74; }
.tag-nats-ctr { background: #1e3a5f; color: #93c5fd; }
.tag-nats-cta { background: #1e3a5f; color: #93c5fd; }
.tag-nats-ras { background: #2e1065; color: #c4b5fd; }
.tag-nats-tmz { background: #3b0764; color: #e9d5ff; }
.tag-nats-fir { background: #1c1917; color: #d6d3d1; }
.tag-frz      { background: #7f1d1d; color: #fca5a5; }
.tag-danger   { background: #7c2d12; color: #fdba74; }
.tag-military { background: #1e293b; color: #94a3b8; }
.tag-parks    { background: #14532d; color: #86efac; }
.tag-royal    { background: #4a1d96; color: #d8b4fe; }
.tag-sssi     { background: #164e63; color: #67e8f9; }
.tag-forestry { background: #1a2e05; color: #86efac; }

/* ── MapLibre overrides ── */
.maplibregl-ctrl-attrib { background: #000000aa !important; color: #666 !important; font-size: .65rem !important; }
.maplibregl-ctrl-attrib a { color: #888 !important; }

/* ── Mobile ── */
@media (max-width: 480px) {
  #panel { width: calc(100vw - 24px); top: 8px; left: 8px; right: 8px; }
  #popup { right: 8px; bottom: 20px; width: calc(100vw - 16px); }
}
