:root {
  --navy: #0F173F;
  --navy-2: #1a355c;
  --teal: #00B8C4;
  --teal-ink: #007a83;
  --teal-soft: #e0f6f8;
  --yellow: #FDD314;
  --bg: #f4f8f9;
  --card: #ffffff;
  --line: #e3e8ec;
  --ink: #0F173F;
  --muted: #5b6672;
  --danger: #c0392b;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(15, 23, 63, .08), 0 4px 14px rgba(15, 23, 63, .05);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --soft: #eef2f4;
  --ring: #b9c2cc;
  --grab: #cfd6dc;
  --flash: #fff7cc;
  --ink-2: #1a355c;
  --btn: #0F173F;
  --btn-ink: #ffffff;
  --link: #007aff;
  --danger-line: #f0c9c4;
  --bar: #0F173F;
  --shadow-pop: 0 10px 30px rgba(15, 23, 63, .18);
  color-scheme: light dark;
}

/* Dark theme follows the phone's setting. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0f1f;
    --card: #151c33;
    --line: #26304a;
    --ink: #e9eef6;
    --ink-2: #c6d0df;
    --muted: #97a3b6;
    --teal-ink: #4fd8e1;
    --teal-soft: rgba(0, 184, 196, .16);
    --soft: #1f2842;
    --ring: #56627c;
    --grab: #3a4560;
    --flash: #3b3612;
    --btn: #00B8C4;
    --btn-ink: #0F173F;
    --link: #4fa8ff;
    --danger: #ff7a6b;
    --danger-line: #5a2a28;
    --bar: #0F173F;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-pop: 0 10px 30px rgba(0, 0, 0, .55);
  }
  .bar, .subbar { border-bottom: 1px solid #1c2647; }
  .subbar { border-top: 0; }
  .scrim { background: rgba(0, 0, 0, .6); }
  .auth picture { display: block; }
.auth .logo { filter: none; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 20;
  background: var(--navy); color: #fff;
  padding: calc(var(--safe-top) + 10px) 12px 10px;
  display: flex; align-items: center; gap: 8px; min-height: 56px;
}
.bar h1 { font-size: 19px; font-weight: 700; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.2px; }
.bar .brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.bar .brand img { width: 34px; height: 34px; }
.bar .brand small { display: block; font-size: 11px; font-weight: 500; opacity: .7; letter-spacing: .3px; }
.bar .brand strong { display: block; font-size: 18px; line-height: 1.1; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; color: inherit;
  display: inline-grid; place-items: center; flex: none;
}
.icon-btn, .icon-btn:visited { text-decoration: none; }
.icon-btn:active { background: rgba(255, 255, 255, .12); }
.icon-btn svg { width: 24px; height: 24px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--teal); color: var(--navy);
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
}

main { padding: 16px 16px calc(130px + var(--safe-bottom)); max-width: 640px; margin: 0 auto; }

/* ---------- Buttons and fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 14px; border: 0;
  background: var(--btn); color: var(--btn-ink); font-weight: 600; font-size: 16px; width: 100%;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .55; }
.btn.secondary { background: var(--card); color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.danger { background: var(--card); color: var(--danger); box-shadow: inset 0 0 0 1.5px var(--danger-line); }
.btn svg { width: 20px; height: 20px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.input {
  width: 100%; min-height: 50px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--card);
  padding: 12px 14px; font-size: 17px; outline: none;
}
.input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0, 184, 196, .18); }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 70px; }
.pw-wrap button { position: absolute; right: 6px; top: 6px; height: 38px; border: 0; background: none; color: var(--teal-ink); font-weight: 600; font-size: 14px; padding: 0 10px; }
.error { color: var(--danger); font-size: 14px; margin: 4px 0 12px; min-height: 1em; }
.hint { color: var(--muted); font-size: 14px; }

/* ---------- Sign in ---------- */
.auth { min-height: calc(100vh - 32px); display: flex; flex-direction: column; justify-content: center; padding: calc(var(--safe-top) + 24px) 20px calc(var(--safe-bottom) + 24px); max-width: 420px; margin: 0 auto; }
.auth picture { display: block; }
.auth .logo { width: 260px; max-width: 80%; margin: 0 auto 28px; }
.auth .card { background: var(--card); border-radius: 22px; padding: 22px 18px; box-shadow: var(--shadow); }
.auth h2 { margin: 0 0 4px; font-size: 22px; }
.auth p.sub { margin: 0 0 18px; color: var(--muted); }
.auth .foot { text-align: center; color: var(--muted); font-size: 13px; margin-top: 22px; }

