/* ═══════════════════════════════════════════════════════════════
   Portal sidebar — navegación premium (rail + drawer)
   Alcance: #portal-sidebar.sidebar--rail
   ═══════════════════════════════════════════════════════════════ */

:root {
  --portal-sidebar-rail-width-collapsed: 92px;
  --portal-sidebar-rail-width-expanded: 288px;
  --portal-sidebar-nav-text: #243d56;
  --portal-sidebar-nav-text-muted: #4a6278;
  --portal-sidebar-surface: linear-gradient(
    165deg,
    #ffffff 0%,
    #f7fbff 38%,
    #f0f6fc 100%
  );
  --portal-sidebar-surface-glow:
    radial-gradient(ellipse 120% 80% at 0% 0%, rgba(var(--primary-mid-rgb), 0.14), transparent 55%),
    radial-gradient(ellipse 90% 60% at 100% 100%, rgba(var(--primary-rgb), 0.08), transparent 50%);
  --portal-sidebar-item-radius: 14px;
  --portal-sidebar-icon-size: 36px;
  --portal-sidebar-icon-radius: 11px;
  --portal-sidebar-transition: 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}

body[data-theme="dark"] {
  --portal-sidebar-nav-text: #dcecff;
  --portal-sidebar-nav-text-muted: #9ec0e0;
  --portal-sidebar-surface: linear-gradient(
    165deg,
    #101e32 0%,
    #152238 42%,
    #0f1a2c 100%
  );
  --portal-sidebar-surface-glow:
    radial-gradient(ellipse 110% 70% at 0% 0%, rgba(var(--primary-mid-rgb), 0.12), transparent 52%),
    radial-gradient(ellipse 80% 50% at 100% 100%, rgba(var(--primary-rgb), 0.1), transparent 48%);
}

/* ── Shell ── */
#portal-sidebar.sidebar--rail {
  position: relative;
  isolation: isolate;
  padding: 0.9rem 0.7rem 0.8rem;
  border-right: 1px solid color-mix(in srgb, var(--portal-sidebar-border) 88%, transparent);
  border-radius: 0;
  background: var(--portal-sidebar-surface);
  box-shadow:
    1px 0 0 rgba(255, 255, 255, 0.65) inset,
    4px 0 24px rgba(var(--primary-rgb), 0.06);
  overflow: hidden;
}

#portal-sidebar.sidebar--rail::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--portal-sidebar-surface-glow);
  pointer-events: none;
  z-index: 0;
}

#portal-sidebar.sidebar--rail > * {
  position: relative;
  z-index: 1;
}

body:not(.portal-sidebar-collapsed) #portal-sidebar.sidebar--rail {
  padding: 1rem 0.85rem 0.9rem;
}

/* ── Header / marca ── */
#portal-sidebar .sidebar-rail-head {
  padding: 0.25rem 0.35rem 0.85rem;
  margin-bottom: 0.25rem;
  gap: 0.35rem;
}

body:not(.portal-sidebar-collapsed) #portal-sidebar .sidebar-rail-head {
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  padding: 0.15rem 0.15rem 1rem;
  margin-bottom: 0.35rem;
  border-bottom: 1px solid color-mix(in srgb, var(--portal-sidebar-border) 75%, transparent);
}

#portal-sidebar .sidebar-brand-block {
  position: relative;
  width: 100%;
}

#portal-sidebar .sidebar-brand-logo-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  min-width: 0;
  height: 50px;
  min-height: 50px;
  padding: 0.45rem 2.65rem 0.45rem 0.65rem;
  border-radius: 16px;
  overflow: hidden;
  isolation: isolate;
  background: linear-gradient(
    128deg,
    #071525 0%,
    #0f2844 38%,
    #1a4470 72%,
    #2a6399 100%
  );
  box-shadow:
    0 10px 28px rgba(var(--primary-rgb), 0.28),
    0 0 0 1px rgba(255, 255, 255, 0.12) inset,
    0 0 0 1px rgba(var(--primary-rgb), 0.18),
    0 0 24px rgba(var(--primary-mid-rgb), 0.2);
  transition:
    box-shadow var(--portal-sidebar-transition),
    transform var(--portal-sidebar-transition);
}

#portal-sidebar .sidebar-brand-logo-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 90% 140% at 8% 50%, rgba(var(--primary-mid-rgb), 0.38), transparent 62%),
    radial-gradient(ellipse 60% 80% at 92% 20%, rgba(255, 255, 255, 0.08), transparent 55%);
  pointer-events: none;
  z-index: 0;
}

#portal-sidebar .sidebar-brand-logo-wrap::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.22), transparent);
  pointer-events: none;
  z-index: 2;
}

#portal-sidebar .sidebar-brand-logo-wrap:hover {
  transform: translateY(-1px);
  box-shadow:
    0 14px 32px rgba(var(--primary-rgb), 0.34),
    0 0 0 1px rgba(255, 255, 255, 0.16) inset,
    0 0 0 1px rgba(var(--primary-mid-rgb), 0.28),
    0 0 32px rgba(var(--primary-mid-rgb), 0.28);
}

