/* ==========================================================================
   WISDOM GROUP — UNIFIED ADMIN PANEL
   Accordion sidebar + portal rail for the single /admin experience.
   Inherits the "Porcelain" tokens from admin-redesign.css; fallbacks keep
   it coherent if loaded standalone. Signature: one quiet indigo accent.
   ========================================================================== */

html.wg-unified {
  --wg-u-primary: var(--wg-primary, #4f46e5);
  --wg-u-primary-deep: var(--wg-primary-deep, #4338ca);
  --wg-u-tint: var(--wg-primary-tint, #eef1fe);
  --wg-u-ring: var(--wg-primary-ring, rgba(79, 70, 229, 0.16));
  --wg-u-surface: var(--wg-surface, #ffffff);
  --wg-u-soft: var(--wg-surface-soft, #f7f9fd);
  --wg-u-canvas: var(--wg-canvas, #f4f6fb);
  --wg-u-line: var(--wg-line, #e7eaf3);
  --wg-u-ink: var(--wg-ink, #101828);
  --wg-u-body: var(--wg-body, #3e4a61);
  --wg-u-muted: var(--wg-muted, #67718a);
  --wg-u-faint: var(--wg-faint, #8b95ad);
  --wg-u-radius: var(--wg-radius-sm, 10px);
}

/* --------------------------------------------------------------------------
   1. HIDE ORIGINAL NAVIGATION (React owns those nodes — attribute selectors
      survive className churn; our injected root is excluded).
   -------------------------------------------------------------------------- */
aside[data-wg-unified] > div:not(.wg-unified-nav),
aside[data-wg-unified] > nav {
  display: none !important;
}

/* Academy mobile drawer: keep the head (close button), hide the module list */
[data-wg-drawer-panel] {
  width: 280px !important;
  background: var(--wg-u-surface) !important;
  border-right: 1px solid var(--wg-u-line);
}
[data-wg-drawer-panel] > div:nth-child(2) {
  display: none !important;
}
[data-wg-drawer-panel] > div:first-child {
  border-color: var(--wg-u-line) !important;
  color: var(--wg-u-ink) !important;
}
[data-wg-drawer-panel] > div:first-child span { color: var(--wg-u-muted); }
[data-wg-drawer-panel] > div:first-child button { color: var(--wg-u-muted); }

/* responsive-enhancements.css centers EVERY fixed.inset-0.z-50 overlay (it is
   meant for form dialogs). The Academy mobile drawer is a LEFT slide-in nav,
   not a centered modal — restore left alignment. Higher specificity than
   div[class*="fixed inset-0"][class*="z-50"] so this wins despite !important. */
div.fixed.inset-0[data-wg-drawer] {
  padding: 0 !important;
  display: flex !important;
  align-items: stretch !important;
  justify-content: flex-start !important;
  overflow: hidden !important;
}

/* --------------------------------------------------------------------------
   2. NAV ROOT
   -------------------------------------------------------------------------- */
.wg-unified-nav {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  background: var(--wg-u-surface);
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.wg-nav-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 8px;
}
.wg-nav-title {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--wg-u-faint);
}
.wg-nav-collapse {
  border: none;
  background: transparent;
  color: var(--wg-u-faint);
  width: 26px;
  height: 26px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: background 0.15s ease, color 0.15s ease;
}
.wg-nav-collapse:hover { background: var(--wg-u-soft); color: var(--wg-u-ink); }

.wg-nav-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--wg-u-line) transparent;
}
.wg-nav-body::-webkit-scrollbar { width: 5px; }
.wg-nav-body::-webkit-scrollbar-track { background: transparent; }
.wg-nav-body::-webkit-scrollbar-thumb {
  background: var(--wg-u-line);
  border-radius: 99px;
}
.wg-nav-body::-webkit-scrollbar-thumb:hover { background: #c9d0e0; }

/* --------------------------------------------------------------------------
   3. GROUPS & LEAVES — the accordion
   -------------------------------------------------------------------------- */
.wg-nav-group { display: block; }

.wg-nav-group-btn,
.wg-nav-leaf {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  background: transparent;
  text-align: left;
  padding: 9px 12px;
  border-radius: var(--wg-u-radius);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--wg-u-body);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.wg-nav-group-btn { font-weight: 700; }
.wg-nav-group-btn:hover,
.wg-nav-leaf:hover {
  background: var(--wg-u-soft);
  color: var(--wg-u-ink);
}

.wg-nav-ico {
  width: 18px;
  flex: 0 0 18px;
  text-align: center;
  font-size: 13px;
  color: var(--wg-u-faint);
  transition: color 0.15s ease;
}
.wg-nav-group-btn:hover .wg-nav-ico,
.wg-nav-leaf:hover .wg-nav-ico { color: var(--wg-u-muted); }

.wg-nav-label {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wg-nav-chev {
  font-size: 9px;
  color: var(--wg-u-faint);
  transition: transform 0.22s ease;
}
.wg-nav-group.wg-open > .wg-nav-group-btn .wg-nav-chev { transform: rotate(90deg); }
.wg-nav-group.wg-open > .wg-nav-group-btn { color: var(--wg-u-ink); }
.wg-nav-group.wg-open > .wg-nav-group-btn .wg-nav-ico { color: var(--wg-u-primary); }

.wg-nav-sub {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.26s ease;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 0;
}
.wg-nav-group.wg-open > .wg-nav-sub { padding: 2px 0 4px; }

.wg-nav-leaf-sub { padding-left: 40px; font-weight: 500; color: var(--wg-u-muted); }
.wg-nav-leaf-sub .wg-nav-ico { font-size: 11px; width: 14px; flex-basis: 14px; }

/* Active leaf — the single indigo accent */
.wg-nav-leaf.wg-active {
  background: var(--wg-u-tint);
  color: var(--wg-u-primary-deep);
  font-weight: 700;
}
.wg-nav-leaf.wg-active .wg-nav-ico { color: var(--wg-u-primary); }
.wg-nav-leaf.wg-active:hover { background: var(--wg-u-tint); }

/* --------------------------------------------------------------------------
   4. FOOTER — user chip + sign out
   -------------------------------------------------------------------------- */
.wg-nav-foot {
  flex: 0 0 auto;
  border-top: 1px solid var(--wg-u-line);
  padding: 10px 12px;
}
.wg-nav-user { display: flex; align-items: center; gap: 9px; }
.wg-nav-avatar {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 10px;
  background: var(--wg-u-primary);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px -2px var(--wg-u-ring);
}
.wg-nav-user-meta { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.wg-nav-user-name {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--wg-u-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wg-nav-user-role {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--wg-u-faint);
}
.wg-nav-signout {
  border: none;
  background: transparent;
  color: var(--wg-u-faint);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}
.wg-nav-signout:hover { background: #fdeef1; color: #e11d48; }

/* --------------------------------------------------------------------------
   5. ICON RAIL (collapsed aside, w-16)
   -------------------------------------------------------------------------- */
aside[data-wg-unified].w-16 .wg-nav-label,
aside[data-wg-unified].w-16 .wg-nav-chev,
aside[data-wg-unified].w-16 .wg-nav-title,
aside[data-wg-unified].w-16 .wg-nav-sub,
aside[data-wg-unified].w-16 .wg-nav-user-meta,
aside[data-wg-unified].w-16 .wg-nav-signout { display: none; }

aside[data-wg-unified].w-16 .wg-nav-head { justify-content: center; padding: 12px 6px 6px; }
aside[data-wg-unified].w-16 .wg-nav-body { padding: 4px 8px 10px; }
aside[data-wg-unified].w-16 .wg-nav-group-btn,
aside[data-wg-unified].w-16 .wg-nav-leaf { justify-content: center; padding: 10px 0; }
aside[data-wg-unified].w-16 .wg-nav-ico { width: auto; flex-basis: auto; font-size: 14px; }
aside[data-wg-unified].w-16 .wg-nav-foot { padding: 10px 8px; }
aside[data-wg-unified].w-16 .wg-nav-user { justify-content: center; }

/* --------------------------------------------------------------------------
   6. PORTAL SHELL — fixed left rail for student / parent / customer views
   -------------------------------------------------------------------------- */
.wg-unified-rail {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 264px;
  z-index: 45;
  display: flex;
  flex-direction: column;
  background: var(--wg-u-surface);
  border-right: 1px solid var(--wg-u-line);
  box-shadow: 0 0 24px -12px rgba(16, 24, 40, 0.12);
}
.wg-rail-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--wg-u-line);
}
.wg-rail-logo { height: 30px; width: auto; object-fit: contain; }
.wg-rail-title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--wg-u-ink);
}
.wg-unified-rail .wg-unified-nav { min-height: 0; }

/* Unified chrome over the portal content */
html.wg-unified-portal body { background: var(--wg-u-canvas); }
html.wg-unified-portal header.wg-header-outer { display: none !important; }
html.wg-unified-portal #root main.flex-1 { padding-top: 8px; }

/* Portal role tabs pick up the indigo accent (theme identity) */
html.wg-unified-portal button.bg-slate-900 {
  background: var(--wg-u-primary) !important;
  color: #fff !important;
}

@media (min-width: 1024px) {
  html.wg-unified-portal #root main.flex-1 { margin-left: 264px; transition: margin-left 0.22s ease; }
  .wg-unified-menu-btn { display: none !important; }

  /* Desktop collapse: icon-only rail (persisted in localStorage). The old
     toggle only flipped the mobile off-canvas class, so it did nothing here. */
  .wg-unified-rail { transition: width 0.22s ease; }
  html.wg-rail-collapsed .wg-unified-rail { width: 76px; }
  html.wg-rail-collapsed .wg-rail-title,
  html.wg-rail-collapsed .wg-nav-label,
  html.wg-rail-collapsed .wg-nav-title,
  html.wg-rail-collapsed .wg-nav-user-meta,
  html.wg-rail-collapsed .wg-nav-signout { display: none; }
  html.wg-rail-collapsed .wg-rail-brand { justify-content: center; padding: 16px 8px 12px; }
  html.wg-rail-collapsed .wg-nav-head { justify-content: center; padding: 12px 6px 6px; }
  html.wg-rail-collapsed .wg-nav-body { padding: 4px 8px 10px; }
  html.wg-rail-collapsed .wg-nav-leaf { justify-content: center; padding: 10px 0; }
  html.wg-rail-collapsed .wg-nav-ico { width: auto; flex-basis: auto; font-size: 15px; }
  html.wg-rail-collapsed .wg-nav-foot { padding: 10px 8px; }
  html.wg-rail-collapsed .wg-nav-user { justify-content: center; }
  html.wg-rail-collapsed.wg-unified-portal #root main.flex-1 { margin-left: 76px; }
}

/* Portal topbar (injected by portal-redesign.js) replaces the floating menu
   button — cancel its reserved offsets so the bar sits flush at the top. */
html.wg-pr-topbar.wg-unified-portal #root main.flex-1 { padding-top: 0 !important; }
html.wg-pr-topbar .wg-unified-menu-btn { display: none !important; }

/* Visit Website leaf pins to the bottom of the nav body */
.wg-nav-leaf[data-item="visit-website"] { margin-top: auto; color: var(--wg-u-primary-deep); }
.wg-nav-leaf[data-item="visit-website"] .wg-nav-ico { color: var(--wg-u-primary); }
.wg-nav-leaf[data-item="visit-website"]:hover { background: var(--wg-u-tint); color: var(--wg-u-primary-deep); }

@media (max-width: 1023.98px) {
  .wg-unified-rail {
    transform: translateX(-100%);
    transition: transform 0.24s ease;
  }
  html.wg-rail-open .wg-unified-rail { transform: translateX(0); }
  html.wg-unified-portal #root main.flex-1 { padding-top: 56px; }
  /* Academy has no mobile icon rail (aside is hidden lg:flex; nav lives in the
     drawer), so cancel the 64px CMS rail offset the unified scope adds. */
  html.wg-unified-academy main.overflow-y-auto { margin-left: 0 !important; }
}

.wg-unified-menu-btn {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 46;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid var(--wg-u-line);
  background: var(--wg-u-surface);
  color: var(--wg-u-ink);
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px -4px rgba(16, 24, 40, 0.14);
}

.wg-unified-scrim {
  position: fixed;
  inset: 0;
  z-index: 44;
  background: rgba(15, 23, 42, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}
.wg-unified-scrim.active { opacity: 1; pointer-events: auto; }

/* --------------------------------------------------------------------------
   7. ROLE-AWARE HEADER CLEANUP
   -------------------------------------------------------------------------- */
/* "Main WordPress CMS" shortcut is redundant for roles without CMS access */
html[data-wg-cms="0"] header a[href="/admin"] { display: none !important; }

/* The public website footer must never appear inside the unified panel. The
   SPA only suppresses it for internal /admin and /academy/cms; the role portal
   (/portal) still renders it. Inside the 100vh overflow-hidden viewport lock
   that tall footer squeezes/clips the dashboard (worst on mobile), so hide it
   in every unified mode and let the portal content pane scroll instead. */
html.wg-unified-cms .wg-footer-outer,
html.wg-unified-academy .wg-footer-outer,
html.wg-unified-portal .wg-footer-outer { display: none !important; }

html.wg-unified-portal #root main.flex-1 { overflow-y: auto; }

/* Portal scroll area carries the same quiet scrollbar as the nav */
html.wg-unified-portal #root main.flex-1 { scrollbar-width: thin; scrollbar-color: #c9d0e0 transparent; }
html.wg-unified-portal #root main.flex-1::-webkit-scrollbar { width: 6px; }
html.wg-unified-portal #root main.flex-1::-webkit-scrollbar-track { background: transparent; }
html.wg-unified-portal #root main.flex-1::-webkit-scrollbar-thumb { background: var(--wg-u-line); border-radius: 99px; }
html.wg-unified-portal #root main.flex-1::-webkit-scrollbar-thumb:hover { background: #b6bfd4; }

/* --------------------------------------------------------------------------
   8. ACCESSIBILITY & MOTION
   -------------------------------------------------------------------------- */
.wg-unified-nav button:focus-visible,
.wg-unified-menu-btn:focus-visible {
  outline: 2px solid var(--wg-u-primary);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .wg-nav-sub,
  .wg-nav-chev,
  .wg-unified-rail,
  .wg-unified-scrim,
  .wg-nav-group-btn,
  .wg-nav-leaf,
  html.wg-unified-portal #root main.flex-1 { transition: none !important; }
}