/* =========================================================
   顏色統一放這裡，方便日後修改
   風格：ESG 永續（大地色底、森林綠主色、柔和卡片）
   ========================================================= */

/* 亮色：預設 */
:root {
  --bg: #f3f6f2;          /* 淡淡的米綠色底 */
  --panel: #ffffff;
  --input: #ffffff;
  --text: #17261e;
  --text-soft: #5b6d63;
  --line: #dde6df;
  --red: #c53030;
  --green-ok: #1f8a4c;
  --amber: #b7791f;
  --shadow: 0 1px 2px rgba(20, 50, 35, .06), 0 4px 14px rgba(20, 50, 35, .05);
  /* 圖表六大類別的顏色（固定順序，色盲也分得出相鄰顏色） */
  --c1: #2a78d6; --c2: #eb6834; --c3: #1baf7a; --c4: #eda100; --c5: #e87ba4; --c6: #008300;
  --c-prev: #b9c4bd;      /* 去年（灰色） */
}

/* 暗色：按「暗色」切換（data-theme 由 script.js 設定） */
:root[data-theme="dark"] {
  --bg: #0e1512;
  --panel: #16201b;
  --input: #101914;
  --text: #e3ece6;
  --text-soft: #97aa9f;
  --line: #2a3a31;
  --red: #f07070;
  --green-ok: #4cc38a;
  --amber: #e0a84a;
  --shadow: none;
  --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500; --c5: #d55181; --c6: #008300;
  --c-prev: #4b5a51;
}

