/**
 * ACMOBOOK Identity Hub — logged-in Account Drawer
 * Desktop: right-side drawer · Mobile (<768): bottom sheet
 * ALL rules scoped to #profileDrawer / #profileDrawerOverlay / .acm-hub-*
 */

/* ---------- Backdrop ---------- */
#profileDrawerOverlay.acm-hub-overlay,
#profileDrawerOverlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 30, 0.45);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.24s ease, visibility 0.24s ease;
  z-index: 14100;
}

#profileDrawerOverlay.acm-hub-overlay.active,
#profileDrawerOverlay.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  display: block;
}

#profileDrawerOverlay[hidden]:not(.active) {
  display: none !important;
}

#profileDrawerOverlay.active {
  display: block !important;
}

/* ---------- Desktop: RIGHT-SIDE DRAWER ---------- */
#profileDrawer.acm-hub-drawer,
#profileDrawer.mobile-right-panel.acm-hub-drawer,
#profileDrawer {
  --acm-hub-font: var(--acm-font, "Poppins", system-ui, -apple-system, sans-serif);
  --acm-hub-primary: var(--acm-primary, #635BFF);
  --acm-hub-primary-soft: rgba(99, 91, 255, 0.1);
  --acm-hub-text: var(--acm-text, #111827);
  --acm-hub-muted: var(--acm-text-soft, #667085);
  --acm-hub-border: var(--acm-border, #E7E8F2);

  position: fixed !important;
  top: 0 !important;
  right: 0 !important;
  left: auto !important;
  bottom: 0 !important;
  width: min(460px, 100vw) !important;
  max-width: 500px;
  height: 100vh !important;
  height: 100dvh !important;
  max-height: none;
  margin: 0;
  padding: 0;
  padding-bottom: env(safe-area-inset-bottom, 0);
  background: #fff;
  color: var(--acm-hub-text);
  font-family: var(--acm-hub-font);
  z-index: 14110;
  border: 0;
  border-left: 1px solid rgba(231, 232, 242, 0.9);
  border-radius: 24px 0 0 24px;
  box-shadow: -18px 0 48px rgba(17, 24, 39, 0.14);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  pointer-events: none;
  transform: translateX(104%) !important;
  opacity: 1;
  visibility: visible;
  transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}

#profileDrawer.acm-hub-drawer.active,
#profileDrawer.mobile-right-panel.acm-hub-drawer.active,
#profileDrawer.active {
  right: 0 !important;
  transform: translateX(0) !important;
  pointer-events: auto;
}

#profileDrawer.mobile-right-panel {
  width: min(460px, 100vw) !important;
  right: 0 !important;
  top: 0 !important;
}

/* ---------- Handle (mobile only) ---------- */
#profileDrawer .acm-hub-drawer__handle {
  display: none;
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: #D0D5DD;
  margin: 10px auto 0;
  flex-shrink: 0;
}

/* ---------- Header ---------- */
#profileDrawer .acm-hub-drawer__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 8px;
  flex-shrink: 0;
}

#profileDrawer .acm-hub-drawer__brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

#profileDrawer .acm-hub-drawer__logo {
  display: block;
  width: auto;
  height: 28px;
  max-width: 140px;
  object-fit: contain;
  object-position: left center;
}

#profileDrawer .acm-hub-drawer__tagline {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #98A2B3;
  line-height: 1.2;
}

#profileDrawer .acm-hub-drawer__close {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #667085;
  font-size: 22px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  margin: -6px -6px 0 0;
}

#profileDrawer .acm-hub-drawer__close:hover,
#profileDrawer .acm-hub-drawer__close:focus-visible {
  background: #F4F5FB;
  color: #111827;
  outline: none;
}

/* ---------- Body ---------- */
#profileDrawer .acm-hub-drawer__body {
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ---------- One-line profile switcher ---------- */
#profileDrawer .acm-hub-switch {
  margin: 4px 0 12px;
  position: relative;
}

#profileDrawer .acm-hub-switch__trigger {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 10px 12px;
  border: 1px solid var(--acm-hub-border);
  border-radius: 14px;
  background: #fff;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font: inherit;
  transition: background 0.18s ease, border-color 0.18s ease;
}

#profileDrawer .acm-hub-switch__trigger:hover,
#profileDrawer .acm-hub-switch__trigger:focus-visible {
  background: #F8F7FF;
  border-color: rgba(99, 91, 255, 0.28);
  outline: none;
}

