/* =========================================================
   RESET Y ESTRUCTURA BÁSICA
   ========================================================= */
* {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}
html, body {
	width: 100%;
	height: 100%;
	font-family: "Segoe UI", Arial, sans-serif;
	background: #f4f6f9;
}
body {
	display: flex;
	flex-direction: column;
}
.app {
	display: flex;
	flex-direction: column;
	width: 100%;
	height: 100%;
}

/* =========================================================
   CABECERA SUPERIOR
   ========================================================= */
.header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	background: #0b3d2e;
	color: #fff;
	padding: 0.5rem 1rem;
}
.header .titlebox {
	text-align: center;
	line-height: 1.2;
}
.header .titlebox .l1 { font-size: 0.9rem; font-weight: bold; }
.header .titlebox .l2 { font-size: 1.1rem; font-weight: bold; }
.header .titlebox .l3 { font-size: 0.7rem; }
.header .titlebox .l4 { font-size: 0.7rem; font-style: italic; }
.header .logo-box img {
	max-height: 50px;
}

/* =========================================================
   MAPA PRINCIPAL
   ========================================================= */
#map {
	flex: 1;
	width: 100%;
	height: calc(100vh - 80px);
	background: #fff;
}

/* =========================================================
   SIDEBAR IZQUIERDO
   ========================================================= */
.sidebar {
	position: absolute;
	top: 80px;
	left: 0;
	bottom: 0;
	width: 360px; /* valor base; se sobrescribe abajo con #sidebar (MOD) */
	background: #fff;
	border-right: 1px solid #ccc;
	overflow-y: auto;
	z-index: 1000;
	transition: transform 0.3s ease;
	box-shadow: 2px 0 6px rgba(0,0,0,0.15);
}
.sidebar.hidden {
	transform: translateX(-100%);
}
.sidebar-inner {
	display: flex;
	flex-direction: column;
	height: 100%;
}
.filtros {
	flex: 0 0 auto;
}
.resultados {
	flex: 1 1 auto;
	display: flex;
	flex-direction: column;
}
.resultados .block-b {
	flex: 1;
	display: flex;
	flex-direction: column;
}

/* =========================================================
   BOTÓN PARA OCULTAR SIDEBAR
   ========================================================= */
.toggle-sidebar {
	position: absolute;
	top: 100px;
	left: 360px; /* valor base; se sobrescribe abajo con #toggleSidebar (MOD) */
	background: #0b3d2e;
	color: #fff;
	border: none;
	width: 14px;
	height: 28px;
	border-radius: 0 12px 12px 0;
	cursor: pointer;
	font-size: 0.8rem;
	line-height: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 1200;
	transition: left 0.3s ease, background 0.2s;
}
.toggle-sidebar:hover {
	background: #09533b;
}

/* =========================================================
   FILTROS (SELECTS)
   ========================================================= */
.row {
	margin-bottom: 0.4rem;
}
.row select {
	width: 100%;
	padding: 0.35rem 0.5rem;
	border: 1px solid #ced4da;
	border-radius: 4px;
	background: #fff;
	font-size: 0.85rem;
}
.row select:focus {
	border-color: #0b3d2e;
	box-shadow: 0 0 0 0.15rem rgba(11, 61, 46, 0.25);
}

/* =========================================================
   BLOQUES (Filtros / Resultados)
   ========================================================= */
.block {
	margin-bottom: 1rem;
	border: 1px solid #ccc;
	border-radius: 6px;
	background: #fff;
	box-shadow: 0 1px 3px rgba(0,0,0,0.05);
	display: flex;
	flex-direction: column;
}
.block-h {
	background: #f1f3f5;
	padding: 0.5rem 0.75rem;
	font-weight: 600;
	border-bottom: 1px solid #ddd;
}
.block-b {
	padding: 0.75rem;
	flex: 1;
	display: flex;
	flex-direction: column;
}

/* =========================================================
   TABS (Filtros / Capas)
   ========================================================= */
