/* 插畫風：薄荷綠／天藍色塊、黑色粗框、膠囊按鈕、硬陰影 */
:root {
  --ink: #111;
  --paper: #fff;
  --mint: #62b88e;
  --mint-soft: #d7f0e3;
  --sky: #a9d6e8;
  --sun: #ffd36b;
  --sun-soft: #fff0c2;
  --coral: #ff7a59;
  --cream: #fff8e8;
  --tan: #e9c9a0;
  --muted: #5b5b5b;
  --line: #111;
  --warn: #b25e00;
  --warn-bg: #ffe9c7;
  --danger: #c0291f;
  --danger-bg: #ffe1dc;
  --ok: #17703f;
  --ok-bg: #d4f1de;
  --info: #1b5e9b;
  --info-bg: #d9ecfb;
  --shadow: 4px 4px 0 var(--ink);
  --radius: 18px;
  --heading: "Arial Black", "Helvetica Neue", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 110px; }
body {
  margin: 0;
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.6;
  overflow-x: hidden;
}
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
a { color: inherit; }

/* 跑馬燈 */
.ticker { contain: paint; background: var(--tan); border-bottom: 2px solid var(--ink); overflow: hidden; white-space: nowrap; font-size: 13px; font-weight: 700; padding: 5px 0; }
.ticker-track { display: inline-flex; animation: marquee 40s linear infinite; }
.ticker-track span { padding-right: 24px; }
@keyframes marquee { to { transform: translateX(-50%); } }

/* 頁首 */
.site-header { position: sticky; top: 0; z-index: 30; background: var(--mint); border-bottom: 3px solid var(--ink); }
.header-inner { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding-top: 6px; padding-bottom: 2px; }
.tagline { font-size: 12px; font-weight: 800; line-height: 1.3; }
.brand { text-decoration: none; font-family: var(--heading); font-size: 30px; line-height: 1; letter-spacing: -1px; display: flex; gap: 4px; }
.brand b { color: var(--ink); text-shadow: 2px 2px 0 var(--sun); }
.brand .b2 { color: var(--paper); text-shadow: 2px 2px 0 var(--ink); }
.cart-link { justify-self: end; position: relative; text-decoration: none; font-size: 22px; background: var(--paper); border: 2.5px solid var(--ink); border-radius: 999px; width: 46px; height: 40px; display: grid; place-items: center; }
.badge { position: absolute; top: -8px; right: -8px; min-width: 22px; padding: 0 6px; background: var(--coral); color: #fff; border: 2px solid var(--ink); border-radius: 999px; font-size: 12px; font-weight: 800; text-align: center; line-height: 18px; }
.nav { display: flex; gap: 8px; overflow-x: auto; padding-top: 4px; padding-bottom: 8px; justify-content: center; }
.nav a { white-space: nowrap; padding: 4px 14px; border: 2.5px solid var(--ink); border-radius: 999px; background: var(--paper); text-decoration: none; font-weight: 800; font-size: 14px; }
.nav a:hover { background: var(--sun); }

/* 首頁主視覺 */
.hero { background: var(--mint); border-bottom: 3px solid var(--ink); padding: 18px 0 28px; }
.hero-inner { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.hero-art { width: 100%; max-width: 760px; height: auto; }
.pill-btn { background: var(--ink); color: #fff; text-decoration: none; font-weight: 800; padding: 10px 34px; border-radius: 999px; border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--sun); }
.pill-btn:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--sun); }

/* 區塊：全幅色帶 + 置中標題 */
main section {
  --band: var(--paper);
  position: relative;
  background: var(--band);
  box-shadow: 0 0 0 100vmax var(--band);
  clip-path: inset(0 -100vmax);
  padding: 44px 0 40px;
  text-align: left;
}
#overview { --band: var(--paper); }
#catalog { --band: var(--sky); }
#cart { --band: var(--cream); }
#orders { --band: var(--paper); }
#stock { --band: var(--mint-soft); }
#suppliers { --band: var(--sun-soft); }
main section::before {
  content: "● " attr(data-eyebrow) " ●";
  display: block; text-align: center; font-size: 11px; font-weight: 800; letter-spacing: 3px; margin-bottom: 4px;
}
main .wrap > section::after { content: ""; position: absolute; top: 0; left: -100vmax; right: -100vmax; height: 3px; background: var(--ink); }

h1, h2 { font-family: var(--heading); font-weight: 900; text-align: center; margin: 0 0 8px; font-size: clamp(28px, 6vw, 40px); line-height: 1.2; letter-spacing: 1px; }
h1 span, h2 span { background: linear-gradient(transparent 62%, var(--sun) 62%); }
h2 { margin-bottom: 14px; }
h3 { font-size: 17px; margin: 0 0 10px; font-weight: 800; }
.card h2 { font-size: 20px; text-align: left; letter-spacing: 0; }
.lead, .hint { color: var(--muted); margin: 0 0 16px; font-size: 14px; font-weight: 600; }
.lead { text-align: center; }
.section-head { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 8px; }
.section-head h2 { margin: 0; }
.ledger-head { flex-direction: row; justify-content: space-between; margin-top: 34px; }
.ledger-head h3 { font-size: 22px; font-family: var(--heading); margin: 0; }

/* 卡片 */
.card {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.cart-grid { grid-template-columns: 1.2fr 1fr; align-items: start; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 20px; }
.full { grid-column: 1 / -1; margin: 0; }
.steps { margin: 0 0 10px; padding-left: 20px; }

/* 統計磚 */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 18px 0 22px; }
.stat { border: 3px solid var(--ink); border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow); background: var(--sun); }
.stat:nth-child(3n+2) { background: var(--sky); }
.stat:nth-child(3n) { background: var(--mint-soft); }
.stat b { display: block; font-family: var(--heading); font-size: 26px; }
.stat span { font-size: 13px; font-weight: 700; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 18px 0 6px; justify-content: center; }