#portal-sidebar .sidebar-brand-logo {
  position: relative;
  z-index: 1;
  user-select: none;
  -webkit-user-drag: none;
  mix-blend-mode: screen;
  transition: filter var(--portal-sidebar-transition), transform var(--portal-sidebar-transition), opacity var(--portal-sidebar-transition);
}

#portal-sidebar .sidebar-brand-logo--full {
  display: block;
  width: 100%;
  height: auto;
  max-height: 44px;
  object-fit: contain;
  object-position: left center;
  filter:
    contrast(1.42)
    saturate(1.28)
    brightness(1.22)
    drop-shadow(0 2px 8px rgba(0, 0, 0, 0.5))
    drop-shadow(0 0 20px rgba(200, 230, 255, 0.55))
    drop-shadow(0 0 32px rgba(var(--primary-mid-rgb), 0.45));
}

#portal-sidebar .sidebar-brand-logo--mark {
  display: none;
  width: 100%;
  height: 100%;
  max-width: 38px;
  max-height: 38px;
  margin: 0 auto;
  object-fit: contain;
  object-position: center;
  filter:
    contrast(1.34)
    saturate(1.22)
    brightness(1.14)
    drop-shadow(0 3px 10px rgba(0, 0, 0, 0.42))
    drop-shadow(0 0 14px rgba(184, 228, 255, 0.38))
    drop-shadow(0 0 24px rgba(var(--primary-mid-rgb), 0.32));
}

#portal-sidebar .sidebar-brand-logo-wrap:hover .sidebar-brand-logo--full,
#portal-sidebar .sidebar-brand-logo-wrap:hover .sidebar-brand-logo--mark {
  filter:
    contrast(1.38)
    saturate(1.26)
    brightness(1.18)
    drop-shadow(0 4px 12px rgba(0, 0, 0, 0.45))
    drop-shadow(0 0 22px rgba(210, 238, 255, 0.48))
    drop-shadow(0 0 36px rgba(var(--primary-mid-rgb), 0.4));
  transform: scale(1.04);
}

/* Rail colapsado: isotipo + toggle debajo */
body.portal-sidebar-collapsed #portal-sidebar .sidebar-brand-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

body.portal-sidebar-collapsed #portal-sidebar .sidebar-brand-logo-wrap {
  flex: 0 0 54px;
  width: 54px;
  min-width: 54px;
  height: 54px;
  min-height: 54px;
  padding: 0.5rem;
  justify-content: center;
  align-items: center;
}

body.portal-sidebar-collapsed #portal-sidebar .sidebar-brand-logo--full {
  display: none;
}

body.portal-sidebar-collapsed #portal-sidebar .sidebar-brand-logo--mark {
  display: block;
  max-width: 34px;
  max-height: 34px;
}

body.portal-sidebar-collapsed #portal-sidebar .sidebar-rail-head {
  align-items: center;
}

/* Toggle integrado en el banner (expandido) o debajo del isotipo (colapsado) */
@media (min-width: 921px) {
  #portal-sidebar .sidebar-expand-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 9px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.14);
    color: #eef6ff;
    cursor: pointer;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow:
      0 2px 10px rgba(0, 0, 0, 0.22),
      inset 0 1px 0 rgba(255, 255, 255, 0.18);
    transition:
      background var(--portal-sidebar-transition),
      border-color var(--portal-sidebar-transition),
      color var(--portal-sidebar-transition),
      transform var(--portal-sidebar-transition),
      box-shadow var(--portal-sidebar-transition);
  }

  body:not(.portal-sidebar-collapsed) #portal-sidebar .sidebar-expand-toggle {
    position: absolute;
    top: 50%;
    right: 0.5rem;
    transform: translateY(-50%);
    z-index: 4;
  }

  body.portal-sidebar-collapsed #portal-sidebar .sidebar-expand-toggle {
    position: static;
    transform: none;
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: rgba(var(--primary-rgb), 0.08);
    border-color: rgba(var(--primary-rgb), 0.16);
    color: var(--primary);
    box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.1);
    backdrop-filter: none;
  }

  #portal-sidebar .sidebar-expand-toggle svg {
    width: 15px;
    height: 15px;
  }

  #portal-sidebar .sidebar-expand-toggle:hover {
    background: rgba(255, 255, 255, 0.24);
    border-color: rgba(255, 255, 255, 0.34);
    color: #ffffff;
    box-shadow:
      0 4px 14px rgba(0, 0, 0, 0.28),
      inset 0 1px 0 rgba(255, 255, 255, 0.24);
  }

  body:not(.portal-sidebar-collapsed) #portal-sidebar .sidebar-expand-toggle:hover {
    transform: translateY(-50%) scale(1.06);
  }

  body.portal-sidebar-collapsed #portal-sidebar .sidebar-expand-toggle:hover {
    background: rgba(var(--primary-rgb), 0.14);
    border-color: rgba(var(--primary-rgb), 0.28);
    color: var(--primary-deeper, #1e4a73);
    transform: scale(1.05);
  }

  body.portal-sidebar-collapsed .sidebar-expand-toggle-icon--collapse {
    display: none;
  }

  body.portal-sidebar-collapsed .sidebar-expand-toggle-icon--expand {
    display: block;
  }

  body:not(.portal-sidebar-collapsed) .sidebar-expand-toggle-icon--expand {
    display: none;
  }
}

