:root {
  --bg: #10130f;
  --panel: #191d17;
  --panel2: #21261e;
  --line: #333a2e;
  --text: #e6e9df;
  --dim: #9aa38d;
  --accent: #c8a227;
  --accent2: #7fae3a;
  --bad: #c94b3c;
  --topbar: 50px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 14px;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

/* ------------------------------------------------------------- barra sup */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar);
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px; padding-top: env(safe-area-inset-top);
  background: var(--panel); border-bottom: 1px solid var(--line);
  z-index: 1200;
}
button.tb {
  width: 36px; height: 34px; flex: 0 0 36px; padding: 0;
  font-size: 17px; line-height: 1;
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
button.tb:hover { background: #2b3126; }
#btnPanel { display: none; }

#searchWrap { position: relative; flex: 1; max-width: 460px; display: flex; gap: 6px; }
#search {
  flex: 1; min-width: 0; height: 34px;
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 0 10px;
  font-family: var(--font); font-size: 14px;
}
#search:focus { outline: 1px solid var(--accent2); }
#search::placeholder { color: #6f7663; }

#searchResults {
  display: none; position: absolute; top: 40px; left: 0; right: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  overflow: hidden; box-shadow: 0 10px 28px #0008; z-index: 20;
  max-height: 60vh; overflow-y: auto;
}
#searchResults.on { display: block; }
.sr { padding: 8px 11px; cursor: pointer; border-bottom: 1px solid #262c20; }
.sr:last-child { border-bottom: 0; }
.sr:hover { background: var(--panel2); }
.sr b { display: block; font-size: 13.5px; font-weight: 600; }
.sr span { display: block; font-size: 11px; color: var(--dim); margin-top: 1px; }
.sr-empty { padding: 10px 11px; font-size: 12.5px; color: var(--dim); }

/* ----------------------------------------------------------------- marc */
#app { display: flex; height: 100vh; padding-top: var(--topbar); }

/* ------------------------------------------------------------ barra izq */
#side {
  width: 320px; flex: 0 0 320px;
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow: hidden;
}

#brand { padding: 11px 14px 9px; border-bottom: 1px solid var(--line); }
#brand h1 { margin: 0; font-size: 15.5px; font-weight: 650; letter-spacing: .01em; }
#brand .sub { color: var(--dim); font-size: 11.5px; margin-top: 3px; line-height: 1.35; }

#tabs { display: flex; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.tab {
  flex: 1; padding: 9px 4px; background: none; border: 0;
  border-bottom: 2px solid transparent;
  color: var(--dim); font-family: var(--font); font-size: 12.5px; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.on { color: var(--text); border-bottom-color: var(--accent); }

.pane { display: none; padding: 12px 14px 24px; overflow-y: auto; flex: 1;
        -webkit-overflow-scrolling: touch; }
.pane.on { display: block; }

.grp { margin-bottom: 16px; }
.grp > label.h {
  display: block; font-size: 11px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--dim); margin-bottom: 6px;
}

select, button, input[type=text] {
  font-family: var(--font); font-size: 13px;
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 8px; width: 100%;
}
select:focus, button:focus { outline: 1px solid var(--accent2); }
button { cursor: pointer; }
button:hover { background: #2b3126; }
button.primary { background: #33421f; border-color: #4c6330; }
button.primary:hover { background: #3d4f26; }

.row { display: flex; gap: 6px; }
.row > * { flex: 1; }

input[type=range] { width: 100%; accent-color: var(--accent); height: 26px; }

.check { display: flex; align-items: center; gap: 8px; margin: 7px 0; cursor: pointer; }
.check input { accent-color: var(--accent2); width: 16px; height: 16px; }
.check span { font-size: 12.5px; }

#dateLabel {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12px; color: var(--dim); margin-bottom: 4px;
}
#dateLabel b { color: var(--text); font-size: 13.5px; font-weight: 600; }
#dateLabel .tag {
  font-size: 10.5px; padding: 1px 6px; border-radius: 20px;
  border: 1px solid var(--line); color: var(--dim);
}
#dateLabel .tag.fut { color: #7fb0d8; border-color: #35505f; }

#legendBar { height: 12px; border-radius: 3px; border: 1px solid var(--line); }
#legendTicks {
  display: flex; justify-content: space-between;
  font-size: 10.5px; color: var(--dim); margin-top: 3px;
}
#legendNote { font-size: 11px; color: var(--dim); margin-top: 6px; line-height: 1.4; }

