/* ============================================================
   Website Visitor Monitoring — Style Sheet
   myvisitor.bumixa.com
   Glassmorphism Theme + Responsive + Dark/Light Mode
   Requirements: 6.1–6.4, 7.1–7.5
   ============================================================ */

/* ─── Reset & Base ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Light mode palette */
  --bg-gradient-start: #0f2027;
  --bg-gradient-mid:   #203a43;
  --bg-gradient-end:   #2c5364;

  --glass-bg:          rgba(255, 255, 255, 0.12);
  --glass-bg-hover:    rgba(255, 255, 255, 0.18);
  --glass-border:      rgba(255, 255, 255, 0.25);
  --glass-shadow:      0 8px 32px rgba(0, 0, 0, 0.3);

  --text-primary:      #ffffff;
  --text-secondary:    rgba(255, 255, 255, 0.75);
  --text-muted:        rgba(255, 255, 255, 0.5);

  --accent-cyan:       #00e5ff;
  --accent-green:      #00e676;
  --accent-yellow:     #ffd740;
  --accent-red:        #ff5252;

  --header-height:     56px;
  --panel-height-desk: auto;
  --radius-lg:         16px;
  --radius-md:         10px;
  --radius-sm:         6px;

  --transition-fast:   150ms ease;
  --transition-med:    300ms ease;

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* Dark mode — ikuti preferensi sistem (Requirement 6.2) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-gradient-start: #050e14;
    --bg-gradient-mid:   #0d1e26;
    --bg-gradient-end:   #132030;
    --glass-bg:          rgba(10, 20, 30, 0.55);
    --glass-bg-hover:    rgba(10, 20, 30, 0.70);
    --glass-border:      rgba(255, 255, 255, 0.12);
  }
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: var(--font-sans);
  background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-mid), var(--bg-gradient-end));
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

a {
  color: var(--accent-cyan);
  text-decoration: none;
  transition: opacity var(--transition-fast);
}
a:hover, a:focus { opacity: 0.8; outline: 2px solid var(--accent-cyan); outline-offset: 2px; }

/* Skip to content (accessibility) */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--accent-cyan);
  color: #000;
  padding: 8px 16px;
  z-index: 9999;
  border-radius: 0 0 var(--radius-sm) 0;
  font-weight: 600;
  transition: top var(--transition-fast);
}
.skip-link:focus { top: 0; }

/* ─── Header ─────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  height: var(--header-height);

  /* Glassmorphism (Requirement 6.1) */
  background: var(--glass-bg);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
}

/* Fallback untuk browser tanpa backdrop-filter (Requirement 6.4) */
@supports not (backdrop-filter: blur(1px)) {
  .app-header {
    background: rgba(13, 30, 38, 0.92);
  }
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1rem;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
}
.brand-link:hover, .brand-link:focus { opacity: 0.9; }
.brand-icon { font-size: 1.4rem; }
.brand-sub {
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-left: 0.25rem;
}

.header-nav {
  display: flex;
  gap: 1.25rem;
  align-items: center;
}
.nav-link {
  font-size: 0.875rem;
  color: var(--text-secondary);
  transition: color var(--transition-fast);
}
.nav-link:hover, .nav-link:focus { color: var(--text-primary); }

/* ─── Main Layout ────────────────────────────────────────── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ─── Summary Panel (Requirement 5.1–5.5) ───────────────── */
.summary-panel {
  position: relative;
  z-index: 100;
  padding: 0.875rem 1rem;

  /* Glassmorphism (Requirement 6.1) */
  background: var(--glass-bg);
  backdrop-filter: blur(20px) saturate(200%);
  -webkit-backdrop-filter: blur(20px) saturate(200%);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
}

@supports not (backdrop-filter: blur(1px)) {
  .summary-panel {
    background: rgba(8, 18, 24, 0.90);
  }
}

.panel-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pulse-green {
  background: var(--accent-green);
  animation: blink-dot 2s ease-in-out infinite;
}

@keyframes blink-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 6px var(--accent-green); }
  50%       { opacity: 0.3; box-shadow: none; }
}

.status-text {
  font-weight: 600;
  color: var(--accent-green);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.72rem;
}

