/* ============================================
   ARSES Marketplace Explorer (E2)
   Reusable component — desktop + mobile
   ============================================ */

.mpx-explorer {
  --mpx-green: #1f7a5c;
  --mpx-green-dark: #165a44;
  --mpx-green-soft: rgba(31, 122, 92, 0.08);
  --mpx-text: #1a2e28;
  --mpx-muted: #6b7280;
  --mpx-bg: #ffffff;
  --mpx-bg-subtle: #f7f8f7;
  --mpx-line: rgba(31, 122, 92, 0.1);
  --mpx-radius-lg: 18px;
  --mpx-height: clamp(620px, 72vh, 760px);

  color: var(--mpx-text);
}

/* Loading state (E3.4) */
.mpx-explorer--loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 480px;
  background: var(--mpx-bg);
  border: 1px solid var(--mpx-line);
  border-radius: var(--mpx-radius-lg);
}

.mpx-explorer__loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 48px 24px;
  text-align: center;
  color: var(--mpx-muted);
}

.mpx-explorer__loading p {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 500;
}

.mpx-explorer__loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(31, 122, 92, 0.15);
  border-top-color: var(--mpx-green);
  border-radius: 50%;
  animation: mpx-spin 0.8s linear infinite;
}

@keyframes mpx-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Source badge (E3.4) */
.mpx-explorer__source {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 6;
  padding: 4px 10px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--mpx-muted);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--mpx-line);
  border-radius: 999px;
  pointer-events: none;
}

.mpx-explorer__source[data-mpx-source-type="api"] {
  color: var(--mpx-green-dark);
  background: rgba(31, 122, 92, 0.06);
}

/* Empty sections (E3.5) */
.mpx-sections__empty {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  min-height: 200px;
  padding: 32px 20px;
  text-align: center;
  color: var(--mpx-muted);
}

.mpx-sections__empty[hidden],
.mpx-sections__search-empty[hidden] {
  display: none !important;
}

.mpx-sections__empty-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--mpx-text);
}

.mpx-sections__empty p {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.5;
}

.mpx-explorer--full .mpx-explorer__layout {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0;
  height: auto;
  min-height: 480px;
  max-height: min(720px, 78vh);
  overflow: hidden;
  background: var(--mpx-bg);
  border: 1px solid var(--mpx-line);
  border-radius: var(--mpx-radius-lg);
}

/* Mobile header */
.mpx-mobile-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--mpx-bg);
  border-bottom: 1px solid var(--mpx-line);
}

.mpx-mobile-header__back {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  color: var(--mpx-green-dark);
  background: var(--mpx-bg-subtle);
  border: none;
  border-radius: 10px;
  cursor: pointer;
}

.mpx-mobile-header__back svg {
  width: 20px;
  height: 20px;
}

.mpx-mobile-header__back:focus-visible {
  outline: 2px solid var(--mpx-green);
  outline-offset: 2px;
}

.mpx-mobile-header__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.mpx-mobile-header__context {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--mpx-muted);
}

.mpx-mobile-header__title {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--mpx-text);
  line-height: 1.3;
}

/* Mobile drill-down: one panel at a time */
.mpx-explorer__groups,
.mpx-explorer__sections,
.mpx-explorer__details {
  display: none;
  min-height: 0;
  min-width: 0;
}

.mpx-explorer[data-mpx-view="groups"] .mpx-explorer__groups {
  display: block;
}

.mpx-explorer[data-mpx-view="sections"] .mpx-explorer__sections {
  display: block;
}

.mpx-explorer[data-mpx-view="details"] .mpx-explorer__details {
  display: block;
}

.mpx-explorer[data-mpx-view="search"] .mpx-explorer__search-layer {
  display: block;
}

.mpx-explorer__search-layer {
  display: none;
}

.mpx-explorer[data-mpx-view="search"] .mpx-explorer__groups,
.mpx-explorer[data-mpx-view="search"] .mpx-explorer__sections,
.mpx-explorer[data-mpx-view="search"] .mpx-explorer__details {
  display: none !important;
}