.tabs {
	display: flex;
	background: #2d3e50;
}
.tab-btn {
	flex: 1;
	padding: 8px;
	border: none;
	background: #34495e;
	color: #fff;
	cursor: pointer;
	font-size: 0.9rem;
}
.tab-btn.active {
	background: #1abc9c;
}
.tab-pane {
	display: none;
	padding: 10px;
}
.tab-pane.active {
	display: block;
}

/* =========================================================
   ÁRBOL DE CAPAS
   ========================================================= */
#capasTree {
	font-family: Arial, sans-serif;
	font-size: 0.9rem;
	line-height: 1.3;
}
#capasTree ul {
	list-style: none;
	margin: 0;
	padding-left: 1rem;
}
#capasTree li {
	margin: 2px 0;
}
/* Grupo principal */
#capasTree .grupo {
	font-size: 0.9rem;
	font-weight: bold;
	text-transform: uppercase;
	margin: 6px 0;
	padding: 4px 6px;
	background: #f0f0f0;
	border-left: 3px solid #555;
}
/* Categoría padre */
#capasTree .cat-padre {
	font-size: 0.85rem;
	font-weight: 600;
	color: #333;
	cursor: pointer;
	margin-top: 4px;
}
/* Categoría */
#capasTree .cat {
	font-size: 0.75rem;
	font-weight: 500;
	color: #444;
	cursor: pointer;
	margin-left: 8px;
}
/* Capas */
#capasTree .layer-name {
	font-size: 0.7rem;
	font-weight: normal;
	color: #222;
	margin-left: 4px;
}
/* Toggle desplegable */
#capasTree .toggle {
	cursor: pointer;
	font-size: 0.75rem;
	margin-right: 4px;
}
/* Colapsable */
#capasTree .nested { display: none; }
#capasTree .nested.active { display: block; }
/* Botones de opciones (opacidad / leyenda) */
#capasTree .btn-opc {
	background: none;
	border: none;
	cursor: pointer;
	font-size: 0.85rem;
	margin-left: 4px;
	padding: 2px;
	opacity: 0.7;
}
#capasTree .btn-opc:hover { opacity: 1; }
/* Panel dinámico de cada capa */
#capasTree .layer-panel {
	margin: 4px 0 4px 18px;
	padding: 4px;
	background: #fafafa;
	border: 1px solid #ddd;
	border-radius: 4px;
	font-size: 0.75rem;
}
#capasTree .layer-panel.hidden { display: none; }
/* Control de opacidad */
.opacity-control {
	display: flex;
	align-items: center;
	gap: 6px;
}
.opacity-control input[type=range] { flex: 1; }
.opacity-control .opacity-val {
	min-width: 32px;
	text-align: right;
}
/* Control de leyenda */
.legend-control img {
	max-width: 160px;
	border: 1px solid #ccc;
	background: white;
	padding: 2px;
}

/* =========================================================
   BOTONES DE ACCIÓN (Procesar / Limpiar)
   ========================================================= */
