/* ===========================================================
   長信名茶 內部管理與績效系統 — Demo
   設計 token：介面色取自長信名茶官網的橄欖茶綠與茶褐；
   資料視覺化配色另行通過 CVD / 對比驗證，不跟品牌色混用
   =========================================================== */

:root {
  color-scheme: light;

  /* 版面 */
  --plane:          #f6f4ee;
  --surface-1:      #fdfcf9;
  --surface-2:      #efece4;
  --border:         rgba(68, 55, 49, 0.12);
  --border-strong:  rgba(68, 55, 49, 0.22);

  /* 文字（茶褐） */
  --text-primary:   #2a221d;
  --text-secondary: #5a4f47;
  --text-muted:     #877b71;

  /* 圖表骨架 */
  --gridline:       #e4dfd4;
  --axis:           #c7c0b0;

  /* 資料系列（第 1 槽，單一系列圖表全部使用） */
  --series-1:       #2a78d6;
  --series-1-wash:  rgba(42, 120, 214, 0.10);
  --series-2:       #eb6834;
  --series-3:       #1baf7a;

  /* 循序色階 */
  --seq-100: #cde2fb;
  --seq-250: #86b6ef;
  --seq-400: #3987e5;
  --seq-550: #1c5cab;

  /* 狀態色（固定，不隨主題變） */
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;
  --good-text: #006300;

  /* UI 主色（僅用於介面，絕不用於資料標記） */
  --accent:       #464c3a;
  --accent-ink:   #ffffff;
  --accent-wash:  rgba(70, 76, 58, 0.09);

  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 12px rgba(11, 11, 11, 0.04);
  --font: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --font-serif: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --plane:          #12110e;
    --surface-1:      #1c1a16;
    --surface-2:      #26231e;
    --border:         rgba(255, 255, 255, 0.10);
    --border-strong:  rgba(255, 255, 255, 0.20);
    --text-primary:   #ffffff;
    --text-secondary: #cbc3b5;
    --text-muted:     #948a7e;
    --gridline:       #2c2c2a;
    --axis:           #383835;
    --series-1:       #3987e5;
    --series-1-wash:  rgba(57, 135, 229, 0.12);
    --series-2:       #d95926;
    --series-3:       #199e70;
    --seq-100: #104281;
    --seq-250: #1c5cab;
    --seq-400: #2a78d6;
    --seq-550: #86b6ef;
    --good-text: #0ca30c;
    --accent:       #b0ba92;
    --accent-ink:   #12110e;
    --accent-wash:  rgba(176, 186, 146, 0.13);
    --shadow:    0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.25);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:          #12110e;
  --surface-1:      #1c1a16;
  --surface-2:      #26231e;
  --border:         rgba(255, 255, 255, 0.10);
  --border-strong:  rgba(255, 255, 255, 0.20);
  --text-primary:   #ffffff;
  --text-secondary: #cbc3b5;
  --text-muted:     #948a7e;
  --gridline:       #2c2c2a;
  --axis:           #383835;
  --series-1:       #3987e5;
  --series-1-wash:  rgba(57, 135, 229, 0.12);
  --series-2:       #d95926;
  --series-3:       #199e70;
  --seq-100: #104281;
  --seq-250: #1c5cab;
  --seq-400: #2a78d6;
  --seq-550: #86b6ef;
  --good-text: #0ca30c;
  --accent:       #b0ba92;
  --accent-ink:   #12110e;
  --accent-wash:  rgba(176, 186, 146, 0.13);
  --shadow:    0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

/* 元件自帶的 display 會蓋掉 hidden 屬性，權限鎖定靠它，所以一律強制 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--plane);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-family: var(--font-serif); font-weight: 700; letter-spacing: 0.02em; line-height: 1.3; }
p { margin: 0; }
button { font: inherit; }

/* ---------- 示範資料橫幅 ---------- */
.demo-banner {
  background: var(--accent-wash);
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 13px;
  padding: 8px 20px;
  text-align: center;
}
.demo-banner strong { color: var(--text-primary); }

/* ---------- 後台外框：左側導覽 + 上方工具列 ---------- */
.app-shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: calc(100vh - 37px); }
.sidebar {
  align-self: start;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 37px);
  position: sticky;
  top: 0;
}
.side-brand {
  align-items: center;
  border-bottom: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  display: flex;
  gap: 10px;
  padding: 16px 18px;
}
.brand-mark { color: var(--accent); display: flex; flex: 0 0 auto; height: 34px; width: 34px; }
.brand-mark svg { display: block; height: 100%; width: 100%; }
.side-brand-name { font-family: var(--font-serif); font-size: 17px; font-weight: 700; letter-spacing: 0.12em; line-height: 1.2; }
.side-brand-sub { color: var(--text-muted); font-size: 11.5px; letter-spacing: 0.06em; }
.sidenav { display: flex; flex: 1 1 auto; flex-direction: column; gap: 2px; overflow-y: auto; padding: 10px 10px 16px; }
.nav-group {
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  padding: 14px 10px 6px;
}
.side-foot {
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  display: grid;
  font-size: 11.5px;
  gap: 2px;
  line-height: 1.5;
  padding: 12px 18px;
}
.ico { fill: none; flex: 0 0 auto; height: 18px; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; width: 18px; }

.app-body { min-width: 0; }
.topbar {
  align-items: center;
  backdrop-filter: saturate(1.2) blur(8px);
  background: var(--surface-1);
  background: color-mix(in srgb, var(--surface-1) 88%, transparent);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 10px;
  height: 58px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 40;
}
.crumbs { align-items: baseline; color: var(--text-muted); display: flex; font-size: 13px; gap: 8px; min-width: 0; white-space: nowrap; }
.crumbs strong { color: var(--text-primary); font-family: var(--font-serif); font-size: 17px; letter-spacing: 0.06em; }
.crumb-sep { opacity: 0.5; }
.icon-btn {
  align-items: center;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  height: 36px;
  justify-content: center;
  position: relative;
  width: 36px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text-primary); }
.icon-btn:focus-visible, .user-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn .ico { height: 20px; width: 20px; }
.badge {
  background: var(--critical);
  border: 2px solid var(--surface-1);
  border-radius: 999px;
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1;
  min-width: 19px;
  padding: 3px 5px;
  position: absolute;
  right: -3px;
  top: -2px;
}
.user-btn {
  align-items: center;
  background: none;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  gap: 9px;
  padding: 3px 12px 3px 3px;
}
.user-btn:hover { background: var(--surface-2); }
.avatar {
  align-items: center;
  background: var(--accent);
  border-radius: 50%;
  color: var(--accent-ink);
  display: inline-flex;
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 700;
  height: 32px;
  justify-content: center;
  width: 32px;
}
.user-btn-text { display: grid; line-height: 1.25; text-align: left; }
.user-btn-text span:first-child { font-size: 13.5px; font-weight: 600; }
.user-btn-text span:last-child { color: var(--text-muted); font-size: 11.5px; }

