/* ============================================================
   app.css — Registros Operacionales Bailac
   Mobile-first: se usa en terreno, con guantes y a pleno sol.
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--fuente);
  font-size: var(--t-md);
  color: var(--texto);
  background: var(--fondo);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
svg { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--e2);
  min-height: var(--tactil); padding: 0 var(--e4);
  border: 1px solid transparent; border-radius: var(--r);
  font: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:active { transform: scale(.985); }
.btn:focus-visible { outline: 3px solid var(--la-azul); outline-offset: 2px; }
.btn--primario { background: var(--la-azul); color: var(--texto-inv); }
.btn--primario:hover { background: var(--la-azul-osc); }
.btn--sec { background: var(--superficie); color: var(--texto); border-color: var(--borde-fuerte); }
.btn--sec:hover { background: var(--superficie-2); }
.btn--peligro { background: var(--error); color: var(--texto-inv); }
.btn--bloque { width: 100%; }
.btn--sm { min-height: 38px; padding: 0 var(--e3); font-size: var(--t-sm); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Campos ---------- */
.campo { display: block; margin-bottom: var(--e4); }
.campo__lbl { display: block; margin-bottom: var(--e2); font-size: var(--t-sm); font-weight: 600; color: var(--texto-sec); }
.campo__in, .campo__sel, .campo__area {
  width: 100%; min-height: var(--tactil);
  padding: var(--e3); border: 1px solid var(--borde-fuerte); border-radius: var(--r);
  font: inherit; color: var(--texto); background: var(--superficie);
}
.campo__area { min-height: 90px; resize: vertical; }
.campo__in:focus, .campo__sel:focus, .campo__area:focus {
  outline: none; border-color: var(--la-azul); box-shadow: 0 0 0 3px var(--la-azul-claro);
}
.campo__ayuda { margin: var(--e1) 0 0; font-size: var(--t-xs); color: var(--texto-ter); }
.campo--fila { display: flex; gap: var(--e3); }
.campo--fila > * { flex: 1; }