.last-updated {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ─── Stats Grid ─────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.625rem;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius-md);

  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background var(--transition-med), transform var(--transition-fast);
}

@supports not (backdrop-filter: blur(1px)) {
  .stat-card { background: rgba(10, 22, 30, 0.80); }
}

.stat-card:hover {
  background: var(--glass-bg-hover);
  transform: translateY(-1px);
}

/* Active card — destacado dengan glow cyan */
.stat-active {
  border-color: rgba(0, 229, 255, 0.4);
  box-shadow: 0 0 16px rgba(0, 229, 255, 0.15);
}
.stat-active .stat-icon { color: var(--accent-cyan); }
.stat-active .stat-value { color: var(--accent-cyan); }

.stat-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 0.2rem;
  white-space: nowrap;
}

/* Animasi count-up / fade saat nilai berubah (Requirement 5.4) */
.stat-value.updating {
  animation: value-flash 400ms ease;
}
@keyframes value-flash {
  0%   { opacity: 0.3; transform: translateY(-4px); }
  100% { opacity: 1;   transform: translateY(0); }
}

/* ─── Basemap Toggle (Requirement 4.1–4.5) ──────────────── */
.stat-basemap {
  flex-direction: column;
  align-items: flex-start;
  gap: 0.3rem;
}
.stat-basemap .stat-icon {
  color: var(--accent-yellow);
}

.basemap-toggle {
  display: flex;
  gap: 0.35rem;
}

.basemap-btn {
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
  letter-spacing: 0.05em;
}

.basemap-btn:hover {
  background: var(--glass-bg-hover);
  color: var(--text-primary);
}

.basemap-btn.active,
.basemap-btn[aria-checked="true"] {
  background: var(--accent-cyan);
  color: #000;
  border-color: var(--accent-cyan);
}

.basemap-btn:focus-visible {
  outline: 2px solid var(--accent-cyan);
  outline-offset: 2px;
}

/* ─── Panel Error (Requirement 9.3) ─────────────────────── */
.panel-error {
  margin-top: 0.625rem;
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 82, 82, 0.2);
  border: 1px solid rgba(255, 82, 82, 0.4);
  color: #ff8a80;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ─── Map Section (Requirement 3.1, 3.5) ────────────────── */
.map-section {
  flex: 1;
  position: relative;
  min-height: 500px;
  height: calc(100vh - 56px - 140px); /* viewport - header - panel */
}

#visitor-map {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  width: 100%;
  height: 100%;
  min-height: 500px;
  z-index: 1;
  background: #0d1e26;
}

/* Map loading overlay */
.map-loading {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgba(13, 30, 38, 0.8);
  color: var(--text-secondary);
  font-size: 0.9rem;
  backdrop-filter: blur(4px);
  transition: opacity var(--transition-med);
}

.map-loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.loader-ring {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(0, 229, 255, 0.2);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ─── Pulse Marker (Requirement 3.3) ─────────────────────── */
.pulse-marker-wrapper {
  position: relative;
  width: 16px;
  height: 16px;
}

.pulse-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-cyan);
  box-shadow: 0 0 6px var(--accent-cyan);
  z-index: 2;
}

.pulse-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--accent-cyan);
  transform: translate(-50%, -50%);
  animation: pulse-out 2s ease-out infinite;
  z-index: 1;
}

.pulse-dot.inactive {
  background: rgba(255, 213, 79, 0.8);
  box-shadow: 0 0 6px rgba(255, 213, 79, 0.6);
}
.pulse-ring.inactive {
  border-color: rgba(255, 213, 79, 0.6);
  animation-duration: 3s;
}

@keyframes pulse-out {
  0%   { transform: translate(-50%, -50%) scale(1);   opacity: 0.8; }
  70%  { transform: translate(-50%, -50%) scale(3.5); opacity: 0; }
  100% { transform: translate(-50%, -50%) scale(3.5); opacity: 0; }
}

