:root {
  --bg: #111317; --panel: #1a1d23; --panel2: #22262e; --line: #2e333d;
  --text: #e6e8ec; --dim: #8b93a1; --accent: #f5a623; --accent2: #3ea6ff;
  --ok: #4cc38a; --err: #ff6b6b;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 13px/1.4 "Segoe UI", system-ui, sans-serif;
  display: flex; flex-direction: column; overflow: hidden; }
[hidden] { display: none !important; }
.spacer { flex: 1; }

button, select, input[type=text] { font: inherit; color: var(--text); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; }
button { cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled) { border-color: var(--dim); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #1a1300; font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.1); }
button.big { width: 100%; padding: 9px; font-size: 14px; }
select, input[type=text] { min-width: 0; width: 100%; }
.chk { display: flex; align-items: center; gap: 5px; color: var(--dim); white-space: nowrap; cursor: pointer; }

header { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: var(--panel);
  border-bottom: 1px solid var(--line); }
header h1 { font-size: 16px; margin: 0; color: var(--accent); }
#stats { color: var(--dim); }

main { flex: 1; display: flex; min-height: 0; }
#library { width: 330px; flex: none; }
#right { width: 390px; flex: none; }
body.hideLeft #library, body.hideRight #right { display: none; }
button.tog.off { color: var(--dim); background: transparent; }
#library, #right { overflow-y: auto; background: var(--panel); }
#library { border-right: 1px solid var(--line); padding: 0 10px 20px; }
#right { border-left: 1px solid var(--line); padding: 10px; display: flex; flex-direction: column; gap: 10px; }

/* Biblioteca */
.group h3 { position: sticky; top: 0; z-index: 2; margin: 0 -10px; padding: 9px 10px; background: var(--panel);
  border-bottom: 1px solid var(--line); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.group h3 small { color: var(--dim); font-weight: 400; }
.group h3 button { padding: 2px 8px; font-size: 12px; }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px 0; }
.card { border-radius: 8px; overflow: hidden; background: var(--panel2); cursor: pointer;
  border: 2px solid transparent; }
.card:hover { border-color: var(--line); }
.card.active { border-color: var(--accent); }
.thumb { position: relative; aspect-ratio: 16/9; background: #000; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.badge { position: absolute; padding: 1px 5px; border-radius: 4px; font-size: 11px; font-weight: 600;
  background: rgba(0,0,0,.75); }
.badge.dur { right: 4px; bottom: 4px; }
.badge.fps { left: 4px; top: 4px; }
.badge.f120 { color: var(--accent); }
.badge.f60 { color: var(--ok); }
.card .add { position: absolute; right: 4px; top: 4px; width: 26px; height: 26px; padding: 0;
  border-radius: 50%; font-size: 17px; line-height: 1; opacity: 0; background: var(--accent);
  border: 0; color: #1a1300; font-weight: 700; }
.card:hover .add { opacity: 1; }
.meta { display: flex; justify-content: space-between; padding: 4px 7px; gap: 6px; }
.meta span { color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Reproductor */
#center { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 10px; gap: 8px; }
#stage { position: relative; flex: 1; min-height: 0; background: #000; border-radius: 8px; overflow: hidden; }
#video { width: 100%; height: 100%; display: block; }
#empty, #overlay { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 12px;
  align-items: center; justify-content: center; text-align: center; padding: 20px; color: var(--dim); }
#overlay { background: rgba(0,0,0,.8); color: var(--text); }

#seqStrip { display: flex; gap: 2px; height: 14px; }
#seqStrip div { background: var(--panel2); border-radius: 3px; cursor: pointer; min-width: 3px; }
#seqStrip div:hover { background: var(--dim); }
#seqStrip div.active { background: var(--accent); }

#trimbar { padding: 6px 8px; }
#track { position: relative; height: 26px; background: var(--panel2); border-radius: 5px; cursor: pointer;
  touch-action: none; }
#sel { position: absolute; top: 0; bottom: 0; background: rgba(245,166,35,.28);
  border-top: 2px solid var(--accent); border-bottom: 2px solid var(--accent); pointer-events: none; }
#head { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: #fff;
  pointer-events: none; }
