/* ==============================
   SMART Column Leaching Test DB
   Clean, responsive design
   ============================== */

:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #0ea5e9;
  --radius: 12px;
  --shadow: 0 4px 18px rgba(2, 6, 23, 0.06);
}

/* ===== Global Reset ===== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
  padding: 28px 0 0;
}

.container {
  width: 70%;
  margin: 0 auto;
  padding: 0 16px;
}

/* ===== Header ===== */
.header {
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(2, 6, 23, 0.06);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
}

.title {
  font-weight: 600;
  font-size: 1.35rem;
  letter-spacing: 0.3px;
}

/* ===== Navigation ===== */
.nav {
  display: flex;
  gap: 18px;
  font-size: 0.95rem;
}

.nav a {
  text-decoration: none;
  color: var(--text);
  padding: 6px 8px;
  border-radius: 8px;
  transition: background 0.2s;
}

.nav a:hover {
  background: rgba(2, 6, 23, 0.04);
}

/* Hamburger for mobile */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: space-between;
  width: 28px;
  height: 20px;
  background: transparent;
  border: none;
  cursor: pointer;
}

.hamburger span {
  width: 100%;
  height: 3px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.hamburger.is-open span:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}

.hamburger.is-open span:nth-child(2) {
  opacity: 0;
}

.hamburger.is-open span:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

/* Mobile menu */
@media (max-width: 960px) {
  .hamburger {
    display: inline-flex;
  }

  .nav {
    position: absolute;
    right: 12px;
    top: 56px;
    display: none;
    flex-direction: column;
    gap: 8px;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(2, 6, 23, 0.12);
    padding: 12px;
    z-index: 1000;
    min-width: 210px;
  }

  .nav.open {
    display: flex;
  }

  .nav a {
    padding: 10px 12px;
  }
}

/* ===== Footer ===== */
footer {
  background: var(--surface);
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
  padding: 14px 0;
  box-shadow: 0 -1px 0 rgba(2, 6, 23, 0.06);
}

/* ===== Surface Cards ===== */
.surface {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* ===== Icon Grid ===== */
.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

@media (max-width: 1500px) {
  .icon-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.icon-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px 20px;
  cursor: pointer;
  text-align: center;
  transition: transform 0.2s, box-shadow 0.2s;
}

.icon-card i {
  font-size: 2rem;
  color: var(--accent);
  margin-bottom: 10px;
}

.icon-card span {
  font-weight: 500;
  font-size: 1rem;
}

.icon-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 6px 20px rgba(2, 6, 23, 0.12);
}

/* Tooltip */
.icon-card[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 110%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(31, 41, 55, 0.95);
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.85rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 100;
}

.icon-card[data-tooltip]:hover::after {
  opacity: 1;
}

/* ===== Panels ===== */
.inline-panel {
  margin-top: 50px;
  margin-bottom: 100px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 18px 22px;
  display: none;
}

.inline-panel.open {
  display: block;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 30px;
}

.panel-title {
  font-weight: 600;
  font-size: 1.05rem;
}

/* ===== Legends & Charts ===== */
.legend {
  margin-bottom: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.chart-wrap {
  width: 100%;
  height: 360px;
}

.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

/* === Right-align the Quality Threshold List button inside panel-title === */
#materialQualityPanel .panel-title {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;   /* title left, button right */
  width: 100%;
}

/* Adjust the pill look and spacing */
#materialQualityPanel #qualityInfoToggle {
  margin-left: auto;     /* push it to the far right */
  padding: 6px 12px;
  font-size: 0.9rem;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(14, 165, 233, 0.25);
}

/* Optional: make it look pressed when active */
#materialQualityPanel #qualityInfoToggle.active {
  background: #2563eb;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.35);
}
/* ===== Pill Buttons ===== */
.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(14, 165, 233, 0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s;
}

.pill-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(14, 165, 233, 0.32);
}

/* Info Subpanel */
.info-subpanel {
  margin-top: 16px;
  background: #fff;
  border: 1px solid #e6eef7;
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: 0 8px 24px rgba(2, 6, 23, 0.06);
  color: var(--text);
  font-size: 0.95rem;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* Only the open menu should be clickable and on top */
.select-menu { position: relative; z-index: auto; }
.select-menu.open { z-index: 100; }

/* Closed popups should not capture clicks at all */
.select-menu .select-popup {
  display: none;
  pointer-events: none;       /* ⬅ important */
}
.select-menu.open .select-popup {
  display: block;
  pointer-events: auto;       /* ⬅ important */
}

.select-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  min-height: 34px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.select-popup {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  display: none;
  background: #fff;
  min-width: 220px;
  max-height: 260px;
  overflow: auto;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(2, 6, 23, 0.12);
  padding: 8px;
}



.select-popup label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
}

