/* ============================================================
   Valet Design System — App Shell
   Requires: base-layout.css, base-typography.css

   The structural chrome of a portal/dashboard app.
   Sidebar layout on desktop, top nav + drawer on mobile.

   Slots:
     .shell-sidebar   — fixed side navigation
     .shell-main      — scrollable content area
     .shell-topbar    — mobile top bar
     .shell-content   — inner content wrapper with max-width
   ============================================================ */

/* ── Shell root ──────────────────────────────────────────── */
.shell {
  display: grid;
  grid-template-columns: var(--shell-sidebar-width, 240px) 1fr;
  grid-template-rows: 1fr;
  min-block-size: 100vh;
  background-color: var(--color-bg);
}

/* ── Sidebar ─────────────────────────────────────────────── */
.shell-sidebar {
  position: sticky;
  inset-block-start: 0;
  block-size: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none; /* Firefox */
  background-color: var(--color-surface);
  border-inline-end: 1px solid var(--color-border-light);
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.shell-sidebar::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.shell-sidebar-header {
  padding: var(--space-6);
  border-block-end: 1px solid var(--color-border-light);
  flex-shrink: 0;
}

.shell-sidebar-nav {
  flex: 1;
  padding: var(--space-4) var(--space-3);
  overflow-y: auto;
  scrollbar-width: none; /* Firefox */
}

.shell-sidebar-nav::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.shell-sidebar-footer {
  padding: var(--space-4) var(--space-6);
  border-block-start: 1px solid var(--color-border-light);
  flex-shrink: 0;
}

/* ── Main content area ───────────────────────────────────── */
.shell-main {
  display: flex;
  flex-direction: column;
  min-block-size: 100vh;
  overflow-x: hidden;
}

.shell-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
  padding: var(--space-8) var(--space-8);
  inline-size: min(100%, var(--shell-content-max, 1100px));
}

/* ── Page header (within shell-content) ─────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-block-end: var(--space-8);
}

.page-title {
  font-family: var(--font-heading);
  font-size: var(--text-3xl);
  font-weight: 400;
  line-height: var(--leading-tight);
  color: var(--color-text);
  margin: 0;
}

.page-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-block-start: var(--space-1);
}

.page-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

/* ── Section header (within page) ───────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-block-end: var(--space-5);
}

.section-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
}

/* ── Mobile topbar ───────────────────────────────────────── */
.shell-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  background-color: var(--color-surface);
  border-block-end: 1px solid var(--color-border-light);
  position: sticky;
  inset-block-start: 0;
  z-index: 200;
}

/* ── Mobile drawer ───────────────────────────────────────── */
.shell-drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background-color: oklch(0% 0 0 / 40%);
  z-index: 300;
}

.shell-drawer {
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  inline-size: min(280px, 85vw);
  background-color: var(--color-surface);
  z-index: 400;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 250ms ease;
  overflow-y: auto;
}

.shell-drawer[aria-hidden="false"],
.shell-drawer.is-open {
  transform: translateX(0);
}

.shell-drawer-overlay.is-open {
  display: block;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .shell-sidebar {
    display: none;
  }

  /* Scoped: mobile topbar only on portal pages */
  body.vortal-portal-page .shell-topbar {
    display: flex;
  }

  .shell-content {
    padding: var(--space-5) var(--space-5);
  }

  .page-title {
    font-size: var(--text-2xl);
  }
}

/* ============================================================
   Bricks portal shell — global header-as-sidebar layout
   Sidebar = Bricks Header template (#brx-header)
   Main    = Bricks content area  (#brx-content)

   body.vortal-portal-page is added by the Auth module to all
   pages listed in PAGE_CAPS. New portal pages get it for free
   just by being added there.
   ============================================================ */

/* Hide portal templates on non-portal pages */
body:not(.vortal-portal-page) #brx-header,
body:not(.vortal-portal-page) .shell-topbar,
body:not(.vortal-portal-page) .shell-drawer,
body:not(.vortal-portal-page) .shell-drawer-overlay {
  display: none;
}

@media (min-width: 769px) {
  body.vortal-portal-page {
    display: grid;
    grid-template-columns: var(--shell-sidebar-width, 240px) 1fr;
    grid-template-rows: 1fr;
    min-block-size: 100vh;
  }

  /* If Bricks wraps everything in #brx-page, make it
     layout-transparent so header/content are grid items of body */
  body.vortal-portal-page #brx-page {
    display: contents;
  }

  body.vortal-portal-page #brx-header {
    position: sticky;
    inset-block-start: 0;
    block-size: 100vh;
    overflow: hidden;
    /* Reset any Bricks default header margin/padding */
    margin: 0;
    padding: 0;
  }

  body.vortal-portal-page #brx-content {
    display: flex;
    flex-direction: column;
    min-block-size: 100vh;
    overflow-x: clip; /* clip avoids forcing overflow-y to auto */
  }
}

@media (max-width: 768px) {
  body.vortal-portal-page #brx-header {
    display: none;
  }
}
