/* La vista «Mapa» de la Oficina (mapa.js): una cartografía sobria de Arahal, en claro u oscuro desde los tokens de app.css. El color de
   verdad solo lo llevan los estados (locales) y cada repartidor (su color propio); el mapa es gris neutro para que no compita. */
.mapa {
  --mp-campo: color-mix(in srgb, var(--fg) 3%, var(--bg));
  --mp-suelo: color-mix(in srgb, var(--fg) 5%, var(--bg));
  --mp-manzana: color-mix(in srgb, var(--fg) 8%, var(--bg));
  --mp-edificio: color-mix(in srgb, var(--fg) 14%, var(--bg));
  --mp-edificio-borde: color-mix(in srgb, var(--fg) 21%, var(--bg));
  --mp-verde: color-mix(in srgb, var(--ok) 17%, var(--bg));
  --mp-agua: color-mix(in srgb, #3D7FD9 20%, var(--bg));
  --mp-calle: var(--surface);
  --mp-calle-borde: color-mix(in srgb, var(--fg) 17%, var(--bg));
  --mp-principal: var(--surface);
  --mp-principal-borde: color-mix(in srgb, var(--fg) 32%, var(--bg));
  --mp-peatonal: color-mix(in srgb, var(--fg) 3%, var(--surface));
  --mp-camino: color-mix(in srgb, var(--fg) 15%, var(--bg));
  --mp-tren: color-mix(in srgb, var(--fg) 42%, var(--bg));
  --mp-rotulo: color-mix(in srgb, var(--fg) 64%, var(--bg));
  --mp-halo: var(--surface);
  --mp-superficie: var(--surface);
  --mp-insignia-texto: #FFFFFF;
  --mp-cerrado: color-mix(in srgb, var(--fg) 34%, var(--bg));
}
@media (prefers-color-scheme: dark) {
  .mapa {
    --mp-campo: color-mix(in srgb, var(--fg) 2%, var(--bg));
    --mp-suelo: color-mix(in srgb, var(--fg) 4%, var(--bg));
    --mp-manzana: color-mix(in srgb, var(--fg) 7%, var(--bg));
    --mp-edificio: color-mix(in srgb, var(--fg) 12%, var(--bg));
    --mp-edificio-borde: color-mix(in srgb, var(--fg) 17%, var(--bg));
    --mp-verde: color-mix(in srgb, var(--ok) 13%, var(--bg));
    --mp-agua: color-mix(in srgb, #3D7FD9 24%, var(--bg));
    --mp-calle: color-mix(in srgb, var(--fg) 19%, var(--bg));
    --mp-calle-borde: var(--bg);
    --mp-principal: color-mix(in srgb, var(--fg) 30%, var(--bg));
    --mp-principal-borde: var(--bg);
    --mp-peatonal: color-mix(in srgb, var(--fg) 13%, var(--bg));
    --mp-camino: color-mix(in srgb, var(--fg) 12%, var(--bg));
    --mp-tren: color-mix(in srgb, var(--fg) 34%, var(--bg));
    --mp-rotulo: color-mix(in srgb, var(--fg) 66%, var(--bg));
    --mp-halo: color-mix(in srgb, var(--fg) 6%, var(--bg));
    --mp-superficie: var(--surface);
    --mp-insignia-texto: var(--bg);
    --mp-cerrado: color-mix(in srgb, var(--fg) 30%, var(--bg));
  }
}

/* El lienzo: canvas de la cartografía, canvas de las líneas y, encima, los marcadores en HTML (texto nítido, botones con teclado) */
.mapa-lienzo { position: relative; height: clamp(380px, 64vh, 760px); border-radius: 14px; overflow: hidden; border: 1px solid var(--line); box-shadow: var(--shadow); background: var(--mp-campo); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; cursor: grab; line-height: 1.2; }
.mapa-lienzo.arrastrando { cursor: grabbing; }
.mapa-lienzo:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mapa-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.mapa-marcas { position: absolute; inset: 0; pointer-events: none; }
.mapa-sonda { position: absolute; visibility: hidden; }
@media (max-width: 760px) { .mapa-lienzo { height: min(60vh, 520px); min-height: 340px; border-radius: 12px; } }

/* Locales: un cuadrado con el color de su estado, el número de pedidos pendientes y su nombre */
.mp-local, .mp-moto { position: absolute; left: 0; top: 0; width: 0; height: 0; padding: 0; border: 0; background: none; color: var(--fg); pointer-events: auto; will-change: transform; outline: none; }
.mp-local { --est: var(--work); z-index: 2; }
.est-necesita { --est: var(--bad); }
.est-trabajando { --est: var(--ok); }
.est-espera { --est: var(--work); }
.est-cerrado { --est: var(--mp-cerrado); }
.mp-pin { position: absolute; left: -8px; top: -8px; width: 16px; height: 16px; border-radius: 4px; background: var(--est); box-shadow: 0 0 0 2px var(--mp-superficie), 0 1px 4px rgba(0, 0, 0, .3); }
.mp-pin::after { content: ""; position: absolute; inset: 5px; border-radius: 1.5px; background: var(--mp-superficie); opacity: .9; }
.mp-num { position: absolute; left: 4px; top: -24px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--est); color: var(--mp-insignia-texto); font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; font-variant-numeric: tabular-nums; box-shadow: 0 0 0 2px var(--mp-superficie); }
.mp-et { position: absolute; left: 13px; top: -10px; height: 20px; max-width: 160px; padding: 0 7px; border-radius: 5px; background: color-mix(in srgb, var(--mp-superficie) 90%, transparent); color: var(--fg); font-size: 11.5px; font-weight: 600; line-height: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; box-shadow: 0 0 0 1px var(--line), 0 1px 2px rgba(0, 0, 0, .08); pointer-events: none; }
.mp-local.izq .mp-et { left: auto; right: 13px; }
.mp-local.sin-et .mp-et { display: none; }
.mp-local:hover .mp-et, .mp-local:focus-visible .mp-et, .mp-local.sel .mp-et { display: block; z-index: 4; }
.mp-local:hover, .mp-local:focus-visible, .mp-local.sel { z-index: 6; }
.mp-local.est-cerrado .mp-et { color: var(--muted); }
.mp-local.est-necesita .mp-et { color: var(--bad); }
.mp-local.sel .mp-pin, .mp-local:focus-visible .mp-pin { box-shadow: 0 0 0 2px var(--mp-superficie), 0 0 0 4.5px var(--accent); }
.mp-local.late .mp-pin { animation: mp-late .8s ease 2; }
@keyframes mp-late { 40% { transform: scale(1.35); } }

/* Repartidores: su foto (o iniciales) con un aro de su color, cuántos pedidos lleva, su nombre y cómo va */
.mp-moto { z-index: 3; }
.mp-moto .avatar { position: absolute; left: -16px; top: -16px; width: 32px; height: 32px; font-size: 11.5px; border: 0; color: var(--fg); background: var(--surface-2); box-shadow: 0 0 0 2.5px var(--c, var(--muted)), 0 0 0 4.5px var(--mp-superficie), 0 2px 6px rgba(0, 0, 0, .3); }
.mp-moto .mp-et { left: 0; top: 21px; transform: translateX(-50%); display: flex; align-items: center; gap: 5px; max-width: 170px; box-shadow: 0 0 0 1px color-mix(in srgb, var(--c, var(--line)) 35%, var(--line)), 0 1px 2px rgba(0, 0, 0, .08); }
.mp-moto .mp-et::before { content: ""; flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--c, var(--muted)); }
.mp-moto.sin-et .mp-et { display: none; }
.mp-moto:hover .mp-et, .mp-moto:focus-visible .mp-et, .mp-moto.sel .mp-et { display: flex; }
.mp-moto .mp-et b { font-weight: 700; }
.mp-vel { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.mp-vel:empty { display: none; }
.mp-carga { position: absolute; left: 9px; top: -24px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--fg); color: var(--mp-superficie); font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; font-variant-numeric: tabular-nums; box-shadow: 0 0 0 2px var(--mp-superficie); }
.mp-rumbo { position: absolute; left: 0; top: 0; width: 0; height: 0; pointer-events: none; }
.mp-rumbo::before { content: ""; position: absolute; left: -5px; top: -29px; border: 5px solid transparent; border-bottom: 7px solid var(--c, var(--muted)); border-top: 0; }
.mp-moto.antigua .avatar { opacity: .55; filter: grayscale(.8); }
.mp-moto.antigua .mp-et { opacity: .8; }
.mp-moto.antigua .mp-vel { color: var(--work); }
.mp-moto:hover, .mp-moto:focus-visible, .mp-moto.sel { z-index: 7; }
.mp-moto.sel .avatar, .mp-moto:focus-visible .avatar { box-shadow: 0 0 0 3px var(--c, var(--muted)), 0 0 0 5px var(--mp-superficie), 0 0 0 7px var(--accent), 0 2px 8px rgba(0, 0, 0, .35); opacity: 1; filter: none; }

