:root {
  --pri: #126044;
  --pri-dark: #072f24;
  --accent: #e6b44a;
  --bg: #edf2ef;
  --panel: #fbfdfc;
  --text: #17251f;
  --muted: #65766e;
  --disp: #2e9e5b;
  --res: #e07b00;
  --sel: #1976d2;
  --danger: #c62828;
  --radius: 12px;
  --shadow: 0 12px 34px rgba(4, 27, 20, .18), 0 2px 8px rgba(4, 27, 20, .1);
  font-size: 15px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% 0%, #f9fbfa, var(--bg) 55%);
  height: 100vh;
  overflow: hidden;
}

/* ============ LOGIN ============ */
#login-screen {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(135deg, rgba(4, 31, 23, .72), rgba(4, 31, 23, .94)),
    url("../img/portal.jpg") center/cover no-repeat, #0a3521;
}
.login-box {
  width: min(420px, 92vw);
  background: rgba(251, 253, 252, .95);
  border: 1px solid rgba(255, 255, 255, .38);
  border-radius: 22px;
  padding: 38px 36px 26px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .42);
  backdrop-filter: blur(18px);
}
.login-logo {
  width: 74px; height: 74px; margin: 0 auto 14px;
  border-radius: 20px;
  background: linear-gradient(145deg, #1b7858, var(--pri-dark));
  color: #fff; font-size: 26px; font-weight: 800; letter-spacing: 1px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .28), 0 12px 24px rgba(7, 47, 36, .25);
}
.login-box h1 { font-size: 22px; color: var(--pri-dark); }
.login-sub { color: var(--muted); font-size: 13px; margin: 8px 0 24px; line-height: 1.5; }
#login-form { text-align: left; }
#login-form label { font-size: 13px; font-weight: 600; color: var(--pri-dark); }
#login-form input {
  width: 100%; margin: 6px 0 14px; padding: 11px 14px;
  border: 1.5px solid #c8d2cc; border-radius: 8px; font-size: 15px; outline: none;
  transition: border-color .15s;
}
#login-form input:focus { border-color: var(--pri); }
#login-form button {
  width: 100%; padding: 12px; border: none; border-radius: 8px;
  background: var(--pri); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background .15s;
}
#login-form button:hover { background: var(--pri-dark); }
.login-error {
  margin-top: 12px; padding: 9px 12px; background: #fdecea; color: var(--danger);
  border-radius: 8px; font-size: 13px; text-align: center;
}
.login-box.shake { animation: shake .35s; }
@keyframes shake { 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }
.login-footer { margin-top: 20px; font-size: 11.5px; color: var(--muted); }

/* ============ LAYOUT ============ */
#app { display: flex; flex-direction: column; height: 100vh; }

