/* ============================================================
   CONAUT MANAGER — Navegación (sidebar animado + command palette)
   Eficacia + agilidad. Hereda tokens de conaut.css (cargado por operator.css).
   ============================================================ */

/* Transiciones de página entre documentos (MPA) donde el navegador las soporte. */
@view-transition { navigation: auto; }

:root { --side-w: 244px; --side-w-rail: 76px; }

/* ── Layout: el main se corre a la derecha del sidebar (en desktop con mouse,
     el margen es el del RIEL y la expansión por hover es overlay: el
     contenido NUNCA se mueve) ── */
.app-main { margin-left: var(--side-w); }

/* ── Sidebar ── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--side-w); z-index: 40;
  display: flex; flex-direction: column; padding: 18px 14px;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  overflow-x: clip; /* nada se pinta fuera durante la animación de ancho */
  transition: width var(--dur-menu) var(--ease-menu), transform var(--dur-menu) var(--ease-menu);
}

.side-top { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.sidebar .brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: var(--text); overflow: hidden; }
.sidebar .iso { width: 30px; height: 30px; flex: 0 0 auto; }
.sidebar .iso .ring { transform-box: fill-box; transform-origin: center; animation: spin 16s linear infinite; }
.sidebar .iso .node { transform-box: fill-box; transform-origin: 256px 256px; animation: orbit 16s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes orbit { to { transform: rotate(-360deg); } }
.sidebar .wm { font-family: var(--font-body); font-weight: 700; font-size: 17px; letter-spacing: 0.05em; white-space: nowrap; }

/* ── Nav principal (el estado activo se marca en el ítem y en la etiqueta
     del grupo que lo contiene — no hay indicador flotante) ── */
.side-nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item.is-active { background: rgba(37, 99, 235, 0.07); }
.nav-item, .cmdk, .logout, .brand-item {
  position: relative; z-index: 1; display: flex; align-items: center; gap: 12px;
  padding: 0 12px; height: 42px; border-radius: var(--r-md); text-decoration: none;
  color: var(--text-dim); font-family: var(--font-body); font-size: 0.92rem; font-weight: 500;
  border: 0; background: transparent; cursor: pointer; width: 100%; text-align: left;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.ni-icon { width: 22px; height: 22px; flex: 0 0 auto; display: grid; place-items: center; }
.ni-icon svg { width: 20px; height: 20px; transition: transform var(--dur) var(--ease-spring), filter var(--dur) var(--ease); }
.ni-label, .bi-label { white-space: nowrap; overflow: hidden; transition: opacity var(--dur) var(--ease); }
.nav-item:hover { color: var(--text); }
.nav-item:hover .ni-icon svg { transform: scale(1.06); }
.nav-item.is-active { color: var(--text); }
.nav-item.is-active .ni-icon svg { }

/* ── Marcas ── */
.side-label { font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--text-mute); padding: 18px 14px 8px; }
.side-brands { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; min-height: 0; padding-bottom: 8px; }
.side-brands::-webkit-scrollbar { width: 6px; }
.side-brands::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.brand-item .avatar {
  width: 26px; height: 26px; flex: 0 0 auto; border-radius: 8px; display: grid; place-items: center;
  font-family: var(--font-body); font-weight: 700; font-size: 11px; color: var(--bg-0);
  background: var(--grad-neon); transition: transform var(--dur) var(--ease-spring), box-shadow var(--dur) var(--ease);
}
.brand-item:hover { color: var(--text); background: rgba(9, 9, 11, 0.06); }
.brand-item:hover .avatar { transform: scale(1.05) rotate(-2deg); }
.brand-item.is-active { color: var(--text); background: rgba(37, 99, 235, 0.07); }
.brand-item.is-active .avatar { }

/* ── Bottom (buscar / salir) ── */
.side-bottom { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.cmdk kbd, .palette kbd {
  margin-left: auto; font-family: var(--font-body); font-size: 11px; color: var(--text-mute);
  background: #FFFFFF; border: 1px solid var(--border); border-radius: 6px; padding: 2px 7px;
}
.cmdk:hover, .logout:hover { color: var(--text); background: rgba(9, 9, 11, 0.06); }
.cmdk:hover .ni-icon svg { }

/* ── RIEL con hover-expand (solo desktop con mouse real): el menú vive
     retraído al borde izquierdo mostrando iconos, y al pasar el mouse (o
     enfocar con teclado) se despliega como OVERLAY encima del contenido.
     CERO saltos: los altos de fila son idénticos en ambos estados — solo
     anima el ANCHO y el fade de etiquetas — así el icono bajo el mouse se
     queda exactamente donde estaba. El texto se va ANTES de contraer y
     entra DESPUÉS de expandir; gracia de 150ms contra salidas accidentales.
     En táctil/móvil este bloque no aplica (menú expandido o drawer). ── */
@media (min-width: 881px) and (hover: hover) {
  .app-main { margin-left: var(--side-w-rail); }
  .sidebar {
    width: var(--side-w-rail);
    transition: width 260ms var(--ease-menu) 150ms, box-shadow 260ms var(--ease) 150ms;
  }
  .sidebar:hover, .sidebar:focus-within {
    width: var(--side-w);
    box-shadow: 28px 0 64px -28px rgba(9, 9, 11, 0.22);
    transition: width var(--dur-menu) var(--ease-menu), box-shadow var(--dur-menu) var(--ease);
  }
  .sidebar :is(.ni-label, .bi-label, .wm, .side-label, .nav-group-label, .cmdk kbd) {
    opacity: 0; transition: opacity 90ms var(--ease-exit);
  }
  .sidebar:is(:hover, :focus-within) :is(.ni-label, .bi-label, .wm, .side-label, .nav-group-label, .cmdk kbd) {
    opacity: 1; transition: opacity 220ms var(--ease) 90ms;
  }
  /* El "+" de Marcas es invisible en riel: que tampoco sea clickeable. */
  .sidebar .marca-add { pointer-events: none; }
  .sidebar:is(:hover, :focus-within) .marca-add { pointer-events: auto; }
}

/* ── Toggle móvil + scrim ── */
.nav-toggle {
  position: fixed; top: 16px; left: 16px; z-index: 45; width: 44px; height: 44px; display: none;
  place-items: center; border-radius: var(--r-md); border: 1px solid var(--border-strong);
  background: var(--bg-1); color: var(--text); cursor: pointer;
}
.sidebar-scrim { position: fixed; inset: 0; z-index: 39; background: rgba(9, 9, 11, 0.24); backdrop-filter: blur(4px); opacity: 0; pointer-events: none; transition: opacity var(--dur) var(--ease); }

@media (max-width: 880px) {
  .app-main { margin-left: 0; }
  .sidebar {
    transform: translateX(-100%); width: var(--side-w);
    /* El drawer entero se desliza con el dedo: en pantallas cortas el contenido
       excede el alto y sin esto las opciones de abajo quedaban inalcanzables. */
    overflow-y: auto; overscroll-behavior: contain;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
  }
  /* En el drawer la lista de marcas no scrollea aparte: crece natural y scrollea
     el drawer completo (flex:1 + min-height:0 la colapsaba a ~0px de alto). */
  .side-brands { flex: 0 0 auto; overflow-y: visible; }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .sidebar-scrim { opacity: 1; pointer-events: auto; }
  .nav-toggle { display: grid; }
  .wrap { padding-top: 8px; }
}

/* ── Command palette ── */
.palette-backdrop {
  position: fixed; inset: 0; z-index: 70; display: none; justify-content: center; align-items: flex-start;
  padding: 14vh 20px 20px; background: rgba(9, 9, 11, 0.24); backdrop-filter: blur(4px);
}
.palette-backdrop.open { display: flex; animation: fade 260ms var(--ease); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.palette {
  width: 100%; max-width: 560px; border-radius: var(--r-lg); overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border-strong); box-shadow: 0 40px 100px rgba(9, 9, 11, 0.32);
  animation: palette-pop 300ms var(--ease-menu);
}
@keyframes palette-pop { from { opacity: 0; transform: translateY(-10px) scale(0.98); } to { opacity: 1; transform: none; } }
/* Cierre: el menú se despide rápido y sin ceremonia (nada de display:none seco). */
.palette-backdrop.closing { animation: fade-exit var(--dur-exit) var(--ease-exit) forwards; }
.palette-backdrop.closing .palette { animation: palette-drop var(--dur-exit) var(--ease-exit) forwards; }
@keyframes fade-exit { to { opacity: 0; } }
@keyframes palette-drop { to { opacity: 0; transform: translateY(-6px) scale(0.985); } }
.palette-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); color: var(--text-mute); }
.palette-input { flex: 1; background: transparent; border: 0; outline: none; color: var(--text); font-family: var(--font-body); font-size: 1.05rem; }
.palette-input::placeholder { color: var(--text-mute); }
.palette-results { max-height: 52vh; overflow-y: auto; padding: 8px; }
.palette-group { font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-mute); padding: 10px 12px 6px; }
.p-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: var(--r-md);
  text-decoration: none; color: var(--text-dim); cursor: pointer; position: relative;
  opacity: 0; transform: translateY(6px); animation: p-rise var(--dur) var(--ease) forwards;
}
@keyframes p-rise { to { opacity: 1; transform: none; } }
.p-item .p-ic { width: 26px; height: 26px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 8px; background: #FFFFFF; border: 1px solid var(--border); }
.p-item .p-ic svg { width: 16px; height: 16px; stroke: var(--neon-cyan); }
.p-item .p-ic.avatar { background: var(--grad-neon); color: var(--bg-0); font-family: var(--font-body); font-weight: 700; font-size: 11px; border: 0; }
.p-item .p-label { font-weight: 500; color: var(--text); }
.p-item .p-sub { font-size: 0.8rem; color: var(--text-mute); margin-left: auto; }
.p-item.sel, .p-item:hover { background: linear-gradient(120deg, rgba(37, 99, 235, 0.12), rgba(79, 70, 229, 0.12)); color: var(--text); }
.p-item.sel::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--grad-neon); box-shadow: var(--glow-cyan); }
.palette-empty { padding: 28px; text-align: center; color: var(--text-mute); font-size: 0.9rem; }

