/* =========================================================================
   ACCOUNT PAGES (profile.html, orders.html, collections.html)

   1. The account sidebar, in the header account menu's shape: "My Account"
      (opens its three settings) and the other pages with a red 18px Lucide
      icon; the active item in the logo red with the thin glowing bar and
      the soft aura. No collapse rail (owner's choice). homepage.js
      watchHubNav() opens and closes "My Account"; when closed it is listed
      on html[data-account-nav-closed].
   2. The loading line every account section shows while its real data
      loads (the Favorites one: a spinning ring and "Loading your ...").

   Token-only, loaded last on the three pages, so light and dark need no
   separate surfaces.
   ========================================================================= */

/* ------------------------------------------------------------ sidebar */
.hub-sidebar {
  width: 300px;
  flex-shrink: 0;
  height: fit-content;
  padding: 18px 14px 14px;
  border: 1px solid var(--moto-border);
  border-radius: 12px;
  background: var(--moto-sidebar-glass);
  /* Follows the page as the content scrolls, tucked under the fixed header
     (137 px) and scrolling inside itself on short screens. */
  position: sticky;
  top: 157px;
  align-self: flex-start;
  max-height: calc(100vh - 177px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--moto-overlay-strong) transparent;
}

/* Avatar beside the name and an "Edit profile" link, as one row */
.hub-user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 6px;
  padding: 0 6px 16px;
  border-bottom: 1px solid var(--moto-border);
}

.hub-sidebar .hub-user-info .hub-avatar {
  width: 48px;
  height: 48px;
  margin: 0;
  flex-shrink: 0;
  border: 1px solid var(--moto-border);
  background-color: var(--moto-panel-inset);
  color: var(--moto-text);
  font-size: 1.1rem;
  font-weight: 800;
}

.hub-user-meta {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.hub-user-info h3 {
  margin: 0;
  overflow: hidden;
  color: var(--moto-text);
  font-size: 0.95rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Until the name and photo are known: quiet pulsing shapes of the same size,
   never a placeholder name */
.hub-user-info h3:empty {
  width: 8em;
  height: 1.3em;
  border-radius: 6px;
  background: var(--moto-overlay-strong);
  animation: account-pulse 1.4s ease-in-out infinite alternate;
}

.hub-sidebar .hub-user-info .hub-avatar:empty {
  animation: account-pulse 1.4s ease-in-out infinite alternate;
}

.hub-edit-profile {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--moto-muted);
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  transition: color var(--dur-fast) ease;
}

.hub-edit-profile:hover,
.hub-edit-profile:focus-visible {
  color: var(--moto-text);
}

.hub-edit-icon {
  width: 13px;
  height: 13px;
}

/* The header account menu's shape (homepage.js accountMenuLinksHtml):
   "My Account", with its icon and a chevron, opens the three settings,
   listed as text under its label; the other pages follow as items with a
   red icon (Jemmy, Oct 9). */
.hub-nav,
.hub-nav-sub-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.hub-nav {
  display: grid;
  gap: 2px;
  margin-top: 8px;
}

/* "My Account" is the group's toggle, drawn as an item */
.hub-nav-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 42px;
  margin: 0;
  padding: 10px 12px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--moto-text);
  font: 700 0.9375rem/1.25 'Inter', sans-serif;
  text-align: left;
  cursor: pointer;
  transition: background 220ms var(--ix-ease-out);
}

.hub-nav-heading:hover {
  background: linear-gradient(90deg, var(--moto-overlay) 0%, transparent 100%);
}

.hub-nav-heading:focus-visible {
  outline: 2px solid var(--moto-red);
  outline-offset: 2px;
}

.hub-nav-chevron {
  flex-shrink: 0;
  margin-left: auto;
  color: var(--moto-muted);
  transition: transform 220ms var(--ix-ease-out);
}

.hub-nav-group-body {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 240ms var(--ix-ease-out);
}

html[data-account-nav-closed~="account"] .hub-nav-group[data-group="account"] .hub-nav-group-body {
  grid-template-rows: 0fr;
}

html[data-account-nav-closed~="account"] .hub-nav-group[data-group="account"] .hub-nav-chevron {
  transform: rotate(-90deg);
}

/* A closed "My Account" that holds the current page says so in red */
html[data-account-nav-closed~="account"] .hub-nav-group[data-group="account"]:has(.hub-nav-btn.active) .hub-nav-heading-label {
  color: var(--moto-red);
}

/* The settings list clips while it opens and closes; the side margins leave
   room for the active item's glow */
.hub-nav-sub-list {
  display: grid;
  gap: 2px;
  min-height: 0;
  margin: 0 -14px;
  padding: 0 14px;
  overflow: hidden;
}

