/* Ulises — papel de carta náutica, tinta azul marino y magenta de derrota. */

:root {
  --paper: #f1ede3;
  --surface: #fffdf8;
  --surface-2: #f6f2e8;
  --ink: #0e2238;
  --ink-2: #47596d;
  --ink-3: #667587;
  --line: #e0d9ca;
  --line-strong: #cbc2ae;
  --navy: #0e2238;
  --navy-2: #17314d;
  --on-navy: #eef2f6;
  --on-navy-dim: #93a6ba;
  --accent: #b4236c;
  --accent-ink: #ffffff;
  --accent-soft: #f7e3ee;
  --route: #c2187a;
  --route-ink: #ffffff;
  --ok: #1d7a4d;
  --warn: #a8690d;
  --bad: #bf3526;
  --ok-soft: #e2f1e8;
  --warn-soft: #f8ecd4;
  --bad-soft: #f9e1dd;
  --shadow: 0 1px 2px rgba(14, 34, 56, .08), 0 6px 20px rgba(14, 34, 56, .1);
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-num: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --rail: 90px;
  color-scheme: light;
}

:root[data-theme="night"] {
  --paper: #07121d;
  --surface: #0e1c2b;
  --surface-2: #132537;
  --ink: #e3eaf1;
  --ink-2: #a5b4c3;
  --ink-3: #8193a6;
  --line: #1e3044;
  --line-strong: #2d445e;
  --navy: #040b13;
  --navy-2: #0b1826;
  --accent: #ff6aa9;
  --accent-ink: #2a0716;
  --accent-soft: #3b1730;
  --route: #ff5aa5;
  --route-ink: #2a0716;
  --ok: #4ec98f;
  --warn: #e6b450;
  --bad: #ff7466;
  --ok-soft: #12301f;
  --warn-soft: #33270c;
  --bad-soft: #3a1512;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
/* La página no se desplaza: lo hacen el panel de la ruta y cada sección por dentro. */
html, body { height: 100%; overflow: hidden; }
body {
  margin: 0;
  font: 15px/1.45 var(--font-ui);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -.01em; margin: 0; text-wrap: balance; }
p { margin: 0; }
a { color: var(--accent); text-underline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
[hidden] { display: none !important; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.ico { width: 18px; height: 18px; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Estructura ---------- */

.app { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); height: 100vh; height: 100dvh; }
.main { min-width: 0; min-height: 0; position: relative; }
.view { height: 100%; }

.rail {
  background: var(--navy); color: var(--on-navy);
  display: flex; flex-direction: column; align-items: center;
  padding: 16px 0 14px;
}
.brand { display: grid; justify-items: center; gap: 6px; color: var(--on-navy); text-decoration: none; }
.brand svg { width: 34px; height: 34px; }
.brand-n { fill: #e0428f; }
.brand span { font: italic 600 17px/1 var(--font-display); letter-spacing: .01em; }
.rail-nav { display: flex; flex-direction: column; gap: 4px; width: 100%; padding: 0 8px; margin-top: 22px; }
.rail-link {
  display: grid; justify-items: center; gap: 4px; padding: 10px 2px 8px;
  border-radius: 10px; color: var(--on-navy-dim); text-decoration: none;
  font-size: 10.5px; font-weight: 600; letter-spacing: .01em;
}
.rail-link .ico { width: 22px; height: 22px; }
.rail-link:hover { color: #fff; background: rgba(255, 255, 255, .06); }
.rail-link.is-active { color: #fff; background: rgba(255, 255, 255, .12); }
.rail-theme {
  margin-top: auto; width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .18); background: transparent; color: var(--on-navy-dim);
  display: grid; place-items: center;
}
.rail-theme:hover { color: #fff; border-color: rgba(255, 255, 255, .4); }

/* ---------- Controles ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-size: 13.5px; font-weight: 600; white-space: nowrap; text-decoration: none;
}
.btn .ico { width: 16px; height: 16px; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .35; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); height: 32px; padding: 0 8px; font-size: 12.5px; }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-icon { width: 30px; height: 30px; padding: 0; }
.btn.is-danger:hover, .btn-danger { color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); border-color: var(--bad); }

.input {
  width: 100%; min-width: 0; height: 38px; padding: 0 10px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--surface); color: var(--ink);
}
textarea.input { height: auto; padding: 8px 10px; resize: vertical; line-height: 1.45; }
select.input { padding-right: 6px; }
.input::placeholder { color: var(--ink-3); opacity: .8; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.input.is-invalid { border-color: var(--bad); background: var(--bad-soft); }
.input.is-calc { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }

.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }
.fields-3 { grid-template-columns: 1fr 1fr 1.5fr; }
.field { display: grid; gap: 5px; min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field-short { max-width: 180px; }
.field > label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.field-note { font-weight: 500; color: var(--ink-3); font-family: var(--font-num); font-size: 11.5px; }
.with-unit { position: relative; }
.with-unit .input { padding-right: 44px; }
.with-unit > span { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: 12px; color: var(--ink-3); pointer-events: none; }
.row { display: flex; gap: 8px; align-items: center; }
.row-wrap { flex-wrap: wrap; }
.time-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.hint { font-size: 12.5px; color: var(--ink-3); margin-top: 12px; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 9px; height: 38px; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { width: 38px; height: 22px; border-radius: 11px; background: var(--line-strong); position: relative; flex: none; transition: background .15s; }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: transform .15s; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 9px; overflow: hidden; }
.seg button { height: 38px; padding: 0 16px; border: 0; border-left: 1px solid var(--line-strong); background: var(--surface); font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.seg button:first-child { border-left: 0; }
.seg button[aria-pressed="true"] { background: var(--navy-2); color: #fff; }

/* ---------- Rutas: mapa ---------- */

.view-rutas { display: grid; grid-template-columns: minmax(0, 1fr) 420px; }
.map-wrap { position: relative; min-height: 0; min-width: 0; display: flex; flex-direction: column; }
#map { position: relative; flex: 1 1 auto; min-height: 0; z-index: 0; background: #aad3df; font-family: var(--font-ui); }
#map.is-adding { cursor: crosshair; }
.map-fallback { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 28px; background: var(--surface-2); color: var(--ink-2); }
.map-fallback strong { font: 600 20px var(--font-display); color: var(--ink); }
.map-fallback p { max-width: 38ch; margin-top: 8px; }

.map-tools { position: absolute; top: 12px; left: 12px; z-index: 2; display: flex; gap: 6px; }
.map-btn {
  display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 12px;
  border-radius: 9px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow); font-size: 13px; font-weight: 600;
}
.map-btn .ico { width: 17px; height: 17px; }
.map-btn:hover { background: var(--surface-2); }
.map-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.map-cursor {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 2;
  padding: 4px 10px; border-radius: 7px; background: var(--navy); color: var(--on-navy);
  font-size: 12px; white-space: pre; pointer-events: none; opacity: .92;
}
@media (hover: none) { .map-cursor { display: none; } }

.wp-pin-wrap { background: none; border: 0; }
.wp-pin {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--route); color: var(--route-ink); border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .5);
  font: 700 12px/24px var(--font-num); text-align: center; cursor: grab;
}
.wp-pin.is-selected { box-shadow: 0 0 0 4px rgba(255, 255, 255, .85), 0 1px 6px rgba(0, 0, 0, .6); }
.route-seg { stroke: var(--route); }
.route-hit { stroke: var(--route); cursor: copy; }
.leg-label-wrap { background: none; border: 0; }
.leg-label {
  position: absolute; transform: translate(-50%, -50%); white-space: nowrap;
  padding: 2px 7px; border-radius: 6px;
  background: rgba(255, 253, 248, .94); color: #0e2238; border: 1px solid rgba(14, 34, 56, .28);
  font: 600 11px/1.35 var(--font-num); pointer-events: none;
}
.pos-dot { stroke: #fff; fill: #1c74d8; fill-opacity: 1; }
.pos-acc { stroke: #1c74d8; fill: #1c74d8; fill-opacity: .12; }
.nm-scale {
  border: 2px solid #0e2238; border-top: 0; padding: 0 5px 1px; margin: 0 0 4px 4px;
  font: 600 11px/1.5 var(--font-num); color: #0e2238; white-space: nowrap;
  background: rgba(255, 253, 248, .7);
}

/* Controles de Leaflet a juego con el tema */
.leaflet-bar, .leaflet-control-layers { border: 1px solid var(--line-strong) !important; box-shadow: var(--shadow) !important; border-radius: 9px !important; }
.leaflet-bar a { background: var(--surface); color: var(--ink); border-bottom-color: var(--line); }
.leaflet-bar a:hover { background: var(--surface-2); color: var(--ink); }
.leaflet-bar a:first-child { border-radius: 8px 8px 0 0; }
.leaflet-bar a:last-child { border-radius: 0 0 8px 8px; }
.leaflet-control-layers { background: var(--surface); color: var(--ink); font: 13px var(--font-ui); }
.leaflet-control-layers-expanded { padding: 10px 12px; }
.leaflet-control-layers-separator { border-top-color: var(--line); }
.leaflet-container .leaflet-control-attribution { background: rgba(255, 253, 248, .8); font-size: 10px; }
:root[data-theme="night"] .tiles-osm { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.88) saturate(.75); }
:root[data-theme="night"] #map { background: #0c1c2a; }
:root[data-theme="night"] .leaflet-control-layers-toggle,
:root[data-theme="night"] .leaflet-container .leaflet-control-attribution { filter: invert(1) hue-rotate(180deg); }

/* ---------- Rutas: panel ---------- */

.panel { background: var(--surface); border-left: 1px solid var(--line); overflow-y: auto; min-height: 0; }
.panel-head { padding: 16px 18px 10px; }
.route-pick { display: flex; gap: 8px; }
.route-name {
  width: 100%; margin-top: 12px; padding: 2px 0 4px;
  border: 0; border-bottom: 1px dashed transparent; border-radius: 0; background: transparent;
  font: 600 25px/1.2 var(--font-display); letter-spacing: -.01em; color: var(--ink);
}
.route-name:hover { border-bottom-color: var(--line-strong); }
.route-name:focus { outline: none; border-bottom: 1px solid var(--accent); }
.route-actions { display: flex; align-items: center; gap: 2px; margin: 6px 0 0 -8px; }
.route-actions .btn-icon { margin-left: auto; }

.summary { position: sticky; top: 0; z-index: 3; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--navy); color: var(--on-navy); }
.stat { padding: 11px 10px 12px 14px; border-left: 1px solid rgba(255, 255, 255, .1); min-width: 0; }
.stat:first-child { border-left: 0; padding-left: 18px; }
.stat-label { font-size: 9.5px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--on-navy-dim); white-space: nowrap; }
.stat-value { font: 600 18px/1.25 var(--font-num); font-variant-numeric: tabular-nums; margin-top: 3px; white-space: nowrap; }
.stat-unit { font-size: 11px; font-weight: 500; color: var(--on-navy-dim); margin-left: 3px; }

.section { padding: 18px; border-bottom: 1px solid var(--line); }
.section:last-child { border-bottom: 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.section-title { font: 700 11px/1 var(--font-ui); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); }
.section-meta { font-size: 12px; color: var(--ink-3); }
.boat-link { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); text-decoration: none; min-width: 0; }
.boat-link:hover { color: var(--accent); }
.boat-link .ico { width: 15px; height: 15px; }

.speed-row { display: grid; grid-template-columns: 96px minmax(0, 1fr) auto; gap: 10px; align-items: center; }
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 0; }

