/* ============ AgroDesign 3D Navigator ============ */
:root {
  --ad-green-dark: #0c2a10;
  --ad-green: #123a1a;
  --ad-green-mid: #1d5a2a;
  --ad-green-bright: #3fae4e;
  --ad-gold: #e6b93d;
  --ad-cream: #f4f1e6;
  --panel-bg: rgba(10, 32, 14, 0.92);
  --topbar-h: 56px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; background: var(--ad-green-dark); }

#map { position: absolute; inset: var(--topbar-h) 0 0 0; }

/* ---------- Splash ---------- */
#splash {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 1.2s ease, visibility 1.2s;
}
#splash.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-bg {
  position: absolute; inset: 0;
  background: url("../img/portada.jpg") center/cover no-repeat;
}
.splash-bg::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(160deg, rgba(8,28,11,.88) 0%, rgba(8,28,11,.55) 45%, rgba(8,28,11,.82) 100%);
}
.splash-content {
  position: relative; text-align: center; color: var(--ad-cream);
  padding: 24px; max-width: 720px;
}
.splash-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 28px; flex-wrap: wrap; }
.brand-logo { height: 34px; width: auto; filter: drop-shadow(0 2px 6px rgba(0,0,0,.4)); }
.splash-brand .brand-logo { height: 46px; }
.brand-name { font-size: 26px; font-weight: 700; letter-spacing: .5px; }
.splash-brand .brand-sub { font-size: 13px; opacity: .75; letter-spacing: 1px; text-transform: uppercase; }
#splash h1 {
  font-size: clamp(42px, 9vw, 84px); font-weight: 800; line-height: 1.02;
  letter-spacing: -1px; margin-bottom: 18px;
  text-shadow: 0 4px 30px rgba(0,0,0,.5);
}
.splash-tag { font-size: clamp(15px, 2.4vw, 19px); line-height: 1.5; opacity: .92; margin-bottom: 36px; }
#btn-start {
  font-size: 18px; font-weight: 700; letter-spacing: .3px;
  padding: 16px 42px; border-radius: 40px; border: none; cursor: pointer;
  background: var(--ad-gold); color: #1d1607;
  box-shadow: 0 6px 30px rgba(230,185,61,.45);
  transition: transform .2s, box-shadow .2s, opacity .2s;
}
#btn-start:disabled { opacity: .55; cursor: wait; }
#btn-start:not(:disabled):hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 10px 40px rgba(230,185,61,.6); }
.btn-icon { font-size: 14px; margin-right: 4px; }
.splash-hint { margin-top: 26px; font-size: 12.5px; letter-spacing: 1px; text-transform: uppercase; opacity: .6; }

/* ---------- Topbar ---------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h); z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 14px;
  background: linear-gradient(90deg, var(--ad-green-dark), var(--ad-green));
  border-bottom: 1px solid rgba(230,185,61,.35);
  color: var(--ad-cream);
}
#topbar .brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
#topbar .brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
#topbar .brand-name { font-size: 17px; font-weight: 700; }
#topbar .brand-sub { font-size: 11px; opacity: .7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#scenario-switch {
  display: flex; background: rgba(0,0,0,.35); border-radius: 30px; padding: 4px;
  border: 1px solid rgba(255,255,255,.12);
}
.sw-btn {
  border: none; background: transparent; color: rgba(244,241,230,.75);
  font-size: 13.5px; font-weight: 600; padding: 8px 18px; border-radius: 24px;
  cursor: pointer; transition: all .25s; white-space: nowrap;
}
.sw-btn.active { background: var(--ad-gold); color: #1d1607; box-shadow: 0 2px 12px rgba(230,185,61,.5); }
.sw-btn:not(.active):hover { color: #fff; }

.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-tools { display: flex; align-items: center; gap: 8px; }

/* ---------- Dropdown de campos (estética dashboard) ---------- */
#campo-dd { position: relative; }
#campo-btn {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  height: 42px; padding: 4px 38px 4px 16px; border-radius: 8px; cursor: pointer;
  background: rgba(0,0,0,.35); color: var(--ad-cream);
  border: 1px solid rgba(230,185,61,.5); position: relative; min-width: 190px;
  width: max-content;
}
#campo-btn:hover { background: rgba(0,0,0,.5); }
#campo-btn .dd-tag {
  font-size: 9px; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--ad-gold); font-weight: 700; line-height: 1.2;
}
#campo-current { font-size: 13.5px; font-weight: 700; line-height: 1.2; white-space: nowrap; }
#campo-btn .dd-caret {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  color: var(--ad-gold); font-size: 11px; transition: transform .25s;
}
#campo-dd.open .dd-caret { transform: translateY(-50%) rotate(180deg); }
#campo-menu {
  position: absolute; top: calc(100% + 8px); right: 0; min-width: 250px; max-height: 60vh;
  overflow-y: auto; z-index: 40;
  background: var(--ad-green-dark);
  border: 1px solid rgba(230,185,61,.45); border-radius: 10px;
  box-shadow: 0 14px 40px rgba(0,0,0,.5);
  opacity: 0; visibility: hidden; transform: translateY(-6px);
  transition: all .22s ease;
}
#campo-dd.open #campo-menu { opacity: 1; visibility: visible; transform: translateY(0); }
#campo-menu .dd-header {
  padding: 10px 16px 8px; font-size: 10px; letter-spacing: 1.6px; text-transform: uppercase;
  color: var(--ad-gold); font-weight: 700; border-bottom: 1px solid rgba(255,255,255,.08);
}
#campo-list { list-style: none; padding: 4px 0; }
#campo-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; cursor: pointer; color: var(--ad-cream); font-size: 13.5px;
  border-bottom: 1px solid rgba(255,255,255,.05);
}
#campo-list li:last-child { border-bottom: none; }
#campo-list li:hover { background: var(--ad-green-mid); }
#campo-list li .dot {
  width: 7px; height: 7px; border-radius: 50%; flex: none;
  background: rgba(244,241,230,.35);
}
#campo-list li.selected .dot { background: var(--ad-gold); }
#campo-list li .dd-name { flex: 1; }
#campo-list li .check { color: var(--ad-gold); font-weight: 700; visibility: hidden; }
#campo-list li.selected .check { visibility: visible; }

