/* =========================================================
   Pistacho en tu parcela — estilos
   Paleta: tierra cálida + verde pistacho + acento terracota
   Tipografía: Fraunces (display) + Manrope (texto)
   ========================================================= */

:root {
  --bg:        #F6F2E8;
  --bg-soft:   #EFE9DB;
  --paper:    #FFFDF7;
  --ink:       #2A2620;
  --ink-soft:  #5B5346;
  --line:      #DDD3BD;
  --line-soft: #ECE4D0;
  --brand:     #3D5631;        /* verde oliva oscuro */
  --brand-2:   #6E8A4E;        /* verde pistacho */
  --brand-3:   #B7C893;        /* verde claro */
  --accent:    #C7522A;        /* terracota */
  --accent-2:  #E6A23C;        /* mostaza */
  --good:      #3F8A4A;
  --warn:      #C58A1B;
  --bad:       #B23B2E;
  --info:      #2E6CA0;

  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;

  --shadow-1: 0 1px 2px rgba(40,30,10,.04), 0 1px 1px rgba(40,30,10,.03);
  --shadow-2: 0 4px 14px rgba(40,30,10,.06), 0 1px 2px rgba(40,30,10,.04);
  --shadow-3: 0 14px 40px rgba(40,30,10,.10), 0 4px 10px rgba(40,30,10,.05);

  --sb-w: 264px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Manrope', system-ui, -apple-system, Segoe UI, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { font-family: 'Fraunces', Georgia, serif; font-weight: 600; letter-spacing: -.01em; color: var(--ink); margin: 0; }
h1 { font-size: 28px; line-height: 1.15; }
h2 { font-size: 22px; line-height: 1.2; }
h3 { font-size: 17px; line-height: 1.3; }
small, .muted { color: var(--ink-soft); }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font: inherit; cursor: pointer; }

/* ========================== Layout ========================== */
.layout {
  display: grid;
  grid-template-columns: var(--sb-w) 1fr;
  min-height: 100vh;
}

/* ---- Sidebar (desktop) ---- */
.side {
  position: sticky; top: 0; left: 0;
  height: 100vh;
  background: linear-gradient(180deg, #3D5631 0%, #2F4327 100%);
  color: #F1ECDB;
  display: flex; flex-direction: column;
  padding: 18px 14px 14px;
  border-right: 1px solid rgba(0,0,0,.2);
  z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 18px; }
.brand__mark { width: 36px; height: 36px; color: var(--brand-3); }
.brand__title { font-family: 'Fraunces', serif; font-weight: 700; font-size: 19px; display: block; line-height: 1; }
.brand__sub { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--brand-3); }

.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; padding-right: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 10px;
  color: #E8E1CD; text-decoration: none;
  font-weight: 500; font-size: 14.5px;
  transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255,255,255,.06); }
.nav a.active {
  background: rgba(183,200,147,.18);
  color: #F8F3DE;
  box-shadow: inset 3px 0 0 var(--brand-3);
}
.nav__ico {
  width: 22px; text-align: center; opacity: .8;
  font-family: 'Fraunces', serif; font-size: 16px;
}