/* ---------- Lists home ---------- */
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; margin: 8px 4px 10px; }
.list-card {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--card); border: 0; border-radius: var(--radius); padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.list-card:active { transform: scale(.99); }
.list-card .ico { width: 46px; height: 46px; border-radius: 14px; background: var(--teal-soft); display: grid; place-items: center; flex: none; }
.list-card .ico img { width: 28px; height: 28px; }
.list-card .txt { flex: 1; min-width: 0; }
.list-card .txt strong { display: block; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-card .txt span { font-size: 14px; color: var(--muted); }
.count {
  min-width: 34px; height: 34px; border-radius: 17px; padding: 0 10px; background: var(--btn); color: var(--btn-ink);
  font-weight: 700; font-size: 15px; display: grid; place-items: center; flex: none;
}
.count.done { background: var(--teal-soft); color: var(--teal-ink); }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.empty img { width: 64px; height: 64px; margin: 0 auto 12px; opacity: .9; }
.empty strong { display: block; color: var(--ink); font-size: 18px; margin-bottom: 4px; }

.fab {
  position: fixed; right: 16px; bottom: calc(46px + var(--safe-bottom)); z-index: 15;
  height: 56px; padding: 0 22px 0 18px; border-radius: 28px; border: 0;
  background: var(--btn); color: var(--btn-ink); font-weight: 700; font-size: 16px;
  display: flex; align-items: center; gap: 8px; box-shadow: 0 6px 20px rgba(15, 23, 63, .3);
}
.fab svg { width: 22px; height: 22px; }
.fab .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--yellow); margin-left: 2px; }

/* ---------- Store switch ---------- */
.seg { display: flex; background: rgba(255, 255, 255, .1); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-width: 0; border: 0; background: transparent; color: rgba(255, 255, 255, .78); border-radius: 9px; height: 34px; font-weight: 600; font-size: 14px; padding: 0 4px; white-space: nowrap; }
.seg button[aria-pressed="true"] { background: #fff; color: var(--navy); }
.seg.light { background: var(--soft); }
.seg.light button { color: var(--muted); }
.seg.light button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(15, 23, 63, .12); }
.subbar { background: var(--navy); padding: 0 12px 12px; position: sticky; top: calc(56px + var(--safe-top)); z-index: 19; }
.subbar .seg { max-width: 616px; margin: 0 auto; }

/* ---------- Add bar ---------- */
.addbar { position: relative; margin-bottom: 16px; }
.addbar form { display: flex; gap: 8px; }
.addbar .input { flex: 1; padding-left: 44px; }
.addbar .plus-ico { position: absolute; left: 14px; top: 14px; width: 22px; height: 22px; color: var(--teal-ink); pointer-events: none; }
.addbar .go { width: 50px; min-height: 50px; padding: 0; border-radius: 14px; flex: none; }
.suggest {
  position: absolute; left: 0; right: 0; top: 56px; z-index: 12; background: var(--card); border-radius: 14px;
  box-shadow: var(--shadow-pop); overflow: hidden; max-height: 50vh; overflow-y: auto;
}
.suggest button { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; background: none; text-align: left; padding: 12px 14px; font-size: 16px; border-bottom: 1px solid var(--line); }
.suggest button:last-child { border-bottom: 0; }
.suggest button:active, .suggest button.on { background: var(--teal-soft); }
.suggest img, .suggest svg { width: 24px; height: 24px; flex: none; }
.suggest .nm { flex: 1; min-width: 0; }
.suggest .nm b { font-weight: 700; color: var(--teal-ink); }
.suggest button.have { opacity: .55; }
.suggest button.typed { color: var(--teal-ink); font-weight: 600; }
.suggest button.typed svg { color: var(--teal-ink); }
.suggest small { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: -4px 0 18px; }
.chip { border: 0; background: var(--card); color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); border-radius: 20px; padding: 7px 12px 7px 9px; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.chip img { width: 18px; height: 18px; }
.chip:active { background: var(--teal-soft); }

