/* ==========================================================================
   App Shell Layout
   Authority: docs/design/foundations.md
   Purpose: Core layout structure, scrolling, tab system, page containers
   ========================================================================== */

/* ===== Body Layout Structure ===== */

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== App Content Container ===== */

#app-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0; /* Allow flex children to shrink below content size */
}

/* ===== Main Content Area - Natural scroll ===== */

#main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0; /* Allow content to shrink if needed */
  min-width: 0; /* Allow flex children to shrink below content width */
}

/* Ensure flex containers allow proper sizing */
#app-content > div[class*="flex-1"] {
  min-height: 0; /* Allow flex children to shrink */
  display: flex;
  height: 100%; /* Ensure container has height for h-full children */
}

/* ===== Tab System ===== */

/* Fixed height tabs (for split-pane layouts like custom-search) */
.js-tab.fixed-height {
  height: calc(100vh - 4rem); /* 100vh - shell header height (#header = 4rem) */
  overflow: hidden;
}

/* Mobile: allow fixed-height tabs to scroll */
@media (max-width: 768px) {
  .js-tab.fixed-height {
    height: auto !important;
    min-height: calc(100vh - 4rem);
    overflow-y: auto !important;
    overflow-x: hidden;
  }
}

/* ===== Page Containers ===== */

/* Page Container - Used by ALL tab components for consistency */
.page-container {
  padding: 2rem 1.5rem;
  width: 100%;
  min-height: calc(100vh - 4rem);
}

/* Page Container Fluid - For components that need full width */
.page-container-fluid {
  padding: 0;
  width: 100%;
  min-height: calc(100vh - 4rem);
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .page-container {
    padding: 1rem;
    min-height: calc(100vh - 4rem);
  }
}

/* ===== Page Header Structure ===== */

.page-header {
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-default);
}

.page-title {
  font-size: var(--text-display);
  font-weight: var(--weight-display);
  margin-bottom: var(--space-2);
  line-height: var(--leading-display);
  color: var(--text-primary);
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: var(--text-body);
  line-height: var(--leading-body);
}

/* Mobile responsive */
@media (max-width: 640px) {
  .page-title {
    font-size: var(--text-h1);
  }
  
  .page-subtitle {
    font-size: var(--text-label);
  }
}

/* ===== Content Sections ===== */

.content-section {
  margin-bottom: var(--space-8);
}

.content-section:last-child {
  margin-bottom: 0;
}

.section-title {
  font-size: var(--text-h2);
  font-weight: var(--weight-h2);
  margin-bottom: var(--space-4);
  color: var(--text-primary);
}

/* Mobile responsive */
@media (max-width: 640px) {
  .content-section {
    margin-bottom: var(--space-6);
  }
  
  .section-title {
    font-size: var(--text-h3);
  }
}

/* ===== Loading Overlay ===== */

#app-loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgb(var(--color-surface-default-rgb) / 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-overlay);
}

#app-loading.hidden {
  display: none;
}

/* ===== Custom Scrollbar ===== */

.custom-scrollbar {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

.custom-scrollbar::-webkit-scrollbar {
  width: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
  background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar-thumb);
  border-radius: 3px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background-color: var(--border-control);
}

/* ===== GPU Acceleration ===== */

.gpu-accelerated {
  transform: translateZ(0);
  backface-visibility: hidden;
  perspective: 1000px;
}

/* ===== Smooth Transitions ===== */

.transition-all {
  transition-property: all;
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
  transition-duration: 150ms;
}
