/* =================================================================
   配件管家 — 暖金 · 玫瑰金 風格（方向 1a）
   Design tokens + 元件樣式　|　全繁中　|　PWA-safe（無 blur、無持續動畫）
   把以下對應你現有的 class 貼回 styles.css 即可。
   class 對照見每段註解。
   ================================================================= */

:root {
  /* ---- 字體：3 種角色 ---- */
  --font-ui:    "Noto Sans TC", system-ui, -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
  --font-serif: "Noto Serif TC", "Songti TC", serif;
  --font-mono:  "Space Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  /* ---- 字級階層 ---- */
  --fs-display: 30px;   /* 大數字 / 歡迎標題 */
  --fs-h1:      23px;   /* 畫面主標 */
  --fs-h2:      18px;   /* 面板中文標題 */
  --fs-h3:      15px;   /* 區塊小標 */
  --fs-body:    14px;   /* 內文 */
  --fs-input:   16px;   /* 表單輸入（≥16px，避免 iOS 點擊放大）*/
  --fs-sm:      12.5px;
  --fs-xs:      11px;

  /* ---- 主色 + 強調（香檳玫瑰金）---- */
  --accent:        #A9794E;
  --accent-light:  #D8B48A;
  --accent-deep:   #825A36;
  --accent-soft:   #F3E8D6;
  --accent-glow:   rgba(169,121,78,.18);
  --accent-grad:   linear-gradient(135deg, #C49A6A, #A9794E);

  /* ---- 語意色（各含實色 + 淡色底）---- */
  --success: #5E8C68;  --success-soft: #E5EEE3;
  --danger:  #B5524E;  --danger-soft:  #F6E5E1;
  --warning: #BE8A3C;  --warning-soft: #F7ECD6;
  --info:    #5E7A98;  --info-soft:    #E6ECF2;

  /* ---- 4 個類別 tag（bg + fg）對應 .cat.pkg/.mat/.acc/.gft ---- */
  --tag-1-bg: #E8ECF1;  --tag-1-fg: #5E7388;  /* pkg 包裝耗材（板岩藍）*/
  --tag-2-bg: #EFE7F4;  --tag-2-fg: #7A5E9A;  /* mat 礦石材料（紫水晶）*/
  --tag-3-bg: #E3EEE5;  --tag-3-fg: #4E8262;  /* acc 線材繩材（鼠尾草）*/
  --tag-4-bg: #F6EAD5;  --tag-4-fg: #A9794E;  /* gft 金屬配件（金）   */

  /* ---- 背景階層 ---- */
  --bg-base:     #F1E9DD;  /* 最底（app 外圍）*/
  --bg:          #F7F0E6;  /* 內容區 */
  --bg-card:     #FFFDF8;  /* 卡片 / 面板 */
  --bg-elevated: #FFFFFF;  /* 彈窗 / 浮層 */
  --bg-hover:    #F0E7D8;  /* hover / 表頭 */
  --bg-input:    #FBF5EB;  /* 輸入框底 */

  /* ---- 文字階層 ---- */
  --text:           #3A322B;
  --text-secondary: #6E6256;
  --text-tertiary:  #A4937F;

  /* ---- 邊框 / 陰影 / 圓角 ---- */
  --border:        #EADFCC;
  --border-strong: #D6C4A9;
  --border-accent: #C9A36A;
  --shadow:    0 1px 2px rgba(58,48,38,.06), 0 1px 1px rgba(58,48,38,.04);
  --shadow-lg: 0 16px 40px rgba(58,48,38,.16);
  --radius:      12px;
  --radius-sm:   8px;
  --radius-lg:   18px;
  --radius-pill: 999px;

  /* ---- 間距（4pt 基準）---- */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-7: 32px; --sp-8: 40px;

  /* ---- 動效（僅微互動；無背景無限動畫）---- */
  --ease: cubic-bezier(.4, 0, .2, 1);
  --dur:  .18s;
  --dur-slow: .28s;
}

/* ===== 基底 ===== */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg-base);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.serif { font-family: var(--font-serif); }

/* =================================================================
   版面外殼（若你的結構不同，僅參考；元件樣式才是重點）
   ================================================================= */
