/* 代琳整合系統 — 介面樣式（手機優先） */

:root {
  --bg:        #f5f6f8;
  --surface:   #ffffff;
  --surface-2: #f0f2f5;
  --line:      #e2e5ea;
  --text:      #16181d;
  --muted:     #6b7280;
  --brand:     #0f172a;
  --accent:    #2563eb;
  --accent-sf: #e8efff;
  --good:      #0e8a5f;
  --warn:      #b45309;
  --bad:       #c0392b;
  --radius:    14px;
  --shadow:    0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
  --safe-b:    env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:#0d1117; --surface:#161b22; --surface-2:#1f2630; --line:#2b323c;
    --text:#e6e9ef; --muted:#9aa4b2; --brand:#e6e9ef; --accent:#5b9bff;
    --accent-sf:#16233b; --good:#3fc78e; --warn:#e0a94a; --bad:#ff7a6b;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC",
               "Microsoft JhengHei", "Segoe UI", sans-serif;
  font-size: 15px; line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------------------------------------------------------- 鎖定畫面 */
.lock { position: fixed; inset: 0; display: grid; place-items: center;
        background: var(--bg); z-index: 100; padding: 24px; }
.lock-box { width: 100%; max-width: 320px; text-align: center; }
.lock-logo { font-size: 44px; }
.lock-logo-img { width: 84px; height: 84px; border-radius: 18px; }
.lock-box h1 { font-size: 20px; margin: 8px 0 24px; }
.lock-box input { width: 100%; padding: 14px; border: 1px solid var(--line);
                  border-radius: 12px; background: var(--surface); text-align: center;
                  letter-spacing: 4px; margin-bottom: 12px; }
.err { color: var(--bad); font-size: 13px; min-height: 20px; }

/* ---------------------------------------------------------- 版面 */
.shell { display: flex; min-height: 100%; }

/* 左側目錄：窄螢幕是圖示欄，寬螢幕展開成完整選單 */
.side {
  display: flex; flex-direction: column; flex-shrink: 0;
  width: 66px; height: 100vh; height: 100dvh; position: sticky; top: 0;
  background: var(--surface); border-right: 1px solid var(--line);
  padding-left: env(safe-area-inset-left, 0px);
  z-index: 40;
}
.brand { display: flex; align-items: center; justify-content: center; gap: 9px;
         padding: 14px 6px 10px; font-weight: 700; font-size: 15px; }
.brand-mark { font-size: 21px; }
.brand-mark img { width: 26px; height: 26px; border-radius: 7px; vertical-align: middle; }
.brand-text { display: none; }
.side-nav { flex: 1; padding: 4px 6px; display: flex; flex-direction: column; gap: 2px;
            overflow-y: auto; scrollbar-width: none; }
.side-nav::-webkit-scrollbar { display: none; }
.side-nav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px; border-radius: 10px; text-decoration: none;
  color: var(--muted); font-size: 10.5px; line-height: 1.25;
  -webkit-tap-highlight-color: transparent;
}
.side-nav a span { font-size: 19px; }
.side-nav a:active { background: var(--surface-2); }
.side-nav a.on { background: var(--accent-sf); color: var(--accent); font-weight: 600; }
.side-foot { padding: 10px 6px calc(10px + var(--safe-b)); border-top: 1px solid var(--line);
             text-align: center; }
.side-link { font-size: 16px; color: var(--muted); text-decoration: none; line-height: 1.3;
             display: block; }
