[hidden] { display: none !important; }
:root {
  --bg: #f5f6f3;
  --surface: #ffffff;
  --text: #1c211d;
  --muted: #6b736d;
  --line: #e2e5e0;
  --accent: #2f7d4f;
  --accent-text: #ffffff;
  --accent-soft: #e3f1e8;
  --danger: #b3261e;
  --header: #2f7d4f;
  --header-text: #ffffff;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101411;
    --surface: #1a201c;
    --text: #e8ece9;
    --muted: #97a19a;
    --line: #2b332e;
    --accent: #5cbf85;
    --accent-text: #0d1a12;
    --accent-soft: #1f3528;
    --danger: #ff8a80;
    --header: #16251c;
    --header-text: #e8ece9;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
button, input, select { font: inherit; color: inherit; }
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  background: var(--header); color: var(--header-text);
}
.top h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 4px; }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 10px; color: inherit; display: grid; place-items: center; cursor: pointer; }
.icon-btn:active { background: rgba(255,255,255,.15); }
.live { width: 8px; height: 8px; border-radius: 50%; background: #e0a43a; opacity: .9; }
.live.on { background: #8ff0b3; }
main { max-width: 640px; margin: 0 auto; padding: 14px 16px calc(120px + env(safe-area-inset-bottom)); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.stack > * + * { margin-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 4px 8px; font-weight: 650; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
input[type=text], input[type=password], select {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: block; font-size: 14px; color: var(--muted); margin: 0 0 4px 2px; }
.error { color: var(--danger); font-size: 15px; min-height: 1.2em; }

/* Store list */
.stores { list-style: none; margin: 0; padding: 0; }
.stores li + li { border-top: 1px solid var(--line); }
.stores a {
  display: flex; align-items: center; gap: 12px; padding: 16px; color: inherit; text-decoration: none;
}
.stores .name { flex: 1; font-weight: 600; }
.badge { min-width: 28px; padding: 2px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 15px; text-align: center; }
.badge.zero { background: transparent; color: var(--muted); font-weight: 500; }
.chev { color: var(--muted); }

/* Items */
.group { margin-top: 6px; }
.items { list-style: none; margin: 0; padding: 0; }
.items li { display: flex; align-items: center; gap: 4px; }
.items li + li { border-top: 1px solid var(--line); }
.item-main {
  flex: 1; display: flex; align-items: center; gap: 12px; min-height: 54px; padding: 8px 4px 8px 14px;
  background: none; border: 0; text-align: left; cursor: pointer;
}
.check {
  flex: none; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--muted);
  display: grid; place-items: center;
}
.checked .check { background: var(--accent); border-color: var(--accent); }
.checked .check::after { content: ""; width: 7px; height: 12px; border: solid var(--accent-text); border-width: 0 2.5px 2.5px 0; transform: translateY(-1px) rotate(45deg); }
.item-text { flex: 1; min-width: 0; }
.item-name { display: block; overflow-wrap: anywhere; }
.item-meta { display: block; font-size: 13px; color: var(--muted); }
.qty { color: var(--accent); font-weight: 600; margin-left: 6px; }
.checked .item-name { text-decoration: line-through; color: var(--muted); }
.edit-btn { flex: none; background: none; border: 0; color: var(--muted); padding: 12px; cursor: pointer; border-radius: 10px; }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.cart-head { display: flex; align-items: center; justify-content: space-between; }
.cart-head h2 { margin-bottom: 8px; }

/* Add bar */
.addbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}
.addbar form { max-width: 640px; margin: 0 auto; display: grid; grid-template-columns: 1fr 80px; gap: 8px; }
.addbar .row2 { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.suggest { max-width: 640px; margin: 0 auto 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.suggest:empty { display: none; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 6px 12px; font-size: 15px; cursor: pointer; }

/* Order editor */
.order { list-style: none; margin: 0; padding: 0; }
.order li { display: flex; align-items: center; gap: 6px; padding: 6px 6px 6px 14px; min-height: 52px; }
.order li + li { border-top: 1px solid var(--line); }
.order .num { width: 24px; color: var(--muted); font-size: 14px; }
.order .label { flex: 1; }
.order button { background: none; border: 1px solid var(--line); border-radius: 10px; width: 40px; height: 40px; cursor: pointer; }
.order button:disabled { opacity: .3; }

.row { display: flex; gap: 8px; align-items: center; }
.row > .grow { flex: 1; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; align-items: center; gap: 8px; padding: 10px 8px 10px 14px; min-height: 52px; }
.list-plain li + li { border-top: 1px solid var(--line); }
.list-plain .grow { flex: 1; min-width: 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(140px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); display: flex; gap: 12px; align-items: center;
}
#toast.show { opacity: 1; pointer-events: auto; }
#toast button { background: none; border: 0; color: var(--accent-soft); font-weight: 700; cursor: pointer; padding: 0; }

dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(440px, calc(100% - 32px));
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
#dialog-form { padding: 18px; }
#dialog-form h3 { margin: 0 0 14px; font-size: 19px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.dialog-actions .spacer { flex: 1; }

.auth { max-width: 380px; margin: 8vh auto 0; padding: 22px; }
.auth h2 { text-transform: none; letter-spacing: 0; color: var(--text); font-size: 22px; margin: 0 0 6px; }

/* Purchase history */
.again { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; }
.add-again {
  flex: none; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--accent-soft); color: var(--accent); font-size: 22px; font-weight: 700; cursor: pointer; line-height: 1;
}
.add-again:disabled { background: transparent; opacity: .7; }
.list-plain .item-meta { display: block; }
a.btn { text-decoration: none; color: inherit; }
