* { box-sizing: border-box; margin: 0; padding: 0; }
/* Sin barras de scroll visibles (el desplazamiento sigue funcionando con
   rueda/trackpad). Evita también el desbordamiento horizontal de la página. */
* { scrollbar-width: none; -ms-overflow-style: none; }
*::-webkit-scrollbar { width: 0; height: 0; }
html, body { overflow-x: hidden; max-width: 100vw; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; -webkit-font-smoothing: antialiased; }
.num, table td.num, .mono { font-variant-numeric: tabular-nums; }

/* LOGIN */
#login-overlay, #rol-sin-interfaz {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
#rol-sin-interfaz { display: none; }
#rol-sin-interfaz p { margin-bottom: 20px; }
.login-box {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 12px; padding: 40px; width: 360px; text-align: center;
}
.login-box h1 { font-size: 22px; margin-bottom: 6px; }
.login-box p  { color: var(--text2); margin-bottom: 28px; font-size: 13px; }
.form-group  { margin-bottom: 14px; text-align: left; }
.form-group label { display: block; margin-bottom: 6px; color: var(--text2); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.form-group input {
  width: 100%; padding: 10px 12px; background: var(--bg3);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 14px; outline: none;
}
.form-group input:focus { border-color: var(--accent); }
.btn-primary {
  width: 100%; padding: 11px; background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius); cursor: pointer;
  font-size: 14px; font-weight: 600; margin-top: 8px;
  transition: opacity .15s;
}
.btn-primary:hover { opacity: .85; }
#login-err { color: var(--red); font-size: 12px; margin-top: 10px; min-height: 18px; }

/* LAYOUT — barra lateral (rediseño Precision Analytical) */
#app { display: none; height: 100vh; overflow: hidden; }
.sidebar {
  /* fija: al desplegarse por hover se superpone al contenido en vez de
     empujarlo (asi no se re-maqueta la tabla y el gesto es instantaneo) */
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 120;
  width: var(--sidebar-w); flex-shrink: 0; background: var(--bg2);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  padding: 18px 14px; gap: 6px; overflow: hidden;
  /* Curva tipo "spring": arranca rapido y frena suave. La animacion del ancho
     re-maqueta el contenido en cada fotograma; es asumible porque las tablas
     estan paginadas (~50 filas = ~14 ms/toggle). Si algun dia se vuelven a
     pintar cientos de filas, esto volveria a dar tirones. */
  transition: width .34s cubic-bezier(.32,.72,0,1), padding .34s cubic-bezier(.32,.72,0,1);
  will-change: width;
}
/* Apertura por proximidad del ratón: la barra se despliega SOBRE el contenido
   (el margen de main no cambia) y se repliega al salir. Ver toggleSidebar. */
#app.nav-collapsed.hover-open .sidebar {
  width: var(--sidebar-w); padding-left: 14px; padding-right: 14px;
  box-shadow: 8px 0 32px var(--shadow);
}
/* Botón de plegar/desplegar (solo escritorio) */
.side-toggle {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text2); cursor: pointer; width: 28px; height: 28px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; margin-left: auto;
  transition: color .15s, border-color .15s, transform .34s cubic-bezier(.32,.72,0,1);
}
.side-toggle:hover { color: var(--text); border-color: var(--accent); }
.side-toggle svg { width: 15px; height: 15px; }
/* Estado plegado: solo iconos */
#app.nav-collapsed:not(.hover-open) .sidebar { width: 72px; padding-left: 10px; padding-right: 10px; }
#app.nav-collapsed:not(.hover-open) .sidebar .brand { padding-bottom: 12px; }
#app.nav-collapsed:not(.hover-open) .sidebar .brand > div:not(.mark) { display: none; }
#app.nav-collapsed:not(.hover-open) .sidebar .brand { justify-content: center; }
#app.nav-collapsed:not(.hover-open) .sidebar .brand .mark { display: none; }
#app.nav-collapsed:not(.hover-open) .side-toggle { margin: 0 auto; transform: rotate(180deg); }
#app.nav-collapsed:not(.hover-open) .side-foot .user-badge { display: none; }
/* Etiquetas: se desvanecen y el ancho de la barra las recorta (overflow:hidden).
   Se anima solo 'opacity' (compuesto por GPU), nunca font-size/padding, que
   forzarian un reflujo en cada fotograma y producian tirones. */
.nav-lbl {
  white-space: nowrap; overflow: hidden; max-width: 220px; opacity: 1;
  /* al DESPLEGAR el texto aparece con un pequeño retardo, cuando ya hay hueco */
  transition: opacity .22s ease .12s, max-width .34s cubic-bezier(.32,.72,0,1);
}
/* Al plegar, la etiqueta se desvanece rapido y deja de ocupar sitio, para que el
   icono quede centrado (si conservara su ancho, lo empujaria fuera de la barra) */
