/* =============================================================
   門店備品採買清單 — visual theme (redesign 2026-10-15)
   Matches the original private-artifact aesthetic:
   warm cream + deep forest green + gold, serif display headings.
   Design tokens (defaults; user can override accent/accent2/bg
   in Settings — applied as CSS vars on :root by applyTheme()):
     --bg: #f7f3ec      --surface: #fffdf7    --text: #232a26
     --dim: #6f7a70      --border: #e4dcc8    --accent: #1e3d33
     --accent-ink: #f3ecd9  --gold: #b08d4c   --warn: #b3543f
     --radius: 12px
   ============================================================= */
:root {
  --bg: #f7f3ec;
  --surface: #fffdf7;
  --text: #232a26;
  --dim: #6f7a70;
  --border: #e4dcc8;
  --accent: #1e3d33;
  --accent-ink: #f3ecd9;
  --gold: #b08d4c;
  --warn: #b3543f;
  --radius: 12px;
  --font-display: "Songti TC", "Noto Serif TC", "PMingLiU", serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ---------- top language bar ---------- */
.langbar {
  display: flex;
  justify-content: flex-end;
  padding: 12px 16px 0;
}
.langbar button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--dim);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
}

.shell {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: 0 2px 10px rgba(30, 61, 51, 0.06);
  margin-bottom: 14px;
}
.card h3 {
  margin: 0 0 12px;
  font-size: 17px;
  font-family: var(--font-display);
  letter-spacing: 0.04em;
  color: var(--accent);
}

/* ---------- brand / login ---------- */
.brand { text-align: center; margin-bottom: 20px; }
.brand h1 {
  font-family: var(--font-display);
  font-size: 24px;
  letter-spacing: 0.08em;
  margin: 12px 0 4px;
  color: var(--accent);
}
.brand .sub { color: var(--dim); font-size: 13px; margin: 0; letter-spacing: 0.05em; }

/* ---------- forms ---------- */
form label { display: block; margin-bottom: 14px; }
form label span, .flabel { display: block; font-size: 14px; margin-bottom: 6px; color: var(--text); }
form input, form select {
  width: 100%;
  font-size: 17px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}
form input:focus, form select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  border-color: var(--accent);
}
textarea {
  width: 100%; font-size: 15px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  font-family: inherit; background: var(--surface); color: var(--text);
}
select {
  width: 100%; font-size: 16px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
}