.app { display: flex; min-height: 100vh; background: var(--bg-base); }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.content { flex: 1; padding: var(--sp-4) var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-4); }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-3); }
.layout { display: grid; grid-template-columns: 1.65fr 1fr; gap: var(--sp-4); align-items: start; }
.col-side { display: flex; flex-direction: column; gap: var(--sp-4); min-width: 0; }

/* =================================================================
   左側導航　.rail / .rail .ni / .rail .ni.on
   ================================================================= */
.rail {
  width: 80px; flex-shrink: 0;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
  padding: var(--sp-4) var(--sp-2);
  gap: var(--sp-1);
  padding-top: max(var(--sp-4), env(safe-area-inset-top));
}
/* 品牌 logo（中文字塞圓角方塊）*/
.rail .brand {
  width: 44px; height: 44px; border-radius: var(--radius);
  background: var(--accent-grad); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-serif); font-size: 24px; font-weight: 700;
  box-shadow: var(--shadow); margin-bottom: var(--sp-3);
  user-select: none;
}
.rail .ni {
  position: relative;
  width: 100%; min-height: 56px;        /* ≥44px 觸控 */
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 5px; padding: var(--sp-2) var(--sp-1);
  border: none; background: transparent; cursor: pointer;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-ui);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.rail .ni svg { width: 20px; height: 20px; }
.rail .ni .lab { font-size: var(--fs-xs); font-weight: 500; letter-spacing: .02em; }
.rail .ni:hover { background: var(--bg-hover); color: var(--text); }
.rail .ni.on { background: var(--accent-soft); color: var(--accent); }
.rail .ni.on .lab { font-weight: 700; }
.rail .ni.on::before {            /* 選中態：左側金條 */
  content: ""; position: absolute; left: -8px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 22px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.rail .ni:disabled { opacity: .4; cursor: not-allowed; }

/* =================================================================
   頂部列　.strip / .ttl / .cmd / .icon-btn
   ================================================================= */
.strip {
  height: 56px; flex-shrink: 0;
  display: flex; align-items: center; gap: var(--sp-4);
  padding: 0 var(--sp-5);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.strip .ttl {
  font-family: var(--font-serif); font-size: var(--fs-h1); font-weight: 600;
  color: var(--text); white-space: nowrap; margin: 0;
}
.strip .search { flex: 1; max-width: 360px; min-width: 0; position: relative; display: flex; align-items: center; }
.strip .search svg { position: absolute; left: 12px; width: 16px; height: 16px; color: var(--text-tertiary); pointer-events: none; }
.strip .search .cinput { width: 100%; padding-left: 34px; border-radius: var(--radius-pill); }
.strip .cmd { margin-left: auto; display: flex; align-items: center; gap: var(--sp-3); }

/* 同步狀態（連線中 / 已同步 / 失敗 三色）*/
.sync {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  padding: 6px 12px; border-radius: var(--radius-pill);
  font-size: var(--fs-sm); font-weight: 600;
}
.sync::before { content: ""; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.sync.ok      { background: var(--success-soft); color: var(--success); }
.sync.ok::before      { background: var(--success); }
.sync.syncing { background: var(--info-soft); color: var(--info); }
.sync.syncing::before { background: var(--info); }
.sync.fail    { background: var(--danger-soft); color: var(--danger); }
.sync.fail::before    { background: var(--danger); }

/* 圖示鈕 */
.icon-btn {
  width: 40px; height: 40px; flex-shrink: 0;       /* ≥44 區域含點擊外距亦可 */
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text-secondary); cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--bg-hover); color: var(--accent); border-color: var(--border-strong); }
.icon-btn:active { transform: translateY(1px); }

/* =================================================================
   面板 panel　.panel / .ph (.ix .lab .zh) / .cmd
   ================================================================= */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  overflow: hidden; min-width: 0;
}
.ph { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); }
.ph .ix {                       /* 索引標籤 01 / 02… */
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: var(--fs-xs); font-weight: 700; color: var(--accent);
  background: var(--accent-soft); padding: 2px 6px; border-radius: var(--radius-sm);
}
.ph .meta { display: flex; flex-direction: column; line-height: 1.25; flex: 1; min-width: 0; }
.ph .lab { font-family: var(--font-mono); font-size: 9.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--text-tertiary); }
.ph .zh  { font-family: var(--font-serif); font-size: var(--fs-h2); font-weight: 600; color: var(--text); }
.ph .cmd { margin-left: auto; display: flex; gap: var(--sp-2); }