/* 下拉選單 */
.menu-wrap { position: relative; }
.menu {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(30, 24, 18, 0.16);
  min-width: 240px;
  padding: 6px;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 60;
}
.menu-head { border-bottom: 1px solid var(--border); display: grid; gap: 3px; margin-bottom: 6px; padding: 10px 10px 12px; }
.menu-title { font-size: 13px; font-weight: 700; padding-bottom: 10px; }
.menu-user-name { font-family: var(--font-serif); font-size: 16px; font-weight: 700; }
.menu-user-meta { align-items: center; display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 2px; }
.menu-item {
  align-items: flex-start;
  background: none;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  font-size: 13.5px;
  gap: 10px;
  padding: 9px 10px;
  text-align: left;
  width: 100%;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline: none; }
.menu-danger { color: var(--critical); }
.menu-sep { background: var(--border); height: 1px; margin: 6px 4px; }
.notif-menu { width: 340px; }
.notif-list { max-height: 420px; overflow-y: auto; }
.notif-item .chip-dot { margin-top: 6px; }
.notif-item > span:last-child { display: grid; gap: 1px; }
.notif-text { font-size: 13.5px; }
.dot-critical { background: var(--critical); }
.dot-serious { background: var(--serious); }
.dot-warning { background: var(--warning); }
.dot-neutral { background: var(--text-muted); }

.only-mobile { display: none !important; }

.btn {
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 13px;
  padding: 7px 13px;
  transition: background 0.12s ease, border-color 0.12s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-sm { font-size: 12px; padding: 5px 10px; }

/* ---------- 側邊導覽項目 ---------- */
.tab {
  align-items: center;
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  font-size: 14px;
  gap: 11px;
  padding: 9px 10px;
  position: relative;
  text-align: left;
  width: 100%;
}
.tab:hover { background: var(--surface-2); color: var(--text-primary); }
.tab[aria-selected="true"] { background: var(--accent-wash); color: var(--accent); font-weight: 650; }
.tab[aria-selected="true"]::before {
  background: var(--accent);
  border-radius: 0 3px 3px 0;
  content: "";
  height: 18px;
  left: -10px;
  position: absolute;
  width: 3px;
}
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tab > span { flex: 1 1 auto; }
.nav-count {
  background: var(--surface-2);
  border-radius: 999px;
  color: var(--text-secondary);
  font-size: 11.5px;
  font-style: normal;
  font-weight: 650;
  padding: 1px 8px;
}
.tab[aria-selected="true"] .nav-count { background: var(--accent); color: var(--accent-ink); }

/* 帳號管理表格 */
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.row-muted td { opacity: 0.6; }
.row-muted td:last-child { opacity: 1; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }

/* 變更密碼 */
.modal-desc { color: var(--text-secondary); font-size: 13.5px; line-height: 1.65; margin-bottom: 16px; }
.modal-desc p { margin-bottom: 10px; }
.modal .auth-field .field { font-size: 14px; padding: 9px 11px; width: 100%; }
.pw-meter { background: var(--surface-2); border-radius: 99px; height: 5px; margin: -6px 0 8px; overflow: hidden; }
.pw-meter span { border-radius: 99px; display: block; height: 100%; transition: width 0.2s ease; width: 0; }
.pw-meter .weak { background: var(--critical); }
.pw-meter .mid { background: var(--warning); }
.pw-meter .strong { background: var(--good); }
.pw-rules { color: var(--text-muted); columns: 2; column-gap: 14px; font-size: 12.5px; line-height: 1.75; list-style: none; margin: 0 0 14px; padding: 0; }
.pw-rules .ok { color: var(--good-text); }
.temp-pw-row { align-items: center; display: flex; gap: 10px; }
.temp-pw {
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  flex: 1;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 17px;
  letter-spacing: 0.08em;
  padding: 8px 12px;
}

/* ---------- 版面 ---------- */
main { margin: 0 auto; max-width: 1320px; padding: 26px 28px 72px; }
.panel[hidden] { display: none; }
.section-head {
  align-items: flex-end;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-head h2 { font-size: 19px; }
.section-head p { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.grid { display: grid; gap: 16px; }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

/* ---------- Hero 數字 ---------- */
.hero-card { display: flex; flex-wrap: wrap; gap: 28px; justify-content: space-between; }
.hero-label { color: var(--text-secondary); font-size: 13px; }
.hero-figure {
  font-size: 52px;
  font-weight: 680;
  letter-spacing: -0.03em;
  line-height: 1.05;
  margin: 4px 0 6px;
}
.hero-sub { color: var(--text-secondary); font-size: 13px; }

/* ---------- 統計磚 ---------- */
.tile-label { color: var(--text-secondary); font-size: 13px; }
.tile-value { font-size: 27px; font-weight: 650; letter-spacing: -0.02em; margin: 5px 0 4px; }
.tile-delta { align-items: center; display: flex; font-size: 12.5px; gap: 5px; }
.delta-up { color: var(--good-text); }
.delta-down { color: var(--critical); }
.delta-flat { color: var(--text-muted); }

/* ---------- 圖表 ---------- */
.chart-head { align-items: baseline; display: flex; gap: 12px; justify-content: space-between; margin-bottom: 4px; }
.chart-title { font-size: 15px; font-weight: 620; }
.chart-note { color: var(--text-muted); font-size: 12px; }
.chart-wrap { margin-top: 10px; position: relative; }
svg.chart { display: block; height: auto; width: 100%; }
svg.chart text { font-family: var(--font); }
.axis-label { fill: var(--text-muted); font-size: 11px; }
.value-label { fill: var(--text-secondary); font-size: 11.5px; font-weight: 600; }
.gridline { stroke: var(--gridline); stroke-width: 1; }
.axisline { stroke: var(--axis); stroke-width: 1; }

.tooltip {
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 12.5px;
  line-height: 1.5;
  padding: 7px 10px;
  pointer-events: none;
  position: absolute;
  transform: translate(-50%, -112%);
  white-space: nowrap;
  z-index: 20;
}
.tooltip[hidden] { display: none; }
.tooltip .tt-label { color: var(--text-muted); }
.tooltip .tt-value { color: var(--text-primary); font-weight: 640; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; }
.legend-item { align-items: center; color: var(--text-secondary); display: flex; font-size: 12.5px; gap: 6px; }
.legend-swatch { border-radius: 2px; flex: 0 0 auto; height: 10px; width: 10px; }

/* ---------- 表格 ---------- */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; font-size: 13.5px; width: 100%; }
caption { color: var(--text-muted); font-size: 12px; padding-bottom: 8px; text-align: left; }
th, td { padding: 9px 11px; text-align: left; white-space: nowrap; }
thead th {
  border-bottom: 1px solid var(--border-strong);
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 600;
}
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
tbody tr.is-active { background: var(--accent-wash); }
.num { font-variant-numeric: tabular-nums; text-align: right; }
th.num { text-align: right; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text-primary); }
th.sortable::after { content: "\2195"; font-size: 10px; margin-left: 4px; opacity: 0.35; }
th.sortable[data-dir="asc"]::after { content: "\2191"; opacity: 1; }
th.sortable[data-dir="desc"]::after { content: "\2193"; opacity: 1; }

/* ---------- 標籤 / 狀態 ---------- */
.chip {
  align-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 600;
  gap: 5px;
  padding: 2px 9px;
  white-space: nowrap;
}
.chip-dot { border-radius: 50%; flex: 0 0 auto; height: 7px; width: 7px; }
.chip-good     { border-color: var(--good); }
.chip-good .chip-dot     { background: var(--good); }
.chip-warning  { border-color: var(--warning); }
.chip-warning .chip-dot  { background: var(--warning); }
.chip-serious  { border-color: var(--serious); }
.chip-serious .chip-dot  { background: var(--serious); }
.chip-critical { border-color: var(--critical); }
.chip-critical .chip-dot { background: var(--critical); }
.chip-neutral  { color: var(--text-secondary); }
.chip-neutral .chip-dot  { background: var(--text-muted); }

.grade {
  border-radius: var(--radius-sm);
  display: inline-block;
  font-size: 13px;
  font-weight: 700;
  min-width: 26px;
  padding: 1px 7px;
  text-align: center;
}
.grade-A { background: rgba(12, 163, 12, 0.14); color: var(--good-text); }
.grade-B { background: var(--series-1-wash); color: var(--series-1); }
.grade-C { background: rgba(250, 178, 25, 0.18); color: #8a6000; }
.grade-D { background: rgba(208, 59, 59, 0.14); color: var(--critical); }
:root[data-theme="dark"] .grade-C { color: var(--warning); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .grade-C { color: var(--warning); }
}

/* ---------- 量表 ---------- */
.meter-row { display: grid; gap: 4px; margin-bottom: 13px; }
.meter-top { align-items: baseline; display: flex; font-size: 13px; gap: 8px; justify-content: space-between; }
.meter-name { color: var(--text-secondary); }
.meter-val { font-variant-numeric: tabular-nums; font-weight: 640; }
.meter-track { background: var(--seq-100); border-radius: 999px; height: 7px; position: relative; width: 100%; }
.meter-fill { border-radius: 999px; height: 100%; transition: width 0.25s ease; }
/* 100 分目標線：落在 130 分刻度的 76.9% 處 */
.meter-target {
  background: var(--text-muted);
  bottom: -2px;
  left: 76.9%;
  opacity: 0.55;
  position: absolute;
  top: -2px;
  width: 1px;
}
.meter-weight { color: var(--text-muted); font-size: 11.5px; }

/* ---------- 篩選列 ---------- */
.toolbar {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-bottom: 14px;
}
.field {
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font: inherit;
  font-size: 13.5px;
  padding: 7px 10px;
}
.field:focus-visible { border-color: var(--accent); outline: 2px solid var(--accent-wash); }
input.field::placeholder { color: var(--text-muted); }
.spacer { flex: 1 1 auto; }
.result-count { color: var(--text-muted); font-size: 12.5px; }

/* ---------- 詳情 ---------- */
.detail-grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); }
@media (max-width: 900px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-head { border-bottom: 1px solid var(--border); margin-bottom: 14px; padding-bottom: 12px; }
.detail-name { font-size: 18px; font-weight: 650; }
.detail-meta { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }
.empty-state { color: var(--text-muted); font-size: 13.5px; padding: 28px 12px; text-align: center; }

.score-input { display: grid; gap: 10px; margin-top: 4px; }
.score-input label { color: var(--text-secondary); font-size: 13px; }
.score-input input[type="range"] { accent-color: var(--accent); width: 100%; }
textarea.field { min-height: 76px; resize: vertical; width: 100%; }

.form-grid { display: grid; gap: 11px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.form-grid label { color: var(--text-secondary); display: grid; font-size: 12.5px; gap: 4px; }
.form-grid .field { width: 100%; }

/* ---------- 其他 ---------- */
.stack { display: grid; gap: 16px; }
.inline-note { color: var(--text-muted); font-size: 12.5px; margin-top: 10px; }
.sr-only {
  clip: rect(0 0 0 0); clip-path: inset(50%); height: 1px; overflow: hidden;
  position: absolute; white-space: nowrap; width: 1px;
}
.toast {
  background: var(--text-primary);
  border-radius: var(--radius-sm);
  bottom: 22px;
  color: var(--plane);
  font-size: 13.5px;
  left: 50%;
  padding: 10px 18px;
  position: fixed;
  transform: translateX(-50%);
  z-index: 90;
}
.toast[hidden] { display: none; }

@media (max-width: 640px) {
  .hero-figure { font-size: 40px; }
  main { padding: 18px 16px 60px; }
}

/* 平板以下：側邊導覽改為抽屜 */
@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.25);
    height: 100vh;
    left: 0;
    position: fixed;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    width: 260px;
    z-index: 80;
  }
  .sidebar.open { transform: none; }
  .side-backdrop { background: rgba(20, 18, 14, 0.4); inset: 0; position: fixed; z-index: 70; }
  .only-mobile { display: inline-flex !important; }
  .topbar { padding: 0 12px; }
  .user-btn-text, .hide-mobile, .presence { display: none !important; }
  .user-btn { padding: 3px; }
  .notif-menu { position: fixed; left: 12px; right: 12px; top: 64px; width: auto; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }

/* ===========================================================
   登入、權限、流程、多人協作
   =========================================================== */

/* ---------- 登入畫面 ---------- */
/* 企業登入版型：左側品牌形象（仿官網首頁橫幅），右側登入表單 */
.auth-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  min-height: calc(100vh - 37px);
}
.auth-brand {
  align-self: start;
  color: #464c3a;
  height: calc(100vh - 37px);
  min-height: 560px;
  overflow: hidden;
  position: sticky;
  top: 0;
}
.auth-brand .landscape { height: 100%; inset: 0; position: absolute; width: 100%; }
:root[data-theme="dark"] .auth-brand .landscape { filter: brightness(0.85) saturate(0.9); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .auth-brand .landscape { filter: brightness(0.85) saturate(0.9); }
}
.auth-brand-inner { padding: 64px 56px 0; position: relative; }
.brand-lockup { align-items: center; display: inline-flex; gap: 10px; margin-bottom: 30px; }
.auth-brand .brand-mark { color: #464c3a; height: 46px; width: 46px; }
.brand-name {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1.15;
}
.brand-name small {
  display: block;
  font-family: var(--font);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.08em;
}
.auth-brand h1 { font-size: 40px; letter-spacing: 0.16em; }
.leaf-rule {
  align-items: center;
  color: #6f8c47;
  display: flex;
  gap: 10px;
  margin: 16px 0 12px;
  max-width: 360px;
}
.leaf-rule::before, .leaf-rule::after { background: rgba(70, 76, 58, 0.35); content: ""; flex: 1; height: 1px; }
.leaf-rule svg { height: 14px; width: 14px; }
.auth-brand-inner p { color: #4a4438; font-size: 15px; letter-spacing: 0.2em; }
.auth-store {
  align-items: center;
  backdrop-filter: blur(6px);
  background: rgba(253, 252, 249, 0.92);
  border-radius: var(--radius);
  bottom: 28px;
  box-shadow: 0 8px 24px rgba(30, 40, 20, 0.18);
  display: flex;
  gap: 14px;
  left: 56px;
  margin: 0;
  max-width: 420px;
  padding: 10px;
  position: absolute;
  right: 56px;
}
.auth-store img { border-radius: var(--radius-sm); display: block; flex: 0 0 auto; height: 76px; object-fit: cover; width: 104px; }
.auth-store figcaption { color: #5a4f47; font-size: 12.5px; line-height: 1.6; }
.auth-store strong { color: #464c3a; display: block; font-family: var(--font-serif); font-size: 15px; letter-spacing: 0.1em; }

.auth-main {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 56px 32px 48px;
}
.auth-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(42, 34, 29, 0.05), 0 12px 32px rgba(42, 34, 29, 0.08);
  max-width: 420px;
  padding: 34px 34px 22px;
  width: 100%;
}
.auth-card h2 { font-size: 24px; letter-spacing: 0.08em; }
.auth-sub { color: var(--text-secondary); font-size: 13.5px; margin: 4px 0 22px; }
.auth-field { display: grid; gap: 6px; margin-bottom: 14px; }
.auth-field > span:first-child { color: var(--text-secondary); font-size: 13px; font-weight: 600; }
.auth-field .field { font-size: 15px; padding: 10px 12px; width: 100%; }
.auth-field .field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); outline: none; }
.pw-wrap { display: block; position: relative; }
.pw-wrap .field { padding-right: 58px; }
.pw-toggle {
  background: none;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--accent);
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 8px;
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
}
.pw-toggle:focus-visible { outline: 2px solid var(--accent); }
.caps-hint { color: var(--serious); font-size: 12.5px; margin: -6px 0 10px; }
.auth-row { align-items: center; display: flex; font-size: 13px; justify-content: space-between; margin: 2px 0 16px; }
.check { align-items: center; color: var(--text-secondary); cursor: pointer; display: inline-flex; gap: 7px; }
.check input { accent-color: var(--accent); height: 15px; margin: 0; width: 15px; }
.link-btn {
  background: none;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 0;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 3px;
}
.link-btn:hover { text-decoration-color: currentColor; }
.link-btn:disabled { color: var(--text-muted); cursor: default; text-decoration: none; }
.auth-back { margin-bottom: 14px; }
.auth-meta { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.auth-error {
  background: rgba(208, 59, 59, 0.08);
  border: 1px solid rgba(208, 59, 59, 0.35);
  border-radius: var(--radius-sm);
  color: var(--critical);
  font-size: 13px;
  line-height: 1.55;
  margin-bottom: 14px;
  padding: 9px 12px;
}
.auth-notice {
  background: var(--accent-wash);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.55;
  margin-bottom: 18px;
  padding: 9px 12px;
}
.btn-block { display: flex; font-size: 15px; font-weight: 600; justify-content: center; letter-spacing: 0.1em; padding: 11px 16px; width: 100%; }
.btn-block:disabled { cursor: progress; opacity: 0.8; }
.spinner {
  animation: spin 0.8s linear infinite;
  border: 2px solid currentColor;
  border-radius: 50%;
  border-right-color: transparent;
  display: none;
  height: 15px;
  margin-right: 8px;
  width: 15px;
}
.is-busy .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
.otp { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 22px !important; letter-spacing: 0.5em; text-align: center; }
.sms-sim {
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.6;
  margin-top: 18px;
  padding: 11px 13px;
}
.sms-head { color: var(--text-muted); font-size: 11.5px; letter-spacing: 0.06em; margin-bottom: 3px; }
.sms-body strong { color: var(--accent); font-family: ui-monospace, Consolas, monospace; font-size: 15px; letter-spacing: 0.15em; }
.auth-legal { border-top: 1px solid var(--border); color: var(--text-muted); font-size: 11.5px; line-height: 1.6; margin-top: 22px; padding-top: 14px; text-align: center; }

.demo-accounts { max-width: 640px; width: 100%; }
.demo-accounts-head { align-items: baseline; display: flex; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 12px; }
.demo-accounts-head h2 { font-size: 16px; letter-spacing: 0.08em; }
.demo-accounts-head span { color: var(--text-muted); font-size: 12.5px; }
.demo-accounts code, .login-user code {
  background: var(--surface-2);
  border-radius: 4px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  padding: 1px 5px;
}
.login-user { align-items: center; display: flex; flex-wrap: wrap; gap: 6px; }
.mfa-tag { border: 1px solid var(--accent); border-radius: 999px; color: var(--accent); font-size: 11px; padding: 0 7px; }

@media (max-width: 900px) {
  .auth-shell { grid-template-columns: 1fr; min-height: 0; }
  .auth-brand { height: auto; min-height: 250px; position: relative; }
  .auth-brand-inner { padding: 30px 20px 120px; text-align: center; }
  .brand-lockup { margin-bottom: 14px; }
  .auth-brand h1 { font-size: 27px; letter-spacing: 0.1em; }
  .leaf-rule { margin: 10px auto 8px; }
  .auth-store { display: none; }
  .auth-main { padding: 0 16px 40px; }
  .auth-card { margin-top: -70px; padding: 26px 20px 18px; position: relative; }
}

/* 閒置逾時警告 */
.modal-backdrop {
  align-items: center;
  background: rgba(20, 18, 14, 0.45);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 16px;
  position: fixed;
  z-index: 100;
}
.modal {
  background: var(--surface-1);
  border-radius: 14px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.25);
  max-width: 400px;
  padding: 24px;
  width: 100%;
}
.modal h2 { font-size: 19px; margin-bottom: 8px; }
.modal p { color: var(--text-secondary); font-size: 14px; line-height: 1.65; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
.nowrap { white-space: nowrap; }

/* 庫存表的官網商品圖 */
.tea-cell { align-items: center; display: flex; gap: 10px; }
.tea-thumb {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  flex: 0 0 auto;
  height: 44px;
  object-fit: cover;
  width: 44px;
}

.login-hint {
  background: var(--accent-wash);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 13.5px;
  line-height: 1.65;
  margin-top: 14px;
  padding: 13px 16px;
}
.login-hint strong { color: var(--text-primary); }

.login-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(258px, 1fr)); }
.login-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  display: grid;
  font: inherit;
  gap: 5px;
  padding: 15px;
  text-align: left;
  transition: border-color 0.12s ease, transform 0.12s ease;
}
.login-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.login-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.login-card-top { align-items: center; display: flex; gap: 9px; justify-content: space-between; }
.login-name { color: var(--text-primary); font-size: 16px; font-weight: 650; }
.login-role { color: var(--text-secondary); font-size: 13px; }
.login-note { color: var(--text-muted); font-size: 12.5px; line-height: 1.5; }
.login-state { align-items: center; color: var(--text-muted); display: flex; font-size: 12.5px; gap: 6px; margin-top: 4px; }