body[data-theme="dark"] #portal-sidebar .sidebar-expand-toggle {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.1);
  color: #dcecff;
}

body[data-theme="dark"].portal-sidebar-collapsed #portal-sidebar .sidebar-expand-toggle {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(var(--primary-mid-rgb), 0.22);
  color: var(--portal-sidebar-active-text);
}

/* ── Scroll area ── */
#portal-sidebar .sidebar-rail-scroll {
  gap: 0.2rem;
  padding: 0.15rem 0.5rem 0.35rem 0.1rem;
  scrollbar-gutter: stable;
}

/* ── Section labels ── */
#portal-sidebar .sidebar-section-label {
  display: none;
  align-items: center;
  gap: 0.55rem;
  margin: 0;
  padding: 0.75rem 0.4rem 0.35rem;
  font-family: var(--font-secondary);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--portal-sidebar-nav-text-muted);
  white-space: nowrap;
}

body[data-theme="dark"] #portal-sidebar .sidebar-section-label {
  color: color-mix(in srgb, var(--portal-sidebar-nav-text-muted) 90%, var(--primary-mid));
}

#portal-sidebar .sidebar-section-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(
    90deg,
    rgba(var(--primary-rgb), 0.22),
    rgba(var(--primary-rgb), 0.04) 80%,
    transparent
  );
}

body:not(.portal-sidebar-collapsed) #portal-sidebar .sidebar-section-label {
  display: flex;
}

@media (max-width: 920px) {
  #portal-sidebar .sidebar-section-label {
    display: flex;
  }
}

/* ── Nav links ── */
#portal-sidebar .side-link {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 0.72rem;
  width: 100%;
  min-height: 44px;
  padding: 0.42rem 0.55rem;
  border: 1px solid transparent;
  border-radius: var(--portal-sidebar-item-radius);
  background: transparent;
  color: var(--portal-sidebar-nav-text);
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.25;
  text-align: left;
  cursor: pointer;
  transition:
    background var(--portal-sidebar-transition),
    border-color var(--portal-sidebar-transition),
    color var(--portal-sidebar-transition),
    box-shadow var(--portal-sidebar-transition),
    transform var(--portal-sidebar-transition);
}

#portal-sidebar .side-link__icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: var(--portal-sidebar-icon-size);
  height: var(--portal-sidebar-icon-size);
  min-width: var(--portal-sidebar-icon-size);
  border-radius: var(--portal-sidebar-icon-radius);
  background: rgba(var(--primary-rgb), 0.06);
  border: 1px solid rgba(var(--primary-rgb), 0.09);
  color: color-mix(in srgb, var(--portal-sidebar-link-hover) 88%, var(--primary));
  box-shadow: 0 1px 2px rgba(var(--primary-rgb), 0.04);
  transition:
    background var(--portal-sidebar-transition),
    border-color var(--portal-sidebar-transition),
    color var(--portal-sidebar-transition),
    box-shadow var(--portal-sidebar-transition),
    transform var(--portal-sidebar-transition);
}

#portal-sidebar .side-link__icon-wrap .side-icon,
#portal-sidebar .side-link__icon-wrap svg {
  width: 18px !important;
  height: 18px !important;
  min-width: 18px !important;
  max-width: 18px !important;
  max-height: 18px !important;
  flex-shrink: 0;
  display: block;
}

#portal-sidebar .side-link__label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: inherit;
  font-weight: inherit;
  transition: opacity var(--portal-sidebar-transition), max-width var(--portal-sidebar-transition);
}

#portal-sidebar .side-link:hover {
  background: rgba(var(--primary-rgb), 0.07);
  border-color: rgba(var(--primary-rgb), 0.1);
  color: var(--portal-sidebar-nav-text);
  transform: translateX(2px);
}

#portal-sidebar .side-link:hover .side-link__icon-wrap {
  background: rgba(var(--primary-rgb), 0.11);
  border-color: rgba(var(--primary-rgb), 0.18);
  color: var(--primary);
  transform: scale(1.04);
}

#portal-sidebar .side-link.active {
  background: linear-gradient(
    95deg,
    rgba(var(--primary-rgb), 0.16) 0%,
    rgba(var(--primary-rgb), 0.07) 58%,
    rgba(var(--primary-rgb), 0.03) 100%
  );
  border-color: rgba(var(--primary-rgb), 0.22);
  color: var(--primary-deeper, #1e4a73);
  font-weight: 700;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    0 4px 14px rgba(var(--primary-rgb), 0.1);
}

#portal-sidebar .side-link.active::after {
  display: none;
}

