/* =====================================================================
   Variables de tema — colores de marca
   Azul  rgb(10,50,135)  = #0A3287
   Rojo  rgb(221,39,29)  = #DD271D
   Verde rgb(130,255,0)  = #82FF00
===================================================================== */
:root {
  /* Colores de marca tal cual (para usarlos directo donde haga falta) */
  --brand-blue: #0a3287;
  --brand-red: #dd271d;
  --brand-green: #82ff00;

  --color-bg-start: #eef1f8;
  --color-bg-end: #dde3ef;

  --color-primary: var(--brand-blue);
  --color-primary-hover: #072461; /* azul de marca, ~20% más oscuro, para hover */
  --color-primary-soft: #eaf0fb;  /* azul de marca muy claro, para fondos suaves */

  --color-accent: var(--brand-blue);
  --color-accent-hover: #072461;

  --color-success: var(--brand-green);
  --color-success-text: #1f4a00; /* verde oscuro, para que el texto se lea sobre el verde de marca */
  --color-success-soft: #eeffdb;

  --color-danger: var(--brand-red);
  --color-danger-hover: #b21f17; /* rojo de marca, más oscuro, para hover */
  --color-danger-soft: #fdecea;

  --color-surface: #ffffff;
  --color-surface-muted: #f1f4f9;
  --color-border: #e0e5ee;
  --color-text: #1c2233;
  --color-text-muted: #626b80;
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 3px rgba(10, 50, 135, .08);
  --shadow-md: 0 10px 30px rgba(10, 50, 135, .14);
  --transition: 150ms ease;
}

* {
  box-sizing: border-box;
}

/* Nota: se usa "campo-oculto" (no "oculto") para no interferir con el
   overlay de carga, que también usa una clase "oculto" pero con
   transición de opacidad en vez de display:none. */
.campo-oculto {
  display: none;
}

.opcion-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
}

.opcion-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-width: 18px;
  accent-color: var(--color-accent);
  cursor: pointer;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(160deg, var(--color-bg-start) 0%, var(--color-bg-end) 100%);
  background-attachment: fixed;
  color: var(--color-text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  line-height: 1.4;
}

/* =====================================================================
   Elementos de formulario base (compartidos por login y conteo)
===================================================================== */
label {
  display: block;
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  margin: 16px 0 6px;
  color: var(--color-text-muted);
}

label:first-of-type {
  margin-top: 0;
}

input,
select,
button {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--color-border);
  box-sizing: border-box;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

input::placeholder {
  color: #94a3b8;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(10, 50, 135, .15);
}

input[readonly],
input:disabled,
select:disabled {
  background: var(--color-surface-muted);
  color: var(--color-text-muted);
  cursor: not-allowed;
  pointer-events: none;
}

button {
  background: var(--color-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 600;
  margin-top: 18px;
  padding: 13px 16px;
  min-height: 46px;
}

button:hover {
  background: var(--color-primary-hover);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.mensaje {
  color: var(--color-danger);
  font-size: .85rem;
  min-height: 1.1em;
  margin: 10px 0 0;
}

.mensaje:not(:empty) {
  padding: 9px 12px;
  background: var(--color-danger-soft);
  border: 1px solid #f5c2bd;
  border-radius: var(--radius-sm);
}

/* =====================================================================
   Pantalla de LOGIN
===================================================================== */
.contenedor-login {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

.marca {
  width: 84px;
  height: 84px;
  border-radius: 20px;
  background: #ffffff;
  border: 2.5px solid var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  box-shadow: var(--shadow-md);
  padding: 10px;
  overflow: hidden;
}

.marca img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Logo chico dentro de la barra superior (app de conteo y panel admin) */
.logo-header {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 6px;
  background: #fff;
  padding: 3px;
  flex-shrink: 0;
}

.contenedor-login h1 {
  font-size: clamp(1.25rem, 4vw, 1.6rem);
  margin: 0 0 24px;
  text-align: center;
  color: var(--color-primary);
}

.tarjeta {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: clamp(20px, 5vw, 32px);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 400px;
  margin-bottom: 20px;
}

.opciones-tipo {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--color-surface-muted);
  padding: 4px;
  border-radius: var(--radius-md);
  margin: 6px 0 4px;
}

.opcion-radio {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: .88rem;
  font-weight: 700;
  color: var(--color-text-muted);
  margin: 0;
  padding: 11px 8px;
  border-radius: 7px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  position: relative;
}

.opcion-radio input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.opcion-radio:has(input:checked) {
  background: var(--color-primary);
  color: #fff;
}

.nota {
  font-size: .78rem;
  color: var(--color-text-muted);
  margin-top: 4px;
  text-align: center;
  max-width: 380px;
  line-height: 1.5;
}

.enlace-admin {
  display: inline-block;
  margin-top: 18px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color var(--transition), border-color var(--transition);
}

.enlace-admin:hover {
  color: var(--color-accent);
  border-color: var(--color-accent);
}

/* =====================================================================
   Pantalla de CONTEO
===================================================================== */
.barra-superior {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: var(--color-primary);
  color: #fff;
  flex-wrap: wrap;
  gap: 10px;
  box-shadow: var(--shadow-md);
}

.barra-superior > div {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.barra-superior strong {
  font-size: 1.02rem;
  letter-spacing: .01em;
}

.barra-superior button {
  width: auto;
  padding: 8px 14px;
  font-size: .82rem;
  margin-top: 0;
  min-height: 36px;
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .22);
  color: #fff;
}

.barra-superior button:hover {
  background: rgba(255, 255, 255, .22);
}

/* Salir / cerrar sesión: tinte rojo para que se note que es una acción
   distinta (salir) de las demás del header. */
#btn-salir,
#btn-cerrar-sesion {
  background: rgba(221, 39, 29, .3);
  border-color: rgba(221, 39, 29, .55);
}

#btn-salir:hover,
#btn-cerrar-sesion:hover {
  background: var(--color-danger);
  border-color: var(--color-danger);
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .02em;
}

