/* ==========================================================================
   GestIA · Pantalla de carga, inicio de sesión y estructura de la aplicación
   ========================================================================== */

/* Pantalla de carga */
.boot {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 30% 20%, #1c3486 0%, #0b1848 45%, #060d2b 100%);
  transition: opacity .5s var(--ease), visibility .5s;
}
.boot.done { opacity: 0; visibility: hidden; }
.boot-inner { display: grid; justify-items: center; gap: 18px; color: #fff; }
.boot-inner .brand-art { width: 76px; height: 76px; animation: pop .7s var(--spring), float 3s ease-in-out .7s infinite; }
.boot-bar { width: 140px; height: 4px; overflow: hidden; border-radius: 99px; background: rgba(255, 255, 255, .14); }
.boot-bar::after { content: ""; display: block; width: 45%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #14a4dc, #22c7b3); animation: boot-bar 1.1s ease-in-out infinite; }
@keyframes boot-bar { from { transform: translateX(-100%); } to { transform: translateX(230%); } }

/* Logotipo GestIA: "IA" se destaca con el degradado de la inteligencia artificial */
.gestia-logo { display: inline-flex; align-items: center; gap: 12px; color: inherit; }

/* Logos de marca con su tratamiento: original, placa blanca o silueta blanca (ver js/core/brand.js) */
.brand-art { display: inline-grid; place-items: center; flex: none; line-height: 0; }
.brand-art img { display: block; object-fit: contain; }
.brand-mark { width: var(--brand-size); height: var(--brand-size); }
.brand-mark img { width: 100%; height: 100%; }
.brand-wordmark img { width: auto; height: var(--brand-size); max-width: 100%; }
.brand-art.is-plate { background: var(--logo-plate-bg); }
.brand-mark.is-plate { padding: calc(var(--brand-size) * var(--logo-plate-pad)); border-radius: 50%; }
.brand-wordmark.is-plate { padding: 7px 14px; border-radius: var(--logo-plate-radius); }
.brand-art.is-white img { filter: brightness(0) invert(1); }
.gestia-word { display: grid; line-height: 1; }
.gestia-word b { font-size: 21px; font-weight: 800; letter-spacing: -.01em; }
.gestia-word b span { background: var(--grad-ai); -webkit-background-clip: text; background-clip: text; color: transparent; }
.gestia-word small { margin-top: 5px; font-size: 10.5px; font-weight: 600; letter-spacing: .06em; opacity: .7; }

/* ---------- Estructura principal ---------- */
.shell { min-height: 100dvh; animation: fade .45s ease; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  isolation: isolate;
  /* clip, no hidden: nada puede desplazar el contenido de la barra y dejarlo recortado */
  overflow: clip;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: var(--sidebar);
  padding: 16px 12px 12px;
  color: #fff;
  background: var(--grad-deep);
  transition: transform .35s var(--ease);
}
.sidebar::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 10% 0%, rgba(47, 91, 234, .5), transparent 45%),
    radial-gradient(circle at 110% 100%, rgba(20, 164, 220, .35), transparent 45%);
}
.sidebar::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image: var(--brand-pattern);
  background-size: 56px 56px;
  opacity: .045;
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 4px 6px 8px; }
.sidebar-actions { display: flex; align-items: center; gap: 4px; }
.sidebar-top .btn-icon { color: #fff; }
.sidebar-top .btn-icon:hover { background: rgba(255, 255, 255, .1); }
.sidebar-close { display: none; }
.sidebar-notify { width: 36px; height: 36px; background: rgba(255, 255, 255, .08); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .1); }
.sidebar-notify .i { width: 18px; height: 18px; transition: transform .3s var(--spring); }
.sidebar-notify:hover:not(:disabled) .i { transform: rotate(-10deg) scale(1.1); }
.sidebar-notify:active { transform: scale(.94); }
.nav { display: grid; align-content: start; gap: 2px; flex: 1; min-height: 0; overflow-x: clip; overflow-y: auto; margin: 0 -4px; padding: 0 4px; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .28) transparent; }
/* Cuando el menú no cabe, un desvanecido arriba o abajo avisa que hay más opciones (ver bindNavOverflow). */
.nav.more-below { mask-image: linear-gradient(to bottom, black calc(100% - 40px), transparent); }
.nav.more-above { mask-image: linear-gradient(to bottom, transparent, black 32px); }
.nav.more-above.more-below { mask-image: linear-gradient(to bottom, transparent, black 32px, black calc(100% - 40px), transparent); }
.nav-label { padding: 10px 10px 4px; font-size: 10.5px; font-weight: 750; letter-spacing: .14em; text-transform: uppercase; color: rgba(255, 255, 255, .42); }
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 38px;
  padding: 0 8px;
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 600;
  color: rgba(255, 255, 255, .72);
  transition: background-color .2s, color .2s;
}
.nav-item:hover { color: #fff; background: rgba(255, 255, 255, .07); }
.nav-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 9px;
  color: #fff;
  background: rgba(255, 255, 255, .08);
  transition: transform .3s var(--spring), background .25s, box-shadow .25s;
}
.nav-icon .i { width: 16px; height: 16px; }
.nav-item:hover .nav-icon { transform: scale(1.08) rotate(-5deg); }
.nav-item.active { color: #fff; background: rgba(255, 255, 255, .12); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08); }
.nav-item.active .nav-icon { background: var(--tone); box-shadow: 0 8px 18px -8px var(--tone); }
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 10px;
  bottom: 10px;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: var(--tone);
  animation: fade .3s;
}
.nav-item.is-ai .nav-icon { background: var(--grad-violet); }
.nav-badge {
  display: grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  margin-left: auto;
  padding: 0 7px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 800;
  color: #3d2600;
  background: #fbbf24;
  animation: pop .4s var(--spring);
}
.sidebar-bottom { display: grid; gap: 10px; }
.scope-card { display: grid; gap: 2px; padding: 10px 12px; border-radius: 14px; background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .08); }
.scope-card .eyebrow { color: rgba(255, 255, 255, .5); font-size: 10px; }
.scope-card strong { display: flex; align-items: center; gap: 7px; font-size: 13.5px; }
.scope-card small { font-size: 12px; color: rgba(255, 255, 255, .6); }
.sidebar-bottom, .user-card { min-width: 0; }
.user-card { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 14px; }
/* Un nombre largo no puede empujar el botón de cerrar sesión fuera de la barra. */
.user-card > .avatar, .user-card > .btn-icon { flex: none; }
.user-meta { flex: 1; min-width: 0; }
.user-meta strong { display: block; font-size: 13.5px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.user-meta small { display: block; font-size: 12px; color: rgba(255, 255, 255, .6); }
.user-card .btn-icon { color: rgba(255, 255, 255, .7); }
.user-card .btn-icon:hover { color: #fff; background: rgba(255, 255, 255, .1); }
.sidebar-dwc { display: flex; align-items: center; gap: 8px; padding: 10px 10px 0; border-top: 1px solid rgba(255, 255, 255, .08); font-size: 10.5px; color: rgba(255, 255, 255, .45); }
.sidebar-dwc .brand-art { opacity: .85; }

/* ---------- Menú contraído (escritorio) ----------
   El menú queda solo con iconos. El ancho se anima en la barra fija y en el margen del contenido:
   es la única forma de devolver el espacio a la vista; los textos reaparecen con un fundido. */
.sidebar-toggle { width: 36px; height: 36px; }
.sidebar-toggle .i { width: 18px; height: 18px; transition: transform .35s var(--spring); }
.sidebar-toggle:active { transform: scale(.94); }
.nav-text { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
@media (min-width: 1025px) {
  .sidebar { transition: transform .35s var(--ease), width .3s var(--ease); }
  .main { transition: margin-left .3s var(--ease); }
  .sidebar-top .gestia-word, .nav-text, .scope-card, .user-meta, .sidebar-dwc { animation: fade .25s .1s var(--ease) both; }
  .sidebar-collapsed { --sidebar: var(--sidebar-collapsed); }
  .sidebar-collapsed .sidebar-toggle .i { transform: rotate(180deg); }
  .sidebar-collapsed .sidebar-top { flex-direction: column; gap: 12px; padding: 2px 0 6px; }
  .sidebar-collapsed .sidebar-actions { flex-direction: column; gap: 6px; }
  .sidebar-collapsed .sidebar-top .gestia-word, .sidebar-collapsed .scope-card, .sidebar-collapsed .sidebar-dwc { display: none; }
  .sidebar-collapsed .nav-label { height: 1px; margin: 9px 10px 7px; padding: 0; overflow: hidden; font-size: 0; background: rgba(255, 255, 255, .12); }
  .sidebar-collapsed .nav-item { justify-content: center; padding: 0; }
  .sidebar-collapsed .nav-text, .sidebar-collapsed .user-meta { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; animation: none; }
  .sidebar-collapsed .nav-badge { position: absolute; top: 1px; right: 3px; min-width: 17px; height: 17px; margin: 0; padding: 0 4px; font-size: 10px; box-shadow: 0 0 0 2px var(--navy-900); }
  .sidebar-collapsed .user-card { flex-direction: column; gap: 6px; padding: 6px 0; }
  .sidebar-collapsed .user-profile { flex: none; }
}
@media (max-width: 1024px) {
  .sidebar-toggle { display: none; }
}

/* En pantallas bajas el menú tiene prioridad sobre la tarjeta de alcance */
@media (max-height: 860px) { .scope-card { display: none; } }

.main { display: flex; flex-direction: column; min-height: 100dvh; margin-left: var(--sidebar); min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: 0 clamp(16px, 2.6vw, 34px);
  /* Opaca a propósito: con transparencia el contenido se transparentaba bajo la barra al hacer scroll. */
  background: var(--canvas);
  border-bottom: 1px solid transparent;
  transition: border-color .25s, box-shadow .25s;
}
.topbar.scrolled { border-color: var(--line); box-shadow: 0 8px 24px -20px rgba(14, 22, 51, .4); }
.topbar-row { display: flex; align-items: center; gap: 14px; height: calc(var(--topbar) - 1px); }
/* En escritorio el menú lateral ya dice dónde estás: la fila del título solo queda para lectores de pantalla
   y el encabezado se reduce a las pestañas de la vista, cuando las tiene. */
@media (min-width: 1025px) {
  .topbar-row { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .topbar-tabs { padding-top: 12px; }
  .topbar:not(.has-tabs) { border: 0; box-shadow: none; }
}
.topbar.has-tabs { border-color: var(--line); }
.topbar-tabs { animation: fade .25s var(--ease); }
.menu-btn { display: none; }
.topbar-title { flex: 1; min-width: 0; }
.topbar-title .eyebrow { display: block; font-size: 10.5px; }
.topbar-title h1 { font-size: 18px; font-weight: 800; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sidebar-top > a { color: #fff; }
.scope-card strong .i { width: 15px; height: 15px; opacity: .8; }
/* El margen inferior deja libre la burbuja de GestIA sobre el final de cada vista. */
.content { width: 100%; max-width: 1440px; margin: 0 auto; padding: 22px clamp(16px, 2.6vw, 34px) 96px; flex: 1; }
.content.is-chat { padding-bottom: 20px; }
/* minmax(0, 1fr): sin esto una tabla ancha estira la columna y desplaza toda la página en móvil. */
.view { display: grid; gap: 22px; grid-template-columns: minmax(0, 1fr); }
.view.refreshing { opacity: .6; pointer-events: none; transition: opacity .2s; }
.scrim { display: none; }

@media (max-width: 1024px) {
  :root { --topbar: 60px; }
  .sidebar { transform: translateX(-102%); box-shadow: var(--shadow-lg); }
  .sidebar-close { display: inline-grid; }
  .menu-open .sidebar { transform: none; }
  .scrim { position: fixed; inset: 0; z-index: 45; display: block; background: rgba(6, 13, 43, .5); backdrop-filter: blur(3px); opacity: 0; visibility: hidden; transition: opacity .3s, visibility .3s; }
  .menu-open .scrim { opacity: 1; visibility: visible; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-grid; }
}
/* Igual que en las ventanas modales: en pantallas táctiles el velo del menú no se desenfoca. */
@media (any-pointer: coarse) {
  .scrim { backdrop-filter: none; }
}
/* Burbuja de GestIA: abajo a la derecha en todas las vistas, salvo en el propio chat. */
.ai-fab {
  position: fixed;
  z-index: 40;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  cursor: pointer;
  animation: ai-fab-in .45s var(--spring) .35s both;
}
.ai-fab:focus-visible { outline: none; }
.ai-fab:focus-visible .ai-fab-orb { outline: 3px solid var(--ring-focus); outline-offset: 4px; }
.shell[data-view="assistant"] .ai-fab { display: none; }
.ai-fab-orb { position: relative; display: grid; place-items: center; width: 60px; height: 60px; border-radius: 50%; isolation: isolate; box-shadow: var(--shadow-ai); transition: transform .3s var(--spring); }
/* Halo que respira y onda que se expande: solo transform y opacity. */
.ai-fab-orb::before, .ai-fab-orb::after { content: ""; position: absolute; border-radius: 50%; z-index: -2; pointer-events: none; }
.ai-fab-orb::before { inset: -6px; background: var(--grad-ai); filter: blur(14px); opacity: .45; animation: ai-fab-breathe 3.2s ease-in-out infinite; }
.ai-fab-orb::after { inset: 0; background: var(--violet-500); animation: ai-fab-ping 3.2s var(--ease) 1.2s infinite; }
.ai-fab-ring { position: absolute; inset: 0; z-index: -1; border-radius: 50%; background: var(--grad-ai); animation: spin 5s linear infinite; }
.ai-fab-core { display: grid; place-items: center; width: 50px; height: 50px; border-radius: 50%; background: var(--grad-deep); color: #fff; }
/* Chispa y cruz comparten celda: al abrir el chat una gira hacia afuera y la otra hacia adentro. */
.ai-fab-icon { grid-area: 1 / 1; display: grid; place-items: center; transition: opacity .2s var(--ease), transform .35s var(--spring); }
.ai-fab-icon .i { width: 24px; height: 24px; }
.ai-fab-icon.is-spark .i { animation: ai-fab-twinkle 3.2s var(--ease) infinite; }
.ai-fab-icon.is-close { opacity: 0; transform: rotate(-90deg) scale(.5); }
.ai-fab[aria-expanded="true"] .is-spark { opacity: 0; transform: rotate(90deg) scale(.5); }
.ai-fab[aria-expanded="true"] .is-close { opacity: 1; transform: none; }
.ai-fab-label {
  padding: 10px 16px;
  border-radius: 99px;
  background: var(--surface);
  border: 1px solid var(--violet-100);
  box-shadow: var(--shadow-md);
  font-size: 13.5px;
  font-weight: 650;
  white-space: nowrap;
  opacity: 0;
  transform: translateX(10px) scale(.96);
  transform-origin: right center;
  pointer-events: none;
  transition: opacity .2s var(--ease), transform .3s var(--spring);
}
.ai-fab-label b { color: var(--violet-700); font-weight: 800; }
.ai-fab:hover .ai-fab-label, .ai-fab:focus-visible .ai-fab-label { opacity: 1; transform: none; }
.ai-fab:hover .ai-fab-orb { transform: scale(1.08) rotate(-6deg); }
.ai-fab:active .ai-fab-orb { transform: scale(.94); transition-duration: .12s; }
@keyframes ai-fab-in { from { opacity: 0; transform: translateY(24px) scale(.6); } to { opacity: 1; transform: none; } }
@keyframes ai-fab-breathe { 0%, 100% { opacity: .35; transform: scale(.94); } 50% { opacity: .6; transform: scale(1.06); } }
@keyframes ai-fab-ping { from { opacity: .45; transform: scale(1); } 70%, to { opacity: 0; transform: scale(1.55); } }
@keyframes ai-fab-twinkle { 0%, 70%, 100% { transform: none; } 80% { transform: rotate(-14deg) scale(1.12); } 90% { transform: rotate(8deg) scale(.96); } }
@media (max-width: 640px) {
  .ai-fab { right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); }
  .ai-fab-orb { width: 54px; height: 54px; }
  .ai-fab-core { width: 45px; height: 45px; }
  .ai-fab-label { display: none; }
}