.handle { position: absolute; top: -3px; bottom: -3px; width: 12px; margin-left: -6px;
  background: var(--accent); border-radius: 3px; cursor: ew-resize; }

#controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#controls select { width: auto; }
#play { width: 40px; }
#time { font-variant-numeric: tabular-nums; min-width: 105px; text-align: center; }
#marks { color: var(--accent); font-variant-numeric: tabular-nums; }
.sep { width: 1px; height: 20px; background: var(--line); margin: 0 3px; }

#clipBar { display: flex; align-items: center; gap: 10px; }
#clipInfo { flex: 1; color: var(--dim); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#clipInfo b { color: var(--text); }

/* Paneles derecha */
.panel { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.panelHead { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.panelHead h2 { margin: 0; font-size: 14px; }
#seqTotal { color: var(--dim); }
.hint { color: var(--dim); padding: 6px 2px; }

#seqList { display: flex; flex-direction: column; gap: 4px; max-height: 34vh; overflow-y: auto; }
.seg { display: flex; align-items: center; gap: 7px; padding: 4px; border-radius: 6px; background: var(--panel);
  border: 1px solid transparent; cursor: pointer; }
.seg:hover { border-color: var(--line); }
.seg.active { border-color: var(--accent); }
.seg.over { border-top-color: var(--accent2); }
.seg .n { width: 18px; text-align: right; color: var(--dim); }
.seg img { width: 56px; height: 32px; object-fit: cover; border-radius: 4px; background: #000; }
.seg .t { flex: 1; min-width: 0; }
.seg .t div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg .t small { color: var(--dim); }
.seg .t small.cut { color: var(--accent); }
.seg button { padding: 1px 6px; }

.form { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 6px 8px; align-items: center; }
.form label { color: var(--dim); }
.form.copy .enc { display: none; }
.range { display: flex; align-items: center; gap: 8px; }
.range input { flex: 1; min-width: 0; accent-color: var(--accent); }
.range output { color: var(--dim); white-space: nowrap; }
#exportNote { margin: 8px 0; color: var(--dim); min-height: 18px; }
#exportNote .warn { color: var(--accent); }

.job { padding: 8px; border-radius: 6px; background: var(--panel); margin-bottom: 6px; }
.job .top { display: flex; align-items: center; gap: 8px; }
.job .top b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job .bar { height: 6px; background: var(--panel2); border-radius: 3px; margin: 6px 0; overflow: hidden; }
.job .bar i { display: block; height: 100%; background: var(--accent2); transition: width .4s; }
.job.done .bar i { background: var(--ok); }
.job.error .bar i, .job.cancelled .bar i { background: var(--err); }
.job small { color: var(--dim); display: block; overflow-wrap: anywhere; }
.job.error small.msg { color: var(--err); white-space: pre-wrap; }
.job button { padding: 1px 8px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--panel2);
  border: 1px solid var(--line); padding: 9px 16px; border-radius: 8px; z-index: 10; max-width: 80vw;
  box-shadow: 0 6px 24px rgba(0,0,0,.5); }
#toast.err { border-color: var(--err); }

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; }

@media (max-width: 1250px) {
  #library { width: 250px; }
  #right { width: 340px; }
  .cards { grid-template-columns: 1fr; }
}

/* Sesiones */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 18px; width: min(640px, 92vw); max-height: 85vh; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin: 0 0 12px; font-size: 16px; }
#sessList { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow-y: auto; }
.sess { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 7px;
  background: var(--panel2); border: 1px solid transparent; }
.sess.auto { border-color: var(--accent); }
.sess.current { border-color: var(--accent2); }
.sess .t { flex: 1; min-width: 0; }
.sess .t small { display: block; color: var(--dim); }
.sessSave, .sessFoot { display: flex; gap: 8px; margin-top: 12px; align-items: center; }
#sessBtn b { color: var(--accent); font-weight: 600; }

/* Datos GPS */
#hud { position: absolute; left: 18px; bottom: 16px; pointer-events: none; color: #fff;
  text-shadow: 0 1px 4px #000, 0 0 2px #000; }