/* ---------- buttons ---------- */
button.primary, button.secondary, button.ghost {
  border-radius: var(--radius); padding: 12px 18px; font-size: 16px;
  cursor: pointer; border: 1px solid transparent; font-weight: 600;
}
button.primary {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}
button.primary:active { filter: brightness(1.15); }
button.secondary {
  background: var(--surface); color: var(--accent); border-color: var(--border);
}
button.ghost {
  background: transparent; color: var(--dim); border-color: transparent;
  padding: 8px 10px; font-size: 14px;
}
button.mini {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 6px 10px; font-size: 13px; cursor: pointer;
}
button.mini.danger { color: var(--warn); border-color: #e8c4b8; }
button.mini.warn { color: #8a6d1f; border-color: #e8d9a8; }
button.small { padding: 8px 12px; font-size: 14px; }

/* ---------- status / hints ---------- */
.status { min-height: 20px; font-size: 14px; text-align: center; }
.status.error { color: var(--warn); }
.status.ok { color: var(--accent); }
.hint { text-align: center; color: var(--dim); font-size: 13px; margin-top: 16px; }
.muted { color: var(--dim); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------- overlays / sheets ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(27, 24, 21, 0.45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--surface); border-radius: 18px 18px 0 0; width: 100%; max-width: 480px;
  max-height: 88dvh; overflow-y: auto; padding: 22px 18px calc(20px + env(safe-area-inset-bottom));
}
.sheet.long { max-height: 92dvh; }
.sheet h3 { margin: 0 0 14px; font-family: var(--font-display); color: var(--accent); }
.sheet ol { padding-left: 20px; }
.sheet label { display: block; margin-bottom: 12px; }

/* =============================================================
   MAIN APP HEADER — centered serif store name, sticky + blur
   (mirrors the original artifact header)
   ============================================================= */
.appheader {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-top));
  padding-top: calc(12px + env(safe-area-inset-top));
  margin: -20px -16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.appheader .hleft, .appheader .hright { width: 72px; flex-shrink: 0; }
.appheader .hleft { font-size: 12px; color: var(--dim); }
.appheader .hright { display: flex; justify-content: flex-end; align-items: center; gap: 4px; }
.storename {
  flex: 1; text-align: center;
  font-family: var(--font-display);
  font-size: 19px; letter-spacing: 0.08em;
  color: var(--accent);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.gearbtn {
  border: 0; background: transparent; cursor: pointer;
  font-size: 21px; line-height: 1; padding: 6px;
  color: var(--accent);
  border-radius: 10px;
}
.gearbtn:active { background: var(--border); }
.backbtn {
  border: 0; background: transparent; cursor: pointer;
  font-size: 15px; padding: 6px 4px; color: var(--accent); font-weight: 600;
}
.staffchip {
  font-size: 13px; color: var(--dim); text-align: center;
  margin: -4px 0 10px;
}
.staffchip .pilot { color: var(--gold); font-weight: 700; }

/* ---------- trial banner ---------- */
.banner {
  background: #fdf6e3; border: 1px solid var(--gold); border-radius: var(--radius);
  padding: 10px 14px; font-size: 14px; margin-bottom: 10px; color: var(--text);
}
.banner.warn { background: #fbeee9; border-color: var(--warn); }

/* ---------- tab bar ---------- */
.tabbar {
  position: sticky; bottom: 0; display: flex; background: var(--surface);
  border-top: 1px solid var(--border); margin: 12px -16px -48px;
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; border: 0; background: none; padding: 12px 4px;
  font-size: 13px; color: var(--dim); cursor: pointer;
}
.tabbar button.on { color: var(--accent); font-weight: 700; }
.tabpane { padding-bottom: 8px; }

/* ---------- settings full-screen view ---------- */
.settingsview .tabbar, .settingsview .tabpane { display: none !important; }
.settingsview #tab-settings { display: block !important; }
.settingsview .appheader .hright .gearbtn { display: none; }

/* ---------- board ---------- */
.toolbar { margin-bottom: 10px; }
.toolbar input[type=search] {
  width: 100%; font-size: 16px; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 7px 14px; font-size: 14px; cursor: pointer;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.itemrow {
  display: flex; align-items: center; gap: 10px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; cursor: pointer;
}
.itemrow.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
.itemrow.off { opacity: 0.55; }
.tick {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center; color: var(--accent-ink);
  flex-shrink: 0; font-size: 15px;
}
.itemrow.sel .tick { background: var(--accent); border-color: var(--accent); }
.ibody { flex: 1; min-width: 0; }
.iname { font-size: 16px; font-weight: 600; }
.en { font-weight: 400; color: var(--dim); font-size: 13px; }
.isub { font-size: 13px; color: var(--dim); margin-top: 2px; }
.iprice { font-size: 13px; color: var(--accent); margin-top: 2px; font-weight: 600; }
.badge {
  font-size: 12px; background: color-mix(in srgb, var(--gold) 22%, var(--surface));
  color: var(--text); border-radius: 6px; padding: 1px 6px; border: 1px solid var(--gold);
}
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.bottombar {
  position: sticky; bottom: 64px; display: flex; justify-content: space-between; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 10px 14px; margin-top: 10px;
  box-shadow: 0 4px 14px rgba(30, 61, 51, 0.08);
}

/* ---------- checklist ---------- */
.chgroup { margin-bottom: 14px; }
.chtitle {
  font-weight: 700; font-size: 15px; margin: 8px 0 6px;
  color: var(--accent); font-family: var(--font-display); letter-spacing: 0.04em;
}
.linerow {
  display: flex; gap: 10px; align-items: flex-start; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; cursor: pointer;
}
.linerow.done { opacity: 0.6; }
.linerow.done .lname { text-decoration: line-through; }
.linerow input[type=checkbox] {
  width: 22px; height: 22px; margin-top: 2px; flex-shrink: 0; accent-color: var(--accent);
}
.lbody { flex: 1; }
.lname { font-size: 15px; font-weight: 600; }
.lsub { font-size: 13px; color: var(--dim); display: block; margin-top: 2px; }
.meta { font-size: 14px; margin-bottom: 10px; color: var(--dim); }

/* ---------- generic rows ---------- */
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; margin: 10px 0; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; margin-bottom: 10px; }
.checkline { display: flex !important; align-items: center; gap: 6px; font-size: 14px; }
.checkline input { width: auto !important; accent-color: var(--accent); }

/* =============================================================
   ROUTING RULE — single inline-input sentence (centerpiece)
   滿 $ [150] 走 [McKesson]，未滿走 [Amazon]
   ============================================================= */
.rulebox {
  border: 1.5px solid var(--gold);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--gold) 10%, var(--surface));
  padding: 18px 14px;
  font-family: var(--font-display);
  font-size: 20px;
  line-height: 2.4;
  color: var(--text);
  margin-bottom: 14px;
  text-align: center;
}
.rulebox .ruleinput {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--gold);
  border-radius: 0;
  padding: 2px 6px;
  margin: 0 2px;
  text-align: center;
  min-width: 0;
  vertical-align: baseline;
}
.rulebox .rulemoneyinput { width: 5.2em; }
.rulebox .rulechan { width: 6.5em; }
.rulebox .ruleinput:focus {
  outline: none;
  border-bottom-color: var(--accent);
  background: color-mix(in srgb, var(--gold) 14%, transparent);
}
/* hide number spinners on the inline threshold field */
.rulebox input[type=number]::-webkit-inner-spin-button,
.rulebox input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.rulebox input[type=number] { -moz-appearance: textfield; appearance: textfield; }

