/* ============================================================================
   03 · APP SHELL & CHROME

   App shell grid, global top navbar, sidebar (brand / sections / guild items /
   footer), focused checkout shell, page content, launch promo banner, content
   sections, tooltip and tabs.

   Part of the dashboard stylesheet, split out of the former single style.css.
   LOAD ORDER IS LOAD-BEARING (later parts intentionally override earlier
   ones) — the canonical order is dashboard/views/partials/_app_styles.ejs.
   ========================================================================== */

/* ===== APP SHELL ===== */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* The user shell stacks a global top navbar above the body row; the admin
   shell keeps the classic side-by-side sidebar + main layout. */
.app-shell[data-shell="user"] {
  flex-direction: column;
  height: 100vh;
}

/* Body row sits below the global top navbar; holds the (optional) guild
   sidebar + the main scroll pane. */
.app-body {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

.app-sidebar {
  width: 224px;
  flex-shrink: 0;
  background: var(--glass-strong);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  z-index: 5;
}

/* In the user shell the sidebar lives inside .app-body (below the navbar),
   so it fills that row rather than the full viewport. */
.app-shell[data-shell="user"] .app-sidebar {
  position: static;
  top: auto;
  height: 100%;
}

/* Hidden on account-level pages (All Servers, Refer & Earn) — no guild selected */
.app-sidebar--hidden { display: none; }

/* Only this region scrolls; brand, search and footer stay pinned */
.sidebar-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.sidebar-scroll::-webkit-scrollbar { width: 6px; }
.sidebar-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
.sidebar-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

.app-main {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  overflow-y: auto;
  height: 100vh;
}

/* In the user shell main fills the body row (viewport minus the navbar). */
.app-shell[data-shell="user"] .app-main {
  height: 100%;
}

/* ===== GLOBAL TOP NAVBAR ===== */
.app-topbar {
  flex-shrink: 0;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0 1rem;
  background: var(--glass-strong);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 30;
}

.topbar-nav-toggle {
  display: none; /* shown on mobile */
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1.35rem;
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.topbar-nav-toggle:hover { background: rgba(255,255,255,0.06); }

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 800;
  font-size: 1rem;
  color: var(--text);
  text-decoration: none;
  flex-shrink: 0;
}
.topbar-brand-icon {
  width: 1.875rem;
  height: 1.875rem;
  border-radius: 0.55rem;
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: 0 8px 22px -6px rgba(220,38,38,.55), inset 0 0 0 1px rgba(255,255,255,.08);
}
.topbar-brand-name { color: var(--text); }
.topbar-brand-name span { color: var(--blurple); }

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-left: 0.5rem;
}
.topbar-nav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4375rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.topbar-nav-link .nav-icon { font-size: 1rem; }
.topbar-nav-link:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-primary);
}
.topbar-nav-link.active {
  background: linear-gradient(90deg, rgba(var(--blue-rgb),0.18), rgba(var(--blue-rgb),0.04));
  color: var(--text-primary);
  font-weight: 600;
}
.topbar-nav-link.active .nav-icon { color: var(--blue); }

.topbar-spacer { flex: 1 1 auto; min-width: 0.5rem; }

/* Search box reuses the .sidebar-search-* inner markup, re-scoped for the bar */
.topbar-search-wrap {
  position: relative;
  width: 260px;
  max-width: 32vw;
  flex-shrink: 1;
}

.topbar-user {
  position: relative;
  flex-shrink: 0;
}
.topbar-user-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3125rem 0.5rem 0.3125rem 0.375rem;
  border-radius: 0.625rem;
  border: 1px solid transparent;
  background: none;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  max-width: 11rem;
}
.topbar-user-btn:hover { background: rgba(255,255,255,0.05); border-color: var(--border); }
.topbar-user.open .topbar-user-btn { background: rgba(255,255,255,0.06); border-color: var(--border); }
.topbar-avatar {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--crimson), var(--pistachio));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}
.topbar-avatar img { width: 100%; height: 100%; object-fit: cover; }
.topbar-username {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.topbar-user-caret {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform 0.15s;
}
.topbar-user.open .topbar-user-caret { transform: rotate(180deg); }

.topbar-user-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 11rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 0.625rem;
  box-shadow: 0 12px 28px rgba(0,0,0,0.55);
  padding: 0.3125rem;
  z-index: 320;
}
.topbar-user.open .topbar-user-menu { display: block; }
.topbar-menu-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.625rem;
  border-radius: 0.45rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, color 0.12s;
}
.topbar-menu-item ion-icon { font-size: 1rem; flex-shrink: 0; }
.topbar-menu-item:hover { background: rgba(255,255,255,0.06); color: var(--text-primary); }

