/* =====================================================================
   App shell — spec §16 (desktop 3 columns) / §17 (mobile top + bottom nav)
   ===================================================================== */

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: calc(var(--topbar-h) + var(--safe-t));
  padding-top: var(--safe-t);
  background: color-mix(in srgb, var(--c-surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--c-border);
}
.topbar-inner {
  height: var(--topbar-h); max-width: 1360px; margin: 0 auto; padding: 0 var(--gutter);
  display: flex; align-items: center; gap: 12px;
}
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--c-text); font-weight: 800; font-size: 1.22rem; letter-spacing: -.02em; flex: none; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; background: var(--g-brand); box-shadow: 0 4px 12px rgba(24, 119, 242, .35); }
.brand-mark svg { width: 22px; height: 22px; }
.brand-word b { color: var(--c-primary); font-weight: 800; }

.topbar-search { position: relative; flex: 0 1 300px; margin-left: 4px; }
.topbar-search input {
  width: 100%; height: 40px; border-radius: var(--r-full); border: 1px solid transparent;
  background: var(--c-surface-3); padding: 0 14px 0 40px; font-size: .95rem; transition: border-color var(--t-fast), background var(--t-fast);
}
.topbar-search input:focus { background: var(--c-surface); border-color: var(--c-primary); box-shadow: var(--ring); }
.topbar-search .ico { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--c-text-3); width: 18px; height: 18px; pointer-events: none; }
.search-panel {
  position: absolute; top: calc(100% + 8px); left: 0; width: min(420px, 92vw);
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-lg); box-shadow: var(--sh-3);
  padding: 8px; max-height: 70vh; overflow: auto; z-index: 60;
}

.topbar-center { flex: 1; display: flex; justify-content: center; gap: 4px; }
.topnav-link {
  position: relative; width: 96px; height: 48px; display: grid; place-items: center; color: var(--c-text-2);
  border-radius: var(--r); transition: background var(--t-fast), color var(--t-fast);
}
.topnav-link:hover { background: var(--c-surface-3); color: var(--c-text); text-decoration: none; }
.topnav-link.active { color: var(--c-primary); }
.topnav-link.active::after { content: ""; position: absolute; left: 16px; right: 16px; bottom: -5px; height: 3px; border-radius: 3px; background: var(--c-primary); }
.topnav-link .ico { width: 25px; height: 25px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; flex: none; }
.icon-btn {
  position: relative; width: 40px; height: 40px; border-radius: var(--r-full); display: inline-grid; place-items: center;
  background: var(--c-surface-3); color: var(--c-text); transition: background var(--t-fast), transform var(--t-fast);
}
.icon-btn:hover { background: var(--c-border); text-decoration: none; }
.icon-btn:active { transform: scale(.95); }
.icon-btn.active { background: var(--c-primary-50); color: var(--c-primary); }
.icon-btn .ico { width: 20px; height: 20px; }
.icon-btn.plain { background: transparent; }
.icon-btn.plain:hover { background: var(--c-surface-3); }
.badge-dot {
  position: absolute; top: -3px; right: -3px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: var(--r-full);
  background: var(--c-error); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center;
  border: 2px solid var(--c-surface); line-height: 1;
}
.badge-dot:empty, .badge-dot[data-count="0"] { display: none; }
.avatar-btn { border-radius: var(--r-full); padding: 0; }

/* ---------- 3-column shell ---------- */
.shell {
  display: grid;
  grid-template-columns: var(--nav-w) minmax(0, 1fr) var(--rail-w);
  gap: 28px; max-width: 1360px; margin: 0 auto; padding: 20px var(--gutter) 40px;
  align-items: start;
}
.shell.no-rail { grid-template-columns: var(--nav-w) minmax(0, 1fr); }
.shell.wide { grid-template-columns: var(--nav-w) minmax(0, 1fr); }
.shell-main { min-width: 0; }
.shell-main.feed-width { max-width: var(--feed-w); width: 100%; margin: 0 auto; }

