/* ============================================
   SIG Pemetaan Kampung Wisata Purbayan
   Kotagede, Yogyakarta
   Theme: Heritage Javanese (Earthy + Gold)
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,600;0,700;1,400&family=Inter:wght@300;400;500;600;700&family=Noto+Serif+Javanese&display=swap');

/* === CSS Variables === */
:root {
  /* Heritage Color Palette */
  --primary: #6B3A2A;
  --primary-light: #8B5E3C;
  --primary-dark: #4A2518;
  --gold: #C5A55A;
  --gold-light: #E8D5A3;
  --gold-dark: #A68B3E;
  --cream: #F5F0E8;
  --cream-dark: #E8DFD0;
  --brown-soft: #D4C4A8;
  --text-dark: #2C1810;
  --text-medium: #5C4033;
  --text-light: #8B7355;
  --white: #FFFEF9;
  --overlay: rgba(44, 24, 16, 0.7);

  /* Category colors are now rendered dynamically from JS data */

  /* Spacing */
  --sidebar-width: 400px;
  --header-height: 70px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(44, 24, 16, 0.08);
  --shadow-md: 0 4px 20px rgba(44, 24, 16, 0.12);
  --shadow-lg: 0 8px 40px rgba(44, 24, 16, 0.18);
  --shadow-xl: 0 12px 60px rgba(44, 24, 16, 0.25);

  /* Transitions */
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--cream);
  color: var(--text-dark);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* === App Layout === */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* === Header === */
.header {
  height: var(--header-height);
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 1000;
  position: relative;
  box-shadow: var(--shadow-lg);
}

.header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--gold-dark), var(--gold), var(--gold-light), var(--gold), var(--gold-dark));
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-logo {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: 0 2px 12px rgba(197, 165, 90, 0.4);
}

.header-title {
  display: flex;
  flex-direction: column;
}

.header-title h1 {
  font-family: 'Playfair Display', serif;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--white);
  letter-spacing: 0.5px;
  line-height: 1.2;
}

.header-title span {
  font-size: 0.75rem;
  color: var(--gold-light);
  font-weight: 400;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-toggle-sidebar {
  display: block !important;
  /* Show by default */
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--white);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1.1rem;
  transition: var(--transition-fast);
  backdrop-filter: blur(10px);
}

.btn-toggle-sidebar:hover {
  background: rgba(255, 255, 255, 0.25);
}

.header-stats {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-badge {
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 6px 14px;
  border-radius: 20px;
  color: var(--white);
  font-size: 0.8rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat-badge .count {
  background: var(--gold);
  color: var(--primary-dark);
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.75rem;
}

/* === Main Content === */
.main-content {
  display: flex;
  flex: 1;
  height: calc(100vh - var(--header-height));
  position: relative;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--white);
  border-right: 1px solid var(--cream-dark);
  display: flex;
  flex-direction: column;
  z-index: 500;
  transition: var(--transition);
  box-shadow: var(--shadow-md);
  position: relative;
  /* Ensure toggle button is relative to sidebar */
}

.sidebar.collapsed {
  margin-left: calc(-1 * var(--sidebar-width));
}

/* Gmaps Style Toggle Button */
.gmaps-toggle-btn {
  position: absolute;
  top: 50%;
  /* Center vertically */
  right: -24px;
  /* Hangs outside sidebar */
  width: 24px;
  height: 48px;
  background: var(--white);
  border: 1px solid var(--cream-dark);
  border-left: none;
  /* Seamless join */
  border-radius: 0 8px 8px 0;
  /* Rounded outside edge */
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-medium);
  font-size: 0.8rem;
  box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
  z-index: 501;
  transition: background 0.2s, color 0.2s;
}

.gmaps-toggle-btn:hover {
  background: var(--cream);
  color: var(--primary);
}

.sidebar.collapsed .gmaps-toggle-btn {
  /* No changes needed to position, it moves with sidebar */
  /* Maybe cleaner shadow */
  box-shadow: 4px 0 8px rgba(0, 0, 0, 0.15);
}

/* Search Box */
.search-container {
  padding: 16px 20px;
  background: var(--white);
  border-bottom: 1px solid var(--cream-dark);
}

.search-box {
  position: relative;
}

.search-box input {
  width: 100%;
  padding: 12px 16px 12px 44px;
  border: 2px solid var(--cream-dark);
  border-radius: var(--radius);
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  background: var(--cream);
  color: var(--text-dark);
  transition: var(--transition);
  outline: none;
}

