/* ============ VISTA CELULAR (js/movil.js) ============
   Tres pestañas abajo: Listado, Disponibilidad y Programacion. Usa los
   mismos tokens de color de styles.css, asi que sigue al modo diurno.
   Se esconde solo lo de la vista completa que no es un dialogo: los
   dialogos (generar disponibilidad, login, estado de viajes) viven dentro
   de main y tienen que seguir abriendose. */

#movil-app[hidden], #movil-volver[hidden] { display: none !important; }

body.modo-movil { padding: 0; }
body.modo-movil .encabezado-app,
body.modo-movil #menu-lateral,
body.modo-movil .tab-content,
body.modo-movil .config-warning { display: none !important; }
body.modo-movil .layout-con-sidebar { display: block; margin: 0; padding: 0; }

html:has(body.modo-movil) {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

#movil-app {
  --mv-gutter: 16px;
  --mv-radio: 12px;
  min-height: 100dvh;
  padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  color: var(--text-main);
  background: var(--bg-color);
  font-size: 15px;
}

/* ---------- cabecera ---------- */
.mv-cabecera {
  position: sticky; top: 0; z-index: 20;
  padding: calc(10px + env(safe-area-inset-top, 0px)) var(--mv-gutter) 10px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border-color);
}
.mv-cabecera-fila { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.mv-cabecera h1 { margin: 0; font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em; color: var(--header-text); }
.mv-link {
  background: none; border: 0; padding: 8px 0; color: var(--primary-color);
  font: inherit; font-size: 0.875rem; cursor: pointer;
}

.mv-seg {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 3px;
  background: var(--table-bg); border: 1px solid var(--border-color); border-radius: 10px;
}
.mv-seg button {
  min-height: 38px; border: 0; border-radius: 8px; background: transparent;
  color: var(--text-muted); font: inherit; font-size: 0.9375rem; font-weight: 600; cursor: pointer;
}
.mv-seg button[aria-pressed="true"] { background: var(--card-bg); color: var(--text-main); box-shadow: 0 1px 2px rgba(0, 0, 0, .25); }
#movil-app[data-sector="continente"] .mv-seg button[aria-pressed="true"] { color: var(--color-continente); }
#movil-app[data-sector="isla"] .mv-seg button[aria-pressed="true"] { color: var(--color-isla); }

/* ---------- cuerpo ---------- */
.mv-cuerpo { padding: 14px var(--mv-gutter) 24px; display: flex; flex-direction: column; gap: 14px; }

.mv-resumen {
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card-bg); border: 1px solid var(--border-color); border-radius: var(--mv-radio);
}
.mv-resumen > div {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0;
  padding: 10px 8px 10px 12px; border-left: 1px solid var(--line-soft);
}
.mv-resumen > div:first-child { border-left: 0; }
.mv-resumen strong { font-size: 1.25rem; font-variant-numeric: tabular-nums; line-height: 1.1; }
.mv-resumen span { font-size: 0.6875rem; color: var(--text-muted); white-space: nowrap; }
.mv-resumen .mv-alerta strong { color: var(--color-licencia); }

.mv-buscar input, .mv-campo textarea {
  width: 100%; box-sizing: border-box; font-size: 16px; /* 16px: iOS no hace zoom */
  padding: 11px 12px; color: var(--text-main); background: var(--input-bg);
  border: 1px solid var(--border-color); border-radius: 10px;
}
.mv-campo { display: flex; flex-direction: column; gap: 6px; font-size: 0.875rem; color: var(--text-muted); }
.mv-campo textarea { resize: vertical; min-height: 72px; font-family: inherit; }

.mv-grupo { display: flex; flex-direction: column; gap: 6px; }
.mv-grupo-titulo {
  display: flex; align-items: baseline; gap: 8px; margin: 4px 0 0;
  font-size: 0.8125rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted);
}
.mv-grupo-titulo span { font-weight: 600; color: var(--text-muted); opacity: .8; }
details.mv-pa > summary { cursor: pointer; list-style: none; padding: 6px 0; }
details.mv-pa > summary::-webkit-details-marker { display: none; }
details.mv-pa > summary::after { content: '▾'; margin-left: auto; }
details.mv-pa[open] > summary::after { content: '▴'; }
details.mv-pa > .mv-lista { margin-top: 6px; }