.side-link:hover { color: var(--accent); }
.side-link-full { display: none; }
.side-user { font-size: 18px; line-height: 1.3; color: var(--muted); }
.side-user strong { color: var(--text); font-size: 13px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.tabbar { display: none; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 14px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 {
  font-size: 18px; margin: 0; letter-spacing: .5px;
  white-space: nowrap;            /* 手機上標題不要被擠成直排 */
  overflow: hidden; text-overflow: ellipsis;
  flex: 1 1 auto; min-width: 0;
}
/* 按鈕放不下時整排移到下一行，不要溢出畫面 */
.page-actions {
  display: flex; gap: 8px; flex-wrap: wrap;
  justify-content: flex-end; min-width: 0;
}
@media (max-width: 560px) {
  .topbar h1 { flex: 1 0 100%; }
  .page-actions { flex: 1 0 100%; justify-content: stretch; }
  .page-actions > * { flex: 1 1 auto; text-align: center; }
}

.view { padding: 16px; display: flex; flex-direction: column; gap: 16px; }

/* ---------------------------------------------------------- 元件 */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.card-head h2 { font-size: 15px; margin: 0; flex: 1; }
.card-body { padding: 14px; }
.card-body.tight { padding: 0; }

.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 10px; cursor: pointer; font-size: 14px;
  white-space: nowrap; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { display: block; width: 100%; }
.icon-btn { border: 0; background: transparent; font-size: 18px; cursor: pointer;
            padding: 6px 8px; border-radius: 8px; color: var(--muted); }

.search { display: flex; gap: 8px; }
.search input {
  flex: 1; padding: 11px 14px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--surface);
}

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
       padding: 14px; box-shadow: var(--shadow); }
.kpi .k-label { font-size: 12px; color: var(--muted); }
.kpi .k-value { font-size: 22px; font-weight: 650; margin-top: 4px;
                font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.kpi .k-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* 清單 */
.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-bottom: 1px solid var(--line); cursor: pointer; background: none;
  border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left;
  color: inherit; text-decoration: none;   /* 清單列有些是 <a>，不要藍色底線 */
}
.row:last-child { border-bottom: 0; }
.row:active { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; font-size: 15px;
             white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px;
           overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical;
           -webkit-line-clamp: 2; }
.row-end { text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.row-end .big { font-weight: 650; font-size: 16px; }
.row-end .small { font-size: 12px; color: var(--muted); }

.tag { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 99px;
       background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.tag.good { color: var(--good); border-color: color-mix(in srgb, var(--good) 35%, transparent);
            background: color-mix(in srgb, var(--good) 12%, transparent); }
.tag.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent);
            background: color-mix(in srgb, var(--warn) 12%, transparent); }
.tag.bad  { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent);
            background: color-mix(in srgb, var(--bad) 12%, transparent); }
.tag.accent { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent);
              background: var(--accent-sf); }

/* 三個倉位的小標 */
.buckets { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 5px; }
.bucket { font-size: 11px; padding: 2px 7px; border-radius: 6px;
          background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.bucket b { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 650; }
.bucket.zero { opacity: .5; }
.bucket.neg b { color: var(--bad); }

.pos { color: var(--good); }
.neg { color: var(--bad); }
.mut { color: var(--muted); }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); font-size: 14px; }
.num { font-variant-numeric: tabular-nums; }

/* 表格（寬螢幕） */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th, table.t td { padding: 10px 12px; border-bottom: 1px solid var(--line);
                         text-align: left; white-space: nowrap; }
table.t th { font-size: 12px; color: var(--muted); font-weight: 600;
             background: var(--surface-2); position: sticky; top: 0; }
table.t td.r, table.t th.r { text-align: right; font-variant-numeric: tabular-nums; }
table.t tbody tr:hover { background: var(--surface-2); }

