/* ===================================================
   WebGIS Desa Kumbo - Main Stylesheet
   Tema: Modern, Responsif, Dark/Light mode
   =================================================== */

:root {
  --bg: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #0d6efd;
  --card-bg: #ffffff;
  --sidebar-bg: #f8f9fa;
  --border: #e5e7eb;
  --hero-grad: linear-gradient(135deg, #1e3a8a 0%, #0ea5e9 50%, #14b8a6 100%);
  --shadow: 0 4px 12px rgba(0,0,0,0.08);
  --input-bg: #ffffff;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --primary: #38bdf8;
  --card-bg: #1e293b;
  --sidebar-bg: #111827;
  --border: #334155;
  --hero-grad: linear-gradient(135deg, #020617 0%, #1e293b 50%, #334155 100%);
  --shadow: 0 4px 12px rgba(0,0,0,0.5);
  --input-bg: #1e293b;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--text);
  scroll-behavior: smooth;
}
a { color: var(--primary); }

/* ============ LOADING SCREEN ============ */
.loading-screen {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  transition: opacity 0.4s;
}
.loading-logo {
  width: 90px; height: 90px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 4px 18px rgba(0,0,0,0.15);
  animation: pulse 1.6s infinite;
}
@keyframes pulse {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* ============ BRAND / LOGO ============ */
.brand-logo {
  width: 32px; height: 32px;
  border-radius: 6px;
  object-fit: cover;
}
.hero-logo {
  width: 110px; height: 110px;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid rgba(255,255,255,0.4);
  box-shadow: 0 8px 28px rgba(0,0,0,0.3);
}
.about-logo {
  width: 130px; border-radius: 12px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.2);
}

/* ============ HERO LANDING ============ */
.landing-hero {
  min-height: 100vh;
  background: var(--hero-grad);
  display: flex; flex-direction: column; justify-content: center;
  position: relative; overflow: hidden;
}
.landing-hero::before {
  content: ""; position: absolute; inset: 0;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255,255,255,0.1) 0%, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(255,255,255,0.1) 0%, transparent 40%);
  pointer-events: none;
}
.hero-content { position: relative; z-index: 2; padding: 3rem 1rem; }
.hero-content h1 { text-shadow: 0 2px 12px rgba(0,0,0,0.4); }
.hero-content p { max-width: 760px; margin: 0 auto; opacity: 0.95; }
.hero-stat {
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(8px);
  border-radius: 14px; padding: 1rem;
  border: 1px solid rgba(255,255,255,0.2);
}
.hero-stat h3 { margin: 0; font-weight: 700; }

/* ============ NAVBAR ============ */
.app-navbar { background: var(--card-bg); border-bottom: 1px solid var(--border); }
.app-navbar .nav-link { color: var(--text) !important; }
.app-navbar .nav-link:hover { color: var(--primary) !important; }

/* ============ SIDEBAR ============ */
.app-main { background: var(--bg); }
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  max-height: calc(100vh - 60px);
  overflow-y: auto;
}

/* Offcanvas sidebar untuk mobile */
@media (max-width: 991.98px) {
  .sidebar.offcanvas {
    visibility: visible !important;
    transform: none !important;
    position: fixed !important;
    top: 60px !important;
    left: 0;
    width: 320px !important;
    max-width: 85vw !important;
    height: calc(100vh - 60px) !important;
    z-index: 1045;
    box-shadow: 4px 0 16px rgba(0,0,0,0.2);
    transition: transform 0.3s ease;
  }
  .sidebar.offcanvas:not(.show) {
    transform: translateX(-100%) !important;
  }
  .sidebar-backdrop {
    position: fixed;
    top: 60px; left: 0;
    width: 100%; height: calc(100vh - 60px);
    background: rgba(0,0,0,0.5);
    z-index: 1040;
    display: none;
  }
  .sidebar-backdrop.show { display: block; }
}
.layer-group { margin-bottom: 0.7rem; }
.legend li {
  padding: 4px 0; display: flex; align-items: center; gap: 8px;
}
.legend-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  display: inline-block;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--border);
}
.legend-line {
  width: 22px; height: 4px;
  display: inline-block;
  border-radius: 2px;
}

