/* ==========================================================================
   plugin-shell — chrome unificado de los módulos (plugins a pantalla completa).
   Header arriba (siempre con la salida al chat en la esquina superior izquierda)
   y footer opcional. Dos presentaciones del MISMO componente:

     .pshell-header             barra superior propia del módulo (topbar)
     .pshell-header-side        cabecera del <aside> del módulo (sidebar)

   Altura neutra: el shell SUSTITUYE al chrome que el módulo ya tenía, no añade
   una barra nueva. Por eso ningún calc(100vh - …) de los CSS de plugin cambia.

   Es autosuficiente en color (como plugin-onboarding.css): funciona aunque la
   página del módulo no cargue /css/tokens.css. El acento sí viene del módulo
   (--mod-color, mismo hash que el chip del sidebar del chat).
   ========================================================================== */

:root {
  --pshell-h: 52px;
  --pshell-bg: #ffffff;
  --pshell-fg: #1e293b;
  --pshell-muted: #64748b;
  --pshell-border: #e2e8f0;
  --pshell-hover: #f1f5f9;
  --pshell-menu-bg: #ffffff;
  --pshell-menu-shadow: 0 18px 40px -12px rgba(15, 23, 42, .28);
  /* barra de scroll de los modales: la del chat (tokens.css) si la página la carga; si no, la misma por defecto */
  --pshell-sb-thumb: var(--scrollbar-thumb, rgba(0, 102, 255, .22));
  --pshell-sb-thumb-hover: var(--scrollbar-thumb-hover, rgba(0, 102, 255, .45));
  --pshell-sb-thumb-active: var(--scrollbar-thumb-active, rgba(0, 102, 255, .65));
}

:root[data-theme="dark"] {
  --pshell-bg: #161b22;
  --pshell-fg: #e6edf3;
  --pshell-muted: #9aa3b4;
  --pshell-border: #2b323d;
  --pshell-hover: #232a35;
  --pshell-menu-bg: #1b2029;
  --pshell-menu-shadow: 0 18px 40px -12px rgba(0, 0, 0, .6);
  --pshell-sb-thumb: var(--scrollbar-thumb, rgba(59, 130, 246, .32));
  --pshell-sb-thumb-hover: var(--scrollbar-thumb-hover, rgba(59, 130, 246, .55));
  --pshell-sb-thumb-active: var(--scrollbar-thumb-active, rgba(96, 165, 250, .8));
}

/* -------------------------------------------- scroll de los modales (tema) */
/* Las páginas de módulo no cargan style.css (donde vive la barra fina del chat): sin esto, los modales enseñaban la
   barra gruesa del navegador, clara en tema oscuro. Vale para cualquier <dialog>, [role=dialog] o clase «…modal…» y
   todo lo que llevan dentro. :where() = especificidad 0: un módulo puede sobrescribirla. */
:where(dialog, [role="dialog"], [class*="modal"]),
:where(dialog, [role="dialog"], [class*="modal"]) * {
  scrollbar-width: thin;
  scrollbar-color: var(--pshell-sb-thumb) transparent;
}
:where(dialog, [role="dialog"], [class*="modal"])::-webkit-scrollbar,
:where(dialog, [role="dialog"], [class*="modal"]) ::-webkit-scrollbar { width: 10px; height: 10px; }
:where(dialog, [role="dialog"], [class*="modal"])::-webkit-scrollbar-track,
:where(dialog, [role="dialog"], [class*="modal"]) ::-webkit-scrollbar-track { background: transparent; }
:where(dialog, [role="dialog"], [class*="modal"])::-webkit-scrollbar-thumb,
:where(dialog, [role="dialog"], [class*="modal"]) ::-webkit-scrollbar-thumb {
  background: var(--pshell-sb-thumb);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
:where(dialog, [role="dialog"], [class*="modal"])::-webkit-scrollbar-thumb:hover,
:where(dialog, [role="dialog"], [class*="modal"]) ::-webkit-scrollbar-thumb:hover { background: var(--pshell-sb-thumb-hover); background-clip: content-box; }
:where(dialog, [role="dialog"], [class*="modal"])::-webkit-scrollbar-thumb:active,
:where(dialog, [role="dialog"], [class*="modal"]) ::-webkit-scrollbar-thumb:active { background: var(--pshell-sb-thumb-active); background-clip: content-box; }
:where(dialog, [role="dialog"], [class*="modal"])::-webkit-scrollbar-corner,
:where(dialog, [role="dialog"], [class*="modal"]) ::-webkit-scrollbar-corner { background: transparent; }

/* --------------------------------------------------------------- contenedor */
.pshell-header {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--pshell-h);
  min-height: var(--pshell-h);
  box-sizing: border-box;
  padding: 0 14px;
  background: var(--pshell-bg);
  border-bottom: 1px solid var(--pshell-border);
  color: var(--pshell-fg);
  font-family: inherit;
  flex: 0 0 auto;
}

