/* Enhanced Census App Styles for Optimized Layout */

/* Global responsive foundation */
* {
  box-sizing: border-box;
}

html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  height: 100%;
}

body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  height: 100%;
  margin: 0;
  padding: 0;
}

/* Mobile viewport and scaling fixes */
@media (max-width: 767px) {
  html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    font-size: 16px; /* Prevent iOS zoom on form inputs */
    width: 100%;
    height: 100%;
  }
  
  body {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    font-size: 16px;
    min-width: 320px; /* Minimum mobile width */
    width: 100%;
    max-width: 100%;
    min-height: 100%;
    overflow-x: hidden; /* Prevent horizontal scroll but allow vertical */
    overflow-y: auto;
  }
}

/* Compact navbar for census app */
.navbar {
  min-height: 3rem;
  padding-top: 0.25rem;
  padding-bottom: 0.25rem;
}

/* Mobile navbar adjustments */
@media (max-width: 639px) {
  .navbar {
    min-height: 3.5rem; /* Slightly larger on mobile for better touch targets */
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }
  
  .navbar .btn {
    min-height: 2.5rem;
    min-width: 2.5rem;
  }
  
  .navbar h1 {
    font-size: 1rem !important;
  }
}

@media (min-width: 640px) {
  .navbar {
    min-height: 3.5rem;
  }
}

/* Ensure the sidebar modes are properly highlighted */
#mode-investigate.menu-active,
#mode-compare.menu-active,
#mode-identify.menu-active {
  font-weight: 600;
}

/* Mode-specific header styling */
.census-app section h1 {
  line-height: 1.2;
}

.census-app section p {
  opacity: 0.9;
}

/* Adjust sidebar position for compact navbar */
#sidebar {
  top: 48px !important;
  height: calc(100vh - 48px) !important;
  overflow-y: auto; /* Allow sidebar scrolling on mobile */
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* New Layout Structure - Left Sidebar and Right Map */
.census-app .flex-row {
  display: flex;
  flex-direction: row;
  gap: 1rem;
}

/* Top row should take 2/3 of viewport height on desktop; full/auto on mobile */
@media (min-width: 1024px) {
  .census-app .top-two-thirds {
    /* Allow the top section to expand with content while keeping a sensible minimum */
    min-height: 66.6667vh;
  }
}

@media (max-width: 1024px) {
  .census-app .lg\:flex-row {
    flex-direction: column;
  }
  /* On small screens, ensure the map drops below and does not cover the sidebar */
  .census-app .top-two-thirds {
    min-height: auto;
  }
  .census-app .lg\:w-2\/3,
  .census-app .lg\:w-1\/3 {
    width: 100% !important;
  }
}

/* Left Sidebar Controls - 1/3 width on large screens */
.census-app .left-sidebar {
  overflow-y: visible; /* no internal scroll on desktop */
  scrollbar-width: thin;
  scrollbar-color: rgba(156, 163, 175, 0.5) transparent;
  position: relative;
  z-index: 5; /* Ensure sidebar content sits above map if stacking occurs */
}

@media (min-width: 1024px) {
  .census-app .left-sidebar {
    width: 33.333333%;
    padding-right: 0.5rem; /* Add some padding to separate from map */
    /* Let content define the height to avoid clipping */
  }
  
  /* Ensure proper button layout in wider sidebar */
  .census-app .lg\:w-1\/3 button {
    white-space: nowrap; /* Prevent text wrapping when space allows */
  }
  
  .census-app .lg\:w-1\/3 button span.leading-tight {
    white-space: normal; /* Allow wrapping for multi-line labels */
  }
}

.census-app .left-sidebar::-webkit-scrollbar {
  width: 6px;
}

.census-app .left-sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.census-app .left-sidebar::-webkit-scrollbar-thumb {
  background-color: rgba(156, 163, 175, 0.5);
  border-radius: 3px;
}

/* Enhanced Left Sidebar Container Styles */
.census-app .flex.flex-col {
  display: flex;
  flex-direction: column;
}

