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

.app-shell::before {
  content: '';
  position: fixed;
  inset: 0;
  background: var(--gradient-ambient);
  pointer-events: none;
  z-index: 0;
}

/* ---- Top nav ---- */
.topnav {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--nav-height);
  display: flex;
  align-items: center;
  background: rgba(10, 10, 18, 0.65);
  backdrop-filter: blur(20px) saturate(150%);
  -webkit-backdrop-filter: blur(20px) saturate(150%);
  border-bottom: 1px solid var(--color-border);
}

[data-theme='light'] .topnav {
  background: rgba(245, 244, 250, 0.72);
}

.topnav-inner {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-5);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-md);
  flex-shrink: 0;
}

.brand-name strong { color: var(--color-payout-strong); }

/* Phase 5: wraps the search <form> + its autocomplete dropdown (see
   modules/search.js) — flex/max-width/position live on the wrapper (same
   split as .notif-bell-wrap around .notif-bell-btn/.notif-panel) so the
   dropdown's `position: absolute` anchors to the whole search bar's
   width, not just whatever the <form> itself ends up sized to. */
.nav-search-wrap {
  position: relative;
  flex: 1;
  max-width: 560px;
}

.nav-search {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  padding: 8px 16px;
  transition: border-color var(--duration-fast) var(--ease-out);
}
.nav-search:focus-within { border-color: var(--color-signal); }
.nav-search input {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--color-ink);
}
.nav-search input::placeholder { color: var(--color-faint); }
/* MPS Phase 9 (Accessibility) — same fix as components.css's .input:focus:
   this suppressed the keyboard focus ring entirely, leaving only the
   wrapper's border-color change (:focus-within above) as a focus cue.
   Removing it lets the global :focus-visible outline (base.css) apply. */
.nav-search svg { color: var(--color-faint); flex-shrink: 0; }

.nav-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
  margin-left: auto;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.nav-links a {
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-muted);
  transition: color var(--duration-fast) var(--ease-out), background var(--duration-fast) var(--ease-out);
}
.nav-links a:hover { color: var(--color-ink); background: var(--color-surface); }
.nav-links a.active { color: var(--color-ink); background: var(--color-surface-strong); }

@media (max-width: 860px) {
  .nav-links { display: none; }
  .nav-search-wrap { display: none; }

  /* Bug fix (found 2026-08-09): .nav-actions had no mobile rule at all —
     on a real phone-width viewport, .brand (~216px) plus every single
     desktop action (Studio/Upload/Profile text-link buttons, notif bell,
     theme toggle, sign-out — ~424px, all flex-shrink:0 same as .brand)
     added up to roughly DOUBLE a typical 375-430px phone's width, with
     nothing to stop it, so the row bled off the right edge of the page.
     Studio/Upload/Profile are also reachable from the bottom .tabbar on
     mobile (see partials/tabbar.php — Upload explicitly, Studio/Profile
     one tap away from there), so hiding these three specifically is a
     real duplicate removal, not a feature loss.
     FIX (found 2026-08-09, same day, via live user report after deploy):
     the first version of this rule targeted `.btn-sm` generally, which ALSO
     matches Sign in (.btn.btn-ghost.btn-sm) and Sign up
     (.btn.btn-primary.btn-sm) — those share the exact same size class as
     Studio/Upload/Profile with nothing else distinguishing them in CSS.
     That hid Sign in/Sign up too, leaving a logged-out mobile visitor with
     ONLY the theme toggle in the top bar and no visible way to sign in or
     register — Sign up in particular has NO tabbar equivalent at all (the
     tabbar's guest-state entry is Sign-in-only), so that was a real
     regression, not a harmless duplicate removal. Targeting these three by
     href instead of by shared size class fixes that: Sign in/Sign up (and
     the compact 40px icon buttons: theme toggle, notif bell, sign-out)
     all stay visible on mobile now. */
  .nav-actions a[href="/studio/videos"],
  .nav-actions a[href="/studio/upload"],
  .nav-actions a[href="/profile"] {
    display: none;
  }
}

@media (max-width: 640px) {
  /* Second pass at the same bug, for narrower phones specifically: even
     after the above, .brand's full "YouMakemWePayYou" wordmark (~180px)
     plus the three remaining icon buttons plus padding/gaps could still
     exceed a smaller phone's width (this platform's own home page shows
     ~375-390px is a realistic minimum). Dropping the wordmark and keeping
     just the ring mark is a common, accepted pattern for a long brand name
     at this width — the mark alone is still a recognizable, tappable link
     back home — and tightening the row's own padding/gap recovers real
     width rather than fighting the overflow with clipping. */
  .topnav-inner { padding: 0 var(--space-4); gap: var(--space-3); }
  .brand-name { display: none; }
}

