:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --ink: #23201b;
  --muted: #6f685d;
  --line: #e2dccf;
  --circ: #c8551f;       /* circular */
  --lin: #1d6a86;        /* lineal */
  --sel: #23201b;
  --cap: #3b3730;
  --topbar-h: 64px;
  --panel-w: 400px;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(35, 32, 27, .16);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Barlow Condensed', 'Arial Narrow', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}

/* ---------- barra superior ---------- */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 1100;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-num {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 40px;
  line-height: 1;
  color: var(--circ);
  letter-spacing: -1px;
}
.brand h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  line-height: 1.05;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: .3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.search input {
  width: 260px;
  font: inherit;
  font-size: 14px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
}
.search input:focus { outline: 2px solid var(--lin); outline-offset: 1px; background: #fff; }

/* ---------- mapa ---------- */
.layout { position: relative; height: calc(100% - var(--topbar-h)); }
.map { position: absolute; inset: 0; background: #dfe7ea; }
.leaflet-container { font-family: var(--font); }
.tiles-terrain { filter: saturate(.45) brightness(1.02); }

/* marcador de ruta */
.rm-wrap { background: none; border: none; }
.rm {
  --c: var(--circ);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #fff;
  background: var(--c);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
  cursor: pointer;
  transition: transform .12s ease, opacity .2s ease;
}
.rm.lin { --c: var(--lin); }
.rm.notrack { background: #fff; color: var(--c); border: 2px solid var(--c); }
.rm.aprox { border-style: dashed; }
.rm:hover, .rm.is-hover { transform: scale(1.25); }
.rm.is-selected {
  transform: scale(1.35);
  background: var(--sel);
  color: #fff;
  border: 2px solid #fff;
  box-shadow: 0 0 0 3px var(--c), 0 2px 8px rgba(0, 0, 0, .4);
}
.has-selection .rm:not(.is-selected) { opacity: .5; }
.has-selection .rm:not(.is-selected):hover { opacity: 1; }

/* capitales */
.cap-wrap { background: none; border: none; }
.cap-dot {
  width: 9px; height: 9px;
  background: var(--cap);
  border: 2px solid #fff;
  transform: rotate(45deg);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .15);
}
.leaflet-tooltip.cap-label {
  background: none;
  border: none;
  box-shadow: none;
  padding: 0 0 0 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--cap);
  text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 3px #fff, 0 0 4px #fff;
}
.leaflet-tooltip.cap-label::before { display: none; }
.zoomed-in .leaflet-tooltip.cap-label { display: none; }

/* pop-up al pasar el ratón */
.leaflet-tooltip.route-tip {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 8px 11px;
  font-size: 13px;
  line-height: 1.35;
  white-space: nowrap;
}
.route-tip .tt-name { font-weight: 600; }
.route-tip .tt-num { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 4px; }
.route-tip .tt-stats { color: var(--muted); font-variant-numeric: tabular-nums; }
.route-tip .tt-hint { color: var(--muted); font-size: 11px; margin-top: 3px; }

/* marcador de fin y cursor del perfil */
.end-flag {
  width: 14px; height: 14px; border-radius: 3px;
  background: repeating-conic-gradient(#23201b 0 25%, #fff 0 50%) 0 0 / 7px 7px;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .4);
}

/* ---------- recuadro de Canarias ---------- */
.inset {
  position: absolute;
  left: 12px;
  bottom: 28px;
  width: 250px;
  height: 130px;
  border: 1px solid #b9b1a2;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  z-index: 800;
  background: #dfe7ea;
}
.inset-map { width: 100%; height: 100%; }
.inset-label {
  position: absolute;
  top: 6px; left: 8px;
  z-index: 500;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  background: rgba(255, 253, 248, .85);
  padding: 1px 6px;
  border-radius: 4px;
  pointer-events: none;
}

/* ---------- leyenda ---------- */
.legend {
  position: absolute;
  right: 12px;
  bottom: 28px;
  z-index: 800;
  background: rgba(255, 253, 248, .95);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 12px;
  font-size: 12px;
  display: grid;
  gap: 5px;
  transition: right .25s ease;
}
.legend-row { display: flex; align-items: center; gap: 8px; }
.lg-dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.15); }
.lg-circ { background: var(--circ); }
.lg-lin { background: var(--lin); }
.lg-notrack { background: #fff; border-color: var(--muted); box-shadow: none; }
.lg-aprox { background: #fff; border: 2px dashed var(--muted); box-shadow: none; }
.lg-cap { width: 9px; height: 9px; margin: 0 3px; background: var(--cap); transform: rotate(45deg); }
.legend-count { color: var(--muted); border-top: 1px solid var(--line); padding-top: 6px; margin-top: 2px; }
body.panel-open .legend { right: calc(var(--panel-w) + 12px); }

/* ---------- panel lateral ---------- */
.panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: var(--panel-w);
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 1000;
  transform: translateX(100%);
  transition: transform .25s ease;
  display: flex;
  flex-direction: column;
}
body.panel-open .panel { transform: none; }
.panel-close {
  position: absolute; top: 10px; right: 10px;
  width: 32px; height: 32px;
  border: none; border-radius: 50%;
  background: var(--bg);
  font-size: 22px; line-height: 1;
  color: var(--muted);
  cursor: pointer;
  z-index: 2;
}
.panel-close:hover { color: var(--ink); background: var(--line); }
.panel-body { overflow-y: auto; padding: 20px 22px 28px; }

.p-head { display: flex; gap: 12px; align-items: flex-start; padding-right: 34px; }
.p-num {
  flex: none;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 42px;
  line-height: .9;
  color: var(--c);
  font-variant-numeric: tabular-nums;
}
.p-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  line-height: 1.05;
  margin: 0;
  text-transform: uppercase;
}
.p-sub { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--line);
}
.chip.type { background: var(--c); color: #fff; border-color: var(--c); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 18px 0 14px; }
.stat { background: var(--bg); border-radius: 8px; padding: 10px; }
.stat-v {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 24px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stat-v small { font-size: 14px; color: var(--muted); margin-left: 2px; }
.stat-l { font-size: 11px; color: var(--muted); margin-top: 4px; text-transform: uppercase; letter-spacing: .4px; }

.p-section { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.p-section h3 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
}
.kv { display: grid; grid-template-columns: 92px 1fr; gap: 6px 10px; font-size: 13px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.rating { display: grid; grid-template-columns: 110px 1fr 38px; align-items: center; gap: 10px; font-size: 13px; margin-bottom: 8px; }
.rating-l { color: var(--muted); }
.rating-bar { display: block; height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.rating-fill { display: block; height: 100%; background: var(--c); border-radius: 4px; }
.rating-v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.profile { position: relative; margin-top: 4px; }
.profile svg { display: block; width: 100%; height: 130px; }
.profile-read {
  position: absolute; top: 0; right: 0;
  font-size: 12px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.profile .axis { font-size: 10px; fill: var(--muted); }

.notice {
  font-size: 13px;
  line-height: 1.45;
  background: #fbf3e4;
  border: 1px solid #efdcb9;
  border-radius: 8px;
  padding: 10px 12px;
  color: #6b4d1c;
}
.muted { color: var(--muted); font-size: 12px; line-height: 1.45; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
  text-decoration: none;
  cursor: pointer;
}
.btn.ghost { background: transparent; color: var(--ink); }
.btn:hover { opacity: .88; }

/* ---------- móvil ---------- */
@media (max-width: 760px) {
  :root { --topbar-h: 56px; }
  .topbar { padding: 0 12px; gap: 10px; }
  .brand-num { font-size: 30px; }
  .brand h1 { font-size: 16px; }
  .brand p { display: none; }
  .search input { width: 140px; }
  .inset { width: 160px; height: 90px; left: 8px; bottom: 22px; }
  .legend { display: none; }
  .panel {
    top: auto; left: 0; width: 100%;
    height: 62%;
    border-left: none;
    border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    transform: translateY(100%);
  }
  .panel-body { padding: 16px 16px 24px; }
}

/* versiones de track (principal + variantes) */
.versions { display: grid; gap: 8px; }
.version {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.version.is-main { border-color: var(--c); background: var(--bg); }
.v-name { font-size: 13px; font-weight: 600; text-transform: capitalize; }
.v-name .chip { text-transform: none; margin-left: 4px; background: var(--c); color: #fff; border-color: var(--c); }
.v-stats { font-size: 12px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.btn-sm { padding: 6px 10px; font-size: 12px; flex: none; }