/* 表單 */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 14px; font-weight: 700; flex: 1; min-width: 0; }
.field.grow { flex: 2; }
.field.inline { flex-direction: row; align-items: center; gap: 8px; margin: 0; flex: none; }
.field em { color: var(--danger); font-style: normal; }
input, select, textarea {
  font: inherit; font-size: 16px; font-weight: 500; padding: 9px 12px; width: 100%;
  border: 2.5px solid var(--ink); border-radius: 12px; background: #fff; color: var(--ink);
}
.field.inline select { width: auto; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 3px solid var(--coral); outline-offset: 2px;
}
.invalid { border-color: var(--danger); background: var(--danger-bg); }
.err { color: var(--danger); font-weight: 700; }
.row { display: flex; gap: 12px; }
.filters { display: flex; gap: 12px; margin-bottom: 18px; }
.filters .field { margin-bottom: 0; }

/* 按鈕（膠囊） */
.btn {
  font: inherit; font-size: 14px; font-weight: 800; padding: 7px 18px; border-radius: 999px; cursor: pointer;
  border: 2.5px solid var(--ink); background: var(--paper); color: var(--ink);
  text-decoration: none; display: inline-block; transition: transform .08s, box-shadow .08s;
}
.btn:hover { background: var(--sun); transform: translate(-1px, -1px); box-shadow: 2px 2px 0 var(--ink); }
.btn.primary { background: var(--ink); color: #fff; }
.btn.primary:hover { background: #2b2b2b; box-shadow: 2px 2px 0 var(--sun); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger-bg); box-shadow: none; }
.btn.small { padding: 3px 12px; font-size: 13px; }
.btn.block { width: 100%; padding: 12px; font-size: 16px; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }

/* 品項卡片（縮圖＋內文） */
.item { display: flex; flex-direction: column; gap: 8px; padding: 0; overflow: hidden; }
.thumb { height: 96px; display: grid; place-items: center; position: relative; border-bottom: 3px solid var(--ink); }
.thumb span { font-size: 44px; line-height: 1; }
.thumb em { position: absolute; left: 10px; top: 8px; font-style: normal; font-size: 12px; font-weight: 800; background: var(--paper); border: 2px solid var(--ink); border-radius: 999px; padding: 0 8px; }
.item-body { padding: 0 14px; }
.item h3 { margin: 2px 0 4px; }
.tag { display: inline-block; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 800; background: var(--info-bg); border: 1.5px solid var(--ink); }
.meta { color: var(--muted); font-size: 13px; font-weight: 600; }
.price { font-weight: 900; font-size: 18px; }
.item-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; padding: 8px 14px 14px; flex-wrap: wrap; }

/* 分頁 ← 01 —— 05 → */
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 26px; font-weight: 800; }
.pager:empty { display: none; }
.pg-btn { width: 40px; height: 32px; border: 2.5px solid var(--ink); background: var(--paper); border-radius: 8px; font-size: 18px; font-weight: 900; cursor: pointer; }
.pg-btn:hover:not(:disabled) { background: var(--sun); }
.pg-btn:disabled { opacity: .35; cursor: not-allowed; }
.pg-num { display: inline-flex; align-items: center; gap: 8px; font-family: var(--heading); }
.pg-num i { width: 56px; height: 2px; background: var(--ink); display: inline-block; }

