﻿/* === GIS viewer tab =========================================================
 * Layout: header (title + description + token + basemap switch) over a body
 * that splits into a left sidebar (upload button + per-file list) and a right
 * Leaflet canvas. The styling follows the GUtils house rules (slate text on
 * near-white surfaces, sky-blue interactive accents, 12-16 px corner radii).
 *
 * Leaflet's own CSS handles the map tiles and controls; this file only adds
 * the chrome around the map and tweaks a couple of Leaflet defaults (e.g. a
 * denser attribution line, the popup table styling).
 * ========================================================================== */

/* ---------- Root layout ---------- */
.gis-tab {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 110px);
  min-height: 520px;
  background: #f8fafc;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #eef2f7;
  font-size: 14px;
  color: #1f2937;
}

/* ---------- Header (description + token + basemap) ---------- */
.gis-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  background: #fff;
  border-bottom: 1px solid #eef2f7;
}
.gis-header-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1 1 320px;
}
.gis-header-title h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #0f172a;
  letter-spacing: 0;
}
.gis-header-title p {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: #64748b;
}
.gis-header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.gis-token {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 4px 8px;
  transition: border-color .15s ease, background .15s ease;
}
.gis-token:focus-within {
  border-color: #0ea5e9;
  background: #fff;
}
.gis-token svg {
  width: 14px;
  height: 14px;
  color: #64748b;
  flex: none;
}
.gis-token input {
  border: 0;
  background: transparent;
  outline: 0;
  font-size: 12px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: #0f172a;
  width: 200px;
  letter-spacing: 0.5px;
}
.gis-token input::placeholder {
  color: #94a3b8;
  font-family: inherit;
  letter-spacing: 0;
}
.gis-token.empty {
  border-color: #f59e0b;
  background: #fff7ed;
}
.gis-token.empty:focus-within {
  border-color: #f59e0b;
  background: #fff;
}
.gis-token svg.warn { display: none; color: #f59e0b; }
.gis-token.empty svg.warn { display: inline-block; }
.gis-token.empty svg.lock { display: none; }

/* ---------- Basemap switch (segmented control) ---------- */
.gis-basemap {
  display: inline-flex;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
.gis-basemap button {
  border: 0;
  background: transparent;
  padding: 5px 12px;
  font-size: 12px;
  color: #475569;
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.gis-basemap button:hover {
  color: #0c4a6e;
}
.gis-basemap button.active {
  background: #fff;
  color: #0369a1;
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

/* ---------- Body (sidebar + map) ---------- */
.gis-body {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}
.gis-sidebar {
  width: 300px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-right: 1px solid #eef2f7;
  min-height: 0;
}
.gis-sidebar-head {
  padding: 12px 14px;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}
.gis-sidebar-head .gis-upload-btn {
  flex: 1 1 auto;
  background: #0ea5e9;
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background .15s ease;
}
.gis-sidebar-head .gis-upload-btn:hover {
  background: #0284c7;
}
.gis-sidebar-head .gis-upload-btn:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}
.gis-sidebar-head .gis-clear-btn {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.gis-sidebar-head .gis-clear-btn:hover {
  background: #e2e8f0;
  color: #0f172a;
}

/* ---------- Layer list ---------- */
.gis-layers {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 6px 0;
}
.gis-layers::-webkit-scrollbar {
  width: 6px;
}
.gis-layers::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}
.gis-layers::-webkit-scrollbar-track {
  background: transparent;
}

.gis-layer {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid #f8fafc;
  transition: background .12s ease;
}
.gis-layer:hover {
  background: #f8fafc;
}
.gis-layer-error {
  background: #fef2f2;
}
.gis-layer-error:hover {
  background: #fee2e2;
}

.gis-layer-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #e0f2fe;
  color: #0369a1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  flex: none;
  letter-spacing: 0.5px;
}
.gis-layer-icon.shp {
  background: #fef3c7;
  color: #b45309;
}

.gis-layer-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.gis-layer-name {
  font-size: 13px;
  font-weight: 500;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.gis-layer-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #64748b;
}
.gis-layer-meta .chip {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #475569;
  font-size: 10px;
  letter-spacing: 0;
}
.gis-layer-meta .chip.geojson {
  background: #e0f2fe;
  color: #0369a1;
}
.gis-layer-meta .chip.shp {
  background: #fef3c7;
  color: #b45309;
}
.gis-layer-error-text {
  font-size: 11px;
  color: #b91c1c;
  line-height: 1.4;
  word-break: break-word;
}

.gis-layer-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
}
.gis-color-pick {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
  cursor: pointer;
  padding: 0;
  background-clip: content-box;
}
.gis-icon-btn {
  width: 28px;
  height: 28px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  color: #64748b;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.gis-icon-btn:hover {
  background: #f1f5f9;
  color: #0f172a;
}
.gis-icon-btn.danger:hover {
  background: #fee2e2;
  color: #b91c1c;
}
.gis-icon-btn svg {
  width: 16px;
  height: 16px;
}
.gis-eye-btn.on {
  color: #0369a1;
  background: #e0f2fe;
  border-color: #bae6fd;
}
.gis-eye-btn.off {
  color: #64748b;
  background: #f8fafc;
}
.gis-eye-btn.off:hover {
  color: #0369a1;
}
.gis-fill-btn.on {
  color: #0369a1;
  background: #e0f2fe;
  border-color: #bae6fd;
}
.gis-fill-btn.off {
  color: #64748b;
  background: #f8fafc;
}
.gis-fill-btn.off:hover {
  color: #0369a1;
}

.gis-empty {
  padding: 36px 18px;
  text-align: center;
  color: #94a3b8;
  font-size: 12px;
  line-height: 1.6;
}
.gis-empty-hint {
  margin-top: 6px;
  font-size: 11px;
  color: #cbd5e1;
}

/* ---------- Map ---------- */
.gis-map-wrap {
  flex: 1 1 auto;
  position: relative;
  min-width: 0;
  background: #f1f5f9;
}
.gis-map {
  position: absolute;
  inset: 0;
}
.gis-map-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  background: rgba(241, 245, 249, 0.85);
  backdrop-filter: blur(2px);
  pointer-events: none;
  text-align: center;
  z-index: 500;
}
.gis-map-overlay .gis-overlay-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid #e2e8f0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.gis-map-overlay .gis-overlay-icon svg {
  width: 22px;
  height: 22px;
}
.gis-map-overlay-title {
  font-size: 14px;
  color: #475569;
  font-weight: 500;
}
.gis-map-overlay-sub {
  font-size: 12px;
  color: #94a3b8;
  max-width: 320px;
  line-height: 1.5;
}