#topbar {
  display: flex; align-items: center; gap: 18px; padding: 10px 18px;
  background: linear-gradient(112deg, #062d22 0%, #0c4c38 58%, #17694d 100%);
  color: #fff; z-index: 1200; box-shadow: 0 8px 28px rgba(3, 28, 20, .28); flex-wrap: wrap;
  border-bottom: 1px solid rgba(255,255,255,.13);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo {
  background: linear-gradient(145deg, rgba(255, 255, 255, .2), rgba(255,255,255,.08)); border: 1px solid rgba(255, 255, 255, .34);
  border-radius: 11px; padding: 7px 11px; font-weight: 800; letter-spacing: 1.5px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text small { opacity: .75; font-size: 11px; }

/* Conmutador de modos */
.modos { display: flex; background: rgba(0, 0, 0, .2); border: 1px solid rgba(255,255,255,.09); border-radius: 12px; padding: 3px; gap: 2px; }
.modo-btn {
  border: none; background: transparent; color: rgba(255, 255, 255, .8);
  padding: 7px 14px; border-radius: 8px; font-size: 13.5px; font-weight: 600; cursor: pointer;
  transition: background .15s, color .15s;
}
.modo-btn:hover { color: #fff; }
.modo-btn.active { background: #fff; color: var(--pri-dark); box-shadow: 0 4px 12px rgba(0, 0, 0, .22); }

.stats { display: flex; gap: 8px; margin-left: auto; }
.stat { background: rgba(255, 255, 255, .09); border: 1px solid rgba(255,255,255,.08); border-radius: 10px; padding: 5px 13px; text-align: center; line-height: 1.15; }
.stat span { font-size: 16px; font-weight: 700; display: block; }
.stat small { font-size: 10.5px; opacity: .8; }
.stat.ok span { color: #8ff0b4; }
.stat.warn span { color: #ffce80; }

.topbar-actions { display: flex; gap: 8px; align-items: center; }
.search-box { display: flex; }
.search-box input { border: none; border-radius: 8px 0 0 8px; padding: 8px 10px; width: 130px; font-size: 14px; outline: none; }
.search-box button { border: none; border-radius: 0 8px 8px 0; background: var(--accent); cursor: pointer; padding: 0 10px; font-size: 14px; }

.btn-sec, .btn-pri, .btn-danger, .btn-warn {
  border: none; border-radius: 8px; padding: 8px 14px; font-size: 13.5px; font-weight: 600; cursor: pointer;
  transition: filter .15s;
}
.btn-sec { background: rgba(255, 255, 255, .16); color: #fff; }
#sidebar .btn-sec { background: #e7ece9; color: var(--text); }
.btn-pri { background: var(--pri); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warn { background: var(--accent); color: #2b1f00; }
.btn-sec:hover, .btn-pri:hover, .btn-danger:hover, .btn-warn:hover { filter: brightness(1.12); }

#main { flex: 1; display: flex; position: relative; overflow: hidden; }
#map { flex: 1; height: 100%; background: #cfd8d2; }
#map canvas { outline: none; }

/* ============ SIDEBAR ============ */
#sidebar {
  width: 344px; background: linear-gradient(180deg, #fcfefd, #f4f8f6); border-left: 1px solid rgba(31,72,56,.14);
  display: flex; flex-direction: column; overflow: hidden; transition: margin-right .25s;
  box-shadow: -10px 0 32px rgba(5, 35, 25, .12); z-index: 10;
}
#sidebar.oculto { margin-right: -344px; }
.panel { padding: 14px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 14px; }
.panel[hidden] { display: none; }

.placeholder { color: var(--muted); font-size: 13.5px; line-height: 1.55; padding: 10px 4px; }
.bloque { border: 1px solid rgba(36,84,66,.13); border-radius: var(--radius); padding: 13px; background: rgba(255,255,255,.72); box-shadow: 0 5px 18px rgba(14,60,43,.045); }
.bloque h3 { font-size: 13.5px; color: var(--pri-dark); margin-bottom: 8px; }
.ayuda { font-size: 11.5px; color: var(--muted); margin-top: 7px; line-height: 1.45; }
.col { display: flex; flex-direction: column; gap: 7px; }
.fila { display: flex; gap: 6px; }
.fila input, .fila select { flex: 1; }
.wide { width: 100%; }

input[type=text], select, textarea {
  width: 100%; padding: 8px 10px; border: 1.5px solid #c8d2cc; border-radius: 8px; font-size: 13.5px; font-family: inherit;
}
#sidebar button:not(.btn-pri):not(.btn-danger):not(.btn-warn) { background: #e7ece9; color: var(--text); border: none; border-radius: 8px; padding: 8px 12px; font-size: 13px; font-weight: 600; cursor: pointer; }
#sidebar button:hover { filter: brightness(1.05); }
button.mini { padding: 6px 10px; font-size: 13px; }
.modo-activo { outline: 2.5px solid var(--danger); outline-offset: 1px; }

/* Reserva */
.detalle-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.detalle-head h2 { font-size: 19px; color: var(--pri-dark); }
.badge { padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; color: #fff; }
.badge.disp { background: var(--disp); }
.badge.res { background: var(--res); }
.props { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.props td { padding: 7px 4px; border-bottom: 1px solid #eef2f0; font-size: 14px; }
.props td:first-child { color: var(--muted); width: 42%; }
.props td:last-child { font-weight: 600; }
.reserva-info { background: #fff6e8; border: 1px solid #f3ddb5; border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; font-size: 13.5px; }
.reserva-info h3 { font-size: 13px; color: var(--res); margin-bottom: 6px; }
.reserva-info p { margin: 3px 0; }
#form-reserva label { font-size: 13px; font-weight: 600; color: var(--pri-dark); }
#form-reserva textarea { margin: 6px 0 12px; resize: vertical; }
.acciones { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.reservas-head { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.reservas-head h2 { font-size: 16px; color: var(--pri-dark); }
.resumen { background: #eef5f1; border-radius: var(--radius); padding: 10px 14px; font-size: 13px; line-height: 1.6; }
.lista-reservas { list-style: none; }
.lista-reservas li { border: 1px solid #e2e8e4; border-left: 4px solid var(--res); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; font-size: 13.5px; cursor: pointer; }
.lista-reservas li:hover { background: #f7faf8; }
.lista-reservas .l-head { display: flex; justify-content: space-between; font-weight: 700; }
.lista-reservas .l-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.lista-reservas .l-nota { font-size: 12.5px; margin-top: 4px; font-style: italic; }
.lista-reservas .l-quitar { background: none; border: none; color: var(--danger); font-size: 12px; font-weight: 600; cursor: pointer; padding: 0; margin-top: 6px; }

/* Edición: valores */
#lista-valores { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.chip { display: flex; align-items: center; gap: 8px; border: 2px solid transparent; border-radius: 8px; padding: 7px 9px; background: #f6f8f7; cursor: pointer; font-size: 13px; }
.chip:hover { background: #eef5f1; }
.chip.activo { border-color: var(--pri); background: #eaf5ef; box-shadow: 0 0 0 2px rgba(14,90,58,.15); }
.chip .color { width: 18px; height: 18px; border-radius: 5px; flex: none; border: 1px solid rgba(0,0,0,.25); }
.chip .etiqueta { flex: 1; font-weight: 600; }
.chip .cuenta { color: var(--muted); font-size: 12px; }
.chip .quitar { background: none; border: none; color: var(--danger); font-weight: 700; cursor: pointer; padding: 0 3px; }

/* ============ CONTROL DE CAPAS ============ */
#capas {
  position: absolute; right: 356px; top: 12px; z-index: 1100;
  background: rgba(249, 252, 250, .88); border: 1px solid rgba(255,255,255,.68); border-radius: 14px; box-shadow: var(--shadow);
  padding: 11px 15px; font-size: 12.5px; line-height: 1.55; transition: right .25s;
  backdrop-filter: blur(16px) saturate(125%);
}
#capas strong { display: block; color: var(--pri-dark); margin: 6px 0 3px; }
#capas strong:first-child { margin-top: 0; }
#capas label { display: block; cursor: pointer; padding: 1.5px 0; }
#capas input { margin-right: 6px; accent-color: var(--pri); }
.capa-vistas { display: flex; gap: 5px; margin: 3px 0 6px; }
.capa-vistas button {
  flex: 1; border: 1px solid rgba(11, 92, 70, .22); border-radius: 7px;
  background: rgba(255,255,255,.76); color: var(--pri-dark); padding: 4px 7px;
  font: inherit; font-size: 11px; font-weight: 650; cursor: pointer;
}
.capa-vistas button:hover { background: #e4f2ec; border-color: rgba(11, 92, 70, .45); }
#sidebar.oculto ~ #capas { right: 12px; }

/* ============ LEYENDA ============ */
#leyenda {
  position: absolute; left: 12px; bottom: 24px; z-index: 1100;
  background: rgba(249, 252, 250, .88); border: 1px solid rgba(255,255,255,.68); border-radius: 14px; box-shadow: var(--shadow);
  padding: 11px 15px; font-size: 12.5px; line-height: 1.9; max-height: 42vh; overflow-y: auto;
  backdrop-filter: blur(16px) saturate(125%);
}
#leyenda strong { display: block; margin-bottom: 2px; color: var(--pri-dark); }
.sw { display: inline-block; width: 16px; height: 12px; border-radius: 4px; margin-right: 7px; vertical-align: -1px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.22); }

/* ============ BARRA PRESENTACIÓN ============ */
#viz-bar {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 18px; z-index: 1150;
  background: rgba(249, 252, 250, .9); border: 1px solid rgba(255,255,255,.75); border-radius: 16px; box-shadow: 0 18px 48px rgba(3,27,19,.24), 0 3px 10px rgba(3,27,19,.12);
  padding: 11px 16px; display: flex; align-items: center; gap: 10px; font-size: 13px;
  flex-wrap: wrap; justify-content: center; max-width: 94%;
  backdrop-filter: blur(18px) saturate(135%);
}
#viz-bar strong { color: var(--pri-dark); }
.vb-btn { border: 1px solid #c4d1ca; background: rgba(255,255,255,.86); border-radius: 9px; padding: 7px 11px; font-size: 13px; font-weight: 650; cursor: pointer; box-shadow: 0 2px 5px rgba(7,47,36,.05); }
.vb-btn:hover { background: #eef5f1; }
.vb-btn.active { background: var(--accent); border-color: var(--accent); color: #2b1f00; box-shadow: 0 0 0 2px rgba(212,160,23,.35); }
.vb-btn.pri { background: linear-gradient(145deg, #176e50, var(--pri-dark)); border-color: transparent; color: #fff; box-shadow: 0 6px 14px rgba(7,47,36,.2); }
.vb-btn.pri:hover { background: var(--pri-dark); }
.vb-sep { width: 1px; height: 22px; background: #dde4e0; }
.vb-chk { display: flex; align-items: center; gap: 5px; cursor: pointer; font-weight: 600; }
.vb-chk input { accent-color: var(--pri); }
.vb-slider { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.vb-slider input { accent-color: var(--pri); width: 110px; }
#vb-densidad-val { min-width: 36px; text-align: right; color: var(--pri-dark); }

/* ============ TOAST / CARGANDO ============ */
#toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--pri-dark); color: #fff; padding: 11px 22px; border-radius: 999px;
  font-size: 14px; z-index: 6000; box-shadow: var(--shadow); animation: toast-in .25s;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } }
#cargando {
  position: fixed; inset: 0; z-index: 5500; display: flex; align-items: center; justify-content: center; gap: 14px;
  background: rgba(8, 40, 26, .45); color: #fff; font-size: 15px; font-weight: 600;
}
.spin { width: 34px; height: 34px; border: 4px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Popup MapLibre */
.maplibregl-popup-content { font-family: inherit; font-size: 12.5px; line-height: 1.5; border-radius: 8px; padding: 8px 12px; box-shadow: var(--shadow); }
.maplibregl-ctrl-attrib { font-size: 10px; }
.maplibregl-ctrl-group { border-radius: 12px !important; overflow: hidden; box-shadow: var(--shadow) !important; }
.maplibregl-ctrl-group button { width: 32px; height: 32px; }
.maplibregl-ctrl-scale { border-color: rgba(255,255,255,.9); color: #fff; background: rgba(6,45,34,.72); border-radius: 0 0 5px 5px; text-shadow: 0 1px 2px rgba(0,0,0,.45); }

@media (max-width: 900px) {
  .stats { display: none; }
  #sidebar { position: absolute; right: 0; top: 0; bottom: 0; z-index: 1300; box-shadow: var(--shadow); }
  #capas { right: 12px; }
}
