/* 客供料庫存查詢 — 對外客戶介面 */

:root {
  --bg:        #f4f6f9;
  --surface:   #ffffff;
  --border:    #dfe4ec;
  --text:      #1c2430;
  --text-soft: #5c6878;
  --accent:    #1e5aa8;
  --accent-dk: #17457f;
  --danger:    #b3261e;
  --radius:    10px;
  --shadow:    0 1px 3px rgba(20,32,50,.07), 0 4px 16px rgba(20,32,50,.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Noto Sans TC", "Roboto Condensed", "PingFang TC",
               "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 品牌 ---------- */
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px; flex: 0 0 40px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  border-radius: 9px;
  font-weight: 700; letter-spacing: .5px;
}
.brand h1 { margin: 0; font-size: 20px; font-weight: 700; }
.brand-sub { margin: 2px 0 0; font-size: 12px; color: var(--text-soft); letter-spacing: .4px; }

/* ---------- 登入頁 ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.login-card .brand { margin-bottom: 26px; }
.login-card form { display: grid; gap: 16px; }
.login-card label { display: grid; gap: 6px; }
.login-card label span { font-size: 13px; font-weight: 600; color: var(--text-soft); }
.login-card input[type=text], .login-card input[type=password] {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 7px;
  font-size: 15px; font-family: inherit;
  background: #fff; color: var(--text);
}
.login-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(30,90,168,.13);
}
.login-card button {
  margin-top: 4px; padding: 11px;
  background: var(--accent); color: #fff;
  border: 0; border-radius: 7px;
  font-size: 15px; font-weight: 600; font-family: inherit;
  cursor: pointer;
}
.login-card button:hover { background: var(--accent-dk); }
.login-card .foot {
  margin: 22px 0 0; padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 12.5px; color: var(--text-soft); text-align: center;
}
.error, .notice {
  margin: 0 0 18px; padding: 10px 12px;
  border-radius: 7px; font-size: 13.5px;
}
.error  { background: #fdecea; color: var(--danger); border: 1px solid #f5c6c2; }
.notice { background: #eef4fc; color: var(--accent-dk); border: 1px solid #cfe0f5; }

/* ---------- 頂欄 ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-inner {
  max-width: 1320px; margin: 0 auto; padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.topbar .brand-mark { width: 34px; height: 34px; flex-basis: 34px; font-size: 13px; }
.topbar strong { display: block; font-size: 15px; line-height: 1.3; }
.topbar .cust { display: block; font-size: 12.5px; color: var(--text-soft); }
.logout button {
  padding: 7px 15px;
  background: transparent; color: var(--text-soft);
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 13.5px; font-family: inherit; cursor: pointer;
}
.logout button:hover { background: var(--bg); color: var(--text); }

/* ---------- 版面 ---------- */
.wrap { max-width: 1320px; margin: 0 auto; padding: 24px; }

.cards {
  display: grid; gap: 14px; margin-bottom: 22px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: grid; gap: 3px;
}
.card-label { font-size: 12.5px; color: var(--text-soft); font-weight: 600; }
.card-value { font-size: 26px; font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums; }
.card-value.sm { font-size: 18px; }
.card-value small { font-size: 14px; font-weight: 500; color: var(--text-soft); }
.card-note { font-size: 11.5px; color: var(--text-soft); }

/* ---------- 頁籤 ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs a {
  padding: 9px 16px; margin-bottom: -1px;
  color: var(--text-soft); text-decoration: none;
  font-size: 13.5px; font-weight: 600;
  border-bottom: 2px solid transparent;
}
.tabs a:hover { color: var(--text); }
.tabs a.on { color: var(--accent); border-bottom-color: var(--accent); }
.tabs a span {
  display: inline-block; margin-left: 5px; padding: 1px 7px;
  background: var(--bg); border-radius: 10px;
  font-size: 11px; font-weight: 600; color: var(--text-soft);
}
.tabs a.on span { background: #e6eefa; color: var(--accent); }

/* ---------- 工具列 ---------- */
.toolbar { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type=search] {
  flex: 1 1 260px; max-width: 340px;
  padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 12.5px; font-family: inherit; background: #fff; color: var(--text);
}
.toolbar input[type=search]:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(30,90,168,.13);
}
.chk { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-soft); cursor: pointer; }
.count { margin-left: auto; font-size: 11.5px; color: var(--text-soft); font-variant-numeric: tabular-nums; }

/* ---------- 表格 ---------- */
/* 字級、行距、留白對齊內部的 ragic_part_trace_list.php(css/table-common.css):
   列密、字小、數字用等寬數字。客戶多半是整頁掃過去找自家料號,
   一個畫面能多看十幾列,比字大好用。 */
.tablewrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
  letter-spacing: .01em;
  font-variant-numeric: tabular-nums;
}
/* 表頭刻意「不」用 position:sticky。試過,會同時踩到三個坑:
   (1) top 值得寫死,但頂欄高度是內容算出來的(約 63.5px),寫 58px 就滑進頂欄底下;
   (2) 窄視窗時 thead 與頂欄都貼 top:0,直接疊在一起;
   (3) 外層 .tablewrap 有 overflow-x:auto,是捲動容器,sticky 的黏附基準會變成它
       而不是視窗,行為不可預測。
   每頁只有 50 列,固定表頭本來就沒什麼必要,不值得為它維護這些例外。 */
thead th {
  background: #f8f9fa;
  text-align: left; white-space: nowrap;
  padding: 3px 6px;
  font-size: 11px; font-weight: 600; color: #000;
  letter-spacing: .02em;
  border-bottom: 2px solid #ccc;
}
tbody td {
  padding: 2px 6px;
  border-bottom: 1px solid #e8e8e8;
  color: #1a1a1a;
  line-height: 1.3;
  vertical-align: top;
  max-width: 260px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* 被截斷的欄位滑過就完整展開,不必為了看完整品名去下載 Excel */
tbody td:hover { white-space: normal; overflow: visible; }
tbody tr:last-child td { border-bottom: 0; }
/* 斑馬紋走 JS 掛的 .alt,不用 :nth-child(even)。分頁是把整列 hidden 掉,
   但 nth-child 仍然把隱藏列算進去,底色會在每頁開頭隨機翻面、
   相鄰兩列同色。render() 只對「這一頁看得到的列」依序掛 .alt。 */
tbody tr.alt { background: #f7f9fc; }
tbody tr:hover, tbody tr.alt:hover { background: #eef6ff; }
th.r, td.r { text-align: right; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0; }
.num  { font-weight: 800; }
.num.muted { color: #a4aebc; font-weight: 400; }
.date { white-space: nowrap; color: var(--text-soft); }
/* 規格與原廠代號是多行文字,要求完整顯示,所以不吃上面那條單行截斷 */
.spec, .orig { white-space: pre-line; overflow: visible; line-height: 1.35; }
.spec { max-width: 360px; color: var(--text-soft); }
.orig { max-width: 200px; color: var(--text); }

/* ---------- 可排序表頭 ---------- */
.sortable thead th {
  cursor: pointer; user-select: none;
  /* 箭頭是 ::after 的 position:absolute,少了這行就沒有定位基準,
     會一路找到初始包含區塊 —— 每個欄位的箭頭全部疊在整頁最右緣。 */
  position: relative;
  padding-right: 20px;
}
.sortable thead th:hover { background: #eef2f7; color: var(--text); }
.sortable thead th:focus-visible {
  outline: 2px solid var(--accent); outline-offset: -2px;
}
/* 未排序時淡淡的雙箭頭,滑過才明顯,避免六個欄位都在搶注意力 */
.sortable thead th::after {
  content: "\2195";
  position: absolute; right: 6px;
  opacity: .3; font-size: 10px; font-weight: 400;
}
.sortable thead th:hover::after { opacity: .5; }
.sortable thead th.sort-asc::after  { content: "\2191"; opacity: 1; color: var(--accent); }
.sortable thead th.sort-desc::after { content: "\2193"; opacity: 1; color: var(--accent); }
.empty { padding: 40px; text-align: center; color: var(--text-soft); }

/* ---------- 分頁 ---------- */
.pager {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-top: 14px; flex-wrap: wrap;
}
.pager button {
  min-width: 30px; padding: 4px 8px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  font-size: 11.5px; font-family: inherit; cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.pager button:hover:not(:disabled) { background: #eef2f7; border-color: #c3ccda; }
.pager button:disabled { opacity: .4; cursor: default; }
.pager button.on {
  background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600;
}
.pager .gap { color: var(--text-soft); padding: 0 2px; }
.pager .range {
  margin-left: 8px; font-size: 11.5px; color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}

/* ---------- 下載 ---------- */
.dl {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: var(--surface); color: var(--accent);
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 12.5px; font-weight: 600; text-decoration: none;
}
.dl:hover { background: #eef2f7; border-color: var(--accent); }

.foot { margin-top: 20px; font-size: 12.5px; color: var(--text-soft); }
.foot p { margin: 0; }

@media (max-width: 640px) {
  .wrap, .topbar-inner { padding: 16px; }
  /* 不可以只 display:none 掉 .spec —— 那是 <td> 上的 class,對應的 <th>規格</th>
     還在,表頭會多一格,規格之後的欄位全部錯開一欄。窄畫面靠 .tablewrap 的
     水平捲動處理就好。 */
  .spec { max-width: 240px; }
}
