/* Custom Styles for PANDU-KEPAHIANG (Panel Data Agregat Kependudukan Kepahiang) */

:root {
  --color-primary-green: #0F766E; /* Calm Emerald Teal */
  --color-primary-blue: #0E7490;  /* Calm Cyan Blue */
  --color-accent-green: #059669;
  --color-accent-blue: #0284C7;
  --color-bg-light: #F8FAFC;
  --color-card-light: #FFFFFF;
}

/* Ensure true full-screen width with zero side overflow on mobile */
html {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  position: relative;
}

/* Background image handling for mountain valley di kepahiang */
.bg-mountain-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  background-image: url('/assets/mountain-valley.jpg');
  background-size: cover;
  background-position: center 30%;
  background-repeat: no-repeat;
  pointer-events: none;
  z-index: 0;
  transition: opacity 0.5s ease;
}

/* Light mode opacity: default 25% */
html:not(.dark) .bg-mountain-backdrop {
  opacity: 0.25;
  filter: saturate(1.1) brightness(1.05);
}

/* Dark mode opacity: default 25% */
html.dark .bg-mountain-backdrop {
  opacity: 0.25;
  filter: saturate(1.2) brightness(0.9);
}

/* Glassmorphic card surfaces */
.glass-panel {
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(226, 232, 240, 0.8);
  box-shadow: 0 4px 20px -2px rgba(15, 118, 110, 0.05), 0 2px 6px -1px rgba(0, 0, 0, 0.03);
}

html.dark .glass-panel {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(51, 65, 85, 0.6);
  box-shadow: 0 4px 25px -2px rgba(0, 0, 0, 0.35);
}

/* Stat card glow */
.stat-card-glow {
  position: relative;
  overflow: hidden;
}

.stat-card-glow::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: linear-gradient(90deg, #0F766E, #0E7490, #38BDF8);
  opacity: 0.9;
}

/* Modern table styling */
.custom-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.custom-table th {
  background-color: rgba(241, 245, 249, 0.85);
  font-weight: 600;
  letter-spacing: 0.025em;
  font-size: 0.75rem;
  text-transform: uppercase;
  padding: 0.75rem 1rem;
  border-bottom: 2px solid #E2E8F0;
}

html.dark .custom-table th {
  background-color: rgba(30, 41, 59, 0.85);
  border-bottom: 2px solid #334155;
  color: #94A3B8;
}

.custom-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #F1F5F9;
  font-size: 0.875rem;
}

html.dark .custom-table td {
  border-bottom: 1px solid rgba(51, 65, 85, 0.4);
}

.custom-table tbody tr {
  transition: background-color 0.15s ease;
}

.custom-table tbody tr:hover {
  background-color: rgba(240, 253, 250, 0.6);
}

html.dark .custom-table tbody tr:hover {
  background-color: rgba(19, 78, 74, 0.2);
}

/* Chart Canvas container */
.chart-container-box {
  position: relative;
  width: 100%;
  min-height: 280px;
  max-height: 420px;
}

@media (max-width: 640px) {
  .chart-container-box {
    min-height: 240px;
    max-height: 320px;
  }
}

/* Touch Friendly Scroll Container */
.touch-scroll-x {
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  scrollbar-width: thin;
}

/* Responsive Table Mobile Optimization */
@media (max-width: 640px) {
  .custom-table th {
    padding: 0.5rem 0.6rem;
    font-size: 0.7rem;
    white-space: nowrap;
  }
  .custom-table td {
    padding: 0.5rem 0.6rem;
    font-size: 0.75rem;
    white-space: nowrap;
  }
}

/* Mobile Responsive Fullscreen Fit for Chatbot, Modals & Layout */
@media (max-width: 640px) {
  /* Allow mobile container to use true 100% width with edge alignment */
  .max-w-7xl {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Prevent grid columns from pushing viewport width */
  .grid {
    min-width: 0 !important;
    width: 100% !important;
  }

  /* Ensure tables scroll smoothly without expanding parent */
  .overflow-x-auto {
    width: 100% !important;
    max-width: 100% !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Chatbot Mobile Fullscreen Fit */
  #ai-chat-window {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    border: none !important;
    margin: 0 !important;
    z-index: 60 !important;
  }

  #ai-chatbot-toggle-btn {
    bottom: 1rem !important;
    right: 1rem !important;
    padding: 0.6rem 0.9rem !important;
  }

  /* Modals Fullscreen on mobile */
  #factsheet-modal > div,
  #pdf-preview-modal > div {
    max-width: 100vw !important;
    width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    border: none !important;
  }

  /* SVG Map Responsive Width */
  #kepahiang-choropleth-svg {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
  }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 9999px;
}

html.dark ::-webkit-scrollbar-thumb {
  background: #334155;
}

::-webkit-scrollbar-thumb:hover {
  background: #94A3B8;
}

html.dark ::-webkit-scrollbar-thumb:hover {
  background: #475569;
}

/* Interactive Choropleth Map Styles */
.map-district-path {
  cursor: pointer;
  stroke: #FFFFFF;
  stroke-width: 1.5;
  stroke-linejoin: round;
  transition: all 0.25s ease;
}

html.dark .map-district-path {
  stroke: #0F172A;
}

.map-district-path:hover,
.map-district-path.is-active {
  stroke: #0F766E !important;
  stroke-width: 3.5 !important;
  filter: drop-shadow(0 6px 12px rgba(15, 118, 110, 0.45));
}

html.dark .map-district-path:hover,
html.dark .map-district-path.is-active {
  stroke: #2DD4BF !important;
  filter: drop-shadow(0 6px 14px rgba(45, 212, 191, 0.5));
}

/* Map Tooltip Floating */
#map-tooltip {
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.1s ease;
  z-index: 50;
}

/* Sticky Anchors Nav */
.sticky-nav-active {
  background: linear-gradient(135deg, #0F766E, #0E7490) !important;
  color: #FFFFFF !important;
  box-shadow: 0 4px 12px rgba(15, 118, 110, 0.25) !important;
}

/* Print View Optimization: Only print the 1-page Fact Sheet */
@media print {
  @page {
    size: A4 portrait;
    margin: 8mm;
  }

  body > *:not(#factsheet-printable) {
    display: none !important;
  }

  #mountain-backdrop,
  header,
  section,
  main,
  footer,
  #ai-chat-window,
  #ai-chatbot-toggle-btn,
  #factsheet-modal,
  .no-print {
    display: none !important;
  }

  body {
    background: #FFFFFF !important;
    color: #0F172A !important;
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif !important;
    margin: 0 !important;
    padding: 0 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  #factsheet-printable {
    display: block !important;
    position: static !important;
    width: 100% !important;
    max-width: 100% !important;
    box-shadow: none !important;
    border: none !important;
    background: #FFFFFF !important;
    color: #0F172A !important;
    page-break-after: avoid !important;
    page-break-inside: avoid !important;
  }
}