/* Sidebar brand */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.875rem 0.875rem;
  border-bottom: 1px solid var(--border);
  font-weight: 800;
  font-size: 1rem;
  color: var(--text);
  flex-shrink: 0;
  cursor: pointer;
  text-decoration: none;
}

.sidebar-brand-icon {
  width: 2rem;
  height: 2rem;
  border-radius: 0.625rem;
  background: linear-gradient(135deg, var(--crimson), var(--pistachio-dark));
  box-shadow: 0 8px 22px -6px rgba(220,38,38,.55), inset 0 0 0 1px rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.sidebar-brand-name {
  color: var(--text);
}

.sidebar-brand-name span {
  color: var(--blurple);
}

/* Sidebar sections */
.sidebar-section {
  padding: 0.625rem 0.5rem 0.375rem;
  flex-shrink: 0;
}

.sidebar-section-label {
  padding: 0.375rem 0.5rem 0.25rem;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sidebar-nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.625rem;
  border-radius: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s ease-in-out, color 0.15s ease-in-out;
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  line-height: 1.3;
}

.sidebar-nav-link:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-primary);
}

.sidebar-nav-link.active {
  background: linear-gradient(90deg, rgba(var(--blue-rgb),0.16), rgba(var(--blue-rgb),0.03));
  color: var(--text-primary);
  font-weight: 600;
}
/* Solid 3px crimson indicator on the left edge of the active item */
.sidebar-nav-link.active::before {
  content: "";
  position: absolute;
  left: -2px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 1.15rem;
  border-radius: 0 4px 4px 0;
  background: linear-gradient(180deg, var(--crimson), var(--crimson-glow));
  box-shadow: 0 0 14px 1px rgba(var(--blue-rgb),0.65);
}
.sidebar-nav-link.active .nav-icon { color: var(--blue); }

.nav-icon {
  font-size: 1rem;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Guild items in sidebar */
.sidebar-guild-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.375rem 0.625rem;
  border-radius: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  text-decoration: none;
  overflow: hidden;
}

.sidebar-guild-item:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text);
}

.sidebar-guild-item.active {
  background: rgba(var(--blue-rgb),0.10);
  color: var(--text-primary);
  font-weight: 600;
}

.sidebar-guild-icon {
  width: 1.625rem;
  height: 1.625rem;
  border-radius: 0.375rem;
  flex-shrink: 0;
  object-fit: cover;
}

.sidebar-guild-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 0.25rem 0.625rem;
  flex-shrink: 0;
}

/* Sidebar footer */
.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding: 0.75rem;
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.625rem;
}

.sidebar-avatar {
  width: 1.875rem;
  height: 1.875rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--crimson), var(--pistachio));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sidebar-username {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.sidebar-footer-actions {
  display: flex;
  gap: 0.375rem;
  flex-wrap: wrap;
}

/* ===== FOCUSED CHECKOUT SHELL (no sidebar / navbar — just a Back button) ===== */
.checkout-shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.checkout-topbar {
  flex-shrink: 0;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
  background: var(--glass-strong);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.checkout-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  font-weight: 700;
  color: var(--text);
}
.checkout-brand img {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  object-fit: cover;
}
.checkout-main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
}
.checkout-main .page-content {
  max-width: 1040px;
  margin: 0 auto;
}

/* ===== PAGE CONTENT ===== */
.page-content {
  padding: 1.75rem 2rem;
}

