/* ============================================================
   app-catalogo-regol — PWA del vendedor (Task 11)
   Marca Deportes Regol: naranja #E65B00 sobre negro, un solo acento
   (a diferencia del esquema por-empresa de BNW). DM Sans + JetBrains Mono,
   auto-hospedadas (offline-safe para el shell).
   ============================================================ */
@font-face {
  font-family: 'DM Sans'; font-style: normal; font-weight: 100 1000;
  font-display: swap; src: url(fonts/dmsans.woff2) format('woff2');
}
@font-face {
  font-family: 'JetBrains Mono'; font-style: normal; font-weight: 100 800;
  font-display: swap; src: url(fonts/jetbrainsmono.woff2) format('woff2');
}

:root {
  --font-display: 'DM Sans', ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-sans: 'DM Sans', ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --background: 0 0% 6%;
  --foreground: 0 0% 96%;
  --card: 0 0% 10%;
  --card-foreground: 0 0% 96%;
  --muted: 0 0% 16%;
  --muted-foreground: 0 0% 63%;
  --border: 0 0% 22%;
  --input: 0 0% 24%;

  --primary: 24 100% 45%;          /* #E65B00 */
  --primary-foreground: 0 0% 8%;   /* texto oscuro sobre naranja: 5.9:1, mejor AA que blanco (3.6:1) */
  --ring: 24 90% 55%;

  --destructive: 0 72% 58%;
  --success: 142 55% 50%;
  --warn: 38 92% 55%;

  --radius: 0.625rem;
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.4), 0 1px 2px -1px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 10px 24px -6px rgb(0 0 0 / 0.55);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { overflow-x: hidden; }
body {
  font-family: var(--font-sans);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
[x-cloak] { display: none !important; }
img { max-width: 100%; display: block; }
a { color: hsl(var(--primary)); text-decoration: none; }
.muted { color: hsl(var(--muted-foreground)); font-size: 13px; }

/* ---- Controles base ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 44px; padding: 0 16px; border-radius: calc(var(--radius) - 2px);
  border: 1px solid hsl(var(--border)); background: hsl(var(--card)); color: hsl(var(--foreground));
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: hsl(var(--primary) / 0.6); }
.btn:disabled { opacity: .5; cursor: default; }
/* .sm sigue siendo un objetivo táctil de >=44px (uso a una mano en celular,
   minor de la revisión de Task 11): solo se reduce el padding/tipografía, no
   el alto -antes 32px, muy por debajo del mínimo usual de 44-48px. */
.btn.sm { height: 44px; padding: 0 12px; font-size: 13px; border-radius: calc(var(--radius) - 4px); }
.btn.primary {
  background: hsl(var(--primary)); border-color: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  font-weight: 700;
}
.btn.primary:hover { background: hsl(var(--primary) / 0.88); }
.btn.active { background: hsl(var(--primary) / 0.16); border-color: hsl(var(--primary) / 0.6); color: hsl(var(--primary)); }

input[type=text], input[type=password], input[type=search], select {
  height: 44px; padding: 0 12px; border: 1px solid hsl(var(--input)); border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--card)); color: hsl(var(--foreground)); font: inherit; outline: none;
}
input[type=text]:focus, input[type=password]:focus, input[type=search]:focus, select:focus {
  border-color: hsl(var(--primary)); box-shadow: 0 0 0 2px hsl(var(--ring) / 0.28);
}
input::placeholder { color: hsl(var(--muted-foreground)); }

/* ---- Splash / boot ---- */
.login-logo { width: 120px; max-width: 60%; height: auto; display: block; margin: 0 auto 14px; }