/* Items */
.hub-nav-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--moto-text-secondary);
  font: 600 0.9375rem/1.25 'Inter', sans-serif;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition:
    background 220ms var(--ix-ease-out),
    color 220ms var(--ix-ease-out),
    scale var(--ix-press-dur, 120ms) var(--ix-ease-out);
}

/* The settings under "My Account": text only, lined up with its label
   (12px padding + 18px icon + 12px gap) */
.hub-nav-sub-list .hub-nav-btn {
  min-height: 38px;
  padding: 8px 12px 8px 42px;
  font-size: 0.9rem;
}

.hub-nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--moto-red);
  stroke: currentColor;
  transition: transform 220ms var(--ix-spring);
}

.hub-nav-label {
  position: relative;
  z-index: 2;
  min-width: 0;
}

.hub-nav-btn:not(.active):hover {
  background: linear-gradient(90deg, var(--moto-overlay) 0%, transparent 100%);
  color: var(--moto-text);
}

.hub-nav-btn:not(.active):hover .hub-nav-icon,
.hub-nav-heading:hover .hub-nav-icon {
  transform: scale(1.06);
}

.hub-nav-btn:active {
  scale: var(--ix-press-btn, 0.96);
}

.hub-nav-btn:focus-visible {
  outline: 2px solid var(--moto-red);
  outline-offset: 2px;
}

/* Active item: logo red, thin glowing bar on the left edge, soft aura */
.hub-nav-btn.active {
  background: transparent;
  color: var(--moto-red);
}

.hub-nav-btn.active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 1.5px;
  height: 100%;
  background: linear-gradient(0deg, transparent 0%, var(--moto-red) 50%, transparent 100%);
  box-shadow:
    0 0 10px 2px color-mix(in srgb, var(--moto-red) 80%, transparent),
    -3px 0 18px 4px color-mix(in srgb, var(--moto-red) 45%, transparent);
  pointer-events: none;
  z-index: 3;
}

.hub-nav-btn.active::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 150px;
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--moto-red) 18%, transparent) 0%,
    color-mix(in srgb, var(--moto-red) 5%, transparent) 50%,
    transparent 100%
  );
  pointer-events: none;
  z-index: 1;
}

.hub-nav-btn.active:hover {
  background: linear-gradient(90deg, color-mix(in srgb, var(--moto-red) 8%, transparent) 0%, transparent 100%);
}

.hub-nav-btn.active .hub-nav-icon {
  position: relative;
  z-index: 2;
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--moto-red) 70%, transparent));
  transform: scale(1.05);
}

.hub-nav-btn.active .hub-nav-label {
  text-shadow: 0 0 12px color-mix(in srgb, var(--moto-red) 40%, transparent);
}

/* Light mode drops the text and icon glow and softens the bar, like the
   Staff Portal's light theme */
html[data-theme="light"] .hub-nav-btn:not(.active):hover,
html[data-theme="light"] .hub-nav-heading:hover {
  background: var(--moto-overlay);
}

html[data-theme="light"] .hub-nav-btn.active::before {
  box-shadow: 0 0 8px color-mix(in srgb, var(--moto-red) 50%, transparent);
}

html[data-theme="light"] .hub-nav-btn.active::after {
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--moto-red) 12%, transparent) 0%,
    color-mix(in srgb, var(--moto-red) 3%, transparent) 50%,
    transparent 100%
  );
}

html[data-theme="light"] .hub-nav-btn.active .hub-nav-icon {
  filter: none;
}

html[data-theme="light"] .hub-nav-btn.active .hub-nav-label {
  text-shadow: none;
}

/* Phones and tablets: the sidebar sits above the content and the items are
   one sideways-scrolling row of chips ("My Account" and its state set aside) */
@media (max-width: 900px) {
  .hub-sidebar {
    width: 100%;
    position: static;
    max-height: none;
    overflow: visible;
    padding: 16px 0 0;
  }

  .hub-user-info {
    margin: 0;
    padding: 0 16px 14px;
  }

  .hub-nav {
    display: flex;
    gap: 8px;
    margin: 0;
    padding: 12px 16px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .hub-nav::-webkit-scrollbar {
    display: none;
  }

  .hub-nav > .hub-nav-group,
  .hub-nav-group-body,
  .hub-nav-sub-list {
    display: contents;
  }

  .hub-nav-heading,
  .hub-nav-btn .hub-nav-icon {
    display: none;
  }

  .hub-nav > li,
  .hub-nav-sub-list > li {
    flex: 0 0 auto;
    margin: 0;
  }

  .hub-nav-btn,
  .hub-nav-sub-list .hub-nav-btn {
    width: auto;
    min-height: 0;
    padding: 8px 14px;
    border: 1px solid var(--moto-border);
    border-radius: 999px;
    background: var(--moto-panel-soft);
    font-size: 0.82rem;
    white-space: nowrap;
  }

  .hub-nav-btn.active {
    border-color: var(--moto-red);
    background: var(--moto-red-glow);
  }

  .hub-nav-btn.active::before,
  .hub-nav-btn.active::after {
    display: none;
  }

  .hub-nav-btn.active .hub-nav-label {
    text-shadow: none;
  }
}

/* ------------------------------------------------- profile avatar
   My Profile's avatar card (right column, first on phones) and the preset
   picker that "Change avatar" opens. Markup, text and behaviour are
   home-profile.js's; this is only the look: framed tiles, a neutral ring
   around the photo, and the product page's red-ring language for the chosen
   preset. */
.profile-avatar-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 24px 20px 20px;
  border: 1px solid var(--moto-border);
  border-radius: 16px;
  background: var(--moto-panel-inset);
  text-align: center;
}