#portal-sidebar .side-link.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 58%;
  border-radius: 0 4px 4px 0;
  background: linear-gradient(180deg, var(--primary-mid) 0%, var(--primary) 100%);
  box-shadow: 0 0 10px rgba(var(--primary-rgb), 0.45);
}

#portal-sidebar .side-link.active .side-link__icon-wrap {
  background: linear-gradient(145deg, var(--primary) 0%, var(--primary-mid) 100%);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 6px 16px rgba(var(--primary-rgb), 0.38);
}

#portal-sidebar .side-link-badge {
  position: absolute;
  top: -5px;
  right: -7px;
  margin: 0;
  flex-shrink: 0;
  min-width: 1.1rem;
  min-height: 1.1rem;
  padding: 0 0.28rem;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1.1rem;
  text-align: center;
  background: linear-gradient(135deg, #ef4444, #f97316);
  color: #fff;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.42);
  z-index: 2;
  pointer-events: none;
}

#portal-sidebar .side-link--notif-inbox .side-link__icon-wrap {
  position: relative;
  overflow: visible;
}

#portal-sidebar .side-link--notif-inbox {
  flex: 1 1 0;
  min-width: 0;
  overflow: visible;
  padding: 0.42rem 0.45rem 0.42rem 0.55rem !important;
  margin: 0;
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
}

body.portal-sidebar-collapsed #portal-sidebar .side-link {
  justify-content: center;
  padding: 0.38rem 0.35rem;
  gap: 0;
}

body.portal-sidebar-collapsed #portal-sidebar .side-link__label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body.portal-sidebar-collapsed #portal-sidebar .side-link:hover {
  transform: none;
}

body.portal-sidebar-collapsed #portal-sidebar .side-link.active::before {
  left: 4px;
  height: 48%;
}

/* ── Notificaciones: hub unificado (bandeja + silenciador) ── */
#portal-sidebar .sidebar-notif-group {
  margin-top: 0.15rem;
  overflow: visible;
}

#portal-sidebar .sidebar-notif-hub {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  border-radius: calc(var(--portal-sidebar-item-radius) + 2px);
  border: 1px solid rgba(var(--primary-rgb), 0.1);
  background: rgba(var(--primary-rgb), 0.04);
  overflow: hidden;
  transition:
    background var(--portal-sidebar-transition),
    border-color var(--portal-sidebar-transition),
    box-shadow var(--portal-sidebar-transition);
}

#portal-sidebar .sidebar-notif-hub:has(.side-link--notif-inbox.active) {
  background: rgba(var(--primary-rgb), 0.09);
  border-color: rgba(var(--primary-rgb), 0.2);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

#portal-sidebar .sidebar-notif-hub .side-link--notif-inbox {
  flex: 1 1 0;
  min-width: 0;
  width: auto;
}

#portal-sidebar .sidebar-notif-hub__divider {
  flex-shrink: 0;
  width: 1px;
  align-self: stretch;
  margin: 0.42rem 0;
  background: linear-gradient(
    180deg,
    transparent,
    rgba(var(--primary-rgb), 0.2) 18%,
    rgba(var(--primary-rgb), 0.2) 82%,
    transparent
  );
}

#portal-sidebar .sidebar-notif-hub .sidebar-notif-bell-toggle {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.65rem !important;
  min-width: 2.65rem !important;
  max-width: 2.65rem;
  align-self: stretch;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--portal-sidebar-link-hover);
  cursor: pointer;
  position: relative;
  transition:
    background var(--portal-sidebar-transition),
    color var(--portal-sidebar-transition);
}

#portal-sidebar .sidebar-notif-hub .sidebar-notif-bell-toggle:hover {
  background: rgba(var(--primary-rgb), 0.1);
  color: var(--primary);
  transform: none;
}

#portal-sidebar .sidebar-notif-hub .sidebar-notif-bell-toggle .side-icon {
  width: 18px !important;
  height: 18px !important;
}

#portal-sidebar .side-link--notif-inbox.active {
  background: transparent !important;
  border-color: transparent !important;
  box-shadow: none !important;
  color: var(--portal-sidebar-active-text);
}

#portal-sidebar .side-link--notif-inbox.active .side-link__icon-wrap {
  background: linear-gradient(145deg, var(--primary) 0%, var(--primary-mid) 100%);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 6px 16px rgba(var(--primary-rgb), 0.38);
}

#portal-sidebar .side-link--notif-inbox.active::before {
  display: none;
}

body.portal-sidebar-collapsed #portal-sidebar .sidebar-notif-hub {
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 0.12rem 0;
}

body.portal-sidebar-collapsed #portal-sidebar .sidebar-notif-hub__divider {
  width: auto;
  height: 1px;
  margin: 0 0.35rem;
  align-self: stretch;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(var(--primary-rgb), 0.2) 18%,
    rgba(var(--primary-rgb), 0.2) 82%,
    transparent
  );
}

body.portal-sidebar-collapsed #portal-sidebar .side-link--notif-inbox {
  justify-content: center;
  padding: 0.38rem 0.35rem !important;
}

