:root {
  --fondo: #ece9e1;
  --panel: #ffffff;
  --borde: #d8d3c3;
  --borde-fuerte: #c3bda8;
  --texto: #1a1d1a;
  --tenue: #6b6f61;
  --acento: #b5470d;
  --acento-tenue: #f4e2d6;
  --verde: #1b6b3d;
  --verde-fondo: #e3efe4;
  --ambar: #9a5b12;
  --rojo: #ab2a1e;
  --rojo-fondo: #fbe8e4;
  --gris-fondo: #edeade;
}

/* Sigue la preferencia del sistema operativo, salvo que se haya tocado el
   botón de tema — ahí gana lo que la persona eligió, sea cual sea el modo
   del sistema. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fondo: #17181a;
    --panel: #202224;
    --borde: #34363a;
    --borde-fuerte: #46484d;
    --texto: #ece9e2;
    --tenue: #9a9c92;
    --acento: #e07a3e;
    --acento-tenue: #3a2a1e;
    --verde: #6cbf8b;
    --verde-fondo: #1c2e22;
    --ambar: #d0973f;
    --rojo: #e2685a;
    --rojo-fondo: #33201d;
    --gris-fondo: #26282a;
  }
}

:root[data-theme="dark"] {
  --fondo: #17181a;
  --panel: #202224;
  --borde: #34363a;
  --borde-fuerte: #46484d;
  --texto: #ece9e2;
  --tenue: #9a9c92;
  --acento: #e07a3e;
  --acento-tenue: #3a2a1e;
  --verde: #6cbf8b;
  --verde-fondo: #1c2e22;
  --ambar: #d0973f;
  --rojo: #e2685a;
  --rojo-fondo: #33201d;
  --gris-fondo: #26282a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  font-size: 15px;
}

.barra {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--borde);
}

.barra-derecha { display: flex; align-items: center; gap: 0.75rem; }

.barra h1 {
  font-family: "Bahnschrift", "Arial Narrow", system-ui, sans-serif;
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: 0.01em;
  margin: 0;
}
.sesion-actual { color: var(--tenue); }

.pestanas {
  display: flex;
  gap: 0.25rem;
  padding: 0 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--borde);
}

.pestanas button {
  border: 0;
  background: none;
  padding: 0.7rem 1rem;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--tenue);
  border-bottom: 3px solid transparent;
}

.pestanas button.activa {
  color: var(--acento);
  border-bottom-color: var(--acento);
  font-weight: 600;
}

main { padding: 1.25rem; }
/* Los bloques que además definen su propio `display` necesitan nombrarse
   acá: tienen la misma especificidad que `.oculta` y, al estar más abajo en
   la hoja, ganarían por orden y quedarían siempre visibles. */
.vista.oculta, .instalacion.oculta, .oculta { display: none; }

.metricas {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.metrica {
  background: var(--panel);
  border: 1px solid var(--borde);
  border-left: 3px solid var(--borde-fuerte);
  border-radius: 6px;
  padding: 0.75rem 1rem;
}

.metrica.acento { border-left-color: var(--acento); }
.metrica.alerta { border-left-color: var(--rojo); }

.metrica .valor {
  font-family: "Bahnschrift", "Arial Narrow", system-ui, sans-serif;
  font-weight: 600;
  font-size: 1.7rem;
  font-variant-numeric: tabular-nums;
}
.metrica .rotulo {
  color: var(--tenue);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.filtros {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  align-items: center;
}

input, select, button, .boton {
  font: inherit;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--borde);
  border-radius: 5px;
  background: var(--panel);
  color: var(--texto);
}

button, .boton {
  cursor: pointer;
  background: var(--acento);
  color: #fff;
  border-color: var(--acento);
  text-decoration: none;
}

button.secundario, .boton.secundario {
  background: var(--panel);
  color: var(--texto);
  border-color: var(--borde);
}

.tabla-envoltorio {
  overflow: auto;
  max-height: calc(100vh - 320px);
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 6px;
}

table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }

th, td {
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--borde);
  text-align: left;
  white-space: nowrap;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
  box-shadow: inset 0 -1px 0 var(--borde);
  font-weight: 600;
  color: var(--tenue);
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
}

tbody tr { border-left: 3px solid transparent; }
tbody tr:nth-child(even) { background: color-mix(in srgb, var(--fondo) 45%, var(--panel)); }
tbody tr:hover { background: var(--acento-tenue); }

.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
.sku, td.sku { font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; color: var(--tenue); }

.estado {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.marca {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--borde);
  font-size: 0.78rem;
  color: var(--tenue);
}

.casilla {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--borde);
  border-radius: 5px;
  padding: 0.4rem 0.7rem;
  background: var(--panel);
}

.casilla input { padding: 0; }

.estado-consolidado { background: var(--verde-fondo); color: var(--verde); }
.estado-a-recontar { background: var(--rojo-fondo); color: var(--rojo); }
.estado-sin-contar { background: var(--gris-fondo); color: var(--tenue); }

.lista { list-style: none; padding: 0; }

.lista li {
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 6px;
  padding: 0.6rem 0.9rem;
  margin-bottom: 0.4rem;
}

