/* ===========================================
   Authenticated App Shell: left sidebar + top bar
   Loaded only when app_shell? (logged-in, non-marketing pages)
   =========================================== */

:root {
  --sidebar-width: 240px;
  --topbar-height: 60px;
  /* One notch deeper than --surface so white cards read as content on a canvas */
  --app-canvas: #F6F7F9;
}

.app-shell {
  display: flex;
  flex: 1;
  width: 100%;
}

/* One continuous surface: the canvas shares the sidebar's background so
   the margins around centered content read as canvas, not as a gap.
   White cards provide the content structure. */
body.authenticated.with-app-shell {
  background-color: var(--app-canvas);
}

/* --- Sidebar --- */

.app-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: white;
  border-right: 1px solid #E5E7EB;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
}

.app-sidebar__logo {
  display: flex;
  align-items: center;
  padding: 4px 10px 16px;
}

.app-sidebar__logo img {
  height: 48px;
  width: auto;
}

/* Search section: its own block between the logo and the nav */
.app-sidebar__search {
  padding: 0 0 14px;
  border-bottom: 1px solid #E5E7EB;
  margin-bottom: 12px;
}

/* On the white sidebar the search pill needs a tint to stand out */
.app-sidebar__search .app-search {
  background: var(--app-canvas);
}

.app-sidebar__search .app-search:focus-within {
  background: white;
}

.app-sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Account section: pinned to the bottom, below the nav */
.app-sidebar__user {
  margin-top: auto;
  border-top: 1px solid #E5E7EB;
  padding-top: 12px;
}

.app-sidebar__user .dropdown-container {
  width: 100%;
}

.app-sidebar__user .user-menu-btn {
  width: 100%;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
}

.app-sidebar__user .user-menu-btn:hover {
  background: #FFF7ED;
}

.app-sidebar__user .user-menu-btn__name {
  flex: 1;
  min-width: 0;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  color: #374151;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Open the account menu upward from the bottom of the sidebar */
.app-sidebar__user .dropdown-menu {
  top: auto;
  bottom: calc(100% + 6px);
  left: 0;
  right: auto;
  width: 100%;
  margin-top: 0;
}

.app-sidebar__link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #6B7280;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s;
}

.app-sidebar__link .mdi {
  font-size: 20px;
}

.app-sidebar__link:hover {
  color: #F97316;
  background: #FFF7ED;
}

.app-sidebar__link.active {
  color: #F97316;
  background: #FFF7ED;
  font-weight: 600;
}

.app-sidebar__badge,
.mobile-nav-item__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin-left: auto;
  border-radius: 9px;
  background: #F97316;
  color: white;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.mobile-nav-item__badge {
  margin-left: 8px;
}

/* --- Main column --- */

.app-shell__main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* --- Search pill (shared by sidebar and mobile topbar) --- */

.app-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: white;
  border: 1px solid #E5E7EB;
  border-radius: 10px;
  width: 100%;
  transition: all 0.2s;
}

.app-search .mdi {
  color: var(--text-light);
}

.app-search:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.app-search input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  outline: none;
  font: inherit;
  font-size: 14px;
}

/* --- Top bar (mobile only: sidebar carries search + account on desktop) --- */

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 1000; /* matches old .global-header so modal stacking is unchanged */
  height: var(--topbar-height);
  flex-shrink: 0;
  background: var(--app-canvas);
  border-bottom: 1px solid #E5E7EB;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
}

@media (min-width: 769px) {
  .app-topbar {
    display: none;
  }
}

.app-topbar__search {
  max-width: 420px;
}

.app-topbar__spacer {
  flex: 1;
}

/* Hamburger hidden on desktop (layout.css also hides it >=769px) */
.app-topbar .mobile-menu-wrapper {
  display: none;
}

/* layout.css fixes .mobile-nav at top: 64px (old header height) */
.app-shell .mobile-nav {
  top: var(--topbar-height);
}

/* authenticated.css sticky offset was tuned to the old 74px header;
   with no desktop top bar, content can stick near the viewport top */
.app-shell .split-layout__sidebar {
  top: 24px;
}

/* --- Breakpoints --- */

@media (max-width: 900px) {
  :root {
    --sidebar-width: 220px;
  }
}

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

  .app-topbar {
    padding: 0 16px;
    gap: 12px;
  }

  .app-topbar .mobile-menu-wrapper {
    display: block;
  }

  /* Sticky sidebar content sits below the mobile top bar */
  .app-shell .split-layout__sidebar {
    top: calc(var(--topbar-height) + 24px);
  }
}

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

/* ===========================================
   Wide-screen content width
   Inside the shell, every authenticated page uses the same 1440px cap so
   index, show, and form pages all align. Marketing pages (no shell) keep
   the standard 1200px.
   =========================================== */

.app-shell {
  --auth-content-max-width: 1440px;
}

.app-shell .main-container {
  max-width: 1440px;
}

/* Browse grids gain a 4th column once the wider cap has room for it */
@media (min-width: 1700px) {
  .app-shell .card-grid--3,
  .app-shell .keepsakes-grid,
  .app-shell .stories-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}