/* =================================================================
   KPI 卡　.kpis / .kpi (.lab .zh .val .foot)　.kpi.alert = 警示
   ================================================================= */
.kpi {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 15px;
  display: flex; flex-direction: column; gap: 7px;
  box-shadow: var(--shadow); min-width: 0;
}
.kpi .lab { font-family: var(--font-mono); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-tertiary); }
.kpi .zh  { font-size: var(--fs-sm); color: var(--text-secondary); }
.kpi .val { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: var(--fs-display); font-weight: 700; line-height: 1; color: var(--text); }
.kpi .val .unit { font-family: var(--font-ui); font-size: var(--fs-sm); font-weight: 400; color: var(--text-tertiary); margin-left: 3px; }
.kpi .foot { display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-xs); font-weight: 500; color: var(--text-tertiary); }
.kpi .foot svg { width: 13px; height: 13px; }
.kpi .foot.up   { color: var(--success); }
.kpi .foot.down { color: var(--text-tertiary); }
/* 缺貨數警示態 */
.kpi.alert { background: var(--warning-soft); border-color: transparent; }
.kpi.alert .lab, .kpi.alert .val, .kpi.alert .foot { color: var(--warning); }

/* =================================================================
   桌面表格　table.grid (th / td / tr.low)
   ================================================================= */
table.grid { width: 100%; border-collapse: collapse; }
table.grid th {
  text-align: left; padding: 9px 14px;
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: .02em;
  color: var(--text-tertiary); background: var(--bg-hover);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.grid th.num, table.grid td.num { text-align: right; }
table.grid td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.grid tbody tr { transition: background var(--dur) var(--ease); }
table.grid tbody tr:hover { background: var(--bg-hover); }
table.grid tbody tr:last-child td { border-bottom: none; }
/* 缺貨列強調 */
table.grid tr.low { background: var(--danger-soft); }
table.grid tr.low:hover { background: #F3DAD5; }
table.grid tr.low td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
/* 品名 + 狀態點 */
.cell-name { display: flex; align-items: center; gap: 9px; }
.cell-name .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--success); }
.cell-name .nm { font-size: 13.5px; font-weight: 500; color: var(--text); }
tr.low .cell-name .dot { background: var(--danger); }
.cell-sku { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-secondary); line-height: 1.5; }
.cell-sku .loc { color: var(--text-tertiary); }
.cell-qty { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 16px; font-weight: 700; color: var(--text); white-space: nowrap; }
.cell-qty .unit { font-family: var(--font-ui); font-size: var(--fs-xs); font-weight: 400; color: var(--text-tertiary); margin-left: 3px; }
tr.low .cell-qty { color: var(--danger); }

/* =================================================================
   類別標籤　.cat.pkg / .mat / .acc / .gft
   ================================================================= */
