/* Sistema visual de smart-broker — mismo patrón que trust-api-gateway:
   tokens semánticos light/dark, jerarquía por borde 1px + superficie (sin
   sombras), radios card 8 / button 6 / input 6, base 14px Inter. */

/* Inter empaquetada con la UI: el logo y la tipografía se ven igual en
   cualquier máquina, esté o no instalada la fuente en el sistema. */
@font-face {
  font-family: 'Inter';
  src: url('/ui/fonts/InterVariable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg-canvas: #f8f9fd;
  --bg-panel: #ffffff;
  --bg-header: #edf2f7;
  --bg-hover: rgba(0, 0, 0, 0.05);
  --bg-emphasized: #e2e8f0;
  --fg: #1a202c;
  --fg-muted: #4a5568;
  --fg-subtle: #718096;
  --fg-danger: #e53e3e;
  --border: #e2e8f0;
  --border-emphasized: #cbd5e0;
  --accent: #525252;
  --accent-hover: #363636;
  --ok: #38a169;
  --denied: #e53e3e;
  --warning: #b7791f;
  --active: #525252;
  /* Paleta de datos: validada (banda de luminosidad, croma, separación bajo
     daltonismo y contraste) contra la superficie de tarjeta de cada modo.
     Cambiar un tono obliga a revalidar; ver internal/webui/ui/graficas.js. */
  --serie-1: #2a78d6;
  --serie-2: #eb6834;
  --serie-3: #1baf7a;
  --estado-bien: #0ca30c;
  --estado-aviso: #fab219;
  --estado-critico: #d03b3b;
  --radius-card: 0.5rem;
  --radius-button: 0.375rem;
  --radius-input: 0.375rem;
  /* sidebar: siempre oscuro, en ambos temas */
  --side-bg: #171923;
  --side-fg: #e2e8f0;
  --side-fg-muted: #a0aec0;
  --side-border: #2d3748;
  --side-hover: rgba(255, 255, 255, 0.06);
  --side-active-bg: #1a202c;
  --side-active-fg: #ebebeb;
}

html.dark {
  --bg-canvas: #1a202c;
  --bg-panel: #171923;
  --bg-header: #1a202c;
  --bg-hover: rgba(255, 255, 255, 0.06);
  --bg-emphasized: #2d3748;
  --fg: #ffffff;
  --fg-muted: #e2e8f0;
  --fg-subtle: #a0aec0;
  --fg-danger: #fc8181;
  --border: #2d3748;
  --border-emphasized: #4a5568;
  --accent: #ebebeb;
  --accent-hover: #ffffff;
  --ok: #48bb78;
  --denied: #fc8181;
  --warning: #d69e2e;
  --active: #ebebeb;
  /* Mismos hues, re-escalonados para la superficie oscura. Los de estado son
     fijos: un estado no cambia de significado con el tema. */
  --serie-1: #3987e5;
  --serie-2: #d95926;
  --serie-3: #199e70;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg-canvas);
  color: var(--fg);
}
.mono { font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace; }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Shell ─────────────────────────────────────────────────────────────── */
.shell { display: flex; height: 100dvh; overflow: hidden; }

.sidebar {
  width: 240px; flex-shrink: 0; height: 100%;
  background: var(--side-bg); color: var(--side-fg);
  border-right: 1px solid var(--side-border);
  display: flex; flex-direction: column; overflow: hidden;
}
/* El logotipo es texto con estilo fijo: misma fuente (Inter empaquetada),
   mismos pesos y mismo tratamiento en el sidebar y en el login. */
.logo {
  font-family: 'Inter', ui-sans-serif, system-ui, sans-serif;
  font-weight: 700; letter-spacing: 0.02em; line-height: 1;
}
.logo span { color: var(--side-fg-muted); font-weight: 400; }

.sidebar .brand {
  height: 64px; display: flex; align-items: center; justify-content: center;
  border-bottom: 1px solid var(--side-border); flex-shrink: 0;
  font-size: 24px; padding: 0 16px;
}
/* El logotipo es claro: vive sobre el sidebar y la tarjeta de acceso, que son
   oscuros en ambos temas. */
.logo-img { max-width: 100%; display: block; }
.sidebar .brand .logo-img { height: 21px; }
.login-logo { display: flex; justify-content: center; }
.login-logo .logo-img { height: 34px; }

/* ── secciones de la navegación ───────────────────────────────────────── */
.nav-grupo { display: flex; flex-direction: column; gap: 2px; margin-top: 10px; }
.nav-grupo-cabecera {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 6px 12px; border: none; background: transparent;
  color: var(--side-fg-muted); font-size: 11px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.06em;
}
.nav-grupo-cabecera:hover { color: var(--side-fg); }
.nav-grupo-cabecera svg { transition: transform 0.15s ease; }
.nav-grupo.plegado .nav-grupo-cabecera svg { transform: rotate(-90deg); }
.nav-grupo.plegado .nav-grupo-items { display: none; }
.nav-grupo-items { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 8px; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px;
  border-radius: var(--radius-button); color: var(--side-fg-muted);
  text-decoration: none; font-size: 14px;
}
.nav-item svg { flex-shrink: 0; }
.nav-item:hover { background: var(--side-hover); color: var(--side-fg); }
.nav-item.active { background: var(--side-active-bg); color: var(--side-active-fg); font-weight: 500; }
.sidebar .foot { padding: 12px; border-top: 1px solid var(--side-border); font-size: 12px; color: var(--side-fg-muted); }

.principal { display: flex; flex-direction: column; flex: 1; min-width: 0; height: 100%; overflow: hidden; }

/* El sidebar se pliega desde la topbar; su estado se recuerda entre visitas. */
.shell.sin-sidebar .sidebar { display: none; }

.topbar {
  height: 64px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 0 24px; background: var(--bg-panel); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; font-weight: 600; line-height: 1.2; }
.topbar .desc { font-size: 12px; color: var(--fg-subtle); line-height: 1.3; }
.topbar .acciones { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.topbar-izq { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-titulo { min-width: 0; }

.icono-boton {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; flex-shrink: 0;
  border: none; background: transparent; color: var(--fg-muted);
  border-radius: var(--radius-button);
}
.icono-boton:hover { background: var(--bg-hover); color: var(--fg); }

/* ── menú de usuario ──────────────────────────────────────────────────── */
.menu-usuario { position: relative; }

.menu-disparador {
  display: flex; align-items: center; gap: 10px; padding: 5px 10px 5px 5px;
  border: 1px solid transparent; border-radius: 999px;
  background: transparent; color: var(--fg);
}
.menu-disparador:hover, .menu-usuario.abierto .menu-disparador {
  background: var(--bg-hover); border-color: var(--border);
}
.menu-disparador svg { color: var(--fg-subtle); transition: transform 0.15s ease; }
.menu-usuario.abierto .menu-disparador svg { transform: rotate(180deg); }

.avatar {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; flex-shrink: 0; border-radius: 50%;
  background: var(--accent); color: var(--bg-panel);
  font-size: 12px; font-weight: 600; letter-spacing: 0.02em;
}
.avatar.grande { width: 40px; height: 40px; font-size: 14px; }

.menu-quien { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; line-height: 1.25; }
.menu-nombre { font-size: 13px; font-weight: 500; }
.menu-empresa, .menu-email { font-size: 11px; color: var(--fg-subtle); }

.menu-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 20;
  min-width: 260px; padding: 6px;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.14);
  animation: menu-entra 0.12s ease-out;
}
html.dark .menu-panel { box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); }
@keyframes menu-entra { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.menu-cabecera { display: flex; align-items: center; gap: 10px; padding: 10px 10px 12px; }
.menu-separador { height: 1px; background: var(--border); margin: 4px 0; }

.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border: none; background: transparent;
  color: var(--fg-muted); font-size: 14px; text-align: left;
  text-decoration: none; border-radius: var(--radius-button);
}
.menu-item:hover { background: var(--bg-hover); color: var(--fg); }
.menu-item svg { color: var(--fg-subtle); flex-shrink: 0; }
.menu-item.peligro { color: var(--fg-danger); }
.menu-item.peligro svg { color: var(--fg-danger); }

