/* ============================================================
   App Shell (Phase 6.0) — layout layer for templates/base_shell.html
   Ported from the app.plor.us template contract (_TEMP/layout-integration-handoff.md §2),
   restyled to Summit Guardian tokens (variables.css).

   Loaded INSTEAD of layout.css — base_shell.html documents must never
   include both (class names overlap by design: same contract, new chrome).

   IA: LEFT rail = top-level modules · RIGHT sub-nav = active module's
   sub-items · CENTER = breadcrumb + tabbed content.
   ============================================================ */

:root {
  /* Template contract widths: 240px expanded / 70px collapsed */
  --shell-sidebar-expanded: 240px;
  --shell-sidebar-collapsed: 70px;
  --shell-rightsubnav-expanded: 240px;
  --shell-rightsubnav-collapsed: 56px;

  /* Glassmorphism (Richard, 2026-07-08): frosted chrome in SG's palette */
  --shell-glass-bg: rgba(255, 255, 255, 0.62);
  --shell-glass-border: rgba(255, 255, 255, 0.45);
  --shell-glass-blur: 14px;
}

html.dark {
  --shell-glass-bg: rgba(24, 24, 26, 0.55);
  --shell-glass-border: rgba(255, 255, 255, 0.08);
}

/* ==================== APP GRID ==================== */
.app-container.layout-page {
  display: grid;
  grid-template-areas:
    "sidebar header"
    "sidebar main"
    "sidebar footer";
  grid-template-rows: var(--header-height) 1fr auto;
  grid-template-columns: var(--shell-sidebar-collapsed) 1fr;
  min-height: 100vh;
  /* Faint brand-tinted washes so the frosted chrome reads as glass */
  background:
    radial-gradient(1200px 600px at 85% -10%, var(--vp-c-brand-soft), transparent 60%),
    radial-gradient(900px 500px at -10% 100%, var(--vp-c-brand-soft), transparent 55%),
    var(--vp-c-bg);
  background-attachment: fixed;
  transition: grid-template-columns var(--transition-medium);
}

.app-container.layout-page.sidebar-expanded {
  grid-template-columns: var(--shell-sidebar-expanded) 1fr;
}

.app-container.layout-page.has-rightsubnav {
  grid-template-areas:
    "sidebar header header"
    "sidebar main rightsubnav"
    "sidebar footer rightsubnav";
  grid-template-columns: var(--shell-sidebar-collapsed) 1fr var(--shell-rightsubnav-expanded);
}

.app-container.layout-page.has-rightsubnav.sidebar-expanded {
  grid-template-columns: var(--shell-sidebar-expanded) 1fr var(--shell-rightsubnav-expanded);
}

.app-container.layout-page.has-rightsubnav.rsn-collapsed {
  grid-template-columns: var(--shell-sidebar-collapsed) 1fr var(--shell-rightsubnav-collapsed);
}

.app-container.layout-page.has-rightsubnav.sidebar-expanded.rsn-collapsed {
  grid-template-columns: var(--shell-sidebar-expanded) 1fr var(--shell-rightsubnav-collapsed);
}

/* ==================== FIXED BACKGROUND WATERMARK ==================== */
/* Sits above the container's wash gradients, below all content (which is
   lifted to z-index 1 where not already positioned). The glass rails'
   backdrop-filter picks it up, so the frosted chrome reads as real glass. */
.app-background {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: url('/static/images/app-bg-bear.png') center / contain no-repeat;
  opacity: 0.06;
}

/* Bear mark is pure black; invert to a light silhouette so it reads on the dark bg. */
html.dark .app-background { opacity: 0.08; filter: invert(1); }

/* Prominent full-bleed variant for hero-style sections (e.g. /auth/login):
   full-strength image scoped to the section + a scrim for contrast.
   Children are lifted above the two pseudo-element layers. */
.app-hero {
  position: relative;
  isolation: isolate;
}

.app-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  /* attachment:fixed sizes/positions the image against the VIEWPORT,
     so it spans the entire browser window, not just this section */
  background: url('/static/images/app-bg.jpg') center / cover no-repeat fixed;
}

.app-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(rgba(0, 0, 0, 0.30), rgba(0, 0, 0, 0.40));
}

html.dark .app-hero::after {
  background: linear-gradient(rgba(0, 0, 0, 0.50), rgba(0, 0, 0, 0.60));
}

/* Hero card: 60% transparent glass — blur keeps the form readable */
.app-hero-card {
  background: color-mix(in srgb, var(--vp-c-bg) 40%, transparent);
  backdrop-filter: blur(var(--shell-glass-blur));
  -webkit-backdrop-filter: blur(var(--shell-glass-blur));
}

