/* ================================================================
   TF 內部系統入口網 — 共用樣式
   /_shared/ui.css
   版本 v5  2026-09-02
   v3：手機卡片改為一致的「標籤：值」兩欄
   v4：手機新增「表格 / 卡片」檢視切換，表格模式可橫向捲動比對數字
   v5：底色系去除綠調，改為中性冷灰，整體提亮一階。
       重點色（pine / rust / brass）維持不變，底色中性後反而更跳出來。
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;500;700&display=swap');

:root {
  --ink:      #16202b;
  --ink-2:    #4a5a66;
  --ink-3:    #7e8b92;

  /* 表面色。v5 之前是綠調灰（#edf0ee 系），整體偏暗且泛綠，
     改為中性冷灰。這幾個值要一起調，只改其中一個會顯得不協調。 */
  --ground:   #f4f6f8;
  --panel:    #ffffff;
  --rule:     #dcdfe4;
  --rule-2:   #edeff2;
  --tint:     #f7f9fb;   /* 結果列、hover、載入更多的底色 */
  --tint-2:   #f1f4f8;   /* 表頭 */
  --tint-3:   #fafbfd;   /* 捲動提示 */

  /* 重點色。品牌墨綠，只用在標籤、狀態、focus，不進表面色。 */
  --pine:     #14584e;
  --pine-dim: #e2edea;
  --rust:     #9e3b26;
  --rust-dim: #f7e9e5;
  --brass:    #8a6a1f;
  --brass-dim:#f6efdd;

  --sans: 'Noto Sans TC', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Mono', Consolas, monospace;

  --r: 3px;

  /* 頁首實際高度，由 JS 量測後覆寫。表頭靠這個值釘在頁首下方。 */
  --head-h: 58px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  font-feature-settings: 'tnum' 1;
}

a { color: var(--pine); }
:focus-visible { outline: 2px solid var(--pine); outline-offset: 2px; }

.mono { font-family: var(--mono); font-size: .92em; letter-spacing: -.01em; }
.num  { font-variant-numeric: tabular-nums; }
.dim  { color: var(--ink-3); }
.neg  { color: var(--rust); }
[hidden] { display: none !important; }

/* ---------- 頁首 ---------- */

.tf-head { background: var(--panel); border-bottom: 1px solid var(--rule); position: sticky; top: 0; z-index: 40; }
.tf-head-in { max-width: 1400px; margin: 0 auto; padding: 14px 20px; display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.tf-mark {
  display: inline-flex; align-items: center;
  text-decoration: none; flex: 0 0 auto;
}
.tf-mark img { width: 26px; height: 26px; display: block; }

/* 系統頁回入口綠。標誌已改連公司入口綠，這裡裝回站內導覽。 */
.tf-back {
  font-size: 13px;
  color: var(--ink-3);
  text-decoration: none;
  white-space: nowrap;
}
.tf-back:hover { color: var(--pine); }
.tf-back::before { content: "← "; }
.tf-title { font-size: 17px; font-weight: 500; margin: 0; padding-left: 16px; border-left: 1px solid var(--rule); }
.tf-who { margin-left: auto; font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 10px; }
.tf-scope { font-size: 11px; font-weight: 500; padding: 2px 7px; border: 1px solid var(--rule); border-radius: var(--r); color: var(--ink-2); }
.tf-scope[data-scope="SELF"] { border-color: #cdd8d4; background: var(--pine-dim); color: var(--pine); }
.tf-out { background: none; border: 0; padding: 2px 4px; color: var(--ink-3); font-family: inherit; font-size: 13px; cursor: pointer; }
.tf-out:hover { color: var(--rust); }

/* ---------- 版面 ---------- */

main { max-width: 1400px; margin: 0 auto; padding: 20px 20px 64px; }
.panel { background: var(--panel); border: 1px solid var(--rule); border-radius: var(--r); }

/* ---------- 表單元件 ---------- */

label { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 5px; }

input[type=text], input[type=date], input[type=search], select {
  width: 100%; padding: 7px 9px;
  font-family: inherit; font-size: 14px; color: var(--ink);
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--r);
}
input:focus, select:focus { border-color: var(--pine); outline: none; box-shadow: 0 0 0 3px var(--pine-dim); }

button { font-family: inherit; cursor: pointer; }

.btn { padding: 7px 14px; font-size: 14px; border: 1px solid var(--rule); border-radius: var(--r); background: var(--panel); color: var(--ink); }
.btn:hover { border-color: var(--ink-3); }
.btn-primary { background: var(--pine); border-color: var(--pine); color: #fff; }
.btn-primary:hover { background: #0f463e; }
.btn-sm { padding: 4px 9px; font-size: 12px; }

.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: var(--r); overflow: hidden; }
.seg button { padding: 6px 10px; font-size: 12px; background: var(--panel); border: 0; border-right: 1px solid var(--rule); color: var(--ink-2); }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--pine-dim); color: var(--pine); }
.seg button[aria-pressed="true"] { background: var(--pine); color: #fff; }

.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); cursor: pointer; user-select: none; }
.chk input { width: 15px; height: 15px; accent-color: var(--pine); margin: 0; }