/* La zona de acciones del módulo y el ⋯ van siempre a la derecha, aunque el
   partial se incluya antes en el markup (el plugin conserva su orden).
   El `> *` es la red de seguridad: cualquier hermano suelto que el módulo
   conserve dentro de la barra (botón de colapsar, cerrar off-canvas…) cae
   después de la identidad y NUNCA delante de la salida al chat. */
.pshell-header > * { order: 40; }
.pshell-header > .pshell-exit { order: 1; }
.pshell-header > .pshell-sep  { order: 2; }
.pshell-header > .pshell-id   { order: 3; flex: 1 1 auto; min-width: 0; }
.pshell-header > .pshell-actions { order: 50; }
.pshell-header > .pshell-more { order: 99; }

/* ------------------------------------------------------------------- salida */
/* Todo lo de dentro se escribe como `.pshell-header .x` (especificidad 0,2,0)
   para ganar a las reglas descendentes que cada módulo tiene sobre su propio
   contenedor (`.ns-side a`, `.od-side a`… → 0,1,1). Y este fichero se carga
   SIEMPRE el último del <head> para ganar también los empates. */
.pshell-header .pshell-exit {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  height: 32px;
  padding: 0 11px 0 9px;
  border-radius: 9px;
  border: 1px solid var(--pshell-border);
  background: transparent;
  color: var(--pshell-fg);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: background .14s ease, border-color .14s ease, transform .14s ease;
}
.pshell-header .pshell-exit:hover { background: var(--pshell-hover); border-color: var(--pshell-border); }
.pshell-header .pshell-exit:active { transform: translateX(-1px); }
.pshell-header .pshell-exit:focus-visible { outline: 2px solid var(--mod-color, #6366f1); outline-offset: 2px; }
.pshell-header .pshell-exit i { font-size: 16px; }

.pshell-header .pshell-sep {
  flex: 0 0 auto;
  width: 1px;
  height: 22px;
  background: var(--pshell-border);
}

/* ---------------------------------------------------------------- identidad */
.pshell-header .pshell-id {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}
.pshell-header .pshell-id-ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  font-size: 15px;
  color: var(--mod-color, #6366f1);
  background: color-mix(in srgb, var(--mod-color, #6366f1) 14%, transparent);
}
.pshell-header .pshell-id-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pshell-header .pshell-id-sub {
  flex: 0 1 auto;
  min-width: 0;
  padding-left: 9px;
  border-left: 1px solid var(--pshell-border);
  font-size: 13px;
  color: var(--pshell-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pshell-header .pshell-emoji, .pshell-footer .pshell-emoji { font-size: 15px; line-height: 1; }

/* ------------------------------------------------------ acciones del módulo */
/* Contenedor neutro: NO impone estilo a los botones propios de cada módulo. */
.pshell-header .pshell-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  min-width: 0;
}

/* ------------------------------------------------------------------ menú ⋯ */
.pshell-header .pshell-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--pshell-muted);
  font-size: 17px;
  cursor: pointer;
  transition: background .14s ease, color .14s ease;
}
.pshell-header .pshell-more:hover { background: var(--pshell-hover); color: var(--pshell-fg); }
.pshell-header .pshell-more[aria-expanded="true"] { background: var(--pshell-hover); color: var(--pshell-fg); }

/* El menú se cuelga de <html> (ver plugin-shell.js: `body` lleva zoom en ≥1100px
   y desplazaría el position:fixed), así que NO puede heredar la tipografía del
   body: la declara explícitamente. */
.pshell-menu {
  position: fixed;
  z-index: 9999;
  min-width: 208px;
  padding: 6px;
  border-radius: 12px;
  border: 1px solid var(--pshell-border);
  background: var(--pshell-menu-bg);
  box-shadow: var(--pshell-menu-shadow);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--pshell-fg);
}
.pshell-menu a,
.pshell-menu button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--pshell-fg);
  font-size: 13.5px;
  font-family: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.pshell-menu a:hover,
.pshell-menu button:hover { background: var(--pshell-hover); }
.pshell-menu i { font-size: 16px; color: var(--pshell-muted); }
.pshell-menu-meta {
  padding: 7px 10px 4px;
  font-size: 11.5px;
  color: var(--pshell-muted);
  border-top: 1px solid var(--pshell-border);
  margin-top: 4px;
}

/* ------------------------------------------------- variante sidebar (aside) */
/* El aside del módulo es la esquina superior izquierda de la página: el shell
   va como su primer bloque. Ancho reducido → la etiqueta colapsa. */
.pshell-header-side {
  padding: 0 10px;
  gap: 8px;
}
.pshell-header-side .pshell-exit {
  padding: 0;
  width: 32px;
  justify-content: center;
}
.pshell-header-side .pshell-exit-label { display: none; }
.pshell-header-side .pshell-sep { display: none; }
/* aviso «solo en español» (módulos sin catálogo, usuario en otro idioma) */
.pshell-header .pshell-id-lang {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 6px;
  padding: 2px 8px;
  border: 1px solid var(--pshell-border);
  border-radius: 999px;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--pshell-muted);
  white-space: nowrap;
  cursor: help;
}
.pshell-header .pshell-id-lang i { font-size: 13px; }
.pshell-header-side .pshell-id-sub,
.pshell-header-side .pshell-id-lang { display: none; }
.pshell-header-side .pshell-id-name { font-size: 14px; }