.fuel { margin-top: 16px; }
.gauge-wrap { position: relative; padding: 4px 0; }
.gauge { position: relative; height: 12px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line-strong); overflow: hidden; }
.gauge-left { position: absolute; top: 0; bottom: 0; left: 0; background: var(--ok); }
.gauge-used { position: absolute; top: 0; bottom: 0; background: repeating-linear-gradient(-45deg, var(--ink-3) 0 3px, transparent 3px 6px); opacity: .55; }
.gauge-reserve { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--ink); border-radius: 1px; }
.fuel.is-warn .gauge-left { background: var(--warn); }
.fuel.is-bad .gauge-used { background: repeating-linear-gradient(-45deg, var(--bad) 0 3px, transparent 3px 6px); opacity: .9; }
.fuel-msg { margin-top: 8px; font-size: 13px; color: var(--ink-2); padding-left: 10px; border-left: 3px solid var(--ok); }
.fuel-msg b { color: var(--ink); font-family: var(--font-num); }
.fuel.is-warn .fuel-msg { border-left-color: var(--warn); }
.fuel.is-bad .fuel-msg { border-left-color: var(--bad); color: var(--bad); }
.fuel.is-bad .fuel-msg b { color: var(--bad); }

/* Derrota: los puntos cuelgan de una línea, como en la carta */
.wp-list { list-style: none; margin: 0; padding: 0; }
.wp-empty { padding: 16px; border: 1px dashed var(--line-strong); border-radius: 10px; color: var(--ink-3); font-size: 13.5px; text-align: center; }
.wp { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 0 10px; align-items: start; padding: 6px 6px 6px 4px; margin: 0 -6px 0 -4px; border-radius: 10px; }
.wp.is-selected { background: var(--accent-soft); }
.wp-dot { width: 26px; height: 26px; margin-top: 2px; border-radius: 50%; background: var(--route); color: var(--route-ink); font-size: 12px; font-weight: 700; line-height: 26px; text-align: center; }
.wp-body { min-width: 0; display: grid; gap: 1px; }
.wp-name { width: 100%; height: 26px; padding: 0; border: 0; border-bottom: 1px solid transparent; background: transparent; font-weight: 600; font-size: 14.5px; color: var(--ink); border-radius: 0; }
.wp-name::placeholder { color: var(--ink-3); font-weight: 500; }
.wp-name:hover { border-bottom-color: var(--line-strong); }
.wp-name:focus { outline: none; border-bottom-color: var(--accent); }
.wp-coord { justify-self: start; padding: 2px 0; border: 0; background: none; font-size: 11.5px; color: var(--ink-3); text-align: left; }
.wp-coord:hover { color: var(--accent); text-decoration: underline; }
.wp-side { display: flex; align-items: center; gap: 4px; }
.wp-eta { font-size: 12.5px; font-weight: 600; color: var(--ink); margin-right: 2px; }
.wp-tools { display: flex; }
.wp-tools .btn-icon { width: 26px; height: 28px; }
.wp-tools .ico { width: 14px; height: 14px; }
.leg { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 10px; }
.leg::before { content: ""; justify-self: center; width: 2px; margin: -6px 0; background: var(--route); opacity: .45; }
.leg-info { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; padding: 7px 0; font-size: 12.5px; color: var(--ink-2); }
.leg-info b { color: var(--ink); font-size: 13.5px; }
.coord-edit { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 4px; }
.coord-edit .input { height: 34px; font-size: 12.5px; padding: 0 8px; }
.coord-edit .btn { height: 32px; }
.coord-add { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; margin-top: 16px; }
.coord-add .input { font-size: 12.5px; padding: 0 8px; }

