/* App shell + collapsible user menu (logged-in dashboard chrome) */

:root {
  --app-menu-width-expanded: 320px;
  --app-menu-width-collapsed: 56px;
  --app-mobile-topbar-height: 48px;
}

/* ----- App shell ----- */

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

.app-shell .content-inner {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  padding: 1em;
  box-sizing: border-box;
}

/* ----- Mobile sticky top bar ----- */

.app-mobile-topbar {
  display: none;
}

.app-menu-backdrop {
  display: none;
}

body.app-menu-drawer-open {
  overflow: hidden;
}

/* ----- User menu base ----- */

.user-menu {
  background-color: #f6f8fa;
  border-right: 1px solid #d0d7de;
  z-index: 1040;
}

.user-menu-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.user-menu-brand {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  padding: 12px 8px 8px 8px;
  border-bottom: 1px solid #d0d7de;
}

.user-menu-brand-link {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
  text-decoration: none;
  color: inherit;
  padding: 4px;
  border-radius: 6px;
}

.user-menu-brand-link:hover {
  background-color: #f3f4f6;
  text-decoration: none;
  color: inherit;
}

.user-menu-brand-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 4px;
}

.user-menu-brand-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: #3d50f5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.user-menu-collapse-toggle {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #656d76;
  cursor: pointer;
}

.user-menu-collapse-toggle:hover {
  background-color: #f3f4f6;
  color: #24292f;
}

.user-menu-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding: 8px 0 16px 0;
}

.user-menu-footer {
  flex-shrink: 0;
  border-top: 1px solid #d0d7de;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-menu-footer-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}

.user-menu-user-link {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10pt;
  color: var(--bs-body-color);
  text-decoration: none;
  min-width: 0;
  border-radius: 6px;
  padding: 4px 6px;
}

.user-menu-user-link:hover {
  background-color: #f3f4f6;
  text-decoration: none;
  color: var(--bs-body-color);
}

.user-menu-subscribe {
  width: 100%;
}

.user-menu-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35em;
  flex-shrink: 0;
  font-size: 1.05em;
  line-height: 1;
  text-align: center;
}

.user-menu-icon .bi {
  font-size: 1.1rem;
}

.user-menu-label {
  min-width: 0;
}

/* Menu Section Headers */
.user-menu-inner h4,
.user-menu-section-label {
  font-size: 12px;
  font-weight: 600;
  color: #656d76;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 24px 16px 8px 16px;
  padding: 0;
}

.user-menu-nav > h4:first-child,
.user-menu-nav > .user-menu-section-label:first-child {
  margin-top: 8px;
}

/* Action List Container */
.user-menu .list-group {
  border: none;
  background: transparent;
  margin: 0;
  padding: 0;
}

/* Action List Items */
.user-menu .list-group-item {
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  border-radius: 0;
}

.user-menu .list-group-item:first-child {
  border-top: none;
}

.user-menu .list-group-item:last-child {
  border-bottom: none;
}

/* Action Links */
.user-menu .list-group-item a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  color: #24292f;
  text-decoration: none;
  font-size: 14px;
  font-weight: 400;
  line-height: 20px;
  border-radius: 6px;
  margin: 0 8px;
  transition: background-color 0.15s ease, color 0.15s ease;
  position: relative;
}

/* Hover State */
.user-menu .list-group-item a:hover {
  background-color: #f3f4f6;
  color: #24292f;
  text-decoration: none;
}

/* Current Page Indicator */
.user-menu .list-group-item a[aria-current="page"],
.user-menu .list-group-item a.active,
.user-menu .list-group-item a:focus,
.user-menu .list-group-item a:active {
  font-weight: 600;
}

.user-menu .list-group-item a[aria-current="page"]:before,
.user-menu .list-group-item a.active:before,
.user-menu .list-group-item a:focus:before,
.user-menu .list-group-item a:active:before {
  content: "";
  display: block;
  width: 5px;
  height: 100%;
  background-color: #3d50f5;
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 8px;
}

.user-menu .list-group-item a:focus:before,
.user-menu .list-group-item a:active:before {
  background-color: grey;
}

/* Disabled/Unavailable Links */
.user-menu .list-group-item a.no-invites-available {
  color: #656d76;
  cursor: not-allowed;
  opacity: 0.6;
}

.user-menu .list-group-item a.no-invites-available:hover {
  background-color: transparent;
  color: #656d76;
}

/* Contact Section */
.user-menu .mt-4 {
  margin-top: 24px !important;
  padding: 0 16px;
}

