/* Control de Fletes — Transportes Macías.
   Herramienta de trabajo: sobria, legible, rápida. Marca: verde y negro. */

:root {
  --tinta: #171a17;
  --tinta-2: #4f5651;
  /* 5.07:1 sobre blanco y 4.90:1 sobre las tarjetas tintadas. El anterior
     (#878e88) daba 3.36:1 y no llegaba al mínimo AA de 4.5:1. Es el color de
     los pies de tarjeta y los encabezados de tabla: el texto que se lee en un
     celular, a pleno sol, en un patio de maniobras.
     Ojo al medirlo: sobre las tarjetas de alerta el fondo NO es blanco puro,
     así que un gris que apenas pasa en blanco ahí se queda corto. */
  --tinta-suave: #6A706B;
  --plano: #f4f6f3;
  --superficie: #ffffff;
  --borde: #e0e4de;
  --linea: #ecefe9;

  --acento: #166534;          /* verde marca, AA sobre blanco */
  --acento-hover: #14532d;
  --acento-tinte: #e7f3ea;
  --acento-vivo: #1f9d2c;     /* verde del logo, solo decorativo */

  --lateral: #121412;         /* negro marca */
  --lateral-tinta: #cdd4cd;

  --ok-texto: #166534;
  --ok-tinte: #e2f2e4;
  --info-texto: #184f95;
  --info-tinte: #e3edfa;
  --aviso-texto: #7a5300;
  --aviso-tinte: #fdf3d9;
  --rojo-texto: #a02c2c;
  --rojo-tinte: #fbe4e4;
  --neutro-texto: #52514e;
  --neutro-tinte: #eef0ec;

  --radio: 10px;
  --sombra: 0 1px 2px rgba(18, 20, 18, 0.06), 0 4px 16px rgba(18, 20, 18, 0.05);
  --tabbar-h: 62px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--tinta);
  background: var(--plano);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; color: inherit; }
h1, h2 { margin: 0; font-weight: 650; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1rem; }
:focus-visible { outline: 2px solid var(--acento); outline-offset: 2px; border-radius: 4px; }

.solo-mov, .cards-m.solo-mov, .chips.solo-mov { display: none; }

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px;
  flex: none;
  background: var(--lateral);
  color: var(--lateral-tinta);
  display: flex;
  flex-direction: column;
  padding: 16px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.main { flex: 1; min-width: 0; padding: 26px 30px 60px; overflow-y: auto; height: 100vh; }
.topbar-m, .tabbar { display: none; }