/* 表單 */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface);
}
.field textarea { min-height: 68px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

/* 設定頁：每一間公司的抬頭各自一塊，才不會兩組欄位混在一起看不出誰是誰 */
.co-block {
  border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 14px 4px; margin-bottom: 14px; background: var(--bg);
}
.co-head {
  font-size: 11px; font-weight: 600; letter-spacing: 2px;
  color: var(--muted); margin-bottom: 12px;
}
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* 叫貨單拖放區。原生的檔案按鈕在獨立視窗模式下叫不出系統視窗，
   拖放才是穩的那條路，所以做得明顯一點。 */
.dropzone {
  position: relative;                /* 讓透明的檔案欄位鋪在上面 */
  border: 2px dashed var(--line); border-radius: 12px;
  background: var(--surface); padding: 26px 16px; text-align: center;
  cursor: pointer; transition: border-color .15s, background .15s;
}
/* 原生檔案欄位鋪滿整塊、透明。點擊由它自己接，
   不經過程式 —— WebKit 不讓程式叫開隱藏的檔案欄位。 */
.dz-input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.over { border-color: var(--accent); background: var(--accent-sf); }
.dz-ico { font-size: 30px; line-height: 1; margin-bottom: 8px; }
.dz-main { font-size: 15px; font-weight: 600; }
.dz-sub { font-size: 13px; color: var(--muted); margin-top: 10px; }
.dz-sub .btn { margin-left: 2px; }

/* 匯入讀檔失敗時的說明。錯誤訊息裡有換行與對齊過的表格內容，要照原樣顯示 */
.err-card { margin: 12px 0 0; border-color: var(--bad); }
.err-detail {
  margin: 6px 0 0; padding: 10px 12px;
  background: var(--bg); border-radius: 8px;
  font: 12px/1.6 ui-monospace, "SF Mono", Menlo, monospace;
  white-space: pre-wrap; word-break: break-word;
  max-height: 260px; overflow: auto;
}
/* 產品介紹：保留換行、可捲動 */
.intro-box { white-space: pre-wrap; font-size: 13.5px; line-height: 1.7;
             background: var(--surface-2); border: 1px solid var(--line);
             border-radius: 12px; padding: 12px 14px; max-height: 46vh;
             overflow-y: auto; -webkit-overflow-scrolling: touch; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.check input { width: 18px; height: 18px; }
.check label { font-size: 14px; }

/* 明細列編輯 */
.lines { display: flex; flex-direction: column; gap: 10px; }
.line { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
        background: var(--surface-2); }
.line-top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.line-top strong { flex: 1; font-size: 14px; }
.line-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.line-grid label { font-size: 11px; color: var(--muted); display: block; margin-bottom: 3px; }
.line-grid input { width: 100%; padding: 8px; border: 1px solid var(--line);
                   border-radius: 8px; background: var(--surface); text-align: right; }
.line-foot { margin-top: 8px; font-size: 12px; color: var(--muted); text-align: right; }

.totals { display: flex; justify-content: space-between; padding: 12px 14px;
          border-top: 1px solid var(--line); font-size: 14px; }
.totals strong { font-size: 17px; font-variant-numeric: tabular-nums; }

/* Sheet（彈出表單） */
.sheet-wrap { position: fixed; inset: 0; z-index: 60; display: flex;
              align-items: flex-end; justify-content: center; }
.sheet-bg { position: absolute; inset: 0; background: rgba(8,12,20,.5); }
.sheet {
  position: relative; width: 100%; max-width: 560px;
  /* dvh 會跟著 iOS 的網址列縮放，vh 不會 —— 用 vh 的話表單底部的
     「儲存」會被推到看不到的地方，看起來就像按鈕壞掉。舊瀏覽器吃前面那行。 */
  max-height: 92vh; max-height: 92dvh;
  background: var(--bg); border-radius: 18px 18px 0 0;
  display: flex; flex-direction: column; box-shadow: 0 -8px 40px rgba(0,0,0,.28);
  animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: .6; } }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px;
              border-bottom: 1px solid var(--line); }
.sheet-head h2 { flex: 1; font-size: 16px; margin: 0; }
.sheet-body { padding: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-foot { display: flex; gap: 10px; padding: 12px 16px calc(12px + var(--safe-b));
              border-top: 1px solid var(--line); background: var(--surface); }
.sheet-foot .btn { flex: 1; padding: 12px; }

/* 選取清單（產品/客戶挑選） */
.picker-list { max-height: 46vh; overflow-y: auto; border: 1px solid var(--line);
               border-radius: 12px; background: var(--surface); }
.picker-item { display: flex; gap: 10px; align-items: center; padding: 11px 12px;
               border-bottom: 1px solid var(--line); cursor: pointer; }
.picker-item:last-child { border-bottom: 0; }
.picker-item:active { background: var(--surface-2); }
.picker-item .pi-main { flex: 1; min-width: 0; }
.picker-item .pi-sub { font-size: 12px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b));
  transform: translateX(-50%) translateY(20px);
  background: var(--brand); color: var(--bg);
  padding: 11px 18px; border-radius: 99px; font-size: 14px; z-index: 90;
  opacity: 0; pointer-events: none; transition: all .2s; max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px;
       border: 1px solid var(--line); }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px;
              cursor: pointer; font-size: 13.5px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600;
                 box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------------------------------------------------------- 寬螢幕 */
