/* ============================================================================
   PAGE STYLES - Homepage, Explorer, and Client Map page layouts
   ============================================================================
   Consolidates:
   - Homepage hero, sections, and grid layouts
   - Explorer map page viewport and filter layout
   - Client map popup and sidebar positioning
   - Responsive breakpoints for all pages
*/

/* ──────────────────────────────────────────────────────
   HOMEPAGE - Hero Section & Layout
   ────────────────────────────────────────────────────– */

.hero-container {
  position: relative;
  height: 50vh;
  min-height: 300px;
  overflow: hidden;
}

.hero-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url(https://caboz.ch/media/pages/hero/1230733497-1717883727/p1050185-3000x.jpg);
  background-size: cover;
  background-position: 75% center;
  z-index: 0;
}

.hero-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.6));
  z-index: 1;
}

.hero-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  display: flex;
  align-items: center;
}

/* Hero text - responsive sizing */
.hero-title {
  font-weight: 900;
  color: white;
  line-height: 1.1;
  text-align: center;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  margin: 0;
  font-size: clamp(1.5rem, 5vw, 3.5rem);
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: normal;
  hyphens: auto;
}

.hero-subtitle {
  font-weight: 400;
  color: rgba(255, 255, 255, 0.9);
  line-height: 1.3;
  text-align: center;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
  margin: 0.3rem 0 0 0;
  font-size: clamp(0.9rem, 2.5vw, 1.4rem);
}

/* Mobile hero adjustments */
@media (max-width: 767px) {
  .hero-title {
    font-size: clamp(1.2rem, 4vw, 2rem);
  }

  .hero-subtitle {
    font-size: clamp(0.75rem, 2vw, 1rem);
  }
}

/* Tablet/Desktop */
@media (min-width: 768px) and (max-width: 991px) {
  .hero-title {
    font-size: clamp(1.8rem, 4vw, 2.8rem);
  }
}

@media (min-width: 1200px) {
  .hero-title {
    font-size: 3.5rem;
  }
}

/* ──────────────────────────────────────────────────────
   HOMEPAGE - Section Styling
   ────────────────────────────────────────────────────– */

.impact-section,
.biodiversity-section {
  background-color: #fcfcfc;
}

.impact-image,
.biodiversity-image {
  height: 400px;
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  background-size: cover;
  background-position: center;
}

/* ──────────────────────────────────────────────────────
   HOMEPAGE - Page Preview Cards
   ────────────────────────────────────────────────────– */

.page-preview-card {
  display: flex !important;
  flex-direction: column !important;
  justify-content: center !important;
  align-items: center !important;
  min-height: 100px !important;
  min-width: 90px !important;
  padding: 1rem !important;
  cursor: pointer !important;
  transition: all 0.3s ease !important;
  text-decoration: none !important;
  color: white !important;
  border: none !important;
  border-radius: var(--radius-md) !important;
  background-color: transparent !important;
  background: transparent !important;
}

.page-preview-card:hover {
  background-color: rgba(255, 255, 255, 0.1) !important;
  border-radius: var(--radius-lg) !important;
  transform: translateY(-4px) !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2) !important;
}

/* Icon styling */
.page-preview-icon {
  color: white !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.page-preview-icon svg {
  fill: white !important;
  color: white !important;
}

.page-preview-card .mantine-Stack-root {
  color: white !important;
  background-color: transparent !important;
}

.page-preview-card .mantine-Text-root {
  color: white !important;
}

/* ──────────────────────────────────────────────────────
   HOMEPAGE - Project Cards (Transparency Layout)
   ────────────────────────────────────────────────────– */

.project-card-hover {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
  cursor: pointer !important;
}

.project-card-hover:hover {
  transform: translateY(-6px) !important;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12) !important;
  border-color: var(--mantine-color-gray-300) !important;
}

.page-list-item {
  transition: all 0.2s ease !important;
  text-decoration: none !important;
}

.page-list-item:hover {
  opacity: 0.8 !important;
  transform: translateX(4px) !important;
}

/* ──────────────────────────────────────────────────────
   HOMEPAGE - Main Grid & Layout
   ────────────────────────────────────────────────────– */

