/* ============================================================
   Layout — Shell con sidebar + topbar + página
   ============================================================ */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  position: relative;
  z-index: 1;
  transition: grid-template-columns var(--dur) var(--ease);
}

.app-shell[data-sidebar="collapsed"] {
  grid-template-columns: var(--sidebar-w-collapsed) 1fr;
}

/* ============ SIDEBAR ============ */
.sidebar {
  grid-row: 1 / -1;
  background: var(--bg-0);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: var(--z-sidebar);
  position: relative;
}

.sidebar::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--grad-surface);
  pointer-events: none;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--sp-5);
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  position: relative;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-width: 0;
}

.brand__logo {
  flex-shrink: 0;
  filter: drop-shadow(0 0 8px rgba(34, 211, 238, 0.25));
}

.brand__text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.brand__name {
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--text-hi);
  letter-spacing: -0.01em;
}

.brand__tag {
  font-size: 0.6875rem; /* 11 */
  font-weight: 500;
  color: var(--text-lo);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar__toggle {
  flex-shrink: 0;
}

.app-shell[data-sidebar="collapsed"] .brand,
.app-shell[data-sidebar="collapsed"] .user-pill__info,
.app-shell[data-sidebar="collapsed"] .nav__group-label,
.app-shell[data-sidebar="collapsed"] .nav__item-label {
  display: none;
}

.app-shell[data-sidebar="collapsed"] .sidebar__brand {
  padding-left: var(--sp-3);
  padding-right: var(--sp-3);
  justify-content: center;
}

/* Gira el icono del toggle cuando el sidebar está colapsado
   para comunicar visualmente que ahora "abre" en vez de "cerrar". */
.app-shell[data-sidebar="collapsed"] .sidebar__toggle svg {
  transform: rotate(180deg);
}
.sidebar__toggle svg {
  transition: transform var(--dur) var(--ease);
}

.app-shell[data-sidebar="collapsed"] .nav__item {
  justify-content: center;
  padding: var(--sp-3);
}

.app-shell[data-sidebar="collapsed"] .user-pill {
  justify-content: center;
  padding: var(--sp-3);
}

/* ---------- Navegación ---------- */
.nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-4) var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  position: relative;
}

.nav__group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav__group-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0 var(--sp-3) var(--sp-2);
}

/* ---------- Módulos expandibles ---------- */
.nav__module {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav__module-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-md);
  color: var(--text-hi);
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.nav__module-header:hover {
  background: var(--bg-2);
}

.nav__module-chevron {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  color: var(--text-dim);
  transition: transform var(--dur-fast) var(--ease);
}

.nav__module.is-expanded .nav__module-chevron {
  transform: rotate(90deg);
}

.nav__module-items {
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--dur) var(--ease);
}

.nav__module.is-expanded .nav__module-items {
  max-height: 800px;
}

.nav__module-items__inner {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 2px;
}

.nav__item--nested {
  padding-left: calc(var(--sp-3) + 18px + var(--sp-3));
  font-size: var(--fs-sm);
  color: var(--text-md);
}

.nav__item--nested .nav__item-icon {
  width: 14px;
  height: 14px;
  opacity: 0.65;
}

.nav__item--nested.is-active .nav__item-icon {
  opacity: 1;
}

/* Sidebar colapsado: oculta submenú y chevron, deja solo el icono del módulo */
.app-shell[data-sidebar="collapsed"] .nav__module-items,
.app-shell[data-sidebar="collapsed"] .nav__module-chevron {
  display: none;
}

.nav__item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-md);
  color: var(--text-md);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  text-decoration: none;
  white-space: nowrap;
  position: relative;
}

.nav__item:hover {
  background: var(--bg-2);
  color: var(--text-hi);
}

.nav__item.is-active {
  background: var(--accent-dim);
  color: var(--accent);
}

.nav__item.is-active::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
  box-shadow: 0 0 8px var(--accent);
}

.nav__item-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
}