@media (min-width: 860px) {
  body { font-size: 14.5px; }
  .side { width: 224px; }
  .brand { justify-content: flex-start; padding: 20px 18px 14px; font-size: 16px; }
  .brand-text { display: inline; }
  .side-nav { padding: 6px 10px; }
  .side-nav a { flex-direction: row; align-items: center; gap: 10px;
                padding: 10px 12px; font-size: 14.5px; }
  .side-nav a span { font-size: 17px; width: 22px; text-align: center; }
  .side-nav a:hover { background: var(--surface-2); color: var(--text); }
  .side-foot { padding: 12px 18px 18px; text-align: left; }
  .side-link { font-size: 12.5px; }
  .side-link-short { display: none; }
  .side-link-full { display: inline; }
  .view { padding: 20px 24px; max-width: 1180px; }
  .topbar { padding: 18px 24px; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 18px; max-height: 86vh; max-height: 86dvh; }
  .line-grid { grid-template-columns: repeat(4, 1fr); }
}

@media print {
  .side, .topbar, .page-actions, .sheet-foot { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; }
}

/* ---------------------------------------------------------- 視覺強化 */

/* 庫存量長條，一眼看出多寡 */
.bar { height: 5px; border-radius: 99px; background: var(--surface-2);
       margin: 7px 0 5px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px;
            background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #fff));
            transition: width .3s ease; }
.bar-fill.neg { background: var(--bad); }

/* 提醒橫幅 */
.alert {
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 13px; line-height: 1.6;
}
.alert strong { display: block; font-size: 14px; margin-bottom: 3px; }
.alert div { color: var(--muted); }
.alert.bad {
  background: color-mix(in srgb, var(--bad) 8%, var(--surface));
  border-color: color-mix(in srgb, var(--bad) 32%, var(--line));
}
.alert.bad strong { color: var(--bad); }
.alert.warn {
  background: color-mix(in srgb, var(--warn) 10%, var(--surface));
  border-color: color-mix(in srgb, var(--warn) 32%, var(--line));
}
.alert.warn strong { color: var(--warn); }

/* 標題列的徽章間距 */
.row-title .tag { margin-left: 4px; vertical-align: 1px; }


/* ═══════════════════════════════════════════════════════════
   介面精簡：把裝飾拿掉，留下資訊本身
   ═══════════════════════════════════════════════════════════ */

:root {
  --shadow: none;                    /* 卡片不再堆陰影，改用一條細線 */
  --radius: 12px;
}

/* ---------- 側邊選單：線條圖示、分組、低對比 ---------- */
.side { width: 74px; background: var(--bg); border-right: 1px solid var(--line); }
.brand { padding: 18px 6px 14px; }
.brand-mark img { width: 30px; height: 30px; border-radius: 8px; }

.side-nav { gap: 1px; padding: 4px 8px; }
.side-nav a {
  gap: 5px; padding: 10px 2px; font-size: 11px; font-weight: 500;
  color: var(--muted); border-radius: 10px;
}
.side-nav a.on { background: transparent; color: var(--text); font-weight: 700; }
.side-nav a.on .nav-ico { color: var(--accent); }