#profileDrawer .acm-hub-switch__trigger--static {
  cursor: default;
  pointer-events: none;
}

#profileDrawer .acm-hub-switch__trigger[aria-expanded="true"] {
  background: #F8F7FF;
  border-color: rgba(99, 91, 255, 0.35);
}

#profileDrawer .acm-hub-switch__trigger[aria-expanded="true"] .acm-hub-switch__chevron {
  transform: rotate(180deg);
}

#profileDrawer .acm-hub-switch__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(145deg, #EDE9FE, #F5F3FF);
  color: var(--acm-hub-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
  font-size: 14px;
  font-weight: 700;
}

#profileDrawer .acm-hub-switch__avatar--rect {
  border-radius: 10px;
}

#profileDrawer .acm-hub-switch__avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#profileDrawer .acm-hub-switch__initial {
  position: relative;
  z-index: 0;
}

#profileDrawer .acm-hub-switch__meta {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#profileDrawer .acm-hub-switch__name {
  font-size: 15px;
  font-weight: 700;
  color: #0F172A;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#profileDrawer .acm-hub-switch__sub {
  font-size: 12px;
  font-weight: 500;
  color: #667085;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#profileDrawer .acm-hub-switch__chevron {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--acm-hub-primary-soft);
  color: var(--acm-hub-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s ease;
  font-size: 12px;
}

/* Expandable panel */
#profileDrawer .acm-hub-switch__panel {
  margin-top: 8px;
  padding: 10px 8px 8px;
  border-radius: 14px;
  background: #FAFBFC;
  border: 1px solid #EEF0F6;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.22s ease, opacity 0.2s ease, margin 0.2s ease, padding 0.2s ease;
}

#profileDrawer .acm-hub-switch__panel.is-open,
#profileDrawer .acm-hub-switch__panel:not([hidden]) {
  max-height: 520px;
  opacity: 1;
}

#profileDrawer .acm-hub-switch__panel[hidden] {
  display: block !important;
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-width: 0;
  pointer-events: none;
}

#profileDrawer .acm-hub-switch__panel-label {
  margin: 0 8px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #98A2B3;
}

#profileDrawer .acm-hub-switch__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#profileDrawer .acm-hub-switch .acm-profile-switch__btn {
  width: 100%;
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

#profileDrawer .acm-hub-switch .acm-profile-switch__btn:hover,
#profileDrawer .acm-hub-switch .acm-profile-switch__btn:focus-visible {
  background: #fff;
  outline: none;
  box-shadow: 0 0 0 1px rgba(99, 91, 255, 0.18);
}

#profileDrawer .acm-hub-switch .acm-profile-switch__btn.is-active {
  background: var(--acm-hub-primary-soft);
  cursor: default;
}

#profileDrawer .acm-hub-switch .acm-profile-switch__name {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#profileDrawer .acm-hub-switch .acm-profile-switch__type {
  font-size: 12px;
  color: #667085;
}

#profileDrawer .acm-hub-switch .acm-profile-switch__check {
  margin-left: auto;
  color: var(--acm-hub-primary);
  font-weight: 700;
}

#profileDrawer .acm-hub-switch .acm-profile-switch__status {
  margin: 8px 4px 0;
  font-size: 12px;
  color: #667085;
}

#profileDrawer .acm-hub-switch .acm-profile-switch__status.is-error {
  color: #B42318;
}

#profileDrawer .acm-hub-switch .acm-profile-switch__btn.is-switching {
  pointer-events: none;
}

#profileDrawer .acm-hub-switch.is-loading .acm-hub-switch__panel {
  opacity: 0.85;
}

/* ---------- Create another profile ---------- */
#profileDrawer .acm-hub-create {
  margin-top: 12px;
  padding-top: 4px;
}

#profileDrawer .acm-hub-create[hidden] {
  display: none !important;
}

#profileDrawer .acm-hub-create__list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#profileDrawer .acm-hub-create__row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 10px 10px;
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s ease;
}

#profileDrawer .acm-hub-create__row:hover,
#profileDrawer .acm-hub-create__row:focus-visible {
  background: #fff;
  outline: none;
  box-shadow: 0 0 0 1px rgba(99, 91, 255, 0.18);
}

#profileDrawer .acm-hub-create__plus {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(99, 91, 255, 0.1);
  color: var(--acm-hub-primary, #635BFF);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
}

