/* ==========================================================================
   Signed-in app shell: sidebar, top bar, page header, banners.
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 1.1rem 0.9rem;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
  z-index: 40;
}
.sidebar-brand {
  padding: 0.3rem 0.5rem 1.1rem;
}
.account-switch {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.7rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  min-width: 0;
}
.account-switch .name {
  font-size: var(--fs-sm);
  font-weight: 700;
  line-height: 1.25;
}
.account-switch .meta {
  font-size: var(--fs-xs);
  color: var(--muted);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-section {
  margin: 1rem 0.65rem 0.35rem;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 500;
  text-decoration: none;
  transition: background-color 0.12s ease, color 0.12s ease;
}
.nav-link svg {
  width: 18px;
  height: 18px;
  flex: none;
}
.nav-link:hover {
  background: var(--surface-3);
  color: var(--text);
  text-decoration: none;
}
.nav-link[aria-current="page"] {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}
.nav-link .count {
  margin-left: auto;
  min-width: 20px;
  padding: 0 0.4rem;
  border-radius: var(--radius-pill);
  background: var(--primary);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
.sidebar-foot {
  margin-top: auto;
  padding-top: 1rem;
}

/* ---------- Main ---------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: var(--topbar-h);
  padding: 0 clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
}
.topbar .crumbs {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: var(--fs-sm);
  color: var(--muted);
}
.topbar .crumbs strong {
  color: var(--text);
}
.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.menu-toggle {
  display: none;
}

.user-button {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.25rem 0.5rem 0.25rem 0.25rem;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: transparent;
}
.user-button:hover {
  background: var(--surface-3);
}
.user-button .who {
  text-align: left;
  line-height: 1.2;
}
.user-button .who strong {
  display: block;
  font-size: var(--fs-sm);
}
.user-button .who span {
  font-size: var(--fs-xs);
  color: var(--muted);
}

.banners:empty {
  display: none;
}
.banners {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem clamp(1rem, 3vw, 2rem) 0;
}
.banner-impersonation {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem clamp(1rem, 3vw, 2rem);
  background: var(--warn);
  color: #1d1400;
  font-size: var(--fs-sm);
  font-weight: 600;
}
.banner-impersonation svg {
  width: 18px;
  height: 18px;
}
.banner-impersonation .btn {
  margin-left: auto;
  --btn-bg: rgba(0, 0, 0, 0.1);
  --btn-fg: #1d1400;
  --btn-border: transparent;
}

.page {
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.5rem clamp(1rem, 3vw, 2rem) 3rem;
}
.page.is-loading {
  opacity: 0.6;
  transition: opacity 0.2s ease;
}
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.page-header h1 {
  font-size: var(--fs-xl);
}
.page-header .sub {
  margin-top: 0.25rem;
  color: var(--text-2);
  font-size: var(--fs-sm);
}
.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.filters .input,
.filters .select {
  width: auto;
  min-width: 150px;
}
.filters .search {
  min-width: 240px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 2rem 0 0.85rem;
}
.section-title h2 {
  font-size: var(--fs-md);
}

.boot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.live-dot {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: var(--fs-xs);
  color: var(--muted);
  font-weight: 600;
}
.live-dot::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 0 rgba(12, 163, 12, 0.5);
  animation: live 2s infinite;
}
.live-dot.is-paused::before {
  background: var(--muted);
  animation: none;
}
@keyframes live {
  0% { box-shadow: 0 0 0 0 rgba(12, 163, 12, 0.45); }
  70% { box-shadow: 0 0 0 7px rgba(12, 163, 12, 0); }
  100% { box-shadow: 0 0 0 0 rgba(12, 163, 12, 0); }
}

@media (max-width: 1024px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: min(var(--sidebar-w), 86vw);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-lg);
  }
  .app.nav-open .sidebar {
    transform: none;
  }
  .app.nav-open::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 35;
    background: var(--overlay);
  }
  .menu-toggle {
    display: inline-flex;
  }
  .user-button .who {
    display: none;
  }
}