/* ---- Login ---- */
.login-wrap {
  display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 20px;
  background:
    radial-gradient(60rem 60rem at 110% -10%, hsl(var(--primary) / 0.10), transparent 60%),
    radial-gradient(50rem 50rem at -10% 110%, hsl(var(--primary) / 0.06), transparent 60%);
}
.login-card {
  position: relative; background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 32px 30px; width: 100%; max-width: 380px; text-align: center;
}
.login-card h2 { margin: 0 0 4px; font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.login-card p { margin: 0 0 22px; color: hsl(var(--muted-foreground)); font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; text-align: left; }
.field label { font-size: 13px; font-weight: 500; }
.field input { width: 100%; }
.err { color: hsl(var(--destructive)); font-size: 13px; margin-bottom: 12px;
  background: hsl(var(--destructive) / 0.12); border: 1px solid hsl(var(--destructive) / 0.3);
  padding: 8px 12px; border-radius: calc(var(--radius) - 4px); }
/* Íconos SVG auto-hospedados (Finding 2 de la revisión de Task 11): la lupa
   y el aviso de sin conexión eran emoji del plano suplementario
   (Emoji_Presentation=Yes) sin respaldo de texto -tofu en cualquier entorno
   sin fuente de emoji a color (confirmado en el propio VPS). Un SVG inline
   no depende de ninguna fuente instalada, igual que las fuentes DM
   Sans/JetBrains Mono que ya se auto-hospedan. */
.ico-inline { width: 14px; height: 14px; vertical-align: -2px; margin-right: 2px; flex: none; }

/* ---- Topbar ---- */
.topbar {
  display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 20;
  background: hsl(var(--card)); border-bottom: 1px solid hsl(var(--border)); padding: 8px 14px;
}
.topbar-logo { height: 30px; width: auto; }
.topbar h1 { font-size: 15px; margin: 0; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; color: hsl(var(--muted-foreground)); }
.topbar .spacer { flex: 1; }
.acctmenu { position: relative; }
.acct-trigger { background: hsl(var(--muted)); }
.acct-pop {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 190px;
  background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 6px; display: flex; flex-direction: column; z-index: 30;
}
.acct-name { padding: 8px 10px; font-weight: 600; font-size: 13px; border-bottom: 1px solid hsl(var(--border)); margin-bottom: 4px; }
.acct-pop a, .acct-pop button {
  display: block; text-align: left; border: none; background: none; cursor: pointer;
  padding: 9px 10px; font: inherit; color: hsl(var(--foreground)); border-radius: calc(var(--radius) - 4px);
}
.acct-pop a:hover, .acct-pop button:hover { background: hsl(var(--muted)); }
.acct-danger { color: hsl(var(--destructive)); }
.sel-trigger { position: relative; background: hsl(var(--muted)); }
.sel-badge {
  display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px;
  padding: 0 5px; border-radius: 999px; background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  font-size: 11px; font-weight: 700; margin-left: 4px;
}

/* ---- Barra de filtros ---- */
.toolbar-sticky {
  position: sticky; top: 47px; z-index: 15; background: hsl(var(--background) / 0.96); backdrop-filter: blur(4px);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 14px; border-bottom: 1px solid hsl(var(--border));
}
.search-wrap { position: relative; flex: 1 1 200px; min-width: 0; }
.search-wrap .search-ico {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: hsl(var(--muted-foreground)); pointer-events: none;
}
.search-wrap .search { width: 100%; padding-left: 36px; }
.toolbar-sticky select { flex: 0 1 auto; min-width: 0; max-width: 100%; }

/* ---- Grid / tarjetas ---- */
.grid {
  display: grid; gap: 12px; padding: 14px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.card {
  background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; min-width: 0; cursor: pointer;
}
.card:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 2px; }
.card .ph { position: relative; aspect-ratio: 1 / 1; background: hsl(var(--muted)); border-bottom: 1px solid hsl(var(--border)); }
.card .ph img { width: 100%; height: 100%; object-fit: cover; }
/* @error de la foto (minor de la revision de Task 11): sin esto el navegador
   pinta su propio icono de "imagen rota" sobre el fondo -aca se oculta el
   <img> (app.js: onImgError) y el propio contenedor muestra un icono de
   placeholder consistente con el resto de la app, en SVG inline vía
   data URI -autohospedado, no depende de ninguna fuente de emoji. */
.card .ph.img-error {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='1.5'%3E%3Crect x='3' y='3' width='18' height='18' rx='2'/%3E%3Ccircle cx='8.5' cy='8.5' r='1.5'/%3E%3Cpath d='M21 15l-5-5L5 21'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: center; background-size: 34%;
}
.destacado-ico { position: absolute; top: 6px; left: 6px; color: hsl(var(--primary)); font-size: 15px; text-shadow: 0 1px 3px rgb(0 0 0 / .8); }

/* ---- Selección para PDF (Task 13, spec §8.1/§8.3) ----
   Una tarjeta ya seleccionada se ve distinta de una que no lo está (borde + halo),
   y el botón redondo sobre la foto cambia de "+" a "✓" y de oscuro a naranja -los
   tres estados de disponibilidad de los chips ya usan forma, no solo color; acá el
   contraste "+"/"✓" cumple el mismo papel para quien no distinga el color. */
.card-sel { border-color: hsl(var(--primary) / 0.7); box-shadow: 0 0 0 2px hsl(var(--primary) / 0.35) inset; }
.sel-toggle {
  position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 50%;
  border: 1.5px solid hsl(0 0% 100% / 0.7); background: hsl(0 0% 0% / 0.45); color: hsl(0 0% 100%);
  font: inherit; font-weight: 700; font-size: 15px; line-height: 1; cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.sel-toggle:hover { background: hsl(0 0% 0% / 0.65); }
.sel-toggle.active {
  background: hsl(var(--primary)); border-color: hsl(var(--primary)); color: hsl(var(--primary-foreground));
}
.card .body { padding: 9px 10px 11px; display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.card .name { font-weight: 500; font-size: 13px; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .ref { font-family: var(--font-mono); font-size: 11px; color: hsl(var(--muted-foreground)); }

.chips { display: flex; flex-wrap: wrap; gap: 4px; min-height: 22px; }
.chip {
  display: inline-flex; align-items: center; gap: 3px; font-family: var(--font-mono);
  font-size: 10.5px; line-height: 1; padding: 4px 6px; border-radius: 999px; border: 1px solid; max-width: 100%;
}
/* Los chips existen para que el vendedor distinga variantes a simple vista
   (Open 2 de la revision de Task 11): truncar con ellipsis a un ancho fijo
   colapsaba pares con prefijo largo compartido ("S / AZUL REY" y "S / AZUL
   OSCURO" ambos leian "S / AZUL ..."), y no hay ficha de producto (Tasks
   12/13) ni forma de leer el "title" en un touchscreen donde recuperar el
   texto completo. Envolver en vez de truncar: el texto completo siempre es
   visible, sin heuristica que pueda fallar con la proxima SKU de prefijo
   largo. Los chips crecen en alto, no en ancho -la grilla ya tiene filas de
   chip de alto variable. */
.chip-lbl { white-space: normal; overflow-wrap: break-word; }
.chip-ico { font-size: 8px; line-height: 1; }

/* Los tres estados se distinguen por FORMA (ícono/borde), no solo por color —
   deben leerse igual en una captura en escala de grises y con luz de sol directa. */
.chip-disponible { border-style: solid; border-color: hsl(var(--border)); background: hsl(var(--muted)); color: hsl(var(--foreground)); }
.chip-disponible .chip-ico { color: hsl(var(--success)); }

.chip-ultimas { border-style: dashed; border-width: 1.5px; border-color: hsl(var(--warn)); background: hsl(var(--warn) / 0.14); color: hsl(var(--foreground)); font-weight: 700; }
.chip-ultimas .chip-ico { color: hsl(var(--warn)); }

.chip-agotado { border-style: dotted; border-color: hsl(var(--muted-foreground)); color: hsl(var(--muted-foreground)); opacity: .7; }
.chip-agotado .chip-lbl { text-decoration: line-through; }
.chip-agotado .chip-ico { color: hsl(var(--destructive)); }

.chip-resto { border-style: solid; background: hsl(var(--primary) / 0.16); border-color: hsl(var(--primary) / 0.55); color: hsl(var(--primary)); font-weight: 700; }

.cardbottom { margin-top: auto; }
.price { font-family: var(--font-mono); font-weight: 700; font-size: 14px; letter-spacing: -.01em; }
.price.consulta { font-family: var(--font-sans); font-weight: 600; font-size: 12.5px; color: hsl(var(--muted-foreground)); }

/* ---- Estados vacíos / carga ---- */
.empty { color: hsl(var(--muted-foreground)); text-align: center; padding: 64px 20px; }
.empty.sm { padding: 18px 20px; font-size: 13px; }
.empty.sm.loaderr { display: flex; flex-direction: column; align-items: center; gap: 8px; color: hsl(var(--destructive)); }
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid hsl(var(--border));
  border-top-color: hsl(var(--primary)); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Aviso sin conexión (reemplaza el catálogo, nunca lo tapa) ---- */
.offline-view {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 80px 24px; gap: 8px; min-height: 50vh;
}
.offline-ico-svg { width: 44px; height: 44px; color: hsl(var(--muted-foreground)); }
.offline-view h2 { margin: 4px 0 0; font-size: 18px; }
.offline-view p { margin: 0 0 10px; color: hsl(var(--muted-foreground)); max-width: 340px; }

/* ---- Ficha de producto (Task 12, spec §8.1) ----
   Todas las variantes SIN el tope de 8 chips de la tarjeta -hasta 121 en el caso
   real (spec §8.1)- así que la tabla es una lista vertical que envuelve texto en
   vez de truncar o forzar ancho: nunca debe producir scroll horizontal. */
.ficha-overlay {
  position: fixed; inset: 0; z-index: 50; background: hsl(0 0% 0% / 0.6);
  display: flex; justify-content: center;
}
.ficha-panel {
  background: hsl(var(--background)); width: 100%; max-width: 560px; height: 100%;
  display: flex; flex-direction: column; overflow: hidden; min-width: 0;
}
.ficha-head {
  display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 5;
  background: hsl(var(--card)); border-bottom: 1px solid hsl(var(--border)); padding: 8px 10px; flex: none;
}
.ficha-head-title {
  font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.ficha-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; min-width: 0; }

.ficha-foto { aspect-ratio: 1 / 1; background: hsl(var(--muted)); border-bottom: 1px solid hsl(var(--border)); }
.ficha-foto img { width: 100%; height: 100%; object-fit: contain; }

.ficha-fotos-strip { display: flex; gap: 8px; padding: 10px; overflow-x: auto; }
.ficha-thumb {
  flex: none; width: 56px; height: 56px; border-radius: calc(var(--radius) - 4px);
  border: 2px solid hsl(var(--border)); background: hsl(var(--muted)); padding: 0; overflow: hidden; cursor: pointer;
}
.ficha-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ficha-thumb.active { border-color: hsl(var(--primary)); }

.ficha-info { padding: 6px 14px 10px; display: flex; flex-direction: column; gap: 4px; }
.ficha-titulo { font-size: 16px; font-weight: 700; line-height: 1.3; overflow-wrap: break-word; }
.ficha-ref { font-family: var(--font-mono); font-size: 12px; color: hsl(var(--muted-foreground)); }
.ficha-precio { font-family: var(--font-mono); font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.ficha-precio.consulta { font-family: var(--font-sans); font-weight: 600; font-size: 14px; color: hsl(var(--muted-foreground)); }
.ficha-disp { font-size: 12.5px; color: hsl(var(--muted-foreground)); }

.ficha-acciones { display: flex; gap: 8px; margin: 6px 14px 16px; }
.ficha-acciones .btn { flex: 1; }

.ficha-variantes { padding: 0 14px 24px; min-width: 0; }
.ficha-variantes-head {
  font-size: 12px; font-weight: 700; color: hsl(var(--muted-foreground)); margin: 4px 0 8px;
  text-transform: uppercase; letter-spacing: .04em;
}
.ficha-tabla { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ficha-fila {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px;
  padding: 9px 10px; border-radius: calc(var(--radius) - 4px); border: 1px solid hsl(var(--border));
  background: hsl(var(--card)); min-width: 0;
}
.fila-left { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1 1 140px; }
.fila-ico { flex: none; font-size: 10px; }
.fila-etiqueta { font-family: var(--font-mono); font-size: 13px; overflow-wrap: break-word; min-width: 0; }
.fila-right { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.fila-estado { font-size: 11.5px; color: hsl(var(--muted-foreground)); white-space: nowrap; }
.fila-precio { font-family: var(--font-mono); font-weight: 600; font-size: 12.5px; white-space: nowrap; }

.fila-disponible .fila-ico { color: hsl(var(--success)); }
.fila-ultimas { border-color: hsl(var(--warn)); background: hsl(var(--warn) / 0.1); }
.fila-ultimas .fila-ico { color: hsl(var(--warn)); }
.fila-ultimas .fila-estado { color: hsl(var(--warn)); font-weight: 700; }
.fila-agotado { opacity: .65; }
.fila-agotado .fila-ico { color: hsl(var(--destructive)); }
.fila-agotado .fila-etiqueta { text-decoration: line-through; }

/* ---- Selección: panel de revisión + exportar PDF (Task 13, spec §8.3) ----
   Mismo patrón visual que .ficha-overlay/.ficha-panel (overlay de pantalla completa,
   header sticky con "← Volver"), z-index por encima de la ficha: no coexisten en la
   práctica (el trigger de la topbar queda tapado mientras la ficha está abierta),
   pero por si acaso. */
.sel-overlay {
  position: fixed; inset: 0; z-index: 55; background: hsl(0 0% 0% / 0.6);
  display: flex; justify-content: center;
}
.sel-panel {
  background: hsl(var(--background)); width: 100%; max-width: 480px; height: 100%;
  display: flex; flex-direction: column; overflow: hidden; min-width: 0;
}
.sel-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px; min-width: 0; }
.sel-list { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.sel-item {
  display: flex; align-items: center; gap: 10px; padding: 8px; min-width: 0;
  border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) - 4px); background: hsl(var(--card));
}
.sel-item-img { width: 40px; height: 40px; border-radius: calc(var(--radius) - 6px); object-fit: cover; background: hsl(var(--muted)); flex: none; }
.sel-item-info { flex: 1; min-width: 0; }
.sel-item-name { font-size: 12.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sel-item-ref { font-family: var(--font-mono); font-size: 11px; color: hsl(var(--muted-foreground)); }
.sel-item-quitar { flex: none; width: 36px; height: 36px; padding: 0; color: hsl(var(--destructive)); }

.sel-pdf { margin-top: 18px; padding-top: 16px; border-top: 1px solid hsl(var(--border)); display: flex; flex-direction: column; gap: 10px; }
.sel-pdf-head { font-size: 12px; font-weight: 700; color: hsl(var(--muted-foreground)); text-transform: uppercase; letter-spacing: .04em; }
.sel-pdf-formatos { display: flex; gap: 8px; }
.sel-pdf-formatos .btn { flex: 1; }
.sel-pdf-listo { display: flex; gap: 8px; }
.sel-pdf-listo .btn { flex: 1; }

/* ---- Toast (aviso breve reutilizable: tope de selección, PDF listo...) ---- */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 90;
  max-width: calc(100% - 32px); text-align: center;
  background: hsl(0 0% 12%); color: hsl(0 0% 96%); border: 1px solid hsl(var(--border));
  padding: 10px 16px; border-radius: calc(var(--radius) - 2px); font-size: 13px; box-shadow: var(--shadow-lg);
}

/* ---- Responsive: sin scroll horizontal en celular ---- */
@media (max-width: 480px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; padding: 10px; }
  .topbar h1 { display: none; }
  .toolbar-sticky { top: 47px; }
  .ficha-fila { padding: 8px; }
  .sel-trigger .btn-lbl-text { display: none; }
}

/* ============================================================
   Panel de administración (Task 14, spec §8.4) — mismo lenguaje visual que el
   catálogo del vendedor (arriba), sin el eje de empresas de app-catalogo (BNW):
   Regol es una sola empresa, así que estas clases nunca dependen de `company_id`.
   Prefijo `.adm-` para no colisionar con nada de arriba.
   ============================================================ */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; text-align: left; }
.field label { font-size: 13px; font-weight: 500; }
.field input, .field select, .field textarea { width: 100%; }
.field textarea { min-height: 70px; padding: 10px 12px; font: inherit; resize: vertical;
  border: 1px solid hsl(var(--input)); border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--card)); color: hsl(var(--foreground)); }
.check-row { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; font-size: 13.5px; }
.check-row input[type=checkbox] { width: 16px; height: 16px; accent-color: hsl(var(--primary)); cursor: pointer; flex: none; }

/* ---- Topbar del admin: reusa .topbar, agrega el link de vuelta ---- */
.adm-back { color: hsl(var(--muted-foreground)); font-size: 13px; white-space: nowrap; }
.adm-back:hover { color: hsl(var(--foreground)); }

/* ---- Tabs (segmentado, mismo patrón que .btn.sm/.active de arriba) ---- */
.adm-tabs {
  position: sticky; top: 47px; z-index: 18; display: flex; gap: 6px; flex-wrap: wrap;
  padding: 8px 14px; background: hsl(var(--background) / 0.96); backdrop-filter: blur(4px);
  border-bottom: 1px solid hsl(var(--border));
}
.adm-tabs .btn.sm { position: relative; }
.adm-tab-badge {
  display: inline-flex; align-items: center; justify-content: center; min-width: 17px; height: 17px;
  padding: 0 4px; border-radius: 999px; background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  font-size: 10.5px; font-weight: 700; margin-left: 2px;
}

.adm-content { padding: 16px 14px 60px; max-width: 1080px; margin: 0 auto; }
.adm-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.adm-head h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.adm-head .spacer { flex: 1; }
.adm-sub { color: hsl(var(--muted-foreground)); font-size: 13px; }

/* ---- Barra de filtros (buscador de modelos) ---- */
.adm-toolbar {
  position: sticky; top: 92px; z-index: 14; background: hsl(var(--background) / 0.96); backdrop-filter: blur(4px);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 0; margin-bottom: 10px;
  border-bottom: 1px solid hsl(var(--border));
}
.adm-toolbar .search-wrap { flex: 1 1 220px; min-width: 0; }
.adm-toolbar select { flex: 0 1 auto; min-width: 0; }

/* ---- Lista de modelos / cola sin foto / usuarios ---- */
.adm-list { display: flex; flex-direction: column; gap: 8px; }
.adm-row {
  display: flex; align-items: center; gap: 12px; padding: 10px; min-width: 0;
  background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: var(--radius);
}
.adm-row.clickable { cursor: pointer; }
.adm-row.clickable:hover { border-color: hsl(var(--primary) / 0.5); }
.adm-thumb {
  flex: none; width: 52px; height: 52px; border-radius: calc(var(--radius) - 4px);
  background: hsl(var(--muted)); object-fit: cover; border: 1px solid hsl(var(--border));
}
.adm-row-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.adm-row-name { font-size: 13.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adm-row-meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 11.5px; color: hsl(var(--muted-foreground)); }
.adm-row-meta .ref { font-family: var(--font-mono); }
.adm-row-badges { display: flex; flex-wrap: wrap; gap: 4px; }
.adm-row-acts { flex: none; display: flex; gap: 6px; }

.adm-badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 10.5px; font-weight: 700;
  padding: 2px 7px; border-radius: 999px; border: 1px solid hsl(var(--border)); white-space: nowrap;
  background: hsl(var(--muted)); color: hsl(var(--muted-foreground));
}
.adm-badge.ok    { color: hsl(var(--success)); background: hsl(var(--success) / 0.14); border-color: hsl(var(--success) / 0.35); }
.adm-badge.warn  { color: hsl(var(--warn)); background: hsl(var(--warn) / 0.14); border-color: hsl(var(--warn) / 0.35); }
.adm-badge.off   { color: hsl(var(--destructive)); background: hsl(var(--destructive) / 0.12); border-color: hsl(var(--destructive) / 0.3); }
.adm-badge.brand { color: hsl(var(--primary)); background: hsl(var(--primary) / 0.14); border-color: hsl(var(--primary) / 0.4); }