/* ---------- Aisle groups and items ---------- */
.aisle { margin-bottom: 14px; }
.aisle-head { display: flex; align-items: center; gap: 10px; padding: 4px 4px 8px; }
.aisle-head img { width: 26px; height: 26px; }
.aisle-head h3 { font-size: 15px; margin: 0; font-weight: 700; flex: 1; }
.aisle-head .n { font-size: 13px; color: var(--muted); font-weight: 600; }
.aisle-head .clear { border: 0; background: none; color: var(--teal-ink); font-weight: 600; font-size: 14px; padding: 4px 6px; }
.items { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item { position: relative; overflow: hidden; border-bottom: 1px solid var(--line); }
.item-in { position: relative; z-index: 1; display: flex; align-items: center; min-height: 56px; background: var(--card); touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.swipe-bg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; font-weight: 700; font-size: 15px; }
.swipe-bg span { display: flex; align-items: center; gap: 8px; opacity: .55; transform: scale(.92); transition: opacity .12s, transform .12s; }
.swipe-bg svg { width: 22px; height: 22px; }
.item[data-dir="right"] .swipe-bg { background: var(--teal); color: #0F173F; }
.item[data-dir="left"] .swipe-bg { background: #d64535; color: #fff; }
.item[data-dir="right"] .sw-left, .item[data-dir="left"] .sw-right, .item:not([data-dir]) .swipe-bg { visibility: hidden; }
.item.armed .swipe-bg span { opacity: 1; transform: scale(1.06); }
.item:last-child { border-bottom: 0; }
.tick { width: 56px; align-self: stretch; border: 0; background: none; display: grid; place-items: center; flex: none; }
.tick span { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--ring); display: grid; place-items: center; transition: background .15s, border-color .15s; }
.tick svg { width: 16px; height: 16px; color: #fff; opacity: 0; }
.item.checked .tick span { background: var(--teal); border-color: var(--teal); }
.item.checked .tick svg { opacity: 1; }
.item .body { flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 10px 14px 10px 0; align-self: stretch; display: flex; flex-direction: column; justify-content: center; }
.item .ai { width: 24px; height: 24px; margin-right: 14px; flex: none; opacity: .9; }
.item .name { font-size: 17px; word-break: break-word; }
.item .qty { display: inline-block; background: var(--yellow); color: var(--navy); font-weight: 700; font-size: 13px; border-radius: 8px; padding: 1px 7px; margin-right: 6px; vertical-align: 2px; }
.item .meta { font-size: 13px; color: var(--muted); margin-top: 1px; }
.item.checked .name { text-decoration: line-through; color: var(--muted); }
.item.checked .qty { background: var(--soft); color: var(--muted); }
.more { display: block; width: 100%; border: 0; background: none; color: var(--teal-ink); font-weight: 600; font-size: 15px; padding: 12px; margin-top: 4px; }
.item.flash .item-in { animation: flash 1.2s ease; }
@keyframes flash { from { background: var(--flash); } to { background: var(--card); } }

/* ---------- Sheets ---------- */
.scrim { position: fixed; inset: 0; background: rgba(15, 23, 63, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .18s ease; }
.sheet {
  background: var(--bg); width: 100%; max-width: 560px; border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(20px + var(--safe-bottom)); max-height: 92vh; overflow-y: auto; animation: up .22s ease;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--grab); margin: 0 auto 12px; }
.sheet h2 { font-size: 20px; margin: 0 0 4px; }
.sheet p.sub { color: var(--muted); margin: 0 0 16px; font-size: 15px; }
.sheet .row { display: flex; gap: 10px; }
.sheet .row > * { flex: 1; }
.sheet .stack > * + * { margin-top: 10px; }
.menu-list { background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); margin-bottom: 12px; }
.menu-list button { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; background: none; text-align: left; padding: 15px 16px; font-size: 16px; border-bottom: 1px solid var(--line); }
.menu-list button:last-child { border-bottom: 0; }
.menu-list button svg { width: 22px; height: 22px; color: var(--ink-2); }
.menu-list button.danger { color: var(--danger); }
.menu-list button.danger svg { color: var(--danger); }
.aisle-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.aisle-grid button { border: 0; background: var(--card); color: var(--ink); border-radius: 12px; padding: 10px 4px 8px; font-size: 12px; line-height: 1.2; box-shadow: inset 0 0 0 1.5px var(--line); min-height: 72px; }
.aisle-grid button img { width: 26px; height: 26px; margin: 0 auto 5px; }
.aisle-grid button[aria-pressed="true"] { box-shadow: inset 0 0 0 2.5px var(--teal); background: var(--teal-soft); font-weight: 600; }
.who { font-size: 13px; color: var(--muted); margin: -6px 0 14px; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Install sheet ---------- */
.install-hero { display: flex; align-items: center; gap: 14px; margin: 4px 0 16px; }
.install-hero img { width: 64px; height: 64px; border-radius: 15px; box-shadow: var(--shadow); }
.install-hero h2 { margin: 0; }
.steps { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 16px; margin-bottom: 16px; list-style: none; counter-reset: s; }
.steps li { counter-increment: s; display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 16px; }
.steps li:last-child { border-bottom: 0; }
.steps li::before { content: counter(s); width: 26px; height: 26px; border-radius: 50%; background: var(--btn); color: var(--btn-ink); font-weight: 700; font-size: 14px; display: grid; place-items: center; flex: none; }
.steps .glyph { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--bg); vertical-align: middle; margin: 0 2px; }
.steps .glyph svg { width: 20px; height: 20px; color: var(--link); }
.pointer { text-align: center; color: var(--teal-ink); font-weight: 600; font-size: 14px; margin: -4px 0 14px; }

/* ---------- Account ---------- */
.card-block { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card-block h3 { margin: 0 0 12px; font-size: 16px; }
.me { display: flex; align-items: center; gap: 14px; }
.me .avatar { width: 52px; height: 52px; font-size: 22px; }
.me strong { font-size: 19px; display: block; }
.me span { color: var(--muted); font-size: 14px; }
.version { text-align: center; color: var(--muted); font-size: 13px; margin-top: 20px; }

/* ---------- Toast and offline ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(112px + var(--safe-bottom)); transform: translate(-50%, 20px);
  background: var(--navy); color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 15px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.has-action { pointer-events: auto; white-space: nowrap; display: flex; align-items: center; gap: 14px; padding-right: 8px; }
#toast button { border: 0; background: var(--teal); color: #0F173F; font-weight: 700; font-size: 14px; border-radius: 9px; padding: 7px 12px; }
.offline { background: var(--yellow); color: var(--navy); font-size: 14px; font-weight: 600; text-align: center; padding: 7px 12px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--teal); border-radius: 50%; margin: 60px auto; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Footer, anchored to the bottom ---------- */
.foot-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 14;
  padding: 7px 16px calc(7px + var(--safe-bottom));
  background: var(--bg); border-top: 1px solid var(--line);
  text-align: center; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.foot-bar a { color: var(--ink); font-weight: 600; text-decoration: none; }
.foot-bar a span { color: var(--teal-ink); }