.search-box input:focus {
  border-color: var(--gold);
  background: var(--white);
  box-shadow: 0 0 0 4px rgba(197, 165, 90, 0.15);
}

.search-box input::placeholder {
  color: var(--text-light);
}

.search-box .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  font-size: 1rem;
}

.search-box .clear-search {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px;
  display: none;
  transition: var(--transition-fast);
}

.search-box .clear-search.visible {
  display: block;
}

.search-box .clear-search:hover {
  color: var(--primary);
}

/* Category Filters */
.filter-container {
  padding: 12px 20px;
  border-bottom: 1px solid var(--cream-dark);
  background: var(--white);
}

.filter-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 10px;
}

.filter-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border: 2px solid var(--cream-dark);
  border-radius: 20px;
  background: var(--white);
  color: var(--text-medium);
  font-family: 'Inter', sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition-fast);
  white-space: nowrap;
}

.filter-btn:hover {
  background: var(--cream);
  border-color: var(--brown-soft);
}

.filter-btn.active {
  border-color: var(--color, var(--primary));
  background: var(--bg, var(--cream));
  color: var(--color, var(--primary));
  font-weight: 600;
}

.filter-btn .emoji {
  font-size: 0.85rem;
}

.filter-btn-all {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}

.filter-btn-all:hover {
  background: var(--primary-light);
  border-color: var(--primary-light);
}

.filter-btn-all.active {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}

/* Location List */
.location-list-container {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  /* padding-bottom: 60px; Removed to simplify */
}

.location-list-container::-webkit-scrollbar {
  width: 6px;
}

.location-list-container::-webkit-scrollbar-track {
  background: transparent;
}

.location-list-container::-webkit-scrollbar-thumb {
  background: var(--brown-soft);
  border-radius: 3px;
}

.location-list-container::-webkit-scrollbar-thumb:hover {
  background: var(--text-light);
}

.location-count {
  padding: 8px 8px 4px;
  font-size: 0.75rem;
  color: var(--text-light);
  font-weight: 500;
}

.location-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  margin-bottom: 6px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition-fast);
  border: 2px solid transparent;
  position: relative;
}

.location-card:hover {
  background: var(--cream);
  border-color: var(--cream-dark);
}

.location-card.active {
  background: linear-gradient(135deg, rgba(197, 165, 90, 0.08), rgba(197, 165, 90, 0.15));
  border-color: var(--gold);
  box-shadow: var(--shadow-sm);
}

.location-card-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
  background: var(--cream);
}

.location-card-content {
  flex: 1;
  min-width: 0;
}

.location-card-name {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-dark);
  margin-bottom: 3px;
  line-height: 1.3;
}

.location-card-category {
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 4px;
}

.location-card-desc {
  font-size: 0.78rem;
  color: var(--text-light);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* No Results */
.no-results {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
}

.no-results-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.no-results h3 {
  font-size: 1rem;
  color: var(--text-medium);
  margin-bottom: 8px;
}

.no-results p {
  font-size: 0.85rem;
}

/* === Map Area === */
.map-container {
  flex: 1;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
  touch-action: none;
  /* Improve touch handling */
}

/* Map Legend */
.map-legend {
  position: absolute;
  bottom: 30px;
  left: 16px;
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  min-width: 200px;
  max-width: 260px;
  transition: var(--transition);
}

.map-legend.collapsed .legend-body {
  display: none;
}

.legend-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  cursor: pointer;
}

.map-legend.collapsed .legend-header {
  margin-bottom: 0;
}

.legend-header h4 {
  font-family: 'Playfair Display', serif;
  font-size: 0.9rem;
  color: var(--primary);
}

.legend-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-light);
  font-size: 0.85rem;
  transition: var(--transition-fast);
}

.legend-toggle:hover {
  color: var(--primary);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  font-size: 0.8rem;
  color: var(--text-medium);
}

.legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid var(--white);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

/* === Detail Panel === */
.detail-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 380px;
  height: 100%;
  background: var(--white);
  box-shadow: var(--shadow-xl);
  z-index: 600;
  transform: translateX(100%);
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.detail-panel.open {
  transform: translateX(0);
}

.detail-panel-header {
  position: relative;
  min-height: 200px;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  display: flex;
  align-items: flex-end;
  padding: 20px;
  overflow: hidden;
}

.detail-panel-header-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  opacity: 0.3;
}

/* Add overlay to ensure text readability on image */
.detail-panel-header-bg::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to bottom, transparent 0%, rgba(0, 0, 0, 0.7) 100%);
}


.detail-panel-header-content {
  position: relative;
  z-index: 2;
  color: var(--white);
  width: 100%;
}

