:root {
  --bosque: #1f4d3a;
  --bosque-2: #2f6b4f;
  --crema: #f7f3ec;
  --tinta: #1d2522;
  --gris: #6b736f;
  --borde: #e3ddd2;
  --ok: #2e8b57;
  --ocupado: #9a9a9a;
  --rojo: #c0392b;
  --radio: 14px;
  --sombra: 0 6px 24px rgba(20, 40, 30, .14);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--tinta);
  background: var(--crema);
  display: flex; flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; cursor: pointer; }

/* Header */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: var(--bosque); color: #fff;
  padding-top: max(10px, env(safe-area-inset-top));
}
.brand { display: flex; gap: 10px; align-items: center; }
.logo {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: #fff; color: var(--bosque); font-size: 18px;
}
.brand h1 { margin: 0; font-size: 1.15rem; letter-spacing: .3px; }
.brand p { margin: 0; font-size: .72rem; opacity: .8; }
.badge-proto {
  font-size: .7rem; padding: 3px 8px; border-radius: 99px;
  background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.3);
}

/* Filtros */
.filters { background: #fff; border-bottom: 1px solid var(--borde); padding: 8px 0 4px; }
.chip-row {
  display: flex; gap: 6px; overflow-x: auto; padding: 0 12px 6px;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--borde); background: #fff; color: var(--tinta);
  padding: 7px 12px; border-radius: 99px; font-size: .85rem; white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.chip[aria-pressed="true"], .chip[aria-checked="true"] {
  background: var(--bosque); color: #fff; border-color: var(--bosque);
}

/* Layout */
.layout { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#map { height: 42vh; min-height: 240px; flex: none; z-index: 0; }
.results { flex: 1; overflow-y: auto; padding: 10px 12px 90px; }
.results-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.link { background: none; border: 0; color: var(--bosque-2); text-decoration: underline; padding: 0; font-size: .85rem; }

@media (min-width: 900px) {
  .layout { flex-direction: row-reverse; }
  #map { height: auto; flex: 1; }
  .results { flex: none; width: 420px; border-right: 1px solid var(--borde); }
}

/* Tarjetas */
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card {
  background: #fff; border-radius: var(--radio); border: 2px solid transparent;
  box-shadow: 0 1px 3px rgba(0,0,0,.06); overflow: hidden; display: flex;
  transition: border-color .15s, transform .15s;
}
.card.activa { border-color: var(--bosque-2); transform: translateY(-1px); box-shadow: var(--sombra); }
.card.ocupada .thumb { filter: grayscale(.85); }
.thumb {
  width: 96px; flex: none; display: grid; place-items: center; color: #fff;
  font-size: 2rem; position: relative;
}
.thumb small {
  position: absolute; bottom: 6px; left: 6px; right: 6px; text-align: center;
  font-size: .62rem; background: rgba(0,0,0,.35); border-radius: 6px; padding: 2px;
}
.card-body { padding: 10px 12px; flex: 1; min-width: 0; }
.card-body h3 { margin: 0 0 2px; font-size: 1rem; }
.card-loc { margin: 0; color: var(--gris); font-size: .8rem; }
.card-tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.tag { font-size: .7rem; padding: 2px 7px; border-radius: 99px; background: #eef3ef; color: var(--bosque); }
.tag.estado-ok { background: #e3f4ea; color: var(--ok); font-weight: 600; }
.tag.estado-no { background: #f1f1f1; color: #666; font-weight: 600; }
.tag.ficticio { background: #fff4d6; color: #8a6200; }
.card-foot { display: flex; justify-content: space-between; align-items: center; }
.precio { font-weight: 700; }
.precio span { font-weight: 400; color: var(--gris); font-size: .8rem; }
.btn {
  border: 0; border-radius: 10px; padding: 8px 12px; background: var(--bosque); color: #fff;
  font-weight: 600; font-size: .85rem;
}
.btn.sec { background: #eef3ef; color: var(--bosque); }
.btn.full { width: 100%; padding: 13px; font-size: 1rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.empty { text-align: center; color: var(--gris); padding: 30px 0; }

/* Pines */
.pin {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -100%);
  background: var(--bosque); color: #fff; font-weight: 700; font-size: 12px;
  padding: 5px 9px; border-radius: 99px; white-space: nowrap; box-shadow: 0 2px 8px rgba(0,0,0,.3);
  border: 2px solid #fff; transition: transform .15s, background .2s;
}
.pin::after {
  content: ""; position: absolute; left: 50%; bottom: -7px; transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: #fff; border-bottom: 0;
}
.pin.mensual { background: #3c5a8a; }
.pin.ocupado { background: var(--ocupado); text-decoration: line-through; }
.pin.activo { transform: translate(-50%, -100%) scale(1.18); z-index: 1000; outline: 3px solid rgba(47,107,79,.35); }
.pin.pulso { animation: pulso .9s ease 2; }
@keyframes pulso { 50% { transform: translate(-50%, -100%) scale(1.35); } }
/* Etiqueta localidad · paraje/barrio bajo cada pin */
.pin-sub {
  position: absolute; left: 0; top: 0; transform: translate(-50%, 10px);
  white-space: nowrap; font-size: 10.5px; line-height: 1.2; color: var(--tinta);
  background: rgba(255,255,255,.94); border: 1px solid var(--borde); border-radius: 6px;
  padding: 2px 6px; box-shadow: 0 1px 4px rgba(0,0,0,.18); pointer-events: none;
  transition: font-size .15s;
}
.pin-sub strong { color: var(--bosque); }
.pin-sub.activo { border-color: var(--bosque-2); }
#map.zoom-lejos .pin-sub { font-size: 9.5px; padding: 1px 5px; }
#map.zoom-cerca .pin-sub { font-size: 12.5px; padding: 3px 8px; }

/* Selector de estilo de mapa */
.estilo-mapa {
  display: flex; background: #fff; border-radius: 10px; box-shadow: var(--sombra);
  padding: 3px; gap: 2px;
}
.estilo-mapa button {
  border: 0; background: transparent; border-radius: 8px; padding: 6px 9px;
  font-size: 12px; font-weight: 600; color: var(--tinta); display: flex; align-items: center; gap: 4px;
}
.estilo-mapa button[aria-pressed="true"] { background: var(--bosque); color: #fff; }
/* En satélite, la leyenda y los nombres de pueblos necesitan más contraste */
#map[data-estilo="hibrido"] .pueblo-label { background: rgba(255,255,255,.95); border-color: #fff; }

.pueblo-label {
  font-size: 11px; font-weight: 700; color: var(--bosque); background: rgba(255,255,255,.85);
  padding: 2px 6px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, 8px);
  pointer-events: none; border: 1px solid var(--borde);
}
.map-legend {
  background: #fff; padding: 6px 8px; border-radius: 8px; font-size: 11px; box-shadow: var(--sombra);
  line-height: 1.6;
}
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }

/* Panel de prueba */
.testpanel {
  position: fixed; right: 12px; bottom: 12px; z-index: 1500; background: #fff; border-radius: var(--radio);
  box-shadow: var(--sombra); border: 2px dashed #e0b84a; max-width: 240px;
  padding-bottom: env(safe-area-inset-bottom);
}
.testpanel-tab { width: 100%; background: #fff4d6; border: 0; border-radius: 12px 12px 0 0; padding: 7px 12px; font-weight: 700; text-align: left; color: #6b4d00; }
.testpanel.cerrado .testpanel-body { display: none; }
.testpanel.cerrado .testpanel-tab { border-radius: 12px; }
.testpanel-body { padding: 8px 12px 12px; font-size: .85rem; }
.testpanel-body p { margin: 0 0 8px; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 700; }
.switch input { display: none; }
.slider { width: 44px; height: 24px; background: var(--rojo); border-radius: 99px; position: relative; transition: background .2s; flex: none; }
.slider::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: transform .2s; }
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::after { transform: translateX(20px); }

.sync { margin: 8px 0 0 !important; font-size: .75rem; color: var(--gris); min-height: 1em; }
.sync.ok { color: var(--ok); font-weight: 600; }
.sync.guardando { color: #8a6200; }
.sync.error { color: var(--rojo); font-weight: 600; }
.switch input:disabled + .slider { opacity: .5; }

/* Detalle (bottom sheet) */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 2000; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 2001; background: #fff;
  border-radius: 20px 20px 0 0; max-height: 92vh; overflow-y: auto;
  box-shadow: 0 -8px 30px rgba(0,0,0,.2); animation: subir .22s ease;
  padding-bottom: env(safe-area-inset-bottom);
}
@keyframes subir { from { transform: translateY(40px); opacity: .3; } }
@media (min-width: 700px) {
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; transform: translate(-50%, -50%); width: 560px; border-radius: 20px; animation: none; }
}
.sheet-hero { height: 130px; display: grid; place-items: center; font-size: 3.4rem; color: #fff; position: relative; }
.sheet-close { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; border-radius: 50%; border: 0; background: rgba(255,255,255,.9); font-size: 1.1rem; }
.sheet-content { padding: 14px 16px 18px; }
.sheet-content h2 { margin: 0; font-size: 1.3rem; }
.sheet-content h4 { margin: 18px 0 6px; font-size: .8rem; text-transform: uppercase; letter-spacing: .6px; color: var(--gris); }
.precio-grande { font-size: 1.5rem; font-weight: 800; margin: 10px 0 0; }
.precio-grande span { font-size: .9rem; font-weight: 400; color: var(--gris); }
.grid-serv { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 0; margin: 0; list-style: none; font-size: .9rem; }
.grid-serv li::before { content: "✓ "; color: var(--ok); font-weight: 700; }
.reqs { margin: 0; padding-left: 18px; font-size: .9rem; line-height: 1.6; }
.aviso { background: #f4f1eb; border-radius: 10px; padding: 10px 12px; font-size: .85rem; margin-top: 10px; }
.aviso.no { background: #fbeaea; color: #8a2a22; }

/* Formulario de consulta */
.form { display: grid; gap: 10px; }
.form .fila { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form label { display: grid; gap: 4px; font-size: .8rem; color: var(--gris); font-weight: 600; }
.form input, .form select, .form textarea {
  font: inherit; font-size: 1rem; padding: 10px; border: 1px solid var(--borde); border-radius: 10px; background: #fff; color: var(--tinta);
}
.form .check { display: flex; align-items: center; gap: 8px; color: var(--tinta); font-weight: 400; font-size: .9rem; }
.resumen { background: #eef3ef; border-radius: 10px; padding: 10px 12px; font-size: .9rem; line-height: 1.5; }
.err { color: var(--rojo); font-size: .85rem; min-height: 1em; margin: 0; }
.msg-preview { white-space: pre-wrap; background: #dcf8c6; border-radius: 12px; padding: 12px; font-size: .9rem; line-height: 1.45; }

/* Toast */
.toast {
  position: fixed; left: 50%; top: 14px; transform: translate(-50%, -80px); z-index: 3000;
  background: var(--tinta); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: .9rem;
  transition: transform .25s; max-width: 90vw; text-align: center;
}
.toast.visible { transform: translate(-50%, 0); }