/* Ensure left sidebar maintains consistent minimum height */
.census-app .left-sidebar,
.census-app .lg\:w-1\/3 {
  min-height: 448px;
}

@media (min-width: 1024px) {
  .census-app .left-sidebar,
  .census-app .lg\:w-1\/3 {
    min-height: 448px;
    display: flex;
    flex-direction: column;
  }
  
  /* Make the flex-1 section expand to fill available space */
  .census-app .lg\:w-1\/3 section.flex-1 {
    flex: 1;
    display: flex;
    flex-direction: column;
  }

  /* Ensure inner sections in left panel compress rather than overflow */
  .census-app .lg\:w-1\/3 section {
    min-height: 0;
  }
  
  /* Ensure right column (map container) stretches to match left sidebar */
  .census-app .lg\:w-2\/3 {
    display: flex;
    flex-direction: column;
    height: 100%;
  }
  
  /* Make map container fill available height */
  .census-app .lg\:w-2\/3 > div.lg\:flex-1 {
    display: flex;
    flex-direction: column;
    min-height: 0; /* Allow proper flex sizing */
  }

  .census-app .lg\:w-2\/3 {
    height: 100%;
  }
}

/* Height utilities - Reduced by 20% */
.census-app .h-\[280px\] {
  height: 280px;
}

.census-app .h-\[320px\] {
  height: 320px;
}

/* Fixed map heights for mobile - important to maintain consistency */
.census-app .h-\[368px\] {
  height: 368px !important;
  min-height: 368px !important;
  max-height: 368px !important;
}

.census-app .h-\[400px\] {
  height: 400px;
}

.census-app .h-\[448px\] {
  height: 448px;
}

.census-app .lg\:h-\[320px\] {
  height: 320px;
}

.census-app .lg\:h-\[448px\] {
  height: 448px;
}

/* Make map flexible on large screens */
@media (min-width: 1024px) {
  /* Allow map containers with the mobile fixed height utility to expand on desktop */
  .census-app .h-\[368px\] {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
  }
  .census-app .lg\:h-auto {
    height: auto !important;
  }
  
  .census-app .lg\:flex-1 {
    flex: 1 1 0% !important;
    min-height: 0;
  }
}

.census-app .min-h-\[320px\] {
  min-height: 320px;
}

.census-app .lg\:min-h-\[360px\] {
  min-height: 360px;
}

.census-app .lg\:max-h-\[480px\] {
  max-height: 480px;
}

/* Ensure sections within sidebar expand properly */
.census-app section {
  display: flex;
  flex-direction: column;
}

@media (min-width: 1024px) {
  .census-app .lg\:min-h-\[360px\] {
    min-height: 360px;
  }
  .census-app .lg\:max-h-\[480px\] {
    max-height: 480px;
  }
  .census-app .lg\:h-\[448px\] {
    height: 448px;
  }
}

/* Ensure proper flex alignment for sidebar and map */
.census-app .flex-col.lg\:flex-row {
  display: flex;
  align-items: stretch;
}

/* Ensure both sidebar and map have equal height and align at bottom */
@media (min-width: 1024px) {
  .census-app .flex.flex-col.lg\:flex-row.items-stretch > div {
    display: flex;
    flex-direction: column;
  }
  
  /* Make both sidebar and map equal height */
  .census-app .lg\:w-1\/3,
  .census-app .lg\:w-2\/3 {
    min-height: 100%;
    display: flex;
    flex-direction: column;
  }
  
  /* Ensure map container fills available height */
  .census-app .lg\:w-2\/3 > div:first-child {
    flex: 1;
    display: flex;
    flex-direction: column;
  }
}