body.portal-sidebar-collapsed #portal-sidebar .sidebar-notif-hub .side-link--notif-inbox {
  flex: 0 0 auto;
  width: 100%;
}

body.portal-sidebar-collapsed #portal-sidebar .sidebar-notif-hub .sidebar-notif-bell-toggle {
  width: 100% !important;
  min-width: 0 !important;
  max-width: none;
  min-height: 2.35rem;
}

/* ── Footer: dock de cuenta ── */
#portal-sidebar .sidebar-rail-foot {
  margin-top: 0.55rem;
  padding-top: 0;
  border-top: none;
  gap: 0;
}

#portal-sidebar .sidebar-account-dock {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0.45rem;
  border-radius: 16px;
  border: 1px solid color-mix(in srgb, var(--portal-sidebar-border) 70%, rgba(var(--primary-rgb), 0.2));
  background:
    linear-gradient(165deg, rgba(255, 255, 255, 0.92) 0%, rgba(247, 251, 255, 0.78) 100%);
  box-shadow:
    0 10px 28px rgba(var(--primary-rgb), 0.1),
    0 0 0 1px rgba(255, 255, 255, 0.65) inset,
    0 1px 0 rgba(255, 255, 255, 0.9) inset;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

#portal-sidebar .sidebar-user-panel {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.4rem 0.45rem;
  border: none;
  border-radius: 14px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition:
    background var(--portal-sidebar-transition),
    transform var(--portal-sidebar-transition);
}

#portal-sidebar .sidebar-session-avatar-wrap {
  position: relative;
  width: 40px;
  height: 40px;
  min-width: 40px;
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.95),
    0 0 0 3px rgba(var(--primary-rgb), 0.18),
    0 6px 16px rgba(var(--primary-rgb), 0.28);
}

#portal-sidebar .sidebar-session-avatar-wrap::after {
  content: "";
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.35);
}

#portal-sidebar .sidebar-user-text {
  display: flex;
  flex-direction: column;
  gap: 0.06rem;
  flex: 1;
  min-width: 0;
}

#portal-sidebar .sidebar-user-eyebrow {
  font-size: 0.55rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--primary) 80%, var(--portal-sidebar-nav-text-muted));
}

#portal-sidebar .sidebar-user-text strong,
#portal-sidebar .sidebar-user-text #sidebar-session-display-name {
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--portal-sidebar-nav-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#portal-sidebar .sidebar-user-text span,
#portal-sidebar .sidebar-user-text #session-meta {
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.25;
  color: var(--portal-sidebar-nav-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#portal-sidebar .sidebar-account-divider {
  height: 1px;
  margin: 0.28rem 0.35rem;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(var(--primary-rgb), 0.18) 20%,
    rgba(var(--primary-rgb), 0.18) 80%,
    transparent
  );
}

#portal-sidebar .sidebar-user-panel:hover {
  background: rgba(var(--primary-rgb), 0.07);
  transform: translateY(-1px);
}

#portal-sidebar .sidebar-user-panel.active {
  background: rgba(var(--primary-rgb), 0.1);
}

#portal-sidebar .sidebar-user-panel:focus-visible {
  outline: 2px solid rgba(var(--primary-rgb), 0.45);
  outline-offset: 2px;
}

#portal-sidebar .sidebar-user-chevron {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  color: var(--portal-sidebar-nav-text-muted);
  background: rgba(var(--primary-rgb), 0.06);
  border: 1px solid rgba(var(--primary-rgb), 0.1);
  transition:
    background var(--portal-sidebar-transition),
    color var(--portal-sidebar-transition),
    transform var(--portal-sidebar-transition);
}

#portal-sidebar .sidebar-user-chevron svg {
  width: 15px;
  height: 15px;
}

#portal-sidebar .sidebar-user-panel:hover .sidebar-user-chevron {
  color: var(--primary);
  background: rgba(var(--primary-rgb), 0.12);
  border-color: rgba(var(--primary-rgb), 0.2);
  transform: translateX(2px);
}

#portal-sidebar .sidebar-account-toolbar {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  padding: 0 0.1rem 0.1rem;
}

/* Tema: solo iconos sol / luna */
#portal-sidebar .theme-toggle--portal-sidebar {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: 0.2rem;
  padding: 0.22rem;
  border-radius: 11px;
  background: rgba(var(--primary-rgb), 0.06);
  border: 1px solid rgba(var(--primary-rgb), 0.12);
  transform: none;
}

#portal-sidebar .theme-toggle--portal-sidebar .theme-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 8px;
  color: var(--portal-sidebar-nav-text-muted);
  transition:
    background var(--portal-sidebar-transition),
    color var(--portal-sidebar-transition),
    box-shadow var(--portal-sidebar-transition);
}

#portal-sidebar .theme-toggle--portal-sidebar .theme-option:hover {
  background: rgba(var(--primary-rgb), 0.1);
  color: var(--primary);
}