.mpx-explorer__scroll {
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(31, 122, 92, 0.25) transparent;
}

.mpx-explorer__scroll::-webkit-scrollbar {
  width: 6px;
}

.mpx-explorer__scroll::-webkit-scrollbar-thumb {
  background: rgba(31, 122, 92, 0.2);
  border-radius: 999px;
}

/* LEFT: Groups */
.mpx-explorer__groups {
  min-height: 0;
  background: var(--mpx-bg-subtle);
  border-right: 1px solid var(--mpx-line);
}

.mpx-groups__list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px 16px;
  list-style: none;
}

.mpx-groups__btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 12px 14px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--mpx-text);
  text-align: left;
  background: var(--mpx-bg);
  border: 1px solid var(--mpx-line);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.mpx-groups__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.mpx-groups__btn:hover {
  background: var(--mpx-green-soft);
}

.mpx-groups__btn.is-active {
  color: var(--mpx-green-dark);
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.mpx-groups__btn:focus-visible {
  outline: 2px solid var(--mpx-green);
  outline-offset: 1px;
}

.mpx-groups__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  color: var(--mpx-green);
}

.mpx-groups__btn.is-active .mpx-groups__icon {
  color: var(--mpx-green-dark);
}

.mpx-groups__icon svg {
  width: 18px;
  height: 18px;
}

.mpx-groups__label {
  line-height: 1.25;
}

.mpx-groups__meta {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--mpx-muted);
}

.mpx-groups__chevron {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  color: #b0bab4;
}

.mpx-groups__chevron svg {
  width: 18px;
  height: 18px;
}

/* CENTER: Sections */
.mpx-explorer__sections {
  min-height: 0;
  background: var(--mpx-bg);
  border-right: 1px solid var(--mpx-line);
}

.mpx-sections__list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 12px 16px 16px;
  list-style: none;
}

.mpx-sections__btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 12px 14px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--mpx-text);
  text-align: left;
  background: var(--mpx-bg);
  border: 1px solid var(--mpx-line);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.mpx-sections__content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.mpx-sections__title {
  font-weight: 600;
  line-height: 1.3;
}

.mpx-sections__meta {
  font-size: 0.75rem;
  color: var(--mpx-muted);
}

.mpx-sections__chevron {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  color: #b0bab4;
}

.mpx-sections__chevron svg {
  width: 18px;
  height: 18px;
}

.mpx-sections__btn:hover {
  color: var(--mpx-text);
  background: var(--mpx-green-soft);
}

.mpx-sections__btn.is-active {
  font-weight: 600;
  color: var(--mpx-green-dark);
  background: var(--mpx-green-soft);
}

.mpx-sections__btn:focus-visible {
  outline: 2px solid var(--mpx-green);
  outline-offset: 1px;
}

.mpx-groups__btn.is-disabled,
.mpx-groups__btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.mpx-sections__loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 180px;
  padding: 24px 20px;
  text-align: center;
  color: var(--mpx-muted);
}

.mpx-sections__loading[hidden] {
  display: none !important;
}

.mpx-sections__loading p {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 500;
}

.mpx-sections__btn[data-mpx-depth] {
  margin-left: calc(var(--mpx-section-depth, 0) * 14px);
  width: calc(100% - (var(--mpx-section-depth, 0) * 14px));
}

.mpx-sections__search-empty {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  min-height: 160px;
  padding: 24px 20px;
  text-align: center;
  color: var(--mpx-muted);
}

.mpx-explorer--error {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 480px;
  background: var(--mpx-bg);
  border: 1px solid var(--mpx-line);
  border-radius: var(--mpx-radius-lg);
}

.mpx-explorer__state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 28rem;
  padding: 40px 24px;
  text-align: center;
}

.mpx-explorer__state h2 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--mpx-text);
}

.mpx-explorer__state p {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--mpx-muted);
}