.sidenav { position: sticky; top: calc(var(--topbar-h) + 20px); max-height: calc(100vh - var(--topbar-h) - 40px); overflow-y: auto; scrollbar-width: thin; padding-bottom: 12px; }
.sidenav::-webkit-scrollbar { width: 6px; } .sidenav::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 6px; }
.nav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: var(--r); color: var(--c-text);
  font-weight: 500; transition: background var(--t-fast);
}
.nav-item:hover { background: var(--c-surface-3); text-decoration: none; }
.nav-item.active { background: var(--c-primary-50); color: var(--c-primary); font-weight: 650; }
.nav-item .nav-ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--c-surface); box-shadow: var(--sh-1); color: var(--c-text-2); flex: none; }
.nav-item.active .nav-ico { background: var(--c-primary); color: #fff; box-shadow: none; }
.nav-item .count { margin-left: auto; font-size: .78rem; font-weight: 700; color: var(--c-primary); background: var(--c-primary-50); border-radius: var(--r-full); padding: 1px 8px; }
.nav-item.premium .nav-ico { background: var(--g-premium); color: #fff; box-shadow: 0 3px 10px rgba(124, 58, 237, .3); }
.nav-section { margin: 14px 12px 6px; font-size: .74rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--c-text-3); }
.sidenav-footer { margin: 18px 12px 0; font-size: .78rem; color: var(--c-text-3); line-height: 1.8; }
.sidenav-footer a { color: var(--c-text-3); }

.rail { position: sticky; top: calc(var(--topbar-h) + 20px); display: flex; flex-direction: column; gap: 16px; max-height: calc(100vh - var(--topbar-h) - 40px); overflow-y: auto; scrollbar-width: none; padding-bottom: 20px; }
.rail::-webkit-scrollbar { display: none; }

/* ---------- Bottom nav (mobile) ---------- */
.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; display: none;
  height: calc(var(--bottombar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--c-surface) 94%, transparent);
  backdrop-filter: saturate(180%) blur(14px); -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--c-border);
}
.bottombar-inner { height: var(--bottombar-h); display: grid; grid-template-columns: repeat(5, 1fr); }
.bb-item { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--c-text-2); font-size: 11px; font-weight: 600; }
.bb-item:hover { text-decoration: none; }
.bb-item.active { color: var(--c-primary); }
.bb-item .ico { width: 24px; height: 24px; }
.bb-item .badge-dot { top: 4px; right: calc(50% - 22px); }
.bb-create { display: grid; place-items: center; }
.bb-create span { width: 46px; height: 36px; border-radius: 12px; display: grid; place-items: center; background: var(--g-brand); color: #fff; box-shadow: 0 6px 16px rgba(24, 119, 242, .35); }

/* ---------- Public / guest + auth layouts ---------- */
.guestbar .topbar-inner { max-width: 1200px; }
.page-wrap { max-width: 1200px; margin: 0 auto; padding: 24px var(--gutter) 60px; }
.page-narrow { max-width: 760px; margin: 0 auto; padding: 28px var(--gutter) 60px; }

.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-aside {
  position: relative; overflow: hidden; color: #fff; padding: 48px;
  background: radial-gradient(1200px 600px at -10% -20%, #3B9BFF 0%, transparent 55%), radial-gradient(900px 500px at 120% 120%, #7C3AED 0%, transparent 50%), #0F3D91;
  display: flex; flex-direction: column; justify-content: space-between;
}
.auth-aside .brand { color: #fff; }
.auth-aside .brand-word b { color: #BFDBFE; }
.auth-aside h1 { color: #fff; font-size: clamp(1.8rem, 3vw, 2.6rem); max-width: 520px; letter-spacing: -.02em; }
.auth-aside p { color: rgba(255, 255, 255, .82); font-size: 1.05rem; max-width: 480px; }
.auth-bubbles { position: absolute; inset: 0; pointer-events: none; opacity: .9; }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 40px var(--gutter); background: var(--c-bg); }
.auth-card { width: 100%; max-width: 440px; }
.auth-card .card { padding: 28px; }

/* ---------- Responsive ---------- */
@media (max-width: 1240px) {
  .shell { grid-template-columns: 240px minmax(0, 1fr) 300px; gap: 20px; }
  .topnav-link { width: 76px; }
}
@media (max-width: 1100px) {
  .shell, .shell.no-rail, .shell.wide { grid-template-columns: 76px minmax(0, 1fr); }
  .rail { display: none; }
  .sidenav .nav-item { justify-content: center; padding: 8px; }
  .sidenav .nav-item > span:not(.nav-ico), .sidenav .nav-section, .sidenav-footer, .sidenav .count, .sidenav .nav-profile-name { display: none; }
  .topbar-center { display: none; }
}
@media (max-width: 900px) {
  :root { --gutter: 12px; }
  .shell, .shell.no-rail, .shell.wide { grid-template-columns: minmax(0, 1fr); padding: 12px var(--gutter) calc(var(--bottombar-h) + var(--safe-b) + 24px); gap: 12px; }
  .sidenav { display: none; }
  .bottombar { display: block; }
  .topbar-search { display: none; }
  .topbar-actions .hide-mobile { display: none; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
  .auth-main { padding-top: 28px; align-items: flex-start; }
  body.has-bottombar .toast-stack { bottom: calc(var(--bottombar-h) + var(--safe-b) + 12px); }
}
@media (max-width: 420px) {
  .brand-word { display: none; }
}