.mv-lista {
  list-style: none; margin: 0; padding: 0;
  background: var(--card-bg); border: 1px solid var(--border-color); border-radius: var(--mv-radio); overflow: hidden;
}
.mv-lista > li { padding: 10px 12px; border-top: 1px solid var(--line-soft); }
.mv-lista > li:first-child { border-top: 0; }
.mv-camion.sin-chofer .mv-patente { color: var(--text-muted); }
.mv-camion.es-inop, .mv-prog.es-inop { box-shadow: inset 3px 0 0 var(--color-licencia); }

.mv-camion-l1, .mv-camion-l2 { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mv-camion-l2 { margin-top: 3px; justify-content: space-between; font-size: 0.875rem; }
.mv-patente { font-size: 1rem; font-weight: 700; letter-spacing: .02em; font-variant-numeric: tabular-nums; }
.mv-derecha { margin-left: auto; flex-shrink: 0; }
.mv-chofer { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mv-apagado { color: var(--text-muted); }
.mv-camion-l2 > .mv-apagado { flex-shrink: 0; font-size: 0.8125rem; }
.mv-turno { font-size: 0.6875rem; font-weight: 700; color: var(--color-descanso); }
.mv-cubre {
  font-size: 0.75rem; font-weight: 600; padding: 2px 7px; border-radius: 999px;
  color: var(--color-backup); background: var(--bg-backup);
}
#movil-app .badge { font-size: 0.6875rem; }
#movil-app .badge-product { font-size: 0.6875rem; padding: 2px 7px; }

/* ---------- fecha ---------- */
.mv-fecha {
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
  background: var(--card-bg); border: 1px solid var(--border-color); border-radius: var(--mv-radio);
}
.mv-fecha-paso {
  height: 48px; border: 0; background: none; color: var(--text-main);
  font-size: 1.5rem; line-height: 1; cursor: pointer;
}
.mv-fecha-centro { position: relative; display: flex; justify-content: center; align-items: center; height: 48px; cursor: pointer; }
.mv-fecha-texto { font-size: 1rem; font-weight: 600; text-transform: none; letter-spacing: 0; color: var(--text-main); }
/* El input nativo queda encima, invisible: al tocar el texto se abre el
   calendario del telefono. */
.mv-fecha-centro input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; font-size: 16px; }

/* ---------- estado y botones ---------- */
.mv-estado {
  display: flex; flex-direction: column; gap: 3px; padding: 12px 14px;
  background: var(--card-bg); border: 1px solid var(--border-color); border-radius: var(--mv-radio);
  font-size: 0.875rem; color: var(--text-muted);
}
.mv-estado strong { color: var(--text-main); font-size: 0.9375rem; }
.mv-estado-ok { border-color: color-mix(in srgb, var(--color-titular) 45%, var(--border-color)); }
.mv-estado-ok strong { color: var(--color-titular); }

.mv-acciones { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mv-btn {
  min-height: 46px; padding: 0 14px; border-radius: 10px; cursor: pointer;
  font: inherit; font-size: 0.9375rem; font-weight: 600; white-space: nowrap;
  color: var(--text-main); background: var(--card-bg); border: 1px solid var(--border-color);
  transition: transform 120ms var(--ease-out), background-color 120ms;
}
.mv-btn-primario { color: #062027; background: var(--primary-color); border-color: var(--primary-color); }
.mv-btn:active:not(:disabled) { transform: scale(0.97); }
.mv-btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- programacion ---------- */
.mv-viajes { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.mv-viaje { padding: 8px 10px; background: var(--table-bg); border-radius: 8px; }
.mv-viaje-ruta { font-size: 0.875rem; line-height: 1.35; }
.mv-hora { display: inline-block; margin-right: 6px; font-weight: 700; color: var(--color-backup); font-variant-numeric: tabular-nums; }
.mv-flecha { color: var(--text-muted); }
.mv-viaje-pie { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; font-size: 0.8125rem; }

.mv-vacio { margin: 8px 0; color: var(--text-muted); font-size: 0.875rem; line-height: 1.5; }
.mv-cargando { display: flex; flex-direction: column; gap: 8px; }
.mv-cargando .esq-fila { height: 56px; border-radius: var(--mv-radio); }
.mv-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- barra de abajo ---------- */
.mv-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--header-bg); border-top: 1px solid var(--border-color);
}
.mv-nav button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 60px; border: 0; background: none; cursor: pointer;
  color: var(--text-muted); font: inherit; font-size: 0.75rem; font-weight: 600;
}
.mv-nav button span { font-size: 1.25rem; line-height: 1; filter: grayscale(1); opacity: .7; }
.mv-nav button[aria-current="page"] { color: var(--primary-color); }
.mv-nav button[aria-current="page"] span { filter: none; opacity: 1; }

#movil-app button, .mv-volver {
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}

