/*
 * Component: Layout
 *
 * App shell, content areas, and page headers.
 * Sidebar-based layout replacing the old bottom nav.
 */

/* ============================================================================
   APP BACKGROUND - Fixed layer behind app-content
   Not a child of app-content, so it's never affected by the zoom-out transform.
   html background (--sf on desktop with sidebar) shows in the sidebar
   strip, giving Safari's window chrome the right color to sample.
   ============================================================================ */

.app-bg {
  position: fixed;
  inset: 0;
  left: var(--sidebar-w);
  background: var(--bg);
  z-index: -1;
}

.app-bg--full {
  left: 0;
}

@media (max-width: 1099px), (hover: none) and (pointer: coarse) {
  .app-bg {
    left: 0;
  }
}

/* ============================================================================
   APP CONTENT - Main content area (right of sidebar)
   ============================================================================ */

.app-content {
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
  scrollbar-gutter: stable;
}

/* Full width when no sidebar (auth pages, welcome) */
.app-content--full {
  margin-left: 0;
}

/* Mobile: no left margin, confined scroll container, account for bottom nav */
@media (max-width: 1099px), (hover: none) and (pointer: coarse) {
  .app-content {
    margin-left: 0;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: none;
    scrollbar-width: none;
    padding-bottom: calc(var(--bottom-nav-h) + var(--safe-inset-bottom));
  }

  .app-content::-webkit-scrollbar {
    display: none;
  }

  .app-content--full {
    padding-bottom: 0;
  }

  /* A page with the sidebar but no bottom nav (Settings) reserves only
     the home indicator's inset, not the nav's 84px */
  .app-content--no-bottom-nav {
    padding-bottom: var(--safe-inset-bottom);
  }
}

/* ============================================================================
   CONTENT MAIN - Page content container
   ============================================================================ */

.content-main {
  flex: 1;
  padding: var(--sp-8);
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

/* Phone content padding. There is no topbar, so the page header sits just
   under the status bar and owns its own title and actions. */
@media (max-width: 1099px), (hover: none) and (pointer: coarse) {
  .content-main {
    padding: calc(12px + var(--safe-inset-top)) 16px 24px;
  }
}

/* ============================================================================
   PAGE HEADING
   Display title (30/36 desktop, 28/34 phone), a 15px --tx2 subline, actions
   on the right. On phone the settings avatar sits last in the actions. Used
   by the Insights tabs.
   ============================================================================ */

.page-heading {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
}

.page-heading-row {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  width: 100%;
}

.page-heading-text {
  flex: 1;
  min-width: 0;
}

.page-heading-title {
  margin: 0;
  font: var(--fw-bold) var(--t-display) var(--font);
  letter-spacing: var(--tracking-tight);
  color: var(--tx);
}

.page-heading-subline {
  margin: 4px 0 0;
  font: var(--fw-regular) var(--t-body) var(--font);
  color: var(--tx2);
}

.page-heading-actions {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 8px;
}

@media (max-width: 1099px), (hover: none) and (pointer: coarse) {
  .page-heading-title {
    font: var(--fw-bold) var(--t-display-m) var(--font);
  }

  .page-heading .segmented {
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
  }

  /* Header buttons go icon-only on phone so the title keeps its width; the
     label stays readable to screen readers */
  .page-heading-actions .button {
    width: var(--tap-min);
    padding: 0;
  }

  .page-heading-actions .button > span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* ============================================================================
   MOBILE LANDSCAPE - Adjustments for phones rotated to landscape
   ============================================================================ */

@media (orientation: landscape) and (hover: none) and (pointer: coarse) {
  /* Respect side safe areas (notch shifts to left/right in landscape) */
  .app-content {
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
  }
}
