/* SPDX-License-Identifier: GPL-3.0-or-later · Trenalia */
:root {
  --bg: #f4f6fa; --panel: #ffffff; --panel-2: #eef2f8; --line: #d6dde8;
  --text: #16202f; --muted: #556378; --faint: #7d8899;
  --green: #12935c; --amber: #b57600; --red: #d93a32; --blue: #1f6fd1; --grey: #6b7686;
  --glass: rgba(255,255,255,.9); --glass-2: rgba(255,255,255,.96); --map-bg: #dfe6ef;
  --modal-bg: #ffffff; --side-bg: #ffffff; --backdrop: rgba(20,30,45,.45); --shadow: rgba(20,30,45,.18);
  --on: #16202f; --on-fg: #ffffff; --on-accent: #ffffff; --hover-line: #a9b6c9; --handle: #c3ccd9;
  --alert-red-bg: rgba(255,240,239,.97); --alert-amber-bg: rgba(255,248,232,.97); --err-fg: #b42318; --warn-fg: #c0362c; --orange: #c75a00;
  --top-fade: rgba(244,246,250,.96); --top-fade-0: rgba(244,246,250,0);
  color-scheme: light;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --sans: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 10px;
}
/* Tema oscuro (botón sol/luna; por defecto, claro). La cabina va siempre en oscuro: es un panel de instrumentos */
:root[data-theme="dark"], .cab, .cab-dark {
  --bg: #0b111c; --panel: #111a29; --panel-2: #172234; --line: #22304a;
  --text: #e6ecf5; --muted: #8c9ab3; --faint: #5d6b85;
  --green: #3ecf8e; --amber: #f2b33d; --red: #ff5a52; --blue: #5aa9ff; --grey: #8b95a7;
  --glass: rgba(11,17,28,.88); --glass-2: rgba(11,17,28,.94); --map-bg: #070b12;
  --modal-bg: #0f1828; --side-bg: #0e1625; --backdrop: rgba(4,7,12,.72); --shadow: rgba(0,0,0,.45);
  --on: #e6ecf5; --on-fg: #0b111c; --on-accent: #06101f; --hover-line: #33476b; --handle: #3a4a66;
  --alert-red-bg: rgba(40,12,14,.94); --alert-amber-bg: rgba(38,28,8,.94); --err-fg: #ffb4ae; --warn-fg: #ff9a94; --orange: #ff9b3d;
  --top-fade: rgba(7,11,18,.96); --top-fade-0: rgba(7,11,18,0);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); }
button { font: inherit; color: inherit; cursor: pointer; }
h2 { font-size: 15px; margin: 0; font-weight: 700; letter-spacing: .01em; }

.app { display: grid; grid-template-columns: 1fr 380px; height: 100vh; }
.main { display: grid; grid-template-rows: 1fr auto; min-width: 0; min-height: 0; }
.mapwrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--map-bg); }

/* Barra superior sobre el mapa */
.topbar {
  position: absolute; z-index: 600; left: 12px; right: 12px; top: 12px;
  display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 10px; background: var(--glass); backdrop-filter: blur(6px); border: 1px solid var(--line); border-radius: var(--r); padding: 7px 12px; }
.logo { width: 20px; height: 20px; fill: none; stroke: var(--blue); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.name { font-weight: 700; font-size: 16px; }
.live { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.live.on i { background: var(--green); box-shadow: 0 0 0 0 rgba(62,207,142,.6); animation: pulse 2s infinite; }
.live.demo i { background: var(--amber); }
.live.off i { background: var(--red); }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(62,207,142,0); } 100% { box-shadow: 0 0 0 0 rgba(62,207,142,0); } }

.search input {
  width: 210px; background: var(--glass); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--r); padding: 8px 12px; font: 13px var(--sans); outline: none;
}
.search input:focus { border-color: var(--blue); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
.chip {
  display: inline-flex; gap: 6px; align-items: center; padding: 5px 10px; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--line); font-size: 12px; font-weight: 600; color: var(--muted);
}
.chip b { font-family: var(--mono); font-weight: 700; color: var(--text); }
.chip.on { background: var(--on); color: var(--on-fg); border-color: var(--on); }
.chip.on b { color: var(--on-fg); }
.chip[disabled] { opacity: .45; cursor: not-allowed; }

