:root {
  --bi-bg: #ffffff;
  --bi-surface-2: #f3f4f6;
  --bi-text: #2a2e20;
  --bi-text-2: #5f6355;
  --bi-border: #e5e7eb;
  --bi-accent: #7c8e47;
  --bi-accent-hover: #6a7a3b;
  --bi-accent-soft: rgba(124, 142, 71, 0.12);
  --bi-amber: #be8a2e;
  --bi-success: #3d6b34;
  --bi-danger: #9b2f26;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --sombra: 0 1px 2px rgb(42 46 32 / 6%), 0 2px 8px rgb(42 46 32 / 4%);
  font-family: "Montserrat", "Poppins", system-ui, sans-serif;
  color: var(--bi-text);
  font-size: 15px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bi-bg); line-height: 1.5; }
[hidden] { display: none !important; }
h1, h2 { margin: 0; color: var(--bi-text); }
button, input, select { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--bi-accent); outline-offset: 2px; }
.oculto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- controles ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; border: 1px solid transparent; border-radius: var(--r-md); padding: .55rem 1rem; font-weight: 600; font-size: .9rem; cursor: pointer; transition: background .15s, border-color .15s; white-space: nowrap; }
.btn-primario { background: var(--bi-accent); color: #fff; }
.btn-primario:hover { background: var(--bi-accent-hover); }
.btn-secundario { background: var(--bi-bg); border-color: var(--bi-border); color: var(--bi-text); }
.btn-secundario:hover { background: var(--bi-surface-2); }
.btn-peligro { background: var(--bi-danger); color: #fff; }
.btn-peligro:hover { background: #82271f; }
.conf-texto { margin: .6rem 0 0; line-height: 1.55; }
.btn-chico { padding: .3rem .7rem; font-size: .82rem; font-weight: 500; }
.btn-ancho { width: 100%; margin-top: 1.25rem; }
.btn:disabled { opacity: .55; cursor: progress; }
.icono-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--bi-text-2); cursor: pointer; }
.icono-btn:hover { background: var(--bi-surface-2); color: var(--bi-text); }
.icono-peligro:hover { color: var(--bi-danger); background: rgb(155 47 38 / 8%); }
.estado-campo { margin-top: 1rem; padding-top: .9rem; border-top: 1px solid var(--bi-border); }
.enlace { background: none; border: 0; padding: 0; color: var(--bi-accent); font-weight: 500; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.enlace:disabled { color: #a3a69a; text-decoration: none; cursor: default; }
label { display: block; font-weight: 500; font-size: .82rem; color: var(--bi-text-2); margin: 1rem 0 .35rem; }
input, select { width: 100%; padding: .55rem .75rem; border: 1px solid var(--bi-border); border-radius: var(--r-md); background: var(--bi-bg); }
input:disabled, select:disabled { background: var(--bi-surface-2); color: var(--bi-text-2); cursor: not-allowed; }
input:focus, select:focus { border-color: var(--bi-accent); outline: none; box-shadow: 0 0 0 3px var(--bi-accent-soft); }
.aviso { margin: 1rem 0 0; padding: .65rem .85rem; border-radius: var(--r-md); font-size: .875rem; border: 1px solid rgb(155 47 38 / 25%); background: rgb(155 47 38 / 6%); color: var(--bi-danger); }
.aviso[data-tipo="ok"] { border-color: rgb(61 107 52 / 25%); background: rgb(61 107 52 / 7%); color: var(--bi-success); }
.ayuda { font-size: .875rem; color: var(--bi-text-2); margin: .4rem 0 0; }

/* ---------- cargando ---------- */
.cargando { min-height: 100vh; display: grid; place-items: center; }
.cargando-logo { width: 140px; opacity: .85; animation: pulso 1.6s ease-in-out infinite; }
@keyframes pulso { 50% { opacity: .35; } }

/* ---------- acceso ---------- */
.acceso { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1rem; background: var(--bi-surface-2); }
.acceso-tarjeta { width: 100%; max-width: 400px; background: var(--bi-bg); border: 1px solid var(--bi-border); border-radius: var(--r-lg); box-shadow: var(--sombra); padding: 2rem; }
.acceso-logo { height: 34px; }
.acceso-producto { margin: .35rem 0 1.5rem; color: var(--bi-text-2); font-size: .875rem; }
.acceso-tarjeta h1 { font-size: 1.5rem; font-weight: 700; }
.codigo { font-size: 1.5rem; letter-spacing: .5em; text-align: center; font-weight: 600; }
.acciones-codigo { display: flex; gap: 1.25rem; flex-wrap: wrap; margin-top: 1.1rem; font-size: .875rem; }

/* ---------- estructura ---------- */
.app { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.lateral { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; border-right: 1px solid var(--bi-border); background: var(--bi-bg); padding: 1.1rem .75rem; }
.marca { display: flex; align-items: center; gap: .7rem; padding: .25rem .5rem 1.4rem; }
.marca-icono { display: grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r-md); background: var(--bi-accent-soft); color: var(--bi-accent); }
.marca strong { display: block; font-size: .95rem; }
.marca span { display: block; font-size: .78rem; color: var(--bi-text-2); }
.nav { display: grid; gap: 2px; }
.nav-seccion { margin: .5rem .6rem .45rem; font-size: .68rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--bi-text-2); }
.nav-item { display: flex; align-items: center; gap: .7rem; width: 100%; padding: .6rem .7rem; border: 0; border-radius: var(--r-md); background: transparent; text-align: left; font-weight: 500; cursor: pointer; color: var(--bi-text); }
.nav-item:hover { background: var(--bi-surface-2); }
.nav-item[aria-current="page"] { background: var(--bi-accent-soft); font-weight: 600; }
.nav-item[aria-current="page"] svg { color: var(--bi-accent); }
.usuario { margin-top: auto; display: flex; align-items: center; gap: .65rem; padding: .9rem .4rem 0; border-top: 1px solid var(--bi-border); }
.avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--bi-accent); color: #fff; font-weight: 600; font-size: .85rem; flex: none; }
.usuario-datos { min-width: 0; flex: 1; }
.usuario-datos strong { display: block; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usuario-datos span { display: block; font-size: .75rem; color: var(--bi-text-2); }

.principal { padding: 1.4rem clamp(1rem, 3vw, 2.5rem) 4rem; max-width: 1240px; width: 100%; }
.migas { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; font-size: .8rem; color: var(--bi-text-2); min-height: 1.2rem; }
.migas button { background: none; border: 0; padding: 0; color: var(--bi-text-2); cursor: pointer; }
.migas button:hover { color: var(--bi-text); text-decoration: underline; }
.migas .actual { color: var(--bi-accent); font-weight: 600; }
.migas span[aria-hidden] { color: #b5b8ac; }
.cabecera { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin: .5rem 0 1.25rem; }
.cabecera h1 { font-size: clamp(1.6rem, 3vw, 2rem); font-weight: 700; line-height: 1.15; overflow-wrap: anywhere; }
.subtitulo { margin: .3rem 0 0; color: var(--bi-text-2); font-size: .9rem; }
.acciones { display: flex; gap: .5rem; }

.buscador { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.buscador-campo { position: relative; flex: 3 1 260px; }
.buscador-campo svg { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--bi-text-2); }
.buscador-campo input { padding-left: 2.3rem; }
.buscador select { flex: 1 1 140px; width: auto; }

/* ---------- lista ---------- */
.tarjeta { position: relative; background: var(--bi-bg); border: 1px solid var(--bi-border); border-radius: var(--r-lg); box-shadow: var(--sombra); overflow: hidden; }
.lista { list-style: none; margin: 0; padding: 0; }
.fila { display: grid; grid-template-columns: 44px minmax(0, 1fr) 90px 120px 210px; align-items: center; gap: .75rem; padding: .6rem 1rem; border-bottom: 1px solid var(--bi-border); }
.fila:last-child { border-bottom: 0; }
.fila:hover { background: var(--bi-surface-2); }
.fila-carpeta { cursor: pointer; }
.fila-icono svg { width: 22px; height: 22px; color: var(--bi-accent); fill: var(--bi-accent-soft); }
.fila-nombre { min-width: 0; }
.fila-nombre strong, .fila-nombre button { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fila-nombre button { background: none; border: 0; padding: 0; text-align: left; width: 100%; cursor: pointer; font-weight: 600; }
.fila-ruta { display: block; font-size: .75rem; color: var(--bi-text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fila-ruta button { background: none; border: 0; padding: 0; color: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.fila-meta { font-size: .82rem; color: var(--bi-text-2); text-align: right; white-space: nowrap; }
.fila-accion { display: flex; justify-content: flex-end; gap: .35rem; }
.fila-nombre .abrir { font-weight: 500; }
.fila-nombre .abrir:hover { color: var(--bi-accent); text-decoration: underline; text-underline-offset: 2px; }
.chip { display: inline-block; min-width: 38px; text-align: center; padding: .15rem .3rem; border-radius: var(--r-sm); background: var(--bi-surface-2); color: var(--bi-text-2); font-size: .66rem; font-weight: 700; letter-spacing: .03em; }
.vacio { padding: 2.5rem 1rem; color: var(--bi-text-2); text-align: center; }
.btn-mas { margin-top: 1rem; }
.soltar { position: absolute; inset: 0; display: grid; place-items: center; padding: 1rem; text-align: center; background: rgb(124 142 71 / 8%); border: 2px dashed var(--bi-accent); border-radius: var(--r-lg); color: var(--bi-text); font-weight: 500; }

/* ---------- subidas ---------- */
.panel-subidas { position: fixed; right: 1.25rem; bottom: 1.25rem; width: min(380px, calc(100vw - 2.5rem)); max-height: 60vh; display: flex; flex-direction: column; background: var(--bi-bg); border: 1px solid var(--bi-border); border-radius: var(--r-lg); box-shadow: 0 4px 24px rgb(42 46 32 / 12%); z-index: 20; }
.panel-subidas header { display: flex; align-items: center; justify-content: space-between; padding: .7rem .7rem .7rem 1rem; border-bottom: 1px solid var(--bi-border); font-size: .9rem; }
.panel-subidas ul { list-style: none; margin: 0; padding: .25rem 0; overflow-y: auto; }
.subida { padding: .6rem 1rem; }
.subida-nombre { display: flex; justify-content: space-between; gap: .75rem; font-size: .82rem; }
.subida-nombre strong { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subida-estado { color: var(--bi-text-2); white-space: nowrap; }
.subida[data-estado="ok"] .subida-estado { color: var(--bi-success); }
.subida[data-estado="error"] .subida-estado { color: var(--bi-danger); }
.barra { height: 4px; margin-top: .4rem; border-radius: 99px; background: var(--bi-surface-2); overflow: hidden; }
.barra span { display: block; height: 100%; width: 0; background: var(--bi-accent); transition: width .2s; }
.subida[data-estado="error"] .barra span { background: var(--bi-danger); }
.subida-error { margin: .3rem 0 0; font-size: .75rem; color: var(--bi-danger); }

/* ---------- diálogo ---------- */
.dialogo { border: 1px solid var(--bi-border); border-radius: var(--r-lg); box-shadow: 0 8px 32px rgb(42 46 32 / 16%); padding: 1.5rem; width: min(420px, calc(100vw - 2rem)); }
.dialogo::backdrop { background: rgb(42 46 32 / 30%); }
.dialogo h2 { font-size: 1.15rem; }
.dialogo-acciones { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }

/* ---------- administración ---------- */
.pestanas { display: flex; gap: .25rem; border-bottom: 1px solid var(--bi-border); margin-bottom: 1rem; }
.pestanas button { border: 0; background: none; padding: .55rem .9rem; font-weight: 500; color: var(--bi-text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; }
.pestanas button[aria-selected="true"] { color: var(--bi-text); border-bottom-color: var(--bi-accent); font-weight: 600; }
.tabla-envoltura { overflow-x: auto; }
.tabla { width: 100%; border-collapse: collapse; font-size: .875rem; }
.tabla th { text-align: left; font-weight: 600; font-size: .75rem; color: var(--bi-text-2); padding: .65rem 1rem; border-bottom: 1px solid var(--bi-border); white-space: nowrap; }
.tabla td { padding: .65rem 1rem; border-bottom: 1px solid var(--bi-border); vertical-align: middle; }
.tabla tr:last-child td { border-bottom: 0; }
.tabla tbody tr:hover { background: var(--bi-surface-2); }
.tabla .secundario { display: block; font-size: .78rem; color: var(--bi-text-2); }
.tabla .acciones-celda { text-align: right; white-space: nowrap; }
.tabla .detalle { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--bi-text-2); font-size: .8rem; }
.estado { display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; white-space: nowrap; }
.estado::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: currentColor; }
.estado-ok { color: var(--bi-success); }
.estado-off { color: var(--bi-text-2); }
.estado-alerta { color: var(--bi-amber); }
.estado-error { color: var(--bi-danger); }
.etiqueta { display: inline-block; padding: .1rem .45rem; margin: 0 .25rem .2rem 0; border-radius: var(--r-sm); background: var(--bi-surface-2); font-size: .75rem; color: var(--bi-text-2); }
.dialogo-ancho { width: min(640px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); overflow-y: auto; }
.campos { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.grupo-campos { border: 0; padding: 0; margin: 1rem 0 0; }
.grupo-campos legend { font-weight: 500; font-size: .82rem; color: var(--bi-text-2); margin-bottom: .35rem; padding: 0; }
.checks { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; }
.check { display: flex; align-items: center; gap: .5rem; margin: .6rem 0 0; font-size: .875rem; color: var(--bi-text); font-weight: 400; cursor: pointer; }
.check input { width: auto; margin: 0; accent-color: var(--bi-accent); }
.bloque-titulo { display: flex; align-items: center; justify-content: space-between; margin: 1.4rem 0 .5rem; }
.bloque-titulo h3 { margin: 0; font-size: .95rem; }
.permisos { list-style: none; margin: 0; padding: 0; border: 1px solid var(--bi-border); border-radius: var(--r-md); }
.permisos li { display: flex; align-items: center; gap: .75rem; padding: .55rem .75rem; border-bottom: 1px solid var(--bi-border); font-size: .85rem; }
.permisos li:last-child { border-bottom: 0; }
.permisos .p-carpeta { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.permisos .p-meta { color: var(--bi-text-2); font-size: .78rem; white-space: nowrap; }
.permisos .vacio-p { color: var(--bi-text-2); justify-content: center; }
.dialogo-acciones .dialogo-izq { margin-right: auto; }
.selector { border: 1px solid var(--bi-border); border-radius: var(--r-md); padding: .6rem .75rem; }
.selector-lista { list-style: none; margin: .4rem 0; padding: 0; max-height: 220px; overflow-y: auto; }
.selector-lista button { display: flex; align-items: center; gap: .5rem; width: 100%; padding: .4rem .5rem; border: 0; border-radius: var(--r-sm); background: none; text-align: left; cursor: pointer; font-size: .875rem; }
.selector-lista button:hover { background: var(--bi-surface-2); }
.selector-lista svg { color: var(--bi-accent); }
.selector-elegida { margin: .3rem 0 0; font-size: .82rem; color: var(--bi-text-2); }
.selector-elegida strong { color: var(--bi-text); }

/* ---------- auditoría ---------- */
.segmentado { display: inline-flex; padding: 3px; border: 1px solid var(--bi-border); border-radius: var(--r-md); background: var(--bi-surface-2); }
.segmentado button { border: 0; background: none; padding: .4rem .85rem; border-radius: var(--r-sm); font-size: .85rem; color: var(--bi-text-2); cursor: pointer; }
.segmentado button[aria-pressed="true"] { background: var(--bi-bg); color: var(--bi-text); font-weight: 600; box-shadow: var(--sombra); }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .9rem; }
.chip-filtro { display: inline-flex; align-items: center; gap: .5rem; padding: .45rem .9rem; border: 1px solid var(--bi-border); border-radius: 999px; background: var(--bi-bg); font-size: .875rem; font-weight: 500; cursor: pointer; }
.chip-filtro:hover { background: var(--bi-surface-2); }
.chip-filtro .cuenta { min-width: 1.4rem; padding: 0 .35rem; border-radius: 999px; background: var(--bi-surface-2); font-size: .72rem; font-weight: 600; text-align: center; color: var(--bi-text-2); }
.chip-filtro[aria-pressed="true"] { background: var(--bi-accent); border-color: var(--bi-accent); color: #fff; }
.chip-filtro[aria-pressed="true"] .cuenta { background: rgb(255 255 255 / 22%); color: #fff; }
.chip-filtro.chip-error .cuenta { background: rgb(190 138 46 / 18%); color: #8a6420; }
.aud-filtros { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.aud-filtros select { width: auto; flex: 0 1 220px; }
.aud-filtros .buscador-campo { flex: 1 1 320px; max-width: 520px; }
.linea-tiempo { padding: .5rem 1.25rem 1rem; }
.dia { padding-top: .75rem; }
.dia-titulo { margin: 0 0 .25rem; font-size: .9rem; font-weight: 600; }
.dia-titulo span { margin-left: .4rem; font-weight: 400; color: var(--bi-text-2); }
.eventos { list-style: none; margin: 0 0 0 1.25rem; padding: 0; border-left: 2px solid var(--bi-border); }
.evento { display: grid; grid-template-columns: 52px 30px minmax(0, 1fr); gap: .75rem; align-items: start; padding: .7rem 0 .7rem .9rem; border-bottom: 1px dashed var(--bi-border); }
.evento:last-child { border-bottom: 0; }
.evento-hora { font-size: .8rem; color: var(--bi-text-2); padding-top: .3rem; font-variant-numeric: tabular-nums; }
.evento .avatar { width: 28px; height: 28px; font-size: .75rem; }
.evento-frase { margin: 0; font-size: .92rem; line-height: 1.5; overflow-wrap: anywhere; }
.evento-frase b { font-weight: 600; }
.evento-sub { margin: .1rem 0 0; font-size: .8rem; color: var(--bi-text-2); overflow-wrap: anywhere; }
.evento-error .evento-frase { color: var(--bi-danger); }
.evento-error .avatar { background: var(--bi-danger); }
.evento-admin .avatar { background: var(--bi-amber); }
.marca-fallo { display: inline-block; margin-left: .4rem; padding: .05rem .5rem; border-radius: 999px; background: rgb(155 47 38 / 10%); color: var(--bi-danger); font-size: .72rem; font-weight: 600; vertical-align: 1px; }

/* ---------- visor ---------- */
.visor { width: min(1200px, calc(100vw - 2rem)); height: min(900px, calc(100vh - 2rem)); padding: 0; border: 1px solid var(--bi-border); border-radius: var(--r-lg); box-shadow: 0 12px 48px rgb(42 46 32 / 22%); overflow: hidden; }
.visor[open] { display: flex; flex-direction: column; }
.visor::backdrop { background: rgb(42 46 32 / 55%); }
.visor-cabecera { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .6rem .75rem .6rem 1.1rem; border-bottom: 1px solid var(--bi-border); }
.visor-titulo { min-width: 0; }
.visor-titulo strong { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.visor-titulo span { display: block; font-size: .78rem; color: var(--bi-text-2); }
.visor-acciones { display: flex; align-items: center; gap: .25rem; flex: none; }
.visor-cuerpo { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; background: var(--bi-surface-2); }
.visor-cuerpo img { max-width: 100%; max-height: 100%; object-fit: contain; background: repeating-conic-gradient(#e9eaec 0 25%, #fff 0 50%) 0 0 / 20px 20px; }
.visor-cuerpo video { max-width: 100%; max-height: 100%; background: #000; }
.visor-cuerpo iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.visor-cuerpo audio { width: min(520px, 90%); }
.visor-estado { padding: 2rem; text-align: center; color: var(--bi-text-2); max-width: 46ch; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .lateral { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .6rem .75rem; border-right: 0; border-bottom: 1px solid var(--bi-border); }
  .marca { padding: 0 .25rem; flex: 1; }
  .lateral > .nav { order: 3; width: 100%; display: flex; gap: .25rem; overflow-x: auto; }
  .nav-seccion { display: none; }
  #nav-admin { display: contents; }
  .nav-item { width: auto; white-space: nowrap; }
  .usuario { margin: 0; padding: 0; border: 0; }
  .usuario-datos { display: none; }
  .cabecera { align-items: flex-start; }
  .fila { grid-template-columns: 36px minmax(0, 1fr) auto; padding: .6rem .75rem; }
  .fila-meta.tamano, .fila-meta.fecha { display: none; }
  .fila-accion .btn-ver { display: none; }
  .campos { grid-template-columns: 1fr; }
  .visor { width: 100vw; height: 100vh; max-width: none; max-height: none; border-radius: 0; }
}
@media (prefers-reduced-motion: reduce) { .cargando-logo { animation: none; } * { transition: none !important; } }