/* ---------- Páginas ---------- */

.page { overflow-y: auto; }
.page-inner { max-width: 1080px; margin: 0 auto; padding: 36px 28px 64px; }
.page-narrow { max-width: 680px; }
.page-head h1 { font-size: 36px; line-height: 1.1; }
.page-head { margin-bottom: 24px; }
.lede { color: var(--ink-2); margin-top: 8px; max-width: 62ch; font-size: 15.5px; }
.stack { display: grid; gap: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; align-items: start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px; min-width: 0; }
.card h2 { font-size: 20px; margin-bottom: 6px; }
.card-desc { color: var(--ink-2); font-size: 13.5px; margin-bottom: 16px; max-width: 60ch; }
.card-note { background: var(--surface-2); }
.card-note p { color: var(--ink-2); font-size: 13.5px; }
.card-navy { background: var(--navy); border-color: var(--navy); color: var(--on-navy); }
:root[data-theme="night"] .card-navy { border-color: var(--line); }
.callout { background: var(--warn-soft); color: var(--ink); border-left: 3px solid var(--warn); border-radius: 6px; padding: 9px 12px; font-size: 13px; margin-bottom: 14px; }

.results { margin-top: 16px; }
.results:empty { display: none; }
.result { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 13.5px; }
.result > span { color: var(--ink-2); }
.result > b { text-align: right; font-weight: 600; }
.card-navy .result { border-top-color: rgba(255, 255, 255, .12); }
.card-navy .result > span { color: var(--on-navy-dim); }