/* ---------- Leaflet overrides ---------- */
.leaflet-container {
  font: inherit;
  background: #f8fafc;
}
/* White base-map (白底图) keeps the Leaflet canvas pure white so user-uploaded
   shapes stand out clearly without any tile graphics behind them. */
.gis-map.is-blank .leaflet-container,
.gis-map.is-blank {
  background: #ffffff;
}
.leaflet-popup-content-wrapper {
  border-radius: 10px;
}
.leaflet-popup-content {
  margin: 10px 12px;
  font-size: 12px;
  line-height: 1.5;
  max-width: 280px;
}
.gis-popup-title {
  font-size: 12px;
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid #eef2f7;
}
.gis-popup-table {
  width: 100%;
  border-collapse: collapse;
}
.gis-popup-table tr + tr td {
  border-top: 1px solid #f1f5f9;
}
.gis-popup-table td {
  padding: 3px 6px;
  vertical-align: top;
  word-break: break-word;
}
.gis-popup-table td:first-child {
  color: #64748b;
  font-size: 11px;
  white-space: nowrap;
  width: 1%;
  padding-right: 8px;
}
.gis-popup-table td:last-child {
  color: #0f172a;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
}
.gis-popup-empty {
  color: #94a3b8;
  font-style: italic;
  font-size: 11px;
}
.leaflet-control-attribution {
  font-size: 10px;
  background: rgba(255, 255, 255, 0.8) !important;
}

/* ---------- AK banner (shown when no Tianditu AK has been entered) ---------- */
.gis-ak-banner {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 600;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 12px;
  color: #9a3412;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  max-width: calc(100% - 32px);
  text-align: center;
  pointer-events: none;
}

/* ---------- Responsive (narrow viewports) ---------- */
@media (max-width: 768px) {
  .gis-tab {
    height: auto;
    min-height: 0;
  }
  .gis-body {
    flex-direction: column;
  }
  .gis-sidebar {
    width: 100%;
    border-right: 0;
    border-bottom: 1px solid #eef2f7;
    max-height: 280px;
  }
  .gis-token input {
    width: 140px;
  }
}