/* ==================== HEADER ==================== */
.app-header {
  grid-area: header;
  /* grid item: min-width:auto would let long page titles stretch the
     mobile single-column track past the viewport */
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: 0 var(--spacing-lg);
  background: var(--shell-glass-bg);
  backdrop-filter: blur(var(--shell-glass-blur));
  -webkit-backdrop-filter: blur(var(--shell-glass-blur));
  border-bottom: 1px solid var(--vp-c-divider);
  position: sticky;
  top: 0;
  z-index: var(--z-header);
}

.page-greeting {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--vp-c-text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* flex child: without min-width:0 it can't shrink below its text width,
     which pushes the header (and the whole mobile grid) past the viewport */
  min-width: 0;
}

.header-spacer { flex: 1; }

.nav-toggle {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--vp-c-text-2);
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.nav-toggle:hover {
  background: var(--vp-c-bg-soft);
  color: var(--vp-c-text-1);
}

.header-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: var(--font-size-sm);
  color: var(--vp-c-text-2);
  text-decoration: none;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.header-link:hover {
  background: var(--vp-c-bg-soft);
  color: var(--vp-c-text-1);
}

/* Apps launcher dropdown (surface switcher) — solid background by decision
   (5.1 manual QA): the glass treatment read as confusing over page content. */
.apps-panel {
  position: fixed;
  top: calc(var(--header-height) + 6px);
  right: var(--spacing-lg);
  min-width: 220px;
  background: var(--vp-c-bg);
  border: 1px solid var(--shell-glass-border);
  border-radius: 12px;
  box-shadow: var(--vp-shadow-3);
  padding: var(--spacing-sm);
  z-index: var(--z-modal);
}

.apps-panel-title {
  font-size: var(--font-size-xs, 12px);
  font-weight: 600;
  color: var(--vp-c-text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 10px 8px;
}

.apps-panel-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--vp-c-text-2);
  text-decoration: none;
  font-size: var(--font-size-sm);
  white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.apps-panel-item .material-symbols-outlined { font-size: 20px; }

.apps-panel-item:hover {
  background: var(--vp-c-bg-soft);
  color: var(--vp-c-text-1);
}

/* Mobile-only toggles (hidden on desktop) */
.mobile-menu-toggle,
.rightsubnav-mobile-toggle { display: none; }

/* ==================== LEFT SIDEBAR (modules) ==================== */
.sidebar-desktop {
  grid-area: sidebar;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--shell-glass-bg);
  backdrop-filter: blur(var(--shell-glass-blur));
  -webkit-backdrop-filter: blur(var(--shell-glass-blur));
  border-right: 1px solid var(--vp-c-divider);
  width: var(--shell-sidebar-collapsed);
  overflow: hidden;
  transition: width var(--transition-medium);
  z-index: var(--z-sidebar);
}

.sidebar-desktop.expanded { width: var(--shell-sidebar-expanded); }

.sidebar-header {
  display: flex;
  align-items: center;
  padding: 0 11px;
  height: var(--header-height);
  flex-shrink: 0;
  border-bottom: 1px solid var(--vp-c-divider);
}

.sidebar-logo-container {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  padding: 0;
  transition: transform var(--transition-fast);
}

.sidebar-logo-container:hover { transform: scale(1.1); }

.sidebar-logo-container .material-symbols-outlined {
  font-size: 25px;
  color: var(--vp-c-brand-1);
}

.sidebar-logo-container .sidebar-logo-bear {
  height: 26px;
  width: 21px;
  color: var(--vp-c-brand-1);
}

.sidebar-brand-text {
  color: var(--vp-c-text-1);
  font-weight: 600;
  font-size: var(--font-size-lg);
  white-space: nowrap;
  overflow: hidden;
  margin-left: var(--spacing-sm);
  opacity: 0;
  transition: opacity var(--transition-medium);
}

.sidebar-desktop.expanded .sidebar-brand-text { opacity: 1; }

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--spacing-sm) 0;
  scrollbar-width: thin;
}

.nav-item { position: relative; padding: 2px 11px; }

.nav-item-link {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  color: var(--vp-c-text-2);
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.nav-item-link .material-symbols-outlined {
  font-size: 24px;
  flex-shrink: 0;
}

.nav-item-link .text {
  overflow: hidden;
  font-size: var(--font-size-sm);
  font-weight: 500;
  opacity: 0;
  transition: opacity var(--transition-medium);
}

.sidebar-desktop.expanded .nav-item-link .text { opacity: 1; }

.nav-item-link:hover {
  background: var(--vp-c-bg-soft);
  color: var(--vp-c-text-1);
}

.nav-item-link.active {
  background: var(--vp-c-brand-soft);
  color: var(--vp-c-brand-1);
}

/* Collapsed-state tooltip — fixed-positioned by shell.js (sidebar clips overflow) */
.nav-tooltip {
  position: fixed;
  left: calc(var(--shell-sidebar-collapsed) + 6px);
  background: var(--vp-c-bg-elv, var(--vp-c-bg));
  color: var(--vp-c-text-1);
  border: 1px solid var(--vp-c-border);
  border-radius: 8px;
  box-shadow: var(--vp-shadow-2);
  padding: 6px 12px;
  font-size: var(--font-size-sm);
  font-weight: 500;
  white-space: nowrap;
  z-index: var(--z-tooltip);
  pointer-events: none;
}

/* Backstop: a tooltip must never render on the expanded rail, even if the
   Alpine state gets stranded (touch mouseenter without mouseleave, bfcache). */
.sidebar-desktop.expanded .nav-tooltip { display: none !important; }

.sidebar-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--vp-c-divider);
  padding: var(--spacing-md) 11px;
}