#home-page-container {
  width: 100%;
  overflow-x: hidden;
}

@media (max-width: 768px) {
  /* Grid response on mobile */
  .mantine-Grid-col {
    padding: 0.5rem !important;
  }

  .mantine-GridCol-root[style*="base: 12"] {
    width: 100% !important;
  }

  /* Reduce text sizes */
  .mantine-Text-root[size="sm"] {
    font-size: calc(0.75rem - 0.1rem) !important;
  }

  .mantine-Text-root[size="xs"] {
    font-size: calc(0.65rem - 0.05rem) !important;
  }

  /* Icon sizing */
  [style*="width: 36px"] {
    width: 32px !important;
    height: 32px !important;
  }

  /* Tight stacking (home page only) */
  #home-page-container .mantine-Stack-root {
    gap: 0.25rem !important;
  }

  .mantine-Container-root {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }

  /* Compact groups (home page only) */
  #home-page-container .mantine-Group-root {
    gap: 0.25rem !important;
  }
}

/* Small mobile phones */
@media (max-width: 479px) {
  #home-page-container {
    padding: 0 !important;
  }

  .mantine-GridCol-root {
    width: 100% !important;
    padding: 0.25rem !important;
  }

  #home-page-container .mantine-Paper-root {
    padding: 0.5rem !important;
  }

  .mantine-Text-root {
    word-break: break-word !important;
  }

  #home-page-container .mantine-Group-root {
    gap: 0.15rem !important;
    row-gap: 0.25rem !important;
  }

  img[style*="height: 20px"] {
    height: 16px !important;
  }
}

/* Prevent horizontal scrolling */
@media (max-width: 768px) {
  body,
  html {
    overflow-x: hidden !important;
    width: 100% !important;
  }

  #page-content {
    width: 100% !important;
    overflow-x: hidden !important;
  }

  .mantine-Container-root {
    max-width: 100% !important;
    width: 100% !important;
  }
}

/* Large screens */
@media (min-width: 900px) {
  .mantine-Container-root {
    padding-left: 2rem !important;
    padding-right: 2rem !important;
  }

  .mantine-Grid-col {
    padding: 1rem !important;
  }
}

/* Responsive 2-col grid */
@media (max-width: 640px) {
  [style*="cols="] .mantine-Grid-col {
    max-width: 50% !important;
    padding: 0.35rem !important;
  }
}

/* Dual background images - responsive */
.hero-bg-left {
  width: 50% !important;
  left: 0 !important;
}

.hero-bg-right {
  width: 50% !important;
  right: 0 !important;
}

@media (max-width: 767px) {
  .hero-bg-left {
    width: 100% !important;
  }

  .hero-bg-right {
    display: none !important;
  }
}

/* Project cards - flex distribution (home page) */
.mantine-SimpleGrid-root .mantine-Paper-root {
  display: flex !important;
  flex-direction: column !important;
  justify-content: space-between !important;
}

/* Explorer cards should NOT spread content */
.explorer-page .mantine-SimpleGrid-root .mantine-Paper-root {
  justify-content: flex-start !important;
  min-height: auto !important;
}

.mantine-Paper-root .mantine-Title-root {
  word-break: break-word !important;
  white-space: normal !important;
  min-width: 0 !important;
}

/* Mobile - larger project cards (home page only) */
@media (max-width: 768px) {
  #home-page-container .mantine-Paper-root .mantine-Group-root {
    gap: 1.25rem !important;
    row-gap: 1.25rem !important;
  }

  .page-preview-card {
    min-height: 110px !important;
    min-width: 100px !important;
    padding: 1rem !important;
  }

  #home-page-container .mantine-SimpleGrid-root .mantine-Paper-root {
    min-height: 340px !important;
    padding: 2rem !important;
  }

  #home-page-container .mantine-Paper-root .mantine-Title-root {
    font-size: 1.3rem !important;
    margin-bottom: 1.5rem !important;
  }
}

