/* Tipografía corporativa: Futura (Ruben, 2026-09-29), ficheros oficiales
   del grupo (GM_Proyectos/00_Generales/Logos/futura) pasados a woff2 en
   static/vendor/futura: Light BT 300, Book BT 400, Medium BT 500,
   Heavy BT 600, Bold 700. No traen el signo €: ese carácter (y cualquier
   otro que falte) lo pinta Jost (static/vendor/jost, OFL, clon libre de
   Futura), que va justo detrás en la lista. */
@font-face { font-family: "Futura GM"; src: url("/static/vendor/futura/futura-300.woff2") format("woff2"); font-weight: 300; font-display: swap; }
@font-face { font-family: "Futura GM"; src: url("/static/vendor/futura/futura-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Futura GM"; src: url("/static/vendor/futura/futura-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Futura GM"; src: url("/static/vendor/futura/futura-600.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Futura GM"; src: url("/static/vendor/futura/futura-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Jost"; src: url("/static/vendor/jost/jost-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Jost"; src: url("/static/vendor/jost/jost-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Jost"; src: url("/static/vendor/jost/jost-600.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Jost"; src: url("/static/vendor/jost/jost-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  /* Un solo tamaño para todos los textos de la cabecera: pestañas,
     Facturas/Presupuestos y botones (Ruben, 2026-09-29). */
  --topbar-font: 13px;
  --font: "Futura GM", "Jost", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #1c1f26;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eef2ff;
  --primary-soft-text: #4338ca;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

/* Fondos invertidos (Ruben, 2026-09-29): cuerpo blanco como la cabecera y
   tarjetas en gris (antes al revés). */
body {
  margin: 0;
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 18px 28px;
  background: var(--surface);
}

.topbar h1 {
  font-size: 20px;
  margin: 0;
  line-height: 0;
  align-self: center;
}

/* Logo en lugar del texto "Grupo Mambo" (Ruben, 2026-09-29). */
.topbar-logo {
  display: block;
  height: 36px;
  width: auto;
}

.summary {
  color: var(--text-muted);
  font-size: 14px;
}

.topbar-spacer {
  flex: 1;
}

.user-badge {
  font-size: 13px;
  color: var(--text-muted);
  align-items: center;
  gap: 8px;
}

.user-badge:not([hidden]) {
  display: flex;
}

.topbar #btn-refresh-scan { font-size: var(--topbar-font); }

.user-badge .btn-logout {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: var(--topbar-font);
  cursor: pointer;
}

.select-gestor {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.45);
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

/* [hidden] es un selector de igual especificidad que .modal-overlay — sin
   esto, "display: flex" de arriba lo pisaría y el modal se vería siempre. */
.modal-overlay:not([hidden]) {
  display: flex;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  width: 100%;
  max-width: 340px;
}

.modal-card h2 {
  font-size: 17px;
  margin: 0 0 16px;
}

.modal-card label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.modal-card input[type="password"] {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}

.modal-error {
  color: var(--danger);
  font-size: 13px;
  margin: 0 0 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.scan-banner {
  padding: 8px 28px;
  font-size: 13px;
  background: #f3f4f6;
  color: #374151;
  border-bottom: 1px solid var(--border);
}

/* Franja "Último escaneo" oculta en móvil y escritorio (Ruben, 2026-09-29):
   era una barra gris entre la cabecera y el cuerpo. */
.scan-banner { display: none; }

.scan-banner.scan-banner-warn {
  background: #e5e7eb;
  color: #111827;
  font-weight: 600;
}

.board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  padding: 20px 28px 40px;
  max-width: 1400px;
  margin: 0 auto;
  align-items: start;
}

/* Selector Facturas / Presupuestos: solo en móvil (Ruben, 2026-09-29). */
.doc-switch { display: none; }

@media (max-width: 860px) {
  .board { grid-template-columns: 1fr; }

  .doc-switch:not([hidden]) {
    display: flex;
    width: 100%;
    gap: 4px;
    padding: 3px;
    background: #f3f4f6;
    border-radius: 10px;
  }

  /* Solo se ve la columna elegida en el selector. */
  .board[data-pane="facturas"] .pane-presupuestos,
  .board[data-pane="presupuestos"] .pane-facturas { display: none; }

  /* El título y su contador ya están en el selector. */
  .pane > h2:first-child { display: none; }
}

.doc-switch-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 10px;
  border: none;
  border-radius: 8px;
  background: none;
  font-size: var(--topbar-font);
  font-weight: 600;
  color: var(--text-muted);
}

.doc-switch-btn.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow);
}
.doc-switch-presupuestos.active { color: #0891b2; }

.doc-switch-count {
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--primary);
  color: #fff;
}
.doc-switch-presupuestos .doc-switch-count { background: #0891b2; }

.pane h2 {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 12px 2px;
}

/* Presupuestos en azul cian (Ruben, 2026-09-28): redefinir el primario aquí
   cambia a la vez botones, pestañas y etiquetas. (La línea de color encima
   de cada columna se quitó el 2026-09-29.) */
.pane-presupuestos {
  --primary: #0891b2;
  --primary-hover: #0e7490;
  --primary-soft: #ecfeff;
  --primary-soft-text: #0e7490;
}
.pane-count { text-transform: none; letter-spacing: 0; font-weight: 500; }

/* Historial plegado por defecto: lo pendiente queda arriba y a la vista. */
.historial { margin-top: 20px; }
.historial > summary {
  cursor: pointer;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 12px 2px;
}

/* Filtro del master "Ver también las de otros gestores". */
.filtro-todas {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 28px 0;
  display: flex;
  justify-content: flex-end;
}
.filtro-todas[hidden] { display: none; }
.switch-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.switch-label input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: #d1d5db;
  transition: background 0.15s;
  flex-shrink: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s;
}
.switch-label input:checked + .switch { background: var(--text); }
.switch-label input:checked + .switch::after { transform: translateX(14px); }
.switch-label input:focus-visible + .switch { outline: 2px solid var(--primary); outline-offset: 2px; }

.asignada-a {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  background: #e5e7eb;
  border-radius: 999px;
  padding: 3px 10px;
  margin-bottom: 10px;
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.empty-msg {
  color: var(--text-muted);
  font-size: 14px;
  padding: 20px;
  text-align: center;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

/* --- invoice cards --- */

.invoice-card .card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

/* Proveedor / nº de factura largos sin espacios: que partan línea en vez
   de empujar el importe fuera de la tarjeta (en móvil ensanchaba la página). */
.invoice-card .card-head > div:first-child { min-width: 0; overflow-wrap: anywhere; }
.invoice-card .card-head > div:last-child { flex-shrink: 0; text-align: right; }

.invoice-card .proveedor {
  font-weight: 600;
  font-size: 15px;
}

.invoice-card .meta {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 2px;
}

.invoice-card .importe {
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-pendiente_ot, .badge-pendiente_recursos { background: var(--primary-soft); color: var(--primary-soft-text); }
.badge-esperando_pdf { background: #fff7ed; color: var(--warn); }
.badge-completada { background: #ecfdf5; color: var(--ok); }
.badge-descartada { background: #f3f4f6; color: var(--text-muted); }
.badge-error { background: #fef2f2; color: var(--danger); }

.conceptos {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}

.conceptos li {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
  color: var(--text-muted);
}

.conceptos li span:first-child { min-width: 0; overflow-wrap: anywhere; }

.conceptos li span:last-child {
  flex-shrink: 0;
  padding-left: 8px;
  white-space: nowrap;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.ot-line {
  margin-top: 10px;
  font-size: 13px;
  color: var(--primary);
  font-weight: 600;
}

.error-line {
  margin-top: 10px;
  font-size: 13px;
  color: var(--danger);
}

.card-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

.pdf-link {
  display: inline-block;
  margin-top: 10px;
  font-size: 13px;
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}
.pdf-link:hover { text-decoration: underline; }

/* --- doubt cards --- */

.doubt-card .ref {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.doubt-card .question {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  line-height: 1.4;
}

.invoice-edit label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.invoice-edit input[type="text"] {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}

.concepto-editor { margin: 12px 0; }

.concepto-row {
  display: grid;
  grid-template-columns: 1fr 90px auto;
  gap: 6px;
  margin-bottom: 6px;
}

.concepto-row input {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}

.btn-remove-line {
  border: none;
  background: #fef2f2;
  color: var(--danger);
  border-radius: 6px;
  width: 28px;
  font-size: 13px;
}
.btn-remove-line:hover { background: #fee2e2; }

.doubt-form label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.doubt-form input[type="text"],
.doubt-form select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  border: none;
  background: none;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

/* "Adjuntar a esta OT" a la izquierda y "Mover a …" a la derecha, en la
   misma fila (Ruben, 2026-09-29). */
.fila-adjuntar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.fila-adjuntar .btn-mover-tipo { white-space: nowrap; }
/* En móvil el botón dice "A Presupuestos →" / "← A Facturas" para caber
   en la fila junto a "Adjuntar a esta OT". */
.btn-mover-tipo .txt-corto { display: none; }
@media (max-width: 860px) {
  .btn-mover-tipo .txt-largo { display: none; }
  .btn-mover-tipo .txt-corto { display: inline; }
  .fila-adjuntar .btn-primary,
  .fila-adjuntar .btn-mover-tipo { padding: 9px 11px; }
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.choice-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.proveedor-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.concept-line {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.lineas-list {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.linea-concepto {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.linea-concepto:last-child { border-bottom: none; }

/* Prefijo ".doubt-form" en estas 4 reglas a propósito: sin él, las reglas
   genéricas ".doubt-form label" y ".doubt-form input[type=text]" (más
   arriba) tienen más especificidad CSS y ganan, forzando display:block y
   width:100% aquí - eso hacía que el recuadro de importe se estirase a
   todo el ancho y se montase encima del texto de la descripción.
   OJO con ".linea-importe-input" en concreto: ".doubt-form" + una sola
   clase (0,2,0) sigue perdiendo contra ".doubt-form input[type=text]"
   (0,2,1) - el selector de tipo "input" cuenta un punto más. Hace falta
   una clase extra (".lineas-list") para ganar con margen (0,3,0). */
.doubt-form .linea-check {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  margin-bottom: 0;
}

.doubt-form .linea-check .linea-desc {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doubt-form .linea-importe-fijo {
  font-weight: 600;
  white-space: nowrap;
}

.doubt-form .lineas-list .linea-importe-input {
  display: inline-block;
  width: 120px;
  flex: 0 0 auto;
  margin-top: 0;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}

.pdf-preview-wrap {
  margin-bottom: 14px;
}

/* Visor del PDF con la proporción del papel A (210 × 297, vertical)
   (Ruben, 2026-09-29), en escritorio (<iframe>) y en móvil (PDF.js). */
.pdf-frame {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 210 / 297;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* PDF dibujado con PDF.js en móvil: páginas apiladas en una caja con
   scroll propio, como el <iframe> de escritorio. */
.pdf-pages {
  aspect-ratio: 210 / 297;
  overflow: auto;
  /* Solo desplazar: el pellizco lo gestiona app.js (activarZoomPdf). */
  touch-action: pan-x pan-y;
  padding: 8px;
  background: #e5e7eb;
  border: 1px solid var(--border);
  border-radius: 8px;
}
/* Su ancho crece con el zoom (100% = sin ampliar). */
.pdf-inner {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}
.pdf-page {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
  box-shadow: var(--shadow);
}
.pdf-loading { margin: 0; padding: 20px; text-align: center; }

.pdf-missing {
  font-size: 13px;
  color: var(--warn);
  background: #fff7ed;
  border: 1px dashed #fed7aa;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.btn-primary, .btn-danger, .btn-choice, .btn-secondary {
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }

.btn-choice { background: var(--primary-soft); color: var(--primary-soft-text); }
.btn-choice:hover { background: #e0e7ff; }

.btn-secondary { background: #f3f4f6; color: var(--text); }
.btn-secondary:hover { background: #e5e7eb; }
/* Dentro de las tarjetas (ahora grises) el botón gris no se distinguía. */
.card .btn-secondary { background: var(--surface); box-shadow: inset 0 0 0 1px var(--border); }
.card .btn-secondary:hover { background: #e5e7eb; }

/* Pestañas con la misma estructura que el selector Facturas / Presupuestos
   (Ruben, 2026-09-29): caja gris y la pestaña activa en blanco con sombra. */
.app-tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: #f3f4f6;
  border-radius: 10px;
}

.app-tab {
  font-size: var(--topbar-font);
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.app-tab:hover:not(.active) { background: rgba(255, 255, 255, 0.6); }

.app-tab.active {
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.dashboard-iframe {
  display: block;
  width: 100%;
  height: 88vh;
  border: 0;
}

.muted { color: var(--text-muted); font-size: 13px; }

.aviso-banner {
  color: #7c4a03;
  background: #fef3e0;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}

.equipo-hint {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 8px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.equipo-hint-text { font-weight: 600; color: var(--text); }
.btn-link {
  background: none;
  border: none;
  padding: 0;
  margin-left: 6px;
  color: var(--primary);
  text-decoration: underline;
  font-size: 13px;
  cursor: pointer;
}

.doubt-card.busy .doubt-form { opacity: 0.5; pointer-events: none; }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.toast-error { background: var(--danger); }

/* ---------- Pestaña Sensores ---------- */
.sensores-view { padding: 20px 28px 40px; }

.sensores-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-bottom: 16px;
}

.sensores-resumen { display: flex; gap: 8px; flex-wrap: wrap; }

.estado-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
}
.estado-ok { color: #166534; background: #ecfdf3; border-color: #86d9a4; }
.estado-fallo { color: #991b1b; background: #fef2f2; border-color: #f0a3a3; }
.estado-manual { color: #4b5563; background: #f3f4f6; border-color: #d1d5db; }

.sensores-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  align-items: start;
}

.local-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px 16px;
}
.local-box.fallo { border-color: var(--danger); }

.local-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.local-head h3 { margin: 0; font-size: 16px; }
.local-head .muted { font-size: 12px; }

.dev-list { display: flex; flex-direction: column; gap: 6px; }

.dev-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid;
  border-left-width: 5px;
  cursor: pointer;
}
.dev-chip:hover { filter: brightness(0.97); }
.dev-chip:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.dev-chip.ok { background: #ecfdf3; border-color: #86d9a4; border-left-color: var(--ok); }
.dev-chip.fallo { background: #fef2f2; border-color: #f0a3a3; border-left-color: var(--danger); }
.dev-chip.manual { background: #f3f4f6; border-color: #d1d5db; border-left-color: #9ca3af; }
.dev-chip .dev-name { flex: 1; font-weight: 600; }
.dev-chip .dev-sub { display: block; font-weight: 400; font-size: 12px; color: var(--text-muted); }
.dev-chip .dev-state { font-size: 12px; font-weight: 700; white-space: nowrap; }
.dev-chip.ok .dev-state { color: #166534; }
.dev-chip.fallo .dev-state { color: #991b1b; }
.dev-chip.manual .dev-state { color: #4b5563; }

.sensor-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(16, 24, 40, 0.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 4vh 16px;
  overflow-y: auto;
}
.sensor-modal[hidden] { display: none; }
.sensor-modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  width: min(880px, 100%);
  padding: 18px 20px 22px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, 0.25);
}
.sensor-modal-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-bottom: 14px; }
.sensor-modal-head h2 { margin: 0; font-size: 18px; }

.range-btns { display: flex; gap: 2px; background: #f3f4f6; border-radius: 8px; padding: 2px; }
.range-btn {
  font: inherit; font-size: 13px; font-weight: 600; color: var(--text-muted);
  background: none; border: none; border-radius: 6px; padding: 5px 10px; cursor: pointer;
}
.range-btn.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }

.medidor-card { border-top: 1px solid var(--border); padding: 14px 0 6px; }
.medidor-card:first-child { border-top: none; padding-top: 0; }
.medidor-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 12px; margin-bottom: 6px; }
.medidor-head h4 { margin: 0; font-size: 14px; }
.medidor-valor { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.medidor-valor small { font-size: 12px; font-weight: 500; color: var(--text-muted); }
.medidor-motivo { font-size: 12px; color: var(--text-muted); }

.chart-wrap { position: relative; width: 100%; }
.chart-wrap svg { display: block; width: 100%; height: auto; }
.chart-empty { font-size: 13px; color: var(--text-muted); padding: 18px 0; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 2;
  background: var(--text); color: #fff; font-size: 12px; line-height: 1.35;
  padding: 5px 8px; border-radius: 6px; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.chart-grid { stroke: #e5e7eb; stroke-width: 1; }
.chart-axis-label { fill: #6b7280; font-size: 11px; }
.chart-line { fill: none; stroke: #2a78d6; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: #2a78d6; stroke: #fff; stroke-width: 2; }
.chart-limit { stroke: #dc2626; stroke-width: 1; stroke-dasharray: 4 4; }
.chart-limit-label { fill: #b91c1c; font-size: 11px; }
.chart-cross { stroke: #9ca3af; stroke-width: 1; }

@media (max-width: 480px) {
  .sensores-view { padding: 16px 16px 32px; }
  .sensores-grid { grid-template-columns: 1fr; }
}

/* Ajustes de móvil al final: así ganan a las reglas base de arriba. */

/* Cabecera en móvil (Ruben, 2026-09-29), todo a ancho completo:
     1) Grupo Mambo ........ Contraseña · Salir · Actualizar
     2) nombre del usuario
     3) pestañas Panel / Dashboard / Sensores
     4) selector Facturas / Presupuestos
   El badge de usuario se "disuelve" (display: contents) para que su nombre
   y sus dos botones se coloquen cada uno en su sitio de la rejilla. */
@media (max-width: 860px) {
  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto auto;
    grid-template-areas:
      "title pass logout refresh"
      "name  name name   name"
      "tabs  tabs tabs   tabs"
      "switch switch switch switch";
    align-items: center;
    gap: 6px 4px;
    padding: 12px 16px;
  }
  .topbar h1 { grid-area: title; min-width: 0; }
  /* En pantallas estrechas el logo se encoge antes que los botones. */
  .topbar-logo {
    height: 30px;
    max-width: 100%;
    object-fit: contain;
    object-position: left center;
  }
  .summary, .topbar-spacer { display: none; }
  .topbar .user-badge:not([hidden]) { display: contents; }
  /* Nombre pequeño, a la derecha, bajo "Actualizar" (Ruben, 2026-09-29). */
  .user-name { grid-area: name; justify-self: end; font-size: 11px; color: var(--text-muted); margin-top: -2px; }
  .btn-change-password { grid-area: pass; }
  .btn-logout:not(.btn-change-password) { grid-area: logout; }
  #btn-refresh-scan { grid-area: refresh; }
  .topbar .btn-logout,
  .topbar #btn-refresh-scan {
    padding: 7px 7px;
    font-size: var(--topbar-font);
    border-radius: 6px;
    white-space: nowrap;
  }

  .app-tabs { grid-area: tabs; margin-top: 4px; }
  /* Cada pestaña ocupa lo que necesita su texto; si aun así no caben
     (master con Dashboard + Sensores en un móvil estrecho), la fila se
     desplaza en horizontal en vez de ensanchar la página. */
  .app-tabs { overflow-x: auto; scrollbar-width: none; }
  .app-tabs::-webkit-scrollbar { display: none; }
  .app-tab { flex: 1 0 auto; white-space: nowrap; padding: 9px 8px; }
  /* Pestañas de la tarjeta (OT existente · Crear OT · Asignar · Descartar):
     si no caben, pasan a una segunda línea. */
  .tabs { flex-wrap: wrap; }
  .tabs .tab-btn { white-space: nowrap; padding: 8px 8px; }
  .doc-switch:not([hidden]) { grid-area: switch; }

  /* Al bajar por las tarjetas, la cabecera sube pero la fila Facturas /
     Presupuestos se queda anclada arriba (Ruben, 2026-09-29). La cabecera
     entera es "sticky" con un top negativo = lo que mide por encima de esa
     fila; app.js (ajustarCabeceraFija) calcula ese valor. */
  .topbar {
    position: sticky;
    top: var(--topbar-stick, 0px);
    z-index: 20;
  }
}

/* Contenido en móvil alineado con la cabecera (Ruben, 2026-09-29): mismo
   margen lateral de 16px, y el PDF ocupa todo el ancho de la tarjeta (se
   come el relleno lateral de la tarjeta con margen negativo), para que sus
   bordes coincidan con los de la cabecera y las tarjetas. */
@media (max-width: 860px) {
  /* Sin zoom del navegador en todo el panel; solo el PDF se amplía. */
  html, body { touch-action: pan-x pan-y; }
  /* minmax(0, 1fr) y min-width: 0 impiden que algo ancho (un canvas del PDF,
     un texto sin cortes) ensanche la columna más que la pantalla: entonces
     el móvil se aleja y la cabecera se ve más estrecha que el contenido. */
  .board { grid-template-columns: minmax(0, 1fr); padding: 12px 16px 32px; gap: 16px; }
  .filtro-todas { padding: 12px 16px 0; }
  .pane, .card, .pdf-preview-wrap { min-width: 0; }
  .scan-banner { padding: 8px 16px; }
  .card { padding: 14px; }
  .pdf-preview-wrap { margin-left: -14px; margin-right: -14px; }
  .pdf-pages {
    padding: 6px 0;
    border-left: none;
    border-right: none;
    border-radius: 0;
  }
  .pdf-page { box-shadow: none; }
  .toast { left: 16px; right: 16px; bottom: 16px; text-align: center; }
}