.brand { display: flex; gap: 10px; align-items: center; padding: 2px 4px 16px; }
.brand-logo {
  width: 46px; height: 46px; flex: none;
  object-fit: contain;
  background: #fff;
  border-radius: 10px;
  padding: 3px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { color: #fff; font-size: 0.95rem; }
.brand-text span { font-size: 0.75rem; color: #8fa393; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: none; border: 0; border-radius: 8px;
  color: var(--lateral-tinta);
  text-align: left; font-size: 0.95rem;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
.nav-item.is-active {
  background: rgba(31, 157, 44, 0.18);
  color: #fff; font-weight: 600;
  box-shadow: inset 3px 0 0 var(--acento-vivo);
}
.nav-pill {
  margin-left: auto;
  background: #d03b3b; color: #fff;
  font-size: 0.72rem; font-weight: 700;
  min-width: 20px; height: 20px;
  display: grid; place-items: center;
  border-radius: 999px; padding: 0 6px;
}
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 4px; }
.sidebar-foot .btn-ghost { color: #a9b3aa; border-color: #333b34; font-size: 0.8rem; }
.sidebar-foot .btn-ghost:hover { color: #fff; border-color: #4c574e; background: rgba(255, 255, 255, 0.05); }
.demo-note { margin: 0; font-size: 0.72rem; color: #6d786f; }

/* ── Encabezado de vista ── */
.view-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  margin-bottom: 18px;
}
.sub { margin: 4px 0 0; color: var(--tinta-2); font-size: 0.9rem; }
.sub .rojo, .rojo { color: var(--rojo-texto); }
.head-actions { display: flex; gap: 10px; }

/* ── Botones ── */
.btn-primary {
  background: var(--acento); color: #fff;
  border: 0; border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600; font-size: 0.92rem;
  min-height: 44px;
}
.btn-primary:hover { background: var(--acento-hover); }
.btn-ghost {
  background: none;
  border: 1px solid var(--borde); border-radius: 8px;
  padding: 9px 14px;
  color: var(--tinta-2); font-size: 0.9rem;
  min-height: 44px;
}
.btn-ghost:hover { border-color: var(--acento); color: var(--acento); }
.btn-sm {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--superficie);
  border: 1px solid var(--borde); border-radius: 7px;
  padding: 6px 12px;
  font-size: 0.82rem; color: var(--tinta-2);
  min-height: 44px;
}
.btn-sm:hover { border-color: var(--acento); color: var(--acento); }
.btn-ok { border-color: #bfe0c4; color: var(--ok-texto); }
.btn-ok:hover { background: var(--ok-tinte); border-color: var(--ok-texto); color: var(--ok-texto); }
.btn-peligro {
  background: none; border: 1px solid #f0c6c6; color: var(--rojo-texto);
  border-radius: 8px; padding: 9px 14px; font-size: 0.9rem;
}
.btn-peligro:hover { background: var(--rojo-tinte); }
.btn-x {
  background: none; border: 0;
  font-size: 1.5rem; line-height: 1;
  color: var(--tinta-suave);
  padding: 4px 10px; border-radius: 6px;
}
.btn-x:hover { color: var(--tinta); }
.btn-limpiar {
  background: none; border: 0;
  color: var(--acento); font-size: 0.88rem; font-weight: 600;
  padding: 9px 10px; border-radius: 8px;
  min-height: 44px;
  white-space: nowrap;
}
.btn-limpiar:hover { background: var(--acento-tinte); }

/* ── Tiles ── */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.tiles-caja { grid-template-columns: repeat(auto-fit, minmax(220px, 280px)); }
.tile {
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 15px 17px;
  display: flex; flex-direction: column; gap: 4px;
  text-align: left;
}
button.tile:hover { border-color: var(--acento); }
.tile-label { font-size: 0.78rem; color: var(--tinta-2); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.tile-value { font-size: 1.5rem; font-weight: 700; }
.tile-foot { font-size: 0.8rem; color: var(--tinta-suave); }
.tile-alerta { border-color: #f0c6c6; background: #fffafa; }
.tile-alerta .tile-value { color: var(--rojo-texto); }

/* ── Paneles y tablas ── */
.panel {
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  margin-bottom: 18px;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 0;
}
section.panel { padding-bottom: 8px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 10px 9px; text-align: left; white-space: nowrap; }
th:first-child, td:first-child { padding-left: 18px; }
th:last-child, td:last-child { padding-right: 18px; }
thead th {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--tinta-suave); font-weight: 650;
  border-bottom: 1px solid var(--borde);
  position: sticky; top: 0; background: var(--superficie);
}
tbody tr { border-bottom: 1px solid var(--linea); }
tbody tr:last-child { border-bottom: 0; }
tbody tr:hover { background: #f8faf7; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-variant-numeric: tabular-nums; letter-spacing: 0.01em; }
.ruta { max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.cliente { max-width: 195px; overflow: hidden; text-overflow: ellipsis; }
.nota-celda { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--tinta-suave); font-size: 0.8rem; }
.verde { color: var(--ok-texto); }
.empty { text-align: center; color: var(--tinta-suave); padding: 34px 12px !important; }
.row-vencida { background: #fffafa; }
.row-vencida:hover { background: #fdf4f4; }
.nota { color: var(--tinta-suave); font-size: 0.82rem; margin: 6px 2px 0; }

/* ── Badges de estatus (color + texto, nunca solo color) ── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.78rem; font-weight: 600;
  padding: 3px 9px; border-radius: 999px;
  white-space: nowrap;
}
.b-pendiente { background: var(--neutro-tinte); color: var(--neutro-texto); }
.b-transito { background: var(--info-tinte); color: var(--info-texto); }
.b-entregado { background: var(--aviso-tinte); color: var(--aviso-texto); }
.b-pagado { background: var(--ok-tinte); color: var(--ok-texto); }
.b-vencido { background: var(--rojo-tinte); color: var(--rojo-texto); }
.b-libre { background: var(--neutro-tinte); color: var(--neutro-texto); }
.b-caja { background: var(--neutro-tinte); color: var(--neutro-texto); }
.tag-especial {
  display: inline-block;
  background: var(--acento-tinte); color: var(--acento);
  font-size: 0.7rem; font-weight: 700;
  padding: 1px 7px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.03em;
}

/* ── Alerta de cobranza (dashboard) ── */
.alerta {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--rojo-tinte);
  border: 1px solid #f0c6c6;
  border-radius: var(--radio);
  padding: 12px 16px;
  margin-bottom: 18px;
  font-size: 0.9rem;
}
.alerta strong { color: var(--rojo-texto); }
.alerta-det { color: var(--tinta-2); }
.alerta .btn-sm { margin-left: auto; background: #fff; }

/* ── Chips ── */
.chips { display: flex; gap: 10px; flex-wrap: wrap; padding: 12px 18px 16px; }
.chips-filtro { padding: 0 0 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--superficie);
  border: 1px solid var(--borde); border-radius: 999px;
  padding: 6px 14px 6px 9px;
  font-size: 0.88rem;
  /* 44px: el mínimo para dedo. Con camión en movimiento, 38px se falla. */
  min-height: 44px;
}
.chip:hover { border-color: var(--acento); }
.chip strong { font-variant-numeric: tabular-nums; }
.chip-total { border-style: dashed; padding-left: 12px; cursor: default; color: var(--tinta-2); }
.chip-on { border-color: var(--acento); background: var(--acento-tinte); color: var(--acento); font-weight: 600; }
.chips-filtro .chip { padding: 6px 12px; }

/* ── Filtros ── */
.filtros {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  margin-bottom: 14px;
}
.filtros input[type="search"] { flex: 1 1 220px; }
input, select {
  font: inherit;
  color: var(--tinta);
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: 8px;
  padding: 9px 12px;
  min-height: 44px;
}
input:focus-visible, select:focus-visible { outline: 2px solid var(--acento); outline-offset: 0; border-color: var(--acento); }
option { font-size: 15px; font-family: system-ui, sans-serif; }

/* ── Cards de camiones ── */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.card {
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 4px;
  font-size: 0.9rem;
  text-align: left;
}
.card-btn:hover { border-color: var(--acento); }
.card-roja { border-color: #f0c6c6; }
.card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.eco {
  font-weight: 700; font-size: 1rem;
  background: var(--acento-tinte); color: var(--acento);
  padding: 2px 9px; border-radius: 6px;
}
.card-foot {
  display: flex; justify-content: space-between;
  margin-top: 8px; padding-top: 8px;
  border-top: 1px solid var(--linea);
  color: var(--tinta-2); font-size: 0.85rem;
}
.alertas-mini { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.mini { font-size: 0.78rem; color: var(--tinta-2); }
.mini.rojo { color: var(--rojo-texto); font-weight: 600; }
.mini.amarillo { color: var(--aviso-texto); }

/* ── Cards móviles (listas) ── */
.cards-m { display: flex; flex-direction: column; gap: 10px; }
.card-m {
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 6px;
  text-align: left;
  width: 100%;
}
button.card-m:active { background: #f6f8f5; }
.card-vencida { border-color: #f0c6c6; background: #fffafa; }
.card-m-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.card-m-top strong { font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-m-ruta { font-size: 0.88rem; color: var(--tinta-2); }
.card-m-bot { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.card-m-bot .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Lista "Más" (móvil) ── */
.lista-mas {
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  margin-bottom: 16px;
  overflow: hidden;
}
.item-mas {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  width: 100%;
  background: none; border: 0;
  border-bottom: 1px solid var(--linea);
  padding: 15px 16px;
  font-size: 0.98rem;
  text-align: left;
  min-height: 52px;
}
.item-mas:last-child { border-bottom: 0; }
.item-mas:active { background: #f6f8f5; }

/* ── Modal ── */
.modal-backdrop[hidden] { display: none; }
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(16, 20, 16, 0.5);
  display: grid; place-items: center;
  padding: 18px;
  z-index: 50;
}
.modal {
  background: var(--superficie);
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.22);
  width: min(680px, 100%);
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  padding: 20px 22px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
}
.form-grid label, .anticipos label { display: flex; flex-direction: column; gap: 5px; font-size: 0.85rem; font-weight: 600; color: var(--tinta-2); }
.form-grid .span2 { grid-column: span 2; }
.form-grid input, .form-grid select, .anticipos input { font-weight: 400; width: 100%; }
.hint { font-weight: 400; color: var(--tinta-suave); }

.bloque {
  border: 1px solid var(--borde);
  border-radius: 10px;
  margin: 14px 0 0;
  padding: 10px 14px 14px;
}
.bloque legend { font-size: 0.82rem; font-weight: 650; color: var(--tinta-2); padding: 0 6px; }
.radio { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; padding: 5px 0; cursor: pointer; }
.radio input { min-height: auto; width: 17px; height: 17px; accent-color: var(--acento); }
.bloque input[name="comisionMonto"] { margin-top: 6px; width: 100%; }
.anticipos { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.emergencia-row { display: flex; gap: 8px; }
.emergencia-row input { flex: 1; }
.emergencia-row .btn-sm { min-height: 44px; white-space: nowrap; }

.mant-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; align-items: end; }
.mant-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 0.85rem; font-weight: 600; color: var(--tinta-2); }
.mant-grid input { font-weight: 400; }
.mant-info { font-size: 0.85rem; padding-bottom: 10px; }

.alertas-ficha {
  border: 1px solid #f0c6c6;
  background: #fffafa;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.alertas-ficha.ok { border-color: #bfe0c4; background: #f4faf5; color: var(--ok-texto); font-weight: 600; }
.alerta-linea { font-size: 0.88rem; }
.alerta-linea.rojo { color: var(--rojo-texto); font-weight: 600; }
.alerta-linea.amarillo { color: var(--aviso-texto); }

.viajes-mini { display: flex; flex-direction: column; gap: 6px; }
.viaje-mini {
  display: flex; align-items: center; gap: 10px;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--linea);
  padding-bottom: 6px;
}
.viaje-mini:last-child { border-bottom: 0; padding-bottom: 0; }
.viaje-ruta { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.calc {
  margin-top: 14px;
  border: 1px solid var(--borde);
  border-radius: 10px;
  background: #f7faf6;
  padding: 10px 14px;
  display: grid; gap: 6px;
  font-size: 0.9rem;
}
.calc div { display: flex; justify-content: space-between; align-items: baseline; }
.calc span { color: var(--tinta-2); }
.calc em { font-style: normal; color: var(--tinta-suave); }
.calc-total { border-top: 1px dashed var(--borde); padding-top: 6px; font-size: 1rem; }
.modal-foot { display: flex; gap: 10px; align-items: center; margin-top: 18px; }
.modal-foot .spacer { flex: 1; }

/* ── Reportes / Estado de resultados ── */
.dos-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 1100px) { .dos-cols { grid-template-columns: 1fr; } }
.er-body { padding: 6px 18px 12px; display: grid; gap: 4px; }
.er-linea { display: flex; justify-content: space-between; align-items: baseline; padding: 5px 0; font-size: 0.95rem; }
.er-linea span { color: var(--tinta-2); }
.er-sub { border-top: 1px dashed var(--borde); font-weight: 650; }
.er-sub span { color: var(--tinta); }
.er-total { border-top: 2px solid var(--tinta); margin-top: 4px; padding-top: 9px; font-size: 1.05rem; font-weight: 750; }
.er-total span { color: var(--tinta); }
.er-total strong { color: var(--acento); }
.er-neg strong { color: var(--rojo-texto); }
/* Desglose por partida bajo "Gastos generales": es detalle, no un renglón más
   del estado de resultados — por eso va sangrado, chico y sin peso. */
.er-detalle { padding: 1px 0 1px 18px; font-size: 0.86rem; }
.er-detalle span, .er-detalle strong { color: var(--tinta-suave); font-weight: 500; }
.rango { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; color: var(--tinta-2); font-weight: 600; }
.nota-alerta { color: var(--rojo-texto); }

/* ── Gastos: ranking por partida / por unidad ── */
.ranking { padding: 6px 18px 16px; display: grid; gap: 12px; }
.rank-fila { display: grid; gap: 4px; }
.rank-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 0.92rem; }
.rank-top > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-barra { height: 6px; border-radius: 99px; background: var(--linea); overflow: hidden; }
.rank-barra span { display: block; height: 100%; background: var(--acento); border-radius: 99px; }
.rank-pct { font-size: 0.76rem; }
.ranking .empty { padding: 8px 0; }

/* ── Tarifario ── */
.tarifa-row { display: grid; grid-template-columns: 1fr 130px 40px; gap: 8px; margin-bottom: 8px; align-items: center; }

/* ── Ajustes ── */
.ajustes-form { padding: 6px 18px 18px; }
.ajustes-form .bloque { margin-top: 12px; }
.partida-row { display: grid; grid-template-columns: 1fr 84px 76px 40px; gap: 10px; margin-bottom: 8px; align-items: center; }
/* Los checkbox heredan el min-height 44px de los campos de texto: aquí se
   devuelven a tamaño de casilla (mismo tratamiento que .permisos-grid). */
.check-inline { display: flex; flex-direction: row; align-items: center; gap: 7px; font-size: 0.82rem; font-weight: 600; color: var(--tinta-2); white-space: nowrap; }
.check-inline input[type="checkbox"] { min-height: 0; width: 17px; height: 17px; padding: 0; accent-color: var(--acento); flex: none; }
.partida-row .mini { text-align: right; }
@media (max-width: 700px) {
  .partida-row { grid-template-columns: 1fr 40px; grid-template-areas: 'nom quitar' 'act gastos'; row-gap: 4px; }
  .partida-row > input:not([type="hidden"]) { grid-area: nom; }
  .partida-row .check-inline { grid-area: act; }
  .partida-row .mini { grid-area: gastos; }
  .partida-row .btn-x { grid-area: quitar; }
}

/* ── Toast ── */
.toast[hidden] { display: none; }
.toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: 24px;
  background: var(--lateral); color: #fff;
  font-size: 0.9rem; font-weight: 600;
  padding: 11px 18px;
  border-radius: 999px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  z-index: 80;
  max-width: calc(100vw - 32px);
}

/* ── Móvil (≤900px): tab bar inferior + cards ── */
@media (max-width: 900px) {
  .solo-esc { display: none !important; }
  .solo-mov { display: flex; }
  .cards-m.solo-mov { display: flex; }
  .chips.solo-mov { display: flex; }

  .layout { display: block; }
  .sidebar { display: none; }

  .topbar-m {
    display: flex; align-items: center; gap: 10px;
    position: sticky; top: 0; z-index: 30;
    background: var(--lateral); color: #fff;
    padding: 10px 14px;
    padding-top: max(10px, env(safe-area-inset-top));
  }
  .topbar-logo {
    width: 34px; height: 34px;
    object-fit: contain;
    background: #fff; border-radius: 8px; padding: 2px;
  }
  .topbar-m strong { font-size: 1rem; }

  .main {
    height: auto; overflow: visible;
    padding: 16px 14px calc(var(--tabbar-h) + 26px + env(safe-area-inset-bottom));
  }

  .tabbar {
    /* flex (no grid de tracks fijos): si un tab o el FAB se oculta por
       permisos, los demás se reparten el espacio sin descuadrarse */
    display: flex;
    align-items: center;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--superficie);
    border-top: 1px solid var(--borde);
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding: 0 6px env(safe-area-inset-bottom);
  }
  .tab {
    position: relative;
    flex: 1 1 0; min-width: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    background: none; border: 0;
    font-size: 0.7rem; font-weight: 600;
    color: var(--tinta-suave);
    min-height: 48px;
    border-radius: 10px;
  }
  .tab-ico { font-size: 1.15rem; line-height: 1; }
  .tab.is-active { color: var(--acento); }
  .tab-dot {
    position: absolute; top: 6px; right: 24%;
    width: 8px; height: 8px; border-radius: 50%;
    background: #d03b3b;
  }
  .tab-dot[hidden] { display: none; }
  .tab-nuevo {
    width: 52px; height: 52px;
    margin: 0 8px;
    border: 0; border-radius: 50%;
    background: var(--acento); color: #fff;
    font-size: 1.7rem; font-weight: 600; line-height: 1;
    box-shadow: 0 4px 14px rgba(22, 101, 52, 0.4);
    transform: translateY(-10px);
  }
  .tab-nuevo:active { background: var(--acento-hover); }

  .view-head { margin-bottom: 14px; }
  .view-head h1 { display: none; }  /* el título ya vive en la barra superior */
  .view-head .sub { margin-top: 0; }
  .head-actions { width: 100%; }
  .head-actions .btn-ghost { flex: 1; }

  .tiles { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tile { padding: 12px 14px; }
  .tile-value { font-size: 1.2rem; }
  .tile-foot { font-size: 0.74rem; }

  .alerta .btn-sm { margin-left: 0; width: 100%; }
  .chips { padding: 10px 14px 14px; }

  .filtros { gap: 8px; }
  .filtros input[type="search"] { flex: 1 1 100%; }
  .filtros select { flex: 1 1 40%; min-width: 0; }

  section.panel .cards-m { padding: 12px 14px 14px; }

  .modal-backdrop { padding: 0; align-items: stretch; }
  .modal {
    width: 100%; max-height: 100vh; height: 100vh;
    border-radius: 0;
    padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  }
  .form-grid, .anticipos, .mant-grid { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: span 1; }
  .mant-info { padding-bottom: 4px; }
  .modal-foot { position: sticky; bottom: 0; background: var(--superficie); padding: 12px 0 0; margin-top: 14px; border-top: 1px solid var(--linea); flex-wrap: wrap; }
  .modal-foot .btn-primary { flex: 1; }

  .toast { bottom: calc(var(--tabbar-h) + 14px + env(safe-area-inset-bottom)); }
}

/* Solo opacidad: animar transform en el modal descoloca los popups nativos
   de <select> en Chromium (se veían gigantes/fuera de lugar). */
@media (prefers-reduced-motion: no-preference) {
  .modal { animation: entrar 0.14s ease-out; }
  @keyframes entrar {
    from { opacity: 0; }
    to { opacity: 1; }
  }
}

/* ── Login y sesión (v5) ── */
.login-capa {
  position: fixed; inset: 0; z-index: 300;
  background: var(--lateral, #121412);
  display: grid; place-items: center;
  padding: 20px;
}
.login-caja {
  width: min(360px, 100%);
  background: var(--superficie, #fff);
  border-radius: 16px;
  padding: 30px 26px calc(26px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}
.login-logo { width: 84px; height: 84px; object-fit: contain; border-radius: 14px; margin: 0 auto; }
.login-titulo { text-align: center; display: flex; flex-direction: column; gap: 2px; margin-bottom: 4px; }
.login-titulo strong { font-size: 1.15rem; }
.login-titulo span { font-size: 0.85rem; color: var(--tinta-2); }
.login-caja label { display: flex; flex-direction: column; gap: 5px; font-size: 0.85rem; font-weight: 600; color: var(--tinta-2); }
.login-caja input { font-weight: 400; width: 100%; }
.login-error { margin: 0; font-size: 0.88rem; color: var(--rojo-texto, #a02c2c); text-align: center; }
.login-btn { width: 100%; }
.sesion-linea { margin: 0 0 2px; font-size: 0.8rem; color: #a9b3aa; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Panel de usuarios */
.permisos-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; }
.permisos-grid .radio { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; font-weight: 400; }
.permisos-grid input[type="checkbox"] { min-height: 0; width: 17px; height: 17px; accent-color: var(--acento); }
@media (max-width: 640px) { .permisos-grid { grid-template-columns: 1fr; } }

/* ── Selector rápido de estatus (v6) ──
   ⚠ ORDEN IMPORTA: las clases .b-* (arriba, ~línea 242) usan el shorthand
   `background:` que resetea background-image; la flechita ▾ de .estatus-quick
   sobrevive SOLO porque esta regla va después en el archivo. No mover ni
   agregar reglas .b-* debajo de esta línea. */
.estatus-quick {
  appearance: none; -webkit-appearance: none;
  font-size: 0.78rem; font-weight: 650; font-family: inherit;
  border: 0; border-radius: 999px;
  padding: 4px 22px 4px 12px;
  min-height: 0; line-height: 1.3;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5' viewBox='0 0 8 5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='%23555'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
.estatus-quick:focus-visible { outline: 2px solid var(--acento); outline-offset: 1px; }
.estatus-celda { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.venc-mini { font-size: 0.75rem; font-weight: 700; color: var(--rojo-texto); }
.sin-marco { border: 0; padding: 0; margin: 0; min-width: 0; }
.sin-marco[disabled] { opacity: 0.75; }

/* ── Modo consulta (sin servidor) ── */
.banda-offline {
  /* Fija arriba de todo: el layout es flex y un bloque normal se volvería
     columna. Además así sigue visible mientras se hace scroll. */
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 60;
  background: var(--rojo-tinte);
  color: var(--rojo-texto);
  border-bottom: 1px solid #f0c9c9;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
}

/* ── Historial ── */
.historial { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; max-height: 60vh; overflow-y: auto; }
.historial > li { border-left: 3px solid var(--acento-tinte); padding: 2px 0 2px 12px; }
.hist-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.hist-cambios { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 2px; font-size: 0.88rem; }

/* ── Área tocable en móvil ────────────────────────────────────────────────
   Los 44px son para el dedo. En pantalla chica no se negocian: quien captura
   va en la cabina, no sentado en un escritorio. */
@media (max-width: 700px) {
  .btn-ghost, .item-mas, .btn-x { min-height: 44px; }
  .tabla-acciones button, .fila-accion { min-height: 44px; min-width: 44px; }
}