.nav-ico { display: block; width: 22px; height: 22px; color: var(--muted); }
.nav-ico svg {
  width: 100%; height: 100%; display: block;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.nav-sep { height: 1px; background: var(--line); margin: 10px 8px; }

/* ---------- 頁面：更多留白，更少框線 ---------- */
.topbar { border-bottom: 0; padding: 18px 16px 6px; }
.topbar h1 { font-size: 22px; font-weight: 700; letter-spacing: -.3px; }
.view { padding: 12px 16px 40px; gap: 14px; }

.card { border-radius: var(--radius); }
.card-head { padding: 14px 16px 10px; border-bottom: 0; }
.card-head h2 { font-size: 13px; color: var(--muted); font-weight: 600;
                letter-spacing: .3px; }

/* ---------- 數字卡片：拿掉外框，靠留白分隔 ---------- */
.kpis { gap: 1px; background: var(--line); border: 1px solid var(--line);
        border-radius: var(--radius); overflow: hidden; }
.kpi { border: 0; border-radius: 0; padding: 16px 14px; }
.kpi .k-label { font-size: 11.5px; letter-spacing: .2px; }
.kpi .k-value { font-size: 25px; letter-spacing: -1px; margin-top: 2px; }
.kpi .k-sub { font-size: 11.5px; }

/* ---------- 清單：加大行距，弱化次要文字 ---------- */
.row { padding: 14px 16px; gap: 14px; }
.row-title { font-size: 15px; font-weight: 600; letter-spacing: -.1px; }
.row-sub { font-size: 12px; margin-top: 3px; opacity: .78; }
.row-end .big { font-size: 17px; letter-spacing: -.4px; }
.row-end .small { font-size: 11.5px; }

/* ---------- 標籤：低調一點 ---------- */
.tag { font-size: 10.5px; padding: 1px 6px; font-weight: 600;
       background: transparent; }
.bucket { font-size: 10.5px; padding: 1px 6px; background: transparent; }

/* ---------- 搜尋與按鈕 ---------- */
.search input { padding: 12px 14px; border-radius: 10px; }
.btn { border-radius: 9px; font-weight: 500; }
.btn.sm { font-size: 12.5px; }
.seg { padding: 2px; border-radius: 9px; }
.seg button { font-size: 13px; padding: 7px; }

/* ---------- 說明文字：需要時才看，平常淡化 ---------- */
.hint { font-size: 11.5px; opacity: .72; }
.view > .hint { text-align: center; padding: 0 12px; }

/* ---------- 長條與提醒 ---------- */
.bar { height: 3px; margin: 8px 0 4px; }
.alert { border-radius: var(--radius); padding: 13px 15px; }

/* ---------- 寬螢幕 ---------- */
@media (min-width: 860px) {
  .side { width: 210px; }
  .side-nav a { flex-direction: row; gap: 12px; padding: 9px 12px; font-size: 14px; }
  .nav-ico { width: 19px; height: 19px; }
  .topbar { padding: 24px 28px 8px; }
  .topbar h1 { font-size: 26px; }
  .view { padding: 12px 28px 48px; }
}

/* ═══════════════════════════════════════════════════════════
   出貨單（畫面版 / 列印版）
   ═══════════════════════════════════════════════════════════ */

/* 紙本：單色。整份文件只有 LOGO 帶顏色，字一律回到近黑，
   小標用很小的級數配大字距、資料放大 —— 靠級數對比而不是靠粗體。 */
:root {
  --doc-ink:  #14161a;   /* 資料 */
  --doc-mut:  #8b9099;   /* 小標與次要資訊 */
  --doc-hair: #dcdee2;   /* 髮線 */
  --doc-rule: #14161a;   /* 主分隔線 */
}

.doc {
  background: #fff; color: var(--doc-ink);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 40px 34px 34px;
  font-size: 14px; line-height: 1.7;
  font-variant-numeric: tabular-nums;
}

/* 小標：中文＋拉丁，字距拉開。整份文件的標籤都用這一個。 */
.doc-k {
  display: block; font-size: 9.5px; font-weight: 500;
  letter-spacing: 2.4px; color: var(--doc-mut); margin-bottom: 5px;
}
.doc-k i,
.doc-table th i,
.doc-sec i { font-style: normal; opacity: .72; margin-left: 5px; }

/* ---------- 抬頭 ---------- */
/* LOGO 單獨一行、公司名在它下面。並排會讓細金線的圖跟中文字打架，
   那正是「沒統一起來」的來源。 */
.doc-logo { display: block; width: 44px; height: 44px; object-fit: contain; margin-bottom: 18px; }

.doc-top-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 32px; }
.doc-issuer { flex: 1 1 auto; min-width: 0; }
.doc-stamp  { flex: 0 0 auto; }
.doc-co { font-size: 21px; font-weight: 400; letter-spacing: 4px; line-height: 1.35; }
.doc-co-en {
  font-size: 9.5px; font-weight: 500; letter-spacing: 3.4px;
  color: var(--doc-mut); margin-top: 5px;
}
.doc-issuer-meta {
  font-size: 11px; line-height: 1.65; color: var(--doc-mut);
  letter-spacing: .3px; margin-top: 9px;
}
.doc-stamp { text-align: right; }
/* 單號與日期跟著標題走，像文件的印記；放進下面的欄位會多佔一整列 */
.doc-stamp-meta {
  font-size: 12px; line-height: 1.7; color: var(--doc-mut);
  letter-spacing: .4px; margin-top: 12px;
}
.doc-stamp-meta b { font-weight: 500; color: var(--doc-ink); }
.doc-title {
  font-size: 30px; font-weight: 300; letter-spacing: 10px; line-height: 1.1;
  margin-right: -10px;                   /* 字距在尾端會多出一格，補回來才切齊右邊 */
}
.doc-title-en {
  font-size: 9.5px; font-weight: 500; letter-spacing: 3.4px;
  color: var(--doc-mut); margin-top: 8px;
}