/* ------------------------------------------- variante inline (barra propia) */
/* Para editores cuya barra superior es una toolbar que NO queremos sustituir
   (Office, App Builder): el shell se incrusta como primer bloque de esa barra,
   sin fondo, sin borde y sin altura fija. La salida sigue en la esquina
   superior izquierda de la página, que es lo que importa. */
.pshell-header.pshell-inline {
  height: auto;
  min-height: 0;
  padding: 0;
  background: transparent;
  border-bottom: 0;
  gap: 8px;
}
.pshell-header.pshell-inline .pshell-id-ico { width: 22px; height: 22px; font-size: 13px; }
.pshell-header.pshell-inline .pshell-id-name { font-size: 13.5px; }
.pshell-header.pshell-inline .pshell-more { width: 28px; height: 28px; font-size: 15px; }

/* --------------------------------------------------------------- footer */
.pshell-footer {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  box-sizing: border-box;
  padding: 12px 18px;
  margin-top: 28px;
  border-top: 1px solid var(--pshell-border);
  background: transparent;
  color: var(--pshell-muted);
  font-size: 12.5px;
}
.pshell-footer .pshell-foot-brand {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  color: var(--pshell-fg);
}
.pshell-footer .pshell-foot-v {
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--pshell-border);
  font-size: 11px;
  font-weight: 600;
  color: var(--pshell-muted);
}
.pshell-footer .pshell-foot-links {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  flex: 1 1 auto;
}
.pshell-footer .pshell-foot-links a { color: var(--pshell-muted); text-decoration: none; }
.pshell-footer .pshell-foot-links a:hover { color: var(--pshell-fg); text-decoration: underline; }
.pshell-footer .pshell-foot-copy { flex: 0 0 auto; }