/* ---------- Alertas ---------- */
.alerta { margin: 0 0 var(--e4); padding: var(--e3); border-radius: var(--r-sm); font-size: var(--t-sm); }
.alerta--error { background: var(--error-bg); color: var(--error); border: 1px solid #f5c2c2; }
.alerta--ok    { background: var(--ok-bg);    color: var(--ok);    border: 1px solid #bbe6cb; }
.alerta--info  { background: var(--la-azul-claro); color: var(--la-azul-osc); border: 1px solid #c3d9ee; }

/* ============================================================
   LOGIN
   ============================================================ */
.login {
  min-height: 100dvh; display: grid; place-items: center; padding: var(--e4);
  background: linear-gradient(160deg, var(--la-azul) 0%, var(--la-azul-osc) 100%);
}
.login__caja {
  width: 100%; max-width: 400px; padding: var(--e6) var(--e5);
  background: var(--superficie); border-radius: var(--r-lg); box-shadow: var(--sombra-lg);
}
.login__marca { text-align: center; margin-bottom: var(--e5); }
.login__logo { max-width: 170px; height: auto; margin-bottom: var(--e4); }
.login__titulo { margin: 0; font-size: var(--t-lg); font-weight: 700; }
.login__sub { margin: var(--e1) 0 0; color: var(--texto-sec); font-size: var(--t-sm); letter-spacing: .08em; text-transform: uppercase; }
.login__pie { margin: var(--e5) 0 0; text-align: center; font-size: var(--t-xs); color: var(--texto-ter); }

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h); padding: 0 var(--e3);
  display: flex; align-items: center; gap: var(--e2);
  background: var(--superficie); border-bottom: 1px solid var(--borde);
}
.topbar__marca { display: flex; align-items: center; gap: var(--e2); padding: var(--e2); background: none; border: 0; cursor: pointer; }
.topbar__logo { height: 26px; width: auto; }
.topbar__nombre { font-weight: 700; font-size: var(--t-sm); color: var(--texto); }
.topbar__btn {
  margin-left: auto; display: grid; place-items: center;
  width: 42px; height: 42px; border: 0; border-radius: var(--r-full);
  background: var(--superficie-2); color: var(--texto-sec); cursor: pointer;
}
.topbar__btn:hover { background: var(--borde); }

.pill {
  display: inline-flex; align-items: center; gap: var(--e2);
  max-width: 46vw; padding: var(--e2) var(--e3);
  background: var(--la-azul-claro); color: var(--la-azul-osc);
  border: 1px solid #c3d9ee; border-radius: var(--r-full);
  font-size: var(--t-sm); font-weight: 600; cursor: pointer;
}
.pill:hover { background: #dce9f6; }
.pill__cod { font-weight: 800; letter-spacing: .04em; }
.pill__nom { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.pill__chev { width: 14px; height: 14px; flex: none; }
.pill--solo { cursor: default; }
.pill--solo .pill__chev { display: none; }

.aviso-offline {
  padding: var(--e2) var(--e4); text-align: center;
  background: var(--alerta-bg); color: #92620a; font-size: var(--t-sm); font-weight: 600;
}

/* ============================================================
   VISTA
   ============================================================ */
.vista { max-width: 900px; margin: 0 auto; padding: var(--e4) var(--e4) var(--e7); }

.encabezado { margin-bottom: var(--e5); }
.encabezado__t { margin: 0 0 var(--e1); font-size: var(--t-xl); font-weight: 700; letter-spacing: -.02em; }
.encabezado__s { margin: 0; color: var(--texto-sec); font-size: var(--t-sm); }

.buscador { position: relative; margin-bottom: var(--e5); }
.buscador__in { width: 100%; min-height: var(--tactil); padding: var(--e3) var(--e3) var(--e3) 44px;
  border: 1px solid var(--borde-fuerte); border-radius: var(--r); font: inherit; background: var(--superficie); }
.buscador__in:focus { outline: none; border-color: var(--la-azul); box-shadow: 0 0 0 3px var(--la-azul-claro); }
.buscador__ico { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--texto-ter); }

.grupo { margin-bottom: var(--e6); }
.grupo__t {
  display: flex; align-items: center; gap: var(--e2);
  margin: 0 0 var(--e3); font-size: var(--t-sm); font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--cat, var(--texto-sec));
}
.grupo__t::after { content: ""; flex: 1; height: 1px; background: var(--borde); }

.tarjetas { display: grid; gap: var(--e3); grid-template-columns: 1fr; }
@media (min-width: 640px) { .tarjetas { grid-template-columns: repeat(2, 1fr); } }

.tarjeta {
  display: flex; align-items: center; gap: var(--e4); width: 100%;
  padding: var(--e4); text-align: left;
  background: var(--superficie); border: 1px solid var(--borde); border-left: 4px solid var(--cat, var(--borde-fuerte));
  border-radius: var(--r); box-shadow: var(--sombra); cursor: pointer;
  transition: box-shadow .15s, transform .05s, border-color .15s;
}
.tarjeta:hover { box-shadow: var(--sombra-md); }
.tarjeta:active { transform: scale(.99); }
.tarjeta:focus-visible { outline: 3px solid var(--la-azul); outline-offset: 2px; }
.tarjeta__ico {
  flex: none; display: grid; place-items: center; width: 46px; height: 46px;
  border-radius: var(--r); background: var(--cat-bg, var(--superficie-2)); color: var(--cat, var(--texto-sec));
}
.tarjeta__ico svg { width: 22px; height: 22px; }
.tarjeta__txt { min-width: 0; flex: 1; }
.tarjeta__n { display: block; font-weight: 600; line-height: 1.3; }
.tarjeta__d { display: block; margin-top: 2px; font-size: var(--t-sm); color: var(--texto-sec); line-height: 1.35; }
.tarjeta__tag {
  display: inline-block; margin-top: var(--e2); padding: 2px var(--e2);
  font-size: var(--t-xs); font-weight: 700; letter-spacing: .04em;
  background: var(--cat-bg); color: var(--cat); border-radius: var(--r-sm);
}
.tarjeta__chev { flex: none; color: var(--texto-ter); }

.vacio { padding: var(--e7) var(--e4); text-align: center; color: var(--texto-sec); }
.vacio__ico { color: var(--texto-ter); margin-bottom: var(--e3); }
.vacio__ico svg { width: 44px; height: 44px; }
.vacio__t { margin: 0 0 var(--e2); font-weight: 600; color: var(--texto); }
.vacio p { margin: 0; font-size: var(--t-sm); }

/* ---------- Lista de faenas / menú ---------- */
.lista { display: grid; gap: var(--e2); }
.lista__it {
  display: flex; align-items: center; gap: var(--e3); width: 100%;
  min-height: var(--tactil); padding: var(--e3) var(--e4); text-align: left;
  background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--r);
  font: inherit; cursor: pointer;
}
.lista__it:hover { background: var(--superficie-2); border-color: var(--borde-fuerte); }
.lista__it--activo { border-color: var(--la-azul); background: var(--la-azul-claro); }
.lista__it--peligro { color: var(--error); }
.lista__cod {
  flex: none; display: grid; place-items: center; min-width: 46px; height: 34px; padding: 0 var(--e2);
  background: var(--la-azul); color: var(--texto-inv); border-radius: var(--r-sm);
  font-size: var(--t-xs); font-weight: 800; letter-spacing: .04em;
}
.lista__txt { flex: 1; min-width: 0; }
.lista__n { display: block; font-weight: 600; }
.lista__d { display: block; font-size: var(--t-sm); color: var(--texto-sec); }

