/* ════════════════════════════════════════
   Design Tokens (v2)
════════════════════════════════════════ */
:root {
  --sky:    #0EA5E9;
  --sky-d:  #0369A1;
  --sky-l:  #E0F2FE;
  --sky-ll: #F0F9FF;
  --amber:  #F59E0B;
  --amber-l:#FEF3C7;
  --ink:    #1E293B;
  --sub:    #475569;
  --muted:  #94A3B8;
  --border: #E2E8F0;
  --white:  #FFFFFF;
  --bg:     #F8FAFC;
  --sw:     220px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Microsoft JhengHei', 'PingFang TC', 'Noto Sans TC', sans-serif;
  font-size: 15px; line-height: 1.6;
  color: var(--ink); background: var(--bg);
}
a { color: inherit; text-decoration: none; }

/* ── Breadcrumb ── */
.bc { background: var(--white); border-bottom: none; margin-top: 80px; }
.bc-inner {
  max-width: 1280px; margin: 0 auto; padding: 10px 24px;
  display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted);
}
.bc a { color: var(--sky-d); }
.bc a:hover { color: var(--sky); }

/* ── Layout ── */
.layout {
  max-width: 1280px; margin: 0 auto;
  display: flex; padding: 24px; align-items: flex-start;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sw); flex-shrink: 0;
  background: var(--white); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; position: sticky; top: 96px;
  max-height: calc(100vh - 100px); overflow-y: auto;
}
.sb-title {
  background: var(--sky-d); color: var(--white);
  font-weight: 700; font-size: 14px; padding: 12px 14px; letter-spacing: .06em;
}
.sb-sec { border-bottom: none; }
.sb-sec-title {
  background: var(--sky-ll); color: var(--sky-d);
  font-size: 13px; font-weight: 700; padding: 8px 14px; letter-spacing: .04em;
}
.sb-links { list-style: none; }
.sb-links a {
  display: block; padding: 7px 14px 7px 20px;
  color: var(--sub); font-size: 14px;
  border-left: 3px solid transparent; transition: all .15s;
}
.sb-links a:hover, .sb-links a.active {
  color: var(--sky-d); background: var(--sky-ll); border-left-color: var(--sky);
}
.sb-links a.active { font-weight: 600; }
.sb-links a.pending { color: var(--muted); cursor: default; pointer-events: none; }
.sb-ext { list-style: none; }
.sb-ext a {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px; color: var(--sub); font-size: 14px; transition: color .15s;
}
.sb-ext a:hover { color: var(--sky-d); }
.sb-ext a::before { content: '→'; color: var(--sky); font-size: 13px; }

/* ── Main ── */
.main { flex: 1; min-width: 0; margin-left: 20px; }

/* ── Contract Header ── */
.ch {
  background: var(--white); border: 1px solid var(--border);
  border-radius: 12px; padding: 24px 28px; margin-bottom: 20px;
}
.badge {
  display: inline-block; background: var(--sky-d); color: var(--white);
  font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 4px;
  letter-spacing: .06em; margin-bottom: 10px;
}
.ch h1 { font-size: 22px; font-weight: 700; color: var(--ink); margin-bottom: 12px; }
.meta { display: flex; flex-wrap: wrap; gap: 16px; font-size: 15px; color: var(--sub); }
.meta strong { color: var(--ink); }

/* ── Spec Box ── */
.spec-box {
  background: var(--sky-ll); border: 1px solid var(--sky-l);
  border-left: 4px solid var(--sky); border-radius: 8px;
  padding: 16px 20px; margin-bottom: 20px;
}
.spec-box h3 { font-size: 15px; font-weight: 700; color: var(--sky-d); margin-bottom: 10px; }
.spec-box p { font-size: 14px; color: var(--sub); line-height: 1.7; margin-bottom: 6px; }

