:root {
  --paper: #F2F4EF;
  --card: #FFFFFF;
  --ink: #262E27;
  --ink-soft: #697065;
  --blue: #4C5FD5;
  --coral: #FF6F61;
  --line: rgba(105, 112, 101, 0.18);
  --radius: 16px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; padding: 0; }
.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.loading { color: var(--ink-soft); text-align: center; margin-top: 40vh; }
.empty { color: var(--ink-soft); font-size: 14px; margin: 8px 0 16px; line-height: 1.45; }
.empty.center { text-align: center; margin-top: 30vh; }

/* ---------- name screen ---------- */
.name-screen { padding: 0 24px; margin: auto 0; }
.name-screen h1 { font-size: 28px; font-weight: 700; margin: 0; }
.name-screen .sub { color: var(--ink-soft); margin: 8px 0 20px; }
.name-screen .btn { margin-top: 12px; border-radius: 14px; }

/* ---------- top bars ---------- */
.top-bar {
  display: flex; align-items: center; gap: 4px;
  padding: 12px 8px 6px 20px; min-height: 64px;
}
.top-bar h1 { flex: 1; font-size: 22px; font-weight: 700; margin: 0; }
.list-bar { padding-left: 4px; }
.title-wrap { flex: 1; min-width: 0; }
.list-title { font-size: 20px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { display: flex; align-items: center; gap: 4px; font-size: 12px; color: rgba(38, 46, 39, 0.7); margin-top: 1px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; flex: none;
}
.icon-btn:hover { background: rgba(38, 46, 39, 0.06); }
.icon-btn svg { width: 22px; height: 22px; }
.list-bar .back { margin-left: 6px; } /* clear of the phone's edge back-swipe */

/* ---------- home and list body ---------- */
.home { padding: 8px 16px calc(100px + env(safe-area-inset-bottom)); flex: 1; }
.rows { display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--card); border-radius: var(--radius); }
.list-row { display: flex; align-items: center; gap: 12px; padding: 16px; cursor: pointer; }
.list-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.list-row .text { flex: 1; min-width: 0; }
.list-row .label { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .meta { font-size: 12px; color: rgba(38, 46, 39, 0.55); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* swipe left to remove */
.swipe { position: relative; border-radius: var(--radius); }
.swipe-bg {
  position: absolute; inset: 0; border-radius: var(--radius); background: var(--coral); color: #fff;
  display: flex; align-items: center; justify-content: flex-end; padding: 0 20px; opacity: 0;
}
.swipe-bg svg { width: 24px; height: 24px; }
.swipe > .card { position: relative; touch-action: pan-y; transition: transform 0.16s ease; user-select: none; -webkit-user-select: none; }
.swipe > .card.swiping { transition: none; }

/* items */
.item { display: flex; align-items: center; padding: 8px 12px 8px 8px; min-height: 56px; cursor: pointer; }
.swipe.unchecked { transition: transform 0.15s ease; }
.swipe.dragging { transition: none; z-index: 2; }
.swipe.dragging > .card { box-shadow: 0 6px 18px rgba(38, 46, 39, 0.18); }
.handle {
  flex: none; width: 30px; height: 40px; display: grid; place-items: center;
  color: rgba(38, 46, 39, 0.35); cursor: grab; touch-action: none;
}
.handle svg { width: 14px; height: 10px; }
.handle.off { cursor: default; }
.swipe.dragging .handle { cursor: grabbing; }
.check { flex: none; width: 20px; height: 20px; margin: 0 10px 0 4px; accent-color: var(--blue); cursor: pointer; }
.item-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.item-name { font-size: 16px; }
.qty { font-size: 13px; color: rgba(38, 46, 39, 0.6); margin-top: 1px; }
.item.done .item-name { text-decoration: line-through; }
.avatar {
  flex: none; width: 24px; height: 24px; border-radius: 50%; margin-left: 6px;
  display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--ink);
}

/* floating add button */
.fab {
  position: fixed; z-index: 5;
  right: max(20px, calc(50vw - 280px + 20px));
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 16px;
  background: var(--coral); color: #fff; display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(38, 46, 39, 0.22);
}
.fab svg { width: 24px; height: 24px; }

/* buttons */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; height: 50px; border-radius: 12px; font-weight: 600; font-size: 15px;
}
.btn.primary { background: var(--blue); color: #fff; }
.btn.outline { border: 1.5px solid var(--line); color: var(--blue); background: transparent; }
.btn.outline.ink { color: var(--ink); }
.btn.outline.danger { color: var(--coral); }
.btn.small { height: 46px; font-size: 14px; }
.btn + .btn { margin-top: 10px; }
.install-tip {
  margin-top: 22px; padding: 14px; background: var(--card); border-radius: var(--radius);
  font-size: 13px; color: var(--ink-soft); line-height: 1.45;
}
.install-tip p { margin: 0 0 10px; }
.install-tip b { color: var(--ink); }
.install-tip .row { display: flex; align-items: center; gap: 6px; }
.install-tip .btn { width: auto; height: 40px; padding: 0 20px; }
.link-btn { padding: 10px 12px; border-radius: 10px; font-weight: 600; font-size: 13px; color: var(--ink-soft); }
.link-btn:hover { background: rgba(38, 46, 39, 0.06); }
.text-btn { padding: 12px 14px; border-radius: 10px; font-weight: 600; font-size: 14px; color: var(--blue); flex: none; }
.text-btn:hover { background: rgba(76, 95, 213, 0.08); }
.text-btn.danger { color: var(--coral); }

/* ---------- overlays: sheets and dialogs ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(20, 24, 21, 0.38);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.15s ease-out;
}
.overlay.dialog-wrap { align-items: center; padding: 20px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0.6; } }
.sheet {
  width: 100%; max-width: 560px; max-height: 88vh; max-height: 88dvh; overflow-y: auto;
  background: var(--paper); border-radius: 22px 22px 0 0;
  padding: 14px 20px calc(28px + env(safe-area-inset-bottom));
  animation: rise 0.18s ease-out;
}
@media (min-width: 640px) {
  .overlay:not(.dialog-wrap) { align-items: center; padding: 20px; }
  .sheet { border-radius: 22px; }
}
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 4px 0 16px; }
.sheet-head h2 { font-size: 18px; font-weight: 700; margin: 0; overflow-wrap: anywhere; }
.sheet-head .code { font-size: 12px; color: rgba(38, 46, 39, 0.5); margin-top: 2px; overflow-wrap: anywhere; }
.dialog {
  width: 100%; max-width: 400px; background: var(--card); border-radius: 22px;
  padding: 22px 22px 12px; animation: rise 0.18s ease-out;
  max-height: 90vh; max-height: 90dvh; overflow-y: auto;
}
.dialog h2 { font-size: 20px; font-weight: 600; margin: 0 0 8px; overflow-wrap: anywhere; }
.dialog p { font-size: 13px; color: var(--ink-soft); margin: 0 0 14px; line-height: 1.45; }
.dialog .actions { display: flex; align-items: center; gap: 4px; margin-top: 8px; }
.dialog .caps { display: block; margin-top: 4px; }
.field {
  display: block; width: 100%; border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--card); padding: 12px 14px; font-size: 16px; margin-bottom: 10px;
  outline: none;
}
.field:focus { border-color: var(--blue); }
.caps { font-size: 11px; font-weight: 700; color: var(--ink-soft); letter-spacing: 0.02em; margin: 0 0 6px; }

/* ---------- snackbar ---------- */
.snackbar {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 20;
  width: calc(100% - 32px); max-width: 528px;
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: #313733; color: #fff; font-size: 14px;
  padding: 6px 8px 6px 16px; min-height: 48px; border-radius: 10px; transition: all 0.2s ease;
}
.snackbar.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.snackbar span { overflow: hidden; text-overflow: ellipsis; }
.snack-action { color: #B8C2FF; font-weight: 700; font-size: 14px; padding: 10px 12px; border-radius: 8px; flex: none; }
