/* ==================================================
   GEOVISOR - FLOATING CARDS THEME (UNIFIED)
   - Institutional Topbar (GAD-style)
   - Floating Glassmorphism Cards
   - Preloader included
   ================================================== */

/* --------------------------------------------------
   0. GLOBAL VARIABLES
-------------------------------------------------- */
:root {
  --font-main: 'Montserrat', 'Inter', system-ui, -apple-system, sans-serif;

  /* Surfaces */
  --color-bg: #F3F4F6;        /* Canvas / Main background */
  --color-bg-alt: #FFFFFF;    /* Panels */
  --color-surface: #FFFFFF;   /* Cards */
  
  /* Text */
  --color-text-topbar: #FFFFFF;
  --color-text: #111827;
  --color-text-muted: #6B7280;

  /* Borders / shadows */
  --color-border: rgba(17,24,39,0.12);
  --color-border-soft: rgba(17,24,39,0.08);

  /* Brand & Actions */
  --color-brand: #ffffff;     
  --color-primary: #2C7BE5;   
  --color-primary-hover: #1A68D1;
  --color-secondary: #4B5563; 
  --color-secondary-hover: #374151;
  --color-accent: #FCEE21;
}

/* --------------------------------------------------
   1. RESET & BASE
-------------------------------------------------- */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-main);
  background: var(--color-bg);
  color: var(--color-text);
  overflow: hidden; 
}

h1, h2, h3, h4, p, span, label, button { font-family: var(--font-main); }
h1 { font-size: 1.2rem; font-weight: 700; margin: 0; }
h3 { font-size: 0.95rem; font-weight: 700; margin: 0; }
h4 { font-size: 0.85rem; font-weight: 700; margin: 0; }
p, span, label { font-size: 0.85rem; }
label { font-weight: 600; color: var(--color-text-muted); }
button { font-weight: 600; font-size: 0.85rem; }

.hidden { display: none !important; }

/* --------------------------------------------------
   2. PRELOADER
-------------------------------------------------- */
#page-loader {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background-color: var(--color-bg); 
  z-index: 9999;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  transition: opacity 0.5s ease, visibility 0.5s;
}

.spinner {
  width: 50px; height: 50px;
  border: 5px solid var(--color-border-soft);
  border-top: 5px solid var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 15px;
}
@keyframes spin { 100% { transform: rotate(360deg); } }
.loader-hidden { opacity: 0; visibility: hidden; }

/* --------------------------------------------------
   3. TOPBAR 
-------------------------------------------------- */
#topbar {
  height: 125px;
  background: linear-gradient(to bottom, #2C7BE5  0%, #1A68D1 100%);
  color: var(--color-text-topbar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid rgba(17,24,39,0.10);
  box-shadow: 0 8px 20px rgba(17,24,39,0.10);
  position: relative;
  overflow: hidden;
}

#topbar::after {
  content: ""; position: absolute; top: 0; right: 0;
  width: 560px; height: 100%;
  background-image: url("/static/img/topbar-pattern.png");
  background-repeat: no-repeat; background-position: right center; background-size: contain;
  opacity: 0.28; pointer-events: none; filter: saturate(0.9);
}

#topbar .topbar-left { display: flex; align-items: center; gap: 12px; }
#topbar #topbar-logo { height: 80px; width: auto; }
#topbar .topbar-titles h1 { font-size: 1.1rem; letter-spacing: 0.3px; }
#topbar .topbar-titles span { display: block; font-size: 0.85rem; opacity: 0.85; margin-top: 2px; }
#topbar .topbar-right a { color: var(--color-text-topbar); text-decoration: none; margin-left: 18px; font-weight: 600; font-size: 0.9rem; opacity: 0.92; }
#topbar .topbar-right a:hover { opacity: 1; text-decoration: underline; }

#header-box { display: none; }

/* --------------------------------------------------
   4. LAYOUT (SIDE-BY-SIDE CARDS)
-------------------------------------------------- */
.grid-container {
  display: grid;
  /* 1. Map Column | 2. Divider | 3. Sidebar Column */
  grid-template-columns: minmax(0, 1fr) 8px 380px; 
  grid-template-rows: calc(100vh - 125px - 44px); /* Accounts for Topbar */
  width: 100vw;
  height: calc(100vh - 125px - 44px);
  position: relative;
  background: var(--color-bg); /* The neutral canvas color between panels */
}