.mpx-explorer__state--error .mpx-explorer__state-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  font-size: 1.25rem;
  font-weight: 700;
  color: #b91c1c;
  background: #fef2f2;
  border-radius: 50%;
}

/* RIGHT: Details */
.mpx-explorer__details {
  min-height: 0;
  min-width: 0;
}

.mpx-details__browse {
  padding: 20px 16px 24px;
}

.mpx-details__breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 20px;
  font-size: 0.8125rem;
}

.mpx-details__crumb {
  padding: 0;
  font-size: inherit;
  font-weight: 500;
  color: var(--mpx-green);
  background: none;
  border: none;
  cursor: pointer;
}

.mpx-details__crumb:hover {
  color: var(--mpx-green-dark);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.mpx-details__crumb--current {
  font-weight: 600;
  color: var(--mpx-text);
  cursor: default;
}

.mpx-details__crumb--current:hover {
  text-decoration: none;
}

.mpx-details__crumb-sep {
  color: #b0bab4;
  user-select: none;
}

.mpx-details__title {
  margin-bottom: 8px;
  font-size: clamp(1.75rem, 3vw, 2.25rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--mpx-text);
}

.mpx-details__description {
  max-width: 36rem;
  margin-bottom: 24px;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--mpx-muted);
}

.mpx-details__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  margin-bottom: 28px;
}

.mpx-details__stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mpx-details__stat-value {
  font-size: 1.375rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--mpx-green-dark);
}

.mpx-details__stat-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--mpx-muted);
}

.mpx-details__block {
  margin-bottom: 24px;
}

.mpx-details__block-title {
  margin-bottom: 12px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--mpx-muted);
}

.mpx-details__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
}

.mpx-details__chip {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--mpx-text);
  background: var(--mpx-bg-subtle);
  border-radius: 999px;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.mpx-details__chip:hover {
  color: var(--mpx-green-dark);
  background: var(--mpx-green-soft);
}

.mpx-details__chip:focus-visible {
  outline: 2px solid var(--mpx-green);
  outline-offset: 2px;
}

.mpx-details__chips--collections .mpx-details__chip {
  color: var(--mpx-green-dark);
  background: rgba(31, 122, 92, 0.06);
}

.mpx-details__shortcuts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  list-style: none;
}

.mpx-details__shortcut {
  display: block;
  padding: 12px 14px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--mpx-text);
  background: var(--mpx-bg-subtle);
  border-radius: 10px;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.mpx-details__shortcut:hover {
  color: var(--mpx-green-dark);
  background: var(--mpx-green-soft);
}

.mpx-details__shortcut:focus-visible {
  outline: 2px solid var(--mpx-green);
  outline-offset: 2px;
}

.mpx-details__cta {
  align-self: flex-start;
  margin-top: 8px;
}

/* Search layer — desktop overlay; mobile inline panel */
.mpx-explorer__search-layer {
  position: static;
  z-index: 5;
  background: var(--mpx-bg);
  border-radius: var(--mpx-radius-lg);
}

.mpx-explorer.is-searching .mpx-explorer__groups,
.mpx-explorer.is-searching .mpx-explorer__sections,
.mpx-explorer.is-searching .mpx-explorer__details {
  visibility: hidden;
}

.mpx-search {
  padding: 20px 16px 24px;
}

.mpx-search__title {
  margin-bottom: 6px;
  font-size: 1.375rem;
  font-weight: 800;
  color: var(--mpx-text);
}

.mpx-search__meta {
  margin-bottom: 16px;
  font-size: 0.875rem;
  color: var(--mpx-muted);
}

.mpx-search__list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  list-style: none;
}

.mpx-search__item {
  display: block;
  width: 100%;
  padding: 14px 16px;
  font-family: inherit;
  font-size: inherit;
  color: var(--mpx-text);
  text-align: left;
  background: var(--mpx-bg-subtle);
  border: none;
  border-radius: 12px;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease;
}

.mpx-search__item:hover {
  background: var(--mpx-green-soft);
}