/* Boton para volver a la vista simple desde la completa, en el celular. */
.mv-volver {
  position: fixed; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); z-index: 40;
  padding: 10px 14px; border-radius: 999px; cursor: pointer;
  font: inherit; font-size: 0.875rem; font-weight: 600;
  color: #062027; background: var(--primary-color); border: 0;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
}

@media (hover: hover) and (pointer: fine) {
  .mv-btn:hover:not(:disabled) { background: var(--hover); }
  .mv-btn-primario:hover:not(:disabled) { background: color-mix(in srgb, var(--primary-color) 88%, white); }
}

/* Los dialogos de la app en el celular: casi pantalla completa. */
body.modo-movil dialog.modal-app {
  max-width: calc(100vw - 16px); width: calc(100vw - 16px);
  max-height: calc(100dvh - 16px);
}

@media (prefers-reduced-motion: reduce) {
  .mv-btn { transition: none; }
  .mv-btn:active:not(:disabled) { transform: none; }
}

/* En el modo diurno el acento es azul oscuro: el texto va blanco. */
[data-theme="light"] .mv-btn-primario,
[data-theme="light"] .mv-volver { color: #fff; }

/* ---------- fila tocable y hoja de edicion ---------- */
.mv-lista > li:has(> .mv-fila-btn) { padding: 0; }
.mv-fila-btn {
  display: block; width: 100%; padding: 10px 12px; margin: 0; text-align: left;
  font: inherit; color: inherit; background: none; border: 0; cursor: pointer;
  transition: background-color 120ms;
}
.mv-fila-btn > .mv-camion-l1, .mv-fila-btn > .mv-camion-l2 { display: flex; }
.mv-fila-btn:active { background: var(--hover); }

dialog.mv-hoja {
  position: fixed; inset: auto 0 0 0; margin: 0; width: 100%; max-width: 100%; max-height: 85dvh;
  box-sizing: border-box; overflow-y: auto; overscroll-behavior: contain;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  display: none; flex-direction: column; gap: 14px;
  color: var(--text-main); background: var(--card-bg);
  border: 1px solid var(--border-color); border-bottom: 0; border-radius: 16px 16px 0 0;
  font-size: 15px;
}
dialog.mv-hoja[open] { display: flex; animation: mv-hoja-sube 220ms var(--ease-out); }
dialog.mv-hoja::backdrop { background: rgba(0, 0, 0, .5); }
.mv-hoja-asa { width: 40px; height: 4px; margin: 0 auto 2px; border-radius: 2px; background: var(--border-color); }
.mv-hoja-patente { font-size: 1.25rem; }
.mv-hoja-dato { margin: -8px 0 0; color: var(--text-muted); font-size: 0.875rem; }
dialog.mv-hoja select {
  width: 100%; height: auto; min-height: 46px; line-height: 1.3; font-size: 16px; padding: 10px 12px;
  color: var(--text-main); background: var(--input-bg);
  border: 1px solid var(--border-color); border-radius: 10px;
}
dialog.mv-hoja .mv-campo .mv-btn { width: 100%; }
dialog.mv-hoja button { touch-action: manipulation; user-select: none; -webkit-user-select: none; }
@keyframes mv-hoja-sube { from { transform: translateY(100%); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) { dialog.mv-hoja[open] { animation: none; } }
