/* ============================================
   IRRA Olivar - WebGIS Olea europaea
   Paleta: verdes olivo, tierra, naranja solar
   ============================================ */
:root {
  --olive-900: #1b2a1a;
  --olive-800: #2e4a2b;
  --olive-700: #3a5a35;
  --olive-600: #556b2f;
  --olive-500: #6b8e23;
  --olive-400: #8da65d;
  --olive-100: #eef3e6;
  --earth-800: #4e342e;
  --earth-600: #6d4c41;
  --earth-100: #efebe9;
  --solar-500: #ff6f00;
  --solar-400: #ff8f00;
  --solar-300: #ffa726;
  --solar-100: #fff3e0;
  --bg: #f6f7f4;
  --card: #ffffff;
  --border: #e0e6db;
  --text: #1e2a1e;
  --muted: #6b7c6b;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(27,42,26,.12);
  --topbar-h: 58px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* Topbar */
.topbar {
  height: var(--topbar-h);
  background: linear-gradient(135deg, var(--olive-900) 0%, var(--olive-700) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  box-shadow: 0 2px 12px rgba(0,0,0,.2);
  z-index: 1000;
  position: relative;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 28px; color: var(--solar-300); }
.brand h1 { font-size: 18px; font-weight: 800; letter-spacing: .5px; }
.brand h1 span { color: var(--solar-300); font-weight: 600; }
.brand p { font-size: 11px; opacity: .85; letter-spacing: .3px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.brand-agrotecnica {
  font-family: 'Inter', sans-serif;
  font-weight: 800; font-size: 16px; letter-spacing: -0.3px;
  color: #fff; text-decoration: none;
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid rgba(255,255,255,.22);
  background: rgba(255,255,255,.10);
  backdrop-filter: blur(6px);
  display: inline-flex; align-items: center; gap: 0;
  margin-left: 4px;
}
.brand-agrotecnica .dot-ar { color: var(--solar-300); }
.brand-agrotecnica:hover { background: rgba(255,255,255,.16); border-color: rgba(255,255,255,.30); }
.coords-badge {
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.18);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  display: flex; align-items: center; gap: 6px;
  backdrop-filter: blur(6px);
}
.btn-primary, .btn-secondary, .btn-icon {
  border: none; cursor: pointer; border-radius: 10px; font-family: inherit;
}
.btn-primary {
  background: var(--solar-500); color: #fff;
  padding: 8px 14px; font-weight: 600; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px;
  box-shadow: 0 4px 14px rgba(255,111,0,.35);
}
.btn-primary:hover { background: var(--solar-400); }
.btn-secondary {
  background: #fff; border: 1px solid var(--border);
  padding: 8px 12px; font-size: 13px; border-radius: 8px;
}
.btn-icon {
  width: 38px; height: 38px;
  background: rgba(255,255,255,.12);
  color: #fff; display: grid; place-items: center;
  border: 1px solid rgba(255,255,255,.15);
}
.btn-icon.small { width: 32px; height: 32px; font-size: 13px; background: #fff; color: var(--olive-800); border: 1px solid var(--border); }
.btn-icon:hover { background: rgba(255,255,255,.2); }

/* Export PDF */
.btn-export {
  width: 100%; margin-top: 12px;
  background: linear-gradient(135deg, var(--olive-800), var(--olive-600));
  color: #fff; border: none; border-radius: 10px;
  padding: 10px 14px; font-weight: 700; font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer; box-shadow: 0 4px 14px rgba(27,42,26,.22);
}
.btn-export:hover { filter: brightness(1.08); }
.btn-export:disabled, .btn-primary:disabled { opacity: .55; cursor: not-allowed; }
#btnExportPDFTop { background: #fff; color: var(--olive-800); border: 1px solid var(--border); box-shadow: none; }
#btnExportPDFTop:hover { background: var(--olive-100); }

/* Layout */
.layout { display: flex; height: calc(100vh - var(--topbar-h)); height: calc(100dvh - var(--topbar-h)); }
.sidebar {
  width: 380px;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: transform .28s ease, width .28s ease, margin .28s ease;
  flex-shrink: 0;
}
.sidebar:not(.open) { width: 0; transform: translateX(-100%); border: none; }
.sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--olive-100);
}
.sidebar-header h2 { font-size: 14px; font-weight: 700; color: var(--olive-800); }
.sidebar-header h2 i { color: var(--olive-600); margin-right: 6px; }
.sidebar-content {
  overflow-y: auto;
  flex: 1;
  padding: 12px;
  display: flex; flex-direction: column; gap: 14px;
}
.panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.panel h3 { font-size: 13px; font-weight: 700; color: var(--olive-800); margin-bottom: 10px; text-transform: uppercase; letter-spacing: .4px; }
.panel h3 i { color: var(--solar-500); margin-right: 6px; }
.sub-title { font-size: 12px; font-weight: 600; color: var(--muted); margin: 12px 0 8px; }
.hint { font-size: 11px; color: var(--muted); margin-top: 8px; font-style: italic; }

/* Layer controls */
.layer-list { display: flex; flex-direction: column; gap: 6px; }
.radio-card {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px;
  cursor: pointer; font-size: 13px; background: #fafaf8;
}
.radio-card:has(input:checked) { border-color: var(--olive-500); background: var(--olive-100); }
.radio-card input { accent-color: var(--olive-600); }

/* Toggle */
.toggle {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; cursor: pointer; padding: 6px 0;
}
.toggle input { display: none; }
.toggle-slider {
  width: 42px; height: 24px; background: #d6ddd2; border-radius: 999px;
  position: relative; transition: .2s; flex-shrink: 0;
}
.toggle-slider::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; background: #fff; border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0,0,0,.15); transition: .2s;
}
.toggle input:checked + .toggle-slider { background: var(--olive-600); }
.toggle input:checked + .toggle-slider::after { transform: translateX(18px); }

