/* =========================================================
   顏色統一放這裡，方便日後修改
   風格：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); }
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; }

/* 平台總管理進入公司查看時的提示條 */
.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; }
.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; }

/* 表格裡的小長條（占比） */
.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; }
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; }
.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); }
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; }
}