/* ---------- Visor de formulario ---------- */
.visor { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; background: var(--superficie); }
.visor__head {
  display: flex; align-items: center; gap: var(--e3); flex: none;
  height: var(--topbar-h); padding: 0 var(--e3);
  background: var(--superficie); border-bottom: 1px solid var(--borde);
}
.visor__volver {
  display: inline-flex; align-items: center; gap: var(--e2);
  min-height: 42px; padding: 0 var(--e3);
  background: var(--superficie-2); border: 1px solid var(--borde); border-radius: var(--r);
  font: inherit; font-weight: 600; font-size: var(--t-sm); cursor: pointer;
}
.visor__tit { min-width: 0; flex: 1; }
.visor__n { display: block; font-weight: 700; font-size: var(--t-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.visor__f { display: block; font-size: var(--t-xs); color: var(--texto-sec); }
.visor__marco { flex: 1; width: 100%; border: 0; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: var(--e4); }
.modal__fondo { position: absolute; inset: 0; background: rgba(15,23,42,.5); }
.modal__caja {
  position: relative; width: 100%; max-width: 520px; max-height: 88dvh;
  display: flex; flex-direction: column;
  background: var(--superficie); border-radius: var(--r-lg); box-shadow: var(--sombra-lg);
}
.modal__head { display: flex; align-items: center; gap: var(--e3); padding: var(--e4) var(--e5); border-bottom: 1px solid var(--borde); }
.modal__titulo { margin: 0; font-size: var(--t-lg); font-weight: 700; }
.modal__x { margin-left: auto; width: 36px; height: 36px; font-size: 26px; line-height: 1;
  background: none; border: 0; color: var(--texto-sec); cursor: pointer; border-radius: var(--r-sm); }
.modal__x:hover { background: var(--superficie-2); }
.modal__cuerpo { padding: var(--e5); overflow-y: auto; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 90; transform: translateX(-50%);
  max-width: 90vw; padding: var(--e3) var(--e5);
  background: #1e293b; color: #fff; border-radius: var(--r-full);
  font-size: var(--t-sm); font-weight: 600; box-shadow: var(--sombra-lg);
  animation: toast-in .2s ease;
}
.toast--error { background: var(--error); }
.toast--ok    { background: var(--ok); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } }

/* ---------- Cargando ---------- */
.cargando { position: fixed; inset: 0; z-index: 95; display: grid; place-items: center; background: rgba(244,246,249,.7); }
.cargando__spin {
  width: 38px; height: 38px; border: 3px solid var(--borde); border-top-color: var(--la-azul);
  border-radius: 50%; animation: giro .7s linear infinite;
}
@keyframes giro { to { transform: rotate(360deg); } }

/* ---------- Tablas (administración) ---------- */
.tabla-scroll { overflow-x: auto; margin: 0 calc(var(--e4) * -1); padding: 0 var(--e4); }
.tabla { width: 100%; border-collapse: collapse; font-size: var(--t-sm); background: var(--superficie); }
.tabla th, .tabla td { padding: var(--e3); text-align: left; border-bottom: 1px solid var(--borde); white-space: nowrap; }
.tabla th { font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .05em; color: var(--texto-sec); background: var(--superficie-2); }
.tabla tr:last-child td { border-bottom: 0; }
.tabla__acc { display: flex; gap: var(--e2); }

.chip { display: inline-block; padding: 2px var(--e2); margin: 1px; border-radius: var(--r-sm);
  background: var(--la-azul-claro); color: var(--la-azul-osc); font-size: var(--t-xs); font-weight: 700; }
.chip--gris { background: var(--superficie-2); color: var(--texto-sec); }
.chip--ok   { background: var(--ok-bg); color: var(--ok); }
.chip--off  { background: var(--error-bg); color: var(--error); }

.barra-acc { display: flex; flex-wrap: wrap; gap: var(--e3); align-items: center; margin-bottom: var(--e4); }
.barra-acc__esp { flex: 1; }

/* Multi-select de faenas (equivale al MS de Eventos-LA) */
.ms { display: flex; flex-wrap: wrap; gap: var(--e2); padding: var(--e2);
  border: 1px solid var(--borde-fuerte); border-radius: var(--r); background: var(--superficie); }
.ms__op { display: inline-flex; align-items: center; gap: var(--e2); padding: var(--e2) var(--e3);
  border: 1px solid var(--borde); border-radius: var(--r-full); cursor: pointer; font-size: var(--t-sm); }
.ms__op:has(input:checked) { background: var(--la-azul-claro); border-color: var(--la-azul); color: var(--la-azul-osc); font-weight: 600; }
.ms__op input { width: 16px; height: 16px; accent-color: var(--la-azul); }

/* ---------- Panel de resumen ---------- */
.kpis { display: grid; gap: var(--e3); grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin-bottom: var(--e5); }
.kpi { padding: var(--e4); background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--r); box-shadow: var(--sombra); }
.kpi__n { display: block; font-size: var(--t-xl); font-weight: 700; line-height: 1.1; color: var(--la-azul); }
.kpi__l { display: block; margin-top: var(--e1); font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .05em; color: var(--texto-sec); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
