/* ============================================
   Inspección de Flota — Incumbral
   Estética industrial oscura, acento ámbar
   ============================================ */
:root {
  --bg:        #0e1116;
  --bg-2:      #161b22;
  --bg-3:      #1c232c;
  --linea:     #2a323d;
  --txt:       #e8edf2;
  --txt-2:     #9aa7b4;
  --txt-3:     #5f6c79;
  --ambar:     #f5a623;
  --ambar-d:   #c97f0a;
  --verde:     #3fb950;
  --rojo:      #f85149;
  --amarillo:  #d29922;
  --radio:     12px;
  --sombra:    0 6px 20px rgba(0,0,0,.35);
  font-size: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
}

.vista { display: none; }
.vista.activa { display: block; }
.oculto { display: none !important; }

/* ---------- LOGIN ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 20px;
  max-width: 440px;
  margin: 0 auto;
}
.brand { text-align: center; margin-bottom: 28px; }
.brand-mark {
  font-size: 44px;
  color: var(--ambar);
  line-height: 1;
  margin-bottom: 8px;
}
.brand h1 { margin: 0; font-size: 1.5rem; letter-spacing: -.02em; }
.brand-sub { margin: 6px 0 0; color: var(--txt-2); font-size: .9rem; }

/* ---------- CARDS ---------- */
.card {
  background: var(--bg-2);
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  padding: 18px;
  margin: 0 0 14px;
}
.login-card { box-shadow: var(--sombra); }
.card-titulo {
  margin: 0 0 14px;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ambar);
  font-weight: 700;
}
.card-ayuda { margin: -6px 0 14px; color: var(--txt-2); font-size: .85rem; }

/* ---------- CAMPOS ---------- */
.campo { display: block; margin-bottom: 14px; }
.campo > span {
  display: block;
  font-size: .8rem;
  color: var(--txt-2);
  margin-bottom: 6px;
  font-weight: 600;
}
input, select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--linea);
  color: var(--txt);
  border-radius: 9px;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--ambar);
}
textarea { resize: vertical; }
.hint { display: block; font-size: .78rem; color: var(--txt-3); margin-top: 5px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
  font-size: .92rem;
  cursor: pointer;
}
.check input { width: auto; margin-top: 2px; accent-color: var(--ambar); }

/* ---------- SEGMENTOS ---------- */
.seg, .bencina {
  display: flex;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--linea);
  border-radius: 10px;
  padding: 5px;
}
.seg button, .bencina button {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--txt-2);
  padding: 10px 4px;
  border-radius: 7px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all .12s;
}
.seg button.activo, .bencina button.activo {
  background: var(--ambar);
  color: #1a1205;
}
.bencina button { font-size: .95rem; }