.select-popup label:hover {
  background: #f3f4f6;
}

/* ===== Controls & Toolbar ===== */
.controls-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 6px 8px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
}

.chk {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid #e5e9f2;
  border-radius: 999px;
  background: #f9fbff;
  color: #374151;
  font-size: 13px;
  font-weight: 600;
}

.controls-spacer {
  width: 1px;
  height: 26px;
  background: #e5e7eb;
  margin: 0 4px;
}

/* ===== Leaching Panel Layout ===== */
.leach-row {
  display: flex;
  gap: 12px;
  align-items: stretch;
}

.leach-main {
  flex: 1 1 100%;
}

.leach-side {
  flex: 0 0 30%;
  display: none;
}

.leach-row.with-solid .leach-main {
  flex-basis: 70%;
}

.leach-row.with-solid .leach-side {
  display: block;
}

.placeholder {
  height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  border: 1px dashed #d9e2f1;
  border-radius: 10px;
}

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-card {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  width: min(92vw, 380px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
}

.modal-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
}

.modal-card input {
  width: 100%;
  padding: 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  margin: 8px 0;
}

.btn-primary {
  margin-top: 8px;
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: #0284c7;
}

.modal-msg {
  margin-top: 10px;
  color: #b91c1c;
  font-size: 0.9rem;
}

/* ---- LS range control ---- */
#lsControl{display:flex;align-items:center;gap:8px;margin:6px 0 4px 0;}
#lsControl[hidden]{display:none!important;}
#lsControl input{
  width:90px;padding:6px 8px;border:1px solid #e5e7eb;border-radius:8px;
  background:#fff; outline:none;
}
#lsControl button{
  padding:6px 10px;border:1px solid #e5e7eb;border-radius:8px;background:#f8fafc;cursor:pointer;
}

/* ─────────────────────────────────────────────────────────────
   Data Statistics — Compound Insights (charts-only styling)
   NOTE: Scoped to #compoundInsights so nothing else is affected.
   ───────────────────────────────────────────────────────────── */

/* Data Statistics → Compound Insights layout guards */
#compoundInsights {
  max-width: 100%;
  margin-bottom: 20px;
}
  #compoundInsightsHeader {
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    gap: 10px; 
    margin-bottom: 10px;
  }
  
  #compoundInsightsTitle {
    font-weight: 800; 
    color: #111827; 
    font-size: 1.05rem;
  }
  
  /* picker uses your existing .select-menu styles; only tighten spacing */
  #compoundPickMenu .select-trigger {
    border-radius: 999px;
    padding: 6px 10px;
  }
  
  /* quick facts grid */
  #compoundFacts {
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px; 
    margin-bottom: 10px;
  }
  
  #compoundFacts .kpi {
    background: #fff; 
    border: 1px solid #e8edf5; 
    border-radius: 12px; 
    padding: 10px;
    box-shadow: 0 4px 16px rgba(2,6,23,0.06);
  }
  #compoundFacts .kpi .k { 
    font-size: .78rem; 
    color: #6b7280; 
    font-weight: 600; 
  }
  #compoundFacts .kpi .v { 
    font-size: 1.2rem; 
    font-weight: 800; 
    color: #111827; 
    margin-top: 2px; 
  }
  
  #compoundCharts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 12px;
  }
  
/* Each chart lives in a fixed-height card so it can't bleed out */
#compoundCharts .card {
  display: flex;
  flex-direction: column;
  height: 340px;              /* <- adjust to taste (e.g., 300–380px) */
  border: 1px solid #e8edf5;
  border-radius: 12px;
  background: #fff;
  overflow: hidden;           /* <- critical: prevents spill */
  box-shadow: 0 4px 16px rgba(2,6,23,0.06);
}
  
  #compoundCharts .card h4 { 
    margin: 10px 12px 0 12px;
    font-size: 0.95rem;
    font-weight: 700;
    color: #111827;
    flex: 0 0 auto;
  }
  
  /* the canvas gets the remaining space; height fixes prevent reflow */
  #compoundCharts .card canvas {
    display: block;
    width: 100% !important;
    height: calc(100% - 36px) !important; /* header height (~36px) */
  }
  
  /* small screens: slightly shorter rows to fit */
  @media (max-width: 600px) {
    #compoundCharts {
      grid-auto-rows: 320px;
    }
    #compoundCharts .card {
      height: 320px; 
      min-height: 320px;
    }
    #compoundCharts .card canvas {
      height: 260px !important;
    }
  }
  
  /* If you render custom legends above a chart in this section,
     reserve a bit of space so toggling doesn’t push content down. */
  #compoundCharts .custom-legend,
  #compoundInsights .custom-legend {
    min-height: 28px;
    margin-bottom: 6px;
  }
  .chart-wrap {
    position: relative;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
  }

  @media (max-width: 640px) {
    #compoundCharts .card { height: 300px; }
  }
  
  /* ===== Data Statistics: two-column, compact ===== */
