/* ==========================================================================
   Fincas Altuzarra — hoja de estilos
   Basada en los tokens del diseño MB (papel cálido, oro envejecido, serif),
   adaptada a una app móvil de campo.
   ========================================================================== */

:root {
  --bg: #f6f3ee;
  --panel: #ffffff;
  --border: #e6e0d6;
  --text: #211e1a;
  --muted: #8d8478;
  --accent: #9a7b4a;
  --accent-hover: #826640;
  --accent-soft: #f1ebde;
  --danger: #8c2f39;
  --danger-soft: #f3e4e5;
  --success: #5f7355;
  --serif: Georgia, "Times New Roman", serif;
  --tabbar: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px; line-height: 1.4;
  overscroll-behavior-y: none;
}
body { padding-bottom: calc(var(--tabbar) + var(--safe-b)); }
body.map-mode { padding-bottom: 0; overflow: hidden; }

a { color: var(--accent); }

/* ---------- Cabecera ---------- */
.app-header {
  position: sticky; top: 0; z-index: 500;
  background: var(--panel);
  border-top: 3px solid var(--accent);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px 9px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
}
.app-header h1 {
  margin: 0; font-family: var(--serif); font-size: 18px; font-weight: 500;
  letter-spacing: .03em; text-transform: uppercase; white-space: nowrap;
}
@media (max-width: 360px) { .app-header h1 { font-size: 16px; } }
.info-btn {
  flex: 0 0 auto; border: 1px solid var(--border); background: var(--bg); color: var(--accent);
  width: 32px; height: 32px; border-radius: 50%; padding: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center; margin-left: 4px;
}
.info-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.info-btn:active { background: var(--accent-soft); }
.app-header .subtitle {
  margin: 1px 0 0; color: var(--muted); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: .13em;
}
.header-row { display: flex; align-items: center; gap: 10px; }
.header-row .totals { margin-left: auto; text-align: right; white-space: nowrap; }
.header-row .totals b { font-family: var(--serif); font-size: 16px; font-weight: 600; display: block; }
.header-row .totals span { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .1em; }