/* Selector de idioma dentro del menú */
.menu-etiqueta {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px 4px;
  color: var(--fg-subtle); font-size: 11px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.06em;
}
.menu-etiqueta svg { color: var(--fg-subtle); }
.menu-radio { padding-left: 10px; }
.menu-radio-marca { display: flex; width: 16px; flex-shrink: 0; color: var(--accent); }

/* Interruptor de idioma de la pantalla de acceso: esquina superior derecha. */
.idioma-toggle {
  position: absolute; top: 20px; right: 24px;
  display: flex; align-items: center; gap: 7px; padding: 7px 12px;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-panel); color: var(--fg-muted);
  font-size: 12px; font-weight: 600; letter-spacing: 0.04em;
}
.idioma-toggle:hover { color: var(--fg); border-color: var(--border-emphasized); }
.idioma-toggle svg { color: var(--fg-subtle); }

/* ── pestañas ─────────────────────────────────────────────────────────── */
.pestanas { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.pestana {
  padding: 10px 16px; border: none; background: transparent;
  color: var(--fg-subtle); font-size: 14px; font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.pestana:hover { color: var(--fg); }
.pestana.activa { color: var(--fg); border-bottom-color: var(--accent); }

.rejilla-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.rejilla-form .acciones-form { grid-column: 1 / -1; display: flex; gap: 12px; }
.campo input:disabled { opacity: 0.6; }

/* ── doble factor ─────────────────────────────────────────────────────── */
.opciones-2fa { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-top: 12px; }
.opcion-2fa {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 16px; text-align: left;
  border: 1px solid var(--border-emphasized); border-radius: var(--radius-card);
  background: var(--bg-canvas); color: var(--fg);
}
.opcion-2fa:hover { border-color: var(--accent); background: var(--bg-hover); }
.opcion-2fa span { font-size: 13px; color: var(--fg-subtle); }

.alta-2fa { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; }
.qr-caja {
  width: 190px; height: 190px; flex-shrink: 0; padding: 10px;
  background: #ffffff; border: 1px solid var(--border); border-radius: var(--radius-card);
}
.qr-caja svg { width: 100%; height: 100%; display: block; }
.alta-texto { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: 8px; }
.clave-manual {
  padding: 10px 12px; background: var(--bg-emphasized); border-radius: var(--radius-input);
  font-size: 14px; letter-spacing: 0.12em; word-break: break-all;
}

main { flex: 1; padding: 24px; min-width: 0; overflow-y: auto; overscroll-behavior: contain; }

/* Pantallas que ocupan el alto disponible: el contenedor NO scrollea, scrollea
   el contenido de la tabla. Así los filtros, la cabecera de columnas y la
   paginación se quedan siempre a la vista. */
/* main es un ítem flex de altura automática, así que un height:100% del hijo no
   resolvería: la cadena se hace con flex y min-height:0 de arriba abajo, y hay
   que encadenar los DOS contenedores (el #contenido del armazón y la pila de la
   página). */
main.sin-scroll { overflow: hidden; display: flex; flex-direction: column; }
main.sin-scroll > .pila { flex: 1; min-height: 0; }
.pila.alto-completo { flex: 1; min-height: 0; }
.pila.alto-completo > .card.crece {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
}
.card.crece > .tabla-envoltorio { flex: 1; min-height: 0; overflow: auto; }
.card.crece > .paginacion { border-top: 1px solid var(--border); flex: none; }
/* Cabecera fija mientras se scrollea el cuerpo. */
.card.crece thead th { position: sticky; top: 0; z-index: 1; }

/* ── Componentes ───────────────────────────────────────────────────────── */
.pila { display: flex; flex-direction: column; gap: 24px; }

.card {
  border: 1px solid var(--border); border-radius: var(--radius-card);
  background: var(--bg-panel); overflow: hidden; min-width: 0;
}
.card > header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: var(--bg-header); border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.card > header h2 { font-size: 14px; font-weight: 600; }
.card .cuerpo { padding: 16px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.stat { border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--bg-panel); padding: 16px; }
.stat .rotulo { font-size: 12px; color: var(--fg-subtle); text-transform: uppercase; letter-spacing: 0.05em; }
.stat .valor { font-size: 28px; font-weight: 600; line-height: 1.2; margin-top: 4px; }
.stat .ayuda { font-size: 12px; color: var(--fg-subtle); margin-top: 2px; }

/* ── Tablero ───────────────────────────────────────────────────────────── */

/* La cifra es el protagonista de la tarjeta: el color saturado se queda en una
   franja fina al borde, nunca tiñendo el bloque entero. */
.stat.destacado { position: relative; overflow: hidden; padding-left: 20px; }
.stat.destacado::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--serie-1);
}
.stat.destacado .valor { font-size: 32px; letter-spacing: -0.02em; }
.stats .stat.destacado:nth-child(2)::before { background: var(--serie-2); }
.stats .stat.destacado:nth-child(3)::before { background: var(--serie-3); }
.stats .stat.destacado:nth-child(4)::before { background: var(--estado-aviso); }