/* La distancia y el código de cada entrega, junto al punto de su calle */
.mp-dest { position: absolute; left: 0; top: 0; z-index: 1; height: 20px; padding: 0 7px; border-radius: 5px; background: var(--mp-superficie); color: var(--fg); font-size: 11px; font-weight: 600; line-height: 20px; white-space: nowrap; font-variant-numeric: tabular-nums; box-shadow: 0 0 0 1px var(--line), 0 1px 2px rgba(0, 0, 0, .1); pointer-events: none; }
.mp-dest.sig { z-index: 2; font-weight: 700; background: color-mix(in srgb, var(--c, var(--accent)) 8%, var(--mp-superficie)); box-shadow: 0 0 0 1px color-mix(in srgb, var(--c, var(--accent)) 45%, var(--line)), 0 1px 3px rgba(0, 0, 0, .15); }
.mp-dest.sig::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: var(--c, var(--accent)); }
.mp-dest.tenue { opacity: .4; }

/* Lo que va encima: quién no manda la ubicación, avisos, controles y la atribución de OpenStreetMap */
.mapa-sin { position: absolute; left: 10px; top: 10px; z-index: 8; margin: 0; max-width: calc(100% - 72px); padding: 6px 10px; border-radius: 8px; background: var(--mp-superficie); border: 1px solid var(--line); color: var(--fg); font-size: 12.5px; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.mapa-sin b { color: var(--bad); font-weight: 700; }
.mapa-aviso { position: absolute; left: 50%; bottom: 30px; z-index: 8; transform: translateX(-50%); width: max-content; max-width: calc(100% - 24px); margin: 0; padding: 7px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); font-size: 12.5px; font-weight: 600; }
.mapa-controles { position: absolute; right: 10px; top: 10px; z-index: 8; display: grid; gap: 6px; }
.mapa-boton { width: 34px; height: 34px; display: grid; place-items: center; padding: 0; border-radius: 8px; border: 1px solid var(--line); background: var(--mp-superficie); color: var(--fg); box-shadow: 0 1px 3px rgba(0, 0, 0, .14); }
.mapa-boton:hover { border-color: var(--accent); color: var(--accent); }
.mapa-boton.encajar { margin-top: 4px; }
.mapa-atrib { position: absolute; right: 0; bottom: 0; z-index: 8; margin: 0; padding: 3px 8px; border-top-left-radius: 6px; background: color-mix(in srgb, var(--mp-superficie) 82%, transparent); color: var(--muted); font-size: 10.5px; line-height: 1.3; }
.mapa-frescura { font-size: 12.5px; color: var(--muted); }
.mapa-frescura.mal { color: var(--bad); font-weight: 600; }

/* Panel de detalle: la ubicación del repartidor y la leyenda */
.mp-ficha { display: grid; gap: 6px; }
.mp-ficha .apoyo.mal { color: var(--bad); }
.mp-ley { display: inline-block; width: 11px; height: 11px; border-radius: 3px; background: var(--est); }

@media (max-width: 480px) {
  .mapa-frescura { order: 3; width: 100%; }
  .mp-et { font-size: 11px; max-width: 120px; }
  .mp-moto .mp-et { max-width: 130px; }
}
@media (prefers-reduced-motion: reduce) { .mp-local.late .mp-pin { animation: none; } }