.cat {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: var(--radius-pill);
  font-size: var(--fs-xs); font-weight: 600; white-space: nowrap;
}
.cat.pkg { background: var(--tag-1-bg); color: var(--tag-1-fg); }
.cat.mat { background: var(--tag-2-bg); color: var(--tag-2-fg); }
.cat.acc { background: var(--tag-3-bg); color: var(--tag-3-fg); }
.cat.gft { background: var(--tag-4-bg); color: var(--tag-4-fg); }
/* 手鍊配件三材質 */
.cat.gld { background: #F6EAD5; color: #A9794E; }   /* 金 */
.cat.slv { background: #ECEEF1; color: #8A8F99; }   /* 銀 */
.cat.stl { background: #E4E9ED; color: #5E7388; }   /* 不鏽鋼（鋼藍灰）*/

/* =================================================================
   庫存量條　.track / .fill（+ .tick 安全庫存刻度線）
   ================================================================= */
.track { position: relative; height: 6px; border-radius: var(--radius-pill); background: var(--bg-hover); width: 100%; max-width: 150px; }
.fill  { position: absolute; left: 0; top: 0; bottom: 0; border-radius: var(--radius-pill); background: var(--accent); }
.fill.low { background: var(--danger); }
.tick  { position: absolute; top: -3px; width: 2px; height: 12px; border-radius: 1px; background: var(--border-strong); transform: translateX(-1px); }
.track-meta { display: flex; justify-content: space-between; margin-top: 4px; font-family: var(--font-mono); font-size: 10.5px; color: var(--text-tertiary); }

/* =================================================================
   手機庫存卡片　.icard (.r1 .nm .cat .csku .r2 .iqty)
   ================================================================= */
.icard-list { display: flex; flex-direction: column; gap: var(--sp-3); }
.icard {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: var(--sp-3) var(--sp-4);
  box-shadow: var(--shadow); position: relative;
}
.icard.low { border-color: transparent; box-shadow: inset 3px 0 0 var(--danger), var(--shadow); }
.icard .r1 { display: flex; align-items: center; gap: var(--sp-2); }
.icard .nm { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; font-size: var(--fs-h3); font-weight: 600; color: var(--text); }
.icard .nm .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); flex-shrink: 0; }
.icard.low .nm .dot { background: var(--danger); }
.icard .csku { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-tertiary); margin: 6px 0 10px; }
.icard .r2 { display: flex; align-items: flex-end; gap: var(--sp-3); }
.icard .r2 .track { flex: 1; max-width: none; }
.icard .iqty { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 18px; font-weight: 700; color: var(--text); white-space: nowrap; }
.icard.low .iqty { color: var(--danger); }
.icard .iqty .unit { font-family: var(--font-ui); font-size: var(--fs-xs); font-weight: 400; color: var(--text-tertiary); margin-left: 2px; }

/* =================================================================
   表單　.cinput / .cselect / .ctextarea（+ date）
   ================================================================= */
.cinput, .cselect, .ctextarea {
  width: 100%; font-family: var(--font-ui); font-size: var(--fs-input);  /* 16px */
  color: var(--text); background: var(--bg-input);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  outline: none; transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.cinput, .cselect { height: 44px; padding: 0 12px; }     /* ≥44 觸控 */
.ctextarea { padding: 10px 12px; min-height: 84px; resize: vertical; line-height: 1.5; }
.cinput::placeholder, .ctextarea::placeholder { color: var(--text-tertiary); }
.cinput:hover, .cselect:hover, .ctextarea:hover { border-color: var(--border-strong); }
.cinput:focus, .cselect:focus, .ctextarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.cinput:disabled, .cselect:disabled, .ctextarea:disabled { opacity: .55; cursor: not-allowed; background: var(--bg-hover); }
/* 下拉箭頭 */
.cselect {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23A4937F' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
/* 欄位標籤 */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-secondary); }

