/* ============================================================
   LAYOUT.CSS — App Shell, Grid, Containers, Regions
   PWA CSS Library by CSTRSK
   ============================================================ */

/* ── APP SHELL ──────────────────────────────────────────────── */

/* Root PWA shell — full screen, no scroll */
.app-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "topbar"
    "main"
    "bottombar";
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  background: var(--bg-base);
}

.app-shell.has-sidebar {
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main"
    "sidebar bottombar";
}

/* ── TOP APP BAR ────────────────────────────────────────────── */

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--topbar-height);
  padding: 0 var(--space-4);
  padding-top:  var(--safe-top);
  padding-left: max(var(--space-4), var(--safe-left));
  padding-right: max(var(--space-4), var(--safe-right));
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-default);
  z-index: var(--z-sticky);
  position: sticky;
  top: 0;
}

.topbar__back    { flex-shrink: 0; }
.topbar__title   { flex: 1; font-size: var(--text-md); font-weight: var(--font-weight-semibold); truncate; }
.topbar__actions { display: flex; align-items: center; gap: var(--space-1); }

/* Transparent variant (for hero pages) */
.topbar--transparent {
  background: transparent;
  border-bottom: none;
  position: absolute;
  top: 0; left: 0; right: 0;
}

/* ── BOTTOM NAVIGATION BAR ──────────────────────────────────── */

.bottombar {
  grid-area: bottombar;
  display: flex;
  align-items: flex-start;
  justify-content: space-around;
  height: var(--bottombar-height);
  padding-top: var(--space-2);
  padding-bottom: var(--safe-bottom);
  padding-left:  var(--safe-left);
  padding-right: var(--safe-right);
  background: var(--bg-surface);
  border-top: 1px solid var(--border-default);
  z-index: var(--z-sticky);
}

.bottombar__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-0-5);
  flex: 1;
  padding: var(--space-1) var(--space-2);
  color: var(--icon-default);
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease-default);
  min-height: var(--tap-min);
  -webkit-tap-highlight-color: transparent;
}

.bottombar__item:hover,
.bottombar__item.is-active {
  color: var(--interactive-primary);
}

.bottombar__icon   { width: 24px; height: 24px; }
.bottombar__label  { font-size: var(--text-xs); font-weight: var(--font-weight-medium); }

/* ── SIDEBAR ────────────────────────────────────────────────── */

.sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border-default);
  overflow-y: auto;
  overflow-x: hidden;
  padding-top: var(--safe-top);
}

.sidebar__header {
  padding: var(--space-6) var(--space-4) var(--space-4);
  border-bottom: 1px solid var(--border-default);
}

.sidebar__nav    { flex: 1; padding: var(--space-4) var(--space-2); }
.sidebar__footer { padding: var(--space-4); border-top: 1px solid var(--border-default); }

/* ── MAIN CONTENT AREA ──────────────────────────────────────── */

.main-content {
  grid-area: main;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* Pull-to-refresh sentinel */
.ptr-sentinel {
  height: 0;
  overflow: hidden;
}

/* ── CONTAINER / PAGE WRAPPER ────────────────────────────────── */

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-4);
}

.container--sm  { max-width: 640px; }
.container--md  { max-width: 768px; }
.container--lg  { max-width: 1024px; }
.container--xl  { max-width: 1280px; }
.container--2xl { max-width: 1536px; }
.container--fluid { max-width: none; }

.page {
  padding: var(--space-6) var(--space-4);
}

.page--compact {
  padding: var(--space-4);
}

/* ── GRID SYSTEM ────────────────────────────────────────────── */

.grid {
  display: grid;
  gap: var(--space-4);
}

.grid-1  { grid-template-columns: 1fr; }
.grid-2  { grid-template-columns: repeat(2, 1fr); }
.grid-3  { grid-template-columns: repeat(3, 1fr); }
.grid-4  { grid-template-columns: repeat(4, 1fr); }
.grid-6  { grid-template-columns: repeat(6, 1fr); }
.grid-12 { grid-template-columns: repeat(12, 1fr); }

/* Auto-fill responsive grids */
.grid-auto-sm  { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.grid-auto-md  { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.grid-auto-lg  { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }

/* Gap variants */
.gap-0  { gap: 0; }
.gap-2  { gap: var(--space-2); }
.gap-3  { gap: var(--space-3); }
.gap-4  { gap: var(--space-4); }
.gap-6  { gap: var(--space-6); }
.gap-8  { gap: var(--space-8); }

/* Column spans */
.col-span-1  { grid-column: span 1; }
.col-span-2  { grid-column: span 2; }
.col-span-3  { grid-column: span 3; }
.col-span-4  { grid-column: span 4; }
.col-span-full { grid-column: 1 / -1; }

/* ── FLEX UTILITIES ─────────────────────────────────────────── */

.flex        { display: flex; }
.flex-col    { display: flex; flex-direction: column; }
.flex-wrap   { flex-wrap: wrap; }
.flex-1      { flex: 1; }
.flex-none   { flex: none; }
.flex-shrink-0 { flex-shrink: 0; }

.items-start   { align-items: flex-start; }
.items-center  { align-items: center; }
.items-end     { align-items: flex-end; }
.items-stretch { align-items: stretch; }

.justify-start   { justify-content: flex-start; }
.justify-center  { justify-content: center; }
.justify-end     { justify-content: flex-end; }
.justify-between { justify-content: space-between; }
.justify-around  { justify-content: space-around; }

/* ── SECTION / REGIONS ──────────────────────────────────────── */

.section {
  padding: var(--space-12) 0;
}

.section--sm { padding: var(--space-8) 0; }
.section--lg { padding: var(--space-20) 0; }

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

.section__title {
  font-size: var(--text-2xl);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.section__subtitle {
  font-size: var(--text-md);
  color: var(--text-secondary);
}

/* ── DIVIDERS ────────────────────────────────────────────────── */

.divider {
  border: none;
  border-top: 1px solid var(--border-default);
  margin: var(--space-4) 0;
}

.divider--dashed {
  border-top-style: dashed;
}

/* ── SCROLL SNAP ─────────────────────────────────────────────── */

.scroll-x {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  gap: var(--space-3);
  padding: var(--space-2) 0;
}

.scroll-x::-webkit-scrollbar { display: none; }

.scroll-x > * {
  scroll-snap-align: start;
  flex-shrink: 0;
}

/* ── RESPONSIVE BREAKPOINTS ─────────────────────────────────── */
/*
  xs:  < 480px   (small phones)
  sm:  >= 480px  (phones)
  md:  >= 768px  (tablets)
  lg:  >= 1024px (small desktop)
  xl:  >= 1280px (desktop)
  2xl: >= 1536px (wide)
*/

@media (max-width: 767px) {
  .app-shell.has-sidebar {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main"
      "bottombar";
  }

  .sidebar {
    display: none;
  }

  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }

  .hide-mobile { display: none !important; }
}

@media (min-width: 768px) {
  .hide-desktop { display: none !important; }

  .container { padding: 0 var(--space-6); }

  .grid-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 1024px) {
  .container { padding: 0 var(--space-8); }
}