/* Very small screens (home page only) */
@media (max-width: 480px) {
  #home-page-container .mantine-SimpleGrid-root .mantine-Paper-root {
    min-height: 360px !important;
    padding: 1.75rem !important;
  }

  #home-page-container .mantine-Paper-root .mantine-Title-root {
    font-size: 1.2rem !important;
    margin-bottom: 1.25rem !important;
  }

  .page-preview-card {
    min-height: 105px !important;
    min-width: 95px !important;
    padding: 0.75rem !important;
  }

  #home-page-container .mantine-Paper-root .mantine-Group-root {
    gap: 1rem !important;
    row-gap: 1rem !important;
  }
}

/* ──────────────────────────────────────────────────────
   EXPLORER PAGE - Map & Viewport Layout
   ────────────────────────────────────────────────────– */

/* Map info card styling */
.map-info-card {
  padding: 10px 12px;
  font-family: var(--font-family);
  background: var(--map-info-bg);
  box-shadow: var(--map-info-shadow);
  border-radius: var(--radius-lg);
  border: var(--map-info-border);
  pointer-events: none;
  z-index: 60 !important;
}

.map-info-card h4 {
  margin: 0 0 6px 0;
  color: #214097;
  font-size: 16px;
  border-bottom: 1px solid #eee;
  padding-bottom: 4px;
}

.map-info-card .info-row {
  margin: 4px 0;
  font-size: 13px;
  line-height: 1.4;
}

.map-info-card .info-label {
  font-weight: 600;
  color: #666;
  margin-right: 4px;
}

.map-info-card .info-value {
  color: #333;
}

/* Explorer viewport layout */
/* Shared full-width page container */
.page-container {
  max-width: 90% !important;
  width: 100% !important;
  box-sizing: border-box !important;
  overflow-x: hidden;
}

@media screen and (max-width: 768px) {
  .page-container {
    max-width: 100% !important;
    padding-left: 8px !important;
    padding-right: 8px !important;
  }
}

/* Explorer-specific: fill viewport with flex column */
.explorer-page {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 90px);
}

/* Tabs root fills remaining space */
.explorer-page > .mantine-Tabs-root {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Active panel fills remaining tab space */
.explorer-page .mantine-Tabs-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: auto;
}

/* Map & table Paper fills its panel */
.explorer-page .mantine-Tabs-panel > .mantine-Paper-root {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* KPI subtabs: fill panel and make content scroll */
.explorer-page .mantine-Tabs-panel > .mantine-Tabs-root {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.explorer-page .mantine-Tabs-panel > .mantine-Tabs-root > .mantine-Tabs-list {
  flex-shrink: 0;
}

/* All explorer tabs: horizontal scroll on mobile */
@media screen and (max-width: 768px) {
  /* Main tabs (Map / Table / KPI) */
  .explorer-page .mantine-Tabs-list {
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 0 !important;
  }
  .explorer-page .mantine-Tabs-list::-webkit-scrollbar {
    display: none;
  }
  .explorer-page .mantine-Tabs-list .mantine-Tabs-tab {
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    font-size: 12px;
    padding: 6px 10px;
  }
}

.explorer-page #explorer-kpi-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

/* KPI content children should not stretch */
.explorer-page #explorer-kpi-content > * {
  height: auto !important;
  flex: none !important;
}

/* Mobile: prevent KPI cards from stretching */
@media screen and (max-width: 768px) {
  .explorer-page #explorer-kpi-content > .mantine-SimpleGrid-root > .mantine-Card-root {
    height: auto !important;
    min-height: auto !important;
    align-self: start !important;
  }

  .explorer-page .mantine-SimpleGrid-root {
    align-content: flex-start !important;
  }
}