.side__foot { margin-top: auto; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.parcel-pill {
  display: block; font-size: 12.5px; padding: 8px 10px;
  background: rgba(255,255,255,.08); border-radius: 10px;
  color: #F1ECDB; margin-bottom: 8px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.health { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #CFC8B0; padding: 0 4px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #888; display: inline-block; }
.dot[data-state="ok"]    { background: #7BB573; box-shadow: 0 0 0 3px rgba(123,181,115,.22); }
.dot[data-state="err"]   { background: #D9695A; box-shadow: 0 0 0 3px rgba(217,105,90,.22); }
.dot[data-state="unknown"] { background: #B2A98C; }

/* ---- Top bar (móvil) ---- */
.topbar {
  display: none;
  position: sticky; top: 0; z-index: 30;
  background: var(--paper); border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  gap: 10px; align-items: center;
}
.iconbtn { background: transparent; border: 1px solid var(--line); border-radius: 10px; padding: 6px; color: var(--ink); }
.topbar__title { font-family: 'Fraunces', serif; font-weight: 600; font-size: 17px; flex: 1; }
.topbar__select { max-width: 50%; padding: 7px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); font: inherit; }

/* ---- Backdrop (móvil) ---- */
.backdrop {
  position: fixed; inset: 0; background: rgba(20,15,5,.45);
  opacity: 0; pointer-events: none; transition: opacity .2s;
  z-index: 35;
}
.backdrop.open { opacity: 1; pointer-events: auto; }

/* ---- Main view ---- */
.view {
  padding: 28px clamp(16px, 4vw, 40px) 80px;
  max-width: 1200px;
}
.view__head {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 22px; gap: 16px; flex-wrap: wrap;
}
.view__head h1 { display: flex; align-items: baseline; gap: 12px; }
.view__head h1::after {
  content: "";
  flex: 1; height: 1px; background: var(--line);
  align-self: center; margin-left: 8px; min-width: 30px;
}
.view__sub { color: var(--ink-soft); margin-top: 4px; font-size: 14.5px; }

/* ========================== Cards ========================== */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(12, 1fr); }
.col-12 { grid-column: span 12; }
.col-8  { grid-column: span 8; }
.col-6  { grid-column: span 6; }
.col-4  { grid-column: span 4; }
.col-3  { grid-column: span 3; }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 18px 18px;
  box-shadow: var(--shadow-1);
}
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card__head h2, .card__head h3 { margin: 0; }
.card__hint { font-size: 12.5px; color: var(--ink-soft); }

/* ========================== Forms ========================== */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-soft); letter-spacing: .01em; }
.field input, .field select, .field textarea {
  font: inherit; color: var(--ink);
  background: var(--paper);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(110,138,78,.18);
}
.row { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); }
.row-3 { display: grid; gap: 12px; grid-template-columns: repeat(3, 1fr); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px;
  border-radius: 10px; border: 1px solid var(--brand);
  background: var(--brand); color: #F8F3DE;
  font-weight: 600; font-size: 14px; letter-spacing: .01em;
  transition: transform .05s, background .15s, border-color .15s;
}
.btn:hover { background: #2F4327; border-color: #2F4327; }
.btn:active { transform: translateY(1px); }
.btn--ghost { background: transparent; color: var(--brand); border-color: var(--brand); }
.btn--ghost:hover { background: rgba(61,86,49,.06); }
.btn--soft   { background: var(--bg-soft); color: var(--ink); border-color: var(--line); }
.btn--soft:hover { background: #E4DCC4; }
.btn--accent { background: var(--accent); border-color: var(--accent); color: #FFF9F0; }
.btn--accent:hover { background: #A8431F; border-color: #A8431F; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn--sm { padding: 6px 10px; font-size: 13px; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

/* ========================== KPI / RAG ========================== */
.kpi { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); }
.kpi__item {
  background: var(--bg-soft); border: 1px solid var(--line-soft);
  border-radius: 12px; padding: 12px 14px;
}
.kpi__lab { font-size: 11.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-soft); }
.kpi__val { font-family: 'Fraunces', serif; font-size: 24px; font-weight: 600; margin-top: 2px; }
.kpi__sub { font-size: 12px; color: var(--ink-soft); }

.rag { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px 4px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.rag::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.rag--green  { background: #E2EFD8; color: var(--good); }
.rag--yellow { background: #FBEFC7; color: var(--warn); }
.rag--red    { background: #F7D9D3; color: var(--bad); }
.rag--gray   { background: var(--bg-soft); color: var(--ink-soft); }
.rag--blue   { background: #DCE7F0; color: var(--info); }

/* ========================== Tables ========================== */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); text-align: left; }
.table th { font-weight: 600; color: var(--ink-soft); font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }
.table tbody tr:hover { background: var(--bg-soft); }

/* ========================== Misc ========================== */
.loader { display: flex; justify-content: center; padding: 64px; }
.loader__spin {
  width: 28px; height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty {
  border: 1px dashed var(--line);
  border-radius: var(--r-md);
  padding: 28px; text-align: center; color: var(--ink-soft);
  background: var(--paper);
}

.toasts {
  position: fixed; right: 16px; bottom: 16px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
  max-width: min(380px, 90vw);
}
.toast {
  background: var(--ink); color: #F1ECDB;
  padding: 10px 14px; border-radius: 10px;
  box-shadow: var(--shadow-3);
  font-size: 14px;
  animation: toastIn .25s ease-out;
}
.toast--ok  { background: #2E5734; }
.toast--err { background: #7A2A22; }
.toast--warn{ background: #855E0F; }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.tag { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--bg-soft); color: var(--ink-soft); border: 1px solid var(--line-soft); }

.pre {
  font-family: 'JetBrains Mono', 'Menlo', monospace; font-size: 12.5px;
  background: #1F1B14; color: #E2DAC4; padding: 12px 14px; border-radius: 10px;
  overflow-x: auto; white-space: pre-wrap; word-break: break-word;
  max-height: 360px; overflow-y: auto;
}

.list { display: flex; flex-direction: column; gap: 8px; }
.list__item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  background: var(--bg-soft); border: 1px solid var(--line-soft);
}
.list__item strong { font-weight: 600; }

iframe.map {
  width: 100%; height: 460px; border: 1px solid var(--line); border-radius: 12px; background: #fff;
}

/* Mapa Leaflet grande (Catastro) */
.map-card { padding: 0; overflow: hidden; }
.map-card .card__head { padding: 14px 18px; border-bottom: 1px solid var(--line-soft); }
.leaflet-big {
  width: 100%;
  height: calc(100vh - 320px);
  min-height: 480px;
  background: #e8e4d8;
}
.leaflet-control-layers { font-family: 'Manrope', sans-serif !important; font-size: 13px !important; }
.leaflet-popup-content { font-family: 'Manrope', sans-serif; font-size: 13px; line-height: 1.5; }
.leaflet-popup-content strong { font-family: 'Fraunces', serif; font-size: 15px; }

.crit-list li, .conc-list li { margin-bottom: 4px; }

.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-soft); margin-top: 8px; }

/* ========================== Responsive ========================== */
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .side {
    position: fixed; top: 0; left: 0;
    width: min(86vw, 320px);
    transform: translateX(-105%);
    transition: transform .25s ease;
    box-shadow: var(--shadow-3);
  }
  .side.open { transform: translateX(0); }
  .topbar { display: flex; }
  .view { padding: 20px 16px 60px; }
  .row, .row-3 { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(6,1fr); }
  .col-8, .col-6, .col-4, .col-3 { grid-column: span 6; }
  h1 { font-size: 24px; }
  iframe.map { height: 360px; }
  .leaflet-big { height: 60vh; min-height: 380px; }
}

/* ========================== Print (informe) ========================== */
@media print {
  .side, .topbar, .toasts, .backdrop, .actions { display: none !important; }
  body { background: #fff; }
  .layout { grid-template-columns: 1fr; }
  .view { padding: 0; max-width: 100%; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
}