/* ===== Launch promo banner (dashboard overview + subscription) ===== */
.launch-banner {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1.5rem;
  padding: 0.7rem 0.9rem 0.7rem 1.1rem;
  border-radius: 0.85rem;
  border: 1px solid rgba(234, 179, 8, 0.4);
  background:
    linear-gradient(135deg, rgba(234, 179, 8, 0.18), rgba(161, 98, 7, 0.1)),
    var(--surface);
  box-shadow: 0 8px 28px -18px rgba(234, 179, 8, 0.55);
  overflow: hidden;
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}
.launch-banner--closing {
  opacity: 0;
  transform: translateY(-6px);
}
.launch-banner-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #422006;
  background: linear-gradient(135deg, #eab308, #a16207);
}
.launch-banner-badge ion-icon { font-size: 0.9rem; }
.launch-banner-text {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--text);
}
.launch-banner-text strong { color: var(--text-primary); font-weight: 700; }
.launch-banner-cta {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.85rem;
  border-radius: 0.6rem;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  color: #422006;
  text-decoration: none;
  background: linear-gradient(135deg, #facc15, #ca8a04);
  transition: filter 0.15s var(--ease);
}
.launch-banner-cta:hover { filter: brightness(1.1); }
.launch-banner-close {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.9rem;
  height: 1.9rem;
  border: 0;
  border-radius: 0.5rem;
  cursor: pointer;
  color: var(--text-muted);
  background: transparent;
  font-size: 1.15rem;
  transition: color 0.15s var(--ease), background 0.15s var(--ease);
}
.launch-banner-close:hover { color: var(--text-primary); background: rgba(255, 255, 255, 0.08); }
@media (max-width: 640px) {
  .launch-banner { flex-wrap: wrap; }
  .launch-banner-text { flex-basis: 100%; order: 3; }
  .launch-banner-close { margin-left: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .launch-banner { transition: none; }
}

.page-header {
  margin-bottom: 1.75rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.page-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-header-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 0.625rem;
}

.breadcrumb a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.12s;
}

.breadcrumb a:hover { color: var(--text); }
.breadcrumb-sep { opacity: 0.4; font-size: 0.75rem; }

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.page-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.375rem;
  line-height: 1.5;
}

/* ===== CONTENT SECTIONS ===== */
.content-section {
  margin-bottom: 1.75rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.section-header-left {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.section-icon {
  width: 2rem;
  height: 2rem;
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.section-subtitle {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 0.125rem;
}

/* ===== TOOLTIP ===== */
.tooltip-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
}

.tooltip-btn {
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: rgba(148,155,164,0.2);
  border: 1px solid rgba(148,155,164,0.3);
  color: var(--text-muted);
  font-size: 0.625rem;
  font-weight: 700;
  cursor: default;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  flex-shrink: 0;
  user-select: none;
}

.tooltip-btn:hover {
  background: var(--blurple);
  color: #fff;
  border-color: var(--blurple);
}

/* Text source only — the visible tooltip is portalled to <body> as a fixed
   element (see js/tooltips.js) so it escapes overflow-clipping ancestors
   (accordions, scrollable modal bodies, cards). Keep this in the DOM but hidden;
   tooltips.js reads its innerHTML. */
.tooltip-popup {
  display: none;
}

/* Body-level fixed tooltip rendered by js/tooltips.js. Positioned via JS. */
.tooltip-portal {
  position: fixed;
  top: 0;
  left: 0;
  width: 220px;
  max-width: calc(100vw - 16px);
  background: #18191c;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.5;
  color: var(--text);
  white-space: normal;
  text-transform: none;
  letter-spacing: 0;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 100000;
}

.tooltip-portal.show {
  opacity: 1;
}

/* Tooltip copy may name a placeholder or a permission — keep <code> legible
   against the dark popup instead of inheriting the page's code styling. */
.tooltip-portal code {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  padding: 0 3px;
}

.tooltip-portal-arrow {
  position: absolute;
  width: 0;
  height: 0;
  border: 5px solid transparent;
  transform: translateX(-50%);
}

.tooltip-portal[data-placement="top"] .tooltip-portal-arrow {
  top: 100%;
  border-top-color: #18191c;
}

.tooltip-portal[data-placement="bottom"] .tooltip-portal-arrow {
  bottom: 100%;
  border-bottom-color: #18191c;
}

/* ===== TABS ===== */
.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
  gap: 0;
}

.tab-btn {
  padding: 0.75rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: -1px;
  white-space: nowrap;
}

.tab-btn:hover:not(:disabled) { color: var(--text); }
.tab-btn.active { color: var(--blurple); border-bottom-color: var(--blurple); }
.tab-btn:disabled { opacity: 0.45; cursor: not-allowed; color: var(--text-muted); }

.tab-content { display: none; }
.tab-content.active { display: block; }

.tab-badge {
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.125rem 0.4rem;
  border-radius: 0.25rem;
  background: rgba(240,177,50,0.15);
  color: var(--yellow);
  border: 1px solid rgba(240,177,50,0.2);
}