/* Leaflet Popup Glassmorphism */
.leaflet-popup-content-wrapper {
  background: var(--glass-bg) !important;
  backdrop-filter: blur(16px) saturate(180%) !important;
  -webkit-backdrop-filter: blur(16px) saturate(180%) !important;
  border: 1px solid var(--glass-border) !important;
  border-radius: var(--radius-md) !important;
  color: var(--text-primary) !important;
  box-shadow: var(--glass-shadow) !important;
}
@supports not (backdrop-filter: blur(1px)) {
  .leaflet-popup-content-wrapper {
    background: rgba(8, 18, 24, 0.92) !important;
  }
}
.leaflet-popup-tip {
  background: var(--glass-bg) !important;
}
.leaflet-popup-content {
  margin: 10px 14px !important;
  line-height: 1.5 !important;
}
.popup-city   { font-weight: 700; font-size: 0.95rem; }
.popup-count  { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; }
.popup-active { font-size: 0.75rem; color: var(--accent-green); margin-top: 2px; }

/* Leaflet controls glassmorphism */
.leaflet-control-zoom a,
.leaflet-control-attribution {
  background: var(--glass-bg) !important;
  backdrop-filter: blur(10px) !important;
  -webkit-backdrop-filter: blur(10px) !important;
  border: 1px solid var(--glass-border) !important;
  color: var(--text-primary) !important;
}
.leaflet-control-zoom a:hover { background: var(--glass-bg-hover) !important; }

/* ─── Footer ─────────────────────────────────────────────── */
.app-footer {
  padding: 0.625rem 1rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--glass-border);
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
@supports not (backdrop-filter: blur(1px)) {
  .app-footer { background: rgba(8, 18, 24, 0.90); }
}
.footer-inner p { line-height: 1.5; }

/* ─── Responsive — Tablet 768–1023px (Requirement 7.1) ───── */
@media (max-width: 1023px) {
  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ─── Responsive — Mobile < 768px (Requirement 7.1, 7.2) ── */
@media (max-width: 767px) {
  :root { --header-height: 50px; }

  .brand-sub { display: none; }

  .summary-panel {
    padding: 0.625rem 0.75rem;
  }

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

  .stat-card {
    padding: 0.5rem 0.625rem;
    gap: 0.5rem;
  }

  .stat-value {
    font-size: 1.2rem;
  }

  .stat-icon { width: 20px; height: 20px; }

  /* Map takes at least 60% screen height (Requirement 7.2) */
  .map-section {
    min-height: 60vh;
    height: 60vh;
    flex: none;
  }

  #visitor-map {
    min-height: 60vh;
    height: 100%;
  }
}

/* ─── Landscape Mobile ────────────────────────────────────── */
@media (max-width: 767px) and (orientation: landscape) {
  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .map-section { min-height: 55vh; }
}

/* ─── Kontras WCAG 2.1 AA (Requirement 6.3) ─────────────── */
/* Nilai stat-value: putih #fff di atas dark background — rasio > 7:1 ✓ */
/* Stat-muted: rgba(255,255,255,0.5) — untuk teks kecil non-kritis */
/* Accent-cyan #00e5ff di atas dark: rasio ~8:1 ✓ */
/* Icon dan label utama: rasio 4.5:1+ ✓ */

/* ─── Print styles ────────────────────────────────────────── */
@media print {
  .app-header, .summary-panel { position: static; }
  #visitor-map { height: 500px; }
}
/* ─── Focus visible (accessibility) ─────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent-cyan);
  outline-offset: 2px;
}

/* ─── Print styles ────────────────────────────────────────── */
@media print {
  .app-header, .summary-panel { position: static; }
  #visitor-map { height: 500px; }
}

/* ─── Cluster Icon Custom ────────────────────────────────── */
.custom-cluster {
  background: transparent;
  border: none;
}
.cluster-icon {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(0, 229, 255, 0.25);
  border: 2px solid var(--accent-cyan);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  font-size: 0.75rem;
  font-weight: 700;
  backdrop-filter: blur(4px);
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.3);
}

/* ─── Focus visible (accessibility) ─────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent-cyan);
  outline-offset: 2px;
}

/* ─── Leaflet map tinggi penuh ───────────────────────────── */
.leaflet-container {
  background: #0d1e26 !important;
}
