/* ==========================================================================
   Lista della Spesa — UI mobile-first, nessun framework CSS
   ========================================================================== */

:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --border: #e3e6f0;
  --text: #191b26;
  --text-soft: #6b7280;
  --primary: #4f46e5;
  --primary-strong: #4338ca;
  --primary-soft: #eef2ff;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --ok: #059669;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(25, 27, 38, .06), 0 8px 24px -12px rgba(25, 27, 38, .12);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
}

/* ---------- layout ---------- */

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  text-decoration: none;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-chip {
  font-size: .82rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 4px 10px;
  border-radius: 999px;
}

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 0 16px;
}

.page-title {
  font-size: 1.35rem;
  font-weight: 750;
  letter-spacing: -.02em;
  margin: 0;
}

.back-link {
  display: inline-block;
  font-size: .95rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  margin-bottom: 8px;
}

.muted {
  color: var(--text-soft);
  font-size: .88rem;
  margin: 4px 0 0;
}

/* ---------- cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.card-title {
  font-size: .95rem;
  font-weight: 700;
  margin: 0 0 12px;
}

/* ---------- form ---------- */

.form label,
.row-form label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-soft);
  margin: 10px 0 4px;
}

.form>.btn {
  margin: 10px 0 4px;
}

input[type="text"],
input[type="password"],
input[type="email"],
select {
  width: 100%;
  font: inherit;
  padding: 11px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}

.row-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.row-form input,
.row-form select {
  margin: 0;
}

.input-grow {
  flex: 1 1 auto;
  min-width: 0;
}

.input-qty {
  flex: 0 0 72px;
}

/* ---------- buttons ---------- */

.btn {
  font: inherit;
  font-weight: 650;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  transition: background .15s, transform .05s, box-shadow .15s;
  white-space: nowrap;
}

.btn:active {
  transform: scale(.97);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-soft);
  border: 1.5px solid var(--border);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--text-soft);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: #b91c1c;
}

.btn-danger-ghost {
  color: var(--danger);
  border-color: transparent;
}

.btn-danger-ghost:hover {
  background: var(--danger-soft);
  border-color: var(--danger-soft);
}

.btn-sm {
  padding: 7px 10px;
  font-size: .85rem;
}

.btn-block {
  width: 100%;
}

/* ---------- auth ---------- */

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 22px;
  margin-top: 10vh;
  max-width: 400px;
  margin-inline: auto;
}

.auth-title {
  text-align: center;
  font-size: 1.5rem;
  margin: 0 0 4px;
}

.auth-sub {
  text-align: center;
  color: var(--text-soft);
  margin: 0 0 16px;
  font-size: .92rem;
}

.auth-alt {
  text-align: center;
  font-size: .9rem;
  color: var(--text-soft);
  margin: 14px 0 0;
}

.auth-alt a {
  color: var(--primary);
  font-weight: 650;
}

/* ---------- alert ---------- */

.alert {
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: .9rem;
  margin-bottom: 14px;
}