/* custom channel management */
.chansect { margin-bottom: 12px; }
.addchanrow { display: flex; gap: 8px; margin: 8px 0; align-items: center; }
.addchanrow .ruleinput {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
.chip.static { cursor: default; }
.chip .x {
  border: none; background: none; color: var(--warn);
  font-size: 16px; font-weight: 700; cursor: pointer;
  padding: 0 0 0 4px; line-height: 1;
}

/* legacy segmented control (kept for compatibility, unused by new UI) */
.seg { display: flex; gap: 6px; margin-bottom: 12px; }
.seg button {
  flex: 1; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 10px 4px; font-size: 13px; cursor: pointer;
}
.seg button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.moneyrow { display: flex; align-items: center; gap: 6px; }
.moneyrow input { flex: 1; }

/* =============================================================
   THEME COLOR CUSTOMIZATION
   ============================================================= */
.colorrow { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.colorfield { display: block; }
.colorfield > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.colorpick { display: flex; align-items: center; gap: 6px; }
input[type=color].swatch {
  width: 44px; height: 36px; padding: 2px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
.colorhex { font-size: 11px; color: var(--dim); font-variant-numeric: tabular-nums; }
.themepreview {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin: 10px 0;
}
.themepreview .pv-title { font-family: var(--font-display); font-weight: 700; margin-bottom: 8px; }
.themepreview .pv-row { display: flex; gap: 8px; }
.pv-btn {
  border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 700;
}
.presetrow { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.preset {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 6px 12px 6px 6px; font-size: 13px; cursor: pointer; color: var(--text);
}
.preset .dots { display: flex; }
.preset .dot { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); margin-right: -5px; }
.preset.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* ---------- item editor ---------- */
.chrow { display: flex; gap: 6px; margin-bottom: 6px; }
.chrow .chname { flex: 1; }
.chrow .chprice { width: 110px; }

.filebtn {
  display: inline-block; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 10px 14px; font-size: 14px; cursor: pointer;
}
.rowbtn {
  width: 100%; text-align: left; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: var(--radius); padding: 14px; font-size: 16px; cursor: pointer;
}

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--accent); color: var(--accent-ink); border-radius: 10px; padding: 10px 18px;
  font-size: 14px; z-index: 99; max-width: 90vw;
}

.contact { font-size: 18px; text-align: center; margin: 16px 0; }
.contact a { color: var(--accent); }
.legal h4 { margin: 16px 0 6px; font-family: var(--font-display); color: var(--accent); }
.legal p { font-size: 14px; line-height: 1.6; }

/* Saved routing rule presets */
.presetlist { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.presetlist:empty { display: none; }
.presetcard {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); padding: 10px 12px;
}
.presetcard .pinfo { flex: 1; min-width: 0; }
.presetcard .plabel { font-weight: 600; font-size: 14px; color: var(--text); }
.presetcard .prule { font-size: 13px; color: var(--dim); margin-top: 2px; }
.presetcard .pbtns { display: flex; gap: 6px; flex-shrink: 0; }
.hint { font-size: 12px; color: var(--dim); margin: 6px 0 0; }
