/* Track Union - estilos */
:root {
  --brand: #4f46e5;          /* índigo */
  --brand-2: #0ea5e9;        /* azul cielo */
  --brand-dark: #4338ca;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f1f5f9;
  --card: #ffffff;
  --ok: #16a34a;
  --bad: #dc2626;
  --route: #8e44ad;
  --accent: #ff7f00;         /* puntos añadidos a mano */
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 14px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: flex; font: 14px/1.4 "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--ink); background: var(--bg); accent-color: var(--brand);
}

/* ---------- Panel lateral ---------- */
#sidebar { width: 400px; height: 100%; display: flex; flex-direction: column; background: var(--bg);
  border-right: 1px solid var(--line); z-index: 2; box-shadow: 2px 0 12px rgba(15, 23, 42, .06); }
.steps { flex: 1; overflow-y: auto; padding: 12px 12px 4px; }

.apphead { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 14px;
  color: #fff; background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%); }
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 40px; height: 40px; flex: none; filter: drop-shadow(0 2px 4px rgba(15,23,42,.25)); }
.apphead h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -.2px; }
.tagline { font-size: 12px; opacity: .85; }
.ver { font-size: 11px; font-weight: 700; color: var(--brand); background: #fff; border-radius: 999px;
  padding: 1px 7px; vertical-align: 2px; }
button.ghost { background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.35); color: #fff; white-space: nowrap; }
button.ghost:hover { background: rgba(255,255,255,.28); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 12px 10px;
  margin-bottom: 12px; box-shadow: var(--shadow); }
h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: 15px; font-weight: 700; }
.step { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font-size: 12px;
  color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand-2)); flex: none; }