#portal-sidebar .theme-toggle--portal-sidebar .theme-option.active {
  background: linear-gradient(145deg, var(--primary) 0%, var(--primary-mid) 100%);
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(var(--primary-rgb), 0.3);
}

#portal-sidebar .sidebar-theme-option-icon {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

/* Cerrar sesión compacto */
#portal-sidebar .sidebar-logout-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  flex: 1;
  min-width: 0;
  min-height: 38px;
  padding: 0.38rem 0.55rem;
  border: 1px solid rgba(214, 40, 40, 0.22);
  border-radius: 11px;
  background: linear-gradient(
    180deg,
    rgba(254, 242, 242, 0.92) 0%,
    rgba(254, 226, 226, 0.82) 100%
  );
  color: #991b1b;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition:
    background var(--portal-sidebar-transition),
    border-color var(--portal-sidebar-transition),
    color var(--portal-sidebar-transition),
    box-shadow var(--portal-sidebar-transition);
}

#portal-sidebar .sidebar-logout-btn__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: rgba(214, 40, 40, 0.12);
  border: 1px solid rgba(214, 40, 40, 0.18);
  color: #dc2626;
  flex-shrink: 0;
  transition: background var(--portal-sidebar-transition);
}

#portal-sidebar .sidebar-logout-btn__icon svg {
  width: 15px;
  height: 15px;
}

#portal-sidebar .sidebar-logout-btn__label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

#portal-sidebar .sidebar-logout-btn:hover {
  background: linear-gradient(
    180deg,
    rgba(254, 226, 226, 1) 0%,
    rgba(252, 165, 165, 0.3) 100%
  );
  border-color: rgba(220, 38, 38, 0.32);
  color: #7f1d1d;
  box-shadow: 0 4px 12px rgba(214, 40, 40, 0.14);
}

#portal-sidebar .sidebar-logout-btn:hover .sidebar-logout-btn__icon {
  background: rgba(214, 40, 40, 0.18);
}

#portal-sidebar .sidebar-logout-btn:active {
  transform: translateY(0);
}

#portal-sidebar .sidebar-logout-btn:focus-visible {
  outline: 2px solid rgba(220, 38, 38, 0.45);
  outline-offset: 2px;
}

/* Colapsado */
body.portal-sidebar-collapsed #portal-sidebar .sidebar-account-dock {
  padding: 0.45rem 0.35rem;
  align-items: center;
}

body.portal-sidebar-collapsed #portal-sidebar .sidebar-user-panel {
  justify-content: center;
  padding: 0.4rem;
}

body.portal-sidebar-collapsed #portal-sidebar .sidebar-user-text,
body.portal-sidebar-collapsed #portal-sidebar .sidebar-user-chevron {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body.portal-sidebar-collapsed #portal-sidebar .sidebar-account-divider {
  width: 70%;
  margin: 0.3rem auto;
}

body.portal-sidebar-collapsed #portal-sidebar .sidebar-account-toolbar {
  flex-direction: column;
  width: 100%;
  padding: 0;
  gap: 0.32rem;
}

body.portal-sidebar-collapsed #portal-sidebar .theme-toggle--portal-sidebar {
  flex-direction: column;
  width: 100%;
  padding: 0.2rem;
}

body.portal-sidebar-collapsed #portal-sidebar .theme-toggle--portal-sidebar .theme-option {
  width: 100%;
  height: 32px;
  min-height: 32px;
}

body.portal-sidebar-collapsed #portal-sidebar .sidebar-logout-btn {
  justify-content: center;
  padding: 0.35rem;
  min-height: 36px;
  width: 100%;
}

body.portal-sidebar-collapsed #portal-sidebar .sidebar-logout-btn__label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

/* Dark */
body[data-theme="dark"] #portal-sidebar .sidebar-account-dock {
  background: linear-gradient(165deg, rgba(22, 38, 58, 0.95) 0%, rgba(15, 28, 44, 0.88) 100%);
  border-color: rgba(var(--primary-mid-rgb), 0.18);
  box-shadow:
    0 12px 32px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(255, 255, 255, 0.05) inset;
}

body[data-theme="dark"] #portal-sidebar .side-link {
  color: var(--portal-sidebar-nav-text);
}

body[data-theme="dark"] #portal-sidebar .side-link:hover {
  color: #f0f7ff;
}

body[data-theme="dark"] #portal-sidebar .side-link.active {
  color: var(--portal-sidebar-active-text);
}

body[data-theme="dark"] #portal-sidebar .sidebar-user-text strong,
body[data-theme="dark"] #portal-sidebar .sidebar-user-text #sidebar-session-display-name {
  color: #e8f2fc;
}

body[data-theme="dark"] #portal-sidebar .theme-toggle--portal-sidebar {
  background: rgba(0, 0, 0, 0.22);
  border-color: rgba(var(--primary-mid-rgb), 0.16);
}

body[data-theme="dark"] #portal-sidebar .theme-toggle--portal-sidebar .theme-option {
  color: #9fb8d4;
}

