/* ══════════════════════════════════════════════════════════════════════════════
   marketplace.css — unified stylesheet for all NFTMarketplace pages
   Loaded AFTER /style.css and /navbar.css in every marketplace page.
   Replaces: profile.css, collection.css, market.css, nft.css
   ══════════════════════════════════════════════════════════════════════════════ */

/* ── CSS variables ─────────────────────────────────────────────────────────── */
:root {
  --bg:     #0b0f17;
  --card:   #121a28;
  --muted:  #98a2b3;
  --text:   #e6eaf2;
  --accent: #6ee7ff;
  --border: rgba(255,255,255,.08);
  --good:   #34d399;
  --bad:    #fb7185;
  --warn:   #fbbf24;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

/* ── Body overrides (marketplace pages only) ───────────────────────────────── */
body {
  padding: 8px;
  align-items: flex-start; /* prevent vertical centering that pushes content down */
}

/* ── Typography ────────────────────────────────────────────────────────────── */
h1 { margin: 0; font-size: clamp(1.3rem, 4vw, 1.8rem); line-height: 1.2; }
h2 { margin: 0; font-size: 1.1rem; line-height: 1.25; }
h3 { margin: 0; font-size: 1rem; }

a { color: var(--accent); }
a:hover { text-decoration: underline; }

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
               "Liberation Mono", "Courier New", monospace;
}
.muted  { color: var(--muted); }
.small  { font-size: 12px; }
.nowrap { white-space: nowrap; }

/* ── Layout: wrapper / wrap ────────────────────────────────────────────────── */
.wrapper,
.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
}
/* nested wrap/wrapper gets no extra top padding */
.wrapper .wrapper,
.wrapper .wrap,
.wrap .wrapper,
.wrap .wrap { padding-top: 0; }

/* ── Header bar (profile / collection pages) ───────────────────────────────── */
header {
  max-width: 1200px;
  margin: 0 auto;
  padding: 22px 18px 10px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
}
.title h1 { margin: 0; font-size: 20px; letter-spacing: .2px; }
.title p  { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.35; }

/* ── Top bar ───────────────────────────────────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

/* ── Card / container ──────────────────────────────────────────────────────── */
.card {
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  background: rgba(255,255,255,.02);
}
.hd {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(to right, rgba(110,231,255,.07), rgba(167,139,250,.04));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}
.bd { padding: 14px; }

/* ── Pill ──────────────────────────────────────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255,255,255,.03);
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
}
.pill b { color: var(--text); font-weight: 600; }

/* ── Chip ──────────────────────────────────────────────────────────────────── */
.chip {
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.03);
  color: var(--muted);
}
.chip.good    { border-color: rgba(52,211,153,.35);  color: #bbf7d0; background: rgba(52,211,153,.08); }
.chip.loading { border-color: rgba(110,231,255,.25); color: #cffafe; background: rgba(110,231,255,.06); }

/* ── Tag ───────────────────────────────────────────────────────────────────── */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.03);
  color: var(--muted);
  width: fit-content;
}