#status {
  padding: 8px 14px; border-top: 1px solid var(--line);
  font-size: 11px; color: var(--dim); line-height: 1.45; flex: 0 0 auto;
}
#status b { color: var(--accent2); font-weight: 600; }
#status.err b { color: var(--bad); }

/* ---------------------------------------------------------------- mapa */
#mapwrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: #0c0e0b; }

.leaflet-container { background: #0c0e0b; font-family: var(--font); }
.leaflet-control-attribution {
  background: rgba(16,19,15,.8) !important; color: var(--dim) !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--dim) !important; }

/* lectura del punt sota el cursor */
#hover {
  display: none; position: absolute; z-index: 800; pointer-events: none;
  background: rgba(16,19,15,.94); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; min-width: 168px;
  box-shadow: 0 8px 22px #0009; font-size: 11.5px; line-height: 1.5;
}
#hover.on { display: block; }
.hv-top { font-size: 12.5px; margin-bottom: 3px; }
.hv-top b { font-size: 16px; font-weight: 700; margin-right: 5px; }
.hv-row { display: flex; justify-content: space-between; gap: 12px; color: var(--dim); }
.hv-row span:last-child { color: var(--text); }
.hv-zone { margin-top: 4px; padding-top: 4px; border-top: 1px solid #2a3024; color: var(--dim); }

#loading {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: rgba(16,19,15,.85); z-index: 900; text-align: center;
}
#loading.on { display: flex; }
#loading .box { max-width: 340px; padding: 20px; }
#loading .bar { height: 4px; background: var(--panel2); border-radius: 3px;
                overflow: hidden; margin-top: 12px; }
#loading .bar i { display: block; height: 100%; width: 0; background: var(--accent2);
                  transition: width .3s; }
#loading p { color: var(--dim); font-size: 12.5px; margin: 8px 0 0; }

/* ------------------------------------------------------- panel derecho */
#detail {
  width: 400px; flex: 0 0 400px;
  background: var(--panel); border-left: 1px solid var(--line);
  overflow-y: auto; display: none; -webkit-overflow-scrolling: touch;
}
#detail.on { display: block; }

#detail header {
  padding: 12px 40px 12px 14px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--panel); z-index: 5;
}
#detail header h2 { margin: 0; font-size: 15px; font-weight: 640; }
#detail header .meta { color: var(--dim); font-size: 11.5px; margin-top: 3px; }
#detail header button.x {
  position: absolute; top: 10px; right: 10px; width: 30px; height: 30px;
  padding: 0; line-height: 1; font-size: 17px;
}

.sec { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.sec h3 {
  margin: 0 0 8px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--dim); font-weight: 600;
}

.kv { display: flex; justify-content: space-between; gap: 10px;
      font-size: 12.5px; padding: 2.5px 0; }
.kv span:first-child { color: var(--dim); flex: 0 0 auto; }
.kv span:last-child { text-align: right; }

.aspbar { display: flex; height: 16px; border-radius: 4px; overflow: hidden; margin: 6px 0 4px; }
.aspbar i { display: block; height: 100%; }
.asplegend { display: flex; gap: 10px; font-size: 10.5px; color: var(--dim); flex-wrap: wrap; }
.asplegend b { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 3px; }