/* ---- Modal genérico (editor de modelo, etiqueta, usuario...) ---- */
.adm-modal-bg {
  position: fixed; inset: 0; z-index: 60; background: hsl(0 0% 0% / 0.6);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.adm-modal {
  background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 640px; max-height: calc(100vh - 32px);
  display: flex; flex-direction: column; overflow: hidden;
}
.adm-modal.wide { max-width: 820px; }
.adm-modal header {
  display: flex; align-items: center; gap: 10px; padding: 16px 18px; flex: none;
  border-bottom: 1px solid hsl(var(--border)); font-weight: 700; font-size: 15px;
}
.adm-modal header .x {
  margin-left: auto; border: none; background: none; font-size: 20px; line-height: 1;
  color: hsl(var(--muted-foreground)); cursor: pointer; padding: 4px;
}
.adm-modal .mbody { padding: 16px 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.adm-modal footer {
  display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; flex: none;
  border-top: 1px solid hsl(var(--border));
}

/* ---- Editor de modelo: foto propia + fotos extra ---- */
.adm-photo-box {
  display: flex; align-items: center; gap: 14px; padding: 12px; margin-bottom: 16px;
  background: hsl(var(--muted) / 0.4); border: 1px solid hsl(var(--border)); border-radius: var(--radius);
}
.adm-photo-box .ph {
  flex: none; width: 84px; height: 84px; border-radius: calc(var(--radius) - 4px); overflow: hidden;
  background: hsl(var(--muted)); border: 1px solid hsl(var(--border));
}
.adm-photo-box .ph img { width: 100%; height: 100%; object-fit: cover; }
.adm-photo-acts { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.adm-extra-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.adm-extra-item { position: relative; width: 64px; height: 64px; border-radius: calc(var(--radius) - 4px); overflow: hidden;
  border: 1px solid hsl(var(--border)); background: hsl(var(--muted)); }
.adm-extra-item img { width: 100%; height: 100%; object-fit: cover; }
.adm-extra-item button {
  position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%;
  border: none; background: hsl(0 0% 0% / 0.6); color: #fff; font-size: 12px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.adm-extra-add {
  width: 64px; height: 64px; border-radius: calc(var(--radius) - 4px); border: 1.5px dashed hsl(var(--border));
  background: none; color: hsl(var(--muted-foreground)); cursor: pointer; font-size: 20px;
  display: flex; align-items: center; justify-content: center;
}

/* ---- Etiquetas: árbol plano indentado por texto (mismo criterio que el
   selector del vendedor, aplanarEtiquetas + '↳ ') ---- */
.adm-tree { display: flex; flex-direction: column; gap: 4px; }
.adm-tree-row {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; min-width: 0;
  background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) - 4px);
}
.adm-tree-name { flex: 1; min-width: 0; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adm-tree-count { font-size: 11px; color: hsl(var(--muted-foreground)); }
.adm-tree-acts { display: flex; gap: 4px; flex: none; }
.adm-iconbtn {
  width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) - 6px); background: hsl(var(--card));
  color: hsl(var(--muted-foreground)); cursor: pointer; font-size: 13px; padding: 0;
}
/* Íconos SVG auto-hospedados (Finding 1 de la revisión de Task 14, mismo criterio que
   .ico-inline de arriba): estos botones eran emoji del plano suplementario -tofu sin
   fuente de emoji a color- y varios son controles de acción destructiva sin más texto
   que un `title` (que necesita hover, no es un respaldo confiable). */