.rejilla-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 24px; }

/* Contenedor de una gráfica: ECharts necesita una altura explícita. */
.lienzo { width: 100%; }
.lienzo.alto-260 { height: 260px; }
.lienzo.alto-320 { height: 320px; }

/* Píldoras de vigencia: punto de color + cifra + etiqueta. El color nunca va
   solo — un estado siempre se puede leer. */
.estados { display: flex; gap: 18px; flex-wrap: wrap; }
.pildora-estado { display: flex; align-items: baseline; gap: 6px; font-size: 13px; }
.pildora-estado .punto {
  width: 8px; height: 8px; border-radius: 50%; flex: none; align-self: center;
}
.pildora-estado .cifra { font-weight: 600; color: var(--fg); }
.pildora-estado .rotulo { color: var(--fg-subtle); }

.vacio-panel { padding: 24px; text-align: center; color: var(--fg-subtle); }

table { width: 100%; border-collapse: collapse; }
.tabla-envoltorio { overflow-x: auto; }
th {
  text-align: left; padding: 10px 16px; background: var(--bg-header);
  color: var(--fg-subtle); font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
td { padding: 10px 16px; border-bottom: 1px solid var(--border); color: var(--fg-muted); }
tbody tr:hover { background: var(--bg-hover); }
tbody tr:last-child td { border-bottom: none; }
td .principal-celda { font-weight: 500; color: var(--fg); }
td .sub-celda { font-size: 12px; color: var(--fg-subtle); }
.vacio-fila { text-align: center; color: var(--fg-subtle); padding: 32px 16px; }

.badge {
  display: inline-block; border-radius: 999px; padding: 1px 8px;
  font-size: 11px; font-weight: 500;
}
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.error { background: color-mix(in srgb, var(--denied) 15%, transparent); color: var(--denied); }
.badge.aviso { background: color-mix(in srgb, var(--warning) 15%, transparent); color: var(--warning); }
.badge.neutro { background: var(--bg-emphasized); color: var(--fg-muted); }
.badge.tecnica {
  border-radius: 4px; padding: 1px 6px; font-size: 10px;
  font-family: SFMono-Regular, Menlo, monospace; text-transform: uppercase;
  background: var(--bg-emphasized); color: var(--fg-muted);
}

.campo { display: flex; flex-direction: column; gap: 4px; }
.campo label { font-size: 13px; color: var(--fg-muted); }
.campo input, .campo select {
  background: var(--bg-canvas); border: 1px solid var(--border-emphasized);
  border-radius: var(--radius-input); color: var(--fg); padding: 7px 10px;
}
.campo input::placeholder { color: var(--fg-subtle); }
.campo .ayuda { font-size: 12px; color: var(--fg-subtle); }

.boton {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-button); border: 1px solid transparent;
  background: var(--accent); color: var(--bg-panel); font-size: 14px; font-weight: 500;
}
.boton:hover { background: var(--accent-hover); }
.boton[disabled] { opacity: 0.6; cursor: default; }
.boton.secundario { background: transparent; border-color: var(--border-emphasized); color: var(--fg); }
.boton.secundario:hover { background: var(--bg-hover); }
.boton.peligro { background: transparent; border-color: color-mix(in srgb, var(--denied) 40%, transparent); color: var(--fg-danger); }
.boton.peligro:hover { background: color-mix(in srgb, var(--denied) 10%, transparent); }
.boton.pequeno { padding: 4px 10px; font-size: 13px; }