/* ---------- Slider de opacidad ---------- */
.opacity-row { display: flex; align-items: center; gap: 12px; }
#opacity-slider {
  flex: 1; -webkit-appearance: none; appearance: none; height: 5px; border-radius: 3px;
  background: linear-gradient(90deg, var(--ad-green-mid), var(--ad-green-bright));
  outline: none; cursor: pointer;
}
#opacity-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--ad-gold); border: 2px solid #1d1607;
  box-shadow: 0 2px 8px rgba(0,0,0,.4); cursor: grab;
}
#opacity-slider::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--ad-gold); border: 2px solid #1d1607; cursor: grab;
}
#opacity-val { font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--ad-gold); font-weight: 700; min-width: 40px; text-align: right; }
.topbar-right button {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.06); color: var(--ad-cream); font-size: 17px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex: none;
}
.topbar-right button:hover { background: rgba(255,255,255,.14); }
.topbar-right button.active { background: var(--ad-gold); color: #1d1607; border-color: var(--ad-gold); }
.topbar-right button svg { display: block; }

/* ---------- Panel lateral ---------- */
#panel {
  position: fixed; top: calc(var(--topbar-h) + 12px); left: 12px; z-index: 25;
  width: 300px; max-height: calc(100% - var(--topbar-h) - 24px);
  overflow-y: auto;
  background: var(--panel-bg); backdrop-filter: blur(8px);
  border: 1px solid rgba(230,185,61,.25); border-radius: 14px;
  color: var(--ad-cream);
  transition: transform .35s ease, opacity .35s;
}
#panel.collapsed { transform: translateX(-120%); opacity: 0; pointer-events: none; }
.panel-section { padding: 16px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.panel-section:last-child { border-bottom: none; }
#panel h2 { font-size: 19px; margin-bottom: 3px; }
#panel-sub { font-size: 12.5px; opacity: .7; }
#panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--ad-gold); margin-bottom: 10px; }

#legend { list-style: none; }
#legend li { display: flex; align-items: center; gap: 9px; padding: 4px 0; font-size: 13.5px; }
.chip { width: 14px; height: 14px; border-radius: 4px; flex: none; border: 1px solid rgba(255,255,255,.25); }
#legend .ha { margin-left: auto; font-variant-numeric: tabular-nums; opacity: .85; font-size: 12.5px; }

.impact-row { display: flex; align-items: stretch; gap: 8px; }
.impact-box {
  flex: 1; background: rgba(255,255,255,.06); border-radius: 10px; padding: 10px;
  display: flex; flex-direction: column; gap: 2px; text-align: center;
}
.impact-box.highlight { background: rgba(63,174,78,.22); border: 1px solid rgba(63,174,78,.5); }
.impact-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .8px; opacity: .75; }
.impact-value { font-size: 20px; font-weight: 700; }
.impact-arrow { align-self: center; color: var(--ad-gold); font-size: 18px; }
.impact-note { margin-top: 10px; font-size: 12.5px; line-height: 1.45; opacity: .85; }
.panel-footer { padding: 12px 18px; font-size: 11.5px; opacity: .55; line-height: 1.4; }