@media (min-width: 1024px) {
  .census-app .lg\:flex-row {
    flex-direction: row !important;
  }
  
  /* Width classes for the new 1/3 and 2/3 layout */
  .census-app .lg\:w-1\/3 {
    width: 33.333333% !important;
    max-width: 33.333333% !important;
    flex: 0 0 33.333333%;
  }
  
  .census-app .lg\:w-2\/3 {
    width: 66.666667% !important;
    max-width: 66.666667% !important;
    flex: 0 0 66.666667%;
  }
  
  /* Legacy support for 1/4 and 3/4 if still used elsewhere */
  .census-app .lg\:w-1\/4 {
    width: 25% !important;
    max-width: 25% !important;
  }
  
  .census-app .lg\:w-3\/4 {
    width: 75% !important;
    max-width: 75% !important;
  }
  
  .census-app .lg\:h-auto {
    height: auto !important;
  }
  
  .census-app .lg\:h-\[400px\] {
    height: 400px !important;
  }
  
  .census-app .lg\:h-\[500px\] {
    height: 500px !important;
  }
  
  .census-app .lg\:mx-auto {
    margin-left: auto !important;
    margin-right: auto !important;
  }
}

/* Ensure items stay side by side on larger screens with equal height */
.census-app .items-stretch {
  align-items: stretch;
}

@media (min-width: 1024px) {
  /* Ensure flex row container allows children to stretch */
  .census-app .lg\:flex-row.items-stretch {
    align-items: stretch;
    min-height: 0;
  }
  
  /* Both columns should stretch to equal height */
  .census-app .lg\:flex-row.items-stretch > div {
    align-self: stretch;
  }
}