.actions {
	display: flex;
	gap: 0.5rem;
	margin: 0 0.5rem 0.8rem;
	justify-content: flex-end;
}
.btn {
	flex: none;
	padding: 0.35rem 0.9rem;
	font-size: 0.8rem;
	font-weight: 600;
	border-radius: 6px;
	cursor: pointer;
	border: none;
	transition: all 0.2s ease-in-out;
	min-width: 80px;
	text-align: center;
}
.btn.primary { background: #0b3d2e; color: #fff; }
.btn.primary:hover { background: #09533b; }
.btn.secondary { background: #adb5bd; color: #fff; }
.btn.secondary:hover { background: #8d959c; }
.btn:active { transform: scale(0.95); }

/* =========================================================
   TARJETAS Y RESUMENES (Resultados)
   ========================================================= */
.cards {
	display: flex;
	gap: 0.5rem;
	margin-bottom: 0.5rem;
}
.card {
	flex: 1;
	padding: 0.6rem;
	background: #fafafa;
	border: 1px solid #ccc;
	border-radius: 6px;
	text-align: center;
	font-size: 0.85rem;
}

/* =========================================================
   GRÁFICOS (Chart.js)
   ========================================================= */
.chart-wrap {
	flex: 1;
	display: flex;
	flex-direction: column;
	justify-content: space-around;
}
.chart-wrap canvas {
	flex: 1;
	margin: 0.5rem 0;
	max-height: none;
}

/* =========================================================
   SWITCHES DERECHA (Clima / Agro / Focos / Afectación)
   ========================================================= */
.right-tools {
	position: absolute;
	top: 100px;
	right: 10px;
	display: flex;
	flex-direction: column;
	gap: 1rem;
	z-index: 1100;
}
.switch {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	cursor: pointer;
	width: 80px;
	text-align: center;
}
.switch input { display: none; }
.switch .slider {
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	width: 70px;
	height: 70px;
	border-radius: 14px;
	background: #eee;
	border: 2px solid transparent;
	padding: 0.3rem;
	transition: all 0.3s ease;
}
.switch .slider img.icon {
	width: 32px;
	height: 32px;
	margin-bottom: 0.3rem;
}
.switch .slider::after {
	content: attr(data-label);
	font-size: 0.7rem;
	font-weight: 600;
	color: #333;
}
/* Efectos activos por tipo */
.switch input:checked + .slider { transform: scale(1.08); color: #fff; font-weight: bold; box-shadow: 0 0 12px rgba(0,0,0,0.35); }
.switch input:checked + .slider.bg-clima { background: #2196f3; border-color: #0b72d9; }
.switch input:checked + .slider.bg-verano { background: #ffc107; border-color: #e0a800; }
.switch input:checked + .slider.bg-invierno { background: #17a2b8; border-color: #117a8b; }
.switch input:checked + .slider.bg-focos { background: #dc3545; border-color: #b52a37; }
.switch input:checked + .slider.bg-afectacion { background: #6f42c1; border-color: #59359b; }

/* =========================================================
   PANEL DERECHO (Detalles flotantes)
   ========================================================= */
.panel {
	position: absolute;
	top: 100px;
	right: 100px;
	width: 300px;
	height: 400px;
	background: #fff;
	border: 1px solid #ccc;
	border-radius: 6px;
	display: none;
	flex-direction: column;
	z-index: 1200;
	box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.panel-h {
	background: #0b3d2e;
	color: #fff;
	padding: 0.5rem;
	font-weight: bold;
}
.panel-b {
	flex: 1;
	padding: 0.5rem;
	overflow-y: auto;
}

/* =========================================================
   DOCK DE LEYENDAS (parte inferior del mapa)
   ========================================================= */
#legendDock { display: none; }

/* =========================================================
   BLOQUES GRANDES (para secciones)
   ========================================================= */
.seccion {
	flex: 1;
	margin-bottom: 1rem;
}
.seccion .block-b {
	flex: 1;
	min-height: 200px;
	display: flex;
	justify-content: center;
	align-items: center;
	color: #555;
	font-size: 0.9rem;
	text-align: center;
}

/* =========================================================
   LEAFLET: atribución transparente
   ========================================================= */
.leaflet-control-attribution {
	background: transparent !important;
	color: rgba(0,0,0,0.5);
	font-size: 0.7rem;
	border: none !important;
	box-shadow: none !important;
}
.leaflet-control-attribution a {
	color: rgba(0,0,0,0.4) !important;
	text-decoration: none;
}

/* =========================================================
   MOD: Anchos y alturas para gráficos del bloque Agrícola
   ========================================================= */
/* MOD: ancho real del sidebar y posición del botón */
#sidebar { width: 420px; }			/* MOD: antes ~360px */
#toggleSidebar { left: 420px; }	   /* MOD: acompaña al ancho real */

/* MOD: contenedores altos para los gráficos */
#blockAgricola .chart-wrap {
	height: 280px;					/* MOD: más alto */
	padding: 8px 8px 16px;
}
#blockAgricola .chart-wrap--alto {
	height: 340px;					/* MOD: aún más alto cuando se use */
}
/* MOD: el canvas llena el contenedor (evita alturas fijas) */
#blockAgricola .chart-wrap canvas {
	width: 100% !important;
	height: 100% !important;
	display: block;
}

#blockAgricola .table-wrap {
	max-height: 240px;
	overflow: auto;
	margin-top: 6px;
	border: 1px solid #e3e6ea;
	border-radius: 6px;
}
#blockAgricola table.ag-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.85rem;
	background: #fff;
}
#blockAgricola .ag-table thead th {
	position: sticky;
	top: 0;
	background: #f8f9fb;
	z-index: 1;
	border-bottom: 1px solid #dee2e6;
}
#blockAgricola .ag-table th,
#blockAgricola .ag-table td {
	padding: 6px 8px;
	border-bottom: 1px solid #f1f3f5;
	white-space: nowrap;
}
#blockAgricola .ag-table td.num,
#blockAgricola .ag-table th.num { text-align: right; }
#blockAgricola .ag-table td.terr { font-weight: 600; }
#blockAgricola .ag-table .strong { font-weight: 700; }

/* ==== Ajustes finos para el bloque Agrícola (sidebar) ==== */
#sidebar { width: 420px; }
#toggleSidebar { left: 420px; }

/* Contenedor de los gráficos: altura controlada y sin “estirarse” de más */
#blockAgricola .chart-wrap {
	height: 200px;			   /* antes era 280/340; baja el alto */
	padding: 6px 6px 10px;
	flex: 0 0 auto;			  /* no crecer con la columna */
}

/* Usa esta clase sólo donde necesites un poquito más de alto */
#blockAgricola .chart-wrap--alto {
	height: 220px;
}

/* Fuerza a que el canvas ocupe exactamente el contenedor */
#blockAgricola .chart-wrap canvas {
	width: 100% !important;
	height: 100% !important;
	display: block;
}

/* Tabla debajo del segundo gráfico: altura fija + scroll */
/* Que el body del bloque pueda desplazar su contenido sin empujar el mapa */
#blockAgricola .block-b{overflow-y:auto}

/* Contenedores de gráficos: ALTURA CHICA y fija en el layout */
#blockAgricola .chart-wrap{
	flex:0 0 160px;   /* altura real (flex-basis) */
	height:160px;	 /* por si alguien usa height */
	padding:4px 4px 8px;
	overflow:hidden;  /* corta leyendas largas */
}
#blockAgricola .chart-wrap--alto{
	flex-basis:180px;
	height:180px;
}

