/* NEXUS — pantalla del mapa (14-nov-2026). Solo estilos del mapa; el resto del tablero no se toca. */

#content-map { padding: 0.75rem 1rem; }

.mapa {
  --m-fondo: #1e293b;
  --m-fondo2: #0f172a;
  --m-borde: #334155;
  --m-texto: #e2e8f0;
  --m-tenue: #94a3b8;
  --m-acento: #38bdf8;
  --m-sombra: 0 6px 20px rgba(2, 6, 23, 0.45);
  --m-ok: #22c55e;
  --m-ambar: #f59e0b;
  --m-rojo: #ef4444;
  --hoja-h: 0px;
  position: relative;
  display: flex;
  gap: 0.75rem;
  height: calc(100vh - var(--mapa-top, 150px) - 12px);
  height: calc(100dvh - var(--mapa-top, 150px) - 12px);
  min-height: 320px;
  color: var(--m-texto);
  font-family: system-ui, -apple-system, sans-serif;
}
.mapa[data-tema="claro"] {
  --m-fondo: #ffffff;
  --m-fondo2: #f1f5f9;
  --m-borde: #cbd5e1;
  --m-texto: #0f172a;
  --m-tenue: #64748b;
  --m-acento: #0284c7;
  --m-sombra: 0 6px 20px rgba(15, 23, 42, 0.18);
}

.mapa-lienzo {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  border-radius: 0.75rem;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid var(--m-borde);
  background: var(--m-fondo2);
}
#map { position: absolute; inset: 0; background: var(--m-fondo2); }
.leaflet-tile-pane .nexus-dark-tiles { filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9); }
.mapa .leaflet-container { font-family: inherit; }
.mapa .leaflet-control-attribution { background: color-mix(in srgb, var(--m-fondo) 80%, transparent); color: var(--m-tenue); font-size: 10px; }
.mapa .leaflet-control-attribution a { color: var(--m-tenue); }
.mapa .leaflet-bar { border: 1px solid var(--m-borde); box-shadow: var(--m-sombra); border-radius: 0.6rem; overflow: hidden; }
.mapa .leaflet-bar a { background: var(--m-fondo); color: var(--m-texto); border-bottom-color: var(--m-borde); width: 36px; height: 36px; line-height: 36px; }
.mapa .leaflet-bar a:hover { background: var(--m-fondo2); color: var(--m-acento); }