#app.nav-collapsed:not(.hover-open) .nav-lbl {
  opacity: 0; max-width: 0;
  transition: opacity .12s ease, max-width .34s cubic-bezier(.32,.72,0,1);
}
/* Los iconos si se animan: transform/opacity los compone la GPU (sin reflujo) */
.sidebar nav button svg, .side-foot .btn-sm svg {
  transition: transform .22s cubic-bezier(.32,.72,0,1);
}
#app.nav-collapsed:not(.hover-open) .sidebar nav button svg { transform: scale(1.08); }
.sidebar nav button, .side-foot .btn-sm { white-space: nowrap; }
#app.nav-collapsed:not(.hover-open) .sidebar nav button,
#app.nav-collapsed:not(.hover-open) .side-foot .btn-sm { justify-content: center; gap: 0; padding-left: 0; padding-right: 0; }
#app.nav-collapsed:not(.hover-open) .sidebar nav button > span:not(.nav-lbl) { display: none; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px 14px; }
.sidebar .brand .mark { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg,var(--accent),#6366f1); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 14px; flex-shrink: 0; }
.sidebar .brand h1 { font-size: 16px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.sidebar .brand h1 span { color: var(--accent-soft); }
.sidebar .brand p { font-size: 11px; color: var(--text2); margin-top: 1px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.sidebar nav button {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 9px 12px; background: none; border: none; border-radius: 10px;
  color: var(--text2); cursor: pointer; font-size: 13.5px; font-weight: 500;
  text-align: left; transition: background .12s, color .12s;
}
.sidebar nav button svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar nav button:hover  { background: var(--bg3); color: var(--text); }
.sidebar nav button.active { background: var(--bg3); color: var(--accent-soft); font-weight: 600; }
.sidebar .side-foot { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 4px; display: flex; flex-direction: column; gap: 2px; }
.sidebar .side-foot .user-badge { margin: 0 4px 8px; text-align: center; }
.user-badge { background: var(--bg3); border: 1px solid var(--border); border-radius: 20px; padding: 5px 12px; font-size: 12px; color: var(--text2); }
.chip-datos { display: block; margin: 0 4px 6px; padding: 4px 10px; border-radius: 20px; font-size: 11px;
  text-align: center; background: var(--bg3); border: 1px solid var(--border); color: var(--text2); cursor: pointer; }
.chip-datos.ok   { color: var(--green);  border-color: var(--green); }
.chip-datos.warn { color: var(--yellow); border-color: var(--yellow); }
.chip-datos.err  { color: var(--red);    border-color: var(--red); }
#app.nav-collapsed:not(.hover-open) .side-foot .chip-datos { display: none; }
.btn-sm { padding: 6px 12px; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text2); cursor: pointer; font-size: 12px; }
.btn-sm:hover { color: var(--text); }

/* botón hamburguesa (solo móvil) */
.burger-fixed { display: none; }

/* BOTÓN DE TEMA: fijo arriba a la derecha, por encima del login (z 1000) y del
   menú móvil (z 210). Muestra el sol en oscuro y la luna en claro. Solo se
   enseña en la entrada y en Hoy (pintarBotonTema): en las demás pantallas se
   pisaba con la barra de acciones de la página. */
.theme-toggle {
  position: fixed; top: 10px; right: 12px; z-index: 1100;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg2); border: 1px solid var(--border); color: var(--text2);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
/* .theme-toggle trae display:flex, que gana a [hidden] por especificidad. */
.theme-toggle[hidden] { display: none; }
.theme-toggle:hover { color: var(--text); border-color: var(--accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle svg { width: 17px; height: 17px; }
.theme-toggle .ico-moon { display: none; }
:root[data-theme="light"] .theme-toggle .ico-sun { display: none; }
:root[data-theme="light"] .theme-toggle .ico-moon { display: block; }

#aviso-sin-gama {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--bg3); border: 1px solid var(--yellow, var(--border));
  border-left: 3px solid var(--yellow, var(--accent));
  border-radius: 8px; padding: 10px 14px; margin-bottom: 16px;
  font-size: 13px; color: var(--text);
}
#aviso-sin-gama button { flex: 0 0 auto; width: auto; }
main {
  flex: 1; overflow-y: auto; padding: 24px 28px; min-width: 0;
  margin-left: var(--sidebar-w);
  transition: margin-left .34s cubic-bezier(.32,.72,0,1);
}
/* Plegada: el contenido se reajusta al carril de 72 px. Al abrirse por HOVER el
   margen NO cambia: la barra se superpone y no se mueve nada del contenido. */
#app.nav-collapsed main { margin-left: 72px; }
.page { display: none; }
.page.active { display: block; }

/* responsive: barra lateral -> cajón deslizante en móvil */
@media (max-width: 860px) {
  /* en móvil no hay apertura por proximidad: cajón deslizante con el botón */
  main { margin-left: 0 !important; }
  #app.nav-collapsed main { margin-left: 0 !important; }
  #app.nav-collapsed.hover-open .sidebar { box-shadow: 0 0 40px var(--shadow); }
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; z-index: 200; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 40px var(--shadow); }
  #app.nav-open .sidebar { transform: translateX(0); }
  #app.nav-open::before { content: ''; position: fixed; inset: 0; background: var(--overlay-soft); z-index: 150; }
  .burger-fixed { display: flex; align-items: center; justify-content: center; position: fixed; top: 10px; left: 12px; z-index: 210; width: 40px; height: 40px; background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; color: var(--text); cursor: pointer; }
  main { padding: 64px 16px 16px; }
}

/* arranque: se enseña mientras se comprueba la sesión, por encima del login */
.arranque { position: fixed; inset: 0; background: var(--bg); z-index: 1001; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--text2); font-size: 13px; }
.arranque .mark { width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(135deg, var(--accent), #6366f1); color: #fff; font-weight: 800; display: grid; place-items: center; }
.login-ayuda { margin-top: 14px; font-size: 12.5px; color: var(--text2); }
.sesion-aviso { position: fixed; bottom: 24px; right: 24px; z-index: 950; background: var(--bg2); border: 1px solid var(--yellow); border-left: 4px solid var(--yellow); border-radius: 10px; padding: 12px 16px; display: flex; gap: 14px; align-items: center; font-size: 13px; box-shadow: 0 8px 24px var(--shadow-soft); }