/* Dashboard */
.empty-state {
  text-align: center; padding: 18px 10px; color: var(--muted);
  border: 1px dashed var(--border); border-radius: 10px; background: #fbfcfa;
}
.empty-state i { font-size: 28px; color: var(--olive-400); margin-bottom: 8px; display: block; }
.empty-state p { font-size: 13px; }
.hidden { display: none !important; }

.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.metric {
  background: linear-gradient(135deg, #fff 0%, var(--olive-100) 100%);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 10px; text-align: center;
}
.metric-label { font-size: 10px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; display: block; margin-bottom: 4px; }
.metric-label i { color: var(--solar-500); }
.metric strong { font-size: 20px; color: var(--olive-800); display: block; }
.metric small { font-size: 11px; color: var(--muted); }

.aptitude-badge {
  padding: 10px 12px; border-radius: 10px; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 8px; margin-bottom: 12px;
}
.aptitude-badge.optimo { background: #e8f5e9; color: #2e7d32; border: 1px solid #a5d6a7; }
.aptitude-badge.medio { background: #fff8e1; color: #f57f17; border: 1px solid #ffe082; }
.aptitude-badge.bajo { background: #fce4ec; color: #c62828; border: 1px solid #ef9a9a; }

.chart-wrap { margin: 12px 0; }
.chart-wrap h4 { font-size: 12px; color: var(--olive-700); margin-bottom: 6px; }
.chart-wrap canvas { max-height: 180px; }



/* Species selector */
.species-select {
  width: 100%; padding: 9px 10px; border: 1px solid var(--border); border-radius: 10px;
  background: #fff; font-family: inherit; font-size: 13px; font-weight: 600; color: var(--olive-800);
  margin-top: 6px;
}
.species-info { margin-top: 10px; padding: 10px; background: var(--olive-100); border: 1px solid var(--border); border-radius: 10px; }
.species-info strong { color: var(--olive-800); }
.species-thresholds { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.species-thresholds .thr { font-size: 11px; padding: 4px 7px; border-radius: 999px; border: 1px solid var(--border); background: #fff; }
.thr-opt { border-color: #a5d6a7; color: #2e7d32; font-weight: 700; }
.thr-mid { border-color: #ffe082; color: #8d6e00; }
.thr-low { border-color: #ef9a9a; color: #c62828; }

/* Legend */
.legend h4 { font-size: 11px; font-weight: 700; color: var(--olive-700); margin: 10px 0 6px; text-transform: uppercase; }
.legend-scale { display: flex; align-items: center; gap: 8px; font-size: 12px; margin: 4px 0; }
.legend-scale span { width: 18px; height: 18px; border-radius: 4px; border: 1px solid rgba(0,0,0,.1); flex-shrink: 0; }
.legend-scale label { color: var(--text); }

.references-panel small { font-weight: 400; font-size: 11px; color: var(--muted); letter-spacing: 0; }
.ref-intro { font-size: 11px; color: var(--muted); margin-bottom: 10px; }
.references-list { padding-left: 18px; display: flex; flex-direction: column; gap: 8px; }
.references-list li {
  font-size: 11.5px; line-height: 1.45; color: var(--text);
  padding-left: 6px; text-indent: -6px;
  word-break: break-word;
}
.references-list li em { font-style: italic; }
.references-list li a { color: var(--olive-700); word-break: break-all; text-decoration: underline; text-underline-offset: 2px; }
.references-list li::marker { color: var(--olive-600); font-weight: 700; }
.ref-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.ref-actions .btn-secondary { font-size: 11px; padding: 6px 10px; }

.sidebar-footer { font-size: 11px; color: var(--muted); text-align: center; padding: 10px; border-top: 1px solid var(--border); }
.sidebar-footer a { color: var(--olive-600); font-weight: 600; }

/* Map */
.map-wrap { flex: 1; position: relative; background: #dfe8d5; min-width: 0; min-height: 0; overflow: hidden; }
#map { width: 100%; height: 100%; z-index: 1; display: block; }
.leaflet-container { width: 100%; height: 100%; }

.map-loader {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  background: #fff; padding: 10px 16px; border-radius: 999px;
  box-shadow: var(--shadow); z-index: 500;
  display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; color: var(--olive-800);
  border: 1px solid var(--border);
}
.map-hint {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: rgba(27,42,26,.88); color: #fff; padding: 8px 14px; border-radius: 999px;
  font-size: 12px; z-index: 400; backdrop-filter: blur(6px);
  pointer-events: none;
}
.spinner {
  width: 22px; height: 22px; border: 3px solid var(--olive-100); border-top-color: var(--solar-500);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Leaflet popup custom */
.leaflet-popup-content-wrapper { border-radius: 14px; padding: 0; overflow: hidden; }
.leaflet-popup-content { margin: 0; width: 340px !important; }
.popup-card { font-family: 'Inter', sans-serif; }
.popup-header {
  background: linear-gradient(135deg, var(--olive-800), var(--olive-600));
  color: #fff; padding: 12px 14px; display: flex; align-items: center; gap: 10px;
}
.popup-header i { font-size: 20px; color: var(--solar-300); }
.popup-header h4 { font-size: 14px; font-weight: 700; }
.popup-header small { font-size: 11px; opacity: .85; }
.popup-body { padding: 12px 14px; }
.popup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.popup-metric { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 8px; text-align: center; }
.popup-metric b { display: block; font-size: 16px; color: var(--olive-800); }
.popup-metric span { font-size: 10px; color: var(--muted); text-transform: uppercase; font-weight: 600; }
.popup-chart { height: 160px; }
.popup-footer { padding: 8px 14px; background: var(--olive-100); font-size: 11px; color: var(--muted); text-align: center; }

/* Marker animation */
.leaflet-marker-icon.marker-anim {
  animation: drop .5s cubic-bezier(.34,1.56,.64,1);
}
@keyframes drop {
  0% { transform: translateY(-40px) scale(.5); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

/* Responsive */
@media (max-width: 900px) {
  body { overflow: auto; }
  .layout { flex-direction: column; height: auto; }
  .sidebar {
    width: 100%;
    position: fixed; top: var(--topbar-h); left: 0; right: 0; bottom: 0;
    z-index: 900; transform: translateY(100%); width: 100%;
    border-right: none; border-top: 1px solid var(--border);
  }
  .sidebar.open { transform: translateY(0); }
  .sidebar:not(.open) { width: 100%; transform: translateY(100%); }
  .map-wrap { height: 62vh; min-height: 420px; }
  .topbar { padding: 0 10px; }
  .brand p { display: none; }
  .coords-badge { display: none; }
  .brand-agrotecnica { font-size: 13px; padding: 5px 9px; }
}
@media (max-width: 480px) {
  #btnExportPDFTop, #btnLocate { padding: 6px 9px; font-size: 12px; }
  .brand-agrotecnica { display: none; }
}