.hub-avatar.hub-avatar-lg {
  width: 120px;
  height: 120px;
  margin: 6px 0 4px;
  border: 0;
  background-color: var(--moto-panel-soft);
  color: var(--moto-text);
  font-size: 2.6rem;
  box-shadow:
    0 0 0 4px var(--moto-panel-inset),
    0 0 0 5px var(--moto-border-hover),
    var(--moto-card-shadow);
}

.profile-avatar-hint {
  margin: 0;
  color: var(--moto-muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

/* "Change avatar" / "Close" and the picker's "Done": one neutral button */
#avatarPickerToggle,
#avatarPickerDone {
  min-height: 40px;
  padding: 0 18px;
  border: 1px solid var(--moto-border);
  border-radius: var(--btn-radius, 12px);
  background: var(--moto-panel-soft);
  color: var(--moto-text);
  font-size: 0.86rem;
  font-weight: 600;
  transition:
    background-color var(--dur-fast) ease,
    border-color var(--dur-fast) ease,
    scale var(--ix-press-dur, 120ms) var(--ix-ease-out);
}

#avatarPickerToggle {
  width: 100%;
}

#avatarPickerToggle:hover,
#avatarPickerDone:hover,
#avatarPickerToggle[aria-expanded="true"] {
  border-color: var(--moto-border-hover);
  background: var(--moto-panel-hover);
  color: var(--moto-text);
}

#avatarPickerToggle:active,
#avatarPickerDone:active {
  scale: var(--ix-press-btn, 0.96);
}

/* The picker */
.avatar-preset-panel {
  margin: 28px 0 0;
  padding: 22px 22px 18px;
  border: 1px solid var(--moto-border);
  border-radius: 16px;
  background: var(--moto-panel-inset);
  container-type: inline-size;
}

.avatar-preset-panel:not([hidden]) {
  animation: avatar-panel-in 240ms var(--ix-ease-out) both;
}

.avatar-preset-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--moto-border);
}

.avatar-preset-head h3 {
  margin: 0 0 4px;
  color: var(--moto-text);
  font-size: 1rem;
  font-weight: 700;
}

.avatar-preset-head p {
  margin: 0;
  color: var(--moto-muted);
  font-size: 0.85rem;
}

.avatar-upload-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 18px 0 16px;
  padding: 16px;
  border: 1px solid var(--moto-border);
  border-radius: 12px;
  background: var(--moto-panel-soft);
}

.avatar-upload-copy h4 {
  margin: 0 0 4px;
  color: var(--moto-text);
  font-size: 0.9rem;
  font-weight: 700;
}

.avatar-upload-copy p {
  margin: 0;
  color: var(--moto-muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.avatar-upload-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 8px;
}

.avatar-upload-actions .hub-btn {
  min-height: 40px;
  padding: 0 16px;
  font-size: 0.84rem;
}

.avatar-preset-title {
  margin: 0;
  color: var(--moto-muted);
  font-size: 0.82rem;
  font-weight: 700;
}

/* 18 presets: six across (three full rows), three across when narrow */
.avatar-preset-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

@container (max-width: 560px) {
  .avatar-preset-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
  }
}

@media (max-width: 480px) {
  .avatar-preset-panel {
    padding: 18px 14px 14px;
  }
}