.alert-error {
  background: var(--danger-soft);
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-ok {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

/* ---------- OTP ---------- */

.otp-input {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: .45em;
  text-align: center;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

.resend-form {
  text-align: center;
  margin-top: 4px;
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: .88rem;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

.link-btn:hover {
  color: var(--primary-strong);
}

/* ---------- liste (dashboard) ---------- */

.list-cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.list-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.list-card-link {
  display: grid;
  gap: 6px;
  padding: 14px 16px;
  text-decoration: none;
  color: inherit;
}

.list-card-link:active {
  background: var(--primary-soft);
}

.list-card-name {
  font-weight: 700;
  font-size: 1.02rem;
}

.list-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.list-card-count {
  color: var(--text-soft);
  font-size: .82rem;
}

.list-card.is-shared {
  border-left: 4px solid var(--primary);
}

.badge {
  font-size: .72rem;
  font-weight: 700;
  background: var(--bg);
  color: var(--text-soft);
  border-radius: 999px;
  padding: 3px 9px;
}

.badge-shared {
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.badge-owner {
  background: #ecfdf5;
  color: var(--ok);
}

/* ---------- dettaglio lista ---------- */

.list-head-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
}

.head-actions {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.details-panel {
  position: relative;
}

.details-panel summary {
  list-style: none;
}

.details-panel summary::-webkit-details-marker {
  display: none;
}

.panel-body {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--bg);
}

.check-row {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-size: .92rem !important;
  font-weight: 500 !important;
  color: var(--text) !important;
}

.check-row input {
  width: auto;
  accent-color: var(--primary);
}

/* ---------- items ---------- */

.items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  animation: slide-in .18s ease-out;
}

@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.item-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.item-check {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.item-check input[type="checkbox"] {
  width: 22px;
  height: 22px;
  flex: none;
  accent-color: var(--ok);
  cursor: pointer;
}

.item-name {
  overflow-wrap: anywhere;
  font-weight: 550;
}

.is-checked .item-name {
  text-decoration: line-through;
  color: var(--text-soft);
}

.item-qty {
  flex: none;
  font-size: .8rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 2px 8px;
  border-radius: 999px;
}

.item-actions {
  display: flex;
  gap: 2px;
  flex: none;
}

.item-edit-form {
  flex-wrap: wrap;
}

.item-edit-form .btn {
  margin-top: 2px;
}

.items-empty .empty-state {
  border-style: dashed;
}

/* ---------- empty state ---------- */

.empty-state {
  text-align: center;
  color: var(--text-soft);
  padding: 28px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.empty-icon {
  font-size: 1.8rem;
  margin: 0 0 6px;
}

.empty-state p {
  margin: 0;
}

/* ---------- condivisione ---------- */

.member-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: grid;
  gap: 6px;
}

.member {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.member-name {
  font-weight: 600;
  font-size: .92rem;
}

.is-pending {
  border-style: dashed;
}

.is-pending .member-name {
  font-weight: 500;
  color: var(--text-soft);
}

.share-sub {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-soft);
  margin: 14px 0 6px;
}

/* ---------- flash ---------- */

.flash {
  position: fixed;
  inset-inline: 0;
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 50;
}

/* ---------- utility ---------- */

[hidden] {
  display: none !important;
}

/* ---------- landing (home page) ---------- */

.container-wide {
  max-width: 760px;
}

.landing {
  display: flex;
  flex-direction: column;
  gap: 32px;
  padding-top: 8px;
}

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--primary-strong);
  background: var(--primary-soft);
  border: 1px solid #c7d2fe;
  padding: 4px 12px;
  border-radius: 999px;
  margin: 0;
}

.hero-badge-dot {
  width: 6px;
  height: 6px;
  background: var(--primary);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--primary);
}

.hero-title {
  font-size: clamp(1.55rem, 6vw, 2.3rem);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -.02em;
  margin: 0;
  max-width: 21ch;
}

.text-gradient {
  background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.hero-subtitle {
  color: var(--text-soft);
  font-size: clamp(.95rem, 2.5vw, 1.05rem);
  line-height: 1.55;
  max-width: 54ch;
  margin: 0;
}

.hero-steps-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 18px;
  box-shadow: var(--shadow);
  margin: 4px 0;
}

.hero-step-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.step-badge {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: .72rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  flex-shrink: 0;
}

.step-label {
  font-size: .84rem;
  font-weight: 700;
  white-space: nowrap;
}

.step-divider {
  color: var(--primary);
  font-weight: bold;
  font-size: .9rem;
  line-height: 1;
  user-select: none;
}

.hero-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 340px;
  margin-top: 6px;
}

.btn-lg {
  padding: 14px 20px;
  font-size: 1.02rem;
}

.trust-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.trust-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  text-align: left;
}

.trust-icon {
  font-size: 1.35rem;
  line-height: 1.2;
  flex-shrink: 0;
}

.trust-title {
  display: block;
  font-size: .95rem;
  margin: 0 0 2px;
}

.trust-desc {
  font-size: .84rem;
  color: var(--text-soft);
  line-height: 1.45;
  margin: 0;
}

.section-title {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -.01em;
  margin: 0 0 4px;
  text-align: center;
}

.section-sub {
  text-align: center;
  color: var(--text-soft);
  margin: 0 0 18px;
  font-size: .92rem;
}

.how {
  display: flex;
  flex-direction: column;
}

.how-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
  counter-reset: how-step;
}

.how-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.how-num {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 1rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px -2px rgba(79, 70, 229, .45);
}

.how-card h3 {
  margin: 0 0 4px;
  font-size: 1.02rem;
  font-weight: 750;
}

.how-card p {
  margin: 0;
  color: var(--text-soft);
  font-size: .9rem;
  line-height: 1.5;
}

.why-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.why-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: .93rem;
  line-height: 1.5;
}

.why-icon {
  color: var(--ok);
  flex-shrink: 0;
  line-height: 1.4;
}

.final-cta {
  text-align: center;
  background: linear-gradient(135deg, var(--primary-soft), #f5f3ff);
  border: 1px solid #c7d2fe;
  border-radius: var(--radius);
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.final-cta h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -.01em;
}

.final-cta p {
  margin: 0 0 10px;
  color: var(--text-soft);
  font-size: .93rem;
}

.final-cta .btn {
  max-width: 340px;
  width: 100%;
}

.landing-footer {
  text-align: center;
  font-size: .85rem;
  color: var(--text-soft);
  margin: 0;
}

.landing-footer a {
  color: var(--primary);
  font-weight: 650;
}

/* ---------- wide screens ---------- */

@media (min-width: 720px) {
  .container {
    padding: 28px 24px;
  }

  .auth-card {
    margin-top: 14vh;
  }

  .input-qty {
    flex-basis: 90px;
  }

  .hero-actions {
    flex-direction: row;
    justify-content: center;
    max-width: 420px;
  }

  .trust-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .how-steps {
    grid-template-columns: repeat(3, 1fr);
  }

  .how-card {
    flex-direction: column;
  }
}