.nav__item-badge {
  margin-left: auto;
  font-size: var(--fs-xs);
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background: var(--bg-3);
  color: var(--text-md);
  font-weight: 600;
  font-family: var(--font-mono);
}

.nav__item.is-active .nav__item-badge {
  background: var(--accent);
  color: var(--bg-0);
}

/* ---------- Footer sidebar ---------- */
.sidebar__footer {
  padding: var(--sp-3);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-md);
  background: var(--bg-2);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
}

.user-pill:hover { background: var(--bg-3); }

.user-pill__avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--grad-accent);
  color: var(--bg-0);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: var(--fs-sm);
  flex-shrink: 0;
}

.user-pill__info {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
  flex: 1;
}

.user-pill__name { font-size: var(--fs-sm); font-weight: 600; color: var(--text-hi); }
.user-pill__role { font-size: var(--fs-xs); color: var(--text-lo); }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  box-shadow: 0 0 0 2px var(--bg-2);
}
.status-dot--success { background: var(--success); }
.status-dot--warning { background: var(--warning); animation: pulse 2s ease infinite; }
.status-dot--danger { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ============ MAIN AREA ============ */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-h);
  padding: 0 var(--sp-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  background: var(--bg-1);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  z-index: var(--z-topbar);
  backdrop-filter: blur(12px);
}

.topbar__left, .topbar__right {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.topbar__left { min-width: 0; flex: 1; }

.topbar__menu { display: none; }

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  color: var(--text-md);
  min-width: 0;
  overflow: hidden;
}

.breadcrumbs__separator {
  color: var(--text-dim);
  user-select: none;
}

.breadcrumbs__item {
  color: var(--text-md);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease);
  white-space: nowrap;
}

.breadcrumbs__item:hover { color: var(--text-hi); }

.breadcrumbs__item.is-current {
  color: var(--text-hi);
  font-weight: 600;
  cursor: default;
  pointer-events: none;
}

/* ---------- Búsqueda topbar ---------- */
.search {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 var(--sp-3);
  height: 36px;
  min-width: 320px;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.search:focus-within {
  border-color: var(--accent);
  background: var(--bg-1);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.search__icon { color: var(--text-lo); flex-shrink: 0; }

.search__input {
  border: none;
  background: transparent;
  outline: none;
  flex: 1;
  font-size: var(--fs-sm);
  color: var(--text-hi);
  min-width: 0;
}

.search__input::placeholder { color: var(--text-lo); }

.kbd {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--text-lo);
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  flex-shrink: 0;
  font-weight: 500;
}

/* ============ PÁGINA ============ */
.page {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-6);
  outline: none;
  position: relative;
}

.page__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
  flex-wrap: wrap;
}

.page__title { font-size: var(--fs-3xl); font-weight: 700; letter-spacing: -0.02em; }
.page__subtitle { font-size: var(--fs-md); color: var(--text-md); margin-top: var(--sp-1); }
.page__actions { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }

/* ============ BANNER ============ */
.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  margin: var(--sp-3) var(--sp-6) 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-2);
}

.banner--warning {
  border-color: var(--warning);
  background: var(--warning-dim);
  color: var(--warning);
}

.banner--warning strong { color: var(--text-hi); }

.banner__body { flex: 1; font-size: var(--fs-sm); color: var(--text-md); }
.banner__body strong { display: inline; margin-right: var(--sp-2); }
.banner__body code {
  background: rgba(0,0,0,0.2);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.9em;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 1024px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    transform: translateX(-100%);
    transition: transform var(--dur) var(--ease);
    border-right: 1px solid var(--border);
  }
  .app-shell[data-mobile-open="true"] .sidebar { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .topbar__menu { display: inline-flex; }
  .search { min-width: 0; width: auto; }
  .search .kbd { display: none; }
}

@media (max-width: 640px) {
  .page { padding: var(--sp-4); }
  .topbar { padding: 0 var(--sp-4); }
  .search { display: none; }
}