.token {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.4rem;
  max-width: 46rem;
}

.token input {
  flex: 1;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.85rem;
  color: var(--tenue);
}

/* Uno al lado del otro: es lo que hace que se puedan escanear varios QR
   seguidos sin scrollear entre uno y el siguiente. */
.lista-operarios {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.lista-operarios li.operario {
  width: 320px;
  margin-bottom: 0;
}

.operario {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.sectores-asignados {
  color: var(--tenue);
  font-size: 0.85rem;
}

/* Aparte del campo del token: con la tarjeta angosta, compartir renglón con
   el input y "Copiar" hacía que el botón "Sectores" se saliera del esquema. */
.fila-sectores { margin-top: 0.4rem; }

.novedad {
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 6px;
  padding: 0.8rem 1rem;
  margin-bottom: 0.8rem;
}

.novedad h3 { margin: 0 0 0.4rem; }
.novedad ul { margin: 0; padding-left: 1.2rem; }

.instalacion {
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 6px;
  padding: 1rem;
  margin-bottom: 1.25rem;
}

.qr {
  width: 148px;
  height: 148px;
  border: 1px solid var(--borde);
  border-radius: 6px;
  background: var(--panel);
}

.chip-ubicacion {
  display: inline-block;
  padding: 0.08rem 0.5rem;
  border-radius: 4px;
  background: var(--gris-fondo);
  color: var(--tenue);
  font-size: 0.75rem;
  margin: 0.1rem 0.25rem 0.1rem 0;
}

.ayuda { color: var(--tenue); max-width: 60ch; }
.mapeo { margin-top: 1rem; }
.error { color: var(--rojo); }
.aviso { color: var(--tenue); }

dialog { max-width: 28rem; border: 1px solid var(--borde); border-radius: 8px; }

.tarjeta-operario {
  background: var(--panel);
  border: 1px solid var(--borde);
  border-left: 3px solid var(--borde-fuerte);
  border-radius: 8px;
  padding: 0.9rem 1.1rem;
  margin-bottom: 0.75rem;
}

/* De un vistazo, sin leer el número: terminó, está en curso, o no empezó. */
.tarjeta-operario.completo { border-left-color: var(--verde); }
.tarjeta-operario.en-curso { border-left-color: var(--acento); }

.tarjeta-operario summary {
  cursor: pointer;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  list-style: none;
}

/* Safari sigue mostrando el triángulo nativo aunque `list-style` lo
   esconda en los demás navegadores. Se reemplaza por una flecha propia,
   así se ve igual en todos lados y gira sola con el atributo `open` de
   `<details>`, sin JavaScript. */
.tarjeta-operario summary::-webkit-details-marker { display: none; }

.flecha-desplegar {
  font-size: 1.2rem;
  color: var(--tenue);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.tarjeta-operario[open] .flecha-desplegar { transform: rotate(180deg); }

.resumen-operario { display: flex; flex-direction: column; gap: 0.15rem; }
.ubicaciones-resumen { color: var(--tenue); font-size: 0.85rem; }

.resumen-numerico {
  display: flex;
  gap: 1.5rem;
}

.resumen-numerico .dato {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 4.5rem;
}

.resumen-numerico .valor {
  font-family: "Bahnschrift", "Arial Narrow", system-ui, sans-serif;
  font-weight: 600;
  font-size: 1.3rem;
  font-variant-numeric: tabular-nums;
}
.resumen-numerico .rotulo {
  color: var(--tenue);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: center;
}

.dato-verde { color: var(--verde); }
.dato-ambar { color: var(--ambar); }

.detalle-operario {
  margin-top: 0.9rem;
  border-top: 1px solid var(--borde);
  padding-top: 0.6rem;
}

#sectores-lista {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.6rem 0;
}

.tolerancia {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 8px;
  padding: 0.9rem 1.1rem;
  margin-bottom: 1.25rem;
}

.tolerancia label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--tenue);
}

#abrir-recuento { margin: 0.75rem 0 1.5rem; }

.tarjeta-recuento {
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 8px;
  padding: 0.9rem 1.1rem;
  margin-bottom: 0.75rem;
}

.tarjeta-recuento h4 { margin: 0; }

.encabezado-tarjeta-recuento {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.2rem;
}

.operarios-del-recuento {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.6rem 0;
}

.operario-recuento {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--borde);
  border-radius: 5px;
  padding: 0.25rem 0.25rem 0.25rem 0.6rem;
  font-size: 0.85rem;
}

.fila-ubicacion-recuento {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: 6px;
  padding: 0.6rem 0.9rem;
  margin-bottom: 0.4rem;
}

/* La fila salta a la vista sin tener que leer la columna de estado: el
   borde lateral se ve escaneando la tabla con la mirada, el chip de color
   solo no alcanza en una tabla larga. Van después de `:nth-child(even)`
   a propósito, misma especificidad, para ganarle por orden. */
tbody tr.fila-alerta {
  border-left-color: var(--rojo);
  background: color-mix(in srgb, var(--rojo-fondo) 55%, var(--panel));
}
tbody tr.fila-ok { border-left-color: var(--verde); }