#statsMainWrap{
  display: grid;
  grid-template-columns: 300px 1fr; /* left slim | right charts grid */
  gap: 14px;
  align-items: start;
}

/* Left column (collapsible) */
#statsAside details{
  border: 1px solid #e8edf5;
  border-radius: 10px;
  background: #fff;
  margin: 0 0 10px 0;
  padding: 6px 8px 8px;
}
#statsAside summary{
  cursor: pointer;
  list-style: none;
  outline: none;
  padding: 6px 2px;
  color: #111827;
}
#statsAside summary::-webkit-details-marker { display:none; }
#statsAside summary::after{
  content: "▾";
  float: right;
  color: #6b7280;
  transform: rotate(0deg);
  transition: transform .15s ease;
}
#statsAside details[open] summary::after { transform: rotate(180deg); }

/* KPIs tighter */
#statsKpis{
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important;
  gap: 8px !important;
  margin-top: 6px;
}
#statsKpis .kpi-card{
  padding: 8px !important;
  border-radius: 10px !important;
}
#statsKpis .kpi-card .kpi-title{ font-size:.72rem; color:#6b7280; font-weight:600; margin:0; }
#statsKpis .kpi-card .kpi-value{ font-size:1.08rem; font-weight:800; color:#111827; margin:2px 0 0; }
#statsKpis .kpi-card .kpi-subtitle{ font-size:.72rem; color:#6b7280; margin-top:2px; }

/* Compound header + facts */
#compoundInsightsHeader{
  display:flex; align-items:center; justify-content:space-between;
  gap:8px; padding:6px; border:1px solid #e8edf5; border-radius:10px; background:#fff; margin-top:6px;
}
#compoundInsightsTitle{ font-weight:700; font-size:.92rem; color:#111827; }
#compoundFacts{
  display:grid; gap:6px; margin-top:8px;
}
#compoundFacts .kpi{
  display:grid; grid-template-columns:auto 1fr; gap:6px;
  padding:8px; border:1px solid #e8edf5; border-radius:10px; background:#fff;
}
#compoundFacts .k{ font-size:.74rem; color:#6b7280; font-weight:600; }
#compoundFacts .v{ font-size:.96rem; color:#111827; font-weight:700; }

/* Right 2×2 grid */
#statsChartsGrid{
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: 280px; /* visible without scrolling */
  gap: 14px;
}
.stats-card{
  display:flex; flex-direction:column; min-height:0;
  border:1px solid #e8edf5; border-radius:12px; background:#fff;
  box-shadow:0 4px 16px rgba(2,6,23,0.06); overflow:hidden;
}
.stats-card h4{ margin:8px 10px; font-size:.9rem; font-weight:700; color:#111827; }
.stats-card .canvas-wrap{ flex:1; min-height:0; padding:6px 8px 10px; }
.stats-card canvas{ width:100% !important; height:100% !important; display:block; }

/* Tighter select trigger inside the aside */
#statsAside .select-menu .select-trigger{
  padding: 6px 10px; border-radius: 999px; border:1px solid #e5e7eb; background:#f8fafc;
}

/* Hide legacy dynamic charts container (we render to fixed canvases) */
#compoundCharts{ display:none !important; }

/* Panel spacing */
#dataStatsPanel.open{ padding-bottom: 6px; }

/* Responsive */
@media (max-width: 1100px){
  #statsMainWrap{ grid-template-columns: 1fr; }
  #statsChartsGrid{ grid-template-columns: 1fr; grid-auto-rows: 260px; }
}

/* ── Data Stats: compact, pro, scrollable ───────────────────────────── */
.ds-panel { position: relative; padding-top: 8px; padding-bottom: 8px; }