/* ---------- FOTOS ---------- */
.fotos-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.foto-slot { position: relative; }
.foto-slot label {
  display: block;
  aspect-ratio: 4/3;
  border: 1.5px dashed var(--linea);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  background: var(--bg);
}
.foto-slot input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.foto-ph {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--txt-3);
  font-size: .85rem;
  font-weight: 600;
  text-align: center;
}
.foto-slot.cargada label { border-style: solid; border-color: var(--ambar); }
.foto-slot img.preview {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.foto-slot .badge-cat {
  position: absolute; bottom: 6px; left: 6px;
  background: rgba(0,0,0,.7);
  color: #fff; font-size: .68rem;
  padding: 2px 7px; border-radius: 5px;
  z-index: 2;
}

/* ---------- BOTONES ---------- */
.btn {
  border: none;
  border-radius: 10px;
  padding: 13px 18px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: filter .12s, transform .05s;
}
.btn:active { transform: scale(.985); }
.btn-block { width: 100%; }
.btn-grande { padding: 16px; font-size: 1.05rem; margin-bottom: 24px; }
.btn-primario { background: var(--ambar); color: #1a1205; }
.btn-primario:hover { filter: brightness(1.07); }
.btn-secundario {
  background: transparent;
  color: var(--ambar);
  border: 1px solid var(--ambar-d);
}
.btn-icono {
  background: var(--bg-3);
  border: 1px solid var(--linea);
  color: var(--txt);
  width: 40px; height: 40px;
  border-radius: 9px;
  font-size: 1.1rem;
  cursor: pointer;
}

/* ---------- TOPBAR / TABS ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--linea);
  position: sticky; top: 0; z-index: 20;
}
.topbar-id { display: flex; align-items: center; gap: 10px; }
.topbar-id strong { font-size: .98rem; }
.chip {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  background: var(--bg-3);
  color: var(--ambar);
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 700;
}
.tabs {
  display: flex;
  background: var(--bg-2);
  border-bottom: 1px solid var(--linea);
  position: sticky; top: 53px; z-index: 19;
}
.tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--txt-2);
  padding: 14px 0;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  border-bottom: 2px solid transparent;
}
.tab.activo { color: var(--ambar); border-bottom-color: var(--ambar); }

.tab-panel { display: none; padding: 16px; max-width: 560px; margin: 0 auto; }
.tab-panel.activo { display: block; }

/* ---------- LISTAS ---------- */
.lista { display: flex; flex-direction: column; gap: 10px; }
.item {
  background: var(--bg-2);
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  padding: 14px;
  cursor: pointer;
  transition: border-color .12s;
}
.item:hover { border-color: var(--ambar-d); }
.item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.item-pat { font-weight: 700; font-size: 1rem; }
.item-fecha { font-size: .78rem; color: var(--txt-3); }
.item-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag {
  font-size: .72rem;
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--bg-3);
  color: var(--txt-2);
  font-weight: 600;
}
.tag.alerta { background: rgba(248,81,73,.15); color: var(--rojo); }
.tag.ok { background: rgba(63,185,80,.13); color: var(--verde); }
.tag.warn { background: rgba(210,153,34,.15); color: var(--amarillo); }
.item-sub { font-size: .82rem; color: var(--txt-2); margin-top: 4px; }

/* ---------- MENSAJES ---------- */
.error-msg { color: var(--rojo); font-size: .85rem; margin: 10px 0 0; min-height: 1em; text-align: center; }
.estado-msg { font-size: .9rem; text-align: center; margin: 4px 0 20px; min-height: 1em; }
.estado-msg.ok { color: var(--verde); }
.estado-msg.error { color: var(--rojo); }

/* ---------- MODAL ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.72);
  display: flex; align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
.modal-box {
  background: var(--bg-2);
  border: 1px solid var(--linea);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 22px 18px calc(22px + env(safe-area-inset-bottom));
  position: relative;
}
.modal-cerrar {
  position: absolute; top: 14px; right: 14px;
  background: var(--bg-3);
  border: none; color: var(--txt);
  width: 34px; height: 34px;
  border-radius: 8px; cursor: pointer;
  font-size: 1rem;
}
.detalle-h { margin: 0 0 4px; font-size: 1.25rem; }
.detalle-sub { color: var(--txt-2); font-size: .88rem; margin: 0 0 16px; }
.detalle-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px; margin-bottom: 16px;
}
.dato { background: var(--bg); border: 1px solid var(--linea); border-radius: 9px; padding: 10px 12px; }
.dato .k { font-size: .72rem; color: var(--txt-3); text-transform: uppercase; letter-spacing: .04em; }
.dato .v { font-size: 1.05rem; font-weight: 700; margin-top: 2px; }
.detalle-fotos { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.detalle-fotos figure { margin: 0; }
.detalle-fotos img { width: 100%; border-radius: 9px; display: block; border: 1px solid var(--linea); }
.detalle-fotos figcaption { font-size: .72rem; color: var(--txt-3); margin-top: 4px; text-transform: capitalize; }
.hash-box {
  font-family: ui-monospace, monospace;
  font-size: .75rem;
  color: var(--txt-3);
  background: var(--bg);
  border: 1px solid var(--linea);
  border-radius: 8px;
  padding: 8px 10px;
  margin-top: 14px;
  word-break: break-all;
}

@media (min-width: 600px) {
  .fotos-grid { grid-template-columns: 1fr 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ============================================
   Hub central y panel de administración
   ============================================ */
.topbar-acciones { display: flex; gap: 8px; }
.logo-mini { font-size: 1.4rem; color: var(--ambar); }
.topbar-id > div { display: flex; flex-direction: column; line-height: 1.2; }
.chip-super { background: var(--ambar); color: #1a1205; }

.hub-cont { max-width: 640px; margin: 0 auto; padding: 22px 16px; }
.hub-saludo { font-size: 1.3rem; margin: 0 0 4px; letter-spacing: -.02em; }
.hub-sub { color: var(--txt-2); font-size: .9rem; margin: 0 0 22px; }

.hub-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 460px){ .hub-grid { grid-template-columns: 1fr; } }

.mod-card {
  background: var(--bg-2); border: 1px solid var(--linea);
  border-radius: 14px; padding: 20px 18px;
  cursor: pointer; position: relative; overflow: hidden;
  transition: border-color .15s, transform .05s;
  min-height: 150px; display: flex; flex-direction: column;
}
.mod-card:active { transform: scale(.99); }
.mod-card:hover { border-color: var(--ambar-d); }
.mod-icono { font-size: 2.2rem; line-height: 1; margin-bottom: 12px; color: var(--ambar); }
.mod-nombre { font-size: 1.05rem; font-weight: 700; margin-bottom: 6px; }
.mod-desc { font-size: .82rem; color: var(--txt-2); line-height: 1.4; flex: 1; }
.mod-abrir { font-size: .8rem; color: var(--ambar); font-weight: 700; margin-top: 12px; }

/* Bloqueado */
.mod-card.bloqueado { cursor: pointer; opacity: 1; }
.mod-card.bloqueado .mod-icono,
.mod-card.bloqueado .mod-nombre,
.mod-card.bloqueado .mod-desc { filter: grayscale(1); opacity: .5; }
.mod-card.bloqueado::after {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(45deg, transparent, transparent 12px, rgba(255,255,255,.012) 12px, rgba(255,255,255,.012) 24px);
  pointer-events: none;
}
.mod-lock {
  position: absolute; top: 14px; right: 14px;
  background: var(--bg-3); border: 1px solid var(--linea);
  width: 30px; height: 30px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem; z-index: 2;
}
.mod-card.bloqueado .mod-abrir { color: var(--txt-3); filter: none; opacity: 1; }
.mod-badge-plan {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(245,166,35,.08));
  text-align: center; font-size: .72rem; font-weight: 700;
  color: var(--ambar); padding: 8px; z-index: 2;
}