/* ---- Fichas flotantes: sello y aviso ---- */
.mapa-arriba {
  position: absolute; z-index: 1000; top: 10px; left: 10px; right: 60px;
  display: flex; flex-wrap: wrap; gap: 6px; pointer-events: none;
}
.mapa-chip {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 999px;
  background: var(--m-fondo); color: var(--m-texto);
  border: 1px solid var(--m-borde); box-shadow: var(--m-sombra);
  font-size: 12px; font-weight: 600; line-height: 1; white-space: nowrap;
  font-variant-numeric: tabular-nums; cursor: default;
}
button.mapa-chip { cursor: pointer; }
.mapa-chip[hidden] { display: none; }
.mapa-chip .punto { width: 8px; height: 8px; border-radius: 50%; background: var(--m-tenue); flex: none; }
.mapa-chip[data-estado="ok"] .punto { background: var(--m-ok); }
.mapa-chip[data-estado="lento"] { border-color: var(--m-ambar); color: var(--m-ambar); }
.mapa-chip[data-estado="lento"] .punto { background: var(--m-ambar); }
.mapa-chip[data-estado="error"] { border-color: var(--m-rojo); color: var(--m-rojo); }
.mapa[data-tema="claro"] .mapa-chip[data-estado="lento"] { color: #b45309; }
.mapa[data-tema="claro"] .mapa-chip[data-estado="error"] { color: #b91c1c; }
.mapa-chip[data-estado="error"] .punto { background: var(--m-rojo); animation: mapa-parpadeo 1.2s infinite; }
.mapa-chip-aviso { color: var(--m-tenue); font-weight: 500; }
@keyframes mapa-parpadeo { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ---- Controles (encuadrar, tema, leyenda) ---- */
.mapa-controles {
  position: absolute; z-index: 1000; top: 10px; right: 10px;
  display: flex; flex-direction: column; gap: 8px;
}
.mapa-btn {
  width: 40px; height: 40px; border-radius: 0.6rem;
  display: flex; align-items: center; justify-content: center;
  background: var(--m-fondo); color: var(--m-texto);
  border: 1px solid var(--m-borde); box-shadow: var(--m-sombra);
  cursor: pointer; padding: 0;
}
.mapa-btn:hover { color: var(--m-acento); }
.mapa-btn[aria-pressed="true"] { color: var(--m-acento); border-color: var(--m-acento); }
.mapa-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- Leyenda ---- */
.mapa-leyenda {
  position: absolute; z-index: 1000; left: 10px; bottom: 24px;
  width: 232px; max-width: calc(100% - 20px);
  background: var(--m-fondo); border: 1px solid var(--m-borde); border-radius: 0.75rem;
  box-shadow: var(--m-sombra); padding: 10px 12px; font-size: 12px;
}
.mapa-leyenda[hidden] { display: none; }
.mapa-leyenda h4 { margin: 0 0 6px; font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--m-tenue); }
.mapa-leyenda h4:not(:first-child) { margin-top: 10px; }
.mapa-leyenda ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 5px 10px; }
.mapa-leyenda li { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.mapa-leyenda .ley-notas { grid-template-columns: 1fr; color: var(--m-tenue); }
.mapa-leyenda .ley-notas b { color: var(--m-texto); font-weight: 600; font-variant-numeric: tabular-nums; }
.ley-p { width: 14px; height: 14px; border-radius: 50%; flex: none; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.25); }
.ley-e { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.ley-v { width: 14px; height: 14px; border-radius: 50%; flex: none; border: 2px solid var(--m-rojo); background: transparent; }

/* ---- Marcadores ---- */
.mk { background: none; border: none; }
.mk-pos { position: absolute; left: 0; top: 0; transition: transform 0.2s ease; }

.mk-pedido { position: absolute; left: -15px; top: -15px; width: 30px; display: flex; flex-direction: column; align-items: center; cursor: pointer; }
.mk-pedido .bola {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--c); border: 2px solid #fff; box-shadow: 0 2px 6px rgba(2, 6, 23, 0.45);
}
.mk-pedido .bola svg { width: 16px; height: 16px; fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.mk-pedido .reloj {
  margin-top: 2px; padding: 1px 5px; border-radius: 6px;
  background: rgba(15, 23, 42, 0.88); color: #f1f5f9;
  font-size: 10.5px; font-weight: 700; line-height: 1.35; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.mk-pedido.vencido .bola { border-color: var(--m-rojo, #ef4444); animation: mapa-pulso 1.4s ease-out infinite; }
.mk-pedido.vencido .reloj { background: #dc2626; color: #fff; }
.mk-pedido.sel .bola { outline: 3px solid var(--m-acento, #38bdf8); outline-offset: 2px; }
@keyframes mapa-pulso {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.75), 0 2px 6px rgba(2, 6, 23, 0.45); }
  100% { box-shadow: 0 0 0 14px rgba(239, 68, 68, 0), 0 2px 6px rgba(2, 6, 23, 0.45); }
}

.mk-rider {
  position: absolute; left: -16px; top: -16px; height: 32px;
  display: flex; align-items: center; gap: 6px; padding-right: 10px;
  background: var(--m-fondo, #1e293b); color: var(--m-texto, #e2e8f0);
  border: 1.5px solid var(--e); border-radius: 999px;
  box-shadow: 0 2px 8px rgba(2, 6, 23, 0.45);
  font-size: 12px; font-weight: 700; line-height: 1; white-space: nowrap; cursor: pointer;
}
.mk-rider.izq { left: auto; right: -16px; flex-direction: row-reverse; padding-right: 0; padding-left: 10px; }
.mk-rider .av {
  width: 29px; height: 29px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--c); color: #fff; font-size: 13px; font-weight: 800;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
}
.mk-rider .est { width: 8px; height: 8px; border-radius: 50%; background: var(--e); flex: none; }
.mk-rider .sub { font-weight: 500; color: var(--m-tenue, #94a3b8); }
.mk-rider.viejo { opacity: 0.6; border-style: dashed; }
.mk-rider.viejo .av { filter: grayscale(0.7); }

/* ---- Popups ---- */
.mapa .leaflet-popup-content-wrapper { background: var(--m-fondo); color: var(--m-texto); border-radius: 0.75rem; border: 1px solid var(--m-borde); box-shadow: var(--m-sombra); }
.mapa .leaflet-popup-tip { background: var(--m-fondo); border: 1px solid var(--m-borde); box-shadow: none; }
.mapa .leaflet-popup-content { margin: 12px 14px; font-size: 13px; line-height: 1.45; min-width: 190px; }
.mapa .leaflet-container a.leaflet-popup-close-button { color: var(--m-tenue); }
.pp-t { font-size: 14px; font-weight: 700; margin-bottom: 4px; padding-right: 14px; overflow-wrap: anywhere; }
.pp-paso { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700; color: #fff; background: var(--c); margin-bottom: 6px; }
.pp-f { display: flex; gap: 8px; justify-content: space-between; overflow-wrap: anywhere; }
.pp-f span:first-child { color: var(--m-tenue); flex: none; }
.pp-f span:last-child { text-align: right; font-weight: 600; }
.pp-venc { color: var(--m-rojo); font-weight: 700; margin-top: 4px; }
.pp-id { margin-top: 6px; font-size: 11px; color: var(--m-tenue); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ---- Panel de pedidos ---- */
.mapa-panel {
  flex: none; width: 340px; display: flex; flex-direction: column; min-height: 0;
  background: var(--m-fondo); border: 1px solid var(--m-borde); border-radius: 0.75rem; overflow: hidden;
}
.mapa-panel-asa {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 12px 14px 10px; border: none; border-bottom: 1px solid var(--m-borde);
  background: none; color: inherit; font: inherit; text-align: left; width: 100%; cursor: default;
}
.mapa-panel-asa .agarre { display: none; }
.mapa-panel-asa .tit { font-size: 14px; font-weight: 700; }
.mapa-panel-asa .cta { font-size: 12px; color: var(--m-tenue); font-variant-numeric: tabular-nums; }
.mapa-ins { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.mapa-ins.rojo { background: rgba(239, 68, 68, 0.16); color: #f87171; }
.mapa-ins.rosa { background: rgba(219, 39, 119, 0.16); color: #f472b6; }
.mapa-ins.gris { background: color-mix(in srgb, var(--m-tenue) 18%, transparent); color: var(--m-tenue); }
.mapa[data-tema="claro"] .mapa-ins.rojo { color: #b91c1c; }
.mapa[data-tema="claro"] .mapa-ins.rosa { color: #be185d; }
.mapa-panel-cuerpo { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.mapa-panel-cuerpo::-webkit-scrollbar-track { background: transparent; }
.mapa[data-tema="claro"] .mapa-panel-cuerpo::-webkit-scrollbar-thumb { background: #cbd5e1; }

.mapa-riders { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--m-borde); }
.mapa-riders:empty { display: none; }
.rd {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 9px 0 3px;
  border-radius: 999px; border: 1px solid var(--m-borde); background: var(--m-fondo2); color: var(--m-texto);
  font: inherit; font-size: 12px; font-weight: 600; white-space: nowrap; cursor: pointer;
}
.rd .av { width: 22px; height: 22px; border-radius: 50%; background: var(--c); color: #fff; font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.rd .est { width: 7px; height: 7px; border-radius: 50%; background: var(--e); }
.rd .sub { color: var(--m-tenue); font-weight: 500; }
.rd.fuera { opacity: 0.6; border-style: dashed; cursor: default; }

.mapa-lista { padding: 6px; }
.pd {
  display: grid; grid-template-columns: 4px 1fr auto; gap: 0 10px; align-items: stretch;
  width: 100%; padding: 9px 10px 9px 6px; margin: 0 0 4px; border-radius: 0.6rem;
  border: 1px solid transparent; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.pd:hover { background: var(--m-fondo2); }
.pd.sel { background: var(--m-fondo2); border-color: var(--m-acento); }
.pd.vencido { background: rgba(239, 68, 68, 0.08); border-color: rgba(239, 68, 68, 0.45); }
.pd .barra { border-radius: 4px; background: var(--c); }
.pd .cen { min-width: 0; }
.pd .ven { font-size: 13.5px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pd .lin { margin-top: 2px; font-size: 12px; color: var(--m-tenue); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pd .lin b { font-weight: 600; color: var(--c2, var(--m-texto)); }
.pd .lin .pt { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--c); margin-right: 5px; vertical-align: 1px; }
.pd .der { text-align: right; display: flex; flex-direction: column; align-items: flex-end; justify-content: center; gap: 3px; font-variant-numeric: tabular-nums; }
.pd .t1 { font-size: 13px; font-weight: 700; white-space: nowrap; }
.pd .t2 { font-size: 11px; color: var(--m-tenue); white-space: nowrap; }
.pd.vencido .t1 { color: var(--m-rojo); }
.pd .nota { grid-column: 2 / 4; margin-top: 6px; font-size: 11.5px; color: var(--m-ambar); }
.mapa[data-tema="claro"] .pd .nota { color: #b45309; }
.mapa-vacio { padding: 28px 16px; text-align: center; color: var(--m-tenue); font-size: 13px; }

/* ---- Escritorio: zoom abajo a la derecha ---- */
.mapa .leaflet-bottom.leaflet-right { margin-bottom: 14px; }

/* ---- Móvil: mapa a toda la pantalla y panel como hoja inferior ---- */
@media (max-width: 767px) {
  #content-map { padding: 0; }
  .mapa { display: block; height: calc(100vh - var(--mapa-top, 150px)); height: calc(100dvh - var(--mapa-top, 150px)); --hoja-h: 60px; }
  .mapa-lienzo { position: absolute; inset: 0; border-radius: 0; border: none; }
  .mapa .leaflet-control-zoom { display: none; }
  .mapa .leaflet-bottom { bottom: var(--hoja-h); transition: bottom 0.25s ease; }
  .mapa.arrastrando .leaflet-bottom, .mapa.arrastrando .mapa-panel, .mapa.arrastrando .mapa-controles, .mapa.arrastrando .mapa-leyenda { transition: none; }

  .mapa-panel {
    position: absolute; z-index: 1100; left: 0; right: 0; bottom: 0; width: auto;
    height: var(--hoja-h); max-height: 100%;
    border-radius: 1rem 1rem 0 0; border-width: 1px 0 0;
    box-shadow: 0 -8px 24px rgba(2, 6, 23, 0.4);
    transition: height 0.25s ease;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .mapa-panel-asa { padding: 18px 14px 12px; position: relative; cursor: grab; touch-action: none; min-height: 60px; flex: none; }
  .mapa-panel-asa .agarre { display: block; position: absolute; top: 7px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--m-borde); }

  .mk-rider .sub.txt { display: none; }
  .mapa-controles { top: auto; right: 12px; bottom: calc(var(--hoja-h) + 30px); gap: 10px; transition: bottom 0.25s ease, opacity 0.2s; }
  .mapa-btn { width: 46px; height: 46px; border-radius: 50%; }
  .mapa-arriba { right: 10px; }
  .mapa-leyenda { left: 10px; bottom: calc(var(--hoja-h) + 14px); width: auto; right: 70px; max-width: 250px; transition: bottom 0.25s ease, opacity 0.2s; }
  .mapa[data-hoja="alta"] .mapa-controles, .mapa[data-hoja="alta"] .mapa-leyenda { opacity: 0; pointer-events: none; }
  .pd { padding: 11px 10px 11px 6px; }
  .rd { height: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  .mk-pedido.vencido .bola, .mapa-chip[data-estado="error"] .punto { animation: none; }
  .mk-pos, .mapa-panel, .mapa-controles { transition: none; }
}