body[data-theme="dark"] #portal-sidebar .theme-toggle--portal-sidebar .theme-option.active {
  color: #ffffff;
}

body[data-theme="dark"] #portal-sidebar .sidebar-logout-btn {
  color: #fecaca;
  background: linear-gradient(
    180deg,
    rgba(127, 29, 29, 0.45) 0%,
    rgba(69, 10, 10, 0.55) 100%
  );
  border-color: rgba(248, 113, 113, 0.28);
}

body[data-theme="dark"] #portal-sidebar .sidebar-logout-btn__icon {
  background: rgba(214, 40, 40, 0.22);
  border-color: rgba(248, 113, 113, 0.3);
  color: #fca5a5;
}

body[data-theme="dark"] #portal-sidebar .sidebar-logout-btn:hover {
  color: #fff1f2;
  border-color: rgba(248, 113, 113, 0.45);
  background: linear-gradient(
    180deg,
    rgba(153, 27, 27, 0.65) 0%,
    rgba(127, 29, 29, 0.75) 100%
  );
}

/* ── Drawer móvil ── */
@media (max-width: 920px) {
  #portal-sidebar.sidebar--rail {
    padding: 1.1rem 0.9rem 1.25rem;
    border-radius: 0 24px 24px 0;
    box-shadow:
      20px 0 48px rgba(11, 33, 56, 0.2),
      1px 0 0 rgba(255, 255, 255, 0.5) inset;
  }

  #portal-sidebar .sidebar-rail-head {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
  }

  #portal-sidebar .sidebar-brand-block {
    width: 100%;
  }

  #portal-sidebar .sidebar-expand-toggle {
    display: none !important;
  }

  #portal-sidebar .sidebar-brand-logo-wrap {
    flex: 1;
    width: auto;
    min-width: 0;
    height: 58px;
    min-height: 58px;
    padding: 0.6rem 0.75rem;
  }

  #portal-sidebar .sidebar-brand-logo--full {
    display: block !important;
    max-height: 46px;
  }

  #portal-sidebar .sidebar-brand-logo--mark {
    display: none !important;
  }

  #portal-sidebar .sidebar-account-dock {
    padding: 0.55rem;
  }

  #portal-sidebar .sidebar-user-text strong,
  #portal-sidebar .sidebar-user-text #sidebar-session-display-name {
    font-size: 0.9rem;
  }

  #portal-sidebar .side-link {
    padding: 0.55rem 0.65rem;
    font-size: 0.9rem;
  }

  #portal-sidebar .side-link:hover {
    transform: translateX(3px);
  }

  #portal-sidebar .sidebar-drawer-tagline {
    display: block;
    margin: 0;
    padding: 0.35rem 0.55rem;
    font-size: 0.6rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: color-mix(in srgb, var(--primary) 70%, var(--portal-sidebar-link));
    background: linear-gradient(90deg, rgba(var(--primary-rgb), 0.1), transparent);
    border-radius: 8px;
    border-left: 3px solid var(--primary-mid);
  }
}

body[data-theme="dark"] #portal-sidebar .side-link.active {
  background: linear-gradient(
    95deg,
    rgba(var(--primary-mid-rgb), 0.18) 0%,
    rgba(var(--primary-rgb), 0.08) 58%,
    rgba(var(--primary-rgb), 0.04) 100%
  );
  border-color: rgba(var(--primary-mid-rgb), 0.28);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 4px 14px rgba(0, 0, 0, 0.2);
}

body[data-theme="dark"] #portal-sidebar .side-link__icon-wrap {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(var(--primary-mid-rgb), 0.14);
}

body[data-theme="dark"] #portal-sidebar .side-link:hover .side-link__icon-wrap {
  background: rgba(var(--primary-mid-rgb), 0.14);
  border-color: rgba(var(--primary-mid-rgb), 0.24);
}

body[data-theme="dark"] #portal-sidebar .sidebar-notif-hub {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(var(--primary-mid-rgb), 0.16);
}

body[data-theme="dark"] #portal-sidebar .sidebar-notif-hub:has(.side-link--notif-inbox.active) {
  background: rgba(var(--primary-mid-rgb), 0.12);
  border-color: rgba(var(--primary-mid-rgb), 0.24);
}

body[data-theme="dark"] #portal-sidebar .sidebar-notif-hub .sidebar-notif-bell-toggle {
  background: transparent;
  border: none;
  color: rgba(232, 242, 252, 0.9);
}

body[data-theme="dark"] #portal-sidebar .sidebar-notif-hub .sidebar-notif-bell-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
}

body[data-theme="dark"] #portal-sidebar .sidebar-notif-bell-toggle {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(var(--primary-mid-rgb), 0.14);
}

body[data-theme="dark"] #portal-sidebar .sidebar-brand-logo-wrap {
  background: linear-gradient(
    128deg,
    #050d18 0%,
    #0c1e34 40%,
    #163a5e 78%,
    #245f96 100%
  );
  box-shadow:
    0 12px 30px rgba(0, 0, 0, 0.42),
    0 0 0 1px rgba(var(--primary-mid-rgb), 0.22) inset,
    0 0 0 1px rgba(var(--primary-mid-rgb), 0.16),
    0 0 28px rgba(var(--primary-mid-rgb), 0.18);
}