/* Panel admin */
.admin-lista { display: flex; flex-direction: column; gap: 12px; }
.admin-card {
  background: var(--bg-2); border: 1px solid var(--linea);
  border-radius: 12px; padding: 16px;
  display: flex; align-items: center; gap: 14px;
}
.admin-card .ac-icono { font-size: 1.8rem; color: var(--ambar); }
.admin-card .ac-info { flex: 1; }
.admin-card .ac-nombre { font-weight: 700; font-size: 1rem; }
.admin-card .ac-desc { font-size: .8rem; color: var(--txt-2); margin-top: 2px; }
.admin-card .ac-estado { font-size: .72rem; font-weight: 700; margin-top: 6px; }
.ac-estado.on { color: var(--verde); }
.ac-estado.off { color: var(--txt-3); }

/* Switch */
.switch { position: relative; width: 52px; height: 30px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--bg-3); border: 1px solid var(--linea);
  border-radius: 30px; transition: .2s;
}
.switch .slider::before {
  content: ""; position: absolute; height: 22px; width: 22px;
  left: 3px; bottom: 3px; background: var(--txt-2);
  border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--ambar); border-color: var(--ambar); }
.switch input:checked + .slider::before { transform: translateX(22px); background: #1a1205; }

/* Modal centrado */
.modal-centro { align-self: center; border-radius: 16px; margin: auto 16px; max-width: 400px; }
.modal.oculto { display: none; }
.modal { align-items: center; }
.bloqueado-icono { font-size: 2.6rem; text-align: center; margin-bottom: 8px; }
.bloqueado-msg {
  background: var(--bg); border: 1px solid var(--linea);
  border-radius: 10px; padding: 14px; font-size: .88rem;
  color: var(--txt-2); margin: 16px 0; text-align: center; line-height: 1.5;
}

/* ============================================
   Gestión de usuarios (admin)
   ============================================ */
.admin-tabs { margin-bottom: 16px; }

.usuarios-lista { display: flex; flex-direction: column; gap: 10px; }
.usuario-item {
  background: var(--bg-2); border: 1px solid var(--linea);
  border-radius: 10px; padding: 14px; display: flex; justify-content: space-between; align-items: center;
}
.usuario-info { flex: 1; }
.usuario-nombre { font-weight: 700; font-size: .95rem; }
.usuario-sub { font-size: .8rem; color: var(--txt-2); margin-top: 2px; }
.usuario-mods { font-size: .72rem; color: var(--txt-3); margin-top: 6px; }
.usuario-mods span { display: inline-block; background: var(--bg-3); padding: 2px 7px; border-radius: 3px; margin-right: 4px; }
.usuario-acciones { display: flex; gap: 6px; }
.usuario-acciones button { padding: 8px 10px; font-size: .8rem; }

/* Logo en login */
.brand-logo { width: 100%; max-width: 320px; height: auto; margin: 0 auto 8px; display: block; border-radius: 12px; }

/* Banner PWA */
.pwa-banner {
  position: fixed; bottom: 16px; left: 16px; right: 16px; z-index: 9999;
  background: var(--bg-2); border: 1px solid var(--ambar-d);
  border-radius: 14px; padding: 12px 14px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,.5);
  animation: slideUp .3s ease;
}
.pwa-banner.oculto { display: none; }
.pwa-icon { width: 44px; height: 44px; border-radius: 10px; flex-shrink: 0; }
.pwa-texto { flex: 1; min-width: 0; }
.pwa-texto strong { display: block; font-size: .9rem; color: var(--txt); }
.pwa-texto span { font-size: .78rem; color: var(--txt-2); }
.pwa-banner .btn { padding: 8px 14px; font-size: .82rem; white-space: nowrap; flex-shrink: 0; }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Caja de clave temporal */
.clave-temp-box {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--bg); border: 2px dashed var(--ambar);
  border-radius: 12px; padding: 16px; margin: 16px 0 4px;
}
.clave-temp-box span {
  font-family: ui-monospace, 'Courier New', monospace;
  font-size: 1.5rem; font-weight: 700; color: var(--ambar);
  letter-spacing: 2px; user-select: all;
}

