/* Relist — foglio unico, mobile-first */
:root {
  --bg: #101418;
  --surface: #1a2027;
  --surface-2: #232b34;
  --text: #eef2f6;
  --muted: #9aa7b4;
  --accent: #38d996;
  --accent-ink: #06281a;
  --danger: #ff6b6b;
  --radius: 14px;
  --nav-h: 64px;
  font-size: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

.boot-msg {
  text-align: center;
  color: var(--muted);
  padding: 3rem 1rem;
}
.boot-msg.err { color: var(--danger); }

/* ---------- Barra superiore ---------- */
.topbar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  padding-top: max(.75rem, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--surface-2);
  z-index: 10;
}

.brand {
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--accent);
  font-size: 1.15rem;
}

/* ---------- Contenuto ---------- */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 1rem);
}

.page h2 { margin-bottom: .5rem; }
.page p { margin-bottom: 1rem; line-height: 1.5; }

/* ---------- Navigazione inferiore ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--surface-2);
  z-index: 10;
}

.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--muted);
  font-size: .72rem;
}

.bottom-nav a .icon { font-size: 1.35rem; }
.bottom-nav a.active { color: var(--accent); }

/* ---------- Form di accesso ---------- */
.auth-form {
  min-height: calc(100dvh - 8rem);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: .75rem;
  max-width: 400px;
  margin: 0 auto;
}

.auth-logo {
  font-size: 2.4rem;
  letter-spacing: -0.03em;
  color: var(--accent);
  text-align: center;
}

.auth-tagline {
  color: var(--muted);
  text-align: center;
  margin-bottom: 1.5rem;
}

.auth-form label { font-weight: 600; font-size: .95rem; }

.auth-form input {
  width: 100%;
  padding: .9rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--surface-2);
  background: var(--surface);
  color: var(--text);
  font-size: 1.05rem;
}

.auth-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.otp-input {
  text-align: center;
  font-size: 1.5rem !important;
  letter-spacing: .3em;   /* i codici possono avere fino a 10 cifre */
  font-variant-numeric: tabular-nums;
}

.auth-hint { color: var(--muted); font-size: .85rem; text-align: center; }

.auth-actions {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
}

.form-msg { min-height: 1.4em; font-size: .95rem; color: var(--muted); }
.form-msg.err { color: var(--danger); }

/* ---------- Bottoni ---------- */
button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
}

button.primary {
  min-height: 48px;
  padding: .95rem 1rem;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 1.05rem;
}

button.primary:disabled { opacity: .6; cursor: default; }

button.ghost {
  min-height: 44px;   /* touch target minimo (Apple HIG) */
  padding: .6rem .9rem;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--surface-2);
}

button.ghost:disabled { opacity: .5; cursor: default; }

button.danger {
  min-height: 44px;
  padding: .6rem .9rem;
  margin-top: 1.5rem;
  background: transparent;
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
  width: 100%;
}

button.danger:disabled { opacity: .5; cursor: default; }

/* Link vestito da bottone primario (CTA dell'empty state) */
a.primary-link {
  display: block;
  text-align: center;
  min-height: 48px;
  padding: .95rem 1rem;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 1.05rem;
  border-radius: var(--radius);
  text-decoration: none;
}

.center { text-align: center; }

/* ---------- Inventario ---------- */
.item-list {
  display: flex;
  flex-direction: column;
  gap: .6rem;
  margin-top: .75rem;
}

.item-card {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem;
  background: var(--surface);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
}