/* ---------- 徽章 ---------- */

.tag { display: inline-block; font-size: 11px; font-weight: 500; padding: 1px 6px; border-radius: var(--r); white-space: nowrap; }
.tag-out  { background: var(--pine-dim);  color: var(--pine); }
.tag-ret  { background: var(--rust-dim);  color: var(--rust); }
.tag-ask  { background: var(--brass-dim); color: var(--brass); }
.tag-off  { background: var(--rule-2);    color: var(--ink-3); }

/* ---------- 全頁狀態 ---------- */

.tf-gate { position: fixed; inset: 0; background: var(--ground); z-index: 100; display: grid; place-items: center; padding: 24px; }
.tf-gate-box { max-width: 380px; width: 100%; text-align: center; }
.tf-gate h1 { font-size: 19px; font-weight: 500; margin: 0 0 8px; }
.tf-gate p { margin: 0 0 22px; color: var(--ink-2); font-size: 14px; }
.tf-gate-code { margin-top: 26px; font-size: 11px; color: var(--ink-3); }

.tf-bar { width: 120px; height: 2px; margin: 0 auto 22px; background: var(--rule); overflow: hidden; }
.tf-bar i { display: block; width: 40%; height: 100%; background: var(--pine); animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } }

.btn-google { display: inline-flex; align-items: center; gap: 10px; padding: 9px 18px; background: var(--panel); border: 1px solid var(--rule); border-radius: var(--r); font-size: 14px; color: var(--ink); }
.btn-google:hover { border-color: var(--ink-3); }
.btn-google svg { width: 17px; height: 17px; }

@media (prefers-reduced-motion: reduce) {
  .tf-bar i { animation: none; width: 100%; }
  * { transition: none !important; }
}

/* ---------- 入口網 ---------- */

.portal-lead { display: flex; align-items: flex-end; gap: 20px; flex-wrap: wrap; margin-bottom: 20px; }
.portal-lead .field { flex: 1 1 300px; max-width: 420px; }
.portal-count { font-size: 13px; color: var(--ink-3); padding-bottom: 8px; }

.dept { margin-bottom: 28px; }
.dept h2 { font-size: 13px; font-weight: 500; color: var(--ink-2); margin: 0 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--rule); }

.sys-row { display: flex; align-items: baseline; gap: 14px; padding: 9px 10px; border-bottom: 1px solid var(--rule-2); text-decoration: none; color: inherit; }
.sys-row:last-child { border-bottom: 0; }
.sys-row:hover { background: var(--pine-dim); }
.sys-code { flex: 0 0 92px; font-family: var(--mono); font-size: 12px; color: var(--ink-3); }
.sys-row:hover .sys-code { color: var(--pine); }
.sys-name { flex: 1 1 auto; }
.sys-row.pending { color: var(--ink-3); cursor: default; }
.sys-row.pending:hover { background: transparent; }

.empty { padding: 40px 10px; text-align: center; color: var(--ink-3); font-size: 14px; }

/* ================================================================
   查詢類系統共用
   ================================================================ */

.filters { padding: 16px; margin-bottom: 14px; }