/* Barco */
.boat-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.chip { height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line-strong); background: var(--surface); font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.chip:hover { color: var(--ink); }
.chip.is-active { background: var(--navy-2); border-color: var(--navy-2); color: #fff; }
.chip-add { width: auto; height: 36px; border-radius: 18px; border-style: dashed; font-size: 13.5px; font-weight: 600; color: var(--ink-2); padding-left: 12px; }
.boat-grid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.boat-side { display: grid; gap: 16px; }
.boat-form fieldset + fieldset { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line); }
.boat-form legend { font: 700 11px/1 var(--font-ui); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); padding: 0; margin-bottom: 12px; float: left; width: 100%; }
.boat-form legend + * { clear: both; }
.boat-form .btn-danger { margin-top: 22px; }
.eyebrow { font-size: 10.5px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--on-navy-dim); }
.big { font-size: 52px; font-weight: 600; line-height: 1.05; margin-top: 8px; letter-spacing: -.02em; }
.big small { font-size: 18px; font-weight: 500; color: var(--on-navy-dim); letter-spacing: 0; }
.big-note { font-size: 13px; color: var(--on-navy-dim); margin: 4px 0 16px; }
.stats-empty { color: var(--on-navy-dim); font-size: 13.5px; margin-top: 8px; }
.curve { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.curve th { text-align: left; font-size: 11.5px; font-weight: 600; color: var(--ink-2); padding: 0 6px 8px 0; vertical-align: bottom; }
.curve th small { display: block; font-weight: 500; color: var(--ink-3); font-size: 10.5px; }
.curve td { padding: 3px 6px 3px 0; font-size: 13px; }
.curve td:nth-child(1), .curve td:nth-child(2) { width: 26%; }
.curve td:last-child { width: 30px; padding-right: 0; }
.curve .input { height: 34px; }
.curve-empty { color: var(--ink-3); padding: 10px 0 !important; }

.fieldset-note { clear: both; font-size: 12.5px; color: var(--ink-3); margin: -2px 0 12px; max-width: 56ch; }

/* ---------- Meteo ---------- */

/* Rampas de un solo tono: azul para el viento y naranja para la mar. Más intensidad
   es más valor, y el tramo más bajo se funde con el fondo (por eso en modo noche
   la rampa va al revés: de oscuro a claro). */
:root {
  --wl1: #cde2fb; --wl2: #9ec5f4; --wl3: #6da7ec; --wl4: #3987e5; --wl5: #1c5cab; --wl6: #0d366b;
  --sl1: #fbe0d0; --sl2: #f8c4a6; --sl3: #f3a47b; --sl4: #eb8251; --sl5: #d95926; --sl6: #a63f14;
  --ramp-ink: #0b1a2b;
}
:root[data-theme="night"] {
  --wl1: #0d366b; --wl2: #184f95; --wl3: #256abf; --wl4: #3987e5; --wl5: #6da7ec; --wl6: #b7d3f6;
  --sl1: #5a2410; --sl2: #7d3112; --sl3: #a63f14; --sl4: #d95926; --sl5: #f09263; --sl6: #f8c4a6;
}
.wl1 { background: var(--wl1); } .wl2 { background: var(--wl2); } .wl3 { background: var(--wl3); }
.wl4 { background: var(--wl4); } .wl5 { background: var(--wl5); } .wl6 { background: var(--wl6); }
.sl1 { background: var(--sl1); } .sl2 { background: var(--sl2); } .sl3 { background: var(--sl3); }
.sl4 { background: var(--sl4); } .sl5 { background: var(--sl5); } .sl6 { background: var(--sl6); }
/* Tinta sobre cada tramo, elegida por contraste. */
.wx-table td.wl1, .wx-table td.wl2, .wx-table td.wl3, .wx-table td.sl1, .wx-table td.sl2, .wx-table td.sl3, .wx-table td.sl4,
.lg-cell.wl1, .lg-cell.wl2, .lg-cell.wl3, .lg-cell.sl1, .lg-cell.sl2, .lg-cell.sl3, .lg-cell.sl4 { color: var(--ramp-ink); }
.wx-table td.wl4, .wx-table td.wl5, .wx-table td.wl6, .wx-table td.sl5, .wx-table td.sl6,
.lg-cell.wl4, .lg-cell.wl5, .lg-cell.wl6, .lg-cell.sl5, .lg-cell.sl6 { color: #fff; }
:root[data-theme="night"] .wx-table td:is(.wl1, .wl2, .wl3, .wl4, .sl1, .sl2, .sl3, .sl4),
:root[data-theme="night"] .lg-cell:is(.wl1, .wl2, .wl3, .wl4, .sl1, .sl2, .sl3, .sl4) { color: #fff; }
:root[data-theme="night"] .wx-table td:is(.wl5, .wl6, .sl5, .sl6),
:root[data-theme="night"] .lg-cell:is(.wl5, .wl6, .sl5, .sl6) { color: var(--ramp-ink); }

.is-busy { opacity: .5; transition: opacity .15s; }
.hint-flat { margin-top: 0; }
.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; text-decoration: underline; }
.wx-arrow { width: 13px; height: 13px; fill: currentColor; flex: none; }
.na { color: var(--ink-3); opacity: .6; }
.near { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--warn); vertical-align: middle; }

/* Meteo dentro del panel de la ruta */
.wx-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.wx-stat { display: grid; gap: 1px; padding: 10px 12px; min-width: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.wx-label { font-size: 10px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); white-space: nowrap; }
.wx-stat b { font-size: 20px; font-weight: 600; line-height: 1.25; }
.wx-stat small { font-size: 11px; font-weight: 500; color: var(--ink-3); }
.wx-sub { font-size: 11.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wx-msg { margin-top: 10px; font-size: 13px; color: var(--ink-2); padding-left: 10px; border-left: 3px solid var(--line-strong); }
.wx.is-ok .wx-msg { border-left-color: var(--ok); }
.wx.is-warn .wx-msg { border-left-color: var(--warn); }
.wx.is-bad .wx-msg { border-left-color: var(--bad); color: var(--bad); }
.wx-meta { margin-top: 8px; font-size: 11.5px; color: var(--ink-3); }
.wp-wx { grid-column: 2 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 9px; margin-top: 1px; font-size: 11.5px; color: var(--ink-2); }

/* Página Meteo */
.wx-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; margin-bottom: 16px; }
.wx-bar .field { flex: 0 1 320px; min-width: 200px; }
.wx-age { font-size: 12.5px; color: var(--ink-3); padding-bottom: 10px; }
.wx-state { padding: 28px; text-align: center; color: var(--ink-3); border: 1px dashed var(--line-strong); border-radius: 12px; }
.wx-credit { margin-top: 14px; font-size: 12.5px; color: var(--ink-3); max-width: 75ch; }
.wx-detail { margin-bottom: 16px; }
.wx-now { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; margin-top: 14px; }
.wx-fig-label { font-size: 12px; font-weight: 600; color: var(--on-navy-dim); }
.wx-fig .big { display: flex; align-items: baseline; gap: 8px; font-size: 40px; margin-top: 4px; }
.wx-fig .big .wx-arrow { width: 24px; height: 24px; align-self: center; }
.wx-fig .big .ico { width: 30px; height: 30px; align-self: center; }
.wx-fig p { margin-top: 6px; min-height: 2.9em; font-size: 13px; color: var(--on-navy-dim); }
.wx-verdict { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, .12); font-size: 13.5px; }
.wx-verdict .ico { width: 17px; height: 17px; }
.wx-verdict.is-warn { color: #f3cf7a; }
.wx-verdict.is-bad { color: #ffb3aa; }

.wx-card { padding: 14px 14px 16px; }
.wx-scroll { overflow-x: auto; padding-bottom: 8px; }
.wx-table { border-collapse: separate; border-spacing: 2px; font: 12.5px/1 var(--font-num); font-variant-numeric: tabular-nums; }
.wx-table th[scope="row"], .wx-corner {
  position: sticky; left: 0; z-index: 1; min-width: 108px; padding: 0 12px 0 0;
  background: var(--surface); text-align: left; white-space: nowrap;
  font: 600 12px/1.2 var(--font-ui); color: var(--ink-2);
}
.wx-table th small { font-weight: 500; color: var(--ink-3); }
.wx-table td { min-width: 38px; height: 28px; padding: 0 3px; text-align: center; border-radius: 4px; color: var(--ink); }
.wx-table tr.grp > * { border-top: 8px solid transparent; background-clip: padding-box; }
.wx-table tr.grp > td { height: 36px; }
.wx-day { max-width: 0; padding: 0 4px 7px 6px; overflow: hidden; border-left: 2px solid var(--line-strong); text-align: left; white-space: nowrap; font: 600 12px/1 var(--font-ui); color: var(--ink); }
.wx-hour { padding: 0; }
.wx-hour button { width: 100%; height: 27px; padding: 0; border: 0; border-bottom: 3px solid transparent; border-radius: 4px; background: transparent; color: var(--ink-3); font: inherit; font-weight: 600; }
.wx-hour.in-trip button { border-bottom-color: var(--route); color: var(--ink); }
.wx-hour.is-col button, .wx-hour.is-pin button { background: var(--ink); color: var(--surface); }
.wx-table td.is-col { box-shadow: 0 0 0 2px var(--ink-2); }
.wx-dir .wx-arrow { width: 14px; height: 14px; color: var(--ink-2); vertical-align: middle; }
.wx-sky .ico { width: 17px; height: 17px; color: var(--ink-2); vertical-align: middle; }
.wx-flag .ico { width: 16px; height: 16px; color: var(--bad); vertical-align: middle; }

.wx-legend { display: flex; flex-wrap: wrap; gap: 12px 28px; margin-top: 12px; padding-top: 14px; border-top: 1px solid var(--line); }
.lg { display: grid; gap: 6px; }
.lg-title { font-size: 11.5px; font-weight: 600; color: var(--ink-2); }
.lg-cells { display: flex; flex-wrap: wrap; gap: 2px; }
.lg-cell { min-width: 42px; padding: 5px 6px; border-radius: 4px; text-align: center; white-space: nowrap; font: 11px/1 var(--font-num); }
.lg-cell.wl0, .lg-cell.sl0 { box-shadow: inset 0 0 0 1px var(--line-strong); color: var(--ink-2); }
.lg-marks { display: flex; flex-wrap: wrap; align-items: center; align-self: end; gap: 8px 18px; }
.lg-mark { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.lg-mark .ico { width: 15px; height: 15px; }
.lg-mark.is-bad .ico { color: var(--bad); }
.lg-trip { width: 18px; height: 3px; border-radius: 2px; background: var(--route); }

/* ---------- Buscador de puertos y calas ---------- */

.place-search { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; margin-bottom: 10px; }
.with-icon { position: relative; }
.with-icon .ico { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--ink-3); pointer-events: none; }
.with-icon .input { padding-left: 32px; -webkit-appearance: none; appearance: none; }
.place-results { display: grid; gap: 4px; margin-bottom: 14px; }
.place-results:empty { display: none; }
.place-title { font-size: 10.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.place {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1px 12px; align-items: center;
  width: 100%; padding: 8px 10px; text-align: left;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface);
}
.place:hover { border-color: var(--accent); background: var(--accent-soft); }
.place > * { grid-column: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.place-kind { font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.place b { font-size: 14px; font-weight: 600; }
.place-detail { font-size: 12px; color: var(--ink-3); }
.place .place-dist { grid-column: 2; grid-row: 1 / span 3; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.plan-done { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-top: 16px; }

/* ---------- Navegación en vivo ---------- */

.lbl-short { display: none; }
.map-tools { flex-wrap: wrap; right: 64px; }
.map-go { background: var(--navy); border-color: var(--navy); color: var(--on-navy); }
.map-go:hover { background: var(--navy-2); }
:root[data-theme="night"] .map-go { border-color: var(--line-strong); }
.track-line { stroke: #1c74d8; }
.boat-pos-wrap { background: none; border: 0; }
.boat-pos { position: relative; width: 34px; height: 34px; transition: transform .3s; }
.boat-pos svg { width: 100%; height: 100%; fill: #1c74d8; stroke: #fff; stroke-width: 1.6; stroke-linejoin: round; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .5)); }
.boat-pos.is-still { transform: none !important; }
.boat-pos.is-still svg { display: none; }
.boat-pos.is-still::after { content: ""; position: absolute; inset: 9px; border-radius: 50%; background: #1c74d8; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .5); }

.nav-hud {
  flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 24px;
  padding: 12px 16px;
  background: var(--navy); color: var(--on-navy); border-top: 1px solid rgba(255, 255, 255, .1);
}
.nav-label, .nav-cells dt { font-size: 9.5px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--on-navy-dim); white-space: nowrap; }
.nav-speed { display: grid; gap: 2px; }
.nav-speed b { font-size: 46px; font-weight: 600; line-height: 1; letter-spacing: -.02em; }
.nav-speed small, .nav-cells small { font-size: 11.5px; font-weight: 500; color: var(--on-navy-dim); }
.nav-cells { flex: 1 1 300px; display: grid; grid-template-columns: repeat(auto-fit, minmax(82px, 1fr)); gap: 8px 18px; margin: 0; }
.nav-cells dd { margin: 3px 0 0; font-size: 17px; font-weight: 600; white-space: nowrap; }
.nav-end { display: grid; justify-items: end; gap: 6px; margin-left: auto; }
.nav-gps { font-size: 11.5px; color: var(--on-navy-dim); white-space: nowrap; }
.nav-gps.is-bad { color: #f3cf7a; }
.nav-stop { height: 40px; background: var(--bad); border-color: var(--bad); color: #fff; }
.nav-stop:hover { background: var(--bad); filter: brightness(1.1); }
:root[data-theme="night"] .nav-stop { color: #2a0705; }
.view-rutas.is-nav .map-cursor { display: none; }

/* ---------- Bitácora ---------- */

.log-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 16px; align-items: start; }
.log-wide { grid-column: 1 / -1; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-bottom: 6px; }
.card-head h2 { margin-bottom: 0; }
.log-form { margin-bottom: 18px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.log-form .row { margin-top: 14px; }
#log-trips .log-form { max-width: 560px; }
.amount { display: flex; align-items: center; height: 38px; font-size: 16px; font-weight: 600; }
.table-scroll { overflow-x: auto; }
.log-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.log-table th { padding: 0 12px 8px 0; text-align: left; font-size: 11.5px; font-weight: 600; color: var(--ink-2); border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
.log-table td { padding: 9px 12px 9px 0; border-bottom: 1px solid var(--line); vertical-align: top; white-space: nowrap; }
.log-table .r { text-align: right; }
.log-table td small { display: block; font: 11.5px/1.4 var(--font-ui); color: var(--ink-3); white-space: normal; }
.log-table td.name { min-width: 170px; white-space: normal; }
.log-table td.name b { font-weight: 600; margin-right: 7px; }
.log-table .acts { width: 1%; padding-right: 0; text-align: right; }
.log-table .acts .btn { vertical-align: middle; }
.log-table tr.is-editing td { background: var(--accent-soft); }
.log-table tfoot td { border-bottom: 0; font-weight: 600; color: var(--ink-2); }
.tag { display: inline-block; padding: 2px 7px; border-radius: 5px; font: 600 11px/1.45 var(--font-ui); background: var(--ok-soft); color: var(--ok); white-space: nowrap; }
.tag-dim { background: var(--surface-2); color: var(--ink-2); box-shadow: inset 0 0 0 1px var(--line); }
.pending { font: 600 12px var(--font-ui); color: var(--warn); }
.stats-note { margin-top: 12px; font-size: 12.5px; color: var(--on-navy-dim); }
.btn-on-navy { margin-top: 16px; background: transparent; border-color: rgba(255, 255, 255, .3); color: var(--on-navy); }
.btn-on-navy:hover { background: rgba(255, 255, 255, .1); }
.off-actions { margin-top: 14px; }

/* ---------- Sin conexión ---------- */

.net-badge {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 40;
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 14px;
  background: var(--warn-soft); color: var(--ink); border: 1px solid var(--warn); box-shadow: var(--shadow);
  font-size: 12.5px; font-weight: 600; white-space: nowrap; pointer-events: none;
}
.net-badge .ico { width: 15px; height: 15px; color: var(--warn); }

/* ---------- Aviso flotante ---------- */

.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 50;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  max-width: min(92vw, 460px); padding: 11px 16px; border-radius: 10px;
  background: var(--navy); color: var(--on-navy); box-shadow: var(--shadow);
  font-size: 13.5px; font-weight: 500; text-align: center;
  transition: opacity .2s, transform .2s;
}
:root[data-theme="night"] .toast { border: 1px solid var(--line-strong); }
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.toast.is-bad { background: var(--bad); color: #fff; }
:root[data-theme="night"] .toast.is-bad { color: #2a0705; }

/* ---------- Pantallas estrechas: barra inferior y mapa arriba ---------- */

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .rail { order: 2; flex-direction: row; padding: 4px 6px calc(4px + env(safe-area-inset-bottom)); }
  .brand, .rail-theme { display: none; }
  .rail-nav { flex-direction: row; margin: 0; padding: 0; gap: 2px; }
  .rail-link { flex: 1; min-width: 0; padding: 7px 2px 6px; }
  .view-rutas { grid-template-columns: minmax(0, 1fr); grid-template-rows: 44% minmax(0, 1fr); }
  .view-rutas.is-nav { grid-template-rows: 68% minmax(0, 1fr); }
  .log-grid { grid-template-columns: minmax(0, 1fr); }
  .net-badge { top: auto; bottom: 10px; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .page-inner { padding: 24px 16px 40px; }
  .page-head h1 { font-size: 30px; }
  .boat-grid { grid-template-columns: minmax(0, 1fr); }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .toast { bottom: 84px; }
}

@media (max-width: 640px) {
  /* Bitácora: cada fila de las tablas pasa a ser una ficha con sus datos rotulados. */
  .log-table, .log-table tbody, .log-table tfoot { display: block; }
  .log-table thead { display: none; }
  .log-table tr { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 20px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .log-table tbody tr:first-child { padding-top: 0; }
  .log-table tfoot tr { border-bottom: 0; padding-bottom: 0; }
  .log-table td { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 0; border: 0; white-space: nowrap; }
  .log-table td:empty { display: none; }
  .log-table td[data-label]::before { content: attr(data-label); font: 600 11.5px var(--font-ui); color: var(--ink-3); }
  .log-table td small { display: inline; margin-left: 6px; }
  .log-table td.wide { grid-column: 1 / -1; display: block; white-space: normal; text-align: left; }
  .log-table td.wide small { display: block; margin-left: 0; }
  .log-table td.date { font-size: 12px; color: var(--ink-3); }
  .log-table td.name { min-width: 0; margin-bottom: 4px; font-size: 14.5px; }
  .log-table .acts { grid-column: 1 / -1; width: auto; justify-content: flex-end; margin-top: 2px; }
  .log-table tr.is-editing { background: var(--accent-soft); }
  .wx-now { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .wx-fig p { min-height: 0; }
  .wx-fig .big { font-size: 34px; }
}

@media (max-width: 560px) {
  .map-btn span { display: none; }
  .map-btn { width: 40px; padding: 0; justify-content: center; }
  .map-btn.map-go { width: auto; padding: 0 12px; }
  .map-btn.map-go .lbl-short { display: inline; }
  .rail-link { font-size: 10px; }
  .rail-link .lbl-long { display: none; }
  .rail-link .lbl-short { display: inline; }
  .nav-hud { gap: 10px 16px; padding: 10px 12px; }
  .nav-speed b { font-size: 38px; }
  .nav-cells { order: 3; flex-basis: 100%; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 12px; }
  .nav-cells dd { font-size: 15.5px; }
  .stat { padding-left: 10px; }
  .stat:first-child { padding-left: 14px; }
  .stat-value { font-size: 16px; }
  .fields-3 { grid-template-columns: 1fr 1fr; }
  .fields-3 .field:last-child { grid-column: 1 / -1; }
  .route-actions .btn-ghost:not(.btn-icon) { padding: 0 6px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