.item-thumb {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: 10px;
  object-fit: cover;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.item-info { flex: 1; min-width: 0; }

.item-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-sub {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: 3px;
  font-size: .82rem;
  color: var(--muted);
}

.item-price {
  font-weight: 700;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.badge {
  font-size: .72rem;
  padding: .15rem .55rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}

.badge.listed   { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }
.badge.reserved { background: color-mix(in srgb, #ffcf6b 18%, transparent); color: #ffcf6b; }
.badge.sold     { background: color-mix(in srgb, #6bb8ff 18%, transparent); color: #6bb8ff; }

.empty-state {
  text-align: center;
  padding: 3rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.empty-state .empty-icon { font-size: 3rem; }

/* Bottone flottante "aggiungi": sopra la nav, a portata di pollice */
.fab {
  position: fixed;
  right: 1rem;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 1rem);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.9rem;
  text-decoration: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .45);
  z-index: 9;
}

/* ---------- Scheda item ---------- */
.back-link {
  display: inline-block;
  margin-bottom: .75rem;
  color: var(--muted);
  text-decoration: none;
}

.item-form {
  display: flex;
  flex-direction: column;
  gap: .95rem;
  margin-top: .75rem;
}

.item-form label,
.item-form .field-label {
  display: block;
  margin-bottom: .3rem;
  font-weight: 600;
  font-size: .92rem;
}

.item-form input,
.item-form select,
.item-form textarea {
  width: 100%;
  padding: .8rem .9rem;
  border-radius: var(--radius);
  border: 1px solid var(--surface-2);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

.item-form textarea { resize: vertical; }

.item-form input:focus,
.item-form select:focus,
.item-form textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .6rem;
}

details.form-details {
  background: var(--surface);
  border-radius: var(--radius);
  padding: .8rem .9rem;
}

details.form-details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
}

details.form-details[open] summary { margin-bottom: .9rem; }

.details-fields {
  display: flex;
  flex-direction: column;
  gap: .95rem;
}

/* dentro il box i campi hanno già il loro sfondo: li stacchiamo appena */
.details-fields input,
.details-fields select,
.details-fields textarea {
  background: var(--surface-2);
  border-color: color-mix(in srgb, var(--muted) 22%, transparent);
}

/* ---------- Striscia foto ---------- */
.photo-strip {
  display: flex;
  gap: .5rem;
  overflow-x: auto;
  padding-bottom: .25rem;
}

.photo-tile {
  position: relative;
  width: 84px;
  height: 84px;
  flex-shrink: 0;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-tile .tile-wait { font-size: 1.4rem; }

.photo-tile .remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 26px;
  height: 26px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: .85rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-add {
  width: 84px;
  height: 84px;
  flex-shrink: 0;
  border-radius: 10px;
  border: 1.5px dashed color-mix(in srgb, var(--muted) 55%, transparent);
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
}

.photo-add-hint { font-size: .7rem; }

/* ---------- Ricerca e filtri (S3) ---------- */
.search-input {
  width: 100%;
  margin-top: .75rem;
  padding: .75rem .9rem;
  border-radius: var(--radius);
  border: 1px solid var(--surface-2);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}

.search-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.chips-row {
  display: flex;
  gap: .4rem;
  overflow-x: auto;
  padding: .6rem 0 .4rem;
  scrollbar-width: none;
}
.chips-row::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  min-height: 36px;
  padding: .35rem .8rem;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--surface-2);
  font-size: .85rem;
}

.chip.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 700;
}

.count-line { font-size: .82rem; margin-bottom: .25rem; }

/* Pallini marketplace sulle card e nella scheda */
.mkt-dots { display: inline-flex; gap: .25rem; }

.mkt-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  border-radius: 50%;
  font-size: .68rem;
  font-weight: 800;
  background: var(--surface-2);
  color: var(--text);
}

.mkt-dot.vinted   { background: #0e5f60; color: #8ff0ee; }
.mkt-dot.subito   { background: #5a1f1f; color: #ff9d9d; }
.mkt-dot.ebay     { background: #1f3a5a; color: #9dc4ff; }
.mkt-dot.facebook { background: #22315a; color: #a3b8f5; }

/* ---------- Scheda item (S4) ---------- */
.gallery {
  display: flex;
  gap: .5rem;
  overflow-x: auto;
  margin-top: .25rem;
  border-radius: var(--radius);
}

.gallery-photo {
  height: 240px;
  max-width: 85%;
  flex-shrink: 0;
  border-radius: var(--radius);
  object-fit: cover;
}

.gallery-empty {
  height: 160px;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  background: var(--surface);
}

.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  margin-top: .9rem;
}

.detail-head h2 { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.price-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
  margin: .8rem 0;
}

.price-cell {
  background: var(--surface);
  border-radius: var(--radius);
  padding: .6rem .7rem;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}

.price-cell .muted { font-size: .72rem; }
.price-cell strong { font-variant-numeric: tabular-nums; }
.err-text { color: var(--danger); }

.ghost-link {
  display: block;
  text-align: center;
  min-height: 44px;
  padding: .6rem .9rem;
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  margin-bottom: .5rem;
}

.listings, .prose-box, .timeline { margin-top: 1.2rem; }
.listings h3, .prose-box h3, .timeline h3 { margin-bottom: .6rem; }

.listing-list { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .8rem; }

.listing-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  background: var(--surface);
  border-radius: var(--radius);
  padding: .55rem .7rem;
}

.listing-row.inactive { opacity: .65; }
.listing-info { flex: 1; min-width: 0; font-size: .95rem; }
.listing-info .muted { font-size: .8rem; }
.listing-open { color: var(--accent); text-decoration: none; }
.listing-actions { display: flex; gap: .3rem; }

button.small { min-height: 36px; padding: .35rem .7rem; font-size: .85rem; }
button.primary.small { font-weight: 700; }

.add-listing {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  background: var(--surface);
  border-radius: var(--radius);
  padding: .7rem;
}

.add-listing select,
.add-listing input {
  width: 100%;
  padding: .65rem .8rem;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--muted) 22%, transparent);
  background: var(--surface-2);
  color: var(--text);
  font-size: .95rem;
}

.prose { white-space: pre-wrap; line-height: 1.5; }
.prose-box { background: var(--surface); border-radius: var(--radius); padding: .8rem .9rem; }
.prose-box h3 { font-size: .95rem; }

.timeline ul { list-style: none; display: flex; flex-direction: column; gap: .45rem; }

.timeline li {
  padding-left: 1rem;
  position: relative;
  font-size: .92rem;
  line-height: 1.45;
}

.timeline li::before {
  content: '';
  position: absolute;
  left: 0;
  top: .45em;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.tl-date { font-variant-numeric: tabular-nums; margin-right: .15rem; }

/* ---------- Generatore annunci AI (S6) ---------- */
.ai-box {
  margin-top: 1.2rem;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--radius);
  padding: .9rem;
}

.ai-box h3 { margin-bottom: .3rem; }
.ai-box > p.muted { font-size: .85rem; margin-bottom: .8rem; }

.ai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: .8rem;
}