.user-menu .mt-4[style*="text-align: center"] {
  text-align: center !important;
}

/* Admin Menu Section */
.user-menu .admin-section {
  border-top: 1px solid #d0d7de;
  margin-top: 24px;
  padding-top: 16px;
}

/* Focus visible for better accessibility */
.user-menu .list-group-item a:focus-visible {
  outline: 2px solid #3d50f5;
  outline-offset: -2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .user-menu .list-group-item a {
    border: 1px solid transparent;
  }

  .user-menu .list-group-item a:hover,
  .user-menu .list-group-item a:focus,
  .user-menu .list-group-item a:active,
  .user-menu .list-group-item a[aria-current="page"],
  .user-menu .list-group-item a.active {
    border-color: currentColor;
  }
}

/* Non-shell pages still use centered content */
.content-inner {
  max-width: 1000px;
  margin: 0 auto;
  padding-top: 1em;
}

.page-content {
  max-width: 1000px;
  margin: 0 auto;
}

/* Logged-in shell: keep content centered; 30% wider than previous 1000px cap */
.app-shell .content-inner,
.app-shell .page-content {
  max-width: 1000px;
  margin-left: auto;
  margin-right: auto;
}

/* ----- Mobile (&lt;768px): sticky top bar + drawer ----- */

@media (max-width: 767px) {
  .app-mobile-topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    position: sticky;
    top: 0;
    z-index: 1030;
    height: var(--app-mobile-topbar-height);
    padding: 0 10px;
    background-color: #f6f8fa;
    border-bottom: 1px solid #d0d7de;
    flex-shrink: 0;
  }

  .app-menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #24292f;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
  }

  .app-menu-toggle:hover {
    background-color: #f3f4f6;
  }

  .app-mobile-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    text-decoration: none;
    color: inherit;
  }

  .app-mobile-brand:hover {
    text-decoration: none;
    color: inherit;
  }

  .app-mobile-brand img {
    width: 24px;
    height: 24px;
    object-fit: contain;
    border-radius: 4px;
    flex-shrink: 0;
  }

  .app-mobile-brand-text {
    font-size: 0.9rem;
    font-weight: 600;
    color: #3d50f5;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .app-mobile-page-title {
    min-width: 0;
    flex: 1 1 auto;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--bs-body-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
  }

  .app-mobile-page-title::before {
    content: "·";
    margin: 0 0.35em;
    color: #656d76;
    font-weight: 400;
  }

  .user-menu {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(var(--app-menu-width-expanded), 86vw);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: none;
    padding: 0;
    border-right: 1px solid #d0d7de;
  }

  .app-shell.menu-open .user-menu {
    transform: translateX(0);
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.18);
  }

  .user-menu-brand {
    /* Brand lives in sticky top bar on mobile; keep compact header in drawer */
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
  }

  .user-menu-collapse-toggle {
    display: none !important;
  }

  .app-menu-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1035;
    background: rgba(0, 0, 0, 0.4);
    border: none;
    padding: 0;
    margin: 0;
  }

  .app-menu-backdrop[hidden] {
    display: none !important;
  }

  .app-shell .content-inner {
    min-height: calc(100vh - var(--app-mobile-topbar-height));
  }

  .user-menu .list-group-item a {
    padding: 12px 16px;
    font-size: 16px;
  }

  .user-menu-inner h4,
  .user-menu-section-label {
    margin: 16px 16px 8px 16px;
  }
}

/* ----- Desktop (≥768px): fixed collapsible sidebar ----- */