/* 主色（公司首頁風格）：--brand 按鈕與重點、--brand-soft 淡底、--brand-deep 左側選單 */
:root, :root[data-brand="green"] { --brand: #1d7a55; --brand-soft: #e3f2ea; --brand-deep: #0f3a2a; }
:root[data-brand="teal"]   { --brand: #13817f; --brand-soft: #def1f0; --brand-deep: #0b3536; }
:root[data-brand="blue"]   { --brand: #2a6fc4; --brand-soft: #e2edfa; --brand-deep: #10294a; }
:root[data-brand="orange"] { --brand: #c95f1c; --brand-soft: #faeadf; --brand-deep: #3d2010; }
:root[data-brand="purple"] { --brand: #7350b8; --brand-soft: #eee7f9; --brand-deep: #261a44; }
/* 暗色時：主色調亮、淡底調暗 */
:root[data-theme="dark"][data-brand="green"]  { --brand: #45b583; --brand-soft: #173025; --brand-deep: #0a1f17; }
:root[data-theme="dark"][data-brand="teal"]   { --brand: #3fb5b2; --brand-soft: #132e2e; --brand-deep: #08201f; }
:root[data-theme="dark"][data-brand="blue"]   { --brand: #5596e6; --brand-soft: #172840; --brand-deep: #0a1a2e; }
:root[data-theme="dark"][data-brand="orange"] { --brand: #ee8a4b; --brand-soft: #35231a; --brand-deep: #22130a; }
:root[data-theme="dark"][data-brand="purple"] { --brand: #a283e3; --brand-soft: #261d38; --brand-deep: #160f28; }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  font-size: 14px;
}

[hidden] { display: none !important; }

h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 8px; }
h3 { font-size: 14px; margin: 20px 0 8px; color: var(--brand); }

.note { color: var(--text-soft); font-size: 13px; margin: 0 0 8px; }
.hint { color: var(--text-soft); font-size: 12px; margin: 0; }
.error { color: var(--red); font-size: 14px; min-height: 20px; margin: 4px 0; }

/* ---------- 按鈕與輸入框 ---------- */
button {
  background: var(--brand);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}
button:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--text-soft); border: 1px solid var(--line); }
button.ghost:hover { border-color: var(--brand); color: var(--brand); }
button.small { padding: 4px 10px; font-size: 13px; }
button.danger { background: var(--red); }

/* 工具列的下拉選單（匯入／匯出收在一個鈕裡，點開才展開） */
details.menu { position: relative; }
details.menu > summary {
  list-style: none;                       /* 去掉預設三角形 */
  padding: 8px 14px; border-radius: 8px; font-size: 14px; user-select: none;
  background: transparent; color: var(--text-soft); border: 1px solid var(--line);
}
details.menu > summary::-webkit-details-marker { display: none; }
details.menu > summary:hover,
details.menu[open] > summary { border-color: var(--brand); color: var(--brand); }
details.menu .menu-list {
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 0;
  display: flex; flex-direction: column; gap: 6px; min-width: 210px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px; box-shadow: var(--shadow);
}
details.menu .menu-list button { width: 100%; text-align: left; white-space: nowrap; line-height: 1.35; }
/* 選單按鈕第二行：灰字說明用途，讓維護人員一眼看懂 */
details.menu .menu-list button small { display: block; margin-top: 2px; font-size: 12px; font-weight: normal; color: var(--text-soft); }
input, select, textarea {
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
  background: var(--input); color: var(--text); font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
input.short { width: 80px; }
label { font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }

/* ---------- 白色卡片 ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.panel-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }

/* ---------- 登入畫面 ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login.single { grid-template-columns: 1fr; place-items: center; }
.login-brand {
  background: linear-gradient(150deg, #0f3a2a 0%, #1d7a55 60%, #6bb38a 100%);
  color: #f1f8f3; padding: 56px; display: flex; flex-direction: column; justify-content: center;
}
.login-brand .leaf { font-size: 44px; }
.login-brand h1 { font-size: 32px; line-height: 1.35; margin: 12px 0; }
.login-brand p { opacity: .9; max-width: 440px; line-height: 1.7; }
.login-brand li { margin: 6px 0; opacity: .9; }
.login-box { width: 100%; max-width: 380px; margin: auto; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.login-box label { flex-direction: column; align-items: stretch; }

/* ---------- 登入後：左側選單＋右側內容 ---------- */
.layout { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--brand-deep);
  color: #dbe8e0;
  padding: 18px 12px;
  display: flex; flex-direction: column; gap: 14px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.side-brand { display: flex; flex-direction: column; gap: 10px; padding: 0 8px 14px; border-bottom: 1px solid rgba(255,255,255,.12); }
.side-brand img { max-width: 100%; max-height: 54px; object-fit: contain; background: #fff; border-radius: 8px; padding: 6px; align-self: flex-start; }
.side-brand b { display: block; font-size: 15px; color: #fff; }
.side-brand small { color: rgba(255,255,255,.6); }
#sideNav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-group { font-size: 12px; color: rgba(255,255,255,.5); margin: 12px 10px 4px; letter-spacing: 1px; }
#sideNav button {
  background: transparent; color: #dbe8e0; text-align: left; border-radius: 8px; padding: 9px 12px;
  display: flex; gap: 10px; align-items: center;
}
#sideNav button:hover { background: rgba(255,255,255,.08); filter: none; }
#sideNav button.active { background: rgba(255,255,255,.16); color: #fff; font-weight: bold; }
.side-foot { font-size: 12px; color: rgba(255,255,255,.6); padding: 10px 8px 0; border-top: 1px solid rgba(255,255,255,.12); }

.main { padding: 18px 24px 40px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
/* 系統版號徽章 */
.ver-badge { font-size: 12px; font-weight: 600; letter-spacing: .5px; color: var(--text-soft);
  background: var(--brand-soft); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.ver-badge.clickable { cursor: pointer; }
.ver-badge.clickable:hover { border-color: var(--brand); color: var(--brand); }

/* 平台總管理進入公司查看時的提示條 */
.viewing-bar { background: var(--brand-soft); border: 1px solid var(--brand); border-radius: 10px; padding: 8px 12px; margin-bottom: 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* 工具列：一排放不下就換行 */
.toolbar, .btn-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 14px; }
.toolbar .note { margin: 0; }
.pager { justify-content: center; margin: 12px 0 0; }
.btn-row { margin: 16px 0 0; }
.spacer { flex: 1; }

/* ---------- 盤查總覽 ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); border-top: 3px solid var(--brand); }
.kpi .label { color: var(--text-soft); font-size: 13px; }
.kpi .value { font-size: 24px; font-weight: bold; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.kpi .unit { font-size: 12px; color: var(--text-soft); font-weight: normal; }
.kpi .delta { font-size: 12px; }
.down { color: var(--green-ok); }   /* 排放減少是好事 */
.up { color: var(--red); }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }
.chart-box { position: relative; height: 300px; }
/* 各類別明細：卡片式排列，每張卡片一個小圓餅＋數值表 */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.cat-card { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.cat-card h3 { margin: 0 0 8px; font-size: 15px; font-weight: 600; }
.cat-pie { position: relative; height: 200px; margin-bottom: 8px; }

/* 表格裡的小長條（占比） */
.bar { height: 8px; border-radius: 4px; background: var(--brand); min-width: 2px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }

/* ---------- 排放填報 ---------- */
.cat-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.cat-tabs button { background: var(--panel); color: var(--text-soft); border: 1px solid var(--line); }
.cat-tabs button.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.cat-tabs small { opacity: .8; margin-left: 4px; }
/* 子項目分頁：接在類別分頁下面，往上靠一點、字小一點，看起來是第二層 */
.cat-tabs.sub { margin-top: -6px; margin-bottom: 12px; padding-left: 10px; }
.cat-tabs.sub button { font-size: 13px; padding: 4px 10px; }
tr.void td { color: var(--text-soft); text-decoration: line-through; }
tr.void td:last-child { text-decoration: none; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--brand-soft); color: var(--brand); }
.tag.gray { background: var(--line); color: var(--text-soft); }

/* ---------- 對話框 ---------- */
dialog {
  border: 0; border-radius: 14px; padding: 22px; width: min(760px, 94vw);
  background: var(--panel); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(10, 30, 20, .45); }
.method { display: flex; gap: 18px; flex-wrap: wrap; margin: 14px 0 6px; padding: 10px 12px; background: var(--brand-soft); border-radius: 10px; }
.helper { background: var(--bg); border-radius: 8px; padding: 8px 10px; font-size: 13px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
/* 類別三、四明細欄位（起訖地、距離、重量…） */
.detail-box { background: var(--bg); border-radius: 8px; padding: 10px 12px; margin: 8px 0; font-size: 14px; }
.detail-box .form-grid { margin-top: 8px; }
.preview { margin-top: 14px; padding: 12px 14px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); font-size: 16px; font-weight: bold; }

/* ---------- 表單：自動排成多欄 ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-top: 10px; }
.form-grid label { flex-direction: column; align-items: stretch; }
.form-grid .wide { grid-column: 1 / -1; }

/* Logo 上傳區 */
.logo-row { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.logo-box { width: 200px; height: 100px; border: 1px dashed var(--line); border-radius: 10px; display: flex; align-items: center; justify-content: center; color: #889; font-size: 13px; background: #fff; }
.logo-box img { max-width: 90%; max-height: 90%; object-fit: contain; }

/* 首頁風格色塊 */
.theme-pick { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.swatch { border: 3px solid transparent; }
.swatch.selected { border-color: var(--text); }
.swatch[data-theme-color="green"]  { background: #1d7a55; }
.swatch[data-theme-color="teal"]   { background: #13817f; }
.swatch[data-theme-color="blue"]   { background: #2a6fc4; }
.swatch[data-theme-color="orange"] { background: #c95f1c; }
.swatch[data-theme-color="purple"] { background: #7350b8; }

.mini-logo { height: 28px; max-width: 90px; object-fit: contain; vertical-align: middle; background: #fff; border-radius: 4px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; vertical-align: middle; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 160px; max-width: 320px; }
th { color: var(--text-soft); font-weight: normal; background: var(--bg); }
tbody tr:hover td { background: var(--brand-soft); }
/* 變更紀錄小表格：字小一點，最後一欄（原因）允許換行 */
.mini-table { font-size: 12px; margin-top: 6px; }
.mini-table th, .mini-table td { padding: 5px 8px; }
.mini-table td:last-child { white-space: normal; max-width: 220px; }
td .small + .small { margin-left: 4px; }
.ok { color: var(--green-ok); }
.bad { color: var(--red); }

/* ---------- 手機與窄螢幕：選單改到上方 ---------- */
@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; }
  .login-brand { padding: 32px 24px; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  #sideNav { flex-direction: row; flex-wrap: wrap; }
  .nav-group { display: none; }
  .main { padding: 14px; }
  .grid2 { grid-template-columns: 1fr; }
}

/* ---------- 第三階段：盤查報告、官方係數維護 ---------- */
.panel.warn { border-color: var(--amber); background: color-mix(in srgb, var(--amber) 8%, var(--panel)); }
.panel.warn ul { margin: 6px 0 0; padding-left: 20px; }
.img-line { display: flex; align-items: center; gap: 10px; }
.img-line img, .bound-item img { max-height: 90px; max-width: 220px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.bound-item { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.bound-item input { flex: 1; }
.steps { margin: 0 0 12px; padding-left: 22px; color: var(--text-soft); line-height: 1.8; }
details.quality { margin-top: 12px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
details.quality summary { cursor: pointer; color: var(--brand); font-weight: bold; }
dialog.wide-dialog { width: min(1080px, 96vw); }
#rMatTable select { padding: 4px 6px; }
#rCollect input { width: 100%; min-width: 320px; }
.tag.warn { background: color-mix(in srgb, var(--amber) 18%, transparent); color: var(--amber); }
.tag.okk { background: color-mix(in srgb, var(--green-ok) 15%, transparent); color: var(--green-ok); }
.tag.bad { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
button:disabled { opacity: .45; cursor: not-allowed; filter: none; }

/* ---------- 第四階段：供應商填報頁 ---------- */
.portal { max-width: 920px; margin: 0 auto; padding: 24px 16px 60px; }
.portal-head { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.portal-head img { max-height: 56px; max-width: 160px; object-fit: contain; background: #fff; border-radius: 8px; padding: 6px; }
.portal-head .theme-btn { margin-left: auto; }
#pProducts input { width: 100%; min-width: 70px; }
.link-box { font-size: 12px; color: var(--text-soft); word-break: break-all; }

/* 查證管理：自我檢查清單 */
details.check { border-bottom: 1px solid var(--line); padding: 8px 0; }
details.check summary { cursor: pointer; }
details.check ul { margin: 6px 0 4px; padding-left: 22px; font-size: 13px; }
details.check li { margin: 2px 0; }

/* ===== 簽核流程（第九階段） ===== */
/* 待審核、被退回的資料：整列淡淡的底色 */
tr.pending td { background: color-mix(in srgb, var(--amber) 7%, transparent); }
tr.rejected td { background: color-mix(in srgb, var(--red) 6%, transparent); }
.review-bar { border-color: var(--amber); display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
/* 簽核設定的開關：勾選框在左，說明在右 */
.switch-row { display: flex; gap: 10px; align-items: flex-start; margin: 10px 0; cursor: pointer; }
.switch-row input { margin-top: 4px; }

/* PDF 原文：保留換行，太長時可以捲動 */
.pdf-lines { max-height: 300px; overflow: auto; white-space: pre-wrap; font-size: 12px; background: var(--bg); padding: 8px; border-radius: 6px; }

/* ===== 使用手冊 ===== */
/* 每一章是一個可以展開、收起的區塊 */
.guide details > summary { cursor: pointer; font-size: 17px; font-weight: 600; list-style: none; }
.guide details > summary::before { content: "▸ "; color: var(--brand); }
.guide details[open] > summary::before { content: "▾ "; }
.guide details[open] > summary { margin-bottom: 10px; }
.guide li { margin: 4px 0; line-height: 1.7; }
.guide h3 { margin: 16px 0 6px; font-size: 15px; }
/* 手冊表格的字比較多：自動換行，不用左右捲動 */
.guide td, .guide th { white-space: normal; }

/* ---------- 工作行事曆、問題反映的燈號 ---------- */
/* 小圓燈：灰＝沒有、綠＝沒有待處理、黃＝有但未過期、紅＝緊急 */
.lamp { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #9aa5a0; vertical-align: middle; flex: none; }
#sideNav .lamp { margin-left: auto; }
.lamp.green { background: #2fbf71; }
.lamp.yellow { background: #f2b705; }
.lamp.red { background: #e5484d; }
.lamp.blink { animation: lampBlink 1s ease-in-out infinite; }
@keyframes lampBlink {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 currentColor; }
  50% { opacity: .35; }
}

.cal-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cal-nav h2 { margin: 0 0 0 6px; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 8px 0 0 8px; }
.seg button:last-child { border-radius: 0 8px 8px 0; }

/* 月曆格子：一週 7 欄 */
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.cal-head { padding: 6px; text-align: center; font-size: 12px; color: var(--text-soft); background: var(--bg); border-bottom: 1px solid var(--line); }
.cal-day { min-height: 92px; padding: 4px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); cursor: pointer; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-day:nth-child(7n) { border-right: none; }
.cal-day.tall { min-height: 260px; }
.cal-day.other { opacity: .45; }
.cal-day:hover { background: var(--brand-soft); }
.cal-day.today .cal-num { background: var(--brand); color: #fff; border-radius: 10px; padding: 0 7px; }
.cal-num { font-size: 12px; align-self: flex-start; }
.cal-ev { display: block; width: 100%; text-align: left; font-size: 12px; padding: 2px 6px; border-radius: 4px; border: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.cal-ev.yellow { background: color-mix(in srgb, #f2b705 25%, transparent); }
.cal-ev.red { background: color-mix(in srgb, #e5484d 22%, transparent); }
.cal-ev.done { background: var(--line); color: var(--text-soft); text-decoration: line-through; }
.cal-grid.week .cal-ev { white-space: normal; }
@media (max-width: 860px) { .cal-day { min-height: 64px; } .cal-ev { font-size: 11px; padding: 1px 3px; } }

/* 問題反映的對話串 */
.issue-thread { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; max-height: 46vh; overflow-y: auto; }
.issue-thread .msg { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; max-width: 85%; }
.issue-thread .msg small { margin-left: 8px; color: var(--text-soft); }
.issue-thread .msg p { margin: 6px 0 0; white-space: pre-wrap; }
.issue-thread .msg img { max-width: 100%; max-height: 260px; margin-top: 8px; border-radius: 6px; }
.issue-thread .msg.handler { align-self: flex-end; background: var(--brand-soft); }
.charge-box { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; padding: 8px 12px; border: 1px dashed var(--line); border-radius: 8px; }
#isReplyBox > label { display: flex; flex-direction: column; gap: 4px; }
#isReply { width: 100%; }

/* 合約與報價：附件清單 */
.mail-file { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.money-input { text-align: right; }
