/* ==========================================================================
   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;
}

input[type="text"], input[type="password"], 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; }

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

@media (min-width: 720px) {
  .container { padding: 28px 24px; }
  .auth-card { margin-top: 14vh; }
  .input-qty { flex-basis: 90px; }
}