.advice {
  background: var(--panel2); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: 5px;
  padding: 9px 11px; font-size: 12.5px; line-height: 1.5;
}
.advice.obaga { border-left-color: #5b93c4; }
.advice.solana { border-left-color: #d98b31; }

canvas.chart { width: 100%; display: block; border-radius: 4px; }
.chartlegend { display: flex; gap: 12px; font-size: 10.5px; color: var(--dim);
               margin-top: 5px; flex-wrap: wrap; }
.chartlegend b { display: inline-block; width: 9px; height: 3px; margin-right: 4px;
                 vertical-align: middle; }

/* ranking de especies dentro del detalle */
.sp { border-bottom: 1px solid #262c20; padding: 8px 0; }
.sp:last-child { border-bottom: 0; }
.sp .top { display: flex; align-items: baseline; gap: 8px; cursor: pointer; }
.sp .nm { font-size: 13px; font-weight: 600; flex: 1; }
.sp .nm em { font-style: normal; color: var(--dim); font-weight: 400; font-size: 11px; }
.sp .pc { font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; }
.sp .bar { height: 5px; background: #262c20; border-radius: 3px; margin-top: 5px; overflow: hidden; }
.sp .bar i { display: block; height: 100%; }
.sp .why { font-size: 11.5px; color: var(--dim); margin-top: 4px; line-height: 1.45; }
.sp .why b { color: #d9b64a; font-weight: 600; }
.sp .det { display: none; margin-top: 7px; }
.sp.open .det { display: block; }
.sp .det .tip {
  font-size: 11.5px; line-height: 1.5; color: #c8cfbb;
  background: var(--panel2); border-radius: 5px; padding: 7px 9px; margin-bottom: 6px;
}
.sp .det .sci { font-size: 10.5px; color: var(--dim); font-style: italic; margin-bottom: 6px; }
.fact { display: flex; align-items: center; gap: 6px; font-size: 10.5px; padding: 1.5px 0; }
.fact .n { width: 66px; color: var(--dim); }
.fact .b { flex: 1; height: 4px; background: #262c20; border-radius: 2px; overflow: hidden; }
.fact .b i { display: block; height: 100%; }
.fact .v { width: 34px; text-align: right; font-variant-numeric: tabular-nums; color: var(--dim); }

.rt { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 12.5px; }
.rt .rk { flex: 0 0 8px; height: 8px; border-radius: 2px; }
.rt .rn { flex: 1; color: var(--dim); }
.rt .rv { font-weight: 640; font-variant-numeric: tabular-nums; }
.rt .rt2 { flex: 0 0 62px; text-align: right; color: var(--dim);
           font-variant-numeric: tabular-nums; }

.pointbox { font-size: 12.5px; line-height: 1.5; }
.pointbox .big { font-size: 15px; font-weight: 650; }

.note { font-size: 11px; color: var(--dim); line-height: 1.5; }
.note a { color: var(--accent2); }
.zonepop { font-size: 12px; }
.zonepop b { font-size: 13px; }

/* --------------------------------------------------- millors zones */
.comrow { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 12px; }
.comrow .cn { flex: 0 0 96px; color: var(--text); overflow: hidden;
              text-overflow: ellipsis; white-space: nowrap; }
.comrow .cb { flex: 1; height: 6px; background: #262c20; border-radius: 3px; overflow: hidden; }
.comrow .cb i { display: block; height: 100%; }
.comrow .cv { flex: 0 0 34px; text-align: right; color: var(--dim);
              font-variant-numeric: tabular-nums; }

.toprow {
  display: flex; align-items: center; gap: 9px; padding: 7px 0;
  border-bottom: 1px solid #262c20; cursor: pointer;
}
.toprow:hover { background: #1e2319; }
.toprow .rk { flex: 0 0 20px; text-align: right; color: #6f7663;
              font-size: 11px; font-variant-numeric: tabular-nums; }
.toprow .tn { flex: 1; min-width: 0; }
.toprow .tn b { display: block; font-size: 12.5px; font-weight: 600; }
.toprow .tn em { display: block; font-style: normal; font-size: 10.5px; color: var(--dim); }
.toprow .tv { flex: 0 0 40px; text-align: right; font-size: 13.5px; font-weight: 650;
              font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- guia */
.rules { margin: 0; padding-left: 17px; font-size: 12px; line-height: 1.55; color: #c8cfbb; }
.rules li { margin-bottom: 5px; }
.rules b { color: var(--text); }

.gcard { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px;
         overflow: hidden; background: var(--panel2); }
.ghead { display: flex; align-items: center; gap: 10px; padding: 8px 10px; cursor: pointer; }
.ghead:hover { background: #262c20; }
.gpic { flex: 0 0 42px; height: 42px; }
.gpic svg { width: 42px; height: 42px; display: block; }
.gname { flex: 1; min-width: 0; }
.gname b { display: block; font-size: 13px; font-weight: 640; }
.gname em { display: block; font-style: normal; font-size: 11px; color: var(--dim); }
.gname i { display: block; font-size: 10px; color: #6f7663; font-style: italic;
           overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gchev { color: var(--dim); font-size: 12px; transition: transform .18s; }
.gcard.open .gchev { transform: rotate(180deg); }

.gbody { display: none; padding: 4px 12px 12px; font-size: 12px; line-height: 1.55; }
.gcard.open .gbody { display: block; }
.gbody h4 { margin: 12px 0 5px; font-size: 10.5px; text-transform: uppercase;
            letter-spacing: .07em; color: var(--dim); font-weight: 600; }
.gbody h4.warn { color: #d98b31; }
.gbody ul { margin: 0; padding-left: 16px; }
.gbody li { margin-bottom: 4px; color: #c8cfbb; }
.gbody p { margin: 0 0 6px; color: #c8cfbb; }
.gbody p.hab { color: var(--dim); font-size: 11.5px; }
.gbody b { color: var(--text); }
.conf { border-left: 2px solid #a4562d; padding: 5px 0 5px 9px; margin-bottom: 7px; }
.conf .ct { display: block; font-size: 12px; color: #e5b06a; margin-bottom: 2px; }
.conf span b { color: var(--text); }
.conf span { color: #c8cfbb; }
.grow { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.gmap { width: auto; flex: 1; }
.gwiki { flex: 0 0 auto; font-size: 12px; color: var(--accent2); text-decoration: none;
         padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; }
.gwiki:hover { background: #2b3126; }

/* ------------------------------------------------------------- movil */
@media (max-width: 1180px) {
  #detail { width: 340px; flex-basis: 340px; }
  #side { width: 290px; flex-basis: 290px; }
}

@media (max-width: 860px) {
  #btnPanel { display: block; }

  #app { display: block; height: calc(100vh - var(--topbar)); }
  #mapwrap { position: absolute; inset: var(--topbar) 0 0 0; }

  /* el panell de controls es un calaix que puja des de baix */
  #side {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto; flex: none;
    max-height: 76vh; z-index: 1100;
    border-right: 0; border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -10px 30px #0009;
    transform: translateY(calc(100% + 20px));
    transition: transform .25s ease;
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.panel-open #side { transform: translateY(0); }
  #brand { display: none; }
  #side::before {
    content: ""; display: block; width: 38px; height: 4px; border-radius: 3px;
    background: #3d4534; margin: 8px auto 2px; flex: 0 0 auto;
  }
  .pane { padding-bottom: 18px; }

  /* el detall ocupa tota la pantalla */
  #detail {
    position: fixed; inset: var(--topbar) 0 0 0; width: auto; flex: none;
    z-index: 1150; border-left: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* sense cursor no hi ha hover: la lectura es per toc, dins del detall */
  #hover { display: none !important; }

  /* objectius de toc mes grans */
  select, button, input[type=text] { font-size: 15px; padding: 10px; }
  .tab { padding: 11px 4px; font-size: 13px; }
  .toprow { padding: 10px 0; }
  .ghead { padding: 11px 10px; }
  .leaflet-control-zoom { display: none; }
}

@media (max-width: 420px) {
  #searchWrap { max-width: none; }
  #topbar { gap: 6px; padding: 0 7px; }
}