.detail-category-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  margin-bottom: 10px;
  color: var(--white);
}

.detail-panel-name {
  font-family: 'Playfair Display', serif;
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.3;
}

.detail-close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
  border: none;
  color: var(--white);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.detail-close-btn:hover {
  background: rgba(0, 0, 0, 0.5);
  transform: scale(1.1);
}

.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
}

.detail-body::-webkit-scrollbar {
  width: 4px;
}

.detail-body::-webkit-scrollbar-thumb {
  background: var(--brown-soft);
  border-radius: 2px;
}

.detail-section {
  margin-bottom: 20px;
}

.detail-section h4 {
  font-family: 'Playfair Display', serif;
  font-size: 0.9rem;
  color: var(--primary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.detail-section p {
  font-size: 0.88rem;
  color: var(--text-medium);
  line-height: 1.7;
}

.detail-info-grid {
  display: grid;
  gap: 12px;
}

.detail-info-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  background: var(--cream);
  border-radius: var(--radius-sm);
  transition: var(--transition-fast);
}

.detail-info-item:hover {
  background: var(--cream-dark);
}

.detail-info-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.detail-info-content {
  flex: 1;
}

.detail-info-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-light);
  margin-bottom: 2px;
}

.detail-info-value {
  font-size: 0.85rem;
  color: var(--text-dark);
  font-weight: 500;
  line-height: 1.4;
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.detail-tag {
  padding: 4px 10px;
  background: var(--cream);
  border-radius: 12px;
  font-size: 0.72rem;
  color: var(--text-medium);
  font-weight: 500;
}

.detail-actions {
  padding: 16px 20px;
  border-top: 1px solid var(--cream-dark);
  display: flex;
  gap: 10px;
}

.btn-detail {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
  text-decoration: none;
}

.btn-directions {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: var(--white);
}

.btn-directions:hover {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-share {
  background: var(--cream);
  color: var(--primary);
  border: 2px solid var(--cream-dark);
}

.btn-share:hover {
  background: var(--white);
  border-color: var(--primary);
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--cream);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s ease-out;
}

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

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 5px solid var(--cream-dark);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}

.loading-text {
  font-family: 'Playfair Display', serif;
  font-size: 1.2rem;
  color: var(--primary);
  margin-bottom: 8px;
}

.loading-sub {
  font-size: 0.9rem;
  color: var(--text-light);
}

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

/* === Responsive Actions === */
@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
  }

  .header {
    padding: 0 16px;
  }

  .header-stats {
    display: none;
  }

  .btn-toggle-sidebar {
    display: block;
  }

  .main-content {
    position: relative;
    overflow: hidden;
  }

  .sidebar {
    position: absolute;
    top: 0;
    left: 0;
    width: 280px;
    height: 100%;
    transform: translateX(0);
    z-index: 1000;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
  }

  .sidebar.collapsed {
    transform: translateX(-100%);
    margin-left: 0;
  }

  .detail-panel {
    width: 100%;
    z-index: 1100;
  }
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-fade-in {
  animation: fadeIn 0.4s ease-out forwards;
}

/* === Custom Map Marker === */
.custom-marker {
  cursor: pointer;
  z-index: 400 !important;
  /* Ensure markers are clickable */
}

/* === Custom Map Popup === */
.leaflet-popup-content-wrapper {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 0;
  overflow: hidden;
}

.leaflet-popup-content {
  margin: 0;
  width: 280px !important;
}

.leaflet-popup-tip {
  background: var(--white);
  box-shadow: var(--shadow-lg);
}

.leaflet-container a.leaflet-popup-close-button {
  top: 10px;
  right: 10px;
  color: var(--text-light);
  font-size: 1.2rem;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  transition: var(--transition-fast);
  z-index: 10;
}

.leaflet-container a.leaflet-popup-close-button:hover {
  color: var(--primary);
  background: var(--cream);
}

.info-window {
  padding: 20px;
  text-align: left;
}

.info-window-category {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  color: var(--white);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

.info-window h3 {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  color: var(--primary);
  margin-bottom: 8px;
  line-height: 1.3;
}

.info-window p {
  font-size: 0.85rem;
  color: var(--text-medium);
  margin-bottom: 16px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.info-window-btn {
  width: 100%;
  padding: 10px;
  background: var(--cream);
  border: 1px solid var(--gold);
  border-radius: var(--radius-sm);
  color: var(--primary-dark);
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
}

.info-window-btn:hover {
  background: var(--gold);
  color: var(--white);
  box-shadow: var(--shadow-sm);
}