/* M161 - Interfaz móvil operativa.
   Una sola pantalla inicial: Escudo + botón principal.
   Todos los controles son position:fixed y no pertenecen a Leaflet. */
.mobile-ui { display: none; }

@media (max-width: 760px) {
  :root {
    --mobile-bottom: max(14px, env(safe-area-inset-bottom));
    --mobile-right: max(13px, env(safe-area-inset-right));
    --mobile-left: max(13px, env(safe-area-inset-left));
  }

  html, body, body.viewer-topbar-ready {
    width: 100%; height: 100%; min-height: 100%;
    overflow: hidden !important;
  }
  body.viewer-topbar-ready { display: block !important; }

  .viewer-topbar,
  .shell > .panel,
  .panel-handle,
  .filter-drawer,
  .edit-launch { display: none !important; }

  .viewer-topbar + .shell,
  .shell {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    min-height: 100dvh !important;
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
  }
  .viewer-topbar + .shell .map-area,
  .shell .map-area,
  .map-area {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 100% !important;
    border: 0 !important;
    border-radius: 0 !important;
    overflow: hidden !important;
  }
  .viewer-topbar + .shell #map,
  .shell #map,
  #map {
    width: 100% !important;
    height: 100dvh !important;
    min-height: 100dvh !important;
    border-radius: 0 !important;
  }
  .leaflet-control-zoom { display: none !important; }
  .leaflet-control-attribution {
    margin: 0 0 4px 5px !important;
    max-width: 54vw;
    font-size: 8px !important;
    line-height: 1.1;
    opacity: .48;
  }

  .mobile-ui {
    display: block !important;
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    z-index: 100000 !important;
    pointer-events: none;
    transform: none !important;
  }

  /* Impide mover el mapa en la pantalla inicial o mientras se eligen opciones. */
  .mobile-map-shield {
    position: fixed !important;
    inset: 0 !important;
    z-index: 1;
    background: transparent;
    pointer-events: none;
    touch-action: none;
  }
  .mobile-ui.is-start-screen .mobile-map-shield,
  .mobile-ui.is-menu-open .mobile-map-shield { pointer-events: auto; }

  /* ÚNICO escudo de inicio. */
  .mobile-location-hero {
    position: fixed !important;
    left: 50% !important;
    top: 42% !important;
    width: min(70vw, 300px) !important;
    height: auto !important;
    aspect-ratio: 1 / 1;
    transform: translate(-50%, -50%) !important;
    z-index: 20;
    border: 0;
    padding: 0;
    margin: 0;
    background: transparent;
    box-shadow: none;
    opacity: .92;
    cursor: pointer;
    pointer-events: auto !important;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: opacity .16s ease, visibility .16s ease, scale .16s ease;
  }
  .mobile-location-hero img {
    display: block;
    width: 100%; height: 100%;
    object-fit: contain;
    pointer-events: none;
  }
  .mobile-location-hero.is-hidden {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }
  .mobile-location-hero:active { scale: 1.025; }

  /* Menú flotante: imagen arriba de configuración, sin QR. */
  .mobile-menu-options {
    position: fixed !important;
    right: calc(var(--mobile-right) + 4px) !important;
    bottom: calc(var(--mobile-bottom) + 68px) !important;
    z-index: 60;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px) scale(.97) !important;
    transform-origin: bottom center;
    pointer-events: none;
    transition: opacity .16s ease, visibility .16s ease, transform .20s ease;
  }
  .mobile-ui.is-menu-open .mobile-menu-options {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1) !important;
    pointer-events: auto;
  }

  .mobile-action-btn {
    position: relative;
    width: 50px;
    height: 50px;
    display: grid;
    place-items: center;
    border: 0;
    padding: 0;
    margin: 0;
    background: transparent;
    box-shadow: none;
    cursor: pointer;
    pointer-events: auto;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-action-btn img {
    display: block;
    width: 100%; height: 100%;
    object-fit: contain;
    opacity: .92;
    pointer-events: none;
    filter: drop-shadow(0 3px 4px rgba(15,23,42,.15));
    transition: transform .14s ease, opacity .14s ease;
  }
  .mobile-action-btn:active img,
  .mobile-action-btn.is-active img {
    opacity: 1;
    transform: scale(1.09);
  }

  /* Etiqueta corta al presionar. */
  .mobile-action-btn::before {
    content: attr(data-label);
    position: absolute;
    right: 57px;
    top: 50%;
    transform: translateY(-50%);
    white-space: nowrap;
    padding: 6px 8px;
    border-radius: 9px;
    background: rgba(255,255,255,.94);
    color: #334155;
    border: 1px solid rgba(148,163,184,.30);
    box-shadow: 0 5px 14px rgba(15,23,42,.13);
    font: 700 10px/1 system-ui,-apple-system,"Segoe UI",sans-serif;
    opacity: 0;
    pointer-events: none;
  }
  .mobile-action-btn:active::before,
  .mobile-action-btn:focus-visible::before { opacity: 1; }

  /* Principal SIEMPRE visible e independiente de los demás controles. */
  .mobile-main-btn {
    position: fixed !important;
    right: var(--mobile-right) !important;
    bottom: var(--mobile-bottom) !important;
    width: 60px !important;
    height: 60px !important;
    z-index: 80;
    display: grid !important;
    place-items: center;
    border: 0;
    padding: 0;
    margin: 0;
    background: transparent;
    box-shadow: none;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transform: none !important;
  }
  .mobile-main-btn img {
    display: block;
    width: 100%; height: 100%;
    object-fit: contain;
    opacity: 1;
    pointer-events: none;
    filter: drop-shadow(0 4px 6px rgba(15,23,42,.18));
  }
  .mobile-main-btn:active img,
  .mobile-ui.is-menu-open .mobile-main-btn img { transform: scale(1.06); }

  /* Buscador flotante: fondo reforzado para que se lea sobre cualquier parte del mapa. */
  .mobile-search {
    position: fixed !important;
    left: var(--mobile-left) !important;
    right: calc(var(--mobile-right) + 76px) !important;
    bottom: calc(var(--mobile-bottom) + 3px) !important;
    height: 52px !important;
    z-index: 70;
    border-radius: 13px;
    /* Campo creado íntegramente con CSS: gris claro y translúcido. */
    background: rgba(96,96,98,.26);
    border: 1px solid rgba(96,96,98,.50);
    box-shadow: 0 5px 16px rgba(15,23,42,.12);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    opacity: 0;
    visibility: hidden;
    transform: translateY(9px) !important;
    pointer-events: none;
    overflow: hidden;
    transition: opacity .16s ease, visibility .16s ease, transform .18s ease;
  }
  .mobile-ui.is-menu-open .mobile-search {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) !important;
    pointer-events: auto;
  }
  .mobile-search input {
    position: absolute;
    left: 13px;
    right: 48px;
    top: 7px;
    bottom: 7px;
    width: auto;
    min-width: 0;
    border: 0 !important;
    outline: 0 !important;
    padding: 0 3px;
    background: transparent !important;
    box-shadow: none !important;
    color: #606062;
    font: 600 14px/1 system-ui,-apple-system,"Segoe UI",sans-serif;
    pointer-events: auto;
  }
  .mobile-search input::placeholder { color:#606062; opacity:.82; }

  /* Lupa reducida un 25% respecto de la versión anterior. */
  .mobile-search-btn {
    position: absolute;
    right: 7px;
    top: 9px;
    width: 34px;
    height: 34px;
    border: 0;
    padding: 0;
    margin: 0;
    background: transparent;
    box-shadow: none;
    cursor: pointer;
    pointer-events: auto;
    touch-action: manipulation;
  }
  .mobile-search-btn img {
    display:block;
    width:100%; height:100%;
    object-fit:contain;
    opacity:.92;
    pointer-events:none;
  }
  .mobile-search-btn:active img,
  .mobile-search-btn.is-loading img { transform:scale(1.08); opacity:1; }

  .mobile-toast {
    position: fixed !important;
    left: 50%;
    top: max(17px, calc(env(safe-area-inset-top) + 17px));
    z-index: 100;
    max-width: calc(100vw - 70px);
    padding: 9px 12px;
    border-radius: 12px;
    background: rgba(255,255,255,.96);
    color:#334155;
    border:1px solid rgba(148,163,184,.28);
    box-shadow:0 8px 22px rgba(15,23,42,.15);
    font:700 12px/1.25 system-ui,-apple-system,"Segoe UI",sans-serif;
    text-align:center;
    opacity:0;
    pointer-events:none;
    transform:translateX(-50%) translateY(-7px) !important;
    transition:opacity .16s ease, transform .16s ease;
  }
  .mobile-toast.is-visible { opacity:1; transform:translateX(-50%) translateY(0) !important; }

  /* Popup operativo */
  .leaflet-popup-content .popup-photo-link,
  .leaflet-popup-content .popup-row--desktop { display:none !important; }
  .leaflet-popup-content-wrapper { border-radius:16px; box-shadow:0 9px 28px rgba(15,23,42,.18); }
  .leaflet-popup-content { width:min(245px,calc(100vw - 82px)) !important; margin:11px 13px !important; color:#334155; }
  .popup-title { font-size:14px; line-height:1.2; }
  .popup-row--mobile-keep { display:block !important; }

  .popup-mobile-actions {
    display:flex;
    align-items:center;
    justify-content:center;
    gap:18px;
    margin-top:13px;
    padding-top:11px;
    border-top:1px solid rgba(96,96,98,.20);
  }
  .popup-action-btn {
    display:flex;
    align-items:center;
    justify-content:center;
    gap:8px;
    min-height:40px;
    min-width:108px;
    padding:6px 12px;
    border:0;
    border-radius:12px;
    background:rgba(96,96,98,.10);
    color:#606062;
    font:700 11px/1 system-ui,-apple-system,"Segoe UI",sans-serif;
    cursor:pointer;
    -webkit-tap-highlight-color:transparent;
  }
  .popup-action-btn img { width:28px; height:28px; object-fit:contain; display:block; }
  .popup-action-btn:active { background:rgba(96,96,98,.20); transform:scale(.98); }
  .popup-action-btn.is-disabled { opacity:.38; cursor:default; }


  /* Modales */
  .overlay-modal { z-index:200000 !important; }
  .overlay-modal__backdrop { background:rgba(15,23,42,.56); backdrop-filter:blur(2px); }
  .overlay-modal__dialog { background:#fff; color:#334155; border:0; box-shadow:0 18px 55px rgba(15,23,42,.26); }
  .overlay-modal__dialog h2,.overlay-modal__content,.overlay-modal__caption { color:#334155; }
  .overlay-modal__close { color:#64748b; background:#f1f5f9; border:0; }

  #qr-modal .overlay-modal__dialog { width:min(88vw,390px); min-height:0; max-height:86dvh; border-radius:24px; padding:18px; text-align:center; }
  .mobile-qr-image { display:block; width:min(68vw,280px); height:auto; margin:18px auto 12px; }
  .mobile-qr-link { display:block; color:#64748b; font-size:12px; font-weight:700; word-break:break-all; text-decoration:none; }

  #mobile-config-modal { place-items:end center; }
  #mobile-config-modal .overlay-modal__dialog { width:100vw; min-height:0; max-height:86dvh; margin:0; padding:15px 18px calc(18px + env(safe-area-inset-bottom)); border-radius:24px 24px 0 0; overflow-x:hidden; }
  .mobile-config-intro { margin:0 0 12px; color:#64748b; font-size:13px; line-height:1.35; }
  .mobile-config-section { padding:12px 0; border-top:1px solid #e2e8f0; }
  .mobile-config-section h3 { margin:0 0 8px; color:#334155; font-size:14px; }
  .mobile-dependency-list {
    display:grid;
    gap:8px;
    max-height:25dvh;
    overflow:auto;
    padding:4px 2px 6px;
  }
  .mobile-choice {
    display:grid;
    grid-template-columns:18px minmax(0,1fr);
    align-items:start;
    column-gap:10px;
    width:100%;
    margin:0;
    color:#475569;
    font-size:13px;
    font-weight:650;
    line-height:1.28;
    text-align:left;
  }
  .mobile-choice input[type="checkbox"],
  .mobile-choice input[type="radio"] {
    width:18px !important;
    min-width:18px !important;
    max-width:18px !important;
    height:18px !important;
    min-height:18px !important;
    padding:0 !important;
    margin:0 !important;
    box-sizing:border-box;
    accent-color:#64748b;
    align-self:start;
  }
  .mobile-choice span {
    display:block;
    min-width:0;
    width:auto;
    padding-top:1px;
    text-align:left;
    overflow-wrap:anywhere;
  }
  .mobile-config-section > .mobile-choice + .mobile-choice {
    margin-top:8px;
  }
  .mobile-config-actions { position:sticky; bottom:0; display:grid; grid-template-columns:1fr; padding-top:10px; background:linear-gradient(to bottom,rgba(255,255,255,0),#fff 25%); }
  .mobile-save-btn { min-height:46px; border:0; border-radius:14px; background:#e6e7e8; color:#334155; font-weight:850; cursor:pointer; }
  .mobile-config-note { margin:8px 0 0; color:#94a3b8; font-size:11px; line-height:1.3; }

  .mobile-config-qr-btn {
    width:100%; min-height:48px;
    display:flex; align-items:center; gap:11px;
    border:1px solid #e2e8f0;
    border-radius:13px;
    background:#f8fafc;
    color:#334155;
    padding:7px 12px;
    font:750 13px/1.2 system-ui,-apple-system,"Segoe UI",sans-serif;
    cursor:pointer;
  }
  .mobile-config-qr-btn img { width:34px; height:34px; object-fit:contain; flex:0 0 34px; }

  #photo-modal .overlay-modal__dialog--photo { width:100vw; min-height:100dvh; max-height:100dvh; padding:8px; border-radius:0; background:#0f172a; }
  #photo-modal .overlay-modal__caption { color:#e2e8f0; }
}

@media (max-width: 380px) {
  .mobile-location-hero { width:min(68vw,260px) !important; }
  .mobile-main-btn { width:58px !important; height:58px !important; }
  .mobile-menu-options { bottom:calc(var(--mobile-bottom) + 65px) !important; gap:10px; }
  .mobile-action-btn { width:47px; height:47px; }
  .mobile-search { right:calc(var(--mobile-right) + 72px) !important; height:50px !important; }
  .mobile-search-btn { width:32px; height:32px; top:9px; }
  .mobile-search input { right:45px; font-size:13px; }
}