/* 1. Map Area */
.grid-1 {
  height: 100%;
  width: 100%;
  padding: 14px 0 14px 14px; /* Creates the gap around the map */
}

#map {
  height: 100%;
  width: 100%;
  margin: 0; 
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 14px 30px rgba(17,24,39,0.12), 0 2px 8px rgba(17,24,39,0.08);
  z-index: 1;
}

/* 2. Draggable Divider */
#divider {
  display: block; /* Unhide the divider! */
  cursor: ew-resize;
  background: transparent; /* Keep it invisible until hovered */
  width: 8px;
  position: relative;
  z-index: 10; /* Keep it on top so it's easy to grab */
  transition: background-color 0.2s;
}

#divider:hover {
  background: rgba(17,24,39,0.06); /* Subtle hover effect */
}

/* 3. Sidebar Wrapper */
.grid-2 {
  position: relative; /* Not absolute anymore! Back in the grid. */
  height: 100%;
  width: 100%;
  padding: 14px 14px 14px 6px; /* Spacing around the cards */
  overflow-y: auto; /* Lets you scroll the cards if the screen is short */
  pointer-events: auto; /* Normal clicking */
  z-index: 2;
}

/* Scrollbar for the sidebar column */
.grid-2::-webkit-scrollbar { width: 6px; }
.grid-2::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.10); border-radius: 999px; }
.grid-2::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.20); }

.column-menu {
  background: transparent;
  border: none;
  box-shadow: none;
  height: auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 0;
}

/* --------------------------------------------------
   5. FLOATING CARDS (Sections)
-------------------------------------------------- */
/* ... but clicks are caught by the cards themselves */
#layers-section,
#legend-section,
#tools-box,
#info-box {
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(17,24,39,0.10);
  border-radius: 16px;
  box-shadow: 0 7px 7px rgba(17,24,39,0.12), 0 2px 8px rgba(17,24,39,0.08);
  padding: 14px;
  pointer-events: auto; /* Re-enable clicks on cards */
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  margin: 0; /* Reset margin, gap handles spacing now */
}

/* --------------------------------------------------
   6. HEADERS & TOGGLES
-------------------------------------------------- */
#layers-header, #legend-header {
  display: flex;
  justify-content: space-between;
  align-items: center; 
  
  /* 1. Equal padding on all sides so the text sits perfectly in the middle */
  padding: 8px 12px; 
  
  /* 2. Push the checkboxes below down slightly */
  /* margin-bottom: 8px;  */
  
  /* 3. Give the grey background rounded corners so it matches the buttons */
  border-radius: 10px; 
  
  cursor: pointer;
  
  /* Put your grey background color here if you want to keep it! */
  background: rgba(17, 24, 39, 0.05); 
}

#layers-header h3, #legend-header h3 {
  font-size: 1rem;
  font-weight: 800;
  color: #111827;
  margin: 0; /* Keep this 0 so the browser doesn't add secret margins */
  line-height: 1; 
}

#layers-toggle, #legend-toggle {
  background: #F3F4F6;
  color: #111827;
  border: 1px solid rgba(17,24,39,0.12);
  width: 32px;
  height: 32px;
  border-radius: 10px;
  font-size: 1rem;
  transition: background-color 0.2s;
  cursor: pointer;
}

#layers-toggle:hover, #legend-toggle:hover {
  background: #E5E7EB;
}

/* --------------------------------------------------
   7. LEAFLET LAYERS PANEL
-------------------------------------------------- */
#leaflet-layers-panel {
  max-height: 220px;
  overflow-y: auto;
  padding: 6px 2px 2px 2px;
}
#leaflet-layers-panel::-webkit-scrollbar { width: 6px; }
#leaflet-layers-panel::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 999px; }

.polygon-label {
  background: transparent; border: none; box-shadow: none;
  color: #000; font-size: 0.75rem; font-weight: 700; text-shadow: 1px 1px 2px #ffffff;
}