/* ── Buttons (marketplace variants) ───────────────────────────────────────── */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
}
.btn:hover    { border-color: rgba(110,231,255,.35); }
.btn.small    { padding: 8px 10px; font-size: 12px; border-radius: 10px; }
.btn.secondary { opacity: .85; }
.btn.link     { background: transparent; border-color: transparent; padding: 0; font-weight: 700; color: var(--accent); cursor: pointer; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* back link */
.back-button {
  font-size: 1rem;
  color: var(--accent);
  text-decoration: none;
  transition: color .2s;
}
.back-button:hover { color: #00ccff; }

/* ── Form controls ─────────────────────────────────────────────────────────── */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
select,
input[type="text"],
input[type="number"],
input:not([type="checkbox"]):not([type="radio"]) {
  border: 1px solid var(--border);
  background: rgba(255,255,255,.03);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13px !important; /* override global 25px */
  outline: none;
  margin-bottom: 0;
  width: auto;
}
select { cursor: pointer; }
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 8px rgba(110,231,255,.3);
}

/* ── Status / spinner ──────────────────────────────────────────────────────── */
.status {
  color: var(--muted);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.spinner {
  width: 14px; height: 14px;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,.18);
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Error / note / warning boxes ─────────────────────────────────────────── */
.error, .warning {
  border: 1px solid rgba(251,113,133,.35);
  background: rgba(251,113,133,.08);
  padding: 12px 14px;
  border-radius: 14px;
  color: #fecaca;
  font-size: 13px;
  line-height: 1.45;
  margin: 12px 0;
}
.note {
  border: 1px solid rgba(251,191,36,.30);
  background: rgba(251,191,36,.08);
  padding: 12px 14px;
  border-radius: 14px;
  color: #fde68a;
  font-size: 13px;
  line-height: 1.45;
  margin: 12px 0;
}

/* ── Tables ────────────────────────────────────────────────────────────────── */
table {
  width: 100%;
  max-width: 100%;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table th, table td {
  font-size: 12px;
  padding: 8px 6px;
  text-align: left;
  vertical-align: top;
}

/* ── Collection banner ─────────────────────────────────────────────────────── */
.banner {
  width: 100%;
  aspect-ratio: 21 / 6;
  min-height: 140px;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  position: relative;
  background: rgba(255,255,255,.03);
}
.banner img {
  width: 100%; height: 100%;
  object-fit: cover; display: block;
  transform: scale(1.02);
}
.banner::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(90deg, rgba(0,0,0,.70) 0%, rgba(0,0,0,.45) 45%, rgba(0,0,0,.15) 100%);
}
.bannerContent {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; justify-content: flex-end;
  gap: 8px; padding: 16px;
}
.bannerTitle { font-weight: 900; font-size: clamp(14px, 3vw, 22px); line-height: 1.15; }
.bannerDesc  { color: rgba(255,255,255,.85); font-size: 13px; line-height: 1.45; max-width: 820px; }
.bannerRow   { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }

/* collection.php new banner variant */
.banner__overlay  { position: absolute; inset: 0; background: linear-gradient(to top, rgba(0,0,0,.7) 0%, transparent 60%); z-index: 1; }
.banner__content  { position: relative; z-index: 2; padding: 16px 20px; }
.banner__name     { font-size: clamp(14px, 3vw, 22px); font-weight: 900; color: #fff; margin-bottom: 4px; }
.banner__desc     { font-size: 13px; color: rgba(255,255,255,.7); max-width: 600px;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.banner__no-cover { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,.2); font-weight: 900; font-size: 14px; }

/* ── Collection section (profile.php) ─────────────────────────────────────── */
section.collection {
  border: 1px solid var(--border);
  background: rgba(255,255,255,.02);
  border-radius: 16px;
  overflow: hidden;
}
.collection-header {
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(to right, rgba(110,231,255,.07), rgba(167,139,250,.04));
}
.collection-header__left { text-align: left; }
.collection-header__name { font-size: clamp(13px, 3vw, 17px); font-weight: 900; margin: 0 0 4px; }
.collection-header__meta { font-size: 12px; color: rgba(255,255,255,.5); font-family: monospace; }
.collection-header__badge {
  font-size: 11px; padding: 3px 10px; border-radius: 999px;
  border: 1px solid rgba(255,255,255,.15); background: rgba(255,255,255,.05); color: rgba(255,255,255,.6);
}
.collection-body { padding: 0 16px 16px; }

/* collection-head (old collection.php variant kept for compat) */
.collection-head {
  padding: 14px;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(to right, rgba(110,231,255,.07), rgba(167,139,250,.04));
}
.collection-head h2   { margin: 0; font-size: 15px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.collection-head .meta { margin: 6px 0 0; font-size: 12px; color: var(--muted); line-height: 1.35; }
.collection-head .right { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ── NFT grid (OpenSea-style) ──────────────────────────────────────────────── */
.nft-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}
.nft-card {
  border-radius: 14px; overflow: hidden;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.10);
  transition: border-color .18s, transform .18s;
  text-decoration: none; display: block; color: inherit; cursor: pointer;
}
.nft-card:hover { border-color: rgba(255,255,255,.30); transform: translateY(-3px); }
.nft-card__thumb {
  width: 100%; aspect-ratio: 1/1;
  background: rgba(255,255,255,.06);
  overflow: hidden; position: relative;
  display: flex; align-items: center; justify-content: center;
}
.nft-card__thumb img,
.nft-card__thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.nft-card__thumb .no-media { color: rgba(255,255,255,.25); font-size: 11px; font-weight: 700; }
.nft-card__badge {
  position: absolute; top: 8px; left: 8px;
  background: rgba(0,0,0,.55); border: 1px solid rgba(255,255,255,.15);
  border-radius: 999px; padding: 2px 8px;
  font-size: 11px; font-family: monospace; color: #fff; z-index: 2;
}
.nft-card__body    { padding: 9px 11px 11px; }
.nft-card__name    { font-size: 13px; font-weight: 700; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 3px; }
.nft-card__price   { font-size: 13px; color: #9ad1ff; font-weight: 700; margin-bottom: 2px; }
.nft-card__rarity  { font-size: 11px; color: rgba(255,255,255,.4); }
.nft-card__seller  { font-size: 11px; color: rgba(255,255,255,.4); font-family: monospace; }
.nft-card__id      { font-size: 11px; color: rgba(255,255,255,.45); font-family: monospace; }

/* ── Collection tile (collection.php old grid) ─────────────────────────────── */
.tile {
  display: flex; flex-direction: column; width: 100%;
  border: 1px solid var(--border); border-radius: 14px;
  background: rgba(255,255,255,.02); overflow: hidden; min-height: 240px;
}
.tile .img {
  width: 100%; aspect-ratio: 1/1; background: rgba(255,255,255,.03);
  display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
}
.tile .img img   { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .img video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .img video::-webkit-media-controls,
.tile .img video::-webkit-media-controls-enclosure { display: none !important; }
.tile .info { padding: 10px 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.tile .name { font-weight: 900; font-size: 13px; line-height: 1.2; }
.tile .meta { color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; gap: 8px; }

/* ── NFT detail page (nft.php) ─────────────────────────────────────────────── */
.info-grid { margin-top: 14px; text-align: left; display: grid; gap: 10px; }
.info-row  { display: grid; grid-template-columns: 140px minmax(0,1fr); gap: 10px; }
.info-label { font-weight: 800; }
.contract-address { max-width: 100%; word-break: break-all; overflow-wrap: anywhere; line-height: 1.4; font-family: monospace; color: lightgrey; }

/* Attribute badges */
.attr {
  border: 1px solid var(--border);
  background: rgba(255,255,255,.03);
  padding: 6px 8px; border-radius: 12px;
  display: flex; gap: 6px; align-items: center; max-width: 100%;
}
.attr span  { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.attr .t    { color: var(--text); font-weight: 700; }

/* Media badge overlay */
.badge {
  position: absolute; left: 10px; top: 10px;
  font-size: 11px; color: rgba(255,255,255,.88);
  background: rgba(0,0,0,.45); border: 1px solid rgba(255,255,255,.16);
  padding: 4px 8px; border-radius: 999px; backdrop-filter: blur(6px); z-index: 5;
}

/* ── NFT media box (nft.php) ───────────────────────────────────────────────── */
#media {
  max-width: 100%;
  width: 100% !important;
  box-sizing: border-box;
}
#media img,
#media video {
  max-width: 100%;
  max-height: 100%;
  object-fit: cover;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  padding: 12px 0;
}

/* ── Section header (index.php) ────────────────────────────────────────────── */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 4px;
}
.section-header h1 { margin: 0; font-size: 20px; }

/* ── Filters ───────────────────────────────────────────────────────────────── */
.filters {
  display: flex; flex-wrap: wrap; gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  margin-top: 10px;
}

/* ── Skeleton loading animation ────────────────────────────────────────────── */
@keyframes pulse { 0%,100%{opacity:.35} 50%{opacity:.7} }
.skeleton {
  background: rgba(255,255,255,.07);
  border-radius: 8px;
  animation: pulse 1.6s ease-in-out infinite;
}

/* ── Sentinel (infinite scroll) ────────────────────────────────────────────── */
#sentinel { height: 1px; }

/* ── Reset bottoni dentro sell/buy box ──
   Annulla width, margin e padding ereditati da style.css
── */
#sellBox button,
#buyBox button {
  width: auto !important;
  max-width: 100%;
  box-sizing: border-box;
  margin: 4px 0 !important;
  padding: 10px 16px !important;
}

/* sacrifice-btn specifico: non deve espandersi */
#sellBox .sacrifice-btn,
#buyBox .sacrifice-btn {
  width: auto !important;
}
/* ── Fix: listingId e indirizzi lunghi nel market status ── */
#marketStatus {
  word-break: break-all;
  overflow-wrap: anywhere;
}
/* ══════════════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 860px) {
  .nft-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .grid     { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 700px) {

  #sellBox button,
#buyBox button {
  width: 100% !important;
}

  /* Stack nft.php two-column layout */
  .nft-two-col { flex-direction: column !important; }
  .nft-two-col > * { max-width: 100% !important; min-width: 0 !important; }

  /* LEFT + RIGHT columns: force full width and remove min-width */
  #pageContent > div[style*="display:flex"] > div {
    min-width: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    flex: 1 1 100% !important;
  }

  /* Marketplace header: stack price box */
  #marketCard > div:first-child {
    flex-direction: column !important;
    align-items: flex-start !important;
  }
  #marketCard > div:first-child > div[style*="min-width:220px"] {
    min-width: 0 !important; width: 100% !important; text-align: left !important;
  }

  /* Sell/buy boxes — stack everything */
  #sellBox, #buyBox { padding: 12px !important; }
  #sellBox > div:first-child,
  #buyBox  > div:first-child { flex-direction: column !important; align-items: flex-start !important; }
  #sellBox > div:first-child > div[style*="min-width:180px"] {
    min-width: 0 !important; width: 100% !important; text-align: left !important;
  }
  #sellBox > div:last-child,
  #buyBox  > div:last-child { flex-direction: column !important; }
  #priceInput { min-width: 0 !important; width: 100% !important; font-size: 14px !important; }
  #approveNftBtn, #listBtn, #cancelBtn,
  #approveSkrBtn, #buyBtn { width: 100% !important; margin: 4px 0 !important; }

  /* Transfer table */
  table th, table td { font-size: 11px; padding: 5px 3px; }

  /* NFT media box: fit container on mobile, limit height */
  #media {
    max-height: none;
    max-width: 100%;
    width: 100% !important;
    aspect-ratio: 4/3 !important;
    margin: 14px 0 0;
  }

  /* LEFT column container: remove forced min-width */
  #pageContent .container[style*="min-width:320px"] {
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* 2-column NFT grid on mobile */
  .nft-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 8px; }
  .grid     { grid-template-columns: repeat(2, 1fr); }

  /* Collection banner height */
  .banner { aspect-ratio: unset; height: 140px; }
  .banner__name, .bannerTitle { font-size: 14px; }
  .banner__desc, .bannerDesc  { font-size: 11px; -webkit-line-clamp: 1; }

  /* Buttons */
  button { padding: 6px 12px; font-size: 10px; }
  .btn   { padding: 8px 10px; font-size: 12px; }

  /* Collection header */
  .collection-header { padding: 10px 12px; }
  /* ── Fix overflow da sellBox/buyBox che allarga il layout su mobile ── */
