@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@700;800&display=swap');

/* ── Variables ─────────────────────────────────────────── */
:root {
  --color-primario:    #1a3a5c;
  --color-secundario:  #2d8c1e;
  --color-fondo:       #f0f2f5;
  --color-sidebar:     #111f2e;
  --color-texto:       #2c2c2c;
  --color-acento:      #c1622d;
  --color-alerta:      #a63d3d;
  --color-panel:       #eef1f6;
  --color-grid:        rgba(26,58,92,.08);
  --sidebar-ancho:     240px;
}
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background-color: var(--color-fondo);
  color: var(--color-texto);
  margin: 0;
  font-size: 0.925rem;
}
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f2f5;
}
.login-card {
  background: #fff;
  border-radius: 4px;
  padding: 2.5rem 2.25rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.10);
  border-top: 3px solid var(--color-primario);
}
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo-img {
  max-width: 200px;
  width: 100%;
  height: auto;
  display: block;
  margin: 0 auto 0.5rem;
}
.login-logo p {
  color: #6c757d;
  font-size: 0.8rem;
  margin: 0.4rem 0 0;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-ancho);
  background: var(--color-sidebar);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
}
.sidebar-header {
  padding: 1.3rem 1.25rem 1.1rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.marca-sub {
  display: block;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  color: rgba(255,255,255,0.45);
  text-transform: uppercase;
  margin-bottom: 0.15rem;
}
.marca-nombre {
  display: inline-block;
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff;
  text-transform: none;
  padding-bottom: 0.1rem;
  line-height: 1;
}
.sidebar-nav { flex: 1; padding: 1rem 0; overflow-y: auto; min-height: 0; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  font-size: 0.9rem;
  transition: background 0.2s, color 0.2s;
}
.sidebar-nav a:hover, .sidebar-nav a.activo {
  background: rgba(255,255,255,0.12);
  color: #fff;
}
.sidebar-nav a.activo { border-left: 3px solid var(--color-secundario); }
.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 0.8rem;
  color: rgba(255,255,255,0.5);
}
.sidebar-footer #nombre-usuario {
  color: rgba(255,255,255,0.8);
  font-weight: 600;
  display: block;
  margin-bottom: 0.5rem;
}
/* min-width: 0: un hijo flex no se encoge por debajo de su contenido; sin esto una
   tabla ancha ensanchaba la pagina entera (botones y columnas fuera de la ventana)
   en vez de desplazarse dentro de su .table-responsive. */
.main-content { margin-left: var(--sidebar-ancho); flex: 1; min-width: 0; padding: 1.5rem 2rem; }
/* Etiqueta que puede partirse en varias lineas (nombres largos de equipo). */
.badge-ajustable { white-space: normal; text-align: left; line-height: 1.3; }
/* Celdas de acciones (botones sueltos o en grupo): los botones van en una sola
   linea. Con .main-content en min-width: 0 la tabla ya no ensancha la pagina y el
   navegador angostaba esta columna, apilando los botones y estirando cada fila. */
.table td:has(> .btn), .table td:has(> .btn-group), .table td:has(> div > .btn) { white-space: nowrap; }
.table td > .d-flex:has(> .btn) { flex-wrap: nowrap !important; }
/* Tabla mas ancha que su recuadro (Maquinaria en laptop: los numeros de chasis y
   las 11 columnas no entran): la columna de acciones queda fija al borde derecho
   para que los botones se vean sin desplazar la tabla. */