/* 請購單 */
.line { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 2px dashed #bbb; }
.line:last-child { border-bottom: 0; }
.line .name { flex: 1; min-width: 0; }
.line .name b { display: block; }
.qty { display: flex; align-items: center; gap: 4px; }
.qty input { width: 64px; text-align: center; padding: 5px; }
.qty button { width: 32px; height: 34px; padding: 0; }
.line .sub { width: 90px; text-align: right; font-weight: 800; }
.total { text-align: right; font-size: 20px; font-weight: 900; margin-top: 10px; padding-top: 10px; border-top: 3px solid var(--ink); }
.total small { display: block; font-weight: 600; color: var(--muted); font-size: 12px; }

/* 申請紀錄 */
.order { background: var(--paper); border: 3px solid var(--ink); border-radius: var(--radius); margin-bottom: 14px; box-shadow: var(--shadow); }
.order.flash { box-shadow: 0 0 0 5px var(--coral), var(--shadow); }
.order summary { list-style: none; cursor: pointer; padding: 14px 16px; display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.order summary::-webkit-details-marker { display: none; }
.order summary::before { content: "▸"; font-weight: 900; }
.order[open] summary::before { content: "▾"; }
.order .id { font-weight: 900; font-family: var(--heading); }
.order .grow { flex: 1; color: var(--muted); font-size: 14px; font-weight: 600; }
.order-body { padding: 0 16px 14px; border-top: 2px solid var(--ink); }
.order-body ul { margin: 10px 0; padding-left: 20px; }
.order-body .info { color: var(--muted); font-size: 14px; margin: 8px 0; font-weight: 600; }
.order-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.history { font-size: 13px; color: var(--muted); margin-top: 10px; font-weight: 600; }
.status { padding: 1px 12px; border-radius: 999px; font-size: 13px; font-weight: 800; border: 2px solid var(--ink); }
.s-待審核 { background: var(--sun); }
.s-已核准 { background: var(--sky); }
.s-已下單 { background: #d9ccff; }
.s-已到貨 { background: var(--ok-bg); }
.s-已退回, .s-已取消 { background: var(--danger-bg); }
.urgent { color: #fff; background: var(--coral); border: 2px solid var(--ink); border-radius: 999px; padding: 0 10px; font-weight: 800; font-size: 12px; }

/* 庫存 */
.stock-row { display: grid; grid-template-columns: 1.6fr 1.2fr 1.4fr auto; gap: 12px; align-items: center; background: var(--paper); border: 3px solid var(--ink); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 10px; }
.stock-row.low { background: var(--warn-bg); box-shadow: var(--shadow); }
.bar { height: 10px; background: #fff; border: 2px solid var(--ink); border-radius: 999px; overflow: hidden; margin-bottom: 3px; }
.bar > i { display: block; height: 100%; background: var(--mint); }
.low .bar > i { background: var(--coral); }
.low-tag { color: var(--danger); font-weight: 800; font-size: 13px; }
.row-btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.mini { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 2px dashed #ccc; font-size: 14px; font-weight: 600; }
.mini:last-child { border-bottom: 0; }

/* 庫存異動紀錄 */
.ledger-row { display: flex; gap: 12px; align-items: center; background: var(--paper); border: 2.5px solid var(--ink); border-radius: 14px; padding: 10px 14px; margin-bottom: 8px; }
.ledger-row .grow { flex: 1; min-width: 0; }
.ledger-row .chg { text-align: right; font-weight: 900; white-space: nowrap; }
.ledger-row .chg .meta { font-weight: 600; }
.ledger-row .tm { white-space: nowrap; }
.lt { padding: 1px 12px; border-radius: 999px; font-size: 13px; font-weight: 800; white-space: nowrap; border: 2px solid var(--ink); }
.lt-in { background: var(--ok-bg); }
.lt-out { background: var(--danger-bg); }
.lt-set { background: var(--info-bg); }

/* 空狀態 */
.empty { text-align: center; padding: 28px 12px; color: var(--muted); background: var(--paper); border: 3px dashed var(--ink); border-radius: var(--radius); font-weight: 600; }
.empty b { display: block; color: var(--ink); margin-bottom: 4px; font-size: 16px; }
.card .empty { border: 0; padding: 14px 8px; background: transparent; }
.empty .btn { margin-top: 10px; }

/* 對話框與提示 */
dialog { border: 3px solid var(--ink); border-radius: var(--radius); padding: 20px; width: min(500px, calc(100% - 24px)); box-shadow: 8px 8px 0 var(--ink); background: var(--cream); color: var(--ink); }
dialog::backdrop { background: rgba(17, 17, 17, .5); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; width: min(440px, calc(100% - 24px)); }
.toast { padding: 12px 16px; border-radius: 14px; border: 3px solid var(--ink); box-shadow: 4px 4px 0 var(--ink); font-size: 15px; font-weight: 700; color: var(--ink); }
.toast.ok { background: var(--mint); }
.toast.error { background: var(--coral); }
.toast.info { background: var(--sun); }

.site-footer { background: var(--ink); color: #fff; padding: 22px 0 30px; font-size: 13px; text-align: center; font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  .ticker-track { animation: none; }
  html { scroll-behavior: auto; }
}

/* 平板／手機 */
@media (max-width: 900px) {
  .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  html { scroll-padding-top: 16px; }
  .site-header { position: static; }
  .tagline { display: none; }
  .header-inner { grid-template-columns: 1fr auto; }
  .brand { font-size: 30px; }
  .nav { justify-content: flex-start; }
  .grid-2, .cart-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .filters, .row { flex-direction: column; gap: 0; }
  .filters { gap: 10px; }
  .stock-row { grid-template-columns: 1fr; }
  .stock-row .row-btns { justify-content: flex-start; }
  .line { flex-wrap: wrap; }
  .line .name { flex-basis: 100%; }
  .line .sub { margin-left: auto; }
  .ledger-row { flex-wrap: wrap; }
  .ledger-head { flex-direction: column; }
  main section { padding: 34px 0 30px; }
}

/* 匯入預覽 */
.imp-preview { margin-bottom: 8px; font-size: 14px; font-weight: 600; }
.imp-ok { background: var(--ok-bg); border: 2.5px solid var(--ink); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.imp-err { background: var(--danger-bg); border: 2.5px solid var(--danger); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; color: var(--danger); }
.imp-warn { background: var(--warn-bg); border: 2.5px solid var(--ink); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }

/* 分頁器（庫存也使用） */
.pager.stock-pager { margin-top: 18px; }

/* 手機：觸控尺寸、導覽換行、避免文字被擠成一字一行 */
@media (max-width: 760px) {
  .nav { flex-wrap: wrap; justify-content: center; overflow: visible; gap: 6px; }
  .nav a { min-height: 40px; display: inline-flex; align-items: center; padding: 4px 14px; }
  .cart-link { width: 48px; height: 44px; }
  .btn { min-height: 44px; padding: 8px 18px; }
  .btn.small { min-height: 40px; padding: 6px 14px; }
  .pill-btn { min-height: 48px; display: inline-flex; align-items: center; }
  input, select, textarea { min-height: 44px; }
  input[type=checkbox] { min-height: 0; width: 22px; height: 22px; }
  .qty button { width: 44px; height: 44px; }
  .qty input { width: 72px; height: 44px; }
  .pg-btn { width: 48px; height: 44px; }
  .order summary { min-height: 48px; }
  .order .grow { flex: 1 1 100%; }
  .item-foot .btn { flex: 1 1 auto; }
  .row-btns .btn { flex: 1 1 auto; }
  .ledger-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; }
  .ledger-row .lt { grid-area: 1 / 1; justify-self: start; }
  .ledger-row .tm { grid-area: 1 / 2; text-align: right; }
  .ledger-row .grow { grid-area: 2 / 1 / 3 / 3; }
  .ledger-row .chg { grid-area: 3 / 1 / 4 / 3; text-align: left; }
}

.pack { font-size: 13px; font-weight: 800; background: var(--sun-soft); border: 2px solid var(--ink); border-radius: 10px; padding: 2px 8px; margin-top: 6px; display: inline-block; }

/* ===== 三條路徑：請購端／審核端／管理端 ===== */
body[data-view="request"] [data-views]:not([data-views~="request"]),
body[data-view="review"] [data-views]:not([data-views~="review"]),
body[data-view="admin"] [data-views]:not([data-views~="admin"]) { display: none !important; }
body[data-view="admin"] [data-action="add-cart"],
body[data-view="admin"] [data-action="restock"] { display: none; }
main .wrap > section.first-visible::after { display: none; }

.roletabs { display: flex; gap: 8px; justify-content: center; padding-top: 4px; padding-bottom: 8px; }
.roletabs a { text-decoration: none; padding: 5px 20px; border: 2.5px solid var(--ink); border-radius: 999px; background: var(--paper); font-weight: 900; font-size: 15px; white-space: nowrap; display: inline-flex; align-items: center; }
.roletabs a:hover { background: var(--sun); }
.roletabs a.active { background: var(--ink); color: #fff; box-shadow: 3px 3px 0 var(--sun); }
.roletabs i { font-style: normal; font-size: 12px; font-weight: 800; background: var(--coral); color: #fff; border: 1.5px solid var(--ink); border-radius: 999px; padding: 0 7px; margin-left: 6px; }

.rolebar { border-bottom: 3px solid var(--ink); padding: 14px 0 12px; background: var(--mint-soft); }
body[data-view="review"] .rolebar { background: var(--sky); }
body[data-view="admin"] .rolebar { background: var(--sun-soft); }
.role-desc { margin: 0 0 8px; text-align: center; font-weight: 800; font-size: 15px; }
.rolebar .reviewer { justify-content: center; margin: 0 auto 10px; }
.rolebar .reviewer input { width: 12em; }
.subnav { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.subnav a { text-decoration: none; padding: 3px 14px; border: 2px solid var(--ink); border-radius: 999px; background: var(--paper); font-weight: 800; font-size: 14px; }
.subnav a:hover { background: var(--sun); }
.role-note { margin: 10px 0 0; text-align: center; font-size: 13px; color: var(--muted); font-weight: 600; }

@media (max-width: 760px) {
  .roletabs { gap: 6px; }
  .roletabs a { padding: 4px 12px; min-height: 44px; font-size: 14px; }
  .roletabs i { margin-left: 4px; padding: 0 5px; }
  .subnav a { min-height: 40px; display: inline-flex; align-items: center; }
  .rolebar .reviewer input { width: 10em; }
}

/* ---------- 登入 ---------- */
body.locked { overflow: hidden; }
.auth-gate { position: fixed; inset: 0; z-index: 1000; background: var(--mint-soft); display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; }
.auth-gate[hidden] { display: none; }
.auth-card { width: 100%; max-width: 380px; background: var(--paper); border: 3px solid var(--ink); border-radius: 18px; box-shadow: 6px 6px 0 var(--ink); padding: 24px; display: grid; gap: 12px; }
.auth-card h1 { margin: 0; font-size: 24px; }
.auth-brand { font-size: 22px; display: flex; gap: 2px; }
.auth-msg { min-height: 1.2em; margin: 0; font-size: 14px; color: var(--danger); }
.whoami { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-weight: 700; }