/* --------------------------------------------------
   7. LEGEND PANEL
-------------------------------------------------- */
.legend{
  background:#fff;
  border-radius:14px;
  padding:12px;
  box-shadow:0 10px 25px rgba(0,0,0,.15);
  font-family:Montserrat, system-ui, sans-serif;
  width: 260px;
}

.legend-header{ font-weight:700; margin-bottom:10px; }

.legend-item{
  display:flex; align-items:center; gap:10px;
  padding:6px 0;
}

.legend-swatch{
  width:28px; height:18px; border-radius:6px;
  flex: 0 0 auto;
  display:inline-flex; align-items:center; justify-content:center;
  overflow:hidden;
}

.legend-label{ font-size:13px; line-height:1.2; color:#222; }

/* --------------------------------------------------
   8. TOOLS & SEARCH
-------------------------------------------------- */
#identify-btn, #clean-btn {
  width: 100%;
  border: 1px solid transparent;
  color: #FFFFFF;
  cursor: pointer;
  transition: transform 0.05s, background-color 0.15s, box-shadow 0.15s;
}

#identify-btn { 
  background: var(--color-primary); 
  border-radius: 12px; 
  padding: 12px; 
  font-size: 0.95rem; 
  box-shadow: 0 5px 9px rgba(44,123,229,0.26); 
}
#identify-btn:hover { background: var(--color-primary-hover); }

#clean-btn { 
  margin-top: 10px; 
  background: var(--color-secondary); 
  border-radius: 12px; 
  padding: 11px 12px; 
  font-size: 0.9rem; 
}
#clean-btn:hover { background: var(--color-secondary-hover); }

#search-container {
  margin-top: 12px;
  background: #F9FAFB;
  border: 1px solid rgba(17,24,39,0.10);
  border-radius: 12px;
  padding: 10px;
}

#search-input {
  width: 100%;
  border: 1px solid rgba(17,24,39,0.12);
  border-radius: 10px;
  padding: 10px;
  font-size: 0.95rem;
  background: #FFFFFF;
  color: var(--color-text);
  outline: none;
}
#search-input:focus { border-color: rgba(44,123,229,0.65); box-shadow: 0 0 0 3px rgba(44,123,229,0.18); }

#results-list { list-style: none; padding: 0; margin: 10px 0 0 0; max-height: 170px; overflow-y: auto; }
#results-list li { padding: 10px; cursor: pointer; font-size: 0.95rem; border-radius: 8px; }
#results-list li:hover { background: rgba(44,123,229,0.10); }

/* --------------------------------------------------
   9. INFO PANEL
-------------------------------------------------- */
#info-box h3 { font-size: 1rem; font-weight: 900; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--color-border-soft); }

.info-section {
  background: var(--color-surface);
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(17,24,39,0.10);
  margin-bottom: 10px;
}
.info-section.warning {
  border-left: 4px solid #F59E0B;
  background: #FFFBEB;
}

.info-section h4 { padding-bottom: 8px; border-bottom: 1px solid var(--color-border-soft); margin-bottom: 8px; margin-top: 0; }
.info-content-section { display: grid; grid-template-columns: 145px 1fr; gap: 8px 10px; font-size: 0.92rem; }
.info-label { color: var(--color-text-muted); font-weight: 700; white-space: wrap; }
.info-value { color: var(--color-text); font-weight: 500; border-bottom: 1px dashed rgba(0,0,0,0.06); padding-bottom: 6px; word-break: break-word; }

.info-section.collapsed .info-content-section { display: none; }
.info-title { cursor: pointer; }
.info-title::after { content: "▾"; color: var(--color-text-muted); float: right; transition: transform 0.2s; }
.info-section.collapsed .info-title::after { transform: rotate(-90deg); }

#identify-loading { color: var(--color-primary); font-size: 0.92rem; align-items: center; gap: 6px; padding: 4px 2px; }

