/* ---------- App layout: sidebar / rail / mobile bars ---------- */

/* Mobile-first: bars visible, sidebar hidden */
.sidebar { display: none; }

.main {
  min-height: 100vh;
  padding-top: var(--topbar-h);
  padding-bottom: var(--tabbar-h);
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar__logo .wordmark { font-size: 28px; }
.topbar__actions { display: flex; align-items: center; gap: 20px; }
.topbar__icon { display: inline-flex; padding: 4px; }

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: var(--tabbar-h);
  display: flex;
  align-items: center;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar__item {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-width: 44px;
}

/* ---------- Search drawer (desktop overlay panel) ---------- */
.search-drawer[hidden] { display: none; }
.search-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: var(--sidebar-rail-w);
  z-index: 60;
  width: 397px;
  max-width: calc(100vw - var(--sidebar-rail-w));
  background: var(--bg);
  border-right: 1px solid var(--border);
  border-radius: 0 16px 16px 0;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
}
.search-drawer__head {
  padding: 24px 16px;
  border-bottom: 1px solid var(--border-light);
}
.search-drawer__head h2 { font-size: 24px; font-weight: 600; margin-bottom: 24px; }
.search-drawer__input {
  width: 100%;
  padding: 8px 16px;
  background: var(--border-light);
  border: 0;
  border-radius: 8px;
  font-size: 16px;
  outline: none;
}
.search-drawer__results { flex: 1; overflow-y: auto; padding: 12px 0; }
.search-drawer__hint { padding: 12px 24px; color: var(--text-secondary); }

/* ---------- Tablet: icon rail ---------- */
@media (min-width: 768px) {
  .topbar, .tabbar { display: none; }

  .main {
    padding-top: 0;
    padding-bottom: 0;
    margin-left: var(--sidebar-rail-w);
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 70;
    width: var(--sidebar-rail-w);
    display: flex;
    flex-direction: column;
    padding: 8px 12px 20px;
    background: var(--bg);
    border-right: 1px solid var(--border);
  }
  .sidebar__logo {
    display: flex;
    align-items: center;
    height: 73px;
    padding: 12px;
    margin-bottom: 12px;
  }
  .sidebar__logo .wordmark { display: none; }
  .sidebar__logo-glyph { display: inline-flex; }

  .sidebar__items { display: flex; flex-direction: column; gap: 4px; flex: 1; }

  .nav-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px;
    border-radius: 8px;
    font-size: 16px;
    line-height: 24px;
    width: 100%;
    text-align: left;
    transition: background-color 0.1s ease;
  }
  .nav-item:hover { background: var(--bg-secondary); }
  .nav-item:hover .icon { transform: scale(1.05); }
  .nav-item .icon { transition: transform 0.1s ease; }
  .nav-item.is-active { font-weight: 700; }
  .nav-item__label { display: none; white-space: nowrap; }

  .sidebar__more { position: relative; }
  .more-menu {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    width: 240px;
    background: var(--bg);
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    padding: 8px;
    z-index: 80;
  }
  .more-menu__item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 16px;
    border-radius: 8px;
    font-size: 14px;
    text-align: left;
  }
  .more-menu__item:hover { background: var(--bg-secondary); }
  .more-menu form { border-top: 1px solid var(--border-light); margin-top: 6px; padding-top: 6px; }
}

/* ---------- Desktop: full sidebar with labels ---------- */
@media (min-width: 1264px) {
  .main { margin-left: var(--sidebar-w); }

  .sidebar { width: var(--sidebar-w); }
  .sidebar__logo .wordmark { display: block; }
  .sidebar__logo-glyph { display: none; }
  .nav-item__label { display: block; }

  body.search-open .sidebar { width: var(--sidebar-rail-w); }
  body.search-open .sidebar .wordmark { display: none; }
  body.search-open .sidebar .sidebar__logo-glyph { display: inline-flex; }
  body.search-open .sidebar .nav-item__label { display: none; }
}

/* When the search drawer is open the sidebar collapses to the rail */
body.search-open .main { pointer-events: none; }
body.search-open .search-drawer ~ * { pointer-events: auto; }

/* ---------- Immersive pages (reels, story viewer) ---------- */
body.immersive .topbar,
body.immersive .tabbar { display: none; }
body.immersive .main { padding: 0; }
body.immersive { background: #000; }