/* Matriz de permisos */
.permisos-matriz { display: flex; flex-direction: column; gap: 14px; }
.permiso-rol-card {
  background: var(--bg-2); border: 1px solid var(--linea);
  border-radius: 12px; padding: 14px;
}
.permiso-rol-titulo { font-size: 1rem; color: var(--ambar); margin: 0 0 10px; }
.permiso-lista { display: flex; flex-direction: column; gap: 2px; }
.permiso-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 0; font-size: .85rem; border-bottom: 1px solid var(--linea);
}
.permiso-item:last-child { border-bottom: none; }
.switch-sm { width: 40px; height: 24px; }
.switch-sm .slider::before { height: 18px; width: 18px; }
.switch-sm input:checked + .slider::before { transform: translateX(16px); }

/* --- Reordenar módulos --- */
.ac-orden { display: flex; flex-direction: column; gap: 2px; }
.btn-orden {
  width: 26px; height: 22px; border-radius: 6px; border: 1px solid var(--linea);
  background: var(--bg-3); color: var(--txt-2); font-size: .7rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-family: inherit;
}
.btn-orden:disabled { opacity: .3; cursor: default; }
.btn-orden:not(:disabled):hover { border-color: var(--ambar); color: var(--ambar); }

/* --- Configuración de empresa: logo --- */
.cfg-logo-preview {
  width: 100%; max-width: 220px; margin: 0 auto 14px; aspect-ratio: 1;
  border-radius: 12px; background: var(--bg-3); border: 1px dashed var(--linea);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.cfg-logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.cfg-logo-preview .sin-logo { color: var(--txt-3); font-size: .85rem; text-align: center; padding: 20px; }

/* --- Campanita de notificaciones --- */
.campana-wrap { position: relative; }
.campana-badge {
  position: absolute; top: -2px; right: -2px; background: var(--rojo, #c0392b);
  color: #fff; font-size: .62rem; font-weight: 800; min-width: 16px; height: 16px;
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  padding: 0 3px; line-height: 1;
}

/* --- Última conexión de cada usuario --- */
.usuario-conexion { font-size: .74rem; margin-top: 3px; }
.usuario-conexion .conexion-reciente { color: var(--verde); }
.usuario-conexion .conexion-media { color: var(--ambar); }
.usuario-conexion .conexion-vieja { color: var(--txt-3); }
.usuario-conexion .conexion-nunca { color: var(--txt-3); }
