:root {
  --bg: #f3f6fa;
  --card: #ffffff;
  --text: #1a1f26;
  --muted: #5f6b7a;
  --line: #dce3ec;
  --accent: #0059a8;
  --accent-text: #ffffff;
  --danger: #c62828;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10141a;
    --card: #1b212b;
    --text: #e7ecf3;
    --muted: #98a3b3;
    --line: #2b3442;
    --accent: #5aa7f0;
    --accent-text: #08182b;
    --danger: #ef5350;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--accent); color: var(--accent-text);
}
.bar h1 { margin: 0; font-size: 20px; flex: 1; }
.status { font-size: 13px; opacity: .9; }
.icon-btn {
  border: 0; background: transparent; color: inherit;
  font-size: 24px; width: 40px; height: 40px; border-radius: 50%;
}
.icon-btn:active { background: rgba(255,255,255,.2); }
.spinning { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main, .login { max-width: 560px; margin: 0 auto; padding: 16px; }

.login form { display: grid; gap: 12px; margin-top: 15vh; }
.login input { padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }

.primary {
  border: 0; border-radius: 10px; padding: 12px 16px;
  background: var(--accent); color: var(--accent-text); font-weight: 600;
}
.error { color: var(--danger); margin: 0; }

.add { display: flex; gap: 8px; margin-bottom: 16px; }
.add input {
  min-width: 0; padding: 12px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--card);
}
#add-name { flex: 1; }
#add-qty { width: 64px; text-align: center; }
.add .primary { width: 52px; font-size: 22px; padding: 0; }

.list { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: 12px; overflow: hidden; }
.list li {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--line);
}
.list li:last-child { border-bottom: 0; }
.list li.pending { opacity: .55; }
.name { flex: 1; overflow-wrap: anywhere; }
.qty { display: flex; align-items: center; gap: 2px; }
.qty span { min-width: 32px; text-align: center; font-weight: 600; }
.qty button, .del {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: transparent; font-size: 20px;
}
.qty button:disabled { opacity: .3; }
.del { border: 0; color: var(--danger); }

.empty { text-align: center; color: var(--muted); margin-top: 32px; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
  max-width: 528px; margin: 0 auto; padding: 12px 16px; border-radius: 10px;
  background: var(--text); color: var(--bg); font-size: 15px;
}