.sidebar-footer-icon {
  color: var(--vp-c-text-3);
  display: flex;
  align-items: center;
  transition: color var(--transition-fast);
}

.sidebar-footer-icon:hover { color: var(--vp-c-danger-1); }

/* ==================== RIGHT SUB-NAV (active module's sub-items) ==================== */
.rightsubnav {
  grid-area: rightsubnav;
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  display: flex;
  flex-direction: column;
  background: var(--shell-glass-bg);
  backdrop-filter: blur(var(--shell-glass-blur));
  -webkit-backdrop-filter: blur(var(--shell-glass-blur));
  border-left: 1px solid var(--vp-c-divider);
  width: var(--shell-rightsubnav-expanded);
  overflow: hidden;
  transition: width var(--transition-medium);
}

.rightsubnav.rightsubnav-collapsed { width: var(--shell-rightsubnav-collapsed); }

.rightsubnav-header {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-md) var(--spacing-sm);
  border-bottom: 1px solid var(--vp-c-divider);
  flex-shrink: 0;
}

.rightsubnav-toggle {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--vp-c-text-2);
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.rightsubnav-toggle:hover {
  background: var(--vp-c-bg-soft);
  color: var(--vp-c-text-1);
}

.rightsubnav-header-title {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--vp-c-text-1);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  overflow: hidden;
  opacity: 1;
  transition: opacity var(--transition-medium);
}

.rightsubnav.rightsubnav-collapsed .rightsubnav-header-title { opacity: 0; }

.rightsubnav-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--spacing-sm) 8px;
  scrollbar-width: thin;
}

.rightsubnav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 10px;
  margin-bottom: 2px;
  border-radius: 8px;
  color: var(--vp-c-text-2);
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.rightsubnav-item .material-symbols-outlined {
  font-size: 20px;
  flex-shrink: 0;
}

.rightsubnav-text {
  overflow: hidden;
  font-size: var(--font-size-sm);
  opacity: 1;
  transition: opacity var(--transition-medium);
}

.rightsubnav.rightsubnav-collapsed .rightsubnav-text { opacity: 0; }

.rightsubnav-item:hover {
  background: var(--vp-c-bg-soft);
  color: var(--vp-c-text-1);
}

.rightsubnav-item.active {
  background: var(--vp-c-brand-soft);
  color: var(--vp-c-brand-1);
  font-weight: 500;
}

/* Nested groups (contract support — unused until a sub-item grows children) */
.rightsubnav-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 40px;
  padding: 0 10px;
  border: none;
  background: transparent;
  border-radius: 8px;
  color: var(--vp-c-text-2);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.rightsubnav-group-header:hover { background: var(--vp-c-bg-soft); }

.rightsubnav-group-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.rightsubnav-group-header .chevron {
  font-size: 20px;
  transition: transform var(--transition-fast);
}

.rightsubnav-group-header.expanded .chevron { transform: rotate(90deg); }

.rightsubnav-submenu {
  display: none;
  padding-left: 14px;
}

.rightsubnav-submenu.expanded { display: block; }

/* Bottom icon cluster (template parity — placeholders for now) */
.rightsubnav-footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: var(--spacing-sm) 8px;
  border-top: 1px solid var(--vp-c-divider);
}

.rightsubnav.rightsubnav-collapsed .rightsubnav-footer { display: none; }

.rightsubnav-footer-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--vp-c-text-3);
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.rightsubnav-footer-btn .material-symbols-outlined { font-size: 20px; }

.rightsubnav-footer-btn:hover {
  background: var(--vp-c-bg-soft);
  color: var(--vp-c-text-1);
}

/* ==================== MAIN CONTENT ==================== */
.main-content {
  grid-area: main;
  min-width: 0;
  padding: var(--spacing-lg);
  /* lift above the fixed .app-background watermark */
  position: relative;
  z-index: 1;
}

.content-left { min-width: 0; }

.layout-section { margin-bottom: var(--spacing-xl); }