/* --------------------------------------------------
   10. MAP STATUS BAR (Floating Chip)
-------------------------------------------------- */
#map-status {
  background: rgba(255,255,255,0.80);
  border: 1px solid rgba(17,24,39,0.10);
  border-radius: 14px;
  box-shadow: 0 10px 20px rgba(17,24,39,0.10);
  pointer-events: auto;
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.popup-table {
  border-collapse: collapse;
  font-size: 0.8rem;
  width: 100%;
}

.popup-table th {
  text-align: left;
  padding-right: 6px;
  font-weight: bold;
  color: var(--color-text);
  white-space: nowrap;
  
}

.popup-table td {
  color: var(--color-text-muted);
  padding-left: 4px;

  /* ✅ correct wrapping */
  white-space: normal;
  word-break: break-word;
}

/* --------------------------------------------------
   11. LEAFLET CONTROLS 
-------------------------------------------------- */
.leaflet-bar {
  border-radius: 12px !important;
  overflow: hidden;
  border: 1px solid rgba(17,24,39,0.12) !important;
  box-shadow: 0 14px 24px rgba(17,24,39,0.14) !important;
}

.leaflet-control-zoom a, .leaflet-bar a {
  background: rgba(255,255,255,0.92) !important;
  color: #111827 !important;
  border-bottom: 1px solid var(--color-border-soft) !important;
}

.leaflet-control-attribution {
  background: rgba(255,255,255,0.85) !important;
  border-radius: 10px;
  padding: 2px 8px;
  border: 1px solid var(--color-border-soft);
}

.leaflet-top.leaflet-left { top: 14px !important; left: 14px !important; }

.leaflet-popup-content {
  width: auto !important;
  min-width: 250px; 
  max-width: 320px;
}

.leaflet-popup-content-wrapper {
  border-radius: 12px;
  border: 1px solid rgba(17,24,39,0.12);
  box-shadow: 0 14px 30px rgba(17,24,39,0.12);
}

/* =========================================================
   APP FOOTER 
   ========================================================= */

#app-footer{
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;

  background: rgba(255,255,255,0.86);
  border-top: 1px solid rgba(17,24,39,0.10);
  box-shadow: 0 -10px 24px rgba(17,24,39,0.08);

  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);

  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 999;
}

#app-footer .footer-left,
#app-footer .footer-right{
  display: flex;
  align-items: center;
  gap: 10px;
  color: #4B5563;
  font-size: 0.85rem;
  font-weight: 600;
}

#app-footer .footer-right{
  font-weight: 500;
  color: #6B7280;
}

#app-footer .footer-dot{
  color: #6B7280;
  font-size: 0.65rem;
}

/* --------------------------------------------------
   12. RESPONSIVE BEHAVIOR
-------------------------------------------------- */
@media (max-width: 1100px) {
  .grid-container {
    grid-template-columns: 1fr;
    /* Row 1: Map (50% of screen) | Row 2: Cards (Takes the rest) */
    grid-template-rows: 30vh 1fr; 
    height: calc(100vh - 125px - 44px); /* Keep strict app height */
    overflow: hidden; /* Prevent the whole page from bouncing/scrolling */
  }

  /* 1. Map moves to the top */
  .grid-1 {
    order: 1;
    padding: 14px; /* Even spacing all around */
    height: 100%;
    width: 100%;
  }

  /* 2. Hide the draggable divider on touch screens */
  #divider { 
    display: none !important; 
  }

  /* 3. Cards move to the bottom and become scrollable */
  .grid-2 {
    order: 2;
    padding: 0 14px 14px 14px;
    height: 100%;
    width: 100%;
    overflow-y: auto; /* Let the user scroll through the cards */
  }
}

@media (max-width: 820px) {
  /* Shrink the topbar slightly on very small phones */
  #topbar { padding: 0 12px; height: 100px; }

  #app-footer{
    height: auto;
    padding: 10px 12px;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  
  .grid-container { 
    height: calc(100vh - 100px - 66px); 
    grid-template-rows: 35vh 1fr; /* Give the map 45% of the screen */
  }
  
  /* Simplify the header for mobile */
  #topbar .topbar-right { display: none; }
  #topbar #topbar-logo { height: 60px; }
  #topbar .topbar-titles h1 { font-size: 1rem; }
  #topbar .topbar-titles span { font-size: 0.8rem; }
}