:root {
  --bg: #f5f6f4;
  --card: #ffffff;
  --text: #1d2321;
  --muted: #6b7570;
  --line: #e2e5e2;
  --accent: #1f6f5c;
  --accent-soft: #e3f0ec;
  --danger: #b3261e;
  --counted: #f0f8f5;
  --on-accent: #ffffff;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121514;
    --card: #1b1f1e;
    --text: #e8ecea;
    --muted: #98a39e;
    --line: #2c3331;
    --accent: #5cc2a3;
    --accent-soft: #1d3a32;
    --danger: #ff8a80;
    --counted: #17261f;
    --on-accent: #0d2a22;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.3rem; margin: 0 0 12px; }
h2 { font-size: 1.05rem; margin: 0; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--accent); color: #fff;
}
.topbar a { color: #fff; }
.brand { font-weight: 700; font-size: 1.1rem; }
nav { display: flex; gap: 4px; }
nav a { padding: 6px 10px; border-radius: 8px; font-size: .95rem; }
nav a.active { background: rgba(255,255,255,.2); }

main { max-width: 720px; margin: 0 auto; padding: 16px 16px 120px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; margin-bottom: 12px;
}
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }

label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 4px; }
input, select {
  width: 100%; font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: auto; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px;
  background: var(--card); color: var(--text);
}
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
button.block { width: 100%; }

.login-card { position: relative; max-width: 380px; margin: 24px auto 96px; }
.login-logo { display: block; width: 100%; height: auto; border-radius: 10px; }
/* 柴犬趴在登入按鈕左下角，不擋住點擊 */
.login-dog {
  position: absolute; left: 4px; bottom: -78px; height: 150px; width: auto;
  pointer-events: none; z-index: 1;
}

.error { color: var(--danger); font-size: .9rem; min-height: 1.2em; }

/* 盤點單列表 */
.count-link { display: block; color: inherit; }
.stats { display: flex; gap: 16px; flex-wrap: wrap; font-size: .9rem; color: var(--muted); }
.stats b { color: var(--text); }

/* 點貨畫面 */
.toolbar { position: sticky; top: 56px; z-index: 5; background: var(--bg); padding: 8px 0; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); font-size: .9rem; font-weight: 500;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.cat-title { margin: 20px 0 8px; display: flex; justify-content: space-between; align-items: baseline; }
.items { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.item { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item.counted { background: var(--counted); }
.item .name { font-weight: 600; }
.item .meta { font-size: .8rem; color: var(--muted); }
.stepper { display: flex; align-items: center; gap: 4px; flex: none; }
.stepper button { width: 40px; height: 40px; padding: 0; font-size: 1.2rem; }
.stepper input { width: 64px; text-align: center; padding: 8px 4px; font-size: 1.05rem; }
.save-state { width: 14px; font-size: .75rem; text-align: center; flex: none; }

.summary {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 10px);
}
.summary .inner { max-width: 720px; margin: 0 auto; display: flex; justify-content: space-between; gap: 8px; font-size: .9rem; }
.summary b { display: block; font-size: 1.05rem; }

/* 商品與帳號管理 */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-top: 1px solid var(--line); font-size: .95rem; }
th { color: var(--muted); font-weight: 500; font-size: .85rem; }
.inactive { opacity: .5; }
.tag { font-size: .75rem; padding: 2px 6px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); }

dialog {
  border: 0; border-radius: 14px; padding: 20px; width: min(420px, calc(100% - 32px));
  background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.4); }

#toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; }