.mpx-search__item:focus-visible {
  outline: 2px solid var(--mpx-green);
  outline-offset: 2px;
}

.mpx-search__item-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.mpx-search__item-title {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--mpx-text);
}

.mpx-search__badge {
  display: inline-flex;
  padding: 2px 8px;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--mpx-green-dark);
  background: rgba(31, 122, 92, 0.1);
  border-radius: 999px;
}

.mpx-search__path {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.5;
  color: var(--mpx-muted);
}

.mpx-search__path-sep {
  margin: 0 6px;
  color: #b0bab4;
}

.mpx-search__count {
  display: block;
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--mpx-green);
}

.mpx-search__empty {
  padding: 48px 16px;
  text-align: center;
  color: var(--mpx-muted);
}

.mpx-search__empty-title {
  margin-bottom: 8px;
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--mpx-text);
}

.mpx-search__empty p {
  margin-bottom: 20px;
  font-size: 0.875rem;
  line-height: 1.5;
}

.mpx-search__clear {
  display: inline-flex;
}

.mpx-search__item {
  min-height: 44px;
}

/* ── Mobile-only polish ── */
@media (max-width: 767px) {
  .mpx-explorer__source {
    top: auto;
    bottom: 10px;
  }

  .mpx-explorer__groups,
  .mpx-explorer__sections {
    border-right: none;
  }

  .mpx-search__title {
    display: none;
  }

  .mpx-details__shortcuts {
    grid-template-columns: 1fr;
  }
}

/* ── Tablet: compact 3-column ── */
@media (min-width: 768px) {
  .mpx-mobile-header {
    display: none;
  }

  .mpx-explorer--full .mpx-explorer__layout {
    grid-template-columns: 160px 180px minmax(0, 1fr);
    grid-template-rows: 1fr;
    height: var(--mpx-height);
    min-height: 620px;
    max-height: 760px;
  }

  .mpx-explorer__groups,
  .mpx-explorer__sections,
  .mpx-explorer__details {
    display: block !important;
  }

  .mpx-explorer__search-layer {
    position: absolute;
    inset: 0;
    display: none;
  }

  .mpx-explorer__search-layer:not([hidden]) {
    display: block;
  }

  .mpx-explorer.is-searching .mpx-explorer__groups,
  .mpx-explorer.is-searching .mpx-explorer__sections,
  .mpx-explorer.is-searching .mpx-explorer__details {
    visibility: hidden;
  }

  .mpx-explorer[data-mpx-view="search"] .mpx-explorer__groups,
  .mpx-explorer[data-mpx-view="search"] .mpx-explorer__sections,
  .mpx-explorer[data-mpx-view="search"] .mpx-explorer__details {
    display: none !important;
    visibility: visible;
  }

  .mpx-groups__list {
    gap: 2px;
    padding: 12px 8px;
  }

  .mpx-groups__btn {
    min-height: 0;
    padding: 10px 12px;
    font-size: 0.8125rem;
    background: transparent;
    border: none;
    border-radius: 10px;
  }

  .mpx-groups__meta,
  .mpx-groups__chevron {
    display: none;
  }

  .mpx-sections__list {
    gap: 1px;
    padding: 16px 8px;
  }

  .mpx-sections__btn {
    display: block;
    min-height: 0;
    padding: 10px 14px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--mpx-muted);
  }

  .mpx-sections__meta,
  .mpx-sections__chevron {
    display: none;
  }

  .mpx-sections__title {
    font-weight: inherit;
  }

  .mpx-details__browse {
    padding: 24px 24px 28px;
  }

  .mpx-search {
    padding: 24px 24px 28px;
  }
}

/* ── Desktop: full 3-column (unchanged E1.5) ── */
@media (min-width: 1024px) {
  .mpx-explorer--full .mpx-explorer__layout {
    grid-template-columns: 200px 220px minmax(0, 1fr);
  }

  .mpx-details__browse {
    padding: 28px 32px 32px;
  }

  .mpx-search {
    padding: 28px 32px 32px;
  }
}