/* ── Group Index ── */
.gidx {
  display: flex; flex-wrap: wrap;
  padding: 12px 16px; gap: 8px;
  background: var(--bg); border-bottom: 2px solid var(--sky-l);
}
.gidx a {
  display: inline-block; padding: 6px 14px;
  font-size: 14px; font-weight: 500; color: var(--sky-d);
  border: 1px solid var(--sky); border-radius: 20px;
  text-decoration: none; background: var(--white);
  transition: background .15s, color .15s;
}
.gidx a:hover { background: var(--sky-d); color: #fff; }

/* ── Group Section ── */
.gs {
  background: var(--white); border: 1px solid var(--border);
  border-radius: 12px; margin-bottom: 24px; overflow: hidden;
}
.gh {
  background: var(--sky-d); color: var(--white);
  padding: 14px 20px; display: flex; align-items: center; gap: 10px;
}
.gno {
  background: rgba(255,255,255,.2); color: var(--white);
  font-weight: 700; font-size: 14px;
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.gh h2 { font-size: 17px; font-weight: 700; }
.sgh {
  background: var(--sky-ll); border-bottom: none;
  padding: 11px 20px; margin-top: 32px; font-size: 17px; font-weight: 600; color: var(--sky-d);
  display: flex; align-items: center; gap: 8px;
}
.sgh + .ib { margin-top: 8px; }
.gs { padding-bottom: 8px; }
.sgh::before {
  content: ''; display: inline-block; width: 3px; height: 14px;
  background: var(--sky); border-radius: 2px;
}
.ib {
  border: 1px solid #7ab0d0;
  border-radius: 8px;
  margin: 8px 20px 20px;
  overflow: hidden;
}
.ib:first-child { margin-top: 16px; }

.it {
  background: var(--sky-ll);
  padding: 14px 16px; display: flex; align-items: flex-start; gap: 10px;
}
.ino {
  background: var(--sky-d); color: var(--white);
  font-size: 13px; font-weight: 700; padding: 2px 8px;
  border-radius: 4px; flex-shrink: 0; margin-top: 1px;
}
.idesc { font-size: 14px; color: var(--sub); line-height: 1.6; }

/* ── Table ── */
table.bt { border-collapse: collapse; width: 100%; font-size: 14px; margin: 0; }
table.bt th {
  border: 1px solid #7ab0d0;
  background: #93C5FD; color: var(--sky-d);
  font-weight: 600; padding: 10px 14px; text-align: left;
  font-size: 13px; letter-spacing: .04em;
}
table.bt td { padding: 8px 12px; border: 1px solid #7ab0d0; vertical-align: middle; }
table.bt tbody tr:nth-child(even) td { background: var(--sky-ll); }
table.bt tbody tr:hover td { background: #d0e4f2; }
.pc { font-weight: 700; color: var(--sky-d); white-space: nowrap; }
.pc::before { content: 'NT$ '; font-size: 12px; font-weight: 400; color: var(--muted); }
.ot {
  display: inline-block; background: var(--bg); color: var(--sub);
  font-size: 13px; padding: 1px 6px; border-radius: 3px; border: 1px solid var(--border);
}
.eco {
  display: inline-block; background: #ECFDF5; color: #065f46;
  border: 1px solid #A7F3D0; font-size: 13px; padding: 1px 6px; border-radius: 3px;
}
.eco-pending {
  display: inline-block; background: var(--amber-l); color: #92400E;
  border: 1px solid #FCD34D; font-size: 13px; padding: 1px 6px; border-radius: 3px;
}

:target { scroll-margin-top: 96px; }

/* ── Back to top ── */
.back-top { text-align: right; padding: 6px 20px 0; }
.back-top a {
  font-size: 13px; color: var(--sky-d); text-decoration: none;
  display: inline-flex; align-items: center; gap: 3px;
}
.back-top a:hover { text-decoration: underline; }
.back-top a::before { content: '↑'; font-size: 11px; }

/* ── Footer ── */
footer {
  background: var(--ink); color: var(--muted);
  text-align: center; padding: 20px; font-size: 14px; margin-top: 40px;
}
footer strong { color: var(--sky-l); }

@media (max-width: 768px) {
  .layout { flex-direction: column; align-items: stretch; padding: 12px; }
  .main { margin-left: 0; margin-top: 16px; }
  .sidebar { width: 100%; position: static; max-height: none; }
  .ib { overflow-x: auto; }
}

/* ── 耗材型頁面：搜尋框與表格欄寬（新增，不影響 .bt 既有樣式）── */
.tsearch {
  background: none; border: none; border-radius: 0;
  padding: 0; margin-bottom: 20px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.tsearch::before { content: '🔍 查詢'; font-size: 16px; font-weight: 700; color: var(--sky-d); white-space: nowrap; }
.tsearch input {
  flex: 1; min-width: 220px; padding: 10px 14px; font: inherit; font-size: 15px;
  border: 2px solid var(--sky); border-radius: 8px; background: var(--white);
}
.tsearch input:focus { outline: 3px solid rgba(14,165,233,.35); outline-offset: 0; }
.tsearch .tcount { font-size: 13px; color: var(--muted); }
table.bt .code { font-family: Consolas, monospace; white-space: nowrap; }
table.bt td.models { font-size: 13px; color: var(--sub); }
table.bt td.nw, table.bt th.nw { white-space: nowrap; }
.tnone { padding: 16px 20px; color: var(--muted); display: none; }

/* ── 耗材型：印表機品牌跳轉連結 ── */
.tbrand { background: var(--white); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 20px; overflow: hidden; }
.tbrand-hd { padding: 10px 20px; font-size: 14px; font-weight: 700; color: var(--sky-d); background: var(--sky-ll); }
.tbrand .gidx { border-bottom: none; background: var(--white); padding: 14px 20px; }

/* ── 欄寬統一：欄位相同的表格，各欄寬度一致（只調整寬度，不改框線與配色） ── */
table.bt { table-layout: fixed; }
table.bt td { overflow-wrap: anywhere; }
table.bt .code { white-space: normal; }
/* 6 欄：廠牌 | 型號 | 契約金額 | 原產地 | 環章編號 | 有效期限 */
table.bt th:nth-child(1):nth-last-child(6) { width: 14%; }
table.bt th:nth-child(2):nth-last-child(5) { width: 30%; }
table.bt th:nth-child(3):nth-last-child(4) { width: 14%; }
table.bt th:nth-child(4):nth-last-child(3) { width: 14%; }
table.bt th:nth-child(5):nth-last-child(2) { width: 14%; }
table.bt th:nth-child(6):nth-last-child(1) { width: 14%; }
/* 8 欄：項次 | 廠牌 | 項目名稱 | 耗材編碼 | 適用機型 | 單位 | 契約金額 | 產地 */
table.bt th:nth-child(1):nth-last-child(8) { width: 5%; }
table.bt th:nth-child(2):nth-last-child(7) { width: 9%; }
table.bt th:nth-child(3):nth-last-child(6) { width: 20%; }
table.bt th:nth-child(4):nth-last-child(5) { width: 15%; }
table.bt th:nth-child(5):nth-last-child(4) { width: 24%; }
table.bt th:nth-child(6):nth-last-child(3) { width: 5%; }
table.bt th:nth-child(7):nth-last-child(2) { width: 10%; }
table.bt th:nth-child(8):nth-last-child(1) { width: 12%; }
/* 4 欄 */
table.bt th:nth-child(1):nth-last-child(4) { width: 6%; }
table.bt th:nth-child(2):nth-last-child(3) { width: 12%; }
table.bt th:nth-child(3):nth-last-child(2) { width: 64%; }
table.bt th:nth-child(4):nth-last-child(1) { width: 18%; }
@media (max-width: 768px) {
  table.bt:has(th:nth-child(4)) { min-width: 420px; }
  table.bt:has(th:nth-child(6)) { min-width: 640px; }
  table.bt:has(th:nth-child(8)) { min-width: 820px; }
}
