/* ============================================================
   shell.css — App shell: sidebar + main + topbar
   ------------------------------------------------------------
   Estructura:
   <div class="app-shell">
     <aside class="sidebar">…</aside>
     <main class="app-main">…</main>
   </div>

   En Capa 2 el sidebar es nuevo; el .header legacy sigue
   activo dentro de .app-main (será limpiado en Capa 3).
   ============================================================ */

/* ---- App shell grid ---- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  background: var(--bg-app);
}

.app-main {
  min-width: 0; /* permite que el contenido respete el grid (no overflow) */
  display: flex;
  flex-direction: column;
}

/* ============================================================
   SIDEBAR (base — DEBE ir antes de los media queries para que
   los overrides responsive ganen en la cascada).
   ============================================================ */
.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: var(--sp-5) var(--sp-3);
  gap: var(--sp-5);
  overflow-y: auto;
  transition: width var(--t-med) var(--ease);
  z-index: 50;
}

/* En tablets (<1200px), sidebar colapsa a íconos */
@media (max-width: 1200px) {
  .app-shell {
    grid-template-columns: var(--sidebar-w-collapsed) 1fr;
  }
  .sidebar { width: var(--sidebar-w-collapsed); }
  .sidebar .s-label,
  .sidebar .s-section-title,
  .sidebar .s-brand-text {
    display: none;
  }
  .sidebar .s-link {
    justify-content: center;
    padding: var(--sp-3);
  }
  /* En sidebar collapsed, los s-dot (canales) quedan flotantes sin
     texto → reemplazamos por icon-look: agrandar y centrar */
  .sidebar .s-link .s-dot {
    width: 10px;
    height: 10px;
    opacity: 1;
  }
}

/* En mobile (<900px), sidebar oculto, contenido full-width */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar { display: none; }
}

/* Brand row (logo + nombre) */
.s-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  text-decoration: none;
  color: var(--text-1);
}
.s-brand-logo {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.logo-on-light { display: block; }
.logo-on-dark  { display: none; }
[data-theme="dark"] .logo-on-light { display: none; }
[data-theme="dark"] .logo-on-dark  { display: block; }
.s-brand-logo img { width: 36px; height: 36px; object-fit: contain; }

/* Sidebar refresh buttons — loading state */
.s-link.is-refreshing {
  color: var(--blue);
  background: color-mix(in srgb, var(--blue) 8%, transparent);
  pointer-events: none;
}
.s-link.is-refreshing .s-icon {
  color: var(--blue);
}
.s-link.is-refreshing .s-icon svg {
  animation: spin 0.7s linear infinite;
}
/* Done state — breve flash verde antes de restaurar */
.s-link.refresh-done {
  color: #34c759;
  pointer-events: none;
}
.s-link.refresh-done .s-icon { color: #34c759; }
.s-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}
.s-brand-text .s-brand-name {
  font-size: var(--fs-body);
  font-weight: var(--fw-semi);
  color: var(--text-1);
}
.s-brand-text .s-brand-sub {
  font-size: var(--fs-xs);
  color: var(--text-3);
}

/* Section group */
.s-section {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.s-section-title {
  font-size: var(--fs-micro);
  font-weight: var(--fw-semi);
  letter-spacing: var(--tr-wide);
  text-transform: uppercase;
  color: var(--text-3);
  padding: var(--sp-2) var(--sp-3) var(--sp-1);
}

/* Sidebar link/button (unificado) */
.s-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r);
  font-size: var(--fs-body);
  font-weight: var(--fw-medium);
  color: var(--text-2);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: background var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease);
  width: 100%;
}
.s-link:hover {
  background: var(--surface-2);
  color: var(--text-1);
}
.s-link.is-active {
  background: var(--surface-2);
  color: var(--text-1);
  font-weight: var(--fw-semi);
}
.s-link .s-icon {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  color: var(--text-3);
  display: flex;
  align-items: center;
  justify-content: center;
}
.s-link.is-active .s-icon { color: var(--blue); }
.s-link .s-dot {
  flex: 0 0 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}
.s-link .s-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.s-link .s-ext {
  font-size: var(--fs-xs);
  color: var(--text-4);
}

/* Sub-ítems del nav (Escenas / Brand kit / Saldo, anidados dentro de Generar) */
.s-link.s-sublink {
  padding-left: calc(var(--sp-3) + 26px);
  font-size: var(--fs-sm);
  color: var(--text-3);
}
.s-link.s-sublink .s-icon {
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
}
.s-link.s-sublink.is-active { color: var(--text-1); }

/* Tercer nivel del nav (Promociones, anidado dentro de Mercado Libre) */
.s-link.s-sublink2 {
  padding-left: calc(var(--sp-3) + 44px);
  font-size: var(--fs-xs);
}

/* Spacer: con #sidebarChannelAnchors flex:1 el spacer ya no necesita crecer.
   Mantiene un mínimo de separación visual. */
.s-spacer { flex: 0 0 auto; height: var(--sp-2); }

/* Sidebar anchors (B2C · Secciones) — bullet point indicator */
.s-anchor .s-bullet {
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-4);
  transition: background var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease);
}
.s-anchor:hover .s-bullet {
  background: var(--text-2);
}
.s-anchor.is-active .s-bullet {
  background: var(--blue);
  transform: scale(1.6);
}
.s-anchor.is-active {
  color: var(--text-1);
  font-weight: var(--fw-semi);
}