#profileDrawer .acm-hub-create__meta {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#profileDrawer .acm-hub-create__title {
  font-size: 13px;
  font-weight: 700;
  color: #0F172A;
  line-height: 1.3;
}

#profileDrawer .acm-hub-create__desc {
  font-size: 11px;
  font-weight: 500;
  color: #667085;
  line-height: 1.35;
}

#profileDrawer .acm-hub-create__chevron {
  color: #98A2B3;
  font-size: 12px;
  flex-shrink: 0;
}

/* ---------- Contextual menu ---------- */
#profileDrawer .acm-hub-menu {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 4px;
}

#profileDrawer .acm-hub-section-label,
#profileDrawer .mobile-menu-heading.acm-hub-section-label {
  margin: 8px 8px 10px;
  padding: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #98A2B3;
  background: transparent;
  border: 0;
}

#profileDrawer .acm-hub-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 12px;
  color: #111827;
  text-decoration: none;
  transition: background 0.15s ease;
}

#profileDrawer .acm-hub-link:hover,
#profileDrawer .acm-hub-link:focus-visible {
  background: #F7F8FC;
  outline: none;
}

#profileDrawer .acm-hub-link.is-active {
  background: var(--acm-hub-primary-soft);
  color: #3F3AB8;
}

#profileDrawer .acm-hub-link__left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

#profileDrawer .acm-hub-link__left i {
  font-size: 20px;
  width: 22px;
  text-align: center;
  color: #667085;
  flex-shrink: 0;
}

#profileDrawer .acm-hub-link.is-active .acm-hub-link__left i {
  color: var(--acm-hub-primary);
}

#profileDrawer .acm-hub-link__left span {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#profileDrawer .acm-hub-link__right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  color: #98A2B3;
  font-size: 12px;
}

#profileDrawer .acm-hub-badge,
#profileDrawer .mobile-count.acm-hub-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #F04438;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

/* ---------- Universal actions ---------- */
#profileDrawer .acm-hub-universal {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #EEF0F6;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#profileDrawer .acm-hub-link--logout {
  color: #B42318;
}

#profileDrawer .acm-hub-link--logout .acm-hub-link__left i {
  color: #B42318;
}

/* Hide legacy dropdown when hub drawer is the primary gateway */
#profileDropdown.acm-hub-dropdown,
.header-dropdown.acm-hub-dropdown {
  display: none !important;
}

body.acm-hub-drawer-open {
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  #profileDrawer,
  #profileDrawerOverlay,
  #profileDrawer .acm-hub-switch__panel,
  #profileDrawer .acm-hub-switch__chevron {
    transition: none !important;
  }
}

/* ---------- Mobile / tablet bottom sheet ---------- */
@media (max-width: 767.98px) {
  #profileDrawer.acm-hub-drawer,
  #profileDrawer.mobile-right-panel.acm-hub-drawer,
  #profileDrawer {
    top: auto !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-width: none;
    height: auto !important;
    max-height: 92vh;
    max-height: 92dvh;
    border-radius: 28px 28px 0 0;
    border-left: 0;
    box-shadow: 0 -12px 40px rgba(17, 24, 39, 0.16);
    transform: translateY(108%) !important;
  }

  #profileDrawer.acm-hub-drawer.active,
  #profileDrawer.mobile-right-panel.acm-hub-drawer.active,
  #profileDrawer.active {
    transform: translateY(0) !important;
  }

  #profileDrawer .acm-hub-drawer__handle {
    display: block;
  }

  #profileDrawer .acm-hub-drawer__top {
    padding: 6px 16px 4px;
  }

  #profileDrawer .acm-hub-drawer__body {
    padding: 4px 14px calc(20px + env(safe-area-inset-bottom, 0));
  }

  #profileDrawer .acm-hub-switch__name {
    font-size: 14px;
  }

  #profileDrawer .acm-hub-switch__sub {
    font-size: 11px;
  }
}

@media (max-width: 360px) {
  #profileDrawer .acm-hub-switch__sub {
    font-size: 10.5px;
  }

  #profileDrawer .acm-hub-link__left span {
    font-size: 13px;
  }
}

/* Desktop width band */
@media (min-width: 768px) {
  #profileDrawer.acm-hub-drawer,
  #profileDrawer {
    width: min(460px, 42vw) !important;
  }
}

@media (min-width: 1280px) {
  #profileDrawer.acm-hub-drawer,
  #profileDrawer {
    width: 460px !important;
  }
}