.badge-online {
  background: var(--color-success);
  color: var(--color-success-text);
}

.badge-offline {
  background: var(--color-danger);
  color: #fff;
}

.estado-sync {
  text-align: center;
  font-size: .82rem;
  color: var(--color-text-muted);
  padding: 10px 16px;
  margin: 0;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  min-height: 1.2em;
}

.contenedor {
  max-width: 960px;
  margin: 0 auto;
  padding: clamp(14px, 3vw, 24px);
}

.contenedor .tarjeta {
  max-width: none;
  margin-bottom: 18px;
}

.tarjeta h2 {
  margin: 0 0 4px;
  font-size: 1.02rem;
  color: var(--color-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.tarjeta h2 #contadorLineas {
  color: var(--color-accent);
  font-weight: 800;
}

.icono-seccion {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  min-width: 26px;
  border-radius: 50%;
  background: var(--color-accent);
  color: #fff;
  font-size: .78rem;
  font-weight: 800;
}

.ayuda-seccion {
  margin: 0 0 4px;
  font-size: .8rem;
  color: var(--color-text-muted);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.preview {
  font-size: .8rem;
  min-height: 1.1em;
}

.preview:not(:empty) {
  display: inline-flex;
  align-items: center;
  margin-top: 8px;
  padding: 6px 12px;
  color: var(--color-success-text);
  font-weight: 700;
  background: var(--color-success-soft);
  border: 1px solid #cdf0a0;
  border-radius: 999px;
}

.preview-error:not(:empty) {
  color: var(--color-danger-hover);
  background: var(--color-danger-soft);
  border-color: #f5c2bd;
}

#btn-agregar-linea {
  max-width: 260px;
}

.tabla-scroll {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  margin-top: 14px;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
}

thead th {
  background: var(--color-primary);
  text-align: left;
  padding: 11px 14px;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #fff;
  border-bottom: 1px solid var(--color-primary);
  white-space: nowrap;
}

thead tr:first-child th:first-child {
  border-top-left-radius: var(--radius-sm);
}

thead tr:first-child th:last-child {
  border-top-right-radius: var(--radius-sm);
}

tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--color-border);
  font-size: .9rem;
}

tbody tr:nth-child(even) {
  background: var(--color-surface-muted);
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--color-primary-soft);
}

.btn-quitar {
  width: auto;
  padding: 6px 12px;
  background: transparent;
  color: var(--color-danger);
  border: 1.5px solid var(--color-danger);
  font-size: .76rem;
  margin-top: 0;
  font-weight: 700;
  min-height: 32px;
}

.btn-quitar:hover {
  background: var(--color-danger);
  color: #fff;
}

.boton-guardar {
  max-width: 340px;
  display: block;
  margin: 22px auto 8px;
  font-size: 1.02rem;
  padding: 16px;
  background: var(--color-success);
  color: var(--color-success-text);
}

.boton-guardar:hover {
  background: #6bcc00;
}

/* =====================================================================
   Overlay de carga (pop-up "Cargando...")
===================================================================== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 50, 135, .55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 1;
  transition: opacity 180ms ease, visibility 180ms ease;
}

.overlay.oculto {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay-caja {
  background: var(--color-surface);
  padding: 30px 40px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  min-width: 220px;
  text-align: center;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid var(--color-surface-muted);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: girar .75s linear infinite;
}

@keyframes girar {
  to {
    transform: rotate(360deg);
  }
}

#overlay-texto {
  margin: 0;
  font-size: .92rem;
  font-weight: 600;
  color: var(--color-text);
}

/* =====================================================================
   Animación de entrada de tarjetas
===================================================================== */
@keyframes aparecer {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.tarjeta {
  animation: aparecer .3s ease both;
}

/* =====================================================================
   Responsive
===================================================================== */
@media (max-width: 640px) {
  .barra-superior {
    padding: 12px 14px;
  }

  .barra-superior > div:first-child {
    width: 100%;
    justify-content: space-between;
  }

  .barra-superior > div:last-child {
    width: 100%;
    justify-content: space-between;
  }

  .boton-guardar {
    max-width: 100%;
    position: sticky;
    bottom: 12px;
    box-shadow: var(--shadow-md);
  }

  #btn-agregar-linea {
    max-width: 100%;
  }
}

@media (max-width: 400px) {
  .opcion-radio {
    font-size: .8rem;
    padding: 10px 4px;
  }
}