body[data-theme="dark"] #portal-sidebar .sidebar-brand-logo--full,
body[data-theme="dark"] #portal-sidebar .sidebar-brand-logo--mark {
  filter:
    contrast(1.36)
    saturate(1.24)
    brightness(1.16)
    drop-shadow(0 3px 12px rgba(0, 0, 0, 0.55))
    drop-shadow(0 0 20px rgba(184, 228, 255, 0.42))
    drop-shadow(0 0 34px rgba(var(--primary-mid-rgb), 0.36));
}

body[data-theme="dark"] #portal-sidebar.sidebar--rail {
  box-shadow:
    1px 0 0 rgba(255, 255, 255, 0.04) inset,
    4px 0 28px rgba(0, 0, 0, 0.28);
}

/* Drawer móvil (≤920px): hub de notificaciones a ancho completo */
@media (max-width: 920px) {
  #portal-sidebar .sidebar-notif-group,
  #portal-sidebar .sidebar-notif-hub {
    width: 100%;
    min-width: 0;
  }

  #portal-sidebar .sidebar-notif-hub {
    flex-direction: row !important;
  }

  #portal-sidebar .sidebar-notif-hub .side-link--notif-inbox {
    min-height: 44px;
    padding: 0.55rem 0.5rem 0.55rem 0.65rem !important;
    gap: 0.6rem;
  }

  #portal-sidebar .sidebar-notif-hub .sidebar-notif-bell-toggle {
    width: 2.85rem !important;
    min-width: 2.85rem !important;
    max-width: 2.85rem;
    min-height: 44px;
  }

  #portal-sidebar .side-link--notif-inbox .side-link__label {
    position: static;
    width: auto;
    height: auto;
    padding: 0;
    margin: 0;
    overflow: hidden;
    clip: auto;
    white-space: nowrap;
    text-overflow: ellipsis;
    border: 0;
    flex: 1;
    min-width: 0;
  }

  body.portal-drawer-open.portal-sidebar-collapsed #portal-sidebar .sidebar-notif-hub {
    flex-direction: row !important;
  }

  body.portal-drawer-open #portal-sidebar .sidebar-rail-scroll {
    padding-right: 0.65rem;
  }

  /* Cuando el drawer móvil está abierto y el sidebar estaba colapsado (estado persistido),
     restaurar el layout expandido para que todos los ítems muestren ícono + etiqueta. */
  body.portal-drawer-open.portal-sidebar-collapsed #portal-sidebar .side-link {
    justify-content: flex-start;
    gap: 0.72rem;
    padding: 0.55rem 0.65rem;
  }

  body.portal-drawer-open.portal-sidebar-collapsed #portal-sidebar .side-link__label {
    position: static;
    width: auto;
    height: auto;
    padding: 0;
    margin: 0;
    overflow: hidden;
    clip: auto;
    white-space: nowrap;
    text-overflow: ellipsis;
    border: 0;
    flex: 1;
    min-width: 0;
  }

  body.portal-drawer-open.portal-sidebar-collapsed #portal-sidebar .sidebar-section-label {
    display: flex;
  }

  body.portal-drawer-open.portal-sidebar-collapsed #portal-sidebar .sidebar-user-text,
  body.portal-drawer-open.portal-sidebar-collapsed #portal-sidebar .sidebar-user-chevron {
    position: static;
    width: auto;
    height: auto;
    padding: 0;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
    border: 0;
  }

  body.portal-drawer-open.portal-sidebar-collapsed #portal-sidebar .sidebar-account-divider {
    display: block;
    width: auto;
    margin: 0.28rem 0.35rem;
  }

  body.portal-drawer-open.portal-sidebar-collapsed #portal-sidebar .sidebar-logout-btn__label {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  body.portal-drawer-open.portal-sidebar-collapsed #portal-sidebar .side-link:hover {
    transform: translateX(3px);
  }
}

@media (prefers-reduced-motion: reduce) {
  #portal-sidebar .side-link,
  #portal-sidebar .side-link__icon-wrap,
  #portal-sidebar .sidebar-notif-bell-toggle,
  #portal-sidebar .sidebar-user-panel,
  #portal-sidebar .sidebar-logout-btn,
  #portal-sidebar .sidebar-brand-logo-wrap,
  #portal-sidebar .sidebar-expand-toggle,
  #portal-sidebar .sidebar-brand-logo {
    transition: none !important;
  }

  #portal-sidebar .side-link:hover,
  #portal-sidebar .sidebar-brand-logo-wrap:hover,
  #portal-sidebar .sidebar-brand-logo-wrap:hover .sidebar-brand-logo--full,
  #portal-sidebar .sidebar-brand-logo-wrap:hover .sidebar-brand-logo--mark {
    transform: none;
  }
}