@media (min-width: 768px) {
  .table-responsive > .table:has(tbody td:last-child .btn) > * > tr > :last-child {
    position: sticky; right: 0; z-index: 1;
    box-shadow: inset 0 0 0 9999px var(--bs-table-bg-state, var(--bs-table-bg-type, transparent)),
      inset 1px 0 0 #dee2e6, -6px 0 8px -6px rgba(0, 0, 0, 0.18);
  }
}
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.topbar h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-primario);
  margin: 0;
  letter-spacing: 0.01em;
}
.metricas { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; margin-bottom: 1.5rem; }
.metrica-card {
  background: #fff; border-radius: 14px;
  padding: 2rem 1.5rem;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  border-top: 4px solid var(--color-primario);
  text-align: center;
}
.metrica-card .numero {
  display: block;
  font-size: 3rem; font-weight: 800;
  color: var(--color-primario); line-height: 1;
  margin-bottom: 0.5rem;
}
.metrica-card .etiqueta {
  display: block;
  font-size: 0.78rem; color: #888;
  font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em;
}
.metrica-card.alerta { border-top-color: #dc3545; }
.metrica-card.alerta .numero { color: #dc3545; }
.metrica-card.ok     { border-top-color: #28a745; }
.metrica-card.ok .numero  { color: #28a745; }
.metrica-card.warn   { border-top-color: #e8a020; }
.metrica-card.warn .numero { color: #e8a020; }
.tabla-wrapper { background: #fff; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.07); overflow: hidden; }
.tabla-wrapper .tabla-header { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: space-between; align-items: center; padding: 1rem 1.5rem; border-bottom: 1px solid #eee; }
.tabla-wrapper .tabla-header h5 { margin: 0; font-weight: 600; color: var(--color-primario); }
/* Grupo de filtros del encabezado: en pantallas angostas pasa a varias lineas. */
.tabla-wrapper .tabla-header > .d-flex { flex-wrap: wrap; }

/* ── Masthead de analisis (modulo Reportes) ─────────────── */
.masthead-reporte {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  padding: 1.1rem 1.5rem;
  margin-bottom: 1.25rem;
  border-radius: 10px;
  border-left: 4px solid var(--color-primario);
  background-color: var(--color-panel);
  background-image:
    repeating-linear-gradient(0deg, var(--color-grid) 0 1px, transparent 1px 24px),
    repeating-linear-gradient(90deg, var(--color-grid) 0 1px, transparent 1px 24px);
}
.masthead-reporte .eyebrow {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-acento);
  margin-bottom: 0.15rem;
}
.masthead-reporte h2 {
  margin: 0;
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 700;
  font-size: 1.4rem;
  color: var(--color-primario);
  line-height: 1;
}
.masthead-reporte .timestamp {
  font-size: 0.78rem;
  color: #6b7686;
  white-space: nowrap;
}
.masthead-reporte .timestamp strong { color: var(--color-primario); font-weight: 600; }

/* ── Chart cards (modulo Reportes) ───────────────────────── */
.chart-card-header {
  background: #fff;
  border-bottom: 1px solid #eee;
  font-weight: 600;
  color: var(--color-primario);
  padding: 0.85rem 1.25rem;
}

/* ── Divisor hairline (modulo Reportes) ──────────────────── */
.divisor-hairline {
  height: 1px;
  background-color: rgba(26,58,92,.16);
  margin: 0.25rem 0 1.25rem;
}

/* ── Numeros tabulares (modulo Reportes) ─────────────────── */
.num-tabular { font-variant-numeric: tabular-nums; }

/* ── Entrada escalonada de tarjetas KPI (modulo Reportes) ── */
@keyframes tarjetaEntrada {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.metrica-card.entrada { animation: tarjetaEntrada 0.28s ease-out both; }
@media (prefers-reduced-motion: reduce) {
  .metrica-card.entrada { animation: none; }
  .metrica-card, .metrica-card:hover { transition: none; }
}

.badge-activa     { background: #d4edda; color: #155724; }
.badge-pausada    { background: #fff3cd; color: #856404; }
.badge-completada { background: #cce5ff; color: #004085; }
.badge-problema   { background: #f8d7da; color: #721c24; }
#mapa { height: 500px; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
/* Leyenda bajo el mapa del dashboard (obras por estatus + almacenes por tipo) */
.mapa-leyenda { display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; align-items: center; margin-top: 0.75rem; font-size: 0.82rem; color: #555; }
.mapa-leyenda .leyenda-grupo { font-weight: 600; color: #333; }
.mapa-leyenda .leyenda-pin { display: inline-block; width: 12px; height: 12px; margin-right: 5px; vertical-align: -1px; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.35); }
.mapa-leyenda .leyenda-pin.circulo  { border-radius: 50%; }
.mapa-leyenda .leyenda-pin.cuadrado { border-radius: 3px; }
#toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 9999; }

/* ── Hover en tarjetas ──────────────────────────────────── */
.metrica-card { transition: transform 0.15s, box-shadow 0.15s; }
.metrica-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.12); }

/* ── Barra superior movil ────────────────────────────────── */
.barra-movil {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: var(--color-sidebar);
  align-items: center;
  padding: 0 1rem;
  gap: 0.75rem;
  z-index: 300;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.barra-movil-marca {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: #fff;
}
.btn-hamburguesa {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.9);
  font-size: 1.35rem;
  padding: 0.3rem 0.4rem;
  line-height: 1;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: background 0.15s;
}
.btn-hamburguesa:hover,
.btn-hamburguesa:focus { background: rgba(255,255,255,0.12); outline: none; }

/* Botón X dentro del sidebar header (solo mobile) */
.btn-cerrar-sidebar {
  display: none;
  position: absolute;
  top: 0.9rem; right: 0.75rem;
  background: rgba(255,255,255,0.1);
  border: none;
  border-radius: 6px;
  color: rgba(255,255,255,0.75);
  font-size: 0.95rem;
  padding: 0.3rem 0.45rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-cerrar-sidebar:hover { background: rgba(255,255,255,0.2); color: #fff; }

/* ── Overlay oscuro del sidebar en mobile ───────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 52px; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
}
.sidebar-overlay.activo { display: block; }

/* ── Soporte para modales apilados ──────────────────────── */
.modal-backdrop + .modal-backdrop { z-index: 1059; }
#modal-checklist-mp { z-index: 1060; }

/* ── Centrar modales respecto al sidebar ────────────────── */
.modal {
  left: var(--sidebar-ancho);
  width: calc(100% - var(--sidebar-ancho));
}

/* ── RESPONSIVE ─────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Barra movil visible */
  .barra-movil { display: flex; }

  /* Sidebar: arranca bajo la barra movil, oculto por defecto */
  .sidebar {
    top: 52px;
    height: calc(100vh - 52px);
    transform: translateX(-100%);
    transition: transform 0.26s ease;
    z-index: 250;
  }
  .sidebar.sidebar-abierto { transform: translateX(0); }

  /* Botón cerrar sidebar visible dentro del header */
  .sidebar-header { position: relative; }
  .btn-cerrar-sidebar { display: block; }

  /* Contenido ocupa toda la pantalla y baja bajo la barra */
  .main-content {
    margin-left: 0;
    padding: 1rem;
    padding-top: calc(52px + 1rem);
  }

  /* Topbar de pagina */
  .topbar { margin-bottom: 1rem; gap: 0.5rem; }
  .topbar h1 { font-size: 1.05rem; }

  /* Metricas: 1 columna */
  .metricas { grid-template-columns: 1fr; }

  /* Modales full width */
  .modal { left: 0; width: 100%; }

  /* Mapa mas corto */
  #mapa { height: 280px; }

  /* Tablas con scroll horizontal */
  .table-responsive { overflow-x: auto; }
}

/* ── Modo oscuro (toggle en /dashboard) ──────────────────── */
.btn-modo-oscuro {
  border: 1px solid rgba(0,0,0,0.12);
  background: #fff;
  color: var(--color-primario);
  border-radius: 8px;
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.05rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-modo-oscuro:hover { background: #f0f2f5; }

body.modo-oscuro {
  background-color: #10161d;
  color: #d8dee5;
}
body.modo-oscuro .btn-modo-oscuro {
  background: #1a222c;
  border-color: rgba(255,255,255,0.14);
  color: #eef2f6;
}
body.modo-oscuro .btn-modo-oscuro:hover { background: #202a35; }
body.modo-oscuro .metrica-card,
body.modo-oscuro .tabla-wrapper,
body.modo-oscuro .modal-content,
body.modo-oscuro .card {
  background-color: #1a222c;
  color: #d8dee5;
}
body.modo-oscuro .metrica-card .etiqueta { color: #8b96a3; }
body.modo-oscuro .tabla-wrapper .tabla-header,
body.modo-oscuro .modal-header,
body.modo-oscuro .modal-footer {
  border-color: rgba(255,255,255,0.08);
}
body.modo-oscuro .tabla-wrapper .tabla-header h5,
body.modo-oscuro .topbar h1 {
  color: #eef2f6;
}
body.modo-oscuro .table { color: #d8dee5; }
body.modo-oscuro thead.table-light th {
  background-color: #202a35;
  color: #d8dee5;
  border-color: rgba(255,255,255,0.08);
}
body.modo-oscuro .table-hover > tbody > tr:hover > * {
  background-color: rgba(255,255,255,0.06);
  color: #eef2f6;
}
body.modo-oscuro .table > :not(caption) > * > * {
  border-color: rgba(255,255,255,0.08);
}
body.modo-oscuro .text-muted { color: #8b96a3 !important; }
body.modo-oscuro a.text-dark { color: #eef2f6 !important; }
body.modo-oscuro .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }


/* ── Maquinaria: lista + panel de detalle (2026-10-13) ─────────────────────
   Izquierda la lista de equipos, derecha la ficha del equipo elegido. En
   pantallas angostas una sola columna: la lista, y al elegir un equipo la
   ficha ocupa la pantalla (.con-detalle) con el boton "Equipos" para volver. */
.maq-split { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: 1rem; height: calc(100vh - 7.5rem); min-height: 480px; }
.maq-lista, .maq-detalle { background: #fff; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.07); min-height: 0; display: flex; flex-direction: column; }
.maq-lista { overflow: hidden; }
.maq-detalle { overflow-y: auto; }
.maq-lista-header { padding: .9rem 1rem; border-bottom: 1px solid #eee; display: flex; flex-direction: column; gap: .5rem; }
.maq-lista-header h5 { margin: 0; font-weight: 600; color: var(--color-primario); }
.maq-filtros { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.maq-filtros #filtro-obra { grid-column: 1 / -1; }
.maq-lista-items { flex: 1; overflow-y: auto; outline: none; }
.maq-item { display: flex; gap: .65rem; align-items: flex-start; width: 100%; text-align: left; padding: .6rem 1rem .6rem calc(1rem - 3px); background: none; border: 0; border-bottom: 1px solid #f0f1f3; border-left: 3px solid transparent; color: inherit; }
.maq-item:hover { background: #f6f8fa; }
.maq-item:focus-visible { outline: 2px solid var(--color-primario); outline-offset: -2px; }
.maq-item.activo { background: #eaf1fb; border-left-color: var(--color-primario); }
.maq-item-foto { width: 40px; height: 40px; flex: none; border-radius: 6px; object-fit: cover; }
.maq-item-texto { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: .1rem; }
.maq-item-fila { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.maq-item-nombre { font-weight: 600; font-size: .9rem; line-height: 1.25; }
.maq-item-fila .badge { flex: none; font-size: .68rem; }
.maq-item-sub { font-size: .78rem; color: #6c757d; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sin-foto { display: inline-flex; align-items: center; justify-content: center; background: #f1f3f5; color: #adb5bd; }
.maq-detalle-vacio { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem; color: #adb5bd; }
.maq-detalle-vacio i { font-size: 2.5rem; }
.maq-detalle-header { padding: 1rem 1.25rem; border-bottom: 1px solid #eee; }
.maq-detalle-header h4 { font-size: 1.2rem; font-weight: 600; color: var(--color-primario); }
.maq-detalle-img { width: 72px; height: 72px; flex: none; border-radius: 8px; object-fit: cover; font-size: 1.8rem; }
.maq-detalle .nav-tabs .nav-link { padding: .45rem .7rem; font-size: .85rem; }
.maq-volver { display: none; margin-bottom: .75rem; }
@media (max-width: 991.98px) {
  .maq-split { grid-template-columns: minmax(0, 1fr); height: auto; min-height: 0; }
  .maq-lista, .maq-detalle { overflow: visible; }
  .maq-split .maq-detalle { display: none; }
  .maq-split.con-detalle .maq-lista { display: none; }
  .maq-split.con-detalle .maq-detalle { display: flex; }
  .maq-volver { display: inline-block; }
}
.maq-bloque { border: 1px solid #edf0f3; border-radius: 8px; padding: .85rem 1rem; height: 100%; }
.maq-bloque h6 { font-weight: 600; color: var(--color-primario); margin-bottom: .6rem; }
.maq-dato { display: flex; justify-content: space-between; gap: 1rem; padding: .3rem 0; border-bottom: 1px dashed #edf0f3; font-size: .9rem; }
.maq-dato:last-child { border-bottom: 0; }
.maq-dato-etiqueta { color: #6c757d; }
.maq-dato-etiqueta { flex: none; }
.maq-dato-valor { font-weight: 500; text-align: right; min-width: 0; overflow-wrap: break-word; }
.maq-general { display: grid; grid-template-columns: repeat(auto-fit, minmax(max(290px, calc(50% - .5rem)), 1fr)); gap: 1rem; }
.maq-bloque-ancho { grid-column: 1 / -1; }