/* Paper Stack for table: flex container for Group + AgGrid */
.explorer-page .mantine-Tabs-panel > .mantine-Paper-root > .mantine-Stack-root {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Group with Columns/Export buttons doesn't shrink */
.explorer-page .mantine-Tabs-panel > .mantine-Paper-root > .mantine-Stack-root > .mantine-Group-root {
  flex-shrink: 0;
}

/* AgGrid wrapper fills its Stack parent */
.explorer-page .ag-theme-alpine {
  flex: 1;
  min-height: 0;
  overflow: hidden !important;
}

/* AG Grid body viewport needs explicit constraints */
.explorer-page .ag-root-wrapper {
  height: 100%;
  overflow: hidden;
}

.explorer-page .ag-body-viewport {
  min-height: 0;
}

/* Mobile: KPI specific layout */
@media screen and (max-width: 768px) {
  /* KPI content should scroll, not stretch cards */
  .explorer-page #explorer-kpi-content {
    flex: none !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* KPI content children should not stretch on mobile */
  .explorer-page #explorer-kpi-content > * {
    height: auto !important;
    flex: none !important;
    min-height: auto !important;
  }

  /* Override global project-card rules that bleed into explorer */
  .explorer-page .mantine-SimpleGrid-root .mantine-Paper-root {
    min-height: auto !important;
    justify-content: flex-start !important;
    margin-bottom: 0 !important;
  }
  .explorer-page .mantine-SimpleGrid-root .mantine-Card-root {
    height: auto !important;
    min-height: auto !important;
    align-self: start !important;
    margin-bottom: 0 !important;
  }

  /* Restore basic layout */
  .explorer-page {
    height: auto !important;
    overflow: visible !important;
  }

  /* Tab panels: large fixed min-height on mobile (not viewport-based) */
  .explorer-page .mantine-Tabs-panel {
    min-height: 600px !important;
    overflow: visible !important;
  }

  /* Specific sizing for map and table content to ensure visibility */
  .explorer-page .leaflet-container,
  .explorer-page #explorer-map-container,
  .explorer-page .ag-theme-alpine {
    height: 600px !important;
    min-height: 400px !important;
    width: 100% !important;
  }

  /* Force AgGrid internals to show even if initially empty */
  .explorer-page .ag-root-wrapper,
  .explorer-page .ag-root-wrapper-body {
    height: 100% !important;
    min-height: 400px !important;
  }

  /* Hide legend content on mobile */
  .explorer-page #explorer-map-legend-container {
    display: none !important;
  }
}

/* Leaflet pseudo-fullscreen (iOS fallback — no native Fullscreen API) */
.leaflet-pseudo-fullscreen {
  position: fixed !important;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  top: 0 !important;
  left: 0 !important;
  z-index: 99999 !important;
}

/* AG Grid paging panel - responsive layout */
.explorer-page .ag-paging-panel {
  height: auto;
  flex-wrap: wrap-reverse;
  row-gap: 1rem;
  padding: 0.25rem;
  align-items: center;
  justify-content: flex-end;
}

@media screen and (max-width: 768px) {
  .explorer-page .ag-paging-panel {
    justify-content: center;
  }
}

/* Title row - truncate long names */
.explorer-title-row {
  min-width: 0;
}

.explorer-title-row h5 {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* Mobile: smaller title, tighter spacing */
@media screen and (max-width: 768px) {
  .explorer-page .mantine-Title-root {
    font-size: 16px !important;
  }
  .explorer-page .mantine-Text-root[data-c="dimmed"] {
    font-size: 11px !important;
  }
  /* Main tabs: smaller on mobile */
  .explorer-page > .mantine-Tabs-root > .mantine-Tabs-list .mantine-Tabs-tab {
    font-size: 12px;
    padding: 6px 10px;
  }
  /* KPI stat cards: tighter layout */
  .explorer-page .mantine-Card-root {
    padding: 10px !important;
    height: auto !important;
  }
  .explorer-page .mantine-Card-root .mantine-Text-root[data-fw="700"] {
    font-size: 16px !important;
  }
  
  /* KPI SimpleGrid should not stretch cards height */
  .explorer-page .mantine-SimpleGrid-root {
    align-items: flex-start !important;
  }
}

/* Responsive badge and reset button */
@media screen and (max-width: 768px) {
  .explorer-title-row .mantine-Badge-root {
    font-size: 10px;
    height: 20px;
    padding: 0 6px;
  }

  .explorer-title-row .mantine-Button-root {
    font-size: 11px;
    padding: 2px 6px;
  }
}

/* ──────────────────────────────────────────────────────
   EXPLORER PAGE - Filter Layout
   ────────────────────────────────────────────────────– */

/* Explorer Filter Row - horizontal scroll on mobile/medium */
.explorer-filter-row {
  width: 100%;
  margin: 0;
  padding: 4px 0;
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex-wrap: nowrap !important;
}
.explorer-filter-row::-webkit-scrollbar {
  display: none;
}
.explorer-filter-row > * {
  flex-shrink: 0 !important;
}

/* Map controls row - horizontal scroll on mobile/medium */
.explorer-map-controls-row {
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex-wrap: nowrap !important;
}
.explorer-map-controls-row::-webkit-scrollbar {
  display: none;
}
.explorer-map-controls-row > * {
  flex-shrink: 0 !important;
}

/* Filter Popover Dropdown - mobile-friendly sizing */
.filter-popover-dropdown {
  max-width: calc(100vw - 24px);
}

@media screen and (max-width: 768px) {
  .filter-popover-dropdown {
    width: calc(100vw - 24px) !important;
    max-height: 70vh;
    overflow-y: auto;
  }

  /* Hide Map Legend on Explorer mobile */
  #explorer-map-legend-container {
    display: none !important;
  }
}