.filters-head {
  display: none; align-items: center; justify-content: space-between;
  width: 100%; padding: 0; background: none; border: 0;
  font-size: 14px; color: var(--ink);
}

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.grid .wide { grid-column: span 2; }

.field { position: relative; }

.clearable { position: relative; }
.clearable .x {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; line-height: 20px; text-align: center;
  border: 0; background: none; color: var(--ink-3); font-size: 16px; padding: 0;
}
.clearable .x:hover { color: var(--rust); }

.suggest {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 30;
  margin-top: 2px; max-height: 46vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--r);
  box-shadow: 0 8px 22px rgba(22,32,43,.14);
}
.suggest div {
  padding: 9px 10px; font-size: 14px; cursor: pointer;
  border-bottom: 1px solid var(--rule-2);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.suggest div:last-child { border-bottom: 0; }
.suggest div:hover, .suggest div.on { background: var(--pine-dim); }
.suggest .none { color: var(--ink-3); cursor: default; }
.suggest .none:hover { background: transparent; }

.dates { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dates input { width: auto; flex: 1 1 130px; }

.toolbar { padding: 10px 14px; margin-bottom: 14px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; font-size: 13px; }
.toolbar .sep { width: 1px; height: 18px; background: var(--rule); }
.toolbar .spacer { margin-left: auto; }

.result-bar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 11px 14px; border-bottom: 1px solid var(--rule);
  background: var(--tint); font-size: 13px; color: var(--ink-2);
}
.result-bar b { color: var(--ink); font-weight: 500; }
.result-bar .spacer { margin-left: auto; }
.perf { font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* ---------- 資料表 ---------- */

/* 這一層同時是橫向與縱向的捲動容器。
   sticky 是相對於最近的捲動祖先，所以表頭要釘住就必須讓這層來捲，
   不能讓它只有 overflow-x（那樣會變成有捲動脈絡但不捲，sticky 位移到半空中）。 */
.dt-wrap {
  overflow: auto;
  max-height: calc(100dvh - var(--head-h) - 96px);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

table.dt { width: 100%; border-collapse: collapse; font-size: 13.5px; }

table.dt th {
  position: sticky; top: 0; z-index: 10;
  background: var(--tint-2); border-bottom: 1px solid var(--rule);
  box-shadow: 0 1px 0 var(--rule);
  padding: 9px 12px; font-size: 12px; font-weight: 500; color: var(--ink-2);
  text-align: left; white-space: nowrap;
}
table.dt th.sortable { cursor: pointer; user-select: none; }
table.dt th.sortable:hover { background: var(--pine-dim); color: var(--pine); }
table.dt th .ind { color: var(--ink-3); font-size: 10px; margin-left: 3px; }
table.dt th[aria-sort] { color: var(--pine); }
table.dt th[aria-sort] .ind { color: var(--pine); }

table.dt td { padding: 9px 12px; border-bottom: 1px solid var(--rule-2); vertical-align: top; }
table.dt tbody tr:hover { background: var(--tint); }
table.dt .r, table.dt .r .v { text-align: right; }
table.dt .r { white-space: nowrap; }

.prod-main { font-weight: 500; }
.prod-alt { font-size: 12px; color: var(--ink-3); font-weight: 400; }

.more { padding: 16px; text-align: center; border-top: 1px solid var(--rule); background: var(--tint); }

/* 桌機不顯示檢視切換 */
.mobile-only { display: none !important; }

/* ---------- 行動版 ---------- */

@media (max-width: 760px) {
  body { font-size: 15px; }

  /* 頁首壓成單列：標誌 + 系統名稱 + 使用者資訊。
     公司名以標誌代表，省下一整列高度。 */
  .tf-head-in {
    padding: 8px 12px;
    gap: 9px;
    flex-wrap: nowrap;
    align-items: center;
  }
  .tf-mark img { width: 24px; height: 24px; }
  .tf-back { display: none; }
  .tf-title {
    flex: 1 1 auto;
    min-width: 0;
    padding-left: 0;
    border-left: 0;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .tf-who { margin-left: auto; flex: 0 0 auto; font-size: 12px; gap: 7px; }
  .tf-scope { padding: 1px 5px; font-size: 10px; }
  .tf-out { font-size: 12px; }
  main { padding: 12px 12px 48px; }

  .filters { padding: 14px; }
  .filters-head { display: flex; }
  .filters .grid { display: none; margin-top: 16px; }
  .filters.open .grid { display: grid; }
  .grid { grid-template-columns: 1fr; }
  .grid .wide { grid-column: span 1; }

  .toolbar { gap: 12px 14px; }

  .mobile-only { display: inline-flex !important; }
  span.mobile-only.sep { display: block !important; }

  /* ======== 表格模式：橫向捲動、釘住表頭，方便縱向比對數字 ======== */

  .dt-wrap.mode-table {
    max-height: calc(100dvh - var(--head-h) - 84px);
  }
  .dt-wrap.mode-table table.dt { font-size: 12.5px; min-width: 620px; }
  .dt-wrap.mode-table th,
  .dt-wrap.mode-table td { padding: 7px 9px; white-space: nowrap; }
  .dt-wrap.mode-table td { vertical-align: top; }

  /* 文字欄允許換行並限寬，數字欄維持單行才能對齊 */
  .dt-wrap.mode-table td[data-label="客戶名稱"] .v,
  .dt-wrap.mode-table td[data-label="品名"] .v {
    display: block;
    max-width: 150px;
    white-space: normal;
    word-break: break-word;
  }
  .dt-wrap.mode-table td[data-label="客戶名稱"],
  .dt-wrap.mode-table td[data-label="品名"] { white-space: normal; }

  /* 凍結第一欄：橫向捲動比對數字時，仍看得出這是哪一列 */
  .dt-wrap.mode-table th:first-child,
  .dt-wrap.mode-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 6;
    background: var(--panel);
    box-shadow: 1px 0 0 var(--rule-2);
  }
  .dt-wrap.mode-table thead th:first-child {
    z-index: 14;
    background: var(--tint-2);
    box-shadow: 1px 0 0 var(--rule), 0 1px 0 var(--rule);
  }

  .dt-wrap.mode-table .prod-alt { line-height: 1.4; }
  .dt-wrap.mode-table .more .btn { width: auto; }

  /* 捲動提示 */
  .scroll-hint { display: block; }

  /* ======== 卡片模式 ======== */

  .dt-wrap.mode-card { overflow: visible; max-height: none; }
  .dt-wrap.mode-card table.dt,
  .dt-wrap.mode-card table.dt tbody,
  .dt-wrap.mode-card table.dt tr,
  .dt-wrap.mode-card table.dt td { display: block; width: 100%; }
  .dt-wrap.mode-card table.dt thead { display: none; }

  .dt-wrap.mode-card table.dt tr {
    border: 1px solid var(--rule);
    border-radius: var(--r);
    margin: 0 0 10px;
    padding: 2px 12px 6px;
    background: var(--panel);
  }
  .dt-wrap.mode-card table.dt tbody tr:hover { background: var(--panel); }

  /* 一致的兩欄：左標籤、右值。值一定包在 .v 裡，避免多個子元素被 flex 拆散 */
  .dt-wrap.mode-card table.dt td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    padding: 7px 0;
    border: 0;
    border-bottom: 1px solid var(--rule-2);
    white-space: normal;
  }
  .dt-wrap.mode-card table.dt td:last-child { border-bottom: 0; }

  .dt-wrap.mode-card table.dt td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-size: 12px;
    color: var(--ink-3);
    white-space: nowrap;
  }

  .dt-wrap.mode-card table.dt td .v {
    flex: 1 1 auto;
    min-width: 0;
    text-align: right;
    word-break: break-word;
  }

  .prod-alt { margin-top: 2px; }

  .more { padding: 12px; }
  .dt-wrap.mode-card + .more .btn { width: 100%; }
}

/* 捲動提示：只在手機表格模式出現 */
.scroll-hint {
  display: none;
  padding: 6px 14px;
  font-size: 11px;
  color: var(--ink-3);
  border-bottom: 1px solid var(--rule-2);
  background: var(--tint-3);
}