/* Map container with area selector */
.census-app .flex.flex-col.gap-2 {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.census-app .flex.flex-col.gap-3 {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Area selector positioning */
.census-app .w-full.lg\:w-1\/2.lg\:mx-auto {
  width: 100%;
}

@media (min-width: 1024px) {
  .census-app .w-full.lg\:w-1\/2.lg\:mx-auto {
    width: 50%;
    margin-left: auto;
    margin-right: auto;
  }
}

/* Enhanced button styles for Reports & Analytics */
.census-app button[class*="min-h-"] {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: visible; /* Allow badges to extend outside */
}

/* Text wrapping for multi-line button labels */
.census-app .leading-tight {
  line-height: 1.2;
}

/* Enhanced AI badges positioning and visibility */
.census-app .relative .absolute {
  z-index: 10;
}

/* Ensure AI badges are always visible */
.census-app button .absolute.-top-2.-right-2 {
  z-index: 20;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Button hover effects */
.census-app button.transform.hover\:scale-105:hover {
  transform: scale(1.05);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* Active button styles */
.census-app button[class*="from-primary"],
.census-app button[class*="from-secondary"] {
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15), 0 10px 10px -5px rgba(0, 0, 0, 0.06);
}

/* Improved button text visibility */
.census-app button span.font-medium {
  font-weight: 600;
  letter-spacing: 0.025em;
}

/* Responsive grid adjustments */
@media (min-width: 1536px) {
  .census-app .\\32xl\:grid-cols-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 1280px) {
  .census-app .xl\:grid-cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .census-app .lg\:grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .census-app .lg\:text-\[11px\] {
    font-size: 11px;
  }
  .census-app .lg\:min-h-\[50px\] {
    min-height: 50px;
  }
  .census-app .lg\:min-h-\[40px\] {
    min-height: 40px;
  }
}

@media (min-width: 640px) {
  .census-app .sm\:grid-cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* Base grid columns */
.census-app .grid-cols-1 {
  grid-template-columns: repeat(1, minmax(0, 1fr));
}

.census-app .grid-cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* Grid span utilities */
.census-app .col-span-full {
  grid-column: 1 / -1;
}

/* Smaller screen adjustments */
@media (max-width: 639px) {
  /* Ensure readable text on mobile */
  .census-app button span:not(.absolute) {
    font-size: inherit; /* Use the font size from button class */
  }
  
  /* Maintain proper button heights on mobile */
  .census-app button[class*="min-h-"] {
    min-height: inherit; /* Don't override the min-height set in classes */
  }
  
  /* Ensure touch-friendly targets */
  .census-app section button {
    min-width: 44px; /* iOS touch target minimum */
  }
}

/* Padding adjustments */
.census-app .p-3 {
  padding: 0.75rem;
}

.census-app .p-4 {
  padding: 1rem;
}

.census-app .lg\:p-6 {
  padding: 1.5rem;
}

@media (min-width: 1024px) {
  .census-app .lg\:p-6 {
    padding: 1.5rem;
  }
}

.census-app .mb-1\.5 {
  margin-bottom: 0.375rem;
}

/* Button text size adjustments */
.census-app .text-xs {
  font-size: 0.75rem;
  line-height: 1rem;
}

.census-app .text-\[10px\] {
  font-size: 10px;
}

.census-app .text-\[11px\] {
  font-size: 11px;
}

/* Area selector button styles */
.census-app .min-w-\[60px\] {
  min-width: 60px;
}

.census-app .px-3 {
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}

.census-app .py-1\.5 {
  padding-top: 0.375rem;
  padding-bottom: 0.375rem;
}

/* Ensure proper button heights */
.census-app .min-h-\[35px\] {
  min-height: 35px;
}

.census-app .min-h-\[40px\] {
  min-height: 40px;
}

.census-app .min-h-\[45px\] {
  min-height: 45px;
}

.census-app .min-h-\[50px\] {
  min-height: 50px;
}

/* Gap adjustments */
.census-app .gap-1 {
  gap: 0.25rem;
}

.census-app .gap-2 {
  gap: 0.5rem;
}

.census-app .gap-3 {
  gap: 0.75rem;
}

.census-app .gap-4 {
  gap: 1rem;
}

.census-app .gap-1\.5 {
  gap: 0.375rem;
}

.census-app .gap-0\.5 {
  gap: 0.125rem;
}

/* Compare Mode Specific Styles */
.census-app .items-end {
  align-items: flex-end;
}

/* Ensure proper alignment for compare mode controls */
.census-app .grid.items-end > div {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

/* Compare mode area boxes */
.census-app .bg-blue-50\/50,
.census-app .bg-green-50\/50 {
  background-color: rgba(239, 246, 255, 0.5);
}

.dark .census-app .bg-blue-50\/50 {
  background-color: rgba(30, 58, 138, 0.1);
}

.dark .census-app .bg-green-50\/50 {
  background-color: rgba(20, 83, 45, 0.1);
}

/* Consistent heights for compare mode inputs */
.census-app input[type="text"],
.census-app select {
  min-height: 38px; /* Allow content to define final height to avoid clipping */
  line-height: normal; /* Prevent text from being vertically clipped */
}

/* Responsive alignment for smaller screens */
@media (max-width: 640px) {
  .census-app .grid.sm\:grid-cols-2 {
    grid-template-columns: 1fr;
  }
  
  .census-app .grid.items-end {
    align-items: stretch;
  }
}

/* Map Container - 3/4 width on large screens, reduced height by 20% */
.census-app .map-container {
  min-height: 320px;
  height: 100%;
  position: relative;
}

@media (min-width: 1024px) {
  .census-app .map-container {
    min-height: 400px;
    width: 75%;
  }
}

/* Bottom Report Section */
.census-app .report-section {
  margin-top: 2rem;
  max-width: 100%;
  width: 100%;
}

@media (min-width: 640px) {
  #sidebar {
    top: 56px !important;
    height: calc(100vh - 56px) !important;
  }
}

/* Optimize main content area for different screen sizes */
.census-app {
  display: flex;
  flex-direction: column;
  height: 100%;
  background-color: #f9fafb;
  overflow: visible; /* Prevent additional scrollbar from census-app container */
}

.dark .census-app {
  background-color: #111827;
}

/* Ensure census app container has proper background */
#census-app {
  background-color: #f9fafb;
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  overflow: visible; /* Prevent additional scrollbar */
}

.dark #census-app {
  background-color: #111827;
}

.census-app main {
  flex: 1;
  width: 100%;
  overflow: visible; /* Don't create scrollbar at main level */
}

/* Ensure full height usage without footer constraints */
.section {
  min-height: calc(100vh - 56px); /* Account for navbar */
  overflow: visible; /* Allow content to expand */
}

#main-content {
  min-height: 100%;
  position: relative;
  overflow-y: visible; /* Let body handle scrolling by default */
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Desktop: Allow main-content scrolling when sidebar is fixed */
@media (min-width: 768px) {
  #main-content {
    overflow-y: auto;
  }
}

/* Mobile-specific main content */
@media (max-width: 767px) {
  #main-content {
    overflow-y: visible; /* Let body handle scrolling on mobile */
    overflow-x: hidden;
    min-height: calc(100vh - 48px); /* Changed from height to min-height */
  }
  
  .section {
    min-height: calc(100vh - 48px);
  }
}

