/* WebGIS SPPG Kabupaten Jember — Kartografi Pemerintahan */
:root {
  --color-primary: #1b5e20;
  --color-secondary: #43a047;
  --color-accent: #fb8c00;
  --color-bg: #f5f5f5;
  --color-surface: #ffffff;
  --color-text: #212121;
  --color-text-muted: #616161;
  --color-border: #e0e0e0;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --radius: 6px;
  --header-h: auto;
  --font: "Inter", "Segoe UI", system-ui, sans-serif;
  --font-heading: "IBM Plex Sans", "Inter", "Segoe UI", system-ui, sans-serif;
  --choropleth-1: #c8e6c9;
  --choropleth-2: #a5d6a7;
  --choropleth-3: #66bb6a;
  --choropleth-4: #2e7d32;
  --choropleth-5: #1b5e20;
}

[data-theme="dark"] {
  --color-bg: #121212;
  --color-surface: #1e1e1e;
  --color-text: #e8e8e8;
  --color-text-muted: #b0b0b0;
  --color-border: #333;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
}

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

html,
body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  font-size: 15px;
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Loading */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--color-primary) 0%, #2e7d32 50%, var(--color-secondary) 100%);
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-screen.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-content {
  text-align: center;
  color: #fff;
  padding: 2rem;
}

.loading-logo-wrap {
  position: relative;
  width: 108px;
  height: 108px;
  margin: 0 auto 1.35rem;
}

.loading-logo {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 76px;
  height: 76px;
  object-fit: contain;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.35));
}

.loading-spinner {
  position: absolute;
  inset: 0;
  border: 4px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-title {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
  letter-spacing: 0.02em;
}

.loading-sub {
  margin: 0 0 1.5rem;
  opacity: 0.9;
  font-size: 0.95rem;
}

.loading-bar {
  width: 220px;
  height: 6px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 3px;
  overflow: hidden;
}

.loading-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--color-accent);
  border-radius: 3px;
  transition: width 0.3s ease;
}

/* Header */
.site-header {
  background: linear-gradient(180deg, var(--color-primary) 0%, #2e7d32 100%);
  color: #fff;
  box-shadow: var(--shadow-md);
  border-bottom: 4px solid var(--color-accent);
}

.header-inner {
  display: grid;
  grid-template-columns: 100px 1fr 100px;
  align-items: center;
  gap: 1rem;
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem 1.25rem 0.75rem;
}

.header-logo {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 88px;
  height: 88px;
}

.header-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.25));
}

.header-title {
  text-align: center;
}

.header-title h1 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: clamp(1.1rem, 2.5vw, 1.65rem);
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1.25;
}

.header-title h1 span {
  display: block;
  font-size: 0.92em;
}

.header-subtitle {
  margin: 0.35rem 0 0;
  font-size: 0.95rem;
  opacity: 0.95;
}

.header-meta {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
  opacity: 0.85;
  font-weight: 600;
}

.header-toolbar {
  display: flex;
  justify-content: flex-end;
  padding: 0 1.25rem 0.5rem;
  max-width: 1400px;
  margin: 0 auto;
}

.toolbar-btn {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}

.toolbar-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* Stats */
.stats-section {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  max-width: 1400px;
  margin: 1rem auto;
  padding: 0 1.25rem;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-primary);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-card--accent {
  border-left-color: var(--color-accent);
}

.stat-icon {
  font-size: 1.5rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(27, 94, 32, 0.1);
}

.stat-icon--accent {
  background: rgba(251, 140, 0, 0.15);
}

.stat-label {
  display: block;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-value {
  font-family: var(--font-heading);
  font-size: 1.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--color-primary);
}

.stat-value--sm {
  font-size: 1rem;
  line-height: 1.3;
}

[data-theme="dark"] .stat-value {
  color: var(--color-secondary);
}

/* Main layout */
.main-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1rem;
  max-width: 1400px;
  margin: 0 auto 1rem;
  padding: 0 1.25rem;
  min-height: 520px;
}

.map-panel {
  position: relative;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.map-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  z-index: 500;
}

