/**
 * Sophia STARS — application chrome (roadmap Phase 1, §1.1 / §1.2)
 *
 * Header, sidebar, footer, and the layout offsets that depend on them.
 * This is the ONLY file in the new architecture allowed !important —
 * chrome genuinely does need to win against page content, but that
 * privilege stays contained to one file instead of being sprinkled
 * across a dozen "polish"/"sweep" files, which is exactly what caused
 * four separate specificity bugs in one July session (see the table in
 * the roadmap doc).
 *
 * Fixed chrome contract (§1.2): header height and sidebar widths are
 * DECLARED in tokens.css, not measured at runtime. The old approach
 * (js/enhanced-ui-components.js measuring the header's live
 * getBoundingClientRect() on every load + resize, because sidebar-
 * navigation.css said 64px while professional-header-footer.css said
 * 88px !important) is why the header/house-points gap bug took multiple
 * rounds to pin down. One number, declared once, used everywhere.
 */

/* ===== HEADER ===== */
.page-header,
.enhanced-header-2026 {
  position: fixed;
  inset: 0 0 auto 0;
  left: var(--sidebar-width);
  width: calc(100% - var(--sidebar-width));
  height: var(--header-height);
  z-index: var(--z-chrome);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: 0 var(--sp-6);
  margin: 0;
  background: linear-gradient(135deg, var(--navy-900) 0%, var(--navy-800) 60%, var(--navy-900) 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: var(--sh-md);
  color: #fff;
  transition: left var(--dur-base) var(--ease-out), width var(--dur-base) var(--ease-out);
}

body.sidebar-collapsed .page-header {
  left: var(--sidebar-width-collapsed);
  width: calc(100% - var(--sidebar-width-collapsed));
}

.page-header-left,
.page-header-right {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  min-width: 0;
}

.page-crest,
.enhanced-logo {
  width: 40px;
  height: 40px;
  border-radius: var(--r-sm);
  object-fit: contain;
}

.page-title,
.enhanced-title {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 700;
  color: #fff;
  line-height: 1.1;
}

.page-subtitle,
.enhanced-subtitle {
  display: block;
  font-size: var(--fs-xs);
  color: rgba(255, 255, 255, 0.65);
  font-weight: 500;
}

.welcome-message {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: var(--fs-sm);
  line-height: 1.2;
}
.welcome-text {
  color: rgba(255, 255, 255, 0.6);
  font-size: var(--fs-xs);
}
.welcome-name {
  color: #fff;
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.header-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out);
}
.header-action-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}
.header-action-btn .action-icon svg {
  width: 20px;
  height: 20px;
}

/* Decorative header layers some pages include — kept inert/behind content */
.header-background-effects {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: var(--z-behind);
}

/* ===== SIDEBAR =====
   Width is a literal value here, deliberately NOT var(--sidebar-width):
   js/enhanced-ui-components.js's getSidebarLayoutWidth() measures this
   element's rendered width via getComputedStyle and writes that back
   into --sidebar-width (as an inline style on <html>, which then beats
   tokens.css's :root declaration) so the header/main-content offsets can
   track it. If the sidebar's own width were also driven by that same
   variable, a bad first measurement (e.g. the sidebar not existing yet
   at the moment that JS runs, since it's injected dynamically) gets
   baked in permanently — the sidebar, main-content, header and footer
   all collapse to 0. Keeping the sidebar's own size as a plain literal
   breaks that circular dependency; --sidebar-width stays correct for
   everything that only *depends on* the sidebar rather than *being* it.

   Deliberately .sidebar only, NOT also #sidebar: the collapse toggle
   (js/enhanced-ui-components.js) sets body.sidebar-collapsed and toggles
   width via a class selector below. An ID selector on this same rule
   would give the base 220px an ID's specificity, which always beats a
   class-based override regardless of source order — the collapse click
   handler would keep firing and toggling the classes correctly, but the
   width would never actually change. (This is exactly what happened
   before this comment was added.) */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 220px;
  z-index: var(--z-drawer);
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--navy-900) 0%, var(--navy-800) 100%);
  color: #fff;
  transition: width var(--dur-base) var(--ease-out);
  overflow-y: auto;
}
body.sidebar-collapsed .sidebar {
  width: 60px;
}

/* Sidebar's own logo/branding header — actual markup is generated by
   js/enhanced-ui-components.js SidebarNavigation.generateHTML(); wasn't
   read closely enough on the first pass through this file, which is why
   it rendered unstyled (missing entirely from this stylesheet). */
