:root { --accent: #1565c0; --line: #e6e8eb; --muted: #78838c; --bad: #c62828; --ok: #2a8f2a; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; font-size: 13px; color: #212121; }
[hidden] { display: none !important; }

#tabbar { position: fixed; top: 0; left: 0; right: 0; height: 40px; background: #20242b; display: flex; z-index: 3000; box-shadow: 0 1px 4px rgba(0, 0, 0, .25); }
#tabbar .tab { height: 40px; padding: 0 22px; background: transparent; color: #aeb4bd; border: none; border-bottom: 3px solid transparent; border-radius: 0; font-size: 14px; font-weight: 500; margin: 0; }
#tabbar .tab:hover { color: #fff; background: rgba(255, 255, 255, .06); }
#tabbar .tab.active { color: #fff; border-bottom-color: var(--accent); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
#analysis { position: fixed; top: 40px; left: 0; right: 0; bottom: 0; background: #fafbfc; z-index: 2500; }
.analysis-empty { color: #9aa1a9; text-align: center; padding: 60px 0; font-size: 14px; }

#sidebar { position: absolute; top: 40px; left: 0; bottom: 0; width: 360px; overflow-y: auto; padding: 14px; background: #fafbfc; border-right: 1px solid var(--line); z-index: 1000; }
#map { position: absolute; top: 40px; left: 360px; right: 0; bottom: 0; }

h1 { font-size: 17px; margin: 0 0 12px; padding-bottom: 10px; border-bottom: 2px solid var(--accent); }
h2 { font-size: 13px; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
section { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.step { display: inline-flex; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 11px; align-items: center; justify-content: center; }
.hint { color: #555; line-height: 1.4; margin: 0 0 8px; }
.muted { color: var(--muted); margin-left: 6px; }
code { background: #eef1f4; padding: 1px 4px; border-radius: 4px; }
.sep { height: 1px; background: var(--line); margin: 12px 0; }

button, .file-btn { font: inherit; border: 1px solid var(--accent); color: var(--accent); background: #fff; padding: 6px 12px; border-radius: 6px; cursor: pointer; }
button:hover, .file-btn:hover { background: rgba(21, 101, 192, .08); }
button.primary { display: block; width: 100%; margin-top: 10px; background: var(--accent); color: #fff; font-weight: 600; padding: 8px; }
button.primary:hover { background: #0d4f9a; }
button:disabled { opacity: .5; cursor: not-allowed; }
button + button { margin-top: 6px; }
#btn-pick-reset { display: block; width: 100%; margin-top: 6px; }
.file-btn { display: inline-block; }
input[type=text], select { width: 100%; font: inherit; padding: 6px 8px; border: 1px solid #cfd8dc; border-radius: 6px; margin-bottom: 6px; background: #fff; }
input[type=number] { font: inherit; width: 70px; padding: 3px 6px; border: 1px solid #cfd8dc; border-radius: 6px; }
.check { display: flex; align-items: center; gap: 6px; margin: 6px 0; cursor: pointer; }
.status { min-height: 18px; margin-top: 8px; color: var(--muted); line-height: 1.4; }
.status.error { color: var(--bad); }
.status.busy::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 6px; border: 2px solid var(--accent); border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .25); margin-right: 4px; }
.legend { display: flex; gap: 14px; margin: 6px 0 8px; color: #444; }

.level-block { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.level-title { font-weight: 600; margin-bottom: 4px; }
.level-title small { color: var(--muted); font-weight: 400; }
.metrics { color: var(--muted); font-size: 12px; margin-top: 2px; }

.comp-row { display: flex; justify-content: space-between; gap: 8px; padding: 4px 6px; border-radius: 6px; cursor: pointer; }
.comp-row:hover { background: #eef3f8; }
.comp-status.ok { color: var(--ok); font-weight: 600; }
.comp-status.pending { color: #999; }

.width-row { display: flex; align-items: center; gap: 6px; padding: 3px 4px; border-radius: 6px; }
.width-row:hover { background: #eef3f8; }
.width-row label { display: flex; align-items: center; gap: 6px; cursor: pointer; flex: 1; }
.width-row .stats { color: var(--muted); font-size: 11px; white-space: nowrap; }
.green-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; color: #444; }


.export-block { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.export-block .btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.export-block .btns button { margin: 0; padding: 4px 10px; font-size: 12px; }
#sec-processed .file-btn { margin-bottom: 0; }
.file-btn.primary-file { background: var(--accent); color: #fff; font-weight: 600; }
.file-btn.primary-file:hover { background: #0d4f9a; }
.levels-name { font-weight: 600; color: var(--accent); margin: -2px 0 8px; word-break: break-word; }

/* ---- menus laterales ocultables (Mapa y Analisis) ---- */
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 12px; padding-bottom: 10px; border-bottom: 2px solid var(--accent); }
.side-head h1 { margin: 0; padding: 0; border: 0; }
.menu-hide { margin: 0; padding: 2px 10px; font-size: 16px; line-height: 1.2; }
.menu-show { display: none; position: fixed; top: 48px; left: 8px; z-index: 1100; margin: 0; background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .25); }
#show-analysis-menu { position: absolute; top: 8px; z-index: 5; }
body.hide-map-menu #sidebar { display: none; }
body.hide-map-menu #map { left: 0; }
body.hide-map-menu #show-map-menu { display: block; }
body.hide-map-menu .leaflet-top.leaflet-left { margin-top: 44px; }  /* deja lugar al boton "Menu" */
body.hide-analysis-menu #analysis-side { display: none; }
body.hide-analysis-menu #analysis-main { left: 0; }
body.hide-analysis-menu #show-analysis-menu { display: block; }
body.hide-analysis-menu #analysis-main { padding-top: 52px; }

/* ---- pestaña Analisis ---- */
#analysis-side { position: absolute; top: 0; left: 0; bottom: 0; width: 360px; overflow-y: auto; padding: 14px; background: #fafbfc; border-right: 1px solid var(--line); }
#analysis-main { position: absolute; top: 0; left: 360px; right: 0; bottom: 0; overflow-y: auto; padding: 24px 20px; }
.a-sec { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; }
.a-sec > summary { cursor: pointer; font-weight: 600; margin: -2px 0 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.a-sec:not([open]) > summary { margin-bottom: 0; }
.a-range { margin-bottom: 6px; }
.a-hist { display: block; width: 100%; height: 70px; }
.a-slider { margin: 18px 10px 14px; }
.a-slider.noUi-target { height: 8px; background: #e0e0e0; border-radius: 4px; border: none; box-shadow: none; }
.a-slider .noUi-connect { background: var(--accent); }
.a-slider .noUi-handle { width: 16px; height: 16px; border-radius: 50%; top: -5px; right: -8px; border: 2px solid var(--accent); background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .35); cursor: pointer; }
.a-slider .noUi-handle::before, .a-slider .noUi-handle::after { display: none; }
.a-toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; margin: 4px 0; user-select: none; }
.a-dot { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--accent); background: #fff; transition: background .15s ease; flex-shrink: 0; }
.a-dot.a-dot-on { background: var(--accent); }
.a-goto { display: block; width: 100%; margin-top: 8px; }
.a-card { background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 24px; }
.a-title { padding: 12px 16px 4px; font-weight: 600; font-size: 13px; color: #333; text-align: center; }
.a-chart { display: flex; align-items: flex-start; }
.a-axis { display: block; flex-shrink: 0; }
.a-scroll { overflow-x: auto; flex: 1; min-width: 0; }
.a-plot { display: block; }
.a-xlabel { text-align: center; font-size: 11px; color: var(--muted); padding: 2px 0 12px; }
.a-nodata { padding: 40px; color: #9aa1a9; text-align: center; }

/* ---- color del camino ---- */
.color-row { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; color: #444; }
input[type=color] { width: 34px; height: 26px; padding: 0; border: 1px solid #cfd8dc; border-radius: 6px; background: #fff; cursor: pointer; }

/* ---- sub-pestañas del menu del mapa: Importar / Visualizacion / Exportar ---- */
.subtabs { display: flex; gap: 4px; margin: 0 0 12px; border-bottom: 1px solid var(--line); }
.subtab { flex: 1; margin: 0; padding: 7px 4px; border: none; border-bottom: 3px solid transparent; border-radius: 0; background: transparent; color: var(--muted); font-weight: 600; }
.subtab:hover { background: rgba(21, 101, 192, .06); color: #212121; }
.subtab.active { color: var(--accent); border-bottom-color: var(--accent); }
.sub-label { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: #9e9e9e; margin: 12px 0 4px; }
.export-fmt { display: flex; flex-direction: column; gap: 4px; margin: 8px 0 4px; }
.export-fmt label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.export-block select { margin-bottom: 0; }

/* ---- tramos de cada camino (Visualizacion), plegables ---- */
.tramos { margin: 4px 0 2px; }
.tramos > summary { cursor: pointer; color: #444; font-weight: 600; padding: 2px 0; }

/* ---- pestaña Fusionar ---- */
button.wide { display: block; width: 100%; }
button.wide.active { background: var(--accent); color: #fff; }
kbd { font: 11px/1 ui-monospace, monospace; padding: 1px 4px; border: 1px solid #cfd8dc; border-radius: 3px; background: #fff; }
#merge-huecos { margin-top: 8px; }
.merge-none { margin: 0; }
.merge-sub { font-size: 13px; margin: 14px 0 6px; }
.hueco-row { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; margin-bottom: 6px; }
.hueco-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; cursor: pointer; }
.hueco-head small { color: var(--muted); }
.hueco-head button { margin: 0; padding: 0 8px; line-height: 20px; }
.hueco-row select { margin: 6px 0 0; }
.hueco-row.pending { border-style: dashed; color: var(--muted); }
#map.picking-cuts { cursor: crosshair; }
.merge-avisos { margin: 6px 0 0; padding-left: 18px; color: #8a6d00; }
.export-block input[type=text] { margin: 6px 0 0; }

/* ---- "?" con una explicacion que aparece al pasar el mouse (ej. "Extremos") ---- */
#sec-picker, #sec-fusion, #sec-fix, #sec-caminos, #sec-shapes, #sec-map, #sec-export, #sec-saved { position: relative; }
.help-icon { display: inline-flex; width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid var(--accent); color: var(--accent); font-size: 10px; font-weight: 700; align-items: center; justify-content: center; cursor: help; }
.help-icon:hover, .help-icon:focus { background: var(--accent); color: #fff; outline: none; }
.help-pop { position: absolute; top: 38px; left: 10px; right: 10px; z-index: 20; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px 4px; box-shadow: 0 4px 14px rgba(0, 0, 0, .18); }

/* ---- Visualizacion: secciones plegables e interruptores ---- */
.fold { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 6px; }
.fold > summary { cursor: pointer; font-weight: 600; padding: 4px 0; color: #333; }
.fold > summary small { font-weight: 400; }
.switch-row { display: flex; align-items: center; gap: 8px; padding: 4px 4px; border-radius: 6px; cursor: pointer; }
.switch-row:hover { background: #eef3f8; }
.switch-row .switch-label { flex: 1; min-width: 0; }
.switch-row .metrics { margin: 0; white-space: nowrap; }
input.switch { appearance: none; -webkit-appearance: none; flex-shrink: 0; width: 30px; height: 17px; margin: 0; border-radius: 9px; background: #cfd8dc; position: relative; cursor: pointer; transition: background .15s; }
input.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: transform .15s; }
input.switch:checked { background: var(--accent); }
input.switch:checked::after { transform: translateX(13px); }
input.switch:disabled { opacity: .5; cursor: wait; }

/* ---- Caminos con ancho: un desplegable por camino, con su histograma ---- */
.camino-fold > summary { display: flex; align-items: center; gap: 8px; }
.camino-fold > summary::before { content: "▶"; font-size: 10px; }
.camino-fold[open] > summary::before { content: "▼"; }
.camino-fold > summary { list-style: none; }
.camino-fold > summary::-webkit-details-marker { display: none; }
.camino-fold .camino-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.camino-fold .camino-body { padding: 4px 0 8px; }
/* Visualizacion · Caminos: fila de un nivel sin ancho (sin flecha: se alinea con las que la tienen) */
.camino-row { display: flex; align-items: center; gap: 8px; padding: 4px 0 4px 18px; font-weight: 600; color: #333; }
.camino-row .camino-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.camino-meta { display: block; font-weight: 400; overflow: hidden; text-overflow: ellipsis; }
/* Visualizacion · Shapes: titulo en negro si la carpeta tiene algun camino prendido, gris claro si no */
.fold.shapes-fold > summary { color: #b0b6bc; }
.fold.shapes-fold.on > summary { color: #111; }
.field-label { display: block; margin: 6px 0 2px; font-size: 12px; color: var(--muted); }
.width-hist { padding-bottom: 6px; margin-bottom: 6px; border-bottom: 1px solid var(--line); }
canvas[data-hist] { display: block; width: 100%; height: 60px; cursor: crosshair; }
.width-hist .a-slider { margin: 12px 8px 8px; }
.wh-labels { display: flex; justify-content: space-between; gap: 6px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.hist-tip { display: none; position: fixed; z-index: 4000; pointer-events: none; background: #20242b; color: #fff; font-size: 11px; line-height: 1.35; padding: 4px 8px; border-radius: 6px; }

/* ---- grafico de Analisis: zoom y punto marcado desde el mapa ---- */
.a-zoombar { display: flex; align-items: center; gap: 6px; padding: 2px 16px 6px; }
.a-zoombar button { margin: 0; padding: 1px 10px; font-size: 13px; line-height: 20px; }
.a-zoomlbl { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; min-width: 36px; }
.a-zoomhint { margin-left: auto; color: #9aa1a9; font-size: 11px; }
.a-focus { animation: a-pulse 1s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes a-pulse { 50% { transform: scale(1.5); opacity: .5; } }

/* menu de Analisis: una tarjeta por camino, encabezado con su nombre e interruptor */
.a-sec.camino { padding: 0; }
.camino-head { display: flex; align-items: center; gap: 8px; padding: 7px 10px; font-weight: 600; }
.camino-head .camino-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.camino.is-open .camino-head { border-bottom: 1px solid var(--line); }
.a-sec.camino .camino-body { padding: 8px 12px 10px; }

/* ---- Fusionar: edicion de vertices ---- */
.edit-zone { margin-top: 8px; padding: 8px; border: 1px solid #1565c0; border-radius: 8px; background: #f3f7fc; }
.edit-info { color: #333; font-size: 12px; line-height: 1.4; margin-bottom: 6px; }
.edit-btns { display: flex; gap: 6px; margin-bottom: 6px; }
.edit-btns button { flex: 1; margin: 0; padding: 4px 6px; }
.edit-btns button.active { background: var(--accent); color: #fff; }
.edit-summary { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 6px; color: var(--muted); font-size: 12px; }
.edit-summary button { margin: 0; padding: 2px 8px; font-size: 12px; }
#map.moving-vertex { cursor: crosshair; }

/* ---- Fusionar: union directa (puntos dibujados por banco) ---- */
.direct-row { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; }
.direct-row span { flex: 1; }
.direct-row button { margin: 0; padding: 1px 8px; font-size: 12px; }
.direct-row button.active { background: var(--accent); color: #fff; }

/* ---- menu del mapa: titulo y pestañas fijos arriba al desplazar ---- */
.side-top { position: sticky; top: -14px; z-index: 50; margin: -14px -14px 12px; padding: 14px 14px 0; background: #fafbfc; }
.side-top .subtabs { margin-bottom: 0; }

/* ---- mapa base: al lado de los botones de zoom ---- */
.leaflet-top.leaflet-left { display: flex; align-items: flex-start; }
.basemap-ctl { display: flex; background: #fff; }
.basemap-ctl button { margin: 0; border: none; border-right: 1px solid #ccc; border-radius: 0; padding: 0 10px; height: 30px; font-size: 12px; color: #333; background: #fff; cursor: pointer; }
.basemap-ctl button:last-child { border-right: none; }
.basemap-ctl button:hover { background: #f4f4f4; }
.basemap-ctl button.active { background: var(--accent); color: #fff; }
.sep.thin { margin: 4px 0; }
button.danger { border-color: var(--bad); color: var(--bad); }
button.danger:hover { background: rgba(198, 40, 40, .08); }
/* botones chicos de borrar al final de una fila de Guardados (un nivel, las shapes de una embarcacion) */
button.mini { flex-shrink: 0; margin: 0; padding: 1px 8px; font-size: 12px; font-weight: 400; }
.switch-row input:disabled + .switch-label { color: var(--muted); }
#btn-clear-history { display: block; width: 100%; margin-top: 8px; }
.saved-job { display: flex; align-items: center; gap: 6px; padding: 6px 0; }
.saved-job .info { flex: 1; min-width: 0; }
.saved-job .info b { display: block; word-break: break-word; }
.saved-job.current .info b { color: var(--accent); }
.saved-job button { margin: 0; padding: 3px 8px; font-size: 12px; }
/* Guardados: cada carpeta es un desplegable (flecha) con sus niveles y embarcaciones */
.saved-fold { border-bottom: 1px solid var(--line); }
.saved-fold > summary { list-style: none; cursor: pointer; }
.saved-fold > summary::-webkit-details-marker { display: none; }
.saved-fold > summary::before { content: "▶"; font-size: 10px; color: var(--muted); }
.saved-fold[open] > summary::before { content: "▼"; }
.saved-body { padding: 0 0 8px 16px; }
.saved-group { margin: 6px 0 2px; font-size: 12px; font-weight: 600; color: var(--muted); }
.saved-item { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 2px 0; margin: 0; font-size: 13px; }
.saved-item > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#saved-sueltos { margin-top: 8px; }