/* sticky header with tiny tool buttons */
.ds-header {
  position: sticky; top: 0; z-index: 3;
  background: var(--surface);
  border-bottom: 1px solid #eef2f7;
  padding: 8px 4px;
  margin-bottom: 8px;
  display: flex; align-items: center; justify-content: space-between;
}
.ds-tools { display: inline-flex; align-items: center; gap: 6px; }
.ds-btn {
  width: 28px; height: 28px; border-radius: 8px;
  border: 1px solid #e5e7eb; background: #fff; cursor: pointer;
  font: inherit; font-size: 13px; line-height: 1;
}
.ds-btn:hover { background: #f9fafb; }
.ds-sep { width: 1px; height: 18px; background: #e5e7eb; }

/* internal scroll area (panel stays compact on the page) */
.ds-body {
  max-height: calc(100vh - 180px);
  overflow: auto;
  padding: 6px 0 2px;
}
/* nice thin scrollbar only inside the body */
.ds-body::-webkit-scrollbar { width: 10px; }
.ds-body::-webkit-scrollbar-track { background: #f5f7fb; border-radius: 10px; }
.ds-body::-webkit-scrollbar-thumb {
  background: #cfd8e6; border-radius: 10px; border: 2px solid #f5f7fb;
}
.ds-body { scrollbar-width: thin; scrollbar-color: #cfd8e6 #f5f7fb; }

/* grid layout of the panel content */
.ds-grid {
  display: grid;
  grid-template-columns: 300px 1fr; /* slim aside | charts */
  gap: 14px;
  align-items: start;
}

/* tighten the aside details blocks */
.ds-aside details {
  border: 1px solid #e8edf5; border-radius: 10px;
  background: #fff; margin: 0 0 10px 0; padding: 6px 8px 8px;
}
.ds-aside summary {
  cursor: pointer; list-style: none; outline: none;
  padding: 6px 2px; color: #111827;
}
.ds-aside summary::-webkit-details-marker { display: none; }
.ds-aside summary::after {
  content: "▾"; float: right; color: #6b7280;
  transform: rotate(0deg); transition: transform .15s ease;
}
.ds-aside details[open] summary::after { transform: rotate(180deg); }

/* charts grid: dense 2×2; fixed card heights prevent overflow */
.ds-charts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: 260px;
  gap: 14px;
}
.stats-card {
  display: flex; flex-direction: column; min-height: 0;
  border: 1px solid #e8edf5; border-radius: 12px; background: #fff;
  box-shadow: 0 4px 16px rgba(2,6,23,0.06); overflow: hidden;
}
.stats-card h4 { margin: 8px 10px; font-size: .9rem; font-weight: 700; color: #111827; }
.stats-card .canvas-wrap { flex: 1; min-height: 0; padding: 6px 8px 10px; }
.stats-card canvas { width: 100% !important; height: 100% !important; display: block; }

/* fullscreen mode (keeps everything inside one overlay) */
#dataStatsPanel.ds-fullscreen {
  position: fixed; inset: 12px; z-index: 3000;
  margin: 0 !important; width: auto; max-width: none;
  box-shadow: 0 12px 40px rgba(2,6,23,0.18);
}
#dataStatsPanel.ds-fullscreen .ds-body { max-height: none; height: calc(100vh - 100px); }
#dataStatsPanel.ds-fullscreen::before {
  content: ""; position: fixed; inset: 0; z-index: -1;
  background: rgba(15,23,42,0.35);
}

/* responsive: stack on narrow screens */
@media (max-width: 1100px){
  .ds-grid { grid-template-columns: 1fr; }
  .ds-charts { grid-template-columns: 1fr; grid-auto-rows: 240px; }
  .ds-body { max-height: calc(100vh - 140px); }
}

/* ---- Fix Data Overview chart clipping ---- */
.inline-panel {                /* the white card */
  overflow: visible;           /* was likely hidden via a generic card rule */
}

.inline-panel .chart-wrap {    /* the chart container inside the card */
  position: relative;
  height: 360px;               /* single source of height */
  padding: 12px 14px 16px 16px;/* space for tick labels so the border radius doesn't crop */
  overflow: visible;           /* critical: do not crop canvas edges */
}

.inline-panel .chart-wrap canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;     /* fill the wrapper height */
  box-sizing: border-box;
}

/* ── Data Statistics: Map by district ───────────────────────────── */
.ds-map {
  border: 1px solid #e8edf5;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 4px 16px rgba(2,6,23,0.06);
  margin-bottom: 10px;
  padding: 8px;
}

.leaflet-container, /* keep Leaflet happy on size */
#dsMap {
  width: 100%;
  height: 380px;         /* adjust as you like */
  border-radius: 10px;
  overflow: hidden;
}

.map-legend {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 6px 8px;
  border: 1px solid #e8edf5;
  border-radius: 8px;
  background: #f8fafc;
  font-size: 12px;
  color: #374151;
}
.map-legend .swatch {
  width: 16px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.08);
}