/* ==================== BREADCRUMBS ==================== */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: var(--spacing-lg);
  font-size: var(--font-size-sm);
  flex-wrap: wrap;
}

.breadcrumb-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--vp-c-text-2);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.breadcrumb-link:hover { color: var(--vp-c-brand-1); }

.breadcrumb-icon { font-size: 18px; }

.breadcrumb-separator { color: var(--vp-c-text-3); }

.breadcrumb-text { color: var(--vp-c-text-2); }

.breadcrumb-current {
  color: var(--vp-c-text-1);
  font-weight: 500;
}

/* ==================== TABS ==================== */
.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs.tabs-underline {
  border-bottom: 1px solid var(--vp-c-divider);
  margin-bottom: var(--spacing-lg);
}

.tab {
  padding: 10px 16px;
  border: none;
  background: transparent;
  color: var(--vp-c-text-2);
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.tab:hover { color: var(--vp-c-text-1); }

.tab.active {
  color: var(--vp-c-brand-1);
  border-bottom-color: var(--vp-c-brand-1);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ==================== FOOTER BAR ==================== */
.app-footer {
  grid-area: footer;
  /* grid item: min-width:auto would let the nowrap copyright's intrinsic
     width stretch the mobile single-column track past the viewport */
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: 8px var(--spacing-lg);
  background: var(--shell-glass-bg);
  backdrop-filter: blur(var(--shell-glass-blur));
  -webkit-backdrop-filter: blur(var(--shell-glass-blur));
  border-top: 1px solid var(--vp-c-divider);
  /* lift above the fixed .app-background watermark */
  position: relative;
  z-index: 1;
}

.footer-text {
  font-size: var(--font-size-sm);
  color: var(--vp-c-text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* flex child: without min-width:0 its full text width becomes the grid's
     min-content and pushes the mobile layout past the viewport */
  min-width: 0;
}

.footer-spacer { flex: 1; }

.footer-links {
  display: flex;
  align-items: center;
  gap: 4px;
}

.footer-icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--vp-c-text-3);
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: all var(--transition-fast);
}

.footer-icon-btn .material-symbols-outlined { font-size: 20px; }

.footer-icon-btn:hover {
  background: var(--vp-c-bg-soft);
  color: var(--vp-c-text-1);
}

/* ==================== PANEL ==================== */
/* Shell panel primitive — frosted card (glassmorphism per Richard, 2026-07-08) */
.glass-panel {
  background: var(--shell-glass-bg);
  backdrop-filter: blur(var(--shell-glass-blur));
  -webkit-backdrop-filter: blur(var(--shell-glass-blur));
  border: 1px solid var(--shell-glass-border);
  border-radius: 12px;
  box-shadow: var(--vp-shadow-1);
  padding: var(--spacing-lg);
}

/* ==================== MOBILE (<960px) ==================== */
.shell-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: var(--z-overlay);
}

.shell-overlay.active { display: block; }

@media (max-width: 959px) {
  .app-container.layout-page,
  .app-container.layout-page.sidebar-expanded,
  .app-container.layout-page.has-rightsubnav,
  .app-container.layout-page.has-rightsubnav.sidebar-expanded,
  .app-container.layout-page.has-rightsubnav.rsn-collapsed,
  .app-container.layout-page.has-rightsubnav.sidebar-expanded.rsn-collapsed {
    grid-template-areas:
      "header"
      "main"
      "footer";
    grid-template-columns: 1fr;
  }

  .apps-panel { right: var(--spacing-md); }

  .mobile-menu-toggle { display: flex; }
  .has-rightsubnav .rightsubnav-mobile-toggle { display: flex; }
  .rails-toggle { display: none; }  /* rails are drawers on mobile — own toggles */

  /* Left rail -> off-canvas drawer, always full width */
  .sidebar-desktop,
  .sidebar-desktop.expanded {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--shell-sidebar-expanded);
    transform: translateX(-100%);
    transition: transform var(--transition-medium);
    z-index: var(--z-modal);
  }

  .sidebar-desktop.open { transform: translateX(0); }

  .sidebar-desktop .sidebar-brand-text,
  .sidebar-desktop .nav-item-link .text { opacity: 1; }

  .nav-tooltip { display: none !important; }

  /* Right sub-nav -> off-canvas drawer from the right */
  .rightsubnav,
  .rightsubnav.rightsubnav-collapsed {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: var(--shell-rightsubnav-expanded);
    transform: translateX(100%);
    transition: transform var(--transition-medium);
    z-index: var(--z-modal);
    border-left: 1px solid var(--vp-c-divider);
  }

  .rightsubnav.visible { transform: translateX(0); }

  .rightsubnav.rightsubnav-collapsed .rightsubnav-header-title,
  .rightsubnav.rightsubnav-collapsed .rightsubnav-text { opacity: 1; }

  .main-content { padding: var(--spacing-md); }
}