.doc-rule { height: 1px; background: var(--doc-rule); margin-top: 26px; }

/* ---------- 客戶／單號／收件 ---------- */
.doc-parties {
  display: grid; grid-template-columns: 1fr 1fr; gap: 20px 32px;
  padding: 24px 0 28px;
}
.doc-parties > div { min-width: 0; }
.doc-v { font-size: 15px; line-height: 1.45; word-break: break-word; }
.doc-v .mut { color: var(--doc-mut); }
.doc-span2 { grid-column: 1 / -1; }

/* ---------- 品項 ---------- */
.doc-table { width: 100%; border-collapse: collapse; }
.doc-table th {
  font-size: 9.5px; font-weight: 500; letter-spacing: 2.4px;
  color: var(--doc-mut); text-align: left;
  padding: 0 10px 9px; border-bottom: 1px solid var(--doc-rule);
}
.doc-table td {
  padding: 12px 10px; border-bottom: 1px solid var(--doc-hair); vertical-align: top;
}
.doc-table th:first-child, .doc-table td:first-child { padding-left: 0; }
.doc-table th:last-child,  .doc-table td:last-child  { padding-right: 0; }
.doc-table .r { text-align: right; }
.doc-idx { width: 34px; color: var(--doc-mut); font-size: 12px; }
.doc-name { font-size: 14.5px; }
.doc-note { display: block; color: var(--doc-mut); font-size: 11.5px; margin-top: 3px; }

/* 贈品：一行小標分段，不用底色壓在單子中間 */
.doc-sec td {
  padding: 24px 0 9px; border-bottom: 1px solid var(--doc-hair);
  font-size: 9.5px; font-weight: 500; letter-spacing: 2.4px; color: var(--doc-mut);
}
.doc-free { color: var(--doc-mut); }

/* ---------- 合計 ---------- */
.doc-sum {
  display: flex; align-items: flex-end; justify-content: space-between;
  padding-top: 22px;
}
.doc-sum strong { font-size: 32px; font-weight: 300; letter-spacing: 1px; line-height: 1; }

.doc-remark { font-size: 11.5px; line-height: 1.7; color: var(--doc-mut); max-width: 46%; text-align: right; }

/* ---------- 頁尾 ---------- */
.doc-foot {
  margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--doc-hair);
  display: flex; justify-content: space-between; align-items: flex-start; gap: 24px;
}
.doc-bank { font-size: 12px; line-height: 1.85; }
.doc-bank div { color: var(--doc-mut); }
.doc-bank b { font-weight: 500; color: var(--doc-ink); letter-spacing: .6px; }

.doc-ship .doc-v { font-size: 13.5px; line-height: 1.7; }