/* ---------- 權限徽章 ---------- */
.access-badge {
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  display: inline-block;
  font-size: 11.5px;
  font-weight: 650;
  padding: 1px 8px;
  white-space: nowrap;
}
.access-staff { color: var(--text-secondary); }
.access-manager { border-color: var(--accent); color: var(--accent); }
.access-admin { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---------- Header：使用者與線上名單 ---------- */
.user-chip { align-items: center; display: inline-flex; font-size: 13px; gap: 6px; white-space: nowrap; }
.presence {
  color: var(--text-secondary);
  cursor: default;
  font-size: 12.5px;
  white-space: nowrap;
}
.presence:empty { display: none; }

/* ---------- 表格輔助 ---------- */
.cell-sub { color: var(--text-muted); font-size: 12px; }
.self-tag {
  background: var(--accent-wash);
  border-radius: 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 650;
  margin-left: 6px;
  padding: 1px 5px;
}

/* ---------- 流程進度條 ---------- */
.stepper {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 14px 0 6px;
}
.step { align-items: center; color: var(--text-muted); display: flex; font-size: 12.5px; gap: 6px; }
.step-dot {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  display: flex;
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 700;
  height: 19px;
  justify-content: center;
  width: 19px;
}
.step-done { color: var(--text-secondary); }
.step-done .step-dot { background: var(--accent-wash); border-color: var(--accent); color: var(--accent); }
.step-current { color: var(--text-primary); font-weight: 650; }
.step-current .step-dot { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.step-appeal { color: var(--critical); font-weight: 650; }
.step-appeal .step-dot { background: var(--critical); border-color: var(--critical); color: #fff; }

.state-hint { color: var(--text-secondary); font-size: 12.5px; margin-bottom: 12px; }

/* ---------- 版本衝突 ---------- */
.conflict {
  background: rgba(208, 59, 59, 0.08);
  border: 1px solid var(--critical);
  border-radius: var(--radius);
  margin: 12px 0 16px;
  padding: 13px 15px;
}
.conflict-title { color: var(--critical); font-size: 14px; font-weight: 700; }
.conflict-body { color: var(--text-secondary); font-size: 13px; line-height: 1.6; margin-top: 5px; }
.conflict-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 11px; }

/* ---------- 詳情區塊 ---------- */
.section-label {
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.04em;
  margin: 18px 0 11px;
  padding-top: 13px;
  text-transform: uppercase;
}
.quote {
  background: var(--surface-2);
  border-left: 2px solid var(--border-strong);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.65;
  margin-top: 10px;
  padding: 10px 13px;
}
.quote-alert { border-left-color: var(--critical); }
.locked-note {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.6;
  margin-top: 10px;
  padding: 12px 14px;
}
.kv-row {
  align-items: baseline;
  border-bottom: 1px solid var(--border);
  display: flex;
  font-size: 13px;
  justify-content: space-between;
  padding: 6px 0;
}

.meter-diff { color: var(--text-muted); font-size: 11.5px; margin-right: 9px; }
.diff-up { color: var(--good-text); }
.diff-down { color: var(--critical); }

.editor-legend { color: var(--text-secondary); font-size: 13px; font-weight: 620; margin-bottom: 2px; }
.live-total { font-variant-numeric: tabular-nums; font-weight: 700; }
.field-label { color: var(--text-secondary); display: grid; font-size: 12.5px; gap: 5px; margin-top: 12px; }

.action-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.btn-danger { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn-danger:hover { background: var(--critical); filter: brightness(1.08); }

/* ---------- 稽核軌跡 ---------- */
.history-wrap { border-top: 1px solid var(--border); margin-top: 18px; padding-top: 14px; }
.history { display: grid; gap: 2px; margin-top: 11px; }
.history-row {
  border-left: 2px solid var(--border-strong);
  display: grid;
  font-size: 13px;
  gap: 2px 12px;
  grid-template-columns: 112px minmax(0, 1fr);
  padding: 8px 0 8px 13px;
}
.history-ts { color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.history-move { color: var(--text-muted); font-size: 12px; }
@media (max-width: 560px) {
  .history-row { grid-template-columns: 1fr; }
}

/* ---------- 權限不足卡 ---------- */
.lock-card { align-items: flex-start; display: flex; gap: 14px; }
.lock-icon { font-size: 22px; line-height: 1.2; }

/* ===========================================================
   資料表、表單頁、簽核、報表、檢索、匯入、文件
   =========================================================== */

/* ---------- 頁首排版 ---------- */
.section-head { align-items: flex-end; margin-bottom: 18px; }
.section-head h2 { font-size: 23px; letter-spacing: 0.06em; }
.section-head p { font-size: 13.5px; line-height: 1.6; margin-top: 4px; max-width: 760px; }
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- 分段切換鈕 ---------- */
.seg {
  background: var(--surface-2);
  border-radius: 9px;
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
}
.seg-btn {
  align-items: center;
  background: none;
  border: 0;
  border-radius: 7px;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  font-size: 13px;
  gap: 6px;
  padding: 5px 12px;
  white-space: nowrap;
}
.seg-btn:hover { color: var(--text-primary); }
.seg-btn[aria-pressed="true"] { background: var(--surface-1); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 0 0 1px var(--border); color: var(--text-primary); font-weight: 650; }
.seg-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg-lg .seg-btn { font-size: 14px; padding: 7px 16px; }
.seg-count {
  background: var(--border);
  border-radius: 999px;
  font-size: 11px;
  font-style: normal;
  font-weight: 650;
  min-width: 20px;
  padding: 0 6px;
  text-align: center;
}
.seg-btn[aria-pressed="true"] .seg-count { background: var(--accent); color: var(--accent-ink); }

/* ---------- 清單卡（工具列 + 表格 + 分頁） ---------- */
.list-card { overflow: hidden; padding: 0; }
.list-head { border-bottom: 1px solid var(--border); display: grid; gap: 10px; padding: 12px 14px; }
.list-head .toolbar { margin: 0; }
.list-tools { align-items: center; display: flex; flex-wrap: wrap; gap: 8px; }
.view-pick { align-items: center; color: var(--text-secondary); display: inline-flex; gap: 6px; }
.view-pick .field { font-weight: 600; min-width: 170px; }
.view-form { align-items: center; display: inline-flex; gap: 6px; }
.view-form .field { width: 200px; }
.field-search { min-width: 240px; }
.adv-filter {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  padding: 12px;
}
.adv-filter label { color: var(--text-secondary); display: grid; font-size: 12.5px; gap: 4px; }
.filter-chips { align-items: center; display: flex; flex-wrap: wrap; gap: 6px; }
.filter-chip {
  align-items: center;
  background: var(--accent-wash);
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--text-primary);
  cursor: pointer;
  display: inline-flex;
  font-size: 12.5px;
  gap: 6px;
  padding: 3px 6px 3px 11px;
}
.filter-chip:hover { border-color: var(--accent); }
.filter-chip-k { color: var(--text-muted); }
.filter-chip-x { border-radius: 50%; color: var(--text-muted); font-size: 14px; line-height: 1; padding: 0 3px; }
.bulk-bar {
  align-items: center;
  background: var(--accent);
  border-radius: var(--radius-sm);
  color: var(--accent-ink);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 7px 10px;
}
.bulk-bar .field { padding: 4px 8px; }
.bulk-bar .link-btn { color: var(--accent-ink); }
.list-foot { align-items: center; border-top: 1px solid var(--border); display: flex; gap: 8px; padding: 10px 14px; }
.pager-pos { color: var(--text-secondary); font-size: 12.5px; font-variant-numeric: tabular-nums; min-width: 52px; text-align: center; }
.btn:disabled { cursor: default; opacity: 0.45; }
.btn:disabled:hover { background: var(--surface-1); }

.data-table thead th { background: var(--surface-1); position: sticky; top: 0; z-index: 1; }
.data-table tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 40%, transparent); }
.data-table tbody tr.clickable:hover { background: var(--surface-2); }
.data-table tbody tr.is-selected, .data-table tbody tr.is-active { background: var(--accent-wash); }
.col-check { padding-right: 0; width: 34px; }
.col-check input, .row-check { accent-color: var(--accent); height: 15px; width: 15px; }
.cell-wrap { max-width: 280px; white-space: normal; }
tbody tr.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.form-card { margin-bottom: 16px; }
.form-card-head { align-items: baseline; display: flex; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 14px; }
.form-card-head h3 { font-size: 16px; }
.form-grid label { color: var(--text-secondary); display: grid; font-size: 12.5px; gap: 5px; }

/* ---------- 看板 ---------- */
.board { display: grid; gap: 12px; grid-template-columns: repeat(4, minmax(220px, 1fr)); overflow-x: auto; padding: 14px; }
.board-col {
  background: var(--surface-2);
  border: 2px dashed transparent;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  max-height: 640px;
  min-width: 0;
}
.board-col.drop-on { border-color: var(--accent); }
.board-head { align-items: center; display: flex; gap: 6px; padding: 10px 10px 8px; }
.board-cards { display: grid; gap: 8px; overflow-y: auto; padding: 0 8px 10px; }
.board-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  color: var(--text-primary);
  cursor: pointer;
  display: grid;
  gap: 3px;
  padding: 9px 10px;
  text-align: left;
}
.board-card[draggable="true"] { cursor: grab; }
.board-card:hover { border-color: var(--border-strong); }
.board-card:focus-visible { outline: 2px solid var(--accent); }
.board-card.dragging { opacity: 0.45; }
.board-card-top, .board-card-foot { align-items: center; display: flex; justify-content: space-between; }
.board-card-title { font-size: 13.5px; font-weight: 650; }
.board-card .mono { font-size: 11.5px; }
.board-card-foot { margin-top: 4px; }
.board-more { color: var(--text-muted); font-size: 12px; padding: 10px 4px; text-align: center; }
.avatar-xs { font-size: 11px; height: 22px; width: 22px; }
.avatar-sm { font-size: 13px; height: 28px; width: 28px; }