/* ------------------------------------------------------------- responsive */
@media (max-width: 720px) {
  .pshell-header { padding: 0 10px; gap: 8px; }
  .pshell-header .pshell-exit { padding: 0; width: 32px; justify-content: center; }
  .pshell-header .pshell-exit-label { display: none; }
  .pshell-header .pshell-sep { display: none; }
  .pshell-header .pshell-id-sub { display: none; }
  /* #286 (13/10/2026): en la barra superior la identidad cedía TODO el sitio (flex 1 1 auto + min-width 0)
     y las acciones del módulo no cedían nada → a 390 px los botones se montaban sobre el icono y el ⋯ se
     salía por la derecha (GIS, Tesorería, Tasks, Agents, POS, KB). Ahora la identidad no se encoge y son
     las acciones las que se desplazan en horizontal, con el ⋯ siempre a la vista. */
  .pshell-header > .pshell-id { flex: 0 0 auto; max-width: 45%; }
  .pshell-header > .pshell-actions { flex: 1 1 auto; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .pshell-header > .pshell-actions::-webkit-scrollbar { display: none; }
  .pshell-header > .pshell-actions > * { flex: 0 0 auto; }
  /* A la derecha cuando caben (margen auto), y desde el principio cuando desbordan: con justify-content:
     flex-end el desbordamiento se iría por la izquierda y el primer botón quedaría inalcanzable. */
  .pshell-header > .pshell-actions > :first-child { margin-left: auto; }
  .pshell-header > .pshell-more { flex: 0 0 auto; }
  .pshell-footer { padding: 12px 14px; gap: 10px; }
  .pshell-foot-links { gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .pshell-exit { transition: none; }
  .pshell-exit:active { transform: none; }
}

/* Empotrado en una pestaña del chat (#74): la pestaña ya dice de qué módulo se
   trata, así que aquí sobra repetir el nombre. Se deja el icono (ancla visual
   con el color del módulo) y el subtítulo, que sí aporta: dónde estás dentro. */
.pshell-id-embedded .pshell-id-name { display: none; }
.pshell-id-embedded .pshell-id-sub { margin-left: 0; }

/* 27/10 Puesta en marcha (naios-onboarding): botón flotante «← Volver a Puesta en marcha · Ya lo he hecho»
   cuando se llega a un módulo desde un paso (?onb_step). Abajo a la izquierda para no tapar los FAB de los módulos. */
.pshell-onb {
  position: fixed; left: 16px; bottom: 16px; z-index: 9000;
  display: flex; align-items: center; gap: 4px; max-width: calc(100vw - 32px);
  background: var(--pshell-menu-bg); color: var(--pshell-fg);
  border: 1px solid var(--pshell-border); border-radius: 999px; padding: 4px;
  box-shadow: var(--pshell-menu-shadow); font: 500 13px/1.2 -apple-system, "Segoe UI", Roboto, sans-serif;
}
.pshell-onb a { color: inherit; text-decoration: none; padding: 8px 12px; border-radius: 999px; white-space: nowrap; }
.pshell-onb a:hover { background: var(--pshell-hover); }
.pshell-onb .pshell-onb-done { background: #0d9488; color: #fff; }
.pshell-onb .pshell-onb-done:hover { background: #0f766e; }
.pshell-onb-x { border: 0; background: transparent; color: var(--pshell-muted); font-size: 18px; line-height: 1; width: 30px; height: 30px; border-radius: 50%; cursor: pointer; }
.pshell-onb-x:hover { background: var(--pshell-hover); }
@media (max-width: 480px) { .pshell-onb { left: 8px; right: 8px; bottom: 8px; justify-content: space-between; } .pshell-onb a { padding: 8px 10px; } }