.map-toolbar-group {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  position: relative;
}

.map-toolbar-group--search {
  flex: 1;
  min-width: 180px;
  max-width: 280px;
}

.toolbar-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--color-text-muted);
  letter-spacing: 0.04em;
}

.toolbar-select,
.toolbar-search {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
  color: var(--color-text);
  min-width: 160px;
}

.toolbar-search {
  width: 100%;
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  max-height: 200px;
  overflow-y: auto;
  z-index: 600;
}

.search-results li {
  padding: 0.5rem 0.65rem;
  cursor: pointer;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--color-border);
}

.search-results li:hover {
  background: rgba(67, 160, 71, 0.15);
}

.search-results li:last-child {
  border-bottom: none;
}

.map-toolbar-actions {
  display: flex;
  gap: 0.4rem;
  margin-left: auto;
}

.map-toolbar-actions .toolbar-btn {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

[data-theme="dark"] .map-toolbar-actions .toolbar-btn {
  background: var(--color-secondary);
  border-color: var(--color-secondary);
  color: #111;
}

.map-canvas-area {
  position: relative;
  flex: 1;
  min-height: 480px;
  height: 58vh;
}

.map-container {
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* Map overlays */
.map-overlay--north {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 800;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 4px;
  padding: 4px;
  box-shadow: var(--shadow-sm);
  pointer-events: none;
}

[data-theme="dark"] .map-overlay--north {
  background: rgba(30, 30, 30, 0.92);
}

.map-overlay--coords {
  position: absolute;
  bottom: 36px;
  left: 12px;
  z-index: 800;
  background: rgba(255, 255, 255, 0.94);
  padding: 0.35rem 0.65rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-family: "Consolas", monospace;
  box-shadow: var(--shadow-sm);
  display: flex;
  gap: 0.75rem;
  border: 1px solid var(--color-border);
}

[data-theme="dark"] .map-overlay--coords {
  background: rgba(30, 30, 30, 0.94);
}

/* Legend — kanan bawah, di atas peta inset (layout QGIS) */
.map-legend {
  position: absolute;
  right: 12px;
  bottom: 132px;
  top: auto;
  z-index: 800;
  width: 178px;
  max-height: calc(100% - 160px);
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius);
  padding: 0.55rem 0.7rem;
  box-shadow: var(--shadow-md);
  font-size: 0.76rem;
  pointer-events: none;
}

[data-theme="dark"] .map-legend {
  background: rgba(30, 30, 30, 0.96);
}

.legend-title {
  margin: 0 0 0.5rem;
  font-family: var(--font-heading);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-primary);
  border-bottom: 2px solid var(--color-accent);
  padding-bottom: 0.35rem;
}

.legend-section h4 {
  margin: 0.5rem 0 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.25rem;
}

.legend-symbol--sppg {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.legend-symbol--sppg img {
  width: 22px;
  height: 22px;
  object-fit: contain;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.25));
}

.legend-choropleth {
  margin: 0;
  padding: 0;
  list-style: none;
}

.legend-choropleth li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.2rem;
}

.legend-swatch {
  width: 18px;
  height: 14px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

/* Mini map */
.mini-map {
  position: absolute;
  bottom: 12px;
  right: 12px;
  width: 140px;
  height: 110px;
  z-index: 800;
  border: 2px solid var(--color-primary);
  border-radius: 4px;
  box-shadow: var(--shadow-md);
  background: #fff;
}

.mini-map::before {
  content: "Lokasi";
  position: absolute;
  top: -1px;
  left: -1px;
  right: -1px;
  background: var(--color-primary);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  text-align: center;
  padding: 1px 0;
  z-index: 1;
  letter-spacing: 0.05em;
}

/* Sidebar */
.sidebar-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel-block {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.85rem;
  box-shadow: var(--shadow-sm);
}

.panel-title {
  margin: 0 0 0.65rem;
  font-family: var(--font-heading);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-left: 3px solid var(--color-accent);
  padding-left: 0.5rem;
}

.chart-wrap {
  position: relative;
  height: 200px;
  margin-bottom: 0.75rem;
}

.chart-wrap--pie {
  height: 180px;
  margin-bottom: 0;
}

.analysis-content {
  font-size: 0.88rem;
  color: var(--color-text);
}

.analysis-content p {
  margin: 0 0 0.65rem;
  padding-left: 0.65rem;
  border-left: 2px solid var(--color-secondary);
}

.analysis-content p:last-child {
  margin-bottom: 0;
}

.analysis-highlight {
  color: var(--color-primary);
  font-weight: 700;
}

[data-theme="dark"] .analysis-highlight {
  color: var(--color-secondary);
}

/* Footer */
.site-footer {
  background: var(--color-primary);
  color: rgba(255, 255, 255, 0.95);
  margin-top: 0.5rem;
  padding: 1rem 1.25rem;
  font-size: 0.85rem;
}

.footer-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1.5rem;
  align-items: start;
}

