* {
  box-sizing: border-box;
}

:root {
  --color-primary: #cc6b49;
  --color-primary-dark: #a8523a;
  --color-primary-light: #f6e3da;
  --color-bg: #faf7f4;
  --color-surface: #ffffff;
  --color-text: #2c2620;
  --color-text-muted: #8a7f74;
  --color-border: #ece3dc;
  --color-danger: #d64545;
  --color-danger-light: #fbe4e4;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 3px rgba(44, 38, 32, 0.08);
  --shadow-md: 0 8px 24px rgba(44, 38, 32, 0.16);
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
}

h1 {
  font-size: 1.3rem;
  margin: 4px 0 18px;
}

/* Barra superiore */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.topbar-title {
  font-weight: 700;
  font-size: 1.05rem;
}

.icon-btn {
  border: none;
  background: var(--color-bg);
  color: var(--color-text-muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active {
  transform: scale(0.92);
}

/* Barra di navigazione inferiore */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 4px 8px;
  text-decoration: none;
  color: var(--color-text-muted);
  font-size: 0.72rem;
  font-weight: 600;
}

.nav-icon {
  font-size: 1.35rem;
  line-height: 1;
}

.nav-item.active {
  color: var(--color-primary);
}

main {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px calc(96px + env(safe-area-inset-bottom, 0px));
}

/* Dashboard */
.card-list {
  display: grid;
  gap: 12px;
}

.card-list a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: var(--color-text);
  font-size: 1.05rem;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.card-list .card-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--color-primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

/* Form di aggiunta */
form.add-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

form.add-form input,
form.add-form select {
  padding: 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  background: var(--color-surface);
  color: var(--color-text);
}

form.add-form input:focus,
form.add-form select:focus {
  outline: none;
  border-color: var(--color-primary);
}

form.add-form input[name="nome"] {
  flex: 2;
  min-width: 140px;
}

form.add-form input[name="quantita"] {
  flex: 1;
  min-width: 90px;
}

form.add-form button {
  padding: 12px 18px;
  border: none;
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

form.add-form button:active {
  transform: scale(0.97);
}

/* Liste */
ul.item-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

ul.item-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  background: var(--color-surface);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

ul.item-list li.comprato .item-nome {
  text-decoration: line-through;
  color: var(--color-text-muted);
}

.item-nome {
  flex: 1;
  font-weight: 600;
}

.item-meta {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  min-width: 1.5em;
  text-align: center;
}

.item-meta.basso {
  color: var(--color-danger);
  font-weight: 700;
}

input[type="checkbox"].toggle {
  width: 22px;
  height: 22px;
  accent-color: var(--color-primary);
  flex-shrink: 0;
}

button.qty-btn {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-primary);
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

button.qty-btn:active {
  background: var(--color-primary-light);
}

button.delete-btn {
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

button.delete-btn:active {
  background: var(--color-danger-light);
  color: var(--color-danger);
}

.confirm-all-btn {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.confirm-all-btn:active {
  transform: scale(0.98);
}

.confirm-all-btn[hidden] {
  display: none;
}

/* Login */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}

.login-box {
  background: var(--color-surface);
  padding: 32px 28px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.login-logo {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  margin: 0 auto 14px;
}

.login-box h1 {
  margin: 0 0 20px;
  font-size: 1.2rem;
}

.login-box input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  background: var(--color-bg);
}

.login-box input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.login-box button {
  width: 100%;
  padding: 12px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.login-box button:active {
  transform: scale(0.98);
}

.error-msg {
  color: var(--color-danger);
  margin-bottom: 12px;
  min-height: 1.2em;
  font-size: 0.9rem;
}

.empty-msg {
  color: var(--color-text-muted);
  text-align: center;
  padding: 32px 16px;
}

/* Modale a foglio (bottom sheet) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 24, 18, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-box {
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 24px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-md);
  animation: slide-up 0.18s ease-out;
}

@keyframes slide-up {
  from {
    transform: translateY(16px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-box p {
  margin: 0 0 18px;
  font-weight: 700;
  text-align: center;
  font-size: 1.05rem;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-btn {
  padding: 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  font-size: 0.98rem;
  font-weight: 700;
}

.modal-btn:active {
  transform: scale(0.98);
}

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

.modal-btn.danger {
  background: var(--color-danger-light);
  color: var(--color-danger);
  border-color: var(--color-danger-light);
}