.ai-chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .35rem .7rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  font-size: .85rem;
  cursor: pointer;
}

.ai-chip input { accent-color: var(--accent); }

.ai-box button.primary { width: 100%; }

.ai-results {
  display: flex;
  flex-direction: column;
  gap: .7rem;
  margin-top: .8rem;
}

.ai-variant {
  background: var(--surface);
  border-radius: var(--radius);
  padding: .7rem;
}

.ai-variant-head {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .5rem;
}

.ai-field { margin-top: .5rem; }

.ai-field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .2rem;
}

.ai-field-head .field-label { margin: 0; font-size: .8rem; }

.ai-field-text {
  background: var(--surface-2);
  border-radius: 10px;
  padding: .5rem .65rem;
  font-size: .92rem;
  line-height: 1.4;
  margin: 0;
}

.ai-field-text.multiline { white-space: pre-wrap; }

/* ---------- Vendita (S7) ---------- */
.sell-cta {
  display: block;
  text-align: center;
  min-height: 48px;
  padding: .9rem 1rem;
  margin-bottom: .5rem;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.detail-title-line { margin-top: -.3rem; }

.ship-toggle {
  cursor: pointer;
  width: 100%;
  justify-content: flex-start;
}
.ship-toggle input { accent-color: var(--accent); }

.net-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: .75rem .9rem;
  display: flex;
  flex-direction: column;
  gap: .2rem;
}

.net-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.net-line strong { font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.net-hint { font-size: .78rem; }
.ok-text { color: var(--accent); }

/* Riepilogo vendita sulla scheda */
.sale-summary {
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-radius: var(--radius);
  padding: .8rem .9rem;
  margin-bottom: .5rem;
}

.sale-net {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: .5rem;
}
.sale-net strong { font-size: 1.5rem; font-variant-numeric: tabular-nums; }

.sale-lines {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .25rem .5rem;
  margin: 0;
  font-size: .9rem;
}
.sale-lines dt { color: var(--muted); }
.sale-lines dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.sale-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: .7rem;
  font-size: .85rem;
}

/* Passo 2: schermata "Venduto!" + checklist anti-doppia-vendita */
.sale-done {
  text-align: center;
  padding: 2rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.sale-done-emoji { font-size: 3rem; }

.checklist {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  text-align: left;
  margin: .5rem 0 1rem;
}

.checklist-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .7rem;
  background: var(--surface);
  border-radius: var(--radius);
  cursor: pointer;
}
.checklist-item input { width: 20px; height: 20px; accent-color: var(--accent); flex-shrink: 0; }
.checklist-item.done { opacity: .55; text-decoration: line-through; }
.checklist-item a { color: var(--accent); }