/* 深色模式下這張單一律維持白底，印出來才對 */
@media (prefers-color-scheme: dark) {
  .doc { background: #fff; color: var(--doc-ink); border-color: #2b323c; }
}

/* 窄螢幕：兩欄會擠成一團，改單欄 */
@media (max-width: 520px) {
  .doc { padding: 26px 20px; }
  .doc-top-row { flex-direction: column; align-items: flex-start; gap: 20px; }
  .doc-stamp { text-align: left; }
  .doc-title { font-size: 25px; letter-spacing: 8px; margin-right: -8px; }
  .doc-parties { grid-template-columns: 1fr; gap: 18px; }
  .doc-sum strong { font-size: 27px; }
  /* 欄位窄，表頭的拉丁字會折成兩行，手機上只留中文 */
  .doc-table th i, .doc-sec i { display: none; }
  .doc-foot { flex-direction: column; gap: 14px; }
  .doc-remark { max-width: none; text-align: left; }
}

/* ═══════════════════════════════════════════════════════════
   列印
   ═══════════════════════════════════════════════════════════ */
@media print {
  /* 這兩行是「空白第一頁」與「底部灰塊」的根源：
     畫面版靠 height:100% 撐滿視窗，但列印時 100% 等於一整頁，
     收起來的 shell 還是會佔掉一頁；而灰底掛在 html 上，
     只把 body 改白不夠，內容以外的地方仍然露出灰色。 */
  html, body { height: auto !important; background: #fff !important; }
  body.printing #shell,
  body.printing .sheet-bg,
  body.printing .sheet-head,
  body.printing .sheet-foot,
  body.printing .hint,
  body.printing #toast { display: none !important; }

  body.printing .sheet-wrap { position: static; display: block; }
  body.printing .sheet {
    position: static; max-height: none; box-shadow: none;
    border-radius: 0; background: #fff; max-width: none; animation: none;
  }
  body.printing .sheet-body { overflow: visible; padding: 0; }
  body.printing .doc { border: 0; border-radius: 0; padding: 0; }

  /* 一列品項不要被切成兩頁，表頭在續頁重複 */
  .doc-table { page-break-inside: auto; }
  .doc-table tr { page-break-inside: avoid; }
  .doc-table thead { display: table-header-group; }
  .doc-sum, .doc-foot { page-break-inside: avoid; }

  @page { margin: 15mm; }
}

/* ---------- 直播：一列裡把開價／組合／成本／數量攤開 ---------- */
.figs { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; }
.fig { display: inline-flex; align-items: baseline; gap: 5px; font-size: 12.5px; }
.fig i { font-style: normal; font-size: 10.5px; color: var(--muted); letter-spacing: .5px; }
.fig b { font-weight: 600; font-variant-numeric: tabular-nums; }
.fig.hi b { color: var(--accent); font-size: 14px; }     /* 開價是主角 */
.fig.dim b { font-weight: 400; color: var(--muted); }
.fig.pos b { color: var(--good); }
.fig.neg b { color: var(--bad); }

/* 直播主那一列可以點來篩選 */
.host-row { cursor: pointer; }
.host-row.on { background: var(--accent-sf); }
.host-row.on .row-title { color: var(--accent); }

/* 同一支的多個價位並排：一包 199 ／ 3包 555 */
.tiers { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.tier {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 6px 11px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); cursor: pointer; font: inherit; color: inherit;
}
.tier:hover { border-color: var(--accent); }
.tier b { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); }
.tier i { font-style: normal; font-size: 11.5px; color: var(--muted); }

/* 「或者」分隔線：兩條並存的路要看得出來是並存，不是先後 */
.or-sep {
  display: flex; align-items: center; gap: 12px;
  margin: 18px 0 14px; color: var(--muted); font-size: 12px;
}
.or-sep::before, .or-sep::after {
  content: ''; flex: 1; height: 1px; background: var(--line);
}

/* 匯入叫貨單的品項列 */
.imp-nums {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 13px; margin: 6px 0; font-variant-numeric: tabular-nums;
}
.imp-nums b { font-size: 15px; font-weight: 650; }
.imp-amt { margin-left: auto; font-weight: 650; }
.imp-map { font-size: 13px; margin: 8px 0 8px; }
.line.is-skipped { opacity: .42; }
.line.need-map { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
