/* ---- Theme tokens ---- */
:root, :root[data-theme="light"] {
  --bg: #ffffff;
  --raised: #ffffff;
  --text: #1c1c1e;
  --muted: #8e8e93;
  --hairline: #e5e5ea;
  --fill: rgba(120, 120, 128, 0.12);
  --fill-strong: rgba(120, 120, 128, 0.20);
  --danger: #ff3b30;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
  --radius: 14px;
}
:root[data-theme="dark"] {
  --bg: #0b0f17;
  --raised: #151b27;
  --text: #e7ecf3;
  --muted: #8aa0c0;
  --hairline: rgba(255, 255, 255, 0.10);
  --fill: rgba(120, 120, 128, 0.22);
  --fill-strong: rgba(120, 120, 128, 0.34);
  --danger: #ff453a;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
  --radius: 14px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "SF Pro Text", system-ui, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  background: var(--bg); color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
  transition: background 0.2s ease, color 0.2s ease;
}

/* ---- Pressable buttons ---- */
button { font-family: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent;
  user-select: none; transition: transform 0.12s ease, opacity 0.12s ease, background 0.12s ease; }
button:active { opacity: 0.6; transform: scale(0.97); }
@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
  button:active { transform: none; }
}

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px; padding: 6px; border-radius: 12px;
  background: none; border: 0; color: var(--muted); font-size: 22px;
}
.icon-btn.danger { color: var(--danger); }
#settings-btn { font-size: 28px; }
.icon-btn svg { width: 20px; height: 20px; display: block; }

/* ---- Top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  display: flex; align-items: center; justify-content: flex-end; gap: 6px;
  padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
}

/* ---- Hero ---- */
main { padding: 0 20px 230px; }
.list-title {
  display: block; width: 100%; text-align: center; background: none; border: 0;
  color: var(--text); font-size: 34px; font-weight: 800; letter-spacing: -0.02em;
  margin: 0; padding: 0 0 2px; line-height: 1.1;
}
.list-pills {
  display: flex; gap: 8px; overflow-x: auto; justify-content: center;
  padding: 6px 0 2px; scrollbar-width: none;
}
.list-pills::-webkit-scrollbar { display: none; }
.pill {
  flex: none; border: 0; background: var(--fill); color: var(--text);
  border-radius: 999px; padding: 7px 16px; font-size: 15px; font-weight: 600; white-space: nowrap;
}
.pill.active { background: var(--accent); color: #fff; }
.pill.new { color: var(--muted); font-size: 18px; padding: 7px 15px; }

.avatar {
  border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: #fff; background: var(--accent);
}
.avatar.me { width: 34px; height: 34px; border: 0; padding: 0; cursor: pointer; }

/* ---- Auth (setup / login) ---- */
.auth-overlay {
  position: fixed; inset: 0; z-index: 100; background: var(--bg); padding: 24px;
}
/* display only when shown, so the [hidden] attribute actually hides it */
.auth-overlay:not([hidden]) { display: flex; align-items: center; justify-content: center; }
.auth-card { width: min(360px, 92vw); display: flex; flex-direction: column; gap: 12px; text-align: center; }
/* stack each view's fields with spacing (scoped so [hidden] still hides) */
#auth-setup:not([hidden]), #auth-login:not([hidden]) { display: flex; flex-direction: column; gap: 12px; }
.auth-card h2 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.auth-sub { margin: 0 0 6px; color: var(--muted); }
.auth-input {
  padding: 14px 16px; font-size: 18px; border-radius: var(--radius); border: 0;
  background: var(--fill); color: var(--text); text-align: center;
}
.auth-input::placeholder { color: var(--muted); }
.auth-error { color: var(--danger); font-size: 14px; min-height: 18px; margin: 0; }
.login-users:not([hidden]) { display: flex; flex-direction: column; gap: 8px; }
.login-selected {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  margin-top: 16px; margin-bottom: 4px;
}
.login-selected .avatar { width: 56px; height: 56px; font-size: 20px; }
.login-selected-name { font-size: 18px; font-weight: 600; }
.login-user {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 0;
  border-radius: var(--radius); background: var(--fill); color: var(--text);
  font-size: 17px; text-align: left;
}
.login-user .avatar { width: 38px; height: 38px; }
#login-pin-wrap:not([hidden]) { display: flex; flex-direction: column; gap: 10px; }
.account-colors { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 0; padding: 0; cursor: pointer; }
.swatch.active { outline: 2px solid var(--text); outline-offset: 2px; }

/* ---- Category groups & rows ---- */
.cat-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 24px 0 2px; padding: 4px 0;
}
.cat-head .label {
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text);
}
.cat-head.done .label { color: var(--muted); }
.chev {
  background: none; border: 0; color: var(--muted); padding: 4px 6px;
  display: inline-flex; align-items: center; justify-content: center;
}
.chev svg { width: 20px; height: 20px; display: block; }
.clear-link {
  background: none; border: 0; color: var(--danger); font-size: 14px; font-weight: 600; padding: 4px 6px;
}

