:root {
  --bg: #FAF8F3;
  --ink: #2B2B28;
  --muted: #8A8478;
  --border: #EFE9DD;
  --card: #ffffff;
  --accent: #3F7A5C;
  --accent-ink: #FAF9F5;
  --presence-bg: #FBEADF;
  --presence-border: #F0C9A8;
  --presence-ink: #C85A2A;
  --danger: #B3463C;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Work Sans", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

button { font-family: inherit; }
input, select { font-family: inherit; font-size: 15px; }

/* ---------- Login ---------- */
.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  max-width: 360px;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 28px;
}
.login-emoji { font-size: 40px; margin-bottom: 8px; }
.login-card h1 { font-size: 21px; margin: 0 0 8px; }
.login-card p { color: var(--muted); font-size: 14px; margin: 0 0 24px; line-height: 1.5; }

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 14px;
  padding: 13px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-secondary { background: transparent; color: var(--ink); border: 1px solid #D8D2C4; }
.btn-icon {
  border: none; background: transparent; color: var(--ink);
  width: 38px; height: 38px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.btn-icon:hover { background: var(--border); }
.btn-icon-accent { color: var(--accent); }

/* ---------- App shell ---------- */
.app { max-width: 480px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  padding: 20px 20px 14px;
  display: flex; align-items: flex-start; justify-content: space-between;
}
.app-title { font-size: 20px; font-weight: 700; }
.app-subtitle { font-size: 13px; color: var(--muted); margin-top: 2px; }

.avatars { display: flex; }
.avatar {
  width: 32px; height: 32px; border-radius: 999px;
  background: #EFE9DD; color: var(--ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
  border: 2px solid var(--bg);
  margin-left: -10px;
}
.avatar:first-child { margin-left: 0; }

.presence-banner {
  margin: 0 20px 14px;
  padding: 13px 16px;
  border-radius: 14px;
  background: var(--presence-bg);
  border: 1px solid var(--presence-border);
  display: flex; flex-direction: column; gap: 6px;
}
.presence-item { display: flex; align-items: center; gap: 10px; }
.presence-item .dot { color: var(--presence-ink); display: flex; }
.presence-item .text b { color: var(--ink); }
.presence-item .text span { display: block; font-size: 12px; color: var(--muted); }

.list-area { flex: 1; padding: 0 20px 16px; overflow-y: auto; }
.empty-state { text-align: center; color: var(--muted); font-size: 14px; padding: 40px 10px; }

.store-group { margin-bottom: 26px; }
.store-group-title {
  display: flex; align-items: center; gap: 6px;
  font-size: 15px; font-weight: 700; color: var(--ink);
  padding-bottom: 6px; margin-bottom: 10px; border-bottom: 2px solid var(--border);
}
.store-group-title-active { color: var(--presence-ink); border-bottom-color: var(--presence-border); }

.category-group { margin-bottom: 20px; }
.category-title {
  font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 4px;
}
.item-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.item-check {
  width: 22px; height: 22px; border-radius: 999px; flex-shrink: 0; margin-top: 2px;
  border: 2px solid var(--accent); background: transparent; cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center; color: var(--accent-ink);
}
.item-check.checked { background: var(--accent); }
.item-main { flex: 1; min-width: 0; cursor: pointer; }
.item-label { font-size: 15px; }
.item-label.checked { text-decoration: line-through; color: #B9B3A6; }
.item-note { font-size: 12px; color: var(--muted); margin-top: 1px; }
.item-buyer { font-size: 11px; color: var(--presence-ink); font-weight: 600; margin-top: 2px; }
.item-price { font-size: 12px; color: var(--muted); margin-top: 1px; }
.item-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.item-edit-btn {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  display: flex; align-items: center; padding: 4px;
}
.item-chat-btn {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  display: flex; align-items: center; gap: 4px; padding: 4px; position: relative; flex-shrink: 0;
}
.item-chat-btn.has-unread { color: var(--presence-ink); }
.item-chat-badge {
  position: absolute; top: -2px; right: -2px; width: 8px; height: 8px;
  border-radius: 999px; background: var(--presence-ink);
}

.bottombar {
  padding: 14px 20px 22px;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 10px;
  background: var(--bg);
  position: sticky; bottom: 0;
}
.btn-presence { background: var(--accent); color: var(--accent-ink); }
.btn-presence.active { background: var(--presence-ink); }
.btn-add { background: transparent; color: var(--ink); border: 1px solid #D8D2C4; }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(43,43,40,0.4);
  display: flex; align-items: flex-end; justify-content: center; z-index: 100;
}
.modal {
  background: var(--card); width: 100%; max-width: 480px;
  border-radius: 20px 20px 0 0; max-height: 86vh; display: flex; flex-direction: column;
  animation: slideUp .18s ease-out;
}
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 8px;
}
.modal-header h2 { font-size: 17px; margin: 0; }
.modal-body { padding: 10px 20px 4px; overflow-y: auto; }
.modal-item-name { font-size: 15px; font-weight: 600; margin: 0 0 4px; }
.modal-footer { display: flex; gap: 10px; padding: 16px 20px 20px; }
.modal-footer .btn { flex: 1; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.field input, .field select {
  padding: 11px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--ink);
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.price-hint { font-size: 12px; color: var(--muted); margin: -4px 0 10px; }

.btn-text-danger {
  border: none; background: transparent; color: var(--danger); font-size: 13px; font-weight: 600;
  cursor: pointer; padding: 0 20px; text-align: left; margin-top: 4px;
}

/* ---------- Chat ---------- */
.modal-chat { height: 72vh; }
.chat-messages { flex: 1; overflow-y: auto; padding: 10px 20px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { max-width: 82%; }
.chat-msg.mine { align-self: flex-end; text-align: right; }
.chat-bubble {
  display: inline-block; background: var(--border); border-radius: 14px; padding: 9px 12px;
  font-size: 14px; text-align: left;
}
.chat-msg.mine .chat-bubble { background: var(--accent); color: var(--accent-ink); }
.chat-bubble img { max-width: 100%; border-radius: 10px; display: block; margin-bottom: 4px; }
.chat-meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.chat-composer {
  display: flex; align-items: center; gap: 6px; padding: 10px 14px;
  border-top: 1px solid var(--border);
}
.chat-composer input[type="text"] {
  flex: 1; border: 1px solid var(--border); border-radius: 999px; padding: 10px 14px;
  background: var(--bg); color: var(--ink);
}
.chat-photo-preview { padding: 0 20px 10px; }
.chat-photo-preview img { max-height: 90px; border-radius: 10px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 13px; z-index: 200; max-width: 90vw; text-align: center;
}

/* ---------- Installazione app (PWA) ---------- */
.topbar-right { display: flex; align-items: center; gap: 10px; }
.btn-install {
  border: none; background: var(--accent); color: var(--accent-ink);
  width: 34px; height: 34px; border-radius: 999px; flex: none;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.install-banner {
  margin: 0 20px 14px;
  padding: 13px 16px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.ib-icon { width: 40px; height: 40px; border-radius: 10px; flex: none; }
.ib-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 12px; line-height: 1.3; color: var(--muted); }
.ib-text strong { font-size: 14px; color: var(--ink); }
.install-banner .btn-primary { padding: 9px 14px; font-size: 13px; border-radius: 10px; }
.ib-close { border: none; background: transparent; color: var(--muted); font-size: 20px; line-height: 1; padding: 4px 6px; cursor: pointer; flex: none; }
.install-steps { margin: 0; padding-left: 20px; font-size: 14px; line-height: 1.55; color: var(--ink); }
.install-steps li { margin-bottom: 6px; }