/* Reduce top padding since header is now in navbar */
/* Only apply padding to the first section, not between sections */
.census-app main > div:first-child {
  padding-top: 0.5rem;
}

@media (min-width: 640px) {
  .census-app main > div:first-child {
    padding-top: 0.75rem;
  }
}

/* Ensure consistent spacing for analytics and initial state sections */
/* These sections maintain their natural spacing to prevent layout shifts */

/* Ensure map container uses available space efficiently */
.leaflet-container {
  width: 100%;
  height: 100%;
  border-radius: 0.5rem;
}

/* Ensure map fills the flex-1 container on large screens */
@media (min-width: 1024px) {
  .census-app .lg\:flex-1 .leaflet-container {
    height: 100%;
    min-height: 448px; /* Minimum height to match sidebar */
  }
  
  /* Ensure overflow-hidden doesn't prevent flex expansion */
  .census-app .lg\:flex-1.overflow-hidden {
    overflow: hidden; /* Keep for rounded corners */
    display: flex;
    flex-direction: column;
  }
}

/* Ensure proper flex behavior for main sections */
@media (min-width: 1024px) {
  /* Map container should fill available height */
  .census-app .lg\:w-2\/3 > div:first-child {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
  }
}

/* Maintain top section layout */
.census-app main > div:first-child {
  display: flex;
}

/* Recharts: ensure charts use full width and labels aren't clipped */
.census-app .recharts-responsive-container,
.census-app .recharts-wrapper { width: 100% !important; }

.census-app .recharts-surface { overflow: visible; }

.census-app .recharts-cartesian-axis-tick text { white-space: pre-line; }

/* Reduce horizontal padding around chart blocks to utilize width */
.census-app .bg-white.dark\:bg-gray-800.rounded-xl.shadow-lg,
.census-app .bg-white.dark\:bg-gray-800.rounded-xl.shadow-lg.overflow-hidden {
  padding-left: 0.5rem !important;
  padding-right: 0.5rem !important;
}
@media (min-width: 640px) {
  .census-app .bg-white.dark\:bg-gray-800.rounded-xl.shadow-lg,
  .census-app .bg-white.dark\:bg-gray-800.rounded-xl.shadow-lg.overflow-hidden {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }
}

/* Mobile optimizations */
@media (max-width: 640px) {
  /* Ensure proper mobile viewport scaling */
  html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
  }
  
  body {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    position: relative;
  }
  
  /* Compact header on mobile */
  .census-app h1 {
    font-size: 1.125rem;
  }
  
  /* Ensure map is visible on mobile - reduced by 20% */
  section[aria-labelledby="census-map-heading"] {
    min-height: 280px;
  }
  
  /* Adjust padding for mobile */
  .census-app main > div:first-child {
    padding: 0.5rem;
  }
  
  /* Make tabs scrollable on mobile */
  .census-app nav[aria-label="Tabs"] {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Hide sidebar labels on very small screens */
  #sidebar .text-xs.text-gray-500 {
    display: none;
  }
  
  /* Ensure proper font sizes on mobile */
  .census-app {
    font-size: 14px;
    line-height: 1.4;
  }
  
  /* Make buttons and inputs properly sized for mobile */
  .census-app button,
  .census-app input,
  .census-app select {
    min-height: 44px;
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  /* Ensure proper touch targets */
  .census-app a,
  .census-app button {
    min-height: 44px;
    min-width: 44px;
  }
}

/* Tablet optimizations - reduced by 20% */
@media (min-width: 641px) and (max-width: 1024px) {
  section[aria-labelledby="census-map-heading"] {
    height: 360px !important;
  }
}