.adm-iconbtn svg { width: 15px; height: 15px; flex: none; }
.adm-iconbtn:hover { color: hsl(var(--foreground)); border-color: hsl(var(--primary) / 0.5); }
.adm-iconbtn.danger:hover { color: hsl(var(--destructive)); border-color: hsl(var(--destructive) / 0.5); }
.adm-iconbtn.active { color: hsl(var(--primary)); border-color: hsl(var(--primary) / 0.6); }

/* ---- Buscar-y-agregar (modelos de una etiqueta, usuarios de una audiencia) ---- */
.adm-pickresults { border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) - 2px);
  max-height: 220px; overflow-y: auto; margin-top: 6px; }
.adm-pickresults .pr-item { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; font-size: 13px; cursor: pointer; border-bottom: 1px solid hsl(var(--border)); }
.adm-pickresults .pr-item:last-child { border-bottom: none; }
.adm-pickresults .pr-item:hover { background: hsl(var(--muted)); }
.adm-picked-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.adm-picked-row { display: flex; align-items: center; gap: 8px; padding: 6px 9px;
  background: hsl(var(--muted) / 0.6); border-radius: calc(var(--radius) - 4px); font-size: 12.5px; }
.adm-picked-row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Tabla simple (usuarios, histórico de sync) ---- */
.adm-table { border: 1px solid hsl(var(--border)); border-radius: var(--radius); overflow: hidden; background: hsl(var(--card)); }
.adm-table-row {
  display: grid; gap: 10px; align-items: center; padding: 9px 12px; font-size: 13px;
  border-top: 1px solid hsl(var(--border));
}
.adm-table-row:first-child { border-top: none; }
.adm-table-head { background: hsl(var(--muted) / 0.5); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; color: hsl(var(--muted-foreground)); }
.adm-table-row span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adm-table-row.inactivo { opacity: .55; }