/* ── Entrada de página ── */
.page-enter { animation: page-rise var(--dur-slow) var(--ease) both; }
@keyframes page-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* Motion desactivado por preferencia explícita (ver conaut.css). */
html[data-motion="off"] :is(.page-enter, .palette, .palette-backdrop, .p-item) { animation: none !important; transition: none !important; }
/* .p-item nace en opacity:0 y se revela con la animación. Al matarla hay que
   devolverle el estado final, o los resultados del buscador quedan invisibles. */
html[data-motion="off"] .p-item { opacity: 1 !important; transform: none !important; }
/* Riel: sin motion el ancho y las etiquetas cambian en seco, pero los
   estados (riel/desplegado) siguen siendo correctos. */
html[data-motion="off"] :is(.sidebar, .app-main,
  .sidebar :is(.ni-label, .bi-label, .wm, .side-label, .nav-group-label, .cmdk kbd)) { transition: none !important; }

/* ============================================================
   Barra de título custom — modo app de escritorio (pywebview)
   ============================================================ */
.app-titlebar { display: none; }

body.desktop-shell .app-titlebar {
  display: flex; align-items: center; justify-content: space-between;
  position: fixed; top: 0; left: 0; right: 0; height: 40px; z-index: 200;
  padding-left: 14px; user-select: none; -webkit-user-select: none;
  background: linear-gradient(180deg, var(--bg-1), var(--bg-1));
  border-bottom: 1px solid var(--border);
}
/* El contenido baja para no quedar debajo de la barra. */
body.desktop-shell .sidebar { top: 40px; }
body.desktop-shell .app-main { margin-top: 40px; }
body.desktop-shell .nav-toggle { top: 50px; }