/* El canvas ocupa exactamente su contenedor */
#blockAgricola .chart-wrap canvas{
	width:100%!important;
	height:100%!important;
	display:block;
}

/* La tabla NO se estira; solo scroll interno */
#blockAgricola .table-wrap{
	flex:0 0 auto;
	max-height:550px;
	max-width:350px;
	overflow:auto;
	margin-top:6px;
	border:1px solid #e3e6ea;
	border-radius:6px;
}

#blockAgricola table.ag-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.75rem;
	background: #fff;
}
#blockAgricola .ag-table thead th {
	position: sticky; top: 0;
	background: #f8f9fb; z-index: 1;
	border-bottom: 1px solid #dee2e6;
}
#blockAgricola .ag-table th,
#blockAgricola .ag-table td {
	padding: 6px 8px;
	border-bottom: 1px solid #f1f3f5;
	white-space: nowrap;
}
#blockAgricola .ag-table td.num,
#blockAgricola .ag-table th.num { text-align: right; }
#blockAgricola .ag-table td.terr { font-weight: 600; }
#blockAgricola .ag-table .strong { font-weight: 700; }

/* ===== Panel Clima (sidebar) ===== */
#blockTemperaturas .block-b { padding: 8px 10px; }

.clima-panel {
	width: 100%;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.clima-head {
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.cl-title {
	font-weight: 700;
	font-size: 0.95rem;
	color: #0b3d2e;
}

.cl-sub {
	font-size: 0.75rem;
	color: #666;
}

.cl-cards {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 8px;
}

.cl-card {
	background: #fff;
	border: 1px solid #e6e9ed;
	border-radius: 8px;
	padding: 8px;
	box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.cl-label {
	font-size: 0.78rem;
	color: #555;
	margin-bottom: 4px;
}

.cl-value {
	font-size: 1.05rem;
	font-weight: 700;
	color: #222;
	margin-bottom: 6px;
	display: flex;
	align-items: baseline;
	gap: 4px;
}

.cl-unit {
	font-weight: 600;
	color: #888;
	font-size: 0.78rem;
}

.cl-bar {
	position: relative;
	height: 6px;
	background: #f1f3f5;
	border-radius: 999px;
	overflow: hidden;
}

.cl-bar > span {
	position: absolute;
	left: 0;
	top: 0;
	height: 100%;
	width: 0%;
	background: linear-gradient(90deg, #17a2b8, #1abc9c);
	border-radius: 999px;
	transition: width 300ms ease;
}

.cl-card.is-empty .cl-bar > span {
	width: 0% !important;
	background: #e0e0e0;
}

/* =========================
   PANEL AFECTACIONES (sidebar)
   ========================= */

.afect-panel {
    border: 1px solid #ccc;
    border-radius: 8px;
    background: #f9f9f9;
    margin: 10px 0;
    padding: 12px;
    font-size: 0.9em;
}

.afect-panel .afect-title {
    font-weight: bold;
    font-size: 1.1em;
    margin-bottom: 6px;
    color: #2c6e49;
}

.afect-panel .afect-sub {
    font-size: 0.85em;
    color: #666;
    margin-bottom: 10px;
}

.afect-kpi {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
    margin-bottom: 10px;
}

.afect-kpi .kpi-card {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 6px 10px;
    text-align: center;
    box-shadow: 1px 1px 3px rgba(0,0,0,0.05);
}

.afect-kpi .kpi-card strong {
    display: block;
    font-size: 1.2em;
    color: #333;
}

.afect-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85em;
    margin-top: 6px;
}

.afect-table th, .afect-table td {
    border: 1px solid #ddd;
    padding: 4px 6px;
}

.afect-table th {
    background: #f0f0f0;
    font-weight: bold;
}

.afect-table tbody tr:nth-child(even) {
    background: #fafafa;
}

/* =========================================================
   PANEL DETALLES CLIMÁTICOS (sidebar)
   ========================================================= */

/* Panel general */
.clima-panel {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  padding: 12px 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  font-family: "Segoe UI", sans-serif;
  max-width: 420px;
}

.clima-panel-header {
  text-align: center;
  margin-bottom: 10px;
}

.clima-panel-titulo {
  font-weight: 600;
  font-size: 16px;
  color: #333;
}

.clima-panel-subtitulo {
  font-size: 13px;
  color: #555;
}

.clima-panel-fecha {
  font-size: 12px;
  color: #777;
}

/* === GRID A DOS COLUMNAS === */
.clima-panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 20px;
  row-gap: 10px;
  position: relative;
}

/* Separador vertical central */
.clima-panel-grid::before {
  content: "";
  position: absolute;
  top: 5%;
  bottom: 5%;
  left: 50%;
  width: 1px;
  background-color: #e4e4e4;
}

/* === CADA BLOQUE === */
.clima-panel-grupo {
  padding-top: 6px;
}

.clima-panel-grupo h5 {
  font-size: 13px;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 5px;
  border-bottom: 1px solid #f0f0f0;
  padding-bottom: 3px;
}

/* === DATOS === */
.clima-panel-datos {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
}

.clima-panel-datos .etiqueta {
  color: #555;
}

.clima-panel-datos .valor {
  float: right;
  font-weight: 600;
  color: #0a74da;
}

/* === COLORES TEMÁTICOS === */
.clima-panel-temperatura h5 { color: #e67e22; }
.clima-panel-humedad h5 { color: #0097a7; }
.clima-panel-viento h5 { color: #2e7d32; }
.clima-panel-precipitacion h5 { color: #1565c0; }