@media (max-width: 640px) {
  .avatar-upload-row {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .avatar-upload-actions {
    width: 100%;
  }

  .avatar-upload-actions .hub-btn {
    flex: 1 1 auto;
  }
}

.avatar-preset-option {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 16px 8px 12px;
  border: 1px solid var(--moto-border);
  border-radius: 14px;
  background: var(--moto-panel-soft);
  color: var(--moto-text-secondary);
  font: inherit;
  cursor: pointer;
  transition:
    background-color var(--dur-fast) ease,
    border-color var(--dur-fast) ease,
    scale var(--ix-press-dur, 120ms) var(--ix-ease-out);
}

.avatar-preset-option img {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 0 0 2px var(--moto-panel-soft), 0 0 0 3px var(--moto-border);
  transition: transform 220ms var(--ix-spring), box-shadow var(--dur-fast) ease;
}

.avatar-preset-option span {
  max-width: 100%;
  overflow: hidden;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Narrow picker (after the base tile rules so it wins): smaller pictures,
   and the two-word names wrap instead of being cut off */
@container (max-width: 560px) {
  .avatar-preset-option {
    gap: 8px;
    padding: 14px 6px 10px;
  }

  .avatar-preset-option img {
    width: 52px;
    height: 52px;
  }

  .avatar-preset-option span {
    overflow: visible;
    font-size: 0.72rem;
    text-align: center;
    white-space: normal;
  }
}

@media (hover: hover) and (pointer: fine) {
  .avatar-preset-option:not(:disabled):hover {
    border-color: var(--moto-border-hover);
    background: var(--moto-panel-hover);
    color: var(--moto-text);
  }

  .avatar-preset-option:not(:disabled):hover img {
    transform: scale(1.06);
  }
}

.avatar-preset-option:active:not(:disabled) {
  scale: var(--ix-press-btn, 0.96);
}

.avatar-preset-option:focus-visible {
  outline: 2px solid var(--moto-red);
  outline-offset: 2px;
}

/* The chosen preset: red hairline, faint red tint, red ring on the picture
   and a check badge in the corner */
.avatar-preset-option.is-selected {
  border-color: var(--moto-red);
  background: color-mix(in srgb, var(--moto-red) 8%, var(--moto-panel-soft));
  color: var(--moto-text);
}

.avatar-preset-option.is-selected img {
  box-shadow: 0 0 0 2px var(--moto-panel-soft), 0 0 0 4px var(--moto-red);
}

.avatar-preset-option.is-selected::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--moto-red-solid) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E") center / 11px 11px no-repeat;
  animation: avatar-check-in 240ms var(--ix-ease-out) both;
}

/* While a choice is being saved */
.avatar-preset-option:disabled {
  opacity: 0.55;
  cursor: progress;
}

.avatar-save-status {
  min-height: 20px;
  margin: 14px 0 0;
  color: var(--moto-success);
  font-size: 0.82rem;
}

.avatar-save-status.is-error {
  color: var(--moto-danger);
}

@keyframes avatar-panel-in {
  from { opacity: 0; translate: 0 6px; }
  to { opacity: 1; translate: 0 0; }
}

@keyframes avatar-check-in {
  from { opacity: 0; scale: 0.4; }
  to { opacity: 1; scale: 1; }
}

@media (max-width: 760px) {
  .profile-avatar-card {
    order: -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .avatar-preset-panel:not([hidden]) {
    animation-name: avatar-panel-fade;
  }

  .avatar-preset-option,
  .avatar-preset-option img,
  #avatarPickerToggle,
  #avatarPickerDone {
    transition: none;
  }

  .avatar-preset-option.is-selected::after {
    animation: none;
  }
}

@keyframes avatar-panel-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------------------------------------------------- loading line */
.account-loading {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0;
  padding: 72px 16px;
  color: var(--moto-muted);
  font-size: 0.95rem;
}

.account-spinner {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  border: 2px solid var(--moto-border-subtle);
  border-top-color: var(--moto-red);
  border-radius: 50%;
  animation: account-spin 0.8s linear infinite;
}

/* The same line when the data could not be read: what happened and a retry */
.account-load-error {
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

.account-load-error button {
  min-height: 40px;
  padding: 0 18px;
  border: 1px solid var(--moto-border);
  border-radius: var(--btn-radius, 12px);
  background: var(--moto-panel-soft);
  color: var(--moto-text);
  font: 600 0.88rem 'Inter', sans-serif;
  cursor: pointer;
  transition: background-color var(--dur-fast) ease, border-color var(--dur-fast) ease;
}

.account-load-error button:hover {
  border-color: var(--moto-border-hover);
  background: var(--moto-panel-hover);
}

/* A profile section waits for its data: only its title, subtitle and the
   loading line show (home-profile.js clears is-loading) */
.hub-tab-content.is-loading > :not(.hub-title):not(.hub-subtitle):not(.account-loading) {
  display: none !important;
}

.hub-tab-content:not(.is-loading) > .account-loading {
  display: none;
}

@keyframes account-spin {
  to { rotate: 360deg; }
}

@keyframes account-pulse {
  from { opacity: 1; }
  to { opacity: 0.45; }
}

@media (prefers-reduced-motion: reduce) {
  .hub-nav-chevron,
  .hub-nav-group-body,
  .hub-nav-btn,
  .hub-nav-icon {
    transition: none;
  }

  .hub-user-info h3:empty,
  .hub-sidebar .hub-user-info .hub-avatar:empty {
    animation: none;
  }

  .account-spinner {
    animation-duration: 2.4s;
  }
}