/* ---------- Controles de vuelo ---------- */
#flight-controls {
  position: fixed; right: 12px; bottom: 110px; z-index: 25;
  display: flex; flex-direction: column; gap: 8px;
}
#flight-controls button {
  width: 46px; height: 46px; border-radius: 50%; border: 1px solid rgba(230,185,61,.4);
  background: var(--panel-bg); color: var(--ad-cream); font-size: 19px; cursor: pointer;
  backdrop-filter: blur(6px); transition: all .2s;
  display: flex; align-items: center; justify-content: center;
}
#flight-controls button:hover { background: var(--ad-green-mid); transform: scale(1.07); }
#flight-controls button.active { background: var(--ad-gold); color: #1d1607; border-color: var(--ad-gold); }
#btn-tour svg, #btn-reset svg { display: block; }
#flight-controls #btn-orbit { font-size: 27px; line-height: 1; }

#tour-banner {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(80px);
  z-index: 25; padding: 9px 20px; border-radius: 24px;
  background: var(--panel-bg); color: var(--ad-cream); font-size: 13px;
  border: 1px solid rgba(230,185,61,.35); backdrop-filter: blur(6px);
  opacity: 0; transition: all .4s; pointer-events: none; white-space: nowrap;
}
#tour-banner.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Popup MapLibre ---------- */
.maplibregl-popup-content {
  background: var(--panel-bg) !important; color: var(--ad-cream);
  border: 1px solid rgba(230,185,61,.35); border-radius: 10px !important;
  padding: 12px 16px !important; font-family: inherit;
  backdrop-filter: blur(6px);
}
.maplibregl-popup-tip { border-top-color: rgba(10,32,14,.92) !important; border-bottom-color: rgba(10,32,14,.92) !important; }
.maplibregl-popup-close-button { color: var(--ad-cream); font-size: 16px; right: 4px; top: 2px; }
.popup-title { font-weight: 700; font-size: 14.5px; margin-bottom: 2px; }
.popup-sub { font-size: 11.5px; text-transform: uppercase; letter-spacing: .8px; opacity: .7; margin-bottom: 6px; }
.popup-ha { font-size: 13px; }
.popup-ha b { color: var(--ad-gold); font-size: 16px; }

/* MapLibre controls bajo el header */
.maplibregl-ctrl-top-right { top: 8px; }

/* ---------- Mobile (hasta 830px: antes el conmutador de escenario
   se solapaba con el logo entre 761 y 830) ---------- */
@media (max-width: 830px) {
  #topbar { flex-wrap: wrap; height: auto; padding: 8px 10px; row-gap: 6px; }
  :root { --topbar-h: 98px; }
  #campo-btn { min-width: 0; max-width: 150px; }
  #campo-current { overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
  #campo-menu { right: -50px; min-width: 220px; }
  #scenario-switch { order: 3; width: 100%; justify-content: stretch; }
  .sw-btn { flex: 1; padding: 8px 6px; font-size: 12.5px; }
  #panel { width: calc(100% - 24px); max-height: 45%; }
  #panel { top: auto; bottom: 12px; }
  #panel.collapsed { transform: translateY(130%); }
  #flight-controls { bottom: auto; top: calc(var(--topbar-h) + 12px); }
  /* Control +/- y brújula de MapLibre a la izquierda, para no chocar con los 3 botones de cámara */
  .maplibregl-ctrl-top-right { left: 8px; right: auto; }
  /* Ícono de órbita un poco más grande en móvil */
  #flight-controls #btn-orbit { font-size: 30px; }
  /* Portada: "Navegación libre…" en su propia línea */
  .splash-hint .hint-sep { display: none; }
  .splash-hint .hint-b { display: block; margin-top: 4px; }
  #tour-banner { font-size: 11.5px; max-width: 92%; white-space: normal; text-align: center; }
}

/* ---------- Mobile angosto: header a 3 líneas prolijas. El ancho
   completo fuerza el salto de línea acá (con margen sobre el punto en
   que el selector + botones dejan de entrar junto al logo, ~465px),
   así nunca quedan apilados y pegados al selector ---------- */
@media (max-width: 500px) {
  .topbar-right { width: 100%; justify-content: space-between; }
}
