/* ============================================================
   App shell — mobile first.
   Phone: top header + scrolling content + bottom nav.
   Desktop (>=1024px): persistent sidebar, no bottom nav.
   ============================================================ */

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1000px 520px at 100% -10%, rgba(167,139,250,.18), transparent 60%),
    radial-gradient(760px 420px at -10% 4%, rgba(109,40,217,.10), transparent 62%),
    var(--bg);
  background-attachment: fixed;
}

/* ---------------- Top header ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  height: calc(var(--header-h) + var(--safe-t));
  padding: var(--safe-t) var(--s-4) 0;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  /* Brand-purple chrome in both themes — the bar is the one constant
     surface, so it carries the brand instead of the page background. */
  background: var(--grad-brand);
  color: var(--text-invert-fixed);
  box-shadow: 0 2px 16px rgba(76, 29, 149, .22);
}

/* Icons and text inside the purple chrome are white, whatever the theme. */
.topbar .icon-btn { color: inherit; }
.topbar .icon-btn:hover { background: rgba(255, 255, 255, .16); }
.topbar .icon-btn:active { background: rgba(255, 255, 255, .26); }

.topbar__title {
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -.02em;
}
.topbar__sub {
  display: none;
  font-size: var(--fs-xs);
  color: rgba(255, 255, 255, .78);
  font-weight: 500;
}

.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  color: var(--text);
  flex: none;
  transition: background var(--t-fast) var(--ease-out), transform var(--t-fast) var(--ease-out);
}
.icon-btn:hover { background: var(--lavender); }
.icon-btn:active { transform: scale(.92); background: var(--purple-200); }
.icon-btn svg { width: 21px; height: 21px; }

.topbar__avatar {
  width: 36px; height: 36px; border-radius: var(--r-pill);
  flex: none; overflow: hidden;
  border: 2px solid rgba(255, 255, 255, .55);
  box-shadow: var(--shadow-sm);
  transition: transform var(--t-base) var(--ease-spring);
}
.topbar__avatar:active { transform: scale(.9); }

/* ---------------- Content region ---------------- */
.app-main {
  flex: 1;
  width: 100%;
  /* room for bottom nav + iOS home indicator */
  padding: var(--s-4) var(--s-4) calc(var(--bottomnav-h) + var(--safe-b) + var(--s-7));
}

.page { max-width: var(--content-max); margin-inline: auto; }

.page-head { margin-bottom: var(--s-5); }
.page-head h1 { font-size: var(--fs-2xl); }
.page-head p { color: var(--text-muted); font-size: var(--fs-sm); margin-top: 2px; }

.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--s-3);
  margin: var(--s-6) 0 var(--s-3);
}
.section-head h2 {
  font-size: var(--fs-lg);
  letter-spacing: -.015em;
}
.section-head__link {
  font-size: var(--fs-sm); font-weight: 600; color: var(--brand);
  padding: 6px 2px;
}
.section-head__link:active { opacity: .6; }

/* ---------------- Bottom navigation (mobile) ---------------- */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: var(--z-nav);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  height: calc(var(--bottomnav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--grad-deep);
  box-shadow: 0 -6px 24px rgba(76, 29, 149, .28);
}

.bottom-nav__item {
  height: 100%;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: rgba(255, 255, 255, .62);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .01em;
  transition: color var(--t-base) var(--ease-out);
}
.bottom-nav__item svg { width: 22px; height: 22px; transition: transform var(--t-base) var(--ease-spring); }
.bottom-nav__item:active svg { transform: scale(.85); }
.bottom-nav__item.is-active { color: #fff; }
.bottom-nav__item.is-active svg { transform: translateY(-1px); }
/* A soft glow marks the active tab — a purple pill would vanish here. */
.bottom-nav__item.is-active::after {
  content: '';
  position: absolute;
  top: 6px;
  width: 34px; height: 30px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, .16);
  z-index: -1;
}
.bottom-nav__item { position: relative; z-index: 0; }