.adm-users-grid { grid-template-columns: 1.1fr 1.1fr 0.8fr 0.9fr 1fr; }
.adm-hist-grid { grid-template-columns: 0.9fr 1.3fr 0.7fr 0.6fr 0.7fr 1.6fr; }
@media (max-width: 720px) {
  .adm-users-grid, .adm-hist-grid { grid-template-columns: 1fr; }
  .adm-table-row.adm-table-head { display: none; }
  .adm-table-row { grid-template-columns: 1fr; gap: 2px; }
}

.urol { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.urol.admin  { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.urol.editor { background: hsl(var(--warn) / 0.18); color: hsl(var(--warn)); }
.urol.vendedor { background: hsl(var(--muted)); color: hsl(var(--muted-foreground)); }

/* ---- Sync ---- */
.adm-sync-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin-bottom: 20px; }
.adm-sync-card { background: hsl(var(--card)); border: 1px solid hsl(var(--border)); border-radius: var(--radius); padding: 14px; }
.adm-sync-card h3 { margin: 0 0 8px; font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.adm-sync-kv { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; padding: 3px 0; }
.adm-sync-kv .k { color: hsl(var(--muted-foreground)); }
.adm-sync-kv .v { font-family: var(--font-mono); text-align: right; }
.adm-sync-card .btn { width: 100%; margin-top: 10px; }
.adm-sync-err { margin-top: 8px; font-size: 12px; color: hsl(var(--destructive));
  background: hsl(var(--destructive) / 0.1); border: 1px solid hsl(var(--destructive) / 0.3);
  border-radius: calc(var(--radius) - 4px); padding: 6px 9px; word-break: break-word; }
.adm-pending-banner {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; margin-bottom: 16px;
  background: hsl(var(--warn) / 0.12); border: 1px solid hsl(var(--warn) / 0.4); color: hsl(var(--warn));
  border-radius: calc(var(--radius) - 2px); font-size: 13px; font-weight: 600;
}

/* ---- Categorías ---- */
.adm-cat-row { display: flex; align-items: center; gap: 10px; }
.adm-switch {
  position: relative; width: 38px; height: 22px; flex: none; border-radius: 999px; border: none; cursor: pointer;
  background: hsl(var(--muted-foreground) / 0.35); padding: 0;
}
.adm-switch.on { background: hsl(var(--primary)); }
.adm-switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform .15s ease;
}
.adm-switch.on::after { transform: translateX(16px); }

/* ---- Estados vacíos: deliberados, no accidentales (0 etiquetas/usuarios al inicio) ---- */
.adm-empty {
  text-align: center; padding: 48px 20px; color: hsl(var(--muted-foreground));
  background: hsl(var(--card)); border: 1px dashed hsl(var(--border)); border-radius: var(--radius);
}
.adm-empty .adm-empty-ico { font-size: 26px; margin-bottom: 8px; opacity: .7; }
/* SVG en vez de emoji (Finding 1 de la revisión de Task 14): mismo motivo que .ico-inline. */
.adm-empty .adm-empty-ico svg { width: 30px; height: 30px; }
.adm-empty p { margin: 4px 0 0; font-size: 13px; }

/* ---- "Sin permisos" (vendedor abriendo admin.html directo por URL) ---- */
.adm-noaccess { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 20px; }

@media (max-width: 640px) {
  .adm-content { padding: 12px 10px 60px; }
  .adm-toolbar { top: 88px; }
  .adm-modal { max-width: 100%; max-height: 100%; height: 100%; border-radius: 0; }
  .adm-photo-box { flex-direction: column; align-items: flex-start; }
}
