/* ==========================================================================
   Layout — app shell: sidebar, header, bottom nav, content grid
   ========================================================================== */

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- Desktop Sidebar ---------- */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  background: var(--color-primary-dark);
  color: var(--color-text-inverse);
  display: none;
  flex-direction: column;
  padding: 20px 14px;
  z-index: var(--z-sidebar);
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 20px;
}

.sidebar-brand img { height: 34px; width: auto; filter: brightness(0) invert(1); }

.sidebar-brand-text {
  font-weight: 700;
  font-size: 13.5px;
  line-height: 1.25;
  color: rgba(255,255,255,.92);
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: rgba(255,255,255,.72);
  font-size: 14px;
  font-weight: 500;
  transition: background var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard);
  min-height: 44px;
}

.sidebar-link:hover { background: rgba(255,255,255,.06); color: #fff; }

.sidebar-link.active {
  background: var(--color-secondary);
  color: #fff;
  font-weight: 600;
}

.sidebar-link svg { width: 19px; height: 19px; flex-shrink: 0; }

.sidebar-divider {
  height: 1px;
  background: rgba(255,255,255,.10);
  margin: 12px 4px;
}

.sidebar-foot { display: flex; flex-direction: column; gap: 2px; }

/* ---------- Mobile header ---------- */
.mobile-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: var(--mobile-header-height);
  padding: 0 8px;
  padding-top: env(safe-area-inset-top);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.mobile-header-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  color: var(--color-text);
  flex-shrink: 0;
}

.mobile-header-btn:hover { background: var(--color-surface-alt); }

.mobile-header-title {
  font-weight: 700;
  font-size: 15px;
  flex: 1;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mobile-header.detail .mobile-header-title { text-align: center; }

/* ---------- Desktop header (top bar within content) ---------- */
.desktop-topbar {
  display: none;
}

/* ---------- Main content ---------- */
.app-main {
  flex: 1;
  min-width: 0;
  padding-bottom: calc(var(--bottomnav-height) + env(safe-area-inset-bottom) + 12px);
}

.page-container {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: 16px;
}

/* ---------- Bottom Nav (mobile) ---------- */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-bottomnav);
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -4px 16px rgba(15,32,62,.06);
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 56px;
  color: var(--color-muted);
  font-size: 11px;
  font-weight: 600;
  position: relative;
}

.bottom-nav-item svg { width: 22px; height: 22px; }

.bottom-nav-item.active { color: var(--color-primary); }

.bottom-nav-item.active::before {
  content: "";
  position: absolute;
  top: 2px;
  width: 28px;
  height: 3px;
  border-radius: var(--radius-full);
  background: var(--color-secondary);
}

/* ---------- Grid helpers ---------- */
.grid {
  display: grid;
  gap: 14px;
}

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

.row { display: flex; align-items: center; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.stack { display: flex; flex-direction: column; }

.hscroll {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  padding-bottom: 4px;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.hscroll::-webkit-scrollbar { display: none; }
.hscroll > * { scroll-snap-align: start; flex-shrink: 0; }

/* ---------- Desktop breakpoint: enable sidebar layout ---------- */
@media (min-width: 1024px) {
  .sidebar { display: flex; }
  .mobile-header { display: none; }
  .bottom-nav { display: none; }
  .app-main { margin-left: var(--sidebar-width); padding-bottom: 24px; }
  .page-container { padding: 28px 32px; }
  .desktop-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: 20px 32px 0;
  }
}

@media (min-width: 1440px) {
  .page-container { padding: 32px 40px; }
  .desktop-topbar { padding: 24px 40px 0; }
}