.row { display: flex; align-items: center; gap: 14px; padding: 13px 2px; }
.circle {
  width: 26px; height: 26px; border-radius: 50%; flex: none; padding: 0;
  border: 2px solid var(--muted); background: none; color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 15px;
}
.row.checked .circle { background: var(--accent); border-color: var(--accent); }
.row-name { flex: 1; font-size: 18px; color: var(--text); cursor: text; }
.row.checked .row-name { text-decoration: line-through; color: var(--muted); }
.row-name-edit {
  flex: 1; font-size: 18px; color: var(--text); background: var(--fill);
  border: 0; border-radius: 8px; padding: 6px 10px; min-width: 0;
}
.stepper { display: inline-flex; align-items: center; gap: 8px; flex: none; }
.step {
  width: 28px; height: 28px; flex: none; border-radius: 50%; border: 0; background: var(--fill);
  color: var(--text); font-size: 18px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.step-val { min-width: 16px; text-align: center; font-size: 16px; color: var(--text); }
.row.checked .step-val { color: var(--muted); }
.row-del { background: none; border: 0; color: var(--muted); font-size: 16px; padding: 6px; opacity: 0.7; }

.empty { text-align: center; color: var(--muted); margin-top: 48px; font-size: 16px; }

/* Drag-to-reorder (SortableJS) */
#items.reordering-cats .cat-rows { display: none; }
/* The gap left where the item will drop */
.sortable-ghost {
  opacity: 0.5; background: var(--fill); border-radius: 14px;
  outline: 2px dashed var(--muted); outline-offset: -2px;
}
.sortable-ghost * { visibility: hidden; }
/* The element you've grabbed, floating under your finger ("lifted") */
.drag-floating {
  background: var(--bg); border-radius: 14px; padding: 4px 8px;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.35);
  transform: scale(1.04); opacity: 0.98; z-index: 50;
}

/* ---- Bottom dock ---- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4;
  background: var(--bg); border-top: 1px solid var(--hairline);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.suggest { margin-bottom: 2px; }
.suggest-label {
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted); margin-bottom: 8px;
}
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  background: var(--fill); border: 0; border-radius: 999px;
  padding: 8px 8px 8px 16px; font-size: 16px; color: var(--text); white-space: nowrap;
}
.chip .plus {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 18px; line-height: 1;
}
.add-bar { display: flex; flex-direction: column; gap: 8px; }
.add-main { display: flex; align-items: center; gap: 10px; }
#add-name {
  flex: 1; background: var(--fill); border: 0; border-radius: 999px;
  padding: 14px 18px; font-size: 16px; color: var(--text);
}
#add-name::placeholder { color: var(--muted); }
.add-toggle {
  width: 40px; height: 40px; flex: none; border-radius: 50%; border: 0;
  background: var(--fill); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.add-toggle svg { width: 26px; height: 26px; display: block; }
/* Only flex when shown, so the [hidden] attribute actually hides it.
   margin-right aligns the row's right edge with the input (clears toggle + send). */
.add-details:not([hidden]) { display: flex; gap: 8px; margin-right: 106px; }
.add-qty {
  width: 96px; flex: none; background: var(--fill); border: 0; border-radius: var(--radius);
  padding: 12px 14px; font-size: 16px; color: var(--text);
}
.add-qty::placeholder { color: var(--muted); }
.add-cat {
  flex: 1; background: var(--fill); border: 0; border-radius: var(--radius);
  padding: 12px 14px; font-size: 16px; color: var(--text); appearance: none;
}
.send {
  width: 46px; height: 46px; flex: none; border-radius: 50%; border: 0;
  background: var(--fill-strong); color: var(--muted); font-size: 22px; line-height: 1;
}
.send.ready { background: var(--accent); color: #fff; }

/* ---- Modals & sheet ---- */
.modal {
  border: 0; border-radius: 20px; padding: 22px; background: var(--bg); color: var(--text);
  width: min(440px, 92vw); box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(0, 0, 0, 0.4); }
.modal h2 { margin: 0 0 16px; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.field input {
  padding: 13px 14px; font-size: 16px; border-radius: var(--radius); border: 0;
  background: var(--fill); color: var(--text);
}
.modal-actions { display: flex; gap: 10px; margin: 18px 0 0; padding: 0; }
.btn-ghost, .btn-primary {
  flex: 1; padding: 13px 16px; border-radius: var(--radius); font-size: 16px;
  font-weight: 600; border: 0; min-height: 48px;
}
.btn-ghost { background: var(--fill); color: var(--text); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary.danger { background: var(--danger); }

.sheet-bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.sheet-bar h2 { margin: 0; }
.sheet { width: min(520px, 96vw); }
.sheet h3 {
  margin: 22px 0 8px; font-size: 13px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted);
}
.settings-head {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  margin: 22px 0 8px; padding: 4px 0; background: none; border: 0;
  font-size: 13px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted);
}
.head-chev { display: inline-flex; align-items: center; }
.head-chev svg { width: 18px; height: 18px; display: block; }
.settings-row { display: flex; align-items: center; gap: 8px; padding: 13px 2px; border-bottom: 1px solid var(--hairline); }
.settings-name { flex: 1; font-size: 16px; }
.settings-name.editable { cursor: text; }
.settings-add {
  width: 100%; margin-top: 12px; padding: 14px; border-radius: var(--radius);
  border: 0; background: var(--fill); color: var(--accent); font-size: 16px; font-weight: 600;
  text-align: center;
}

.segmented {
  display: flex; gap: 4px; background: var(--fill); border-radius: var(--radius); padding: 4px;
}
.seg {
  flex: 1; border: 0; background: none; color: var(--text); font-size: 15px; font-weight: 600;
  padding: 10px; border-radius: 10px;
}
.seg.active { background: var(--bg); color: var(--accent); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18); }