#hud .spd { display: flex; align-items: baseline; gap: 8px; }
#hud .spd b { font-size: clamp(44px, 7vw, 110px); line-height: 1; font-variant-numeric: tabular-nums; }
#hud .spd span { font-size: clamp(14px, 1.6vw, 24px); }
#hRows { display: flex; gap: 16px; margin-top: 4px; font-size: clamp(12px, 1.2vw, 18px); font-weight: 600; }
#hRows span { display: block; font-size: .75em; font-weight: 400; opacity: .8; }
#hMap { position: absolute; right: 14px; bottom: 14px; width: 220px; height: 160px; pointer-events: none;
  background: rgba(0,0,0,.4); border-radius: 8px; }
#spdGraph { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; border-radius: 5px; }
input[type=number] { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 6px; padding: 3px 5px; width: 62px; }
.badge.gps { left: 4px; bottom: 4px; color: var(--accent2); }

/* Vistas: video, video + mapa 3D, mapa 3D */
#stage { display: flex; }
#vidPane, #mapPane { position: relative; flex: 1; min-width: 0; height: 100%; }
#stage.view-video #mapPane, #stage.view-map #vidPane { display: none; }
#stage.view-split #mapPane { border-left: 2px solid var(--line); }
#map3d { position: absolute; inset: 0; }
#mapMsg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 20px; color: var(--dim); background: var(--bg); z-index: 2; }
#mapMsg:empty { display: none; }
#mapCtl { position: absolute; left: 10px; top: 10px; z-index: 3; display: flex; gap: 10px; align-items: center;
  background: rgba(17,19,23,.82); padding: 5px 9px; border-radius: 7px; }
#mapCtl select { width: auto; padding: 3px 6px; }
#mapCtl .chk { color: var(--text); }
#hud { z-index: 4; }
#hMapBox { position: absolute; right: 14px; bottom: 14px; width: 260px; height: 190px; border-radius: 8px;
  overflow: hidden; pointer-events: none; background: rgba(0,0,0,.4); box-shadow: 0 2px 10px rgba(0,0,0,.5); }
#hMapBox canvas, #hMapGl { position: absolute; inset: 0; width: 100%; height: 100%; background: none; border-radius: 0; }
.mdot { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid #111;
  box-shadow: 0 0 0 2px #f5a623; }
.rider { font-size: 38px; line-height: 1; filter: drop-shadow(0 2px 3px #000); }
.rider::after { content: ""; display: block; width: 10px; height: 10px; margin: -2px auto 0; border-radius: 50%;
  background: #f5a623; border: 2px solid #fff; }
.menuWrap { position: relative; }
.menu { position: absolute; bottom: calc(100% + 6px); right: 0; z-index: 6; min-width: 250px; display: flex;
  flex-direction: column; gap: 7px; padding: 12px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.5); }
.menu .chk { color: var(--text); }
.menu hr { width: 100%; border: 0; border-top: 1px solid var(--line); margin: 2px 0; }
.menu select { width: auto; }
#hRows { flex-wrap: wrap; row-gap: 4px; }
#stage.view-split #hud { max-width: calc(50% - 36px); }
#stage.view-split #hMapBox { top: 14px; bottom: auto; width: 210px; height: 155px; }

/* Versión web (sin servidor): pantalla de inicio y partes que no aplican */
.webOnly { display: none !important; }
body.web .webOnly { display: revert !important; }
body.web #exportPanel, body.web #openExports { display: none; }
#landing { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; align-items: center;
  justify-content: center; padding: 20px; overflow-y: auto; }
#landing .box { max-width: 560px; display: flex; flex-direction: column; gap: 14px; }
#landing h1 { margin: 0; color: var(--accent); font-size: 30px; }
#landing p { margin: 0; font-size: 15px; }
#landing ul { margin: 0; padding-left: 20px; color: var(--dim); display: flex; flex-direction: column; gap: 6px; }
#landing ul b { color: var(--text); }
#landMsg { min-height: 20px; color: var(--accent); }

/* Leyenda de colores de la ruta */
#mapLegend { position: absolute; left: 10px; top: 52px; z-index: 3; background: rgba(17,19,23,.82);
  padding: 7px 10px; border-radius: 7px; display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
#mapLegend i { display: inline-block; width: 22px; height: 6px; border-radius: 3px; margin-right: 7px; vertical-align: middle; }