/* ---- Main content ---- */
.app-main {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-8);
}

@media (max-width: 640px) {
  .app-main { padding: var(--space-5) var(--space-4) 88px; }
}

/* ---- Mobile bottom tab bar ---- */
.tabbar {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 40;
  background: rgba(10, 10, 18, 0.85);
  backdrop-filter: blur(20px) saturate(150%);
  -webkit-backdrop-filter: blur(20px) saturate(150%);
  border-top: 1px solid var(--color-border);
  padding: 8px var(--space-4) calc(8px + env(safe-area-inset-bottom));
}
[data-theme='light'] .tabbar { background: rgba(245, 244, 250, 0.9); }

.tabbar-inner {
  display: flex;
  justify-content: space-around;
}

.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 10px;
  color: var(--color-faint);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
}
.tabbar a.active { color: var(--color-signal-strong); }

@media (max-width: 640px) {
  .tabbar { display: block; }
}

/* ---- Footer ---- */
.app-footer {
  position: relative;
  z-index: 1;
  border-top: 1px solid var(--color-border);
  padding: var(--space-6) var(--space-5);
  font-size: var(--text-xs);
  color: var(--color-faint);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
}

@media (max-width: 640px) {
  .app-footer { display: none; }
}

/* ---- Theme toggle ---- */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* ---- Notification bell (Phase 4 frontend) ---- */
.notif-bell-wrap {
  position: relative;
}

.notif-bell-btn {
  position: relative;
}

.notif-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: var(--radius-pill);
  background: var(--color-edge);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.notif-panel {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  z-index: 50;
  width: 340px;
  max-height: 420px;
  display: flex;
  flex-direction: column;
  background: var(--color-void-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.notif-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  font-weight: 600;
  font-size: var(--text-sm);
}

.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--color-signal-strong);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }

.notif-list {
  overflow-y: auto;
}

.notif-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  text-decoration: none;
  color: var(--color-ink);
  font-size: var(--text-sm);
  transition: background var(--duration-fast) var(--ease-out);
}

a.notif-item:hover { background: var(--color-surface); }

.notif-item.is-unread {
  background: rgba(124, 92, 252, 0.07);
  position: relative;
}

.notif-item.is-unread::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-signal);
}

.notif-item.is-unread { padding-left: calc(var(--space-4) + 10px); }

.notif-item-time {
  font-size: var(--text-xs);
  color: var(--color-faint);
}

.notif-empty {
  padding: var(--space-6) var(--space-4);
  text-align: center;
  color: var(--color-faint);
  font-size: var(--text-sm);
}

@media (max-width: 640px) {
  .notif-panel {
    position: fixed;
    top: var(--nav-height);
    right: var(--space-3);
    left: var(--space-3);
    width: auto;
  }
}

/* ---- Search autocomplete dropdown (Phase 5 frontend) ---- */
.search-suggest-panel {
  position: absolute;
  top: calc(100% + var(--space-2));
  left: 0;
  right: 0;
  z-index: 50;
  max-height: 420px;
  display: flex;
  flex-direction: column;
  background: var(--color-void-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.search-suggest-list {
  overflow-y: auto;
  padding: var(--space-2) 0;
}

.search-suggest-section-label {
  padding: var(--space-2) var(--space-4) 4px;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.search-suggest-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  text-decoration: none;
  color: var(--color-ink);
  font-size: var(--text-sm);
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.search-suggest-item:hover,
.search-suggest-item:focus-visible { background: var(--color-surface); }

.search-suggest-item-thumb {
  flex-shrink: 0;
  width: 44px;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(124, 92, 252, 0.25), rgba(33, 209, 159, 0.15));
  object-fit: cover;
}

.search-suggest-item-avatar {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.search-suggest-item-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-suggest-item-sub {
  color: var(--color-faint);
  font-size: var(--text-xs);
}

.search-suggest-empty {
  padding: var(--space-5) var(--space-4);
  text-align: center;
  color: var(--color-faint);
  font-size: var(--text-sm);
}

@media (max-width: 640px) {
  .search-suggest-panel {
    position: fixed;
    top: var(--nav-height);
    right: var(--space-3);
    left: var(--space-3);
  }
}