/* Ficha del tren */
.card {
  max-height: calc(100% - 210px); overflow: auto;
  position: absolute; z-index: 700; left: 12px; top: 128px; width: 300px; max-width: calc(100% - 24px);
  background: var(--glass-2); border: 1px solid var(--line); border-left: 3px solid var(--red);
  border-radius: var(--r); padding: 14px 16px; box-shadow: 0 10px 30px var(--shadow);
}
.card.c-green { border-left-color: var(--green); }
.card.c-amber { border-left-color: var(--amber); }
.card h3 { margin: 0; font-size: 15px; }
.card .route { color: var(--muted); font-size: 12px; margin: 2px 0 10px; }
.card dl { display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; margin: 0; font-size: 13px; }
.card dt { color: var(--muted); }
.card dd { margin: 0; text-align: right; font-family: var(--mono); font-size: 12.5px; }
.card dd.txt { font-family: var(--sans); font-size: 13px; }
.card .x { position: absolute; top: 8px; right: 10px; background: none; border: 0; color: var(--muted); font-size: 18px; line-height: 1; }
.card dl.extra { margin-top: 5px; }
.card dl.extra[data-collapsed] { display: none; }
.card s.sched { color: var(--faint); font-size: 11px; margin-left: 4px; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card .share { margin-top: 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; font-size: 12px; color: var(--muted); }

/* KPIs y leyenda */
.kpis {
  position: absolute; z-index: 600; left: 12px; bottom: 12px; display: flex; gap: 22px;
  background: var(--glass); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 14px;
}
.kpis div { display: flex; flex-direction: column; }
.kpis b { font-family: var(--mono); font-size: 22px; line-height: 1.1; }
.kpis span { color: var(--muted); font-size: 11px; }
.red { color: var(--red); }

.legend {
  position: absolute; z-index: 600; right: 12px; bottom: 12px; font-size: 11.5px; color: var(--muted);
  background: var(--glass); border: 1px solid var(--line); border-radius: var(--r); padding: 8px 12px; display: grid; gap: 3px;
}
.legend div { display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.green { background: var(--green); } .dot.amber { background: var(--amber); }
.dot.red { background: var(--red); } .dot.grey { background: var(--grey); width: 7px; height: 7px; }
.dot.hollow { background: transparent; border: 2px solid var(--amber); width: 10px; height: 10px; }
.dot.fire { background: #ff7a1a; box-shadow: 0 0 0 3px rgba(255,122,26,.25); width: 9px; height: 9px; }
.dot.quake { background: #b07cff; width: 10px; height: 10px; }
.dot.wx { background: #4fc3f7; width: 9px; height: 9px; }
.dash { width: 16px; border-top: 2px dashed var(--red); display: inline-block; }

/* Paneles */
.panel { background: var(--panel); border-left: 1px solid var(--line); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px 0; }
.sub { margin: 4px 16px 10px; color: var(--faint); font-size: 12px; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 10px; }
.tabs.small { padding: 0; }
.tabs button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 4px 9px; font-size: 12px; color: var(--muted); }
.tabs button span { font-family: var(--mono); color: var(--faint); margin-left: 3px; }
.tabs button.on { background: var(--on); color: var(--on-fg); border-color: var(--on); }
.tabs button.on span { color: var(--on-fg); }

.incidents { border-left: 0; border-top: 1px solid var(--line); max-height: 34vh; display: flex; flex-direction: column; }
.inc-list { overflow: auto; padding: 0 16px 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px; }
.inc { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; cursor: pointer; }
.inc:hover { border-color: var(--hover-line); }
.inc .t { display: flex; gap: 8px; align-items: flex-start; }
.inc .t i { margin-top: 5px; flex: none; }
.inc .t h4 { margin: 0; font-size: 13px; flex: 1; }
.inc .meta { text-align: right; font-size: 11px; color: var(--muted); white-space: nowrap; }
.inc .meta b { display: block; color: var(--amber); }
.inc.grave .meta b { color: var(--red); }
.inc p { margin: 6px 0 0 18px; color: var(--muted); font-size: 12.5px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.inc.open p { -webkit-line-clamp: unset; display: block; }
.inc .reg { margin: 6px 0 0 18px; color: var(--faint); font-size: 11px; }
.empty { color: var(--faint); font-size: 13px; padding: 4px 0 10px; }

.side { display: flex; flex-direction: column; min-height: 0; }
.arr-list { list-style: none; margin: 0; padding: 0 10px; overflow: auto; flex: 1; }
.arr {
  display: grid; grid-template-columns: 58px 1fr auto; gap: 10px; align-items: center;
  padding: 9px 8px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 6px;
}
.arr:hover, .arr.sel { background: var(--panel-2); }
.arr .d { font-family: var(--mono); font-weight: 700; font-size: 15px; color: var(--red); border-right: 2px solid currentColor; padding-right: 8px; text-align: right; }
.arr .d.amber { color: var(--amber); }
.arr h4 { margin: 0; font-size: 12.5px; font-weight: 600; }
.arr h4 small { color: var(--faint); font-family: var(--mono); font-weight: 500; margin-left: 4px; }
.arr .w { color: var(--faint); font-size: 11.5px; }
.arr .h { text-align: right; font-family: var(--mono); font-size: 12.5px; }
.arr .h s { display: block; color: var(--faint); font-size: 11px; }
.more { margin: 8px 16px; background: none; border: 0; color: var(--blue); text-align: left; padding: 0; font-size: 12.5px; }
.foot { padding: 10px 16px 14px; color: var(--faint); font-size: 11px; border-top: 1px solid var(--line); }
.foot a { color: var(--muted); display: block; margin-top: 3px; }

/* Etiquetas del mapa */
.leaflet-tooltip.tlabel {
  background: var(--glass); border: 1px solid var(--line); color: var(--text); box-shadow: none;
  font: 600 10.5px var(--mono); padding: 1px 5px; border-radius: 4px;
}
.leaflet-tooltip.tlabel::before { display: none; }
.leaflet-tooltip.tlabel .r { color: var(--red); } .leaflet-tooltip.tlabel .a { color: var(--amber); }
.leaflet-tooltip.slabel { background: none; border: 0; box-shadow: none; color: var(--faint); font: 500 11px var(--sans); padding: 0; }
.leaflet-tooltip.slabel::before { display: none; }
.leaflet-container { font-family: var(--sans); }
.leaflet-control-attribution { background: var(--glass) !important; color: var(--faint) !important; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-bar a { background: var(--panel) !important; color: var(--text) !important; border-color: var(--line) !important; }
.leaflet-top.leaflet-right { top: 128px; }

/* Botones auxiliares */
.search-btn { display: none; }
.recenter { width: 34px; height: 34px; display: grid; place-items: center; background: var(--panel); border: 1px solid var(--line) !important; border-radius: 8px !important; cursor: pointer; }
.recenter svg { width: 18px; height: 18px; fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linecap: round; }
.recenter:hover { background: var(--panel-2); }
.sheet { display: none; }

/* ───────── Móvil y tableta vertical: mapa a pantalla completa + panel inferior deslizable ───────── */
@media (max-width: 1000px) {
  html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
  body { position: fixed; inset: 0; }
  .app { display: block; height: 100dvh; }
  .main { display: block; height: 100%; }
  .mapwrap { position: absolute; inset: 0; height: auto; min-height: 0; }
  .side, .incidents { display: none; }

  /* Barra superior compacta */
  .topbar {
    left: 0; right: 0; top: 0; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
    background: linear-gradient(to bottom, var(--top-fade) 60%, var(--top-fade-0));
    flex-wrap: wrap;
  }
  .brand { flex: 1; min-width: 0; padding: 6px 10px; gap: 8px; }
  .name { font-size: 15px; }
  .live { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .search-btn {
    display: grid; place-items: center; width: 42px; height: 42px; flex: none;
    background: var(--glass); border: 1px solid var(--line); border-radius: var(--r);
  }
  .search-btn svg { width: 19px; height: 19px; fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; }
  .search { display: none; width: 100%; order: 3; }
  .search input { width: 100%; font-size: 16px; padding: 10px 12px; }
  .topbar.searching .search { display: block; }
  .topbar.searching .chips { display: none; }
  .chips {
    order: 4; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -10px; padding: 0 10px 2px;
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 10px, #000 calc(100% - 24px), transparent);
            mask-image: linear-gradient(to right, transparent 0, #000 10px, #000 calc(100% - 24px), transparent);
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; padding: 7px 11px; font-size: 12.5px; }

  /* Controles del mapa */
  .leaflet-control-zoom { display: none; }
  .leaflet-top.leaflet-right { top: calc(112px + env(safe-area-inset-top)); }
  .leaflet-bottom { bottom: var(--sheet-visible, 0px); transition: bottom .25s ease; }
  .leaflet-control-attribution { font-size: 9.5px; max-width: 70vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* Ficha del tren: flota sobre el panel */
  .card {
    top: auto; left: 8px; right: 8px; width: auto; bottom: calc(var(--sheet-visible, 0px) + 8px);
    max-height: calc(100dvh - var(--sheet-visible, 0px) - 140px); padding: 12px 14px; z-index: 900;
  }
  .card dl { gap: 4px 12px; font-size: 13px; }
  .card .x { width: 36px; height: 36px; top: 4px; right: 4px; font-size: 22px; }
  .card .share { padding: 8px 12px; font-size: 12.5px; }
  body.sheet-open .card { display: none; }
  body.card-open .tl-fab { display: none; }

  /* Panel inferior */
  .sheet {
    display: flex; flex-direction: column; position: fixed; z-index: 1000; left: 0; right: 0; bottom: 0;
    background: var(--panel); border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
    box-shadow: 0 -10px 30px var(--shadow); transition: transform .28s cubic-bezier(.2,.8,.2,1);
    will-change: transform;
  }
  .sh-grip { flex: none; touch-action: none; padding: 0 12px; user-select: none; -webkit-user-select: none; }
  .sh-handle { display: block; width: 100%; height: 22px; background: none; border: 0; padding: 0; }
  .sh-handle span { display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--handle); margin: 8px auto 0; }
  .sh-peek .kpis {
    position: static; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
    background: none; border: 0; padding: 4px 4px 10px; border-radius: 0;
  }
  .sh-peek .kpis b { font-size: 20px; }
  .sh-tabs { display: flex; gap: 6px; padding-bottom: 10px; }
  .sh-tabs button {
    flex: 1; background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 6px;
    font-size: 13px; font-weight: 600; color: var(--muted);
  }
  .sh-tabs button span { font-family: var(--mono); color: var(--faint); margin-left: 2px; }
  .sh-tabs button.on { background: var(--on); color: var(--on-fg); border-color: var(--on); }
  .sh-tabs button.on span { color: var(--on-fg); }
  .sh-body {
    flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
    border-top: 1px solid var(--line); padding-bottom: calc(80px + env(safe-area-inset-bottom));
  }
  .sh-pane .panel-head { padding-top: 12px; }
  .sh-pane .tabs:not(.small) { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .sh-pane .tabs:not(.small)::-webkit-scrollbar { display: none; }
  .sh-pane .tabs button { flex: none; padding: 6px 10px; font-size: 12.5px; }
  .sh-pane .arr-list { overflow: visible; padding: 0 6px; }
  .arr { grid-template-columns: 54px 1fr auto; padding: 11px 6px; }
  .arr h4 { font-size: 13px; }
  .sh-pane .inc-list { grid-template-columns: 1fr; overflow: visible; }
  .sh-pane .legend { position: static; background: none; border: 0; padding: 12px 16px; font-size: 13px; gap: 8px; }
  .sh-pane .foot { border-top: 0; }
  .sh-info { margin: 14px 16px 0; color: var(--muted); font-size: 13px; }
  .more { padding: 10px 0; }

}

@media (max-width: 1000px) and (max-height: 520px) {
  /* Móvil en horizontal: panel lateral más bajo */
  .sh-peek .kpis { display: none; }
  .chips { display: none; }
  .leaflet-top.leaflet-right { top: 64px; }
}

/* Selector de mapa base */
.leaflet-control-layers { background: var(--panel) !important; color: var(--text); border: 1px solid var(--line) !important; border-radius: 8px !important; }
.leaflet-control-layers-toggle { filter: invert(1) hue-rotate(180deg) brightness(1.2); width: 32px !important; height: 32px !important; }
.leaflet-control-layers-expanded { padding: 8px 10px; font-size: 12.5px; }

/* ───────── Trenalito ───────── */
.tl-fab {
  position: fixed; z-index: 1100; right: 20px; bottom: 20px; display: flex; align-items: center; gap: 8px;
  background: var(--blue); color: var(--on-accent); border: 0; border-radius: 999px; padding: 11px 18px 11px 14px;
  font-weight: 700; font-size: 14px; box-shadow: 0 8px 24px var(--shadow);
}
.tl-fab svg { width: 22px; height: 22px; fill: var(--on-accent); }
.tl-fab svg circle { fill: var(--blue); }
.tl-fab:hover { filter: brightness(1.08); }
body.tl-open .tl-fab { display: none; }

.tl {
  position: fixed; z-index: 1200; top: 0; right: 0; bottom: 0; width: 400px; max-width: 100vw;
  display: flex; flex-direction: column; background: var(--side-bg); border-left: 1px solid var(--line);
  box-shadow: -12px 0 32px var(--shadow); animation: tlIn .18s ease-out;
}
@keyframes tlIn { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.tl[hidden] { display: none; }
.tl-head { display: flex; align-items: flex-start; gap: 6px; padding: 14px 14px 12px 16px; border-bottom: 1px solid var(--line); }
.tl-head > div { flex: 1; }
.tl-head h2 { font-size: 16px; }
.tl-head p { margin: 2px 0 0; color: var(--faint); font-size: 12px; }
.tl-icon { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; width: 32px; height: 32px; font-size: 17px; line-height: 1; color: var(--muted); }
.tl-icon:hover { color: var(--text); }

.tl-log { flex: 1; overflow: auto; padding: 14px 14px 6px; display: flex; flex-direction: column; gap: 10px; }
.tl-msg { max-width: 88%; padding: 9px 12px; border-radius: 12px; font-size: 13.5px; line-height: 1.5; }
.tl-msg p { margin: 0 0 6px; } .tl-msg p:last-child { margin-bottom: 0; }
.tl-msg ul { margin: 4px 0 6px; padding-left: 18px; } .tl-msg li { margin: 2px 0; }
.tl-msg.user { align-self: flex-end; background: var(--blue); color: var(--on-accent); border-bottom-right-radius: 4px; }
.tl-msg.assistant { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.tl-msg.error { border-color: rgba(255,90,82,.5); color: var(--err-fg); }
.tl-train { font: 700 12px var(--mono); background: rgba(90,169,255,.14); color: var(--blue); border: 1px solid rgba(90,169,255,.35); border-radius: 5px; padding: 0 5px; }
.tl-train:hover { background: rgba(90,169,255,.28); }
.tl-dots { display: inline-flex; gap: 4px; padding: 4px 0; }
.tl-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: tlDot 1s infinite ease-in-out; }
.tl-dots i:nth-child(2) { animation-delay: .15s; } .tl-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes tlDot { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.tl-sugs { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 14px 8px; }
.tl-sugs button { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 5px 10px; font-size: 12px; text-align: left; }
.tl-sugs button:hover { border-color: var(--blue); color: var(--text); }

.tl-form { display: flex; gap: 8px; align-items: flex-end; padding: 10px 14px; border-top: 1px solid var(--line); }
.tl-form textarea {
  flex: 1; resize: none; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 11px; font: 14px/1.4 var(--sans); outline: none; max-height: 120px;
}
.tl-form textarea:focus { border-color: var(--blue); }
.tl-form button { width: 40px; height: 40px; border-radius: 10px; border: 0; background: var(--blue); color: var(--on-accent); font-size: 16px; }
.tl-form button:disabled { opacity: .4; cursor: wait; }
.tl-note { margin: 0; padding: 0 14px 12px; color: var(--faint); font-size: 11px; }

@media (max-width: 1000px) {
  .tl { width: 100vw; border-left: 0; }
  .tl-fab { right: 12px; padding: 12px; bottom: calc(var(--sheet-visible, 0px) + 12px); transition: bottom .25s ease; }
  body.sheet-full .tl-fab { display: none; }
  .tl-fab span { display: none; }
  .tl-form { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
}

/* Banner y ventana de fuentes */
.modal { position: fixed; inset: 0; z-index: 2000; background: var(--backdrop); display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box {
  position: relative; width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow: auto;
  background: var(--modal-bg); border: 1px solid var(--line); border-radius: 14px; padding: 22px 22px 18px; box-shadow: 0 20px 60px var(--shadow);
}
.modal-x { position: absolute; top: 8px; right: 10px; width: 36px; height: 36px; background: none; border: 0; color: var(--muted); font-size: 22px; }
.modal h2 { font-size: 19px; margin: 0 0 4px; }
.modal .purpose { font-size: 16px; line-height: 1.5; color: var(--text); margin: 10px 0 14px; padding: 12px 14px; border-left: 3px solid var(--blue); background: rgba(90,169,255,.08); border-radius: 0 8px 8px 0; }
.modal p { color: var(--muted); font-size: 13.5px; }
.modal .ok { margin-top: 8px; background: var(--blue); color: var(--on-accent); border: 0; border-radius: 10px; padding: 11px 18px; font-weight: 700; font-size: 14px; }
.src-list { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 6px; }
.src-list li { display: grid; grid-template-columns: 12px 1fr; gap: 8px; align-items: start; font-size: 13px; }
.src-list li i { width: 9px; height: 9px; border-radius: 50%; margin-top: 5px; background: var(--faint); }
.src-list li i.s-ok { background: var(--green); } .src-list li i.s-bad { background: var(--red); } .src-list li i.s-demo { background: var(--amber); }
.src-list small { display: block; color: var(--faint); }
.prec { font-family: var(--mono); font-size: 12.5px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; color: var(--muted); }
.linkbtn { display: block; background: none; border: 0; padding: 0; margin-top: 4px; color: var(--muted); text-decoration: underline; font-size: 11px; }
.risk-group h5 { margin: 4px 0 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.inc.lvl-red .meta b { color: var(--red); } .inc.lvl-orange .meta b { color: var(--orange); } .inc.lvl-yellow .meta b { color: var(--amber); }
.card .est { display: inline-block; margin-left: 6px; font-size: 10.5px; font-weight: 700; color: var(--amber); border: 1px solid rgba(242,179,61,.5); border-radius: 4px; padding: 0 4px; vertical-align: middle; }

/* ── Histórico ─────────────────────────────────────────────── */
.hist-f { display: flex; gap: 8px; margin: 4px 0 12px; }
.hist-f input { flex: 1; min-width: 0; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.hist-f button { background: var(--blue); color: var(--on-accent); border: 0; border-radius: 8px; padding: 8px 14px; font-weight: 700; }
.hist-day { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin: 6px 0 10px; }
.hist-l { list-style: none; margin: 0 0 8px; padding: 0; }
.hist-l li { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.hist-l small { color: var(--muted); }
.hist-ex { color: var(--muted); font-size: 12px; margin-top: 3px; }
.hist-l .tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 4px; margin-right: 4px; text-transform: uppercase; letter-spacing: .02em; border: 1px solid var(--line); }
.hist-l .tag.c-red { color: var(--red); border-color: rgba(255,90,82,.45); background: rgba(255,90,82,.08); }
.hist-l .tag.c-amber { color: var(--amber); border-color: rgba(242,179,61,.45); background: rgba(242,179,61,.08); }
.hist-day .c-red, .hist-l .c-red { color: var(--red); } .hist-day .c-amber { color: var(--amber); }

/* ── Vista de cabina (panel de instrumentos) ─────────────────── */
.cab-btn { display: inline-flex; align-items: center; gap: 6px; flex: none; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px 6px 9px; font-weight: 600; font-size: 13px; }
.cab-btn svg { width: 18px; height: 18px; fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.cab-btn:hover { border-color: var(--blue); }
body.cab-open .cab-btn { border-color: var(--blue); color: var(--blue); }
body.cab-open .cab-btn svg { stroke: var(--blue); }
body.cab-open .tl-fab { display: none; }

.cab { position: fixed; z-index: 1150; top: 0; right: 0; bottom: 0; width: 420px; max-width: 100vw; display: flex; flex-direction: column;
  background: #0a111d; border-left: 1px solid var(--line); box-shadow: -12px 0 32px var(--shadow); animation: tlIn .18s ease-out; }
.cab[hidden] { display: none; }
.cab.alarm { border-left-color: var(--red); }
.cab-h { display: flex; align-items: center; gap: 6px; padding: 12px 12px 8px 16px; }
.cab-title { flex: 1; min-width: 0; }
.cab-title b { display: block; font-size: 20px; letter-spacing: .01em; font-family: var(--mono); }
.cab-sub { display: block; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cab.following .cab-sub { cursor: pointer; }
.cab-ib { width: 40px; height: 40px; flex: none; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; font-size: 22px; line-height: 1; color: var(--muted); }
.cab-ib svg { width: 20px; height: 20px; fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.cab-ib.off svg { stroke: var(--faint); }
.cab-expand { display: none; }
.cab-note { margin: 0 16px 6px; color: #e9c47a; font-size: 11.5px; }
.cab-f { display: flex; gap: 8px; padding: 4px 16px 8px; }
.cab.following .cab-f { display: none; }
.cab-f input { flex: 1; min-width: 0; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 16px; }
.cab-f button { background: var(--blue); color: var(--on-accent); border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 700; font-size: 15px; }

.cab-alert { margin: 0 12px 8px; padding: 12px 14px; border-radius: 12px; border: 2px solid var(--amber); background: rgba(242,179,61,.12); }
.cab-alert[hidden] { display: none; }
.cab-alert.alta { border-color: var(--red); background: rgba(255,90,82,.16); animation: cabPulse 1.2s ease-in-out infinite; }
.cab-alert .ca-t { font-weight: 800; font-size: 16px; color: var(--red); letter-spacing: .02em; }
.cab-alert.media .ca-t { color: var(--amber); }
.cab-alert .ca-t small { font-weight: 600; font-size: 12px; color: var(--muted); }
.cab-alert .ca-m { font-size: 14px; margin-top: 4px; }
.cab-alert .ca-d { font-size: 11.5px; color: var(--muted); margin-top: 6px; line-height: 1.35; }
@keyframes cabPulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,90,82,0); } 50% { box-shadow: 0 0 0 6px rgba(255,90,82,.25); } }

.cab-b { flex: 1; overflow-y: auto; padding: 0 12px 20px; -webkit-overflow-scrolling: touch; }
.cab-empty, .cab-none { color: var(--muted); font-size: 13px; margin: 6px 4px 10px; }
.g-l { display: block; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; }
.g-u { display: block; color: var(--muted); font-size: 12.5px; }
.g-u s { color: var(--faint); }
.g-u i { font-style: normal; }
.cab-gauges { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.cab-gauges > div, .cab-next, .cab-near { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.g-speed b, .g-delay b { display: block; font-family: var(--mono); font-size: 40px; line-height: 1.05; font-weight: 700; letter-spacing: -.02em; }
.g-delay b { font-size: 30px; padding-top: 6px; white-space: nowrap; }
.cab-next { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; margin-bottom: 8px; }
.cab-next b { display: block; font-size: 18px; }
.cab-next-r { text-align: right; flex: none; }
.cab-next-r b { font-family: var(--mono); font-size: 22px; }
.cab-near { margin-bottom: 8px; }
.cab-near.warn { border-color: rgba(242,179,61,.55); }
.cab-near-row { display: flex; align-items: baseline; gap: 10px; }
.cab-near-row b { font-family: var(--mono); font-size: 26px; flex: none; }
.cab-near-row span { font-size: 13px; color: var(--muted); }
.cab-near-t { margin-top: 2px; color: var(--amber); font-size: 13px; font-weight: 600; }
.cab-rel { font-size: 12px; padding: 6px 10px; border-radius: 8px; margin: 6px 0; }
.cab-rel.ok { background: rgba(62,207,142,.08); color: var(--green); }
.cab-rel.low { background: rgba(255,90,82,.08); color: var(--warn-fg); }
.cab-d { border-top: 1px solid var(--line); }
.cab-d summary { cursor: pointer; padding: 12px 4px; font-weight: 600; font-size: 14px; list-style: none; display: flex; align-items: center; gap: 6px; }
.cab-d summary::-webkit-details-marker { display: none; }
.cab-d summary::before { content: '▸'; color: var(--faint); transition: transform .15s; }
.cab-d[open] summary::before { transform: rotate(90deg); }
.cab-d summary small { color: var(--faint); font-weight: 400; }
.cab-l { list-style: none; margin: 0 0 8px; padding: 0 4px; }
.cab-l li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.cab-l li:last-child { border-bottom: 0; }
.cab-l small { color: var(--muted); }
.cab-close { margin-top: 3px; font-size: 12.5px; color: var(--blue); }
.cab-close.warn { color: var(--amber); font-weight: 600; }
.cab .tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--panel-2); border: 1px solid var(--line); margin-right: 4px; }
.cab .tag.c-red { color: var(--red); border-color: rgba(255,90,82,.4); }
.cab .tag.c-amber { color: var(--amber); border-color: rgba(242,179,61,.4); }
.cab .c-red { color: var(--red); } .cab .c-amber { color: var(--amber); } .cab .c-green { color: var(--green); }
.cab-strip { width: 100%; height: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; margin: 0 0 4px; display: block; }
.cab-strip .trk { fill: #4a6390; }
.cab-strip .tick { stroke: var(--faint); stroke-width: 1; }
.cab-strip .lbl { fill: var(--muted); font-size: 10px; text-anchor: middle; font-family: var(--sans); }
.cab-strip .lbl.l { text-anchor: start; font-size: 10.5px; }
.cab-strip .st { fill: #8c9ab3; }
.cab-strip .me { fill: var(--blue); stroke: #fff; stroke-width: 1.5; }
.cab-strip .ot circle { stroke: #0b111c; stroke-width: 1.5; fill: var(--grey); }
.cab-strip .ot.mismo circle { fill: var(--amber); } .cab-strip .ot.contrario circle { fill: var(--green); } .cab-strip .ot.parado circle { fill: var(--red); }
.cab-strip .ot.est circle { fill-opacity: .15; stroke: var(--amber); stroke-width: 2; stroke-dasharray: 3 2; }
.cab-strip .ot-l { fill: var(--text); font-size: 10px; text-anchor: middle; font-family: var(--mono); }
.cab-strip .hz circle { fill: rgba(242,179,61,.2); stroke: var(--amber); stroke-width: 1.5; }
.cab-strip .hz text { fill: var(--amber); font-size: 12px; font-weight: 800; text-anchor: middle; }
.cab-strip .hz.alto circle { fill: rgba(255,90,82,.2); stroke: var(--red); } .cab-strip .hz.alto text { fill: var(--red); }
.cab-strip .lg-me { fill: var(--blue); } .cab-strip .lg-s { fill: var(--amber); } .cab-strip .lg-c { fill: var(--green); } .cab-strip .lg-p { fill: var(--red); } .cab-strip .lg-h { fill: var(--amber); font-weight: 800; }
.cab-foot { color: var(--faint); font-size: 11px; margin: 12px 4px 0; line-height: 1.4; }

@media (max-width: 760px) {
  /* Móvil: panel inferior que deja ver el tren; botón para pantalla completa */
  .cab { top: auto; width: 100vw; height: 66dvh; border-left: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 32px var(--shadow); animation: cabUp .2s ease-out; }
  .cab.full { top: 0; height: 100dvh; border-radius: 0; }
  .cab.alarm { border-top: 3px solid var(--red); }
  .cab-expand { display: grid; }
  .cab-h { padding: 10px 10px 6px 14px; }
  .cab-title b { font-size: 19px; }
  .cab-note { margin: 0 14px 6px; }
  .cab-b { padding: 0 10px calc(16px + env(safe-area-inset-bottom)); }
  .g-speed b { font-size: 44px; }
  .cab-btn span { display: none; }
  .cab-btn { padding: 6px; }
  body.cab-open .card, body.cab-open .sheet { display: none !important; }
}
@media (max-width: 760px) and (max-height: 600px) { .cab { height: 82dvh; } }
@keyframes cabUp { from { transform: translateY(30px); opacity: .4; } to { transform: none; opacity: 1; } }

/* ── Ficha del tren: acciones principales ───────────────────── */
.card-cta { display: grid; grid-template-columns: 1.4fr 1fr; gap: 8px; margin: 10px 0 8px; }
.card-cta button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 10px; padding: 10px 12px; font-weight: 700; font-size: 14px; border: 1px solid var(--line); min-height: 42px; }
.cta-cab { background: var(--blue); color: var(--on-accent); border-color: var(--blue) !important; }
.cta-cab svg { width: 18px; height: 18px; fill: none; stroke: var(--on-accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.cta-more { background: var(--panel-2); color: var(--text); }
.card-alert { margin: 0 0 8px; padding: 8px 10px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--red); background: rgba(255,90,82,.10); border: 1px solid rgba(255,90,82,.4); }
.card-alert.media { color: var(--amber); background: rgba(242,179,61,.10); border-color: rgba(242,179,61,.4); }
.card-alert .linkbtn { font-weight: 700; color: inherit; text-decoration: underline; }
.card-anom { margin: 0 0 8px; padding: 6px 10px; border-radius: 8px; font-size: 12.5px; color: var(--amber); background: rgba(242,179,61,.08); }
.card-anom.desviado { color: var(--warn-fg); background: rgba(255,90,82,.08); }

/* ── Barra de alerta de alcance (modo normal) ───────────────── */
.alertbar { position: absolute; z-index: 650; left: 12px; right: 12px; max-width: 720px; margin: 0 auto; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px; background: var(--alert-red-bg); border: 2px solid var(--red); box-shadow: 0 10px 28px var(--shadow); backdrop-filter: blur(6px); }
.alertbar[hidden] { display: none; }
.alertbar.media { background: var(--alert-amber-bg); border-color: var(--amber); }
.alertbar.alta { animation: cabPulse 1.4s ease-in-out infinite; }
.ab-ic { font-size: 22px; color: var(--red); flex: none; }
.alertbar.media .ab-ic { color: var(--amber); }
.ab-tx { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.ab-tx b { font-size: 14px; }
.ab-tx span { font-size: 13px; color: var(--text); }
.ab-tx small { font-size: 11px; color: var(--muted); line-height: 1.3; }
.ab-act { display: flex; gap: 6px; flex: none; }
.ab-act button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-weight: 700; font-size: 13px; }
.ab-act .ab-x { padding: 8px 10px; color: var(--muted); }
/* El latido va en un pseudo-elemento: Leaflet posiciona el marcador con transform y no se puede animar ese mismo transform */
.conf-pulse { position: relative; }
.conf-pulse::after { content: ''; position: absolute; inset: 0; border-radius: 50%; background: rgba(255,90,82,.35); border: 2px solid var(--red); animation: confPulse 1.4s ease-out infinite; }
.conf-pulse.media::after { background: rgba(242,179,61,.3); border-color: var(--amber); }
@keyframes confPulse { 0% { transform: scale(.6); opacity: 1; } 100% { transform: scale(1.6); opacity: 0; } }

/* ── Panel de capas ──────────────────────────────────────────── */
.layers-ctl { position: relative; }
.layers-btn { width: 40px; height: 40px; display: grid; place-items: center; background: var(--panel) !important; border: 1px solid var(--line) !important; border-radius: 10px !important; }
.layers-btn svg { width: 20px; height: 20px; fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linejoin: round; }
.layers-btn[aria-expanded="true"] { border-color: var(--blue) !important; }
.layers-panel { position: absolute; right: 0; top: 46px; width: 440px; max-width: calc(100vw - 24px); max-height: 60vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 6px 8px; box-shadow: 0 12px 32px var(--shadow); color: var(--text); z-index: 1000; }
.layers-panel[hidden] { display: none; }
.lp-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 4px; }
.lp-h { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 10px 3px; font-weight: 600; }
.lp-row { display: flex; align-items: center; gap: 9px; padding: 6px 10px; font-size: 13px; line-height: 1.25; cursor: pointer; border-radius: 8px; }
.lp-row:hover { background: var(--panel-2); }
.lp-row input { width: 16px; height: 16px; accent-color: var(--blue); flex: none; margin: 0; }
.lp-foot { display: grid; grid-template-columns: 1fr 1fr; gap: 0 4px; margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--line); }
.lp-foot > div:only-child { grid-column: 1 / -1; }
.lp-base[hidden] { display: none; }
.lp-seg { display: flex; gap: 2px; margin: 2px 10px 4px; padding: 2px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2); }
.lp-seg label { flex: 1; cursor: pointer; }
.lp-seg input { position: absolute; opacity: 0; pointer-events: none; }
.lp-seg span { display: block; text-align: center; padding: 6px 6px; border-radius: 7px; font-size: 12.5px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.lp-seg input:checked + span { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px var(--shadow); }
.lp-seg input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 1px; }
.lp-note { font-size: 11.5px; color: var(--faint); padding: 4px 10px 2px; line-height: 1.35; }

@media (max-width: 760px) {
  .card-cta button { min-height: 44px; font-size: 14.5px; }
  .alertbar { left: 8px; right: 8px; padding: 8px 10px; gap: 8px; flex-wrap: wrap; }
  .ab-tx small { display: none; }
  .ab-act { width: 100%; }
  .ab-act button { flex: 1; padding: 9px 8px; }
  .ab-act .ab-x { flex: 0 0 44px; }
  .layers-panel { position: fixed; right: 8px; left: 8px; top: auto; bottom: calc(var(--sheet-visible, 0px) + 12px); width: auto; max-height: 60dvh; }
  .lp-row { padding: 9px 10px; font-size: 13.5px; }
}
/* La ficha del tren baja si hay una alerta visible (escritorio) */
@media (min-width: 761px) {
  body.has-alert .card { top: calc(128px + var(--alert-h, 0px)); max-height: calc(100% - 140px - var(--alert-h, 0px)); overflow-y: auto; }
  .card-cta { grid-template-columns: 1.5fr 1fr; }
  .card-cta button { font-size: 13.5px; white-space: nowrap; padding: 9px 10px; }
}
@media (max-width: 760px) {
  .alertbar { right: 60px; }
  body.cab-open .alertbar { display: none; }
}

/* ── Formulario de colaboración en Trenalito ─────────────────── */
.tl-collab { width: 100%; }
.collab-f { display: flex; flex-direction: column; gap: 8px; }
.collab-f label { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--muted); }
.collab-f input, .collab-f select, .collab-f textarea { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 14px; }
.collab-f .chk { flex-direction: row; align-items: flex-start; gap: 8px; }
.collab-f .chk input { margin-top: 2px; accent-color: var(--blue); }
.collab-f .hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.collab-f button { background: var(--blue); color: var(--on-accent); border: 0; border-radius: 8px; padding: 9px 14px; font-weight: 700; align-self: flex-start; }
.collab-f button:disabled { opacity: .6; }
.collab-st { margin: 0; font-size: 12.5px; color: var(--amber); }
.tl-msg.tl-collab { max-width: 100%; }

/* ── Menú al pulsar un tren ──────────────────────────────────── */
.train-menu .leaflet-popup-content-wrapper { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 32px var(--shadow); padding: 0; }
.train-menu .leaflet-popup-content { margin: 12px 14px; font: 14px/1.4 var(--sans); }
.train-menu .leaflet-popup-tip { background: var(--panel); border: 1px solid var(--line); }
.train-menu a.leaflet-popup-close-button { color: var(--muted); font-size: 22px; width: 32px; height: 32px; top: 4px; right: 4px; }
.tm-h { display: flex; align-items: center; gap: 8px; padding-right: 22px; }
.tm-h b { font-size: 16px; font-family: var(--mono); }
.tm-h .est { font-size: 10.5px; font-weight: 700; color: var(--amber); border: 1px solid rgba(242,179,61,.5); border-radius: 4px; padding: 0 5px; }
.tm-r { color: var(--muted); font-size: 12.5px; margin: 2px 0 10px; }
.tm-d.red { color: var(--red); } .tm-d.amber { color: var(--amber); } .tm-d.green { color: var(--green); }
.tm-a { color: var(--red); font-size: 12.5px; font-weight: 600; margin: -4px 0 10px; }
.tm-b { display: grid; grid-template-columns: 1fr; gap: 8px; }
.tm-b button { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; border-radius: 10px; font-weight: 700; font-size: 14.5px; border: 1px solid var(--line); cursor: pointer; }
.tm-cab { background: var(--blue); color: var(--on-accent); border-color: var(--blue) !important; }
.tm-cab svg { width: 18px; height: 18px; fill: none; stroke: var(--on-accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tm-det { background: var(--panel-2); color: var(--text); }

/* ── Campana: historial de alertas ───────────────────────────── */
.bell-btn { position: relative; flex: none; width: 38px; height: 38px; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; }
.bell-btn svg { width: 19px; height: 19px; fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.bell-btn.on { border-color: var(--red); }
.bell-btn.on svg { stroke: var(--red); }
.bell-n { position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--red); color: #fff; font-size: 11px; font-weight: 800; display: grid; place-items: center; }
.bell-n[hidden] { display: none; }
.hist-note { color: var(--muted); font-size: 12.5px; margin: 0 0 8px; }
.al-row .tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 4px; margin-right: 4px; border: 1px solid var(--line); }
.al-row .tag.c-red { color: var(--red); border-color: rgba(255,90,82,.45); background: rgba(255,90,82,.08); }
.al-row .tag.c-amber { color: var(--amber); border-color: rgba(242,179,61,.45); background: rgba(242,179,61,.08); }
.al-row b { display: block; margin-top: 3px; }

/* Menú del tren: tres opciones */
.tm-b2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tm-det svg { width: 17px; height: 17px; fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tm-a.amber { color: var(--amber); }
@media (max-width: 760px) {
  .bell-btn { width: 44px; height: 44px; }
}

/* Esquema de vía de la cabina: escala y agrupación */
.cab-strip-w { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; margin: 0 0 4px; padding: 6px 6px 4px; }
.cab-strip-w .cab-strip { border: 0; margin: 0; background: transparent; }
.cab-scale { display: flex; gap: 4px; justify-content: flex-end; flex-wrap: wrap; }
.cab-scale button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; font-size: 11.5px; color: var(--muted); min-height: 28px; }
.cab-scale button.on { color: var(--on-accent); background: var(--blue); border-color: var(--blue); font-weight: 700; }
.cab-legend { font-size: 11px; color: var(--muted); padding: 2px 6px; line-height: 1.6; }
.cab-legend span { font-weight: 800; margin-left: 4px; }
.cab-legend .lg-me { color: var(--blue); margin-left: 0; } .cab-legend .lg-s { color: var(--amber); } .cab-legend .lg-c { color: var(--green); } .cab-legend .lg-p { color: var(--red); } .cab-legend .lg-h { color: var(--amber); }
.cab-strip .ot.mixto circle { fill: #8b95a7; }
.cab-strip .ot.cl circle { stroke: #fff; stroke-width: 1.5; }
.cab-strip .cl-n { fill: var(--on-accent); font-size: 10.5px; font-weight: 800; text-anchor: middle; font-family: var(--sans); pointer-events: none; }
/* Con el menú de un tren abierto, la barra de alerta se aparta y no captura pulsaciones */
body.tm-open .alertbar { visibility: hidden; }

/* Menú del tren en móvil: panel inferior */
.tm-sheet { position: fixed; z-index: 1300; left: 0; right: 0; bottom: 0; background: var(--panel); border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0; box-shadow: 0 -14px 34px var(--shadow); padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); animation: cabUp .18s ease-out; }
.tm-sheet[hidden] { display: none; }
.tm-grip { width: 42px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 10px; }
.tm-x { position: absolute; top: 10px; right: 10px; width: 40px; height: 40px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); font-size: 22px; line-height: 1; }
.tm-sheet .tm-h b { font-size: 18px; }
.tm-sheet .tm-b button { min-height: 50px; font-size: 15.5px; }
body.tm-open .sheet { visibility: hidden; }
body.tm-open .tl-fab { display: none; }

/* Perfil del terreno en la cabina */
.cab-prof { display: block; width: 100%; height: auto; margin-top: -6px; }
.cab-prof .pf-area { fill: rgba(90,169,255,.14); }
.cab-prof .pf-line { fill: none; stroke: #7fb6ff; stroke-width: 1.6; stroke-linejoin: round; }
.cab-prof .pf-me { stroke: var(--blue); stroke-width: 1.5; stroke-dasharray: 3 3; }
.cab-prof .pf-band.rampa { fill: rgba(242,179,61,.18); }
.cab-prof .pf-band.pendiente { fill: rgba(62,207,142,.16); }
.cab-prof .lbl { fill: var(--faint); font-size: 9.5px; font-family: var(--sans); }
.cab-scale { align-items: center; }
.cab-grade { margin-right: auto; font-size: 12.5px; font-weight: 700; color: var(--muted); padding-left: 4px; }
.cab-grade.up { color: var(--amber); } .cab-grade.down { color: var(--green); }
.cab-legend .lg-r { color: rgba(242,179,61,.8); } .cab-legend .lg-d { color: rgba(62,207,142,.8); }
@media (max-width: 760px) {
  .cab-scale { gap: 3px; }
  .cab-grade { flex-basis: 100%; padding: 0 2px 4px; }
  .cab-scale button { padding: 3px 7px; font-size: 11px; }
}

/* ── Vista 3D de cabina ──────────────────────────────────────── */
.cab-3dbtn { font-weight: 800; font-size: 13px; color: var(--text); width: auto; padding: 0 10px; }
.cab-3dbtn.on { background: var(--blue); color: var(--on-accent); border-color: var(--blue); }
.cab-3d { position: relative; height: 300px; margin: 0 12px 8px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: #0b111c; flex: none; }
.cab-3d[hidden] { display: none; }
.c3d-msg { color: var(--muted); font-size: 13px; padding: 16px; margin: 0; }
.c3d-me { width: 34px; height: 34px; filter: drop-shadow(0 2px 4px var(--shadow)); }
.c3d-me svg { width: 100%; height: 100%; fill: var(--blue); stroke: #fff; stroke-width: 2.5; stroke-linejoin: round; }
.c3d-lbl { background: var(--glass); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; font: 600 11px/1.25 var(--sans); color: var(--text); white-space: nowrap; pointer-events: none; text-align: center; }
.c3d-lbl small { display: block; font-weight: 400; color: var(--muted); font-size: 10px; }
.c3d-lbl.conf { border-color: var(--red); color: var(--err-fg); }
.c3d-follow { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 2; display: none; background: var(--blue); color: var(--on-accent); border: 0; border-radius: 999px; padding: 8px 14px; font-weight: 700; font-size: 13px; box-shadow: 0 6px 16px rgba(0,0,0,.4); }
.cab-3d.free .c3d-follow { display: block; }
.cab-3d .maplibregl-ctrl-attrib { font-size: 10px; background: var(--glass); color: var(--muted); }
.cab-3d .maplibregl-ctrl-attrib a { color: var(--muted); }
.cab-3d .maplibregl-ctrl-group { background: var(--panel); }
.cab-3d .maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1) brightness(1.4); }
@media (min-width: 761px) { .cab.with3d { width: 520px; } .cab.with3d .cab-3d { height: 340px; } }
@media (max-width: 760px) { .cab.with3d .cab-3d { height: 44dvh; margin: 0 8px 8px; } }

/* Silenciar avisos */
.alertbar { flex-wrap: wrap; }
.ab-sil { flex-basis: 100%; display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); padding-left: 32px; cursor: pointer; user-select: none; }
.ab-sil input, .al-sil input { width: 16px; height: 16px; accent-color: var(--amber); margin: 0; }
.al-sil { display: inline-flex; align-items: center; gap: 5px; margin-left: 10px; font-size: 12px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tag.sil { background: rgba(140,154,179,.18); color: var(--muted); }
@media (max-width: 760px) { .ab-sil { padding-left: 0; padding-top: 2px; } .al-sil { margin: 6px 0 0; display: flex; } }

/* Créditos */
.cred-btn svg { width: 20px; height: 20px; }
.cr-notice { background: rgba(90,169,255,.08); border: 1px solid rgba(90,169,255,.3); border-radius: 10px; padding: 10px 12px; margin: 4px 0 12px; }
.cr-author { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; }
.cr-author b { font-size: 15px; } .cr-author span { color: var(--muted); font-size: 13px; }
.cr-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.cr-list li { display: flex; flex-direction: column; gap: 1px; padding: 9px 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; }
.cr-list span { color: var(--muted); font-size: 13px; } .cr-list small { color: var(--muted); font-size: 12px; }
.cr-author a, .cr-list a { color: var(--blue, #5aa9ff); text-decoration: none; }
.cr-author a:hover, .cr-list a:hover { text-decoration: underline; }
.cr-list b a { color: var(--text); text-decoration: underline; text-decoration-color: rgba(90,169,255,.6); text-underline-offset: 3px; }
.modal-box a { color: var(--blue); }

.ab-sils { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 4px 18px; padding-left: 32px; }
.ab-sils .ab-sil { flex-basis: auto; padding: 0; }
.al-all { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 9px 12px; margin: 4px 0 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); font-size: 13px; cursor: pointer; }
.al-all input { width: 17px; height: 17px; accent-color: var(--amber); margin: 0; }
.al-all.on { border-color: var(--amber); }
.al-all small { color: var(--muted); }
.bell-btn.muted { border-style: dashed; }
.bell-btn.muted::after { content: ''; position: absolute; width: 24px; height: 2px; background: var(--muted); transform: rotate(-45deg); border-radius: 2px; }
.bell-btn.muted.on::after { background: var(--red); }
@media (max-width: 760px) { .ab-sils { padding-left: 0; gap: 2px 14px; } }

/* Botón de tema */
.theme-btn svg { width: 19px; height: 19px; }
.theme-btn .i-sun { display: none; }
:root[data-theme="dark"] .theme-btn .i-sun { display: block; }
:root[data-theme="dark"] .theme-btn .i-moon { display: none; }
/* Ajustes del tema claro */
.cab { color: var(--text); }

/* Trenes según horario oficial (sin datos en vivo) */
.dot.sched { background: transparent; border: 2px dashed var(--grey); width: 10px; height: 10px; }
.est.sch { color: var(--muted); border-color: var(--line); }
.card-sched { margin: 0 0 8px; padding: 7px 10px; border-radius: 8px; font-size: 12.5px; color: var(--muted); background: var(--panel-2); border: 1px dashed var(--line); }

.tm-d.none, dd.muted { color: var(--muted) !important; font-weight: 500; }
.card.c-none { border-left-color: var(--grey); }
.lang-btn { font-weight: 800; font-size: 12.5px; letter-spacing: .02em; color: var(--text); }

/* Vista de andén: botón de la barra superior y ventana de las estaciones del mapa */
a.and-btn { color: var(--text); text-decoration: none; }
.st-pop { display: grid; gap: 8px; min-width: 170px; font: 13px var(--sans); }
.st-pop b { font-size: 14px; }
.st-pop-btn { display: inline-flex; justify-content: center; min-height: 36px; align-items: center; padding: 0 12px; border-radius: 9px; background: var(--blue); color: var(--on-accent) !important; text-decoration: none; font-weight: 700; }
.slabel.leaflet-interactive { cursor: pointer; }
/* En móvil el botón de créditos deja sitio al de la vista de andén (los créditos siguen en «Leyenda» → pie) */
@media (max-width: 1500px) { a.and-btn span { display: none; } a.and-btn { padding: 6px; } }
@media (max-width: 760px) { .cred-btn { display: none; } }

/* ── Indemnización orientativa y «Sigue mi tren» (public/compensation.js, public/follow.js) ── */
.comp { margin: 10px 0 2px; border: 1px solid color-mix(in srgb, var(--green) 45%, var(--line)); background: color-mix(in srgb, var(--green) 9%, var(--panel)); border-radius: 10px; font-size: 12.5px; color: var(--text); }
.comp summary { display: flex; align-items: center; gap: 8px; padding: 7px 10px; cursor: pointer; list-style: none; line-height: 1.35; }
.comp summary::-webkit-details-marker { display: none; }
.comp-i { flex: none; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: var(--green); color: #fff; font-weight: 700; font-size: 11px; }
.comp-q { margin-left: auto; color: var(--muted); }
.comp ul { margin: 0; padding: 0 12px 9px 34px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.comp li + li { margin-top: 3px; }
.cab .comp { margin: 8px 0; }
.fol-btn.on, .tm-fol.on { border-color: var(--blue) !important; color: var(--blue) !important; }
.tm-fol { width: 100%; margin-top: 6px; padding: 8px 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font-weight: 600; font-size: 13px; cursor: pointer; }
.cab-fol.on { background: var(--blue); color: #fff; }
.fol-chips { position: fixed; z-index: 1150; left: 244px; top: 64px; display: flex; flex-wrap: wrap; gap: 6px; max-width: calc(100vw - 680px); pointer-events: none; }
.fol-chips[hidden] { display: none; }
.fol-chip { display: inline-flex; align-items: center; pointer-events: auto; background: var(--panel); border: 1px solid var(--blue); border-radius: 999px; box-shadow: 0 4px 14px var(--shadow); overflow: hidden; }
.fol-chip button { background: none; border: 0; color: var(--text); font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; padding: 6px 4px 6px 10px; }
.fol-chip .fol-chip-x { padding: 6px 10px 6px 6px; color: var(--muted); font-size: 15px; line-height: 1; }
.fol-toasts { position: fixed; z-index: 4500; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; max-width: min(360px, calc(100vw - 32px)); }
.fol-toast { position: relative; display: flex; flex-direction: column; gap: 2px; padding: 10px 34px 10px 12px; border-radius: 12px; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-left: 4px solid var(--blue); box-shadow: 0 12px 32px var(--shadow); font-size: 13px; }
.fol-toast span { color: var(--muted); }
.fol-toast button { position: absolute; top: 6px; right: 6px; background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }
.fol-back { position: fixed; inset: 0; z-index: 4000; display: grid; place-items: center; padding: 16px; background: var(--backdrop, rgba(20, 30, 45, .45)); }
.fol-dlg { width: min(400px, 100%); background: var(--modal-bg, var(--panel)); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.fol-dlg h3 { margin: 0 0 4px; font-size: 17px; }
.fol-sub, .fol-note { margin: 0 0 10px; color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.fol-note { margin: 10px 0 0; }
.fol-row { display: flex; align-items: center; gap: 10px; padding: 8px 2px; font-size: 14px; border-bottom: 1px solid var(--line); }
.fol-row input { width: 18px; height: 18px; accent-color: var(--blue); flex: none; }
.fol-row span { flex: 1; }
.fol-row select { max-width: 48%; padding: 5px 6px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: inherit; font-size: 13px; }
.fol-b { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.fol-b button { min-height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.fol-b .fol-ok { background: var(--blue); border-color: var(--blue); color: var(--on-accent, #fff); }
.fol-b .fol-stop { margin-right: auto; color: var(--red); background: none; border-color: color-mix(in srgb, var(--red) 50%, var(--line)); }
@media (max-width: 760px) {
  .fol-chips { left: 8px; right: 8px; top: auto; max-width: none; bottom: calc(var(--sheet-visible, 0px) + 74px); }
  .fol-toasts { left: 12px; right: 12px; max-width: none; top: 112px; bottom: auto; }
  .fol-dlg { align-self: end; border-radius: 16px 16px 12px 12px; }
}
body.an-page .fol-chips { left: auto; right: 16px; top: auto; bottom: 16px; max-width: calc(100vw - 32px); justify-content: flex-end; }
body.an-page.sheet-open .fol-chips { display: none; }
/* ── fin indemnización / seguimiento ── */
/* Estado parcial: alguna fuente no responde */
.live.partial i { background: var(--amber); }
.live[title] { cursor: help; }
/* Retraso proyectado (posición frente a horario), complemento del oficial */
.proj { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 6px; font-size: 11.5px; font-weight: 700; color: var(--red); background: rgba(217,58,50,.10); border: 1px dashed currentColor; cursor: help; white-space: nowrap; }
.arr .d .proj-s { display: block; font-size: 10.5px; font-weight: 700; opacity: .85; }
.cab-near-i { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ── Enlaces en riesgo (connections.js) ─────────────────────────── */
.ln-dlg { width: min(520px, 100%); max-height: min(86vh, 760px); overflow-y: auto; }
.ln-f { display: grid; gap: 4px; margin: 10px 0; font-size: 13px; color: var(--muted); position: relative; }
.ln-f select, .ln-f input { font: inherit; font-size: 14px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; min-height: 42px; }
.ln-sug { position: absolute; z-index: 5; left: 0; right: 0; top: 100%; margin: 2px 0 0; padding: 4px; list-style: none; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 24px var(--shadow); }
.ln-sug button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; color: var(--text); font: inherit; cursor: pointer; border-radius: 7px; }
.ln-sug button:hover, .ln-sug button:focus-visible { background: var(--panel-2); }
.ln-arr { font-size: 14px; margin: 8px 0; padding: 10px 12px; border-radius: 10px; background: var(--panel-2); }
.ln-arr small { display: block; color: var(--muted); margin-top: 2px; }
.ln-d { color: var(--amber); font-weight: 600; }
.ln-list { list-style: none; margin: 6px 0; padding: 0; display: grid; gap: 6px; }
.ln-row { display: grid; grid-template-columns: 58px 1fr auto; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-left: 3px solid var(--line); border-radius: 10px; }
.ln-row.ln-safe { border-left-color: var(--green); }
.ln-row.ln-at_risk { border-left-color: var(--amber); }
.ln-row.ln-missed { border-left-color: var(--red); opacity: .85; }
.ln-time b { display: block; font: 700 15px var(--mono); }
.ln-time s { font: 12px var(--mono); color: var(--muted); }
.ln-tr b { display: block; font-size: 13.5px; }
.ln-tr small { color: var(--muted); font-size: 12px; }
.ln-chip { text-align: right; font-size: 12.5px; font-weight: 700; padding: 3px 8px; border-radius: 8px; white-space: nowrap; }
.ln-chip small { display: block; font-weight: 500; font-size: 11.5px; }
.ln-safe .ln-chip { color: var(--green); background: color-mix(in srgb, var(--green) 12%, transparent); }
.ln-at_risk .ln-chip { color: var(--amber); background: color-mix(in srgb, var(--amber) 14%, transparent); }
.ln-missed .ln-chip { color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }
.ln-h { margin: 12px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.ln-empty { color: var(--muted); font-size: 13.5px; margin: 8px 0; }
.ln-note { color: var(--faint, var(--muted)); font-size: 11.5px; line-height: 1.4; margin: 10px 0 2px; }
@media (max-width: 760px) { .ln-row { grid-template-columns: 52px 1fr; } .ln-chip { grid-column: 1 / -1; text-align: left; display: flex; gap: 8px; align-items: baseline; } .ln-chip small { display: inline; } }

/* ---- Tramos en riesgo y capas de aGIS Open Geodata ---- */
.dot.rz1 { background: #f29900; } .dot.rz2 { background: #e8590c; } .dot.rz3 { background: #d93025; }
.rz-note { grid-column: 1 / -1; margin: 0; font-size: 12px; color: var(--muted); }
.inc.rz.lvl-3 { border-left: 3px solid #d93025; } .inc.rz.lvl-2 { border-left: 3px solid #e8590c; } .inc.rz.lvl-1 { border-left: 3px solid #f29900; }
.card-rz { margin: 0 0 8px; padding: 6px 10px; border-radius: 8px; font-size: 12.5px; color: var(--amber); background: rgba(242,179,61,.08); }
.card-rz.lvl-3, .card-rz.lvl-2 { color: var(--warn-fg); background: rgba(255,90,82,.08); }
.agis-legend { position: absolute; left: 12px; bottom: 78px; z-index: 550; max-width: min(420px, calc(100% - 20px)); padding: 6px 10px; border-radius: 8px;
  background: var(--glass-2); color: var(--text); box-shadow: 0 2px 10px rgba(0,0,0,.18); font-size: 11.5px; line-height: 1.6; pointer-events: none; }
.agis-legend[hidden] { display: none; }
.agis-legend i { display: inline-block; width: 14px; height: 3px; margin: 0 4px 2px 6px; vertical-align: middle; border-radius: 2px; }
.agis-legend i.dot { width: 8px; height: 8px; border-radius: 50%; background: #fff; border: 1.5px solid #5f6368; }
.agis-legend i.dot.board { border-color: #0f9d58; }
.agis-legend .src { opacity: .7; font-size: 10.5px; }
@media (max-width: 760px) { .agis-legend { bottom: calc(var(--sheet-visible, 0px) + 12px); font-size: 11px; } }
body.card-open .agis-legend { display: none; }
/* Alertas de red de Trenalia */
.inc.na.lvl-3 { border-left: 3px solid #d93025; } .inc.na.lvl-2 { border-left: 3px solid #e8590c; } .inc.na.lvl-1 { border-left: 3px solid #f29900; }
.inc.na.ltv { border-left: 3px dashed var(--amber); }
.inc.na .reg a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