/* Desktop optimizations */
@media (min-width: 1025px) {
  /* Ensure proper sidebar width */
  #sidebar {
    width: 16rem;
  }
  
  /* Adjust main content margin when sidebar is open */
  #sidebar:not(.-translate-x-full) ~ #main-content {
    margin-left: 16rem;
    width: calc(100% - 16rem);
  }
  
  /* Optimize grid layout for large screens */
  .census-app .grid.lg\:grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  
  /* Full width utilization for main content */
  .census-app main {
    width: 100%;
  }
  
  .census-app main > div {
    width: 100%;
    max-width: 100%;
    padding: 1.5rem 2rem;
  }
}

/* Extra large screens */
@media (min-width: 1440px) {
  /* Use full available width */
  .census-app main > div {
    width: 100%;
    max-width: none;
  }
  
  section[aria-labelledby="census-map-heading"] {
    max-height: 560px;
  }
}

/* Smooth transitions */
#sidebar,
#main-content,
.census-app nav a {
  transition: all 0.3s ease;
}

/* Improve mode indicator visibility */
.census-app .font-semibold.px-2.py-1.rounded-md {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
}

/* Ensure filters section doesn't take too much space */
.filters-container {
  max-height: fit-content;
}

/* Optimize Compare mode area filters */
@media (min-width: 1024px) {
  .filters-container .grid.lg\:grid-cols-2 {
    align-items: start;
  }
}

/* Better visual hierarchy for mode badges */
.census-app .rounded-full {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Smooth transitions for interactive elements */
.census-app button,
.census-app input,
.census-app select {
  transition: all 0.15s ease;
}

/* Improve tab navigation on smaller screens */
@media (max-width: 768px) {
  .census-app nav[aria-label="Tabs"] {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0.25rem;
    padding-bottom: 0.5rem;
  }
  
  .census-app nav[aria-label="Tabs"]::-webkit-scrollbar {
    height: 4px;
  }
  
  .census-app nav[aria-label="Tabs"]::-webkit-scrollbar-thumb {
    background-color: rgba(156, 163, 175, 0.5);
    border-radius: 2px;
  }
}

/* Ensure proper z-index for overlays */
.census-app .fixed.inset-0 {
  z-index: 9999;
}

/* Optimize sidebar mode items */
#sidebar li a {
  position: relative;
  transition: all 0.2s ease;
}

#sidebar li a:hover {
  transform: translateX(2px);
}

/* Active mode indicator animation */
#sidebar li a.border-l-4 {
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Enhanced responsive breakpoints */
@media (min-width: 1920px) {
  /* Ultra-wide screens */
  .census-app main > div {
    padding: 2rem 3rem;
  }
  
  .filters-container {
    padding: 2rem;
  }
}

/* Improved mobile landscape */
@media (max-width: 1024px) and (orientation: landscape) {
  .census-app main > div {
    padding: 1rem 1.5rem;
  }
  
  section[aria-labelledby="census-map-heading"] {
    height: 320px !important;
  }
}

/* Enhanced tablet portrait */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
  .census-app main > div {
    padding: 1.25rem 1.5rem;
  }
  
  .filters-container {
    padding: 1.25rem 1.5rem;
  }
}

/* Fix for very small screens */
@media (max-width: 360px) {
  .census-app main > div {
    padding: 0.75rem 1rem;
  }
  
  .filters-container {
    padding: 1rem;
  }
  
  /* Ensure buttons are touch-friendly */
  .census-app button {
    min-height: 48px;
    min-width: 48px;
  }
}

/* Print styles */
@media print {
  #sidebar,
  .census-app nav[aria-label="Tabs"] {
    display: none;
  }
  
  .census-app main {
    overflow: visible;
    width: 100% !important;
  }
  
  #main-content {
    margin-left: 0 !important;
    width: 100% !important;
  }
  
  section[aria-labelledby="census-map-heading"] {
    height: auto !important;
    page-break-inside: avoid;
  }
}

