/* =============================================================
   GeoEnv Platform v2 — Geospatial Dashboard
   Dark professional theme, full-viewport scroll layout
   ============================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;600&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #080d14;
  --surface:    #0e1520;
  --surface2:   #131d2e;
  --border:     #1c2d42;
  --border2:    #243650;
  --text:       #c8d8ec;
  --text-dim:   #7a90aa;
  --accent:     #3b9eff;
  --accent-dim: rgba(59,158,255,.12);
  --green:      #23d18b;
  --yellow:     #e5b93c;
  --orange:     #f07b3a;
  --red:        #e8425a;
  --teal:       #18c2b4;
  --purple:     #9b72f5;

  --header-h:  52px;
  --map-h:     40vh;
  --ctrl-w:    340px;
  --radius:    10px;
  --mono:      'JetBrains Mono', 'Courier New', monospace;
}

/* ── Base ── */
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ── */
.header {
  position: sticky; top: 0; z-index: 200;
  height: var(--header-h);
  background: rgba(8,13,20,.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 20px;
}
.header-logo {
  display: flex; align-items: center; gap: 10px;
}
.header-logo svg { flex-shrink: 0; }
.logo-text { font-size: 1rem; font-weight: 700; color: #fff; letter-spacing: .3px; }
.logo-sub  { font-size: .72rem; color: var(--text-dim); }
.header-spacer { flex: 1; }
.header-chip {
  font-size: .68rem; padding: 3px 10px; border-radius: 20px;
  border: 1px solid var(--border2); color: var(--text-dim);
  font-family: var(--mono); display: none;
}
.header-chip.visible { display: block; }

/* ── Workspace (map + controls, fixed height) ── */
.workspace {
  height: var(--map-h);
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#map {
  flex: 1;
  min-width: 0;
}

/* leaflet override */
.leaflet-container { background: #0a101a; }
.leaflet-bar a { background: #0e1520 !important; border-color: #1c2d42 !important; color: #c8d8ec !important; }
.leaflet-bar a:hover { background: #131d2e !important; }

/* ── Control panel ── */
.ctrl-panel {
  width: var(--ctrl-w);
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.ctrl-inner {
  flex: 1; overflow-y: auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}

.coords-display {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: .72rem;
  color: var(--text-dim);
  min-height: 40px;
  display: flex; align-items: center;
  transition: border-color .2s;
}
.coords-display.active {
  border-color: var(--accent);
  color: var(--text);
}
.coords-display .coord-val {
  font-family: var(--mono);
  font-size: .8rem;
  color: var(--accent);
  font-weight: 600;
}

.field-label {
  font-size: .67rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .7px;
  color: var(--text-dim); margin-bottom: 6px;
}

.scale-row {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
}
.scale-btn {
  appearance: none;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text-dim);
  font-size: .7rem; font-weight: 500;
  padding: 6px 0; cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.scale-btn:hover { border-color: var(--accent); color: var(--accent); }
.scale-btn.active {
  background: var(--accent); border-color: var(--accent);
  color: #000; font-weight: 700;
}
.scale-btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.btn-analyze {
  appearance: none;
  width: 100%; padding: 10px;
  background: var(--accent); border: none; border-radius: 8px;
  color: #000; font-weight: 700; font-size: .88rem;
  cursor: pointer; letter-spacing: .2px;
  transition: opacity .15s, transform .1s;
  margin-top: auto;
}
.btn-analyze:disabled { opacity: .35; cursor: not-allowed; }
.btn-analyze:hover:not(:disabled) { opacity: .87; }
.btn-analyze:active:not(:disabled) { transform: scale(.98); }
.btn-analyze:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }

@media (prefers-reduced-motion: reduce) {
  .btn-analyze { transition: none; }
}

/* ── Dashboard ── */
#dashboard {
  padding: 0 0 60px;
  display: none;
}
#dashboard.visible { display: block; }

/* ── Situation banner ── */
.sit-banner {
  padding: 16px 24px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}
.sit-badge {
  font-size: 1rem; font-weight: 700; padding: 6px 18px;
  border-radius: 6px; letter-spacing: .5px; flex-shrink: 0;
}
.sit-CRÍTICO   { background: rgba(232,66,90,.18); border: 1px solid var(--red);    color: var(--red);    }
.sit-ALERTA    { background: rgba(240,123,58,.18); border: 1px solid var(--orange); color: var(--orange); }
.sit-NORMAL    { background: rgba(59,158,255,.12); border: 1px solid var(--accent); color: var(--accent); }
.sit-FAVORABLE { background: rgba(35,209,139,.14); border: 1px solid var(--green);  color: var(--green);  }
.sit-INDETERMINADO { background: rgba(122,144,170,.1); border: 1px solid var(--text-dim); color: var(--text-dim); }

.sit-meta {
  display: flex; flex-direction: column; gap: 2px;
  font-size: .73rem; color: var(--text-dim);
}
.sit-meta strong { color: var(--text); }
.sit-elapsed { margin-left: auto; font-size: .68rem; font-family: var(--mono); color: var(--text-dim); }

/* ── Index sections ── */
.idx-section {
  padding: 20px 24px 0;
}
.idx-section-header {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 14px; padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.idx-section-icon { font-size: 1.1rem; }
.idx-section-title {
  font-size: .78rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .8px; color: var(--text);
}
.idx-section-sub { font-size: .65rem; color: var(--text-dim); margin-left: auto; }

.idx-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.idx-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  position: relative;
  overflow: hidden;
  transition: border-color .2s;
}
.idx-card::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; border-radius: 3px 0 0 3px;
  background: var(--border2);
  transition: background .2s;
}
.idx-card.z-normal::before   { background: var(--green); }
.idx-card.z-moderate::before { background: var(--yellow); }
.idx-card.z-extreme::before  { background: var(--red); }
.idx-card.z-nodata::before   { background: var(--border2); }

.idx-name {
  font-size: .65rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .8px; color: var(--text-dim); margin-bottom: 2px;
}
.idx-desc { font-size: .62rem; color: var(--text-dim); opacity: .7; margin-bottom: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.idx-value {
  font-size: 1.55rem; font-weight: 700; font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  line-height: 1; margin-bottom: 6px;
  color: var(--text);
}
.idx-value.c-normal   { color: var(--green); }
.idx-value.c-moderate { color: var(--yellow); }
.idx-value.c-extreme  { color: var(--red); }
.idx-value.c-nodata   { color: var(--text-dim); }

.idx-badge {
  display: inline-block; font-size: .6rem; font-weight: 600;
  padding: 2px 7px; border-radius: 10px; margin-bottom: 8px;
}
.badge-normal   { background: rgba(35,209,139,.15); color: var(--green); }
.badge-moderate { background: rgba(229,185,60,.15); color: var(--yellow); }
.badge-extreme  { background: rgba(232,66,90,.15);  color: var(--red); }
.badge-nodata   { background: rgba(122,144,170,.1); color: var(--text-dim); }

.idx-stats {
  font-size: .63rem; color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  line-height: 1.6;
}
.idx-stats .z-val { font-family: var(--mono); font-weight: 600; }

.z-track {
  height: 4px; background: var(--border);
  border-radius: 2px; margin-top: 8px; overflow: hidden;
}
.z-fill {
  height: 100%; border-radius: 2px;
  transition: width .5s ease;
}
@media (prefers-reduced-motion: reduce) { .z-fill { transition: none; } }

/* ── Precipitation card (special wide card) ── */
.precip-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px;
  display: flex; gap: 32px; flex-wrap: wrap; align-items: center;
  margin-bottom: 20px;
}
.precip-main { display: flex; flex-direction: column; gap: 4px; }
.precip-val { font-size: 2rem; font-weight: 700; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.precip-label { font-size: .68rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; }
.precip-compare { font-size: .78rem; color: var(--text-dim); }
.precip-compare strong { color: var(--text); }
.precip-badge { align-self: flex-start; }

/* ── Chart section ── */
.chart-section {
  padding: 0 24px 4px;
}
.chart-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; margin-bottom: 12px;
}
.chart-header {
  padding: 9px 14px;
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border);
  font-size: .7rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .6px; color: var(--text-dim);
}
.chart-wrap { height: 220px; padding: 4px; }

/* ── Socio section ── */
.socio-section {
  padding: 20px 24px;
}
.socio-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin-bottom: 16px;
}
@media (max-width: 900px) { .socio-grid { grid-template-columns: 1fr; } }

.socio-cell {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}
.socio-cell-label {
  font-size: .63rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .7px; color: var(--text-dim); margin-bottom: 6px;
}
.socio-cell-body { font-size: .77rem; line-height: 1.6; color: var(--text); }
.crops-list { margin-top: 6px; }
.crop-tag {
  display: inline-block; font-size: .65rem;
  background: rgba(229,185,60,.12); border: 1px solid rgba(229,185,60,.3);
  color: var(--yellow); border-radius: 4px; padding: 2px 7px;
  margin: 2px 3px 2px 0;
}
.causality-box {
  background: rgba(59,158,255,.06); border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0; padding: 12px 16px;
  font-size: .77rem; line-height: 1.65; color: var(--accent);
  font-style: italic; margin-bottom: 12px;
}
.assumptions-box {
  font-size: .65rem; color: var(--text-dim); line-height: 1.7;
}
.assumptions-box li { margin-left: 12px; }

/* ── Report section ── */
.report-section {
  padding: 20px 24px 40px;
  border-top: 1px solid var(--border);
}
.report-header {
  display: flex; align-items: center; gap: 16px; margin-bottom: 16px;
}
.report-title {
  font-size: .78rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .8px; color: var(--text);
}
.report-sub { font-size: .65rem; color: var(--text-dim); }
.btn-report {
  appearance: none;
  padding: 9px 20px; background: transparent;
  border: 1px solid var(--accent); border-radius: 7px;
  color: var(--accent); font-weight: 600; font-size: .8rem;
  cursor: pointer; transition: background .15s;
}
.btn-report:hover { background: var(--accent-dim); }
.btn-report:disabled { opacity: .35; cursor: not-allowed; }
.btn-report:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.report-body {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px 28px;
  font-size: .82rem; line-height: 1.75;
  color: var(--text);
  min-height: 120px;
}
/* Markdown rendered in report */
.report-body h2  { font-size: 1rem; font-weight: 700; color: #fff; margin: 20px 0 8px; border-bottom: 1px solid var(--border); padding-bottom: 5px; }
.report-body h3  { font-size: .88rem; font-weight: 600; color: var(--text); margin: 16px 0 6px; }
.report-body p   { margin-bottom: 10px; }
.report-body strong { color: #fff; }
.report-body ul, .report-body ol { margin: 6px 0 10px 18px; }
.report-body li  { margin-bottom: 4px; }
.report-body table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: .75rem; }
.report-body th, .report-body td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.report-body th  { background: var(--surface2); color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; font-size: .65rem; }
.report-body .cursor { display: inline-block; width: 2px; height: 1em; background: var(--accent); animation: blink .8s step-end infinite; vertical-align: text-bottom; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .report-body .cursor { animation: none; opacity: 1; } }

/* ── Spinner ── */
.spinner-wrap {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 16px;
  padding: 60px 24px; color: var(--text-dim); text-align: center;
}
.spin-ring {
  width: 42px; height: 42px;
  border: 3px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spin-ring { animation: none; border-top-color: var(--accent); opacity: .6; }
}
.spinner-text  { font-size: .82rem; }
.spinner-sub   { font-size: .7rem; color: var(--text-dim); margin-top: 4px; }
.spinner-steps { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.spinner-step  { font-size: .7rem; color: var(--text-dim); }
.spinner-step.done { color: var(--green); }

/* ── Error ── */
.error-wrap {
  display: flex; flex-direction: column; align-items: center;
  gap: 12px; padding: 48px 24px; color: var(--red); text-align: center;
}
.error-wrap p { font-size: .82rem; max-width: 420px; line-height: 1.6; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ── Separator ── */
.section-sep {
  height: 1px; background: var(--border);
  margin: 4px 24px 20px;
}