/* 進/出庫分段鈕　.seg-group / .seg（兩色）*/
.seg-group { display: inline-flex; padding: 3px; gap: 3px; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.seg {
  height: 38px; padding: 0 16px; min-width: 64px;
  border: none; background: transparent; cursor: pointer;
  border-radius: calc(var(--radius-sm) - 2px);
  font-family: var(--font-ui); font-size: var(--fs-body); font-weight: 600; color: var(--text-secondary);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.seg:hover { color: var(--text); }
.seg.in.on  { background: var(--success); color: #fff; font-weight: 700; }   /* 進庫 */
.seg.out.on { background: var(--accent);  color: #fff; font-weight: 700; }   /* 出庫 */

/* 盤點加減　.stepper */
.stepper { display: inline-flex; align-items: center; height: 44px; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.stepper .sbtn { width: 40px; height: 100%; border: none; background: transparent; cursor: pointer; font-size: 20px; line-height: 1; color: var(--text-secondary); transition: background var(--dur) var(--ease); }
.stepper .sbtn:last-child { color: var(--accent); }
.stepper .sbtn:hover { background: var(--bg-hover); }
.stepper .sval { min-width: 44px; text-align: center; font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: var(--fs-input); color: var(--text); }

/* =================================================================
   按鈕　.cbtn (.primary .secondary .ghost .danger)
   ================================================================= */
.cbtn {
  height: 44px; padding: 0 18px; min-height: 44px;       /* ≥44 觸控 */
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font-family: var(--font-ui); font-size: var(--fs-body); font-weight: 600; white-space: nowrap;
  cursor: pointer; transition: filter var(--dur) var(--ease), background var(--dur) var(--ease), transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.cbtn svg { width: 16px; height: 16px; }
.cbtn.sm { height: 34px; padding: 0 14px; font-size: var(--fs-sm); min-height: 0; }
.cbtn:active { transform: translateY(1px); }
.cbtn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.cbtn.primary { background: var(--accent-grad); color: #fff; box-shadow: var(--shadow); }
.cbtn.primary:hover { filter: brightness(1.05); box-shadow: 0 4px 14px var(--accent-glow); }

.cbtn.secondary { background: var(--accent-soft); color: var(--accent-deep); }
.cbtn.secondary:hover { background: #ECDCC2; }

.cbtn.ghost { background: transparent; color: var(--text-secondary); border-color: var(--border); }
.cbtn.ghost:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-strong); }

.cbtn.danger { background: var(--danger-soft); color: var(--danger); }
.cbtn.danger:hover { background: #F3D8D2; }

/* =================================================================
   彈窗　.modal / .modal-card（手機從底部滑出）
   ================================================================= */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-5);
  background: rgba(42, 32, 24, .42);          /* 無 blur，用半透明遮罩 */
}
.modal-card {
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: modal-in var(--dur-slow) var(--ease);
}
.modal-head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-5) var(--sp-5) var(--sp-3); }
.modal-head .zh { font-family: var(--font-serif); font-size: var(--fs-h2); font-weight: 600; color: var(--text); margin: 0; flex: 1; }
.modal-head .x { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border: none; background: var(--bg-hover); color: var(--text-secondary); border-radius: var(--radius-sm); cursor: pointer; }
.modal-head .x:hover { background: var(--border); color: var(--text); }
.modal-body { padding: var(--sp-2) var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-4); }
.modal-foot { padding: var(--sp-4) var(--sp-5) var(--sp-5); display: flex; gap: var(--sp-3); justify-content: flex-end; }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }

/* =================================================================
   Toast 提示　.global-toast (.success / .error)
   ================================================================= */
.global-toast {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 11px 15px; border-radius: var(--radius);
  background: var(--bg-elevated); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}
.global-toast .ico { width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; color: #fff; }
.global-toast .ico svg { width: 13px; height: 13px; }
.global-toast .t-title { font-size: var(--fs-sm); font-weight: 600; color: var(--text); }
.global-toast .t-sub { font-size: var(--fs-xs); color: var(--text-secondary); }
.global-toast.success .ico { background: var(--success); }
.global-toast.error   .ico { background: var(--danger); }
.global-toast.error .t-title { color: var(--danger); }

/* 缺貨警示列（清單列／橫幅）*/
.alert-strip {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 11px 14px; border-radius: var(--radius-sm);
  background: var(--danger-soft); color: var(--danger);
  font-size: var(--fs-sm); font-weight: 500;
}
.alert-strip svg { width: 17px; height: 17px; flex-shrink: 0; }
.alert-strip .count { margin-left: auto; font-family: var(--font-mono); font-weight: 700; }

/* =================================================================
   月度趨勢長條圖　.trend / .tbar（進貨 / 出庫 兩色）
   ================================================================= */
.trend { display: flex; align-items: flex-end; gap: var(--sp-3); height: 150px; padding: var(--sp-2) 0; }
.tcol { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 7px; height: 100%; }
.tcol .tbars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 4px; }
.tbar { width: 12px; border-radius: 4px 4px 0 0; transition: opacity var(--dur) var(--ease); }
.tbar.in  { background: var(--success); }       /* 進貨 */
.tbar.out { background: var(--accent); }         /* 出庫 */
.tcol:hover .tbar { opacity: .82; }
.tcol .tlabel { font-size: var(--fs-xs); color: var(--text-tertiary); }
.trend-legend { display: flex; gap: var(--sp-4); margin-top: var(--sp-2); font-size: var(--fs-xs); color: var(--text-secondary); }
.trend-legend span { display: inline-flex; align-items: center; gap: 6px; }
.trend-legend i { width: 10px; height: 10px; border-radius: 3px; }

/* =================================================================
   類別佔比 donut　.gauge-donut（+ legend）
   背景請以 inline style 給 conic-gradient，例：
   <div class="gauge-donut" style="background:conic-gradient(var(--tag-2-fg) 0 46%, var(--tag-4-fg) 46% 73%, var(--tag-3-fg) 73% 91%, var(--tag-1-fg) 91% 100%)">
   ================================================================= */
.gauge-donut { position: relative; width: 110px; height: 110px; border-radius: 50%; flex-shrink: 0; }
.gauge-donut::after {
  content: ""; position: absolute; inset: 24px; border-radius: 50%; background: var(--bg-card);
}
.gauge-donut .gc { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 1; }
.gauge-donut .gc .n { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 18px; font-weight: 700; color: var(--text); line-height: 1; }
.gauge-donut .gc .u { font-size: 9.5px; color: var(--text-tertiary); margin-top: 1px; }
.gauge-legend { display: flex; flex-direction: column; gap: 8px; }
.gl-row { display: flex; align-items: center; gap: 8px; }
.gl-dot { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.gl-row .gl-name { flex: 1; font-size: var(--fs-sm); color: var(--text-secondary); white-space: nowrap; }
.gl-row .gl-pct { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: var(--fs-sm); font-weight: 700; color: var(--text); }

/* =================================================================
   手機底部 tab bar　.mobile-tabbar / .mtab / .mtab.on
   桌面隱藏，<768 顯示（見最底 @media）
   ================================================================= */
.mobile-tabbar {
  display: none;             /* 桌面隱藏 */
  position: sticky; bottom: 0; z-index: 50;
  align-items: stretch;
  background: var(--bg-card); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.mtab {
  flex: 1; min-height: 56px;       /* ≥44 觸控 */
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: none; background: transparent; cursor: pointer;
  color: var(--text-tertiary); font-family: var(--font-ui);
  transition: color var(--dur) var(--ease);
}
.mtab svg { width: 21px; height: 21px; }
.mtab .lab { font-size: 10.5px; font-weight: 500; }
.mtab.on { color: var(--accent); }
.mtab.on .lab { font-weight: 700; }

/* 手機頂部列（精簡版）*/
.m-top {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  padding-top: max(var(--sp-3), env(safe-area-inset-top));
  background: var(--bg-card); border-bottom: 1px solid var(--border);
}
.m-top .ttl { font-family: var(--font-serif); font-size: var(--fs-h2); font-weight: 600; margin: 0; flex: 1; }

/* =================================================================
   響應式斷點
   ================================================================= */
@media (max-width: 767px) {
  .rail { display: none; }
  .mobile-tabbar { display: flex; }
  .strip { display: none; }                 /* 改用 .m-top */
  table.grid { display: none; }             /* 改用 .icard 卡片清單 */
  .layout { grid-template-columns: 1fr; }
  .content { padding: var(--sp-3) var(--sp-4); }
  /* 彈窗從底部滑出、近全寬 */
  .modal { align-items: flex-end; padding: 0; }
  .modal-card { max-width: none; border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 92vh; animation: sheet-in var(--dur-slow) var(--ease); }
}
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }

@media (max-width: 479px) {
  .kpis { grid-template-columns: 1fr 1fr; }   /* KPI 2×2 */
}

/* ═══════════════════════════════════════════════════════════
   補充元件（配件管家 — 對齊 app.js / index.html，全用上方 tokens）
   ═══════════════════════════════════════════════════════════ */

/* 螢幕 / tab 切換 */
.screen { min-height: 100vh; }
.screen.hidden, .hidden { display: none !important; }
.tab-panel { display: none; }
.tab-panel.active { display: flex; flex-direction: column; gap: var(--sp-4); }
.pad { padding: var(--sp-4); }
.scroll { overflow: auto; }

/* 兩欄表單列 */
.frow { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
@media (max-width: 479px) { .frow { grid-template-columns: 1fr; } }
.rq { color: var(--danger); }

/* 工具列（filters）*/
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); }
.search.sm { max-width: 240px; flex: 0 1 240px; }
.search.sm .cinput { height: 36px; }
.cselect.sm { height: 36px; max-width: 150px; font-size: var(--fs-sm); }
.count-tag { margin-left: auto; font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-tertiary); }