.aviso-error {
  display: flex; gap: 10px; align-items: flex-start; padding: 16px;
  background: color-mix(in srgb, var(--denied) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--denied) 40%, transparent);
  border-radius: var(--radius-card); color: var(--fg);
}
.aviso-exito {
  padding: 16px; border-radius: var(--radius-card); color: var(--fg);
  background: color-mix(in srgb, var(--ok) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--ok) 40%, transparent);
  word-break: break-all;
}

/* En curso: una verificación contra el portal tarda un par de segundos y hay
   que decirlo, sin teñirlo de éxito ni de error todavía. */
.aviso-info {
  display: flex; gap: 10px; align-items: center; padding: 12px 16px;
  border-radius: var(--radius-card); color: var(--fg-muted);
  background: var(--bg-header); border: 1px solid var(--border);
}
.aviso-info::before {
  content: ''; width: 14px; height: 14px; flex: none; border-radius: 50%;
  border: 2px solid var(--border-emphasized); border-top-color: var(--fg-muted);
  animation: girar 0.7s linear infinite;
}
@keyframes girar { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .aviso-info::before { animation: none; } }

/* Acciones de fila: en línea mientras quepan; si no, se apilan ordenadas a la
   derecha en vez de desbordar la tabla. */
.acciones-fila { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.acciones-fila .boton { white-space: nowrap; }

/* Resumen de ajustes en la tabla: solo lectura, el detalle va en el diálogo. */
.resumen-ajustes { display: flex; flex-direction: column; gap: 2px; font-size: 13px; min-width: 150px; }
.resumen-ajustes .dato { color: var(--fg-muted); }
.resumen-ajustes .dato b { font-weight: 600; color: var(--fg); }

/* Diálogo modal (elemento <dialog> nativo). */
.dialogo {
  /* margin:auto es lo que centra un <dialog> modal; el reset lo pone a 0. */
  margin: auto; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-card);
  background: var(--bg-panel); color: var(--fg); width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px); overflow: auto;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
}
.dialogo::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialogo header {
  display: flex; justify-content: space-between; align-items: baseline; gap: 16px;
  padding: 16px 20px; border-bottom: 1px solid var(--border); background: var(--bg-header);
  border-radius: var(--radius-card) var(--radius-card) 0 0;
}
.dialogo header h2 { margin: 0; font-size: 16px; font-weight: 600; }
.dialogo header .sub { font-size: 13px; color: var(--fg-subtle); }
.dialogo .cuerpo { padding: 20px; display: flex; flex-direction: column; gap: 22px; }
.dialogo footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 20px; border-top: 1px solid var(--border);
}