.drop { display: flex; flex-direction: column; align-items: center; gap: 4px; border: 2px dashed #c7d2fe;
  border-radius: 10px; padding: 14px; text-align: center; cursor: pointer; color: var(--muted);
  background: #f8faff; transition: background .15s, border-color .15s; }
.drop:hover, .drop.over { background: #eef2ff; border-color: var(--brand); color: var(--brand-dark); }
.drop-ico { width: 26px; height: 26px; color: var(--brand); }
#km-step { margin-left: auto; }

/* Listas de tracks y trozos */
.list { list-style: none; margin: 8px 0 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 8px; }
.list li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li .meta { color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
#tracks li { cursor: pointer; transition: background .12s; }
#tracks li:hover { background: #f1f5f9; }
#tracks li.active { background: #eef2ff; box-shadow: inset 3px 0 0 var(--brand); }
#pieces li { border: 1px solid var(--line); margin-top: 4px; background: #fff; }
#pieces li:hover { border-color: #c7d2fe; }
#pieces li .num { font-weight: 700; min-width: 18px; text-align: right; color: var(--brand); }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px #fff, 0 0 0 3px rgba(0,0,0,.08); }

/* Saltos entre trozos */
.gap { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); padding: 2px 0 2px 32px; }
.gap.warn { color: var(--bad); font-weight: 600; }
.gap .gtxt { flex: 1; }
.gap .gopts { display: flex; flex: none; }
button.opt { padding: 1px 7px; font-size: 11px; font-weight: 500; color: var(--muted); border-radius: 0; }
button.opt:first-child { border-radius: 6px 0 0 6px; }
button.opt:last-child { border-radius: 0 6px 6px 0; border-left: none; }
button.opt.on { background: var(--route); border-color: var(--route); color: #fff; }

/* Selección de trozo */
.active-name { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
label.rng { display: flex; justify-content: space-between; align-items: baseline; }
input[type=range] { width: 100%; margin: 2px 0 4px; }
.info { margin: 6px 0; font-weight: 600; }
b.g { color: var(--ok); } b.r { color: var(--bad); }

/* Plegables */
details.adv { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 6px; }
details.adv summary { cursor: pointer; color: var(--brand-dark); font-weight: 600; font-size: 13px; list-style: none; user-select: none; }
details.adv summary::-webkit-details-marker { display: none; }
details.adv summary::before { content: '▸'; display: inline-block; width: 14px; transition: transform .15s; }
details.adv[open] summary::before { transform: rotate(90deg); }

/* Pie fijo con el total y la descarga */
.dock { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: #fff; border-top: 1px solid var(--line);
  box-shadow: 0 -4px 14px rgba(15, 23, 42, .06); }
.total { flex: 1; font-size: 12px; color: var(--muted); }
.hist { display: flex; gap: 3px; flex: none; }
.hist button { padding: 4px 8px; font-size: 15px; line-height: 1; }
.hist button:disabled { cursor: default; opacity: .35; }

/* Aviso de sesión guardada */
.restore { border: 1px solid #c7d2fe; background: #eef2ff; border-radius: 10px; padding: 8px 10px; margin-bottom: 10px; }
.restore .row { margin-top: 6px; }
button.big { padding: 9px 16px; font-size: 14px; font-weight: 700; border-radius: 10px; white-space: nowrap; }

/* ---------- Controles genéricos ---------- */
label { display: block; margin-top: 8px; }
label.chk { display: flex; gap: 8px; align-items: center; }
input[type=text], select, textarea { font: inherit; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; color: var(--ink); }
input[type=text] { width: 100%; padding: 6px 8px; margin-top: 3px; }
select { padding: 4px 6px; margin-left: 4px; }
#wpt-mode { margin: 3px 0 0; width: 100%; padding: 6px 8px; }
input[type=text]:focus, select:focus, textarea:focus { outline: 2px solid #c7d2fe; border-color: var(--brand); }
.mono { font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 2px; }
.hint a { color: var(--brand-dark); }
.row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }

button { font: inherit; padding: 6px 11px; border: 1px solid #cbd5e1; background: #fff; color: var(--ink);
  border-radius: 8px; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, box-shadow .12s; }
button:hover { background: #f8fafc; border-color: #94a3b8; }
button:disabled { opacity: .5; cursor: wait; }
button.primary { background: linear-gradient(135deg, var(--brand), var(--brand-dark)); color: #fff; border-color: transparent;
  box-shadow: 0 2px 8px rgba(79, 70, 229, .35); }
button.primary:hover { background: var(--brand-dark); }
button.wide { width: 100%; }
button.icon { padding: 2px 7px; font-size: 12px; border-radius: 6px; }
button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Interruptor (checkbox con class="switch") */
input.switch { appearance: none; -webkit-appearance: none; width: 32px; height: 18px; margin: 0; flex: none; border-radius: 999px;
  background: #cbd5e1; position: relative; cursor: pointer; transition: background .15s; }
input.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s; }
input.switch:checked { background: var(--brand); }
input.switch:checked::after { transform: translateX(14px); }
input.switch:focus-visible { outline: 2px solid #c7d2fe; outline-offset: 2px; }

/* ---------- Mapa y controles flotantes ---------- */
#mapwrap { flex: 1; position: relative; height: 100%; }
#map { position: absolute; inset: 0; }
#map.adding, #map.adding .leaflet-interactive { cursor: crosshair; }

.mapctl { position: absolute; top: 12px; right: 12px; z-index: 1000; width: 220px; padding: 10px 12px 12px;
  background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px); border: 1px solid rgba(226, 232, 240, .9);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(15, 23, 42, .15); }
.mapctl label { margin-top: 8px; font-size: 13px; }
.mapctl #btn-fit { margin-top: 10px; }
.ctl-title { cursor: pointer; user-select: none; display: flex; justify-content: space-between; }
.ctl-title::after { content: '▾'; transition: transform .15s; }
.mapctl.collapsed { width: auto; padding-bottom: 10px; }
.mapctl.collapsed .ctl-title { margin-bottom: 0; gap: 8px; }
.mapctl.collapsed .ctl-title::after { transform: rotate(90deg); }
.mapctl.collapsed > :not(.ctl-title) { display: none; }
.ctl-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 6px; }
.seg { display: flex; background: #f1f5f9; border-radius: 8px; padding: 2px; gap: 2px; }
.seg button { flex: 1; border: none; background: none; padding: 4px 2px; font-size: 12px; border-radius: 6px; color: var(--muted); }
.seg button.sel { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.fab { position: absolute; right: 12px; bottom: 28px; z-index: 1000; padding: 10px 16px; border: none; border-radius: 999px;
  font-weight: 700; background: #fff; color: var(--ink); box-shadow: 0 6px 20px rgba(15, 23, 42, .25); }
.fab:hover { background: #fff7ed; }
.fab.on { background: var(--accent); color: #fff; }
.addbanner { display: none; position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 1000;
  padding: 8px 14px; border-radius: 999px; background: var(--ink); color: #fff; font-size: 13px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, .3); white-space: nowrap; }
#mapwrap.adding .addbanner { display: block; }

/* Perfil de altitud (encima de la atribución del mapa, abajo a la derecha) */
.elev { position: absolute; left: 12px; right: 12px; bottom: 22px; z-index: 1000; padding: 6px 10px 8px;
  background: rgba(255, 255, 255, .95); backdrop-filter: blur(8px); border: 1px solid rgba(226, 232, 240, .9);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(15, 23, 42, .15); }
.elev-head { display: flex; align-items: center; gap: 10px; }
.elev-head .seg { flex: none; }
.elev-head .seg button { flex: none; padding: 3px 9px; }
.seg button:disabled { cursor: default; opacity: .4; }
.elev-stats { flex: 1; min-width: 0; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.elev-body { position: relative; height: 120px; margin-top: 4px; }
.elev.collapsed .elev-body { display: none; }
#elev-canvas { display: block; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
.elev-tip { position: absolute; top: 0; transform: translateX(-50%); padding: 1px 6px; border-radius: 6px; font-size: 11px;
  background: var(--ink); color: #fff; pointer-events: none; white-space: nowrap; font-variant-numeric: tabular-nums; }
/* El botón «Añadir punto» se sube para no quedar tapado por el perfil */
#mapwrap:has(#elev:not([hidden])) .fab { bottom: 196px; }
#mapwrap:has(#elev.collapsed:not([hidden])) .fab { bottom: 74px; }

/* Marcadores */
.pin { width: 22px; height: 22px; border-radius: 50%; color: #fff; font-weight: 700; text-align: center; line-height: 18px;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.5); }
.pin.a { background: var(--ok); } .pin.b { background: var(--bad); }
.pnum { background: var(--ink); color: #fff; border-radius: 9px; padding: 0 5px; font-size: 11px; font-weight: 700;
  border: 1px solid #fff; white-space: nowrap; }
.kmlbl { background: #fff; color: var(--ink); border: 1.5px solid var(--ink); border-radius: 8px; padding: 0 4px;
  font-size: 10px; font-weight: 700; line-height: 14px; white-space: nowrap; transform: translate(-50%, -50%);
  display: inline-block; box-shadow: 0 0 2px rgba(0,0,0,.4); }

/* Ventana de un punto de trayecto */
.wpt-pop b { display: block; margin-bottom: 2px; }
.wpt-pop input, .wpt-pop textarea { width: 220px; padding: 4px 6px; margin: 2px 0 6px; }
.wpt-pop textarea { height: 52px; resize: vertical; }
.wpt-pop .lbl { font-size: 11px; color: var(--muted); }
.wpt-pop button.danger { margin-top: 6px; color: var(--bad); border-color: #fecaca; }
.wpt-pop button.danger:hover { background: #fef2f2; }
.leaflet-popup-content-wrapper { border-radius: 12px; }

/* Ventana de novedades */
#whatsnew { max-width: 540px; width: calc(100% - 32px); max-height: calc(100% - 32px); border: none; border-radius: 16px;
  padding: 0; overflow: hidden; box-shadow: 0 20px 60px rgba(15, 23, 42, .35); }
/* Título y botones fijos; la lista de novedades se desplaza si no cabe */
#whatsnew[open] { display: flex; flex-direction: column; }
#whatsnew h2, #whatsnew > .row, #whatsnew > .hint { flex: none; }
.whatsnew-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 4px;
  border-bottom: 1px solid var(--line); }
#whatsnew::backdrop { background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px); }
#whatsnew h2 { margin: 0; padding: 16px 20px; font-size: 18px; color: #fff;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%); }
#whatsnew .news, #whatsnew .row, #whatsnew .hint { margin-left: 20px; margin-right: 20px; }
#whatsnew .hint { margin-bottom: 14px; }
#whatsnew h3 { margin: 14px 20px 0; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
#whatsnew h3 + .news { margin-top: 6px; }
.news { margin: 14px 0 6px; padding-left: 18px; line-height: 1.5; }
.news li { margin-bottom: 8px; }
.news li::marker { color: var(--brand); }

/* ---------- Móvil: mapa arriba, panel abajo ---------- */
@media (max-width: 760px) {
  body { flex-direction: column-reverse; }
  #sidebar { width: 100%; height: 55%; border-right: none; border-top: 1px solid var(--line); }
  #mapwrap { height: 45%; flex: none; }
  .mapctl { width: 180px; padding: 8px 10px; top: 8px; right: 8px; }
  .apphead { padding: 10px 12px; }
  .tagline { display: none; }
  .elev { left: 8px; right: 8px; padding: 4px 8px 6px; }
  .elev-body { height: 80px; }
  .elev-head .seg button { padding: 2px 6px; font-size: 11px; }
  #mapwrap:has(#elev:not([hidden])) .fab { bottom: 148px; }
  #mapwrap:has(#elev.collapsed:not([hidden])) .fab { bottom: 70px; }
  .addbanner { white-space: normal; width: calc(100% - 24px); text-align: center; border-radius: 12px; }
}