.footer-block h3 {
  margin: 0 0 0.4rem;
  font-family: var(--font-heading);
  font-size: 0.9rem;
  font-weight: 600;
}

.footer-block ol {
  margin: 0;
  padding-left: 1.25rem;
}

.site-footer a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.site-footer a:hover {
  color: #fff;
  opacity: 0.9;
}

.footer-block--crs {
  text-align: right;
}

.footer-copy {
  margin: 0.5rem 0 0;
  opacity: 0.8;
  font-size: 0.8rem;
}

/* Leaflet overrides */
.leaflet-container {
  font-family: var(--font);
  background: #e8f5e9;
}

[data-theme="dark"] .leaflet-container {
  background: #1a2e1a;
}

.leaflet-control-layers {
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-sm) !important;
}

.leaflet-control-scale {
  margin-left: 12px !important;
  margin-bottom: 8px !important;
}

.leaflet-popup-content-wrapper {
  border-radius: var(--radius);
  border-top: 3px solid var(--color-accent);
}

.popup-title {
  margin: 0 0 0.5rem;
  font-weight: 700;
  color: var(--color-primary);
  font-size: 0.95rem;
}

.popup-table {
  width: 100%;
  font-size: 0.82rem;
  border-collapse: collapse;
}

.popup-table th {
  text-align: left;
  padding: 0.2rem 0.5rem 0.2rem 0;
  color: var(--color-text-muted);
  font-weight: 600;
  vertical-align: top;
  width: 38%;
}

.popup-table td {
  padding: 0.2rem 0;
}

.popup-btn {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.35rem 0.65rem;
  background: var(--color-accent);
  color: #fff !important;
  text-decoration: none;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
}

.popup-btn:hover {
  background: #f57c00;
}

.kecamatan-tooltip {
  font-weight: 600;
  font-size: 0.85rem;
}

/* Marker lokasi SPPG — logo BGN */
.sppg-marker {
  background: transparent !important;
  border: none !important;
}

.sppg-marker img {
  width: 24px;
  height: 24px;
  object-fit: contain;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.35));
  display: block;
  transition: transform 0.15s ease;
}

.sppg-marker:hover img {
  transform: scale(1.12);
  border-color: var(--color-accent);
}

/* Responsive */
@media (max-width: 1100px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  .sidebar-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .panel-block--analysis {
    grid-column: 1 / -1;
  }
}

@media (max-width: 768px) {
  .header-inner {
    grid-template-columns: 64px 1fr 64px;
    padding: 0.75rem;
  }

  .header-logo {
    width: 56px;
    height: 56px;
  }

  .stats-section {
    grid-template-columns: repeat(2, 1fr);
  }

  .sidebar-panel {
    grid-template-columns: 1fr;
  }

  .map-legend {
    right: 8px;
    bottom: 118px;
    width: 155px;
    max-height: 42vh;
  }

  .map-overlay--north {
    top: 8px;
    right: 8px;
  }

  .mini-map {
    width: 120px;
    height: 90px;
  }
}

@media (max-width: 480px) {
  .stats-section {
    grid-template-columns: 1fr;
  }

  .map-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .map-toolbar-actions {
    margin-left: 0;
  }
}