/* hint / micro / empty */
.hint { font-size: var(--fs-sm); margin-top: 8px; min-height: 1em; color: var(--text-secondary); }
.hint.success { color: var(--success); }
.hint.error { color: var(--danger); }
.micro { font-size: var(--fs-xs); color: var(--text-tertiary); display: block; margin-top: 4px; }
.empty { color: var(--text-tertiary); font-size: var(--fs-sm); text-align: center; padding: 24px; }

/* checkbox label */
.check-inline { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-secondary); cursor: pointer; white-space: nowrap; }
.check-inline input { width: 16px; height: 16px; accent-color: var(--accent); }

/* seg 用 label 包 radio（design .seg 原為 button）*/
.seg-group .seg { display: inline-flex; align-items: center; justify-content: center; position: relative; }
.seg-group .seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg-group .seg:has(input:checked).in  { background: var(--success); color: #fff; font-weight: 700; }
.seg-group .seg:has(input:checked).out { background: var(--accent);  color: #fff; font-weight: 700; }

/* 設定頁 */
.settings-wrap { max-width: 680px; display: flex; flex-direction: column; gap: var(--sp-4); }
.btn-row { display: flex; gap: var(--sp-3); flex-wrap: wrap; }
.setrow { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }
.setrow .d { font-size: var(--fs-sm); color: var(--text-secondary); }
.mono-pre { font-family: var(--font-mono); font-size: 12px; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; white-space: pre-wrap; word-break: break-all; color: var(--text-secondary); }

/* modal 副標 + 盤點 stepper input + 差異 */
.msub { font-size: var(--fs-sm); color: var(--text-secondary); margin-bottom: var(--sp-2); }
.stepper .sval-input { width: 86px; height: 100%; border: none; background: transparent; text-align: center; font-family: var(--font-mono); font-size: var(--fs-input); color: var(--text); outline: none; }
.diff { padding: 9px 12px; border-radius: var(--radius-sm); font-size: var(--fs-sm); font-weight: 600; text-align: center; margin: var(--sp-2) 0; }
.diff.zero { background: var(--bg-hover); color: var(--text-secondary); }
.diff.pos  { background: var(--success-soft); color: var(--success); }
.diff.neg  { background: var(--danger-soft); color: var(--danger); }

/* 首次設定精靈 */
.wizard { max-width: 720px; margin: 0 auto; padding: 48px 24px; }
.wizard header { text-align: center; margin-bottom: 28px; }
.wizard h1 { font-family: var(--font-serif); font-size: var(--fs-display); font-weight: 700; color: var(--text); margin: 0 0 8px; }
.wizard h1 .brand-text { color: var(--accent); }
.wizard .subtitle { color: var(--text-secondary); font-size: var(--fs-body); }
.steps { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--sp-3); }
.steps li { display: flex; gap: 14px; padding: var(--sp-4); background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.steps .badge { width: 30px; height: 30px; flex-shrink: 0; border-radius: 50%; background: var(--accent-grad); color: #fff; display: flex; align-items: center; justify-content: center; font-family: var(--font-mono); font-weight: 700; }
.steps .step-body { flex: 1; min-width: 0; }
.steps .step-body h3 { font-family: var(--font-serif); font-size: var(--fs-h3); margin: 0 0 4px; color: var(--text); }
.steps .step-body p { font-size: var(--fs-sm); color: var(--text-secondary); margin: 0; line-height: 1.7; }
.steps code { font-family: var(--font-mono); font-size: 12px; background: var(--accent-soft); color: var(--accent-deep); padding: 1px 6px; border-radius: 4px; }
.steps b { color: var(--text); }
.url-row { display: flex; gap: 10px; margin-top: var(--sp-3); }
.url-row .cinput { flex: 1; }
.steps .cbtn { margin-top: 10px; }

/* 缺貨警示清單（側欄）*/
.alerts { display: flex; flex-direction: column; gap: 8px; padding: var(--sp-3) var(--sp-4); max-height: 380px; overflow-y: auto; }

/* 類別佔比 bar（側欄）*/
.bars { display: flex; flex-direction: column; gap: 12px; padding: var(--sp-4); }
.cat-bar { display: flex; flex-direction: column; gap: 5px; }
.cat-bar-top { display: flex; justify-content: space-between; font-size: var(--fs-sm); color: var(--text-secondary); }
.cat-bar-top .v { font-family: var(--font-mono); }
.cat-bar-track { height: 6px; border-radius: var(--radius-pill); background: var(--bg-hover); overflow: hidden; }
.cat-bar-fill { height: 100%; border-radius: var(--radius-pill); }

/* feed（最近紀錄）*/
.feed { display: flex; flex-direction: column; gap: 6px; padding: var(--sp-3); overflow-y: auto; }
.feed-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--bg-input); cursor: pointer; transition: background var(--dur) var(--ease); }
.feed-item:hover { background: var(--bg-hover); }
.feed-item .fdir { font-size: var(--fs-xs); font-weight: 700; padding: 2px 7px; border-radius: 4px; white-space: nowrap; }
.feed-item .fdir.in  { background: var(--success-soft); color: var(--success); }
.feed-item .fdir.out { background: var(--accent-soft); color: var(--accent-deep); }
.feed-item .fnm { flex: 1; min-width: 0; font-size: var(--fs-sm); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed-item .fqty { font-family: var(--font-mono); font-weight: 700; font-size: var(--fs-sm); white-space: nowrap; }

/* 盤點清單 */
.stwrap { display: flex; flex-direction: column; gap: 8px; }
.st-row { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); flex-wrap: wrap; }
.st-row .st-info { flex: 1; min-width: 140px; }
.st-row .st-nm { font-size: var(--fs-h3); font-weight: 600; color: var(--text); }
.st-row .st-sku { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-tertiary); }
.st-row .st-cur { font-family: var(--font-mono); font-size: var(--fs-sm); color: var(--text-secondary); white-space: nowrap; }