/* ---------- Buscador y filtros ---------- */
.tools { padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--border); }
.searchbox { position: relative; }
.searchbox input {
  width: 100%; padding: 11px 34px 11px 12px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
  color: var(--text); font-family: inherit; -webkit-appearance: none;
}
.searchbox input:focus { outline: none; border-color: var(--accent); background: #fff; }
.searchbox .clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: none; color: var(--muted); font-size: 20px; padding: 0 6px; cursor: pointer;
}
.chips { display: flex; gap: 7px; overflow-x: auto; margin-top: 9px; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; padding: 6px 12px; border-radius: 999px; font-size: 12.5px;
  border: 1px solid var(--border); background: var(--bg); color: var(--muted);
  cursor: pointer; white-space: nowrap; font-family: inherit;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.chip.sort { border-style: dashed; }

.result-line { padding: 8px 14px 0; color: var(--muted); font-size: 12px; display: flex; align-items: baseline; gap: 8px; }
.result-line b { color: var(--text); font-family: var(--serif); font-size: 14px; }

/* ---------- Listado ---------- */
.list { padding: 8px 10px 20px; }
.finca {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 12px; margin-bottom: 8px; display: flex; gap: 11px; align-items: flex-start;
  cursor: pointer;
}
.finca:active { background: var(--accent-soft); }
.finca .num {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent-hover);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif); font-size: 14px; font-weight: 600;
}
.finca.urb .num { background: #eae7f1; color: #5b4b7a; }
.finca .body { flex: 1; min-width: 0; }
.finca .t1 { font-family: var(--serif); font-size: 15.5px; font-weight: 600; line-height: 1.25; }
.finca .t2 { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.finca .t3 { font-size: 11.5px; color: var(--muted); margin-top: 3px; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.finca .right { flex: 0 0 auto; text-align: right; }
.finca .sup { font-family: var(--serif); font-size: 15px; font-weight: 600; white-space: nowrap; }
.finca .sup small { display: block; font-size: 10.5px; color: var(--muted); font-family: inherit; font-weight: 400; }
.finca .dist { font-size: 11px; color: var(--accent); margin-top: 3px; font-weight: 600; }

.badge {
  display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 4px;
  text-transform: uppercase; letter-spacing: .08em; font-weight: 700; vertical-align: 1px;
}
.badge.rus { background: var(--accent-soft); color: var(--accent-hover); }
.badge.urb { background: #eae7f1; color: #5b4b7a; }
.badge.warn { background: var(--danger-soft); color: var(--danger); }

.empty { text-align: center; color: var(--muted); padding: 50px 20px; }
.load-more { text-align: center; color: var(--muted); font-size: 12px; padding: 14px; }

/* ---------- Barra de pestañas ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 900;
  height: calc(var(--tabbar) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--panel); border-top: 1px solid var(--border);
  display: flex;
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; color: var(--muted); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: .1em; font-weight: 600;
}
.tabbar a.active { color: var(--accent); }
.tabbar svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; }

/* ---------- Ficha (hoja inferior) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(33,30,26,.45); z-index: 1000;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1001;
  background: var(--panel); border-radius: 16px 16px 0 0;
  max-height: 88vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  transform: translateY(100%); transition: transform .25s ease;
  padding-bottom: calc(18px + var(--safe-b));
  box-shadow: 0 -6px 28px rgba(33,30,26,.18);
}
.sheet.open { transform: translateY(0); }
.sheet .grip { width: 38px; height: 4px; background: var(--border); border-radius: 2px; margin: 9px auto 4px; }
.sheet-head { padding: 6px 16px 12px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.sheet-head .eyebrow { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .13em; }
.sheet-head h2 { margin: 3px 0 0; font-family: var(--serif); font-size: 21px; font-weight: 500; line-height: 1.2; }
.sheet-head .close { position: absolute; right: 10px; top: 4px; border: 0; background: none; font-size: 26px; color: var(--muted); padding: 4px 10px; cursor: pointer; }
.sheet-body { padding: 4px 16px 0; }

.actions { display: flex; gap: 8px; padding: 12px 16px; flex-wrap: wrap; }
.btn {
  flex: 1 1 45%; text-align: center; padding: 11px 10px; border-radius: 8px;
  background: var(--accent); color: #fff; border: 1px solid var(--accent);
  font-size: 13.5px; font-weight: 600; text-decoration: none; cursor: pointer;
  font-family: inherit; display: flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active { background: var(--accent-hover); }
.btn.secondary { background: var(--panel); color: var(--accent-hover); }
.btn.wide { flex-basis: 100%; }
.btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }

.kv { border-top: 1px solid var(--border); }
.kv div { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.kv dt { flex: 0 0 128px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; padding-top: 1px; }
.kv dd { margin: 0; flex: 1; min-width: 0; word-break: break-word; }
.kv dd.mono { font-variant-numeric: tabular-nums; letter-spacing: .03em; }
.section-title {
  font-family: var(--serif); font-size: 13px; text-transform: uppercase; letter-spacing: .12em;
  color: var(--accent-hover); margin: 18px 0 6px;
}
.quote {
  background: var(--bg); border-left: 3px solid var(--accent); border-radius: 0 6px 6px 0;
  padding: 10px 12px; font-size: 13px; color: #443f38; line-height: 1.5;
}
.notice {
  background: var(--accent-soft); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 11px; font-size: 12.5px; color: #5c4a2f; margin: 10px 0;
}
.notice.warn { background: var(--danger-soft); border-color: #e3c9cb; color: var(--danger); }

/* ---------- Mapa ---------- */
#map { position: fixed; inset: 0; bottom: calc(var(--tabbar) + var(--safe-b)); background: #2b2b2b; }
.leaflet-container { font-family: inherit; background: #2b2b2b; }
.map-top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 600;
  padding: calc(8px + env(safe-area-inset-top,0px)) 10px 8px;
  background: linear-gradient(to bottom, rgba(246,243,238,.97) 62%, rgba(246,243,238,0));
  pointer-events: none;
}
.map-top > * { pointer-events: auto; }
.gps-banner {
  background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 9px; padding: 9px 11px; box-shadow: 0 2px 10px rgba(33,30,26,.10);
  display: flex; align-items: center; gap: 10px; cursor: pointer;
}
.gps-banner.inside { border-left-color: var(--success); }
.gps-banner.off { border-left-color: var(--muted); }
.gps-banner .txt { flex: 1; min-width: 0; }
.gps-banner .lbl { font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.gps-banner .val { font-family: var(--serif); font-size: 15px; font-weight: 600; line-height: 1.25; margin-top: 1px; }
.gps-banner .sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.gps-banner .chevron { color: var(--muted); font-size: 20px; }
.map-search { margin-top: 8px; }
.map-search input {
  width: 100%; padding: 9px 11px; font-size: 16px; border: 1px solid var(--border);
  border-radius: 8px; background: rgba(255,255,255,.96); font-family: inherit;
}
.map-suggest {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  margin-top: 4px; max-height: 46vh; overflow-y: auto; box-shadow: 0 4px 14px rgba(33,30,26,.14);
}
.map-suggest div { padding: 9px 11px; border-bottom: 1px solid var(--border); font-size: 13.5px; cursor: pointer; }
.map-suggest div:last-child { border-bottom: 0; }
.map-suggest .s2 { color: var(--muted); font-size: 11.5px; }

.map-fabs { position: fixed; right: 12px; z-index: 600; bottom: calc(var(--tabbar) + var(--safe-b) + 14px); display: flex; flex-direction: column; gap: 9px; }
.fab {
  width: 46px; height: 46px; border-radius: 50%; background: var(--panel);
  border: 1px solid var(--border); box-shadow: 0 2px 10px rgba(33,30,26,.18);
  display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text);
}
.fab.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.fab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.fab.locating svg { animation: spin 1.1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.map-legend {
  position: fixed; left: 12px; z-index: 600; bottom: calc(var(--tabbar) + var(--safe-b) + 14px);
  background: rgba(255,255,255,.94); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 9px; font-size: 11px; color: var(--muted); line-height: 1.7;
}
.map-legend i { display: inline-block; width: 11px; height: 11px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

.leaflet-popup-content-wrapper { border-radius: 10px; }
.leaflet-popup-content { margin: 11px 13px; font-size: 13px; min-width: 190px; }
.pop-t { font-family: var(--serif); font-size: 15px; font-weight: 600; }
.pop-s { color: var(--muted); font-size: 12px; margin: 2px 0 7px; }
.pop-a { display: flex; gap: 6px; }
.pop-a a { flex: 1; text-align: center; padding: 7px 8px; border-radius: 6px; background: var(--accent); color: #fff; text-decoration: none; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pop-a a.sec { background: var(--panel); color: var(--accent-hover); border: 1px solid var(--border); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar) + var(--safe-b) + 74px); z-index: 1200;
  background: rgba(33,30,26,.92); color: #fff; padding: 9px 15px; border-radius: 999px;
  font-size: 12.5px; opacity: 0; transition: opacity .25s; pointer-events: none; max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; }

.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .45 } }

@media (min-width: 720px) {
  .list { max-width: 780px; margin: 0 auto; }
  .tools, .app-header, .result-line { max-width: 780px; margin-left: auto; margin-right: auto; }
  .sheet { max-width: 620px; left: 50%; transform: translate(-50%, 100%); border-radius: 16px 16px 0 0; }
  .sheet.open { transform: translate(-50%, 0); }
  .map-top { max-width: 460px; }
}