.app-titlebar .tb-brand { display: flex; align-items: center; gap: 9px; pointer-events: none; }
.app-titlebar .tb-iso { width: 19px; height: 19px; }
.app-titlebar .tb-title { font-family: var(--font-body); font-weight: 600; font-size: 12.5px; letter-spacing: 0.06em; color: var(--text-dim); }

.app-titlebar .tb-controls { display: flex; align-items: stretch; height: 100%; }
.app-titlebar .tb-btn {
  width: 46px; height: 40px; display: grid; place-items: center; border: 0; cursor: default;
  background: transparent; color: var(--text-dim); transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.app-titlebar .tb-btn:hover { background: rgba(9, 9, 11, 0.1); color: var(--text); }
.app-titlebar .tb-btn:active { background: rgba(9, 9, 11, 0.16); }
.app-titlebar .tb-close:hover { background: var(--neon-red); color: #fff; }
.app-titlebar .tb-close:active { background: #B91C1C; }

/* ── Tech minimal: wordmark tight + avatares de marca como orbes vivos ── */
.sidebar .wm { letter-spacing: -0.02em; font-weight: 700; }
.side-brands .avatar {
  background:
    radial-gradient(120% 120% at 30% 25%, var(--orb-a) 0%, transparent 52%),
    radial-gradient(130% 130% at 72% 70%, var(--orb-b) 0%, transparent 56%),
    radial-gradient(150% 150% at 50% 100%, var(--orb-c) 0%, transparent 58%),
    #0E0E11;
  background-size: 190% 190%, 200% 200%, 210% 210%, 100% 100%;
  animation: orb-drift 13s ease-in-out infinite alternate;
  color: #FFFFFF;
}
.side-brands .brand-item:nth-child(2) .avatar { animation-duration: 17s; animation-delay: -4s; }
.side-brands .brand-item:nth-child(3) .avatar { animation-duration: 21s; animation-delay: -9s; }

/* ── Grupos del nav: etiqueta + ítems, siempre visibles (el hover-expand
     vive a nivel de TODO el sidebar, arriba). La fila de etiqueta existe en
     ambos estados — en riel su texto es invisible pero conserva el alto —
     para que nada salte verticalmente al desplegar. ── */
.nav-group { display: flex; flex-direction: column; gap: 3px; }
.nav-group-label { display: block; font-size: 9.5px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-mute); padding: 16px 14px 5px; user-select: none; white-space: nowrap; }
/* La etiqueta del grupo con la sección activa te orienta de un vistazo. */
.nav-group.has-active .nav-group-label { color: var(--accent); }
.marcas-label { display:flex; align-items:center; justify-content:space-between; }
.marca-add { display:inline-flex; align-items:center; justify-content:center; width:18px; height:18px;
  border:1px solid var(--border-strong); border-radius:6px; color:var(--text-mute); text-decoration:none;
  font-size:13px; line-height:1; transition:color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease); }
.marca-add:hover { color:var(--neon-cyan); border-color:var(--neon-cyan); }
