/* CCV · Estado de planta: mapa a pantalla completa, controles flotantes y hoja inferior */
:root {
  --rojo: #c62a24; --rojo-osc: #9e1f1a;
  --degradado: linear-gradient(90deg, #ad0272 0%, #a00644 45%, #930a14 100%);
  --tinta: #26211f; --gris: #6e6562; --linea: #dcd6d3; --acero: #f3f1f0;
  --alerta: #b3261e; --radio: 10px;
  --sombra: 0 6px 24px rgba(20, 10, 12, .18), 0 1px 3px rgba(20, 10, 12, .12);
  --f-texto: "Barlow", "Segoe UI", system-ui, sans-serif;
  --f-titulo: "Barlow Semi Condensed", "Arial Narrow", "Segoe UI", sans-serif;
  --alto-barra: 52px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 400 15px/1.4 var(--f-texto); color: var(--tinta); background: #e9e6e4; overflow: hidden; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #f2a900; outline-offset: 2px; }

/* ---------- Barra superior ---------- */
.cb {
  position: fixed; inset: 0 0 auto 0; z-index: 1000; height: calc(var(--alto-barra) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) .5rem 0; display: flex; align-items: center; gap: .4rem;
  background: var(--degradado); color: #fff;
}
.cb svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.cb-home svg { fill: currentColor; stroke: none; }
.cb-home, .cb-btn { flex: none; display: grid; place-items: center; min-width: 40px; height: 40px; border-radius: 8px; color: #fff; background: rgba(255,255,255,.1); border: 0; text-decoration: none; cursor: pointer; }
.cb-home:hover, .cb-btn:hover { background: rgba(255,255,255,.22); }
.cb-txt { padding: 0 .7rem; font-weight: 600; }
.cb-salir { margin: 0; }
.cb-tit { font: 700 1.2rem/1 var(--f-titulo); letter-spacing: .02em; margin-right: auto; padding-left: .2rem; min-width: 0; white-space: nowrap; overflow: hidden; }
.cb-tit small { display: block; font: 500 .72rem var(--f-texto); opacity: .85; letter-spacing: .03em; }
.cb-planos { display: flex; min-width: 0; background: rgba(0,0,0,.2); border-radius: 9px; padding: 3px; }
.cb-planos button { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 0; background: none; color: rgba(255,255,255,.85); padding: .35rem .7rem; border-radius: 7px; font-weight: 600; cursor: pointer; }
.cb-planos button[aria-selected=true] { background: #fff; color: var(--rojo-osc); }

/* ---------- Mapa ---------- */
.lienzo { position: fixed; inset: calc(var(--alto-barra) + env(safe-area-inset-top)) 0 0 0; }
.mapa { position: absolute; inset: 0; background: #f7f6f5; z-index: 0; }
.leaflet-container { font-family: var(--f-texto); }
.lbl { display: none; background: none; border: 0; box-shadow: none; padding: 0; font: 700 9px/1 var(--f-texto); color: #1c1c1c; text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 3px #fff; white-space: nowrap; }
.lbl::before { display: none; }
.ver-lbl .lbl { display: block; }
.herb { width: 12px !important; height: 12px !important; border-radius: 50% 0 50% 50%; background: #3fa34d; border: 2px solid #fff; box-shadow: 0 1px 2px rgba(0,0,0,.35); transform: rotate(-45deg); }
.leaflet-top.leaflet-right { top: .5rem; right: .25rem; }
.leaflet-bar a { width: 38px !important; height: 38px !important; line-height: 38px !important; }

/* ---------- Búsqueda ---------- */
.busqueda { position: absolute; z-index: 900; top: .6rem; left: .6rem; right: 3.4rem; max-width: 460px; background: #fff; border-radius: var(--radio); box-shadow: var(--sombra); overflow: hidden; }
.busqueda input { width: 100%; border: 0; padding: .85rem 1rem; font: 500 1rem var(--f-texto); outline: none; border-bottom: 1px solid var(--linea); }
.busqueda ul { list-style: none; margin: 0; padding: .25rem; max-height: 50vh; overflow-y: auto; }
.busqueda ul:empty { display: none; }
.busqueda li button { width: 100%; display: grid; grid-template-columns: 12px 1fr; gap: 0 .6rem; align-items: center; text-align: left; border: 0; background: none; padding: .55rem .6rem; border-radius: 8px; cursor: pointer; }
.busqueda li button:hover { background: var(--acero); }
.busqueda li i { width: 12px; height: 12px; border-radius: 3px; grid-row: span 2; }
.busqueda li small { color: var(--gris); grid-column: 2; }
.busqueda .sin { padding: .7rem; color: var(--gris); }

/* ---------- Leyenda (también filtro) ---------- */
.leyenda { position: absolute; z-index: 800; left: .6rem; bottom: calc(.6rem + env(safe-area-inset-bottom)); max-width: min(340px, calc(100vw - 5rem)); }
.ley-resumen { display: flex; flex-direction: column; gap: .3rem; width: 100%; padding: .55rem .75rem; background: #fff; border: 0; border-radius: var(--radio); box-shadow: var(--sombra); text-align: left; cursor: pointer; }
.ley-barra { display: flex; height: 8px; width: 190px; max-width: 100%; border-radius: 4px; overflow: hidden; background: var(--acero); }
.ley-barra i { display: block; height: 100%; }
.ley-txt { font-weight: 600; font-size: .88rem; }
.ley-txt::after { content: " ▾"; color: var(--gris); }
.leyenda:has(.ley-lista:not([hidden])) .ley-txt::after { content: " ▴"; }
.ley-lista { margin-bottom: .4rem; background: #fff; border-radius: var(--radio); box-shadow: var(--sombra); padding: .4rem; display: flex; flex-direction: column; gap: .15rem; }
.leyenda { display: flex; flex-direction: column-reverse; }
.ley-chip { display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: .55rem; border: 0; background: none; padding: .5rem .55rem; border-radius: 7px; cursor: pointer; text-align: left; font-size: .9rem; }
.ley-chip:hover { background: var(--acero); }
.ley-chip i { width: 14px; height: 14px; border-radius: 4px; }
.ley-chip b { font-variant-numeric: tabular-nums; }
.ley-chip.off { opacity: .4; text-decoration: line-through; }
.ley-atr i { border: 2px dashed #5b4a4a; }
.ley-atr.on { background: #fdeceb; color: var(--alerta); }
.ley-nota { margin: .2rem .55rem .3rem; font-size: .78rem; color: var(--gris); display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.herb-mini { display: inline-block; width: 10px; height: 10px; border-radius: 50% 0 50% 50%; background: #3fa34d; transform: rotate(-45deg); }

/* ---------- Botones flotantes ---------- */
.fabs { position: absolute; z-index: 800; right: .6rem; bottom: calc(.6rem + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: .5rem; }
.fab { width: 48px; height: 48px; border-radius: 50%; border: 0; background: #fff; box-shadow: var(--sombra); display: grid; place-items: center; cursor: pointer; color: #1a73e8; }
.fab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; }
.fab svg circle:first-child { fill: currentColor; }

/* ---------- Hoja del sector ---------- */
.hoja {
  position: absolute; z-index: 950; left: 0; right: 0; bottom: 0;
  max-height: 58%; display: flex; flex-direction: column;
  background: #fff; border-radius: 16px 16px 0 0; box-shadow: 0 -8px 30px rgba(20,10,12,.22);
  animation: sube .2s ease-out; padding-bottom: env(safe-area-inset-bottom);
}
.hoja.expandida { max-height: 92%; }
@keyframes sube { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.hoja-asa { flex: none; height: 22px; border: 0; background: none; cursor: pointer; position: relative; }
.hoja-asa::after { content: ""; position: absolute; left: 50%; top: 8px; width: 40px; height: 5px; margin-left: -20px; border-radius: 3px; background: #cfc8c5; }
.hoja-cuerpo { overflow-y: auto; padding: 0 1rem 1rem; overscroll-behavior: contain; }
.h-cab { display: flex; align-items: flex-start; gap: .5rem; }
.h-cab > div { flex: 1; min-width: 0; }
.h-cab h2 { margin: 0; font: 700 1.3rem/1.15 var(--f-titulo); }
.h-cab p { margin: .15rem 0 0; color: var(--gris); font-size: .88rem; }
.h-cerrar { flex: none; width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--acero); font-size: 1.4rem; line-height: 1; cursor: pointer; }
.h-actual { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .8rem; margin: .6rem 0 .8rem; font-size: .88rem; color: var(--gris); }
.pill { display: inline-flex; align-items: center; gap: .35rem; font-weight: 700; color: var(--tinta); background: color-mix(in srgb, var(--c) 22%, #fff); border: 1px solid var(--c); padding: .15rem .6rem; border-radius: 99px; }
.pill::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.txt-alerta { color: var(--alerta); font-weight: 600; }

.h-form { display: flex; flex-direction: column; gap: .6rem; padding: .7rem 0; border-top: 1px solid var(--acero); }
.h-estados { border: 0; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(5, 1fr); gap: .35rem; }
.h-estados legend { font-size: .8rem; font-weight: 600; color: var(--gris); margin-bottom: .35rem; padding: 0; }
.h-est { position: relative; }
.h-est input { position: absolute; opacity: 0; pointer-events: none; }
.h-est span {
  display: flex; flex-direction: column; align-items: center; gap: .25rem; padding: .45rem .15rem;
  border: 1.5px solid var(--linea); border-radius: 9px; font-size: .74rem; font-weight: 600; text-align: center; cursor: pointer; line-height: 1.1;
  transition: border-color .12s, background-color .12s;
}
.h-est i { width: 16px; height: 16px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 2px rgba(255,255,255,.6); }
.h-est input:checked + span { border-color: var(--c); background: color-mix(in srgb, var(--c) 20%, #fff); box-shadow: 0 0 0 1px var(--c); }
.h-est input:focus-visible + span { outline: 3px solid #f2a900; outline-offset: 2px; }
.h-switch { display: flex; align-items: center; gap: .55rem; font-weight: 500; cursor: pointer; }
.h-switch input { appearance: none; width: 40px; height: 24px; border-radius: 12px; background: #cfc8c5; position: relative; cursor: pointer; transition: background .15s; flex: none; margin: 0; }
.h-switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.h-switch input:checked { background: #3fa34d; }
.h-switch input:checked::after { transform: translateX(16px); }
.h-form textarea, .h-pie input { width: 100%; font: inherit; border: 1px solid var(--linea); border-radius: 8px; padding: .55rem .65rem; resize: vertical; }
.h-pie { display: grid; grid-template-columns: 1fr auto; gap: .5rem; align-items: center; }
.h-pie input { grid-column: 1 / -1; }
.h-gps { font-size: .8rem; color: var(--gris); display: inline-flex; align-items: center; gap: .3rem; }
.h-gps::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #b9c0c2; }
.h-gps.ok::before { background: #1a73e8; } .h-gps.regular::before { background: #e9c23a; }
.h-guardar { min-height: 44px; padding: 0 1.4rem; border: 0; border-radius: 9px; background: var(--rojo); color: #fff; font: 700 1.05rem var(--f-titulo); cursor: pointer; }
.h-guardar:hover { background: var(--rojo-osc); }
.h-guardar:disabled { opacity: .6; cursor: progress; }
.h-ingresar { display: block; text-align: center; padding: .7rem; border-radius: 9px; background: var(--acero); color: var(--rojo-osc); font-weight: 600; text-decoration: none; margin: .3rem 0 .6rem; }

.h-hist { border-top: 1px solid var(--acero); padding-top: .5rem; }
.h-hist summary { cursor: pointer; font-weight: 600; padding: .3rem 0; }
.h-hist ol { list-style: none; margin: .3rem 0 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.h-hist li { border-left: 3px solid var(--acero); padding: .15rem 0 .15rem .6rem; font-size: .88rem; }
.h-hist li.sin, .h-hist li.cargando { color: var(--gris); border: 0; padding: 0; }
.hr-l { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.hr-l i { width: 10px; height: 10px; border-radius: 50%; }
.hr-l small { color: var(--gris); }
.hr-l time { margin-left: auto; color: var(--gris); font-size: .8rem; }
.h-hist p { margin: .2rem 0; }
.hr-m { color: var(--gris); font-size: .78rem; }
.hr-fotos { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .3rem; }
.hr-fotos img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid var(--linea); }

/* Fotos (módulo compartido) */
.fotos-ui { display: flex; flex-direction: column; gap: .45rem; }
.fotos-btns { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; }
.btn-foto { position: relative; display: inline-flex; align-items: center; min-height: 38px; padding: 0 .85rem; border-radius: 8px; font-weight: 600; font-size: .9rem; border: 1.5px solid var(--linea); background: #fff; cursor: pointer; }
.btn-foto input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.btn-camara { background: var(--tinta); color: #fff; border-color: var(--tinta); }
.fotos-cuenta { font-size: .8rem; color: var(--gris); }
.fotos-prev { display: flex; flex-wrap: wrap; gap: .45rem; }
.fotos-prev:empty { display: none; }
.fotos-prev figure { position: relative; margin: 0; }
.fotos-prev img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; }
.fotos-quitar { position: absolute; top: -7px; right: -7px; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; background: var(--alerta); color: #fff; font-weight: 700; line-height: 1; cursor: pointer; padding: 0; }

/* ---------- Aviso ---------- */
.toast {
  position: absolute; z-index: 1100; left: 50%; transform: translateX(-50%); top: .7rem;
  max-width: calc(100vw - 1.2rem); background: var(--tinta); color: #fff; border-radius: var(--radio);
  padding: .6rem .9rem; box-shadow: var(--sombra); display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .7rem; font-size: .92rem;
}
.toast button, .toast a { border: 0; background: #fff; color: var(--tinta); border-radius: 7px; padding: .3rem .65rem; font-weight: 700; cursor: pointer; text-decoration: none; }

/* ---------- Escritorio: la hoja pasa a ser tarjeta flotante ---------- */
@media (min-width: 900px) {
  .hoja { left: auto; right: .8rem; bottom: .8rem; top: .8rem; width: 400px; max-height: none; border-radius: 14px; box-shadow: var(--sombra); }
  .hoja.expandida { max-height: none; }
  .hoja-asa { display: none; }
  .hoja-cuerpo { padding-top: 1rem; }
  .lienzo:has(.hoja:not([hidden])) .fabs { right: 420px; }
  .leaflet-top.leaflet-right { right: .25rem; }
}
@media (max-width: 899px) {
  /* Con la hoja abierta en el celular, se ocultan leyenda y botones para dar espacio */
  .lienzo:has(.hoja:not([hidden])) .leyenda, .lienzo:has(.hoja:not([hidden])) .fabs { display: none; }
}
@media (max-width: 400px) {
  .cb-tit { display: none; }
  .cb-planos { margin-right: auto; }
}
@media (max-width: 480px) {
  .cb { gap: .3rem; padding-left: .35rem; padding-right: .35rem; }
  .cb-tit { font-size: 1.05rem; padding-left: 0; }
  .cb-tit small { display: none; }
  .cb-home, .cb-btn { min-width: 36px; height: 36px; }
  .cb-txt { padding: 0 .5rem; font-size: .88rem; }
  .cb-planos button { padding: .3rem .45rem; font-size: .84rem; }
  .h-est span { font-size: .7rem; }
}