/* Un grupo de ajustes dentro del diálogo. */
.grupo-ajustes { display: flex; flex-direction: column; gap: 14px; }
.grupo-ajustes > .titulo {
  font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--fg-subtle);
}
.ajuste { display: flex; flex-direction: column; gap: 4px; }
.ajuste .fila { display: flex; align-items: center; gap: 12px; }
.ajuste .fila > label { flex: 1; font-size: 14px; }
.ajuste .fila input[type='number'] { width: 110px; }
.ajuste .ayuda { font-size: 12px; }

/* Interruptor para los ajustes booleanos. */
.interruptor { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
.interruptor input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.interruptor .pista {
  position: absolute; inset: 0; border-radius: 999px; pointer-events: none;
  background: var(--bg-emphasized); border: 1px solid var(--border-emphasized);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.interruptor .pista::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: var(--bg-panel); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s ease;
}
.interruptor input:checked + .pista { background: var(--ok); border-color: var(--ok); }
.interruptor input:checked + .pista::after { transform: translateX(18px); }
.interruptor input:focus-visible + .pista { outline: 2px solid var(--accent); outline-offset: 2px; }
.interruptor input:disabled + .pista { opacity: 0.5; }
@media (prefers-reduced-motion: reduce) {
  .interruptor .pista, .interruptor .pista::after { transition: none; }
}

/* Hueco de estado bajo un formulario: sin margen cuando está vacío. */
.estado-form:not(:empty) { margin-top: 12px; }

.filtros { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.filtros .campo { min-width: 160px; }
/* Los desplegables de filtro se ajustan al contenido pero sin acaparar la fila:
   un nombre de producto largo empujaría los botones a otra línea. */
.filtros .campo select { max-width: 260px; }

.paginacion { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px 16px; color: var(--fg-subtle); font-size: 13px; }

/* ── Login ─────────────────────────────────────────────────────────────── */
.login-fondo { position: relative; min-height: 100dvh; display: flex; align-items: center; justify-content: center; background: var(--bg-canvas); padding: 24px; }
.login-caja {
  /* siempre oscura, como la tarjeta de login del patrón */
  width: 100%; max-width: 400px; background: var(--side-bg); color: var(--side-fg);
  border: 1px solid var(--side-border); border-radius: var(--radius-card); padding: 32px;
  display: flex; flex-direction: column; gap: 24px;
}
/* La tarjeta de acceso es oscura en ambos temas, así que los avisos de dentro
   no pueden heredar el color de texto del tema: en claro serían ilegibles. */
.login-caja .aviso-error,
.login-caja .aviso-exito { color: var(--side-fg); }

.login-caja h1 { font-size: 27px; text-align: center; }
.login-caja .campo label { color: var(--side-fg-muted); }
.login-caja .campo input,
.login-caja .campo select {
  background: #1a202c; border-color: #4a5568; color: var(--side-fg);
}
.login-caja .campo select option { background: #1a202c; color: var(--side-fg); }
.login-caja .ayuda { color: var(--side-fg-muted); }


.acceso-subtitulo { text-align: center; font-size: 14px; color: var(--side-fg-muted); margin-top: -12px; }
.acceso-nota { font-size: 13px; color: var(--side-fg-muted); text-align: center; margin: -4px 0 0; }
.acceso-nota strong { color: var(--side-fg); }

.acceso-enlaces { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.acceso-enlaces a { color: var(--side-fg-muted); font-size: 13px; text-decoration: none; }
.acceso-enlaces a:hover { color: var(--side-fg); text-decoration: underline; }

.campo-codigo {
  font-family: SFMono-Regular, Menlo, Monaco, monospace;
  font-size: 24px; letter-spacing: 0.4em; text-align: center;
}

@media (max-width: 900px) { .sidebar { display: none; } }

/* ── Lotes de caché ────────────────────────────────────────────────────── */
/* Dos columnas que ocupan todo el ancho; una sola cuando no caben dos. */
.rejilla-lotes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
@media (max-width: 900px) { .rejilla-lotes { grid-template-columns: 1fr; } }

.lote-cuerpo { display: flex; gap: 18px; align-items: flex-start; }
.lienzo-anillo { width: 92px; height: 92px; flex: none; }
.lote-datos { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.lote-nombre { font-size: 13px; color: var(--fg-subtle); }
.lote-cifra { font-size: 24px; font-weight: 600; line-height: 1.1; }
.lote-cifra span { font-size: 13px; font-weight: 400; color: var(--fg-subtle); }

/* Ficha de datos: etiqueta a la izquierda, valor a la derecha. */
.lote-lista {
  display: grid; grid-template-columns: auto 1fr; gap: 2px 12px;
  margin-top: 4px; font-size: 13px;
}
.lote-lista dt { color: var(--fg-subtle); }
.lote-lista dd { color: var(--fg-muted); text-align: right; }
.lote-restante { margin-top: 4px; font-size: 12px; color: var(--fg-subtle); }

.lote-pie { display: flex; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--border); }
.card > header h2 .badge { margin-left: 6px; vertical-align: middle; }

/* ── Visor de documentos (cajón lateral) ───────────────────────────────── */
.cajon {
  margin: 0 0 0 auto; padding: 0; border: none; height: 100dvh;
  max-height: 100dvh; width: min(900px, 100vw); max-width: 100vw;
  background: var(--bg-panel); color: var(--fg);
  display: flex; flex-direction: column;
  border-left: 1px solid var(--border);
}
.cajon::backdrop { background: rgba(0, 0, 0, 0.45); }
/* El visor de un PDF se abre ENCIMA de la ficha, un poco más estrecho: el borde
   de la ficha asomando por la izquierda es lo que dice que hay algo debajo y
   que cerrar devuelve a la lista, no al listado de pólizas. */
.cajon-secundario { width: min(840px, 96vw); }
.cajon-secundario::backdrop { background: rgba(0, 0, 0, 0.3); }
/* El título puede ser largo (el nombre del contratante o del documento) y no
   debe empujar al botón de cerrar fuera de la cabecera. */
.cajon-titulo { min-width: 0; }
.cajon-titulo h2 { overflow-wrap: anywhere; }
.cajon-titulo .sub { display: block; overflow-wrap: anywhere; }
.cajon header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 20px; border-bottom: 1px solid var(--border); background: var(--bg-header);
  flex: none;
}
.cajon header h2 { font-size: 16px; font-weight: 600; }
.cajon header .sub { font-size: 13px; color: var(--fg-subtle); }
.cajon-cuerpo { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Pestañas del cajón: la ficha y los documentos. */
.pestanas { display: flex; gap: 4px; padding: 8px 12px 0; border-bottom: 1px solid var(--border); overflow-x: auto; flex: none; }
.pestana {
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 8px 14px; border: none; background: transparent; color: var(--fg-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; font-size: 13px;
  border-radius: var(--radius-button) var(--radius-button) 0 0;
}
.pestana:hover { background: var(--bg-hover); color: var(--fg); }
.pestana.activa { color: var(--fg); border-bottom-color: var(--serie-1); font-weight: 500; }

/* El panel es el único que hace scroll: la cabecera y las pestañas se quedan. */
.panel-ficha { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.panel-ficha > * { flex: 1; min-height: 0; }

.detalle-poliza { overflow-y: auto; padding: 16px 20px 24px; }
.ficha-barra {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px;
}
.ficha-seccion { margin-top: 20px; }
.ficha-seccion:first-of-type { margin-top: 0; }
.ficha-seccion h3 {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--fg-subtle); margin-bottom: 8px;
}

/* Formulario de solo lectura: cada plataforma declara sus campos, así que la
   rejilla se adapta al número que venga en vez de fijar columnas. */
.ficha-campos {
  display: grid; gap: 1px; background: var(--border);
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  border: 1px solid var(--border); border-radius: var(--radius-card); overflow: hidden;
}
.ficha-campos > div { background: var(--bg-surface); padding: 10px 12px; }
.ficha-campos dt { font-size: 11px; color: var(--fg-subtle); margin-bottom: 2px; }
.ficha-campos dd { font-size: 13px; color: var(--fg); word-break: break-word; }
.vacio-panel.pequeno { padding: 12px; font-size: 13px; text-align: left; }

.marco-pdf { flex: 1; min-height: 0; background: var(--bg-canvas); }
.marco-pdf .pdf { width: 100%; height: 100%; border: none; display: block; }
.cargando-visor { padding: 32px; text-align: center; color: var(--fg-subtle); }

/* Filas que abren algo: se comportan como un enlace, no como texto. */
.fila-clic { cursor: pointer; }
.fila-clic:hover { background: var(--bg-hover); }
.fila-clic:hover .boton { border-color: var(--border-emphasized); }