.sidebar-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-5) var(--sp-4) var(--sp-4);
  position: relative;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.sidebar-logo-container {
  position: relative;
  width: 48px;
  height: 48px;
}
.sidebar-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  display: block;
  position: relative;
  z-index: var(--z-raised); /* the glow div comes after it in DOM order */
}
.sidebar-logo-glow {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(201, 148, 44, 0.35), transparent 70%);
  z-index: var(--z-behind);
}
.sidebar-title {
  font-size: var(--fs-lg);
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #fff;
}
.sidebar-title-accent {
  width: 32px;
  height: 3px;
  border-radius: var(--r-full);
  background: linear-gradient(90deg, var(--gold-400), transparent);
}

.sidebar-nav {
  list-style: none;
  margin: 0;
  padding: var(--sp-3) 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.sidebar-nav a,
.nav-item,
.nav-item-enhanced {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  color: rgba(255, 255, 255, 0.75);
  text-decoration: none;
  font-size: var(--fs-sm);
  font-weight: 500;
  border-left: 3px solid transparent;
  position: relative;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.sidebar-nav a:hover,
.nav-item:hover,
.nav-item-enhanced:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}
.sidebar-nav a.active,
.nav-item.active,
.nav-item-enhanced.active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-left-color: var(--gold-400);
}
/* Every icon in the sidebar (nav rows, staff avatar) is an inline <svg
   viewBox="0 0 24 24"> with no width/height attribute — unsized like
   this, a browser renders it at the default replaced-element size
   (300x150), the same bug class as the oversized Recognitions star icon
   fixed earlier. Size every icon slot explicitly rather than trusting
   markup to always carry a size. */
.nav-icon svg,
.header-action-btn svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.nav-label {
  flex: 1;
  min-width: 0;
}
.admin-indicator {
  color: var(--gold-400);
  font-size: var(--fs-xs);
}