/* ========================================
   Compact Content Utilities
   Optimizes layouts to fit within viewport
   ======================================== */

/* Viewport-constrained content panel */
.compact-content {
  max-height: calc(100vh - 110px);
  overflow: hidden;
}

@media (min-width: 1024px) {
  .compact-content {
    max-height: calc(100vh - 100px);
  }
}

/* Content area within the main panel */
#census-app .flex-1 {
  min-height: 0; /* Enable proper flex shrinking */
}

/* Ensure content panel doesn't overflow on desktop */
@media (min-width: 1024px) {
  #census-app > div {
    height: calc(100vh - 56px);
    max-height: calc(100vh - 56px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  
  /* Content panel should fill remaining space */
  #census-app > div > .flex-1 {
    flex: 1;
    overflow: auto;
    min-height: 0;
  }
}

/* Compact spacing utilities for UI density */
.space-compact > * + * {
  margin-top: 0.5rem;
}

.gap-compact {
  gap: 0.5rem;
}

/* Reduced padding for tight layouts */
.p-compact {
  padding: 0.5rem;
}

@media (min-width: 640px) {
  .p-compact {
    padding: 0.75rem;
  }
}

@media (min-width: 1024px) {
  .p-compact {
    padding: 1rem;
  }
}

/* Line clamp utilities */
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Ensure proper scrollbar styling */
.census-app ::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.census-app ::-webkit-scrollbar-track {
  background: transparent;
}

.census-app ::-webkit-scrollbar-thumb {
  background-color: rgba(156, 163, 175, 0.4);
  border-radius: 3px;
}

.dark .census-app ::-webkit-scrollbar-thumb {
  background-color: rgba(107, 114, 128, 0.4);
}

.census-app ::-webkit-scrollbar-thumb:hover {
  background-color: rgba(156, 163, 175, 0.6);
}

.dark .census-app ::-webkit-scrollbar-thumb:hover {
  background-color: rgba(107, 114, 128, 0.6);
}

/* Ensure cards fit without excessive whitespace */
.census-app .grid {
  align-content: start;
}

/* Optimize snapshot cards grid for 2 columns on desktop */
@media (min-width: 640px) {
  .census-app .grid.grid-cols-1.sm\\:grid-cols-2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ========================================
   Overview Panel Layout Optimization
   Ensures proper space distribution
   ======================================== */

/* Overview layout - balanced 50/50 split for readability */
@media (min-width: 1024px) {
  /* Both panels take 50% each */
  .census-app .lg\:w-\[50\%\] {
    width: 50% !important;
    flex: 0 0 50%;
  }
  
  /* Ensure map container fills available height */
  .census-app .lg\:w-\[50\%\] .flex-1 {
    flex: 1;
    min-height: 300px;
  }
}

/* Snapshot cards in compare mode - stacked vertically */
.census-app .flex.flex-col.gap-2 > .border-l-4 {
  max-height: 50%;
  overflow-y: auto;
}

/* Ensure the trend chart at bottom is visible */
.census-app .flex-shrink-0 {
  flex-shrink: 0;
}

/* Ensure proper height for overview panels */
@media (min-width: 1024px) {
  .census-app .h-full.flex.flex-col.gap-2 {
    height: 100%;
  }
  
  /* Both panels with controls/snapshots and map */
  .census-app .lg\\:w-\\[50\\%\\] {
    display: flex;
    flex-direction: column;
  }
}

/* Improve snapshot section scrolling behavior */
.census-app .overflow-y-auto.min-h-0 {
  scrollbar-width: thin;
  scrollbar-color: rgba(156, 163, 175, 0.4) transparent;
}

/* Compact area header styling */
.census-app .border-l-4 h3 {
  font-size: 0.875rem !important;
}

/* Map container should fill available height */
@media (min-width: 1024px) {
  .census-app .lg\\:w-\\[50\\%\\] > div {
    height: 100%;
  }
}

/* Report CTA styling to feel like a product card */
.census-app .report-cta-card {
  background-image: linear-gradient(180deg, rgba(59, 130, 246, 0.06), rgba(255, 255, 255, 0));
}