#sellBox,
#buyBox {
  overflow: hidden;     /* blocca qualsiasi figlio che sborda */
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

#sellBox *,
#buyBox * {
  max-width: 100%;
  box-sizing: border-box;
}

/* forza gli input a non avere min-width fisso */
#priceInput,
#amountInput {
  min-width: 0 !important;
  width: 100% !important;
}

/* evita che la flex row degli input/bottoni sfori */
#sellBox > div,
#buyBox  > div {
  min-width: 0;
  max-width: 100%;
}
/* DEBUG — trova il colpevole del overflow */
#marketCard * {
  max-width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
}
}

@media (max-width: 400px) {
  .nft-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .nft-card__name   { font-size: 11px; }
  .nft-card__body   { padding: 6px 8px 8px; }
  .nft-card__id,
  .nft-card__rarity,
  .nft-card__seller { font-size: 10px; }
}

.listing-badge {
  background: linear-gradient(135deg, rgba(80,200,120,.15), rgba(80,200,120,.05));
  border: 1px solid rgba(80,200,120,.35);
  border-radius: 10px;
  padding: 6px 8px;
  margin-bottom: 6px;
}
.listing-badge__price {
  font-size: 13px;
  font-weight: 900;
  color: #6ee7a0;
  line-height: 1.2;
}
.listing-badge__usd {
  font-size: 11px;
  color: #9ad1ff;
  margin-top: 2px;
}

/* ── Fix spaziatura verticale tra le card ── */
.wrapper,
.wrap {
  padding-top: 14px;
}

/* assicura gap verticale tra tutti i container diretti */
.wrapper > .container,
.wrapper > div,
.wrap > .container,
.wrap > div {
  margin-bottom: 0; /* il gap del flex ci pensa già */
}

/* gap esplicito sul wrapper se non già impostato */
.wrapper { gap: 14px; }
.wrap    { gap: 14px; }

/* ── Fix: rimuove min-width ereditato da style.css sui container dentro nft.php ── */
#pageContent .container {
  min-width: 0;
}

/* ── Fix: assicura gap tra le card nella colonna right ── */
#pageContent > div > div {
  gap: 12px;
}