/* ──────────────────────────────────────────────────────
   CLIENT MAP PAGE - Popup & Layout
   ────────────────────────────────────────────────────– */

.client-map-popup-fixed {
  position: fixed !important;
  top: 80px !important;
  left: calc(var(--sidebar-width-collapsed, 42px) + 20px) !important;
  bottom: 20px !important;
  right: auto !important;
  transform: none !important;
  margin: 0 !important;
  width: 400px !important;
  max-width: 400px !important;
  z-index: 1000 !important;
  display: flex;
  flex-direction: column;
}

/* Sidebar visible on expanding: adjust popup position */
@media (min-width: 991px) {
  .client-map-popup-fixed {
    left: calc(var(--sidebar-width-collapsed, 42px) + 20px) !important;
  }
  
  .sidebar-container:hover ~ [class*="client-map"], 
  .sidebar-container.search-pinned ~ [class*="client-map"] {
    /* When sidebar expands, only reposition if needed */
  }
}

.client-map-popup-fixed .leaflet-popup-content-wrapper {
  height: 100%;
  border-radius: var(--radius-xl);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  background: white;
  padding: 0;
}

.client-map-popup-fixed .leaflet-popup-content {
  margin: 0 !important;
  height: 100%;
  overflow-y: auto;
  width: 100% !important;
}

.client-map-popup-fixed .leaflet-popup-tip-container {
  display: none !important;
}

.client-map-popup-fixed a.leaflet-popup-close-button {
  font-size: 24px !important;
  padding: 8px !important;
  color: #333 !important;
  z-index: 1001;
}

/* ──────────────────────────────────────────────────────
   RESPONSIVE ADJUSTMENTS - All Pages
   ────────────────────────────────────────────────────– */

@media (max-width: 768px) {
  /* Reduce grid column padding on mobile */
  .mantine-Grid-col {
    padding: 0.5rem !important;
  }

  /* Compact paper padding (not explorer) */
  .mantine-Paper-root:not(.explorer-page .mantine-Paper-root) {
    padding: 0.75rem !important;
  }

  /* Smaller section gaps (not explorer) */
  :not(.explorer-page) > .mantine-Stack-root {
    gap: 0.5rem !important;
  }
}

/* ──────────────────────────────────────────────────────
   GLOBAL DEFAULT STYLES - Fallback for all elements
   ────────────────────────────────────────────────────– */

/* Ensure containers have proper background colors */
.mantine-Container-root {
  background-color: transparent;
}

/* Default Paper styling if not overridden */
.mantine-Paper-root:not(.page-preview-card):not(.kpi-card) {
  background-color: var(--bg-paper);
  border: 1px solid var(--color-gray-3);
  border-radius: var(--radius-md);
}

/* Ensure Stack has proper spacing */
.mantine-Stack-root {
  gap: inherit;
}

/* Responsive for very large screens */
@media (min-width: 1400px) {
  /* Add extra padding on ultra-wide screens */
  .mantine-Container-root {
    max-width: 1400px !important;
  }
}