/* Staff profile + logout, at the bottom of the sidebar nav list */
.sidebar-footer {
  margin-top: auto;
  padding: var(--sp-4);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.staff-profile {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.staff-avatar-container {
  position: relative;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}
.staff-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.85);
}
.staff-avatar svg {
  width: 20px;
  height: 20px;
}
.avatar-status-indicator {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ok-500);
  border: 2px solid var(--navy-900);
}
.staff-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.staff-name-sidebar {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.staff-role {
  font-size: var(--fs-xs);
  color: rgba(255, 255, 255, 0.55);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-logout {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.85);
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
}
.sidebar-logout:hover {
  background: rgba(239, 68, 68, 0.18);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fff;
}
.sidebar-logout svg {
  width: 18px;
  height: 18px;
}

.sidebar-toggle-btn-internal {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  width: 100%;
  padding: var(--sp-2);
  border-radius: var(--r-md);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: transparent;
  color: rgba(255, 255, 255, 0.6);
  font-size: var(--fs-xs);
  cursor: pointer;
}
.sidebar-toggle-btn-internal:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.sidebar-background-effects {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: var(--z-behind);
}

/* Collapsed state (60px, icon-only): hide every text label rather than
   letting it wrap/overlap in a column too narrow for it. Icons/avatar
   stay centered; text-bearing elements are display:none, not just
   visually hidden, so they don't reserve layout space. */
body.sidebar-collapsed .sidebar-title,
body.sidebar-collapsed .sidebar-title-accent,
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .admin-indicator,
body.sidebar-collapsed .staff-info,
body.sidebar-collapsed .sidebar-logout .nav-label,
body.sidebar-collapsed .toggle-text {
  display: none;
}
body.sidebar-collapsed .sidebar-header {
  padding: var(--sp-4) var(--sp-2);
}
body.sidebar-collapsed .sidebar-nav a,
body.sidebar-collapsed .nav-item,
body.sidebar-collapsed .nav-item-enhanced {
  justify-content: center;
  padding: var(--sp-3);
}
body.sidebar-collapsed .staff-profile {
  justify-content: center;
}
body.sidebar-collapsed .sidebar-logout {
  justify-content: center;
}

/* Mobile drawer toggle/close — only meaningful below the mobile
   breakpoint (the sidebar is permanently visible above it), so both
   must stay fully hidden on desktop. This exact shape — a plain class
   selector's `display: none !important` losing to a broader element
   selector elsewhere — is what caused the sidebar-toggle-leaking-onto-
   desktop bug; scoping strictly by breakpoint here prevents a repeat. */
.sidebar-mobile-toggle,
.sidebar-mobile-close {
  display: none !important;
}
@media (max-width: 768px) {
  .sidebar-mobile-toggle,
  .sidebar-mobile-close {
    display: inline-flex !important;
  }
}

/* ===== MAIN CONTENT OFFSET ===== */
.main-content {
  margin-left: var(--sidebar-width);
  margin-top: var(--header-height);
  min-height: calc(100vh - var(--header-height));
  padding: var(--sp-6);
  transition: margin-left var(--dur-base) var(--ease-out);
}
body.sidebar-collapsed .main-content {
  margin-left: var(--sidebar-width-collapsed);
}

/* ===== FOOTER =====
   Real markup (js/enhanced-ui-components.js EnhancedFooter.generateHTML)
   has a logo/brand block, a quick-links grid, a powered-by grid, and a
   credits row. footer-logo is a plain <img> with no width/height, which
   is why it rendered at its raw file size (huge) before this was added.
   Second pass: a dark navy theme matched the header/sidebar in
   isolation, but created a hard seam against the light page background
   it actually sits below/beside in normal scrolling. Matches the page
   background now instead, with a top border for separation, and is
   generally smaller (tighter padding/type) than either previous pass. */
.enhanced-app-footer-2026,
.app-footer {
  margin-left: var(--sidebar-width);
  background: var(--bg);
  border-top: 1px solid var(--border);
  color: var(--text-2);
}
body.sidebar-collapsed .enhanced-app-footer-2026,
body.sidebar-collapsed .app-footer {
  margin-left: var(--sidebar-width-collapsed);
}

.footer-content-wrapper {
  padding: var(--sp-4) var(--sp-6);
  max-width: 1200px;
  margin: 0 auto;
}

.footer-top-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-5);
  align-items: flex-start;
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--border);
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex: 0 0 auto;
}
.footer-logo {
  width: 30px;
  height: 30px;
  object-fit: contain;
  flex-shrink: 0;
}
.footer-title {
  margin: 0;
  font-size: var(--fs-sm);
  font-weight: 800;
  color: var(--text);
}
.footer-subtitle {
  margin: 0;
  font-size: var(--fs-xs);
  color: var(--text-2);
}
.footer-version {
  display: inline-block;
  margin-top: 0.3rem;
  padding: 0.1rem 0.5rem;
  border: 1px solid rgba(201, 148, 44, 0.35);
  border-radius: var(--r-full);
  background: rgba(201, 148, 44, 0.08);
  font-size: var(--fs-xs);
  color: var(--gold-500);
}

.footer-links {
  flex: 1 1 320px;
}
.footer-section-title {
  margin: 0 0 0.3rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-2);
}
.footer-links-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem var(--sp-4);
}
.footer-link {
  font-size: var(--fs-xs);
  color: var(--text-2);
  text-decoration: none;
  white-space: nowrap;
}
.footer-link:hover {
  color: var(--blue-500);
  text-decoration: underline;
}

.footer-tech {
  flex: 0 0 auto;
}
.footer-tech-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem var(--sp-4);
}
.tech-item {
  font-size: var(--fs-xs);
  color: var(--text-2);
  white-space: nowrap;
}

.footer-bottom-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1) var(--sp-5);
  justify-content: space-between;
  padding-top: var(--sp-2);
  font-size: 0.7rem;
  color: var(--text-2);
}
.footer-bottom-row p,
.footer-copyright,
.footer-developer {
  margin: 0;
  max-width: none;
  font-size: 0.7rem;
}
.footer-dev-link {
  color: var(--text-2);
  text-decoration: underline;
}
.footer-dev-link:hover {
  color: var(--blue-500);
}

@media (max-width: 768px) {
  .footer-bottom-row {
    justify-content: center;
    text-align: center;
  }
}

@media (max-width: 768px) {
  .footer-top-row {
    flex-direction: column;
    gap: var(--sp-5);
  }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .page-header {
    left: 0;
    width: 100%;
    padding: 0 var(--sp-4);
  }
  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--sh-lg);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content,
  .enhanced-app-footer-2026,
  .app-footer {
    margin-left: 0;
  }
  .welcome-message {
    display: none;
  }
}