/* ============ MAP ============ */
.map-wrapper { position: relative; height: calc(100vh - 60px); background: #0f172a; }
#leafletMap { width: 100%; height: 100%; }
.map-coords {
  position: absolute; bottom: 12px; left: 12px; z-index: 1000;
  font-size: 12px; padding: 6px 10px;
}
.map-scale {
  position: absolute; bottom: 12px; right: 60px; z-index: 1000;
  background: rgba(255,255,255,0.9); padding: 4px 8px;
  border-radius: 4px; font-size: 11px; color: #1f2937;
}
.map-overlay-topright {
  position: absolute; top: 12px; right: 12px; z-index: 1000;
}
.map-attribution-bottomleft {
  position: absolute; bottom: 36px; left: 12px; z-index: 999;
  pointer-events: none; opacity: 0.85;
}
.watermark-logo {
  width: 56px; height: 56px; border-radius: 50%;
  object-fit: cover; border: 3px solid rgba(255,255,255,0.7);
  box-shadow: 0 2px 10px rgba(0,0,0,0.3);
  background: rgba(255,255,255,0.6);
}

/* ============ ANIMATION ============ */
@keyframes gps-pulse {
  0% { transform: scale(0.8); opacity: 0.7; }
  100% { transform: scale(2.4); opacity: 0; }
}

/* ============ PERFORMANCE HINTS ============ */
/* GPU acceleration untuk elemen yang sering animasi */
.map-wrapper, #leafletMap, .leaflet-tile-pane {
  will-change: transform;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

/* Disable selection saat drag agar tidak lambat */
.leaflet-container.dragging .leaflet-tile,
.leaflet-container.dragging .leaflet-marker-icon {
  pointer-events: none;
}

/* Smooth scrolling untuk sidebar */
.sidebar {
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* Map zoom controls - lebih jelas */
.leaflet-control-zoom a {
  background: rgba(255,255,255,0.95) !important;
  color: #1f2937 !important;
  font-weight: bold !important;
}
[data-theme="dark"] .leaflet-control-zoom a {
  background: rgba(30,41,59,0.95) !important;
  color: #e5e7eb !important;
  border-color: #334155 !important;
}

/* Tile fade animation */
.leaflet-fade-anim .leaflet-tile {
  will-change: opacity;
}

/* Leaflet attribution */
.leaflet-control-attribution {
  background: rgba(255,255,255,0.85) !important;
  font-size: 10px !important;
}
[data-theme="dark"] .leaflet-control-attribution {
  background: rgba(15,23,42,0.85) !important;
  color: #94a3b8 !important;
}
[data-theme="dark"] .leaflet-control-attribution a {
  color: #38bdf8 !important;
}

/* Print mode */
@media print {
  body.printing .sidebar,
  body.printing .app-navbar,
  body.printing .dashboard-section,
  body.printing .footer-app,
  body.printing .map-overlay-topright,
  body.printing .map-attribution-bottomleft { display: none !important; }
  body.printing .map-wrapper { height: 100vh !important; }
}

/* Custom POI markers (CSS) */
.poi-marker {
  width: 36px; height: 36px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  display: flex; align-items: center; justify-content: center;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  font-size: 18px;
}
.poi-marker > span { transform: rotate(45deg); }
.poi-umkm { background: #f59e0b; }
.poi-sekolah { background: #10b981; }
.poi-masjid, .poi-mushola { background: #8b5cf6; }
.poi-balai { background: #ef4444; }
.poi-puskesmas, .poi-posyandu { background: #06b6d4; }
.poi-wisata { background: #ec4899; }

/* ============ DASHBOARD ============ */
.dashboard-section { background: var(--bg); }
.stat-card { border: none; border-radius: 14px; transition: transform 0.2s; }
.stat-card:hover { transform: translateY(-4px); }
.stat-card .card-body { position: relative; }
.stat-icon { position: absolute; top: 12px; right: 14px; font-size: 2rem; opacity: 0.7; }
.stat-1 { background: linear-gradient(135deg, #0d6efd, #38bdf8); color: #fff; }
.stat-2 { background: linear-gradient(135deg, #14b8a6, #22d3ee); color: #fff; }
.stat-3 { background: linear-gradient(135deg, #f59e0b, #fbbf24); color: #fff; }
.stat-4 { background: linear-gradient(135deg, #ef4444, #f97316); color: #fff; }
.stat-card h4 { font-weight: 800; margin-top: 0.5rem; }
.stat-card small { opacity: 0.9; }
.card { background: var(--card-bg); border: 1px solid var(--border); color: var(--text); }

/* Chart cards - fix agar canvas tidak memanjang ke bawah */
.chart-card { display: flex; flex-direction: column; }
.chart-card h6 { margin-bottom: 0.75rem; }
.chart-wrap {
  position: relative;
  width: 100%;
  height: 260px;          /* Fixed height untuk chart */
  max-height: 260px;
}
.chart-wrap canvas {
  max-width: 100% !important;
  max-height: 100% !important;
  height: 100% !important;
  width: 100% !important;
}
.form-control, .form-select, .input-group-text {
  background: var(--input-bg); color: var(--text); border-color: var(--border);
}
.form-control:focus, .form-select:focus { background: var(--input-bg); color: var(--text); }

/* ============ FOOTER ============ */
.footer-app { background: var(--card-bg); color: var(--muted); border-top: 1px solid var(--border); }

/* ============ MOBILE ============ */
@media (max-width: 768px) {
  .sidebar { max-height: none; }
  .map-wrapper { height: 60vh; }
  .hero-content h1 { font-size: 1.9rem; }
  .map-attribution-bottomleft { bottom: 50px; }
}

/* Scrollbar */
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