@media (min-width: 768px) {
  .app-shell.has-menu {
    flex-direction: row;
    align-items: stretch;
  }

  .app-mobile-topbar {
    display: none !important;
  }

  .app-menu-backdrop {
    display: none !important;
  }

  .user-menu {
    position: sticky;
    top: 0;
    align-self: flex-start;
    width: var(--app-menu-width-expanded);
    max-width: none;
    height: 100vh;
    flex: 0 0 var(--app-menu-width-expanded);
    padding: 0;
    transition: width 0.2s ease, flex-basis 0.2s ease;
    box-shadow: -12px -17px 10px -17px rgba(0, 0, 0, 0.86) inset;
    overflow: visible;
  }

  .user-menu-collapse-toggle {
    display: inline-flex;
  }

  .app-shell .content-inner {
    flex: 1 1 auto;
    min-height: 100vh;
    transition: none;
  }

  /* Collapsed icon rail */
  .app-shell.menu-collapsed .user-menu {
    width: var(--app-menu-width-collapsed);
    flex-basis: var(--app-menu-width-collapsed);
  }

  .app-shell.menu-collapsed .user-menu-brand-title,
  .app-shell.menu-collapsed .user-menu-label,
  .app-shell.menu-collapsed .user-menu-section-label,
  .app-shell.menu-collapsed .user-menu-inner h4,
  .app-shell.menu-collapsed .usage-menu-progress,
  .app-shell.menu-collapsed .user-menu-subscribe .user-menu-label {
    display: none;
  }

  .app-shell.menu-collapsed .user-menu-brand {
    justify-content: center;
    padding: 12px 4px 8px 4px;
  }

  .app-shell.menu-collapsed .user-menu-brand-link {
    flex: 0 0 auto;
    justify-content: center;
    padding: 4px;
  }

  .app-shell.menu-collapsed .user-menu-brand {
    flex-direction: column;
    gap: 4px;
  }

  .app-shell.menu-collapsed .user-menu .list-group-item a {
    justify-content: center;
    padding: 10px 8px;
    margin: 0 4px;
    gap: 0;
  }

  .app-shell.menu-collapsed .user-menu-footer-controls {
    flex-direction: column;
    justify-content: center;
  }

  .app-shell.menu-collapsed .user-menu-user-link {
    justify-content: center;
    padding: 6px;
  }

  .app-shell.menu-collapsed .user-menu-subscribe {
    padding-left: 0.35rem;
    padding-right: 0.35rem;
    font-size: 0;
  }

  .app-shell.menu-collapsed .user-menu-subscribe::before {
    content: "⭐";
    font-size: 1rem;
  }

  .app-shell.menu-collapsed .usage-menu-progress {
    display: none;
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  html:not(.theme-light) .user-menu,
  html:not(.theme-light) .app-mobile-topbar {
    background-color: #0d1117;
    border-right-color: #30363d;
    border-bottom-color: #30363d;
  }

  html:not(.theme-light) .user-menu-brand {
    border-bottom-color: #30363d;
  }

  html:not(.theme-light) .user-menu-footer {
    border-top-color: #30363d;
  }

  html:not(.theme-light) .user-menu .list-group-item a,
  html:not(.theme-light) .app-menu-toggle,
  html:not(.theme-light) .user-menu-user-link {
    color: var(--bs-body-color);
  }

  html:not(.theme-light) .user-menu .list-group-item a:hover,
  html:not(.theme-light) .user-menu-brand-link:hover,
  html:not(.theme-light) .user-menu-collapse-toggle:hover,
  html:not(.theme-light) .app-menu-toggle:hover,
  html:not(.theme-light) .user-menu-user-link:hover {
    background-color: #21262d;
    color: var(--bs-body-color);
  }

  html:not(.theme-light) .user-menu .list-group-item a.no-invites-available {
    color: #8b949e;
  }

  html:not(.theme-light) .user-menu .list-group-item a.no-invites-available:hover {
    color: #8b949e;
  }

  html:not(.theme-light) .user-menu-inner h4,
  html:not(.theme-light) .user-menu-section-label,
  html:not(.theme-light) .user-menu-collapse-toggle {
    color: #8b949e;
  }

  html:not(.theme-light) .user-menu .admin-section {
    border-top-color: #30363d;
  }

  html:not(.theme-light) .user-menu .list-group-item a[aria-current="page"]:before,
  html:not(.theme-light) .user-menu .list-group-item a.active:before {
    background-color: #4b91ff;
  }

  html:not(.theme-light) .user-menu-brand-title,
  html:not(.theme-light) .app-mobile-brand-text {
    color: #4b91ff;
  }
}

/* Manual theme overrides for menu */
html.theme-light .user-menu,
html.theme-light .app-mobile-topbar {
  background-color: #f6f8fa;
  border-right-color: #d0d7de;
  border-bottom-color: #d0d7de;
}

html.theme-light .user-menu .list-group-item a {
  color: #24292f;
}

html.theme-light .user-menu .list-group-item a:hover {
  background-color: #f3f4f6;
  color: #24292f;
}

html.theme-light .user-menu .list-group-item a.no-invites-available {
  color: #656d76;
}

html.theme-light .user-menu .list-group-item a.no-invites-available:hover {
  color: #656d76;
}

html.theme-light .user-menu-inner h4,
html.theme-light .user-menu-section-label {
  color: #656d76;
}

html.theme-light .user-menu .admin-section {
  border-top-color: #d0d7de;
}

html.theme-light .user-menu-brand-title,
html.theme-light .app-mobile-brand-text {
  color: #3d50f5;
}