/* ---------- 行事曆 ---------- */
.cal { padding: 14px; }
.cal-head { align-items: center; display: flex; gap: 10px; margin-bottom: 12px; }
.cal-title { font-family: var(--font-serif); font-size: 17px; min-width: 110px; text-align: center; }
.cal-grid { border-left: 1px solid var(--border); border-top: 1px solid var(--border); display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-wd { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); color: var(--text-muted); font-size: 12px; padding: 6px; text-align: center; }
.cal-cell { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); display: grid; align-content: start; gap: 3px; min-height: 96px; padding: 5px; }
.cal-blank { background: var(--surface-2); opacity: 0.5; }
.cal-day { color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.cal-today { background: var(--accent-wash); }
.cal-today .cal-day { color: var(--accent); font-weight: 700; }
.cal-ev {
  background: var(--surface-2);
  border: 0;
  border-left: 3px solid var(--text-muted);
  border-radius: 4px;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 11.5px;
  overflow: hidden;
  padding: 2px 5px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-ev:hover { background: var(--border); }
.cal-ev-good { border-left-color: var(--good); }
.cal-ev-warning { border-left-color: var(--warning); }
.cal-ev-serious { border-left-color: var(--serious); }
.cal-ev-neutral { border-left-color: var(--text-muted); opacity: 0.7; }
.cal-more { font-size: 11.5px; text-align: left; }

/* ---------- 茶品圖卡 ---------- */
.tea-gallery { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); padding: 14px; }
.tea-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
  text-align: left;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.tea-card:hover { box-shadow: 0 8px 22px rgba(42, 34, 29, 0.12); transform: translateY(-2px); }
.tea-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tea-card-img { aspect-ratio: 4 / 3; background: linear-gradient(160deg, #eef0e6, #dfe5d3); overflow: hidden; }
.tea-card-img img { display: block; height: 100%; object-fit: cover; width: 100%; }
.tea-card-body { display: grid; gap: 7px; padding: 12px 13px 13px; }
.tea-card-top { align-items: center; display: flex; gap: 6px; justify-content: space-between; }
.tea-card-name { font-family: var(--font-serif); font-size: 16px; font-weight: 700; letter-spacing: 0.04em; }
.tea-card-foot { align-items: baseline; display: flex; font-size: 13px; justify-content: space-between; }
.stock-bar { background: var(--surface-2); border-radius: 99px; height: 6px; overflow: hidden; position: relative; }
.stock-fill { border-radius: 99px; display: block; height: 100%; }
.stock-critical { background: var(--critical); }
.stock-serious { background: var(--serious); }
.stock-warning { background: var(--warning); }
.stock-good { background: var(--good); }
.stock-mark { background: var(--text-secondary); height: 100%; position: absolute; top: 0; width: 2px; }

/* ---------- 單筆表單頁（抽屜） ---------- */
body.no-scroll { overflow: hidden; }
.drawer-backdrop { background: rgba(20, 18, 14, 0.38); inset: 0; position: fixed; z-index: 85; }
.drawer {
  background: var(--plane);
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 100vw;
  position: fixed;
  right: 0;
  top: 0;
  width: 620px;
  z-index: 86;
  animation: drawer-in 0.18s ease-out;
}
@keyframes drawer-in { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .drawer { animation: none; } }
.drawer-head {
  align-items: flex-start;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  display: flex;
  gap: 12px;
  padding: 16px 18px 14px 22px;
}
.drawer-head-main { flex: 1 1 auto; min-width: 0; }
.drawer-kicker { color: var(--text-muted); font-size: 12px; letter-spacing: 0.04em; }
.drawer-title-row { align-items: center; display: flex; flex-wrap: wrap; gap: 10px; margin-top: 2px; }
.drawer-title-row h2 { font-size: 21px; letter-spacing: 0.04em; }
.drawer-tools { align-items: center; display: flex; gap: 2px; }
.drawer-tools .icon-btn:disabled { cursor: default; opacity: 0.35; }
.drawer-tabs { background: none; border-bottom: 1px solid var(--border); border-radius: 0; gap: 4px; padding: 8px 18px 0; }
.drawer-tabs .seg-btn { border-radius: 7px 7px 0 0; padding: 8px 12px; }
.drawer-tabs .seg-btn[aria-pressed="true"] { box-shadow: inset 0 -2px 0 var(--accent); background: none; }
.drawer-body { flex: 1 1 auto; overflow-y: auto; padding: 18px 22px 28px; }
.drawer-foot {
  align-items: center;
  background: var(--surface-1);
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 22px;
}
.drawer-hero { background: linear-gradient(160deg, #eef0e6, #dfe5d3); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden; }
.drawer-hero img { display: block; height: 200px; margin: 0 auto; object-fit: contain; padding: 12px; }

.form-sec { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 14px; padding: 14px 16px 6px; }
.form-sec-title {
  align-items: baseline;
  color: var(--text-primary);
  display: flex;
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}
.kv-grid { display: grid; gap: 0 18px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0; }
.kv { border-top: 1px solid var(--border); display: grid; gap: 2px; padding: 8px 0 9px; }
.kv-grid > .kv:nth-child(-n+2) { border-top: 0; }
.kv dt, .kv-label { color: var(--text-muted); font-size: 12px; }
.kv dd { font-size: 14px; margin: 0; overflow-wrap: anywhere; }
.kv-edit { border-top: 0; gap: 5px; padding: 6px 0; }
.kv-edit .field { width: 100%; }
.kv-wide { grid-column: 1 / -1; }
.rec-link {
  background: none;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-align: left;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
  text-underline-offset: 3px;
}
.rec-link:hover { text-decoration-color: currentColor; }
.link-list { display: grid; gap: 8px; margin-bottom: 10px; }
.link-card {
  align-items: center;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  display: flex;
  font: inherit;
  font-size: 13.5px;
  gap: 12px;
  justify-content: space-between;
  padding: 9px 12px;
  text-align: left;
  width: 100%;
}
button.link-card { cursor: pointer; }
button.link-card:hover { border-color: var(--accent); }
.link-card-main { flex: 1 1 auto; min-width: 0; }
.table-compact { font-size: 13px; }
.table-compact td { padding: 7px 8px; }

.mini-bars { align-items: end; display: grid; gap: 10px; grid-template-columns: repeat(6, 1fr); height: 150px; margin-bottom: 12px; }
.mini-bar { align-items: center; display: grid; gap: 4px; grid-template-rows: auto 1fr auto; height: 100%; }
.mini-bar-val { color: var(--text-secondary); font-size: 11px; text-align: center; }
.mini-bar-track { align-items: end; display: flex; height: 100%; justify-content: center; }
.mini-bar-fill { background: var(--series-1); border-radius: 4px 4px 0 0; display: block; width: 70%; }
.mini-bar-lbl { color: var(--text-muted); font-size: 11.5px; text-align: center; }

.timeline { list-style: none; margin: 0; padding: 0 0 0 4px; }
.tl-item { border-left: 2px solid var(--border); padding: 0 0 18px 20px; position: relative; }
.tl-item:last-child { border-left-color: transparent; }
.tl-dot { background: var(--surface-1); border: 2px solid var(--accent); border-radius: 50%; height: 12px; left: -7px; position: absolute; top: 4px; width: 12px; }
.tl-origin .tl-dot { border-color: var(--text-muted); }
.tl-head { font-size: 13.5px; }
.tl-note { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }
.diff-table { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius-sm); margin-top: 8px; width: auto; }
.diff-table td { padding: 5px 10px; }
.diff-old { background: rgba(208, 59, 59, 0.1); border-radius: 3px; color: var(--critical); padding: 0 4px; }
.diff-new { background: rgba(12, 163, 12, 0.12); border-radius: 3px; color: var(--good-text); padding: 0 4px; text-decoration: none; }
.diff-arrow { color: var(--text-muted); }

.comments { display: grid; gap: 12px; list-style: none; margin: 0 0 16px; padding: 0; }
.comment { align-items: flex-start; display: flex; gap: 10px; }
.comment-main { background: var(--surface-1); border: 1px solid var(--border); border-radius: 4px 12px 12px 12px; flex: 1 1 auto; padding: 8px 12px; }
.comment-me .comment-main { background: var(--accent-wash); }
.comment-head { align-items: baseline; display: flex; font-size: 13px; gap: 8px; justify-content: space-between; }
.comment-text { font-size: 14px; line-height: 1.6; margin-top: 2px; white-space: pre-wrap; }
.comment-form { display: grid; gap: 8px; }
.comment-form textarea { resize: vertical; width: 100%; }
.comment-actions { align-items: center; display: flex; gap: 10px; justify-content: space-between; }

/* ---------- 簽核 ---------- */
.ap-kicker { color: var(--text-muted); font-size: 12px; margin-bottom: 2px; }
.detail-name .chip { margin-left: 4px; vertical-align: 2px; }
#ap-detail .kv-grid { margin-bottom: 4px; }
.flow { list-style: none; margin: 0; padding: 0; }
.flow-step { display: flex; gap: 12px; padding-bottom: 14px; position: relative; }
.flow-step:not(:last-child)::before { background: var(--border-strong); bottom: 0; content: ""; left: 12px; position: absolute; top: 26px; width: 2px; }
.flow-dot {
  align-items: center;
  background: var(--surface-2);
  border: 2px solid var(--border-strong);
  border-radius: 50%;
  color: var(--text-muted);
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
  height: 26px;
  justify-content: center;
  width: 26px;
}
.flow-title { font-size: 13.5px; font-weight: 600; }
.flow-state { color: var(--text-muted); font-size: 12px; font-weight: 500; margin-left: 8px; }
.flow-note { background: var(--surface-2); border-radius: var(--radius-sm); color: var(--text-secondary); font-size: 12.5px; margin-top: 4px; padding: 5px 9px; }
.flow-approved .flow-dot { background: var(--good); border-color: var(--good); color: #fff; }
.flow-rejected .flow-dot { background: var(--critical); border-color: var(--critical); color: #fff; }
.flow-rejected .flow-state { color: var(--critical); font-weight: 650; }
.flow-pending .flow-dot { background: var(--surface-1); border-color: var(--warning); color: var(--warning); }
.flow-pending .flow-state { color: var(--text-primary); font-weight: 650; }
.flow-skipped .flow-title, .flow-void .flow-title { color: var(--text-muted); font-weight: 500; }
.flow-compact .flow-step { padding-bottom: 10px; }
.ap-action { background: var(--accent-wash); border-radius: var(--radius); margin-top: 6px; padding: 12px 14px; }
.ap-action textarea { margin-top: 8px; resize: vertical; width: 100%; }
.modal-wide { max-width: 820px; }
.ap-form-grid { display: grid; gap: 22px; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }
.ap-form-grid textarea { resize: vertical; width: 100%; }
.ap-preview { background: var(--surface-2); border-radius: var(--radius); padding: 14px; }
.ap-preview-amt { font-size: 13.5px; margin-bottom: 12px; }
.ap-preview-amt strong { font-size: 18px; }
.form-2 { display: grid; gap: 0 12px; grid-template-columns: 1fr 1fr; }
.modal { max-height: calc(100vh - 32px); overflow-y: auto; }

/* ---------- 報表 ---------- */
.rp-head, .rp-ctls { align-items: center; display: flex; flex-wrap: wrap; gap: 10px 14px; }
.rp-ctls { background: var(--surface-2); border-radius: var(--radius-sm); margin-top: 14px; padding: 10px 12px; }
.rp-ctl { align-items: center; color: var(--text-secondary); display: inline-flex; font-size: 13px; gap: 8px; }
.rp-body { margin-top: 16px; }
.pivot th[scope="row"] { font-weight: 600; }
.pivot tfoot th, .pivot tfoot td { border-top: 2px solid var(--border-strong); font-weight: 700; }
.pivot-total { background: var(--surface-2); font-weight: 650; }
.heat { position: relative; }
.heat-bg { background: var(--series-1); inset: 2px; position: absolute; border-radius: 3px; }
.heat-v { position: relative; }
.heat-strong { color: #fff; font-weight: 650; }
.rank { display: grid; gap: 4px; list-style: none; margin: 0; padding: 0; }
.rank-row {
  align-items: center;
  border-bottom: 1px solid var(--border);
  display: grid;
  gap: 12px;
  grid-template-columns: 28px 28px minmax(130px, 1fr) minmax(120px, 2fr) 120px;
  padding: 10px 4px;
}
.rank-no { color: var(--text-muted); font-size: 15px; font-weight: 700; text-align: center; }
.rank-top { color: var(--accent); font-family: var(--font-serif); font-size: 18px; }
.rank-bar { background: var(--surface-2); border-radius: 4px; height: 14px; overflow: hidden; }
.rank-fill { background: var(--series-1); border-radius: 4px; display: block; height: 100%; }
.rank-val { text-align: right; }
.bar-cell { align-items: center; display: flex; gap: 10px; min-width: 200px; }
.inline-bar { background: var(--surface-2); border-radius: 3px; display: block; flex: 1 1 auto; height: 8px; overflow: hidden; }
.inline-bar span { background: var(--series-1); display: block; height: 100%; }

/* ---------- 全文檢索 ---------- */
.search-btn {
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  font-size: 13px;
  gap: 8px;
  margin-left: 18px;
  max-width: 380px;
  min-width: 0;
  padding: 6px 8px 6px 12px;
}
.search-btn:hover { border-color: var(--border-strong); color: var(--text-secondary); }
.search-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.search-btn-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
kbd {
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--text-secondary);
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11px;
  padding: 0 5px;
  white-space: nowrap;
}
.search-backdrop { align-items: flex-start; padding-top: 12vh; }
.search-panel {
  background: var(--surface-1);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  max-height: 70vh;
  max-width: 640px;
  overflow: hidden;
  width: 100%;
}
.search-input-row { align-items: center; border-bottom: 1px solid var(--border); display: flex; gap: 10px; padding: 14px 16px; }
.search-input-row input { background: none; border: 0; color: var(--text-primary); flex: 1; font: inherit; font-size: 16px; outline: none; }
.search-results { overflow-y: auto; padding: 6px; }
.search-group { color: var(--text-muted); font-size: 11.5px; font-weight: 650; letter-spacing: 0.08em; padding: 10px 10px 4px; }
.search-hit {
  align-items: center;
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  gap: 12px;
  padding: 8px 10px;
  text-align: left;
  width: 100%;
}
.search-hit > span:last-child { display: grid; min-width: 0; }
.search-hit.is-active { background: var(--accent-wash); }
.search-ico { align-items: center; background: var(--surface-2); border-radius: 6px; color: var(--accent); display: inline-flex; flex: 0 0 auto; height: 30px; justify-content: center; width: 30px; }
.search-label { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-foot { border-top: 1px solid var(--border); color: var(--text-muted); display: flex; flex-wrap: wrap; font-size: 12px; gap: 16px; padding: 9px 16px; }

/* ---------- 匯入 ---------- */
.imp-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.file-btn { cursor: pointer; }
.imp-text { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; resize: vertical; width: 100%; }
.imp-sum { align-items: center; display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 8px; }
.imp-table { border: 1px solid var(--border); border-radius: var(--radius-sm); max-height: 260px; overflow: auto; }
.imp-bad td { background: rgba(208, 59, 59, 0.06); }
.imp-err { color: var(--critical); font-size: 12.5px; white-space: normal; }

/* ---------- 文件（出貨單） ---------- */
.print-backdrop { align-items: stretch; padding: 0; }
.print-shell { background: var(--surface-2); display: flex; flex-direction: column; width: 100%; }
.print-toolbar { align-items: center; background: var(--surface-1); border-bottom: 1px solid var(--border); display: flex; gap: 10px; padding: 12px 20px; }
.print-docs { display: grid; gap: 24px; justify-items: center; overflow-y: auto; padding: 28px 16px 48px; }
.doc {
  background: #fff;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  color: #2a221d;
  max-width: 100%;
  padding: 48px 52px 36px;
  width: 760px;
}
.doc-head { align-items: flex-end; border-bottom: 2px solid #464c3a; display: flex; justify-content: space-between; padding-bottom: 14px; }
.doc-brand-name { color: #464c3a; font-family: var(--font-serif); font-size: 26px; font-weight: 700; letter-spacing: 0.16em; }
.doc-brand-sub { color: #877b71; font-size: 11px; letter-spacing: 0.1em; }
.doc-title { font-family: var(--font-serif); font-size: 22px; font-weight: 700; text-align: right; }
.doc-no { color: #5a4f47; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; font-weight: 400; }
.doc-meta { display: grid; font-size: 13.5px; gap: 6px 14px; grid-template-columns: auto 1fr auto 1fr; margin: 18px 0; }
.doc-meta dt { color: #877b71; }
.doc-meta dd { margin: 0; }
.doc-table { border: 1px solid #c7c0b0; font-size: 13.5px; }
.doc-table th { background: #efece4; color: #2a221d; }
.doc-table th, .doc-table td { border: 1px solid #c7c0b0; }
.doc-table tfoot td { font-weight: 700; }
.doc-sign { display: grid; gap: 24px; grid-template-columns: repeat(3, 1fr); margin-top: 40px; }
.doc-sign div { display: grid; font-size: 12.5px; gap: 30px; color: #5a4f47; }
.doc-sign i { border-bottom: 1px solid #877b71; display: block; }
.doc-foot { border-top: 1px dashed #c7c0b0; color: #877b71; font-size: 11px; margin-top: 30px; padding-top: 10px; text-align: center; }

@media print {
  body > *:not(#print-modal) { display: none !important; }
  html, body { background: #fff; }
  #print-modal { background: none; display: block !important; position: static; }
  .print-shell { background: none; }
  .print-toolbar { display: none; }
  .print-docs { display: block; overflow: visible; padding: 0; }
  .doc { box-shadow: none; break-after: page; margin: 0 auto; padding: 0; width: auto; }
}

/* ---------- 權限矩陣 ---------- */
.perm-table { font-size: 13px; margin-top: 8px; }
.perm-table th[scope="row"] { color: var(--text-primary); font-weight: 650; }
.perm-table td { color: var(--text-secondary); white-space: normal; }
.perm-table .perm-none { color: var(--text-muted); }
.perm-table .perm-me { background: var(--series-1-wash); box-shadow: inset 2px 0 0 var(--series-1), inset -2px 0 0 var(--series-1); }

/* ---------- 響應式 ---------- */
@media (max-width: 1100px) {
  .search-btn-text { display: none; }
  .search-btn { margin-left: 8px; }
}
@media (max-width: 900px) {
  .ap-form-grid { grid-template-columns: 1fr; }
  .board { grid-template-columns: repeat(4, 240px); }
  .rank-row { grid-template-columns: 24px 28px minmax(0, 1fr) 96px; }
  .rank-bar { display: none; }
}
@media (max-width: 640px) {
  .drawer { width: 100vw; }
  .kv-grid, .form-2 { grid-template-columns: 1fr; }
  .kv-grid > .kv:nth-child(2) { border-top: 1px solid var(--border); }
  .field-search { min-width: 0; width: 100%; }
  .cal-cell { min-height: 64px; }
  .cal-ev { font-size: 10.5px; }
  .doc { padding: 24px 18px; }
  .doc-meta { grid-template-columns: auto 1fr; }
  .search-btn kbd { display: none; }
  .section-head h2 { font-size: 20px; }
  .list-foot { flex-wrap: wrap; }
}