/* The prominent + action, centred in the nav */
.bottom-nav__fab {
  justify-self: center;
  width: 54px; height: 54px;
  margin-top: -22px;
  border-radius: var(--r-pill);
  display: grid; place-items: center;
  /* White disc on the purple bar — a purple FAB would disappear into it. */
  color: var(--purple-700-fixed);
  background: #fff;
  box-shadow: 0 8px 20px rgba(20, 8, 50, .45);
  border: 3px solid rgba(255, 255, 255, .28);
  transition: transform var(--t-base) var(--ease-spring), box-shadow var(--t-base) var(--ease-out);
}
.bottom-nav__fab svg { width: 26px; height: 26px; }
.bottom-nav__fab:active { transform: scale(.88); box-shadow: 0 4px 12px rgba(20, 8, 50, .5); }

/* ---------------- Sidebar (tablet/desktop) ---------------- */
.sidebar {
  display: none;
  flex-direction: column;
  width: var(--sidebar-w);
  flex: none;
  padding: var(--s-5) var(--s-4);
  gap: var(--s-2);
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-2) var(--s-5); }
.brand__mark {
  width: 38px; height: 38px; flex: none;
  border-radius: 12px;
  display: grid; place-items: center;
  background: var(--grad-brand);
  color: #fff;
  box-shadow: var(--shadow-brand);
}
.brand__mark svg { width: 20px; height: 20px; }
.brand > span { min-width: 0; }
.brand__name { font-weight: 700; letter-spacing: -.02em; font-size: var(--fs-lg); }
.brand__tag { font-size: 11px; color: var(--text-faint); font-weight: 500; }

.nav-list { display: grid; gap: 2px; }
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 44px;
  padding: 0 var(--s-3);
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-weight: 600;
  font-size: var(--fs-base);
  transition: background var(--t-base) var(--ease-out), color var(--t-base) var(--ease-out);
}
.nav-item svg { width: 20px; height: 20px; flex: none; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active { background: var(--lavender); color: var(--purple-700); }
.nav-item.is-active::before {
  left: -16px;
  top: 50%; transform: translateY(-50%);
  width: 3px; height: 22px; border-radius: 0 3px 3px 0;
  background: var(--brand);
}
.nav-item__badge {
  margin-left: auto;
  font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: var(--r-pill);
  background: var(--purple-200); color: var(--purple-800);
}

.sidebar__foot { margin-top: auto; display: grid; gap: var(--s-3); }

.sidebar-user {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3);
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--line);
  width: 100%;
  text-align: left;
  transition: border-color var(--t-base) var(--ease-out), box-shadow var(--t-base) var(--ease-out);
}
.sidebar-user:hover { border-color: var(--purple-200); box-shadow: var(--shadow-sm); }
.sidebar-user img { width: 36px; height: 36px; border-radius: var(--r-pill); flex: none; }
.sidebar-user__name { font-weight: 600; font-size: var(--fs-sm); }
.sidebar-user__mail { font-size: 11px; color: var(--text-faint); }

/* ---------------- Mobile drawer ---------------- */
.drawer-scrim {
  position: fixed; inset: 0;
  z-index: var(--z-drawer);
  background: rgba(30, 27, 46, .45);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base) var(--ease-out);
}
.drawer-scrim.is-open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: calc(var(--z-drawer) + 1);
  width: min(300px, 84vw);
  padding: calc(var(--safe-t) + var(--s-5)) var(--s-4) calc(var(--safe-b) + var(--s-5));
  display: flex; flex-direction: column; gap: var(--s-2);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  transform: translateX(-100%);
  transition: transform var(--t-slow) var(--ease-out);
  overflow-y: auto;
}
.drawer.is-open { transform: translateX(0); }

/* ---------------- Responsive shell ---------------- */
@media (min-width: 768px) {
  .app-main { padding: var(--s-6); padding-bottom: calc(var(--bottomnav-h) + var(--safe-b) + var(--s-7)); }
  .topbar { padding-inline: var(--s-6); }
  .topbar__sub { display: block; }
  .page-head h1 { font-size: var(--fs-3xl); }
}

@media (min-width: 1024px) {
  .app-shell { flex-direction: row; }
  .sidebar { display: flex; position: sticky; top: 0; height: 100dvh; }
  .app-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  .app-main { padding: var(--s-7); padding-bottom: var(--s-8); }
  .bottom-nav, .drawer, .drawer-scrim, .menu-btn { display: none !important; }
  /* The bar stays branded on desktop too, next to the sidebar. */
  .topbar { border-bottom: 0; }
}

@media (min-width: 1440px) {
  .app-main { padding: var(--s-8) var(--s-7); }
}