/* Channel anchors — siempre visibles. Contenido dinámico según canal activo.
   flex:1 + overflow-y:auto → la lista scrollea independiente para que
   Vistas y Datos queden siempre visibles al fondo del sidebar. */
#sidebarChannelAnchors {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  flex: 1 1 0%;
  min-height: 0;          /* permite que flex shrink funcione */
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--text-4) transparent;
}
#sidebarChannelAnchors::-webkit-scrollbar { width: 4px; }
#sidebarChannelAnchors::-webkit-scrollbar-thumb {
  background: var(--text-4);
  border-radius: 4px;
}
#sidebarChannelAnchors::-webkit-scrollbar-track { background: transparent; }
#sidebarAnchorsList { display: flex; flex-direction: column; gap: var(--sp-1); }
/* Si el canal no tiene anchors, ocultamos toda la sección */
#sidebarChannelAnchors:not(:has(.s-anchor)) { display: none; }

/* Theme toggle icons: muestra sol o luna según el tema activo */
.theme-icon-light { display: none; }
.theme-icon-dark  { display: inline; }
[data-theme="dark"] .theme-icon-light { display: inline; }
[data-theme="dark"] .theme-icon-dark  { display: none; }

/* ============================================================
   TOPBAR (placeholder — se completa en Capa 3)
   ============================================================ */
/* Reservado para Capa 3: actualmente el header legacy ocupa el lugar. */

/* ============================================================
   CONTAINER de contenido dentro del main
   ============================================================ */
.app-main > .w,
.app-main > .tab-panel {
  max-width: var(--content-max);
  width: 100%;
}

/* Ajuste sutil del padding en desktop para respirar */
@media (min-width: 1201px) {
  .app-main > .w {
    padding-left: var(--sp-8);
    padding-right: var(--sp-8);
  }
  .app-main > .tab-panel {
    padding-left: var(--sp-8);
    padding-right: var(--sp-8);
  }
}

/* ============================================================
   MOBILE HEADER CONTROLS (hamburger + theme toggle)
   Hidden on desktop, visible ≤900px.
   ============================================================ */
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-title-group {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  flex: 1 1 0%;
  overflow: hidden;
}
.header-subtitle {
  color: var(--text-3);
  font-size: var(--fs-sm);
  white-space: nowrap;
}
.header-mobile-actions {
  display: none;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  width: max-content;
}
.mobile-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--r);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.mobile-icon-btn:hover,
.mobile-icon-btn:active {
  background: var(--surface-2);
  color: var(--text-1);
}
.mobile-icon-btn .close-icon { display: none; }
.mobile-icon-btn[aria-expanded="true"] .hamburger-icon { display: none; }
.mobile-icon-btn[aria-expanded="true"] .close-icon { display: block; }

@media (max-width: 900px) {
  .header-mobile-actions { display: flex; }
  .header-subtitle { display: none; }
  .header-title-group { gap: 0; }
}

/* ============================================================
   MOBILE DRAWER (slide-in panel, ≤900px only)
   Replaces sidebar for section nav, views, refresh, etc.
   ============================================================ */
.mobile-drawer {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  width: min(300px, 85vw);
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px -8px rgba(0,0,0,.15);
  z-index: 200;
  transform: translateX(100%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--sp-5) var(--sp-4) var(--sp-8);
  flex-direction: column;
  gap: var(--sp-5);
}
@media (max-width: 900px) {
  .mobile-drawer { display: flex; }
}
.mobile-drawer.is-open {
  transform: translateX(0);
}
.mobile-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 199;
  background: rgba(0,0,0,.35);
  opacity: 0;
  transition: opacity .25s var(--ease);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
@media (max-width: 900px) {
  .mobile-backdrop { display: block; pointer-events: none; }
}
.mobile-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.mobile-drawer__title {
  font-size: var(--fs-micro);
  font-weight: var(--fw-semi);
  letter-spacing: var(--tr-wide);
  text-transform: uppercase;
  color: var(--text-3);
  padding: 0 var(--sp-2) var(--sp-1);
}
.mobile-drawer__group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.mobile-drawer__link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-3);
  border-radius: var(--r);
  font-size: var(--fs-body);
  font-weight: var(--fw-medium);
  color: var(--text-2);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  width: 100%;
  min-height: 44px;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.mobile-drawer__link:hover,
.mobile-drawer__link:active {
  background: var(--surface-2);
  color: var(--text-1);
}
.mobile-drawer__link.is-active {
  background: var(--surface-2);
  color: var(--text-1);
  font-weight: var(--fw-semi);
}
.mobile-drawer__link svg {
  flex-shrink: 0;
  color: var(--text-3);
}
.mobile-drawer__link:disabled {
  opacity: .5;
  pointer-events: none;
}
.mobile-drawer__sections {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

/* Grupos colapsables del nav (Catálogo · Promociones · Generar), cerrados por default (2026-10-06). */
.s-group-head { display: flex; align-items: center; gap: 2px; }
.s-group-head .s-link { flex: 1; min-width: 0; }
.s-toggle {
  flex: 0 0 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: var(--r);
  color: var(--text-3); font-size: 18px; line-height: 1; cursor: pointer;
  transition: transform var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.s-toggle:hover { background: var(--surface-2); color: var(--text-1); }
.s-group.is-open .s-toggle { transform: rotate(90deg); }
.s-group .s-children { display: none; }
.s-group.is-open .s-children { display: block; }
/* Sidebar angosto (solo íconos): sin flecha y con todo a la vista, como antes. */
@media (max-width: 1200px) {
  .s-toggle { display: none; }
  .s-group .s-children { display: block; }
}