/* 報表 donut 容器 */
.donut-wrap { display: flex; align-items: center; gap: var(--sp-5); flex-wrap: wrap; }

/* global toast / loader */
.global-toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 300; }
.global-toast.hidden { display: none; }
.global-loader { position: fixed; inset: 0; z-index: 400; display: flex; align-items: center; justify-content: center; background: rgba(42,32,24,.3); }
.global-loader.hidden { display: none; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 手機頂部列（桌面隱藏）*/
.m-top { display: none; }
@media (max-width: 767px) {
  .m-top { display: flex; align-items: center; gap: var(--sp-3); }
  .m-top .ttl { flex: 1; }
  .m-top .sync { font-size: var(--fs-xs); padding: 4px 9px; }
  .layout { grid-template-columns: 1fr; }
  .settings-wrap { max-width: none; }
}

/* ═══════════ 品項照片 ═══════════ */
.photo-field { display: flex; gap: var(--sp-3); align-items: center; padding-bottom: var(--sp-3); border-bottom: 1px solid var(--border); }
.photo-preview { width: 76px; height: 76px; flex-shrink: 0; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg-input); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-preview svg { width: 26px; height: 26px; color: var(--text-tertiary); }
.photo-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; min-width: 0; }
.photo-actions .micro { margin: 0; }
/* 清單縮圖 */
.cell-name .thumb { width: 38px; height: 38px; border-radius: var(--radius-sm); object-fit: cover; flex-shrink: 0; background: var(--bg-hover); border: 1px solid var(--border); }
.icard .thumb { width: 46px; height: 46px; border-radius: var(--radius-sm); object-fit: cover; flex-shrink: 0; background: var(--bg-hover); border: 1px solid var(--border); }
.icard .r1 { gap: var(--sp-3); }
