:root {
  --navy: #1c306d;
  --navy-2: #2a4590;
  --navy-soft: #e8ecf6;
  --orange: #d54e23;
  --orange-soft: #fbe9e2;
  --ink: #1f2328;
  --ink-2: #444;
  --muted: #777;
  --line: #e2e2e2;
  --bg: #f4f5f7;
  --card: #fff;
  --ok: #2e7d32;
  --ok-soft: #e7f4e8;
  --warn: #a86400;
  --warn-soft: #fff4dc;
  --err: #c0262d;
  --err-soft: #fde8e8;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Roboto, 'Noto Sans TC', 'Microsoft JhengHei', 'PingFang TC', sans-serif;
  color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.55;
}
button, input, select { font: inherit; }

/* 頂部：仿官網白底＋右側黑色斜切 */
.topbar {
  display: flex; align-items: stretch; justify-content: space-between;
  background: #fff; border-bottom: 3px solid var(--navy); min-height: 72px; position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 18px; padding: 10px 24px; }
.logo { height: 44px; width: auto; }
.brand-title { display: flex; flex-direction: column; border-left: 1px solid var(--line); padding-left: 18px; }
.brand-title strong { font-size: 19px; color: var(--navy); letter-spacing: .02em; }
.brand-title span { font-size: 13px; color: var(--muted); }
.topbar-side {
  display: flex; align-items: center; background: #111; color: #fff; padding: 0 28px 0 56px;
  clip-path: polygon(36px 0, 100% 0, 100% 100%, 0 100%); font-size: 13px;
}
.lock { opacity: .9; }

/* 步驟頁籤 */
.steps { display: flex; gap: 4px; padding: 14px 24px 0; max-width: 1480px; margin: 0 auto; flex-wrap: wrap; }
.steps button {
  border: 1px solid var(--line); border-bottom: none; background: #e9eaee; color: var(--ink-2);
  padding: 10px 18px; border-radius: 8px 8px 0 0; cursor: pointer; display: flex; align-items: center; gap: 8px;
}
.steps button b {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: #c9ccd4; color: #fff; font-size: 12px;
}
.steps button.active { background: #fff; color: var(--navy); font-weight: 700; border-color: var(--line); }
.steps button.active b { background: var(--orange); }
.steps button:disabled { opacity: .45; cursor: not-allowed; }
.steps em { font-style: normal; font-size: 12px; padding: 0 7px; border-radius: 10px; background: var(--err); color: #fff; }
.steps em:empty { display: none; }
.steps em.ok { background: var(--ok); }

main { max-width: 1480px; margin: 0 auto; padding: 0 24px 60px; }
.tab { display: none; }
.tab.active { display: block; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; margin-top: 16px; }
.tab > .card:first-child { margin-top: 0; border-top-left-radius: 0; }
h2 { font-size: 19px; margin: 0 0 6px; color: var(--navy); }
h3 { font-size: 16px; margin: 0 0 8px; color: var(--navy); }
h2.red { color: var(--err); }
.muted { color: var(--muted); margin: 4px 0 12px; }
.small { font-size: 13px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.grow { flex: 1; }

/* 上傳 */
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 38px 20px; margin: 14px 0;
  border: 2px dashed #b9c1d8; border-radius: var(--radius); background: #fafbfe; cursor: pointer; text-align: center; transition: .15s;
}
.drop:hover, .drop.over { border-color: var(--navy); background: var(--navy-soft); }
.drop-icon { font-size: 30px; color: var(--navy); }
.note { padding: 10px 14px; background: var(--navy-soft); border-left: 4px solid var(--navy); border-radius: 6px; margin: 8px 0; font-size: 14px; }
.detect { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; margin: 12px 0; }
.det { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.det b { display: block; color: var(--navy); }
.det.ok { border-color: #b8dcbb; background: var(--ok-soft); }
.det.miss { border-color: #f0c9c9; background: var(--err-soft); }
.det.saved { border-color: #c9d3ec; background: var(--navy-soft); }
.det span { color: var(--ink-2); font-size: 13px; }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; }
.how ol { margin: 6px 0 0; padding-left: 22px; }
.how li { margin: 4px 0; }

/* 按鈕 */
.btn { border: 1px solid var(--navy); background: var(--navy); color: #fff; padding: 8px 16px; border-radius: 6px; cursor: pointer; font-weight: 500; }
.btn:hover { background: var(--navy-2); }
.btn.accent { background: var(--orange); border-color: var(--orange); }
.btn.accent:hover { background: #bd421b; }
.btn.ghost { background: #fff; color: var(--navy); }
.btn.ghost:hover { background: var(--navy-soft); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.sm { padding: 3px 10px; font-size: 13px; }
.btn.ghost.danger { color: var(--err); border-color: #e6b3b3; }
.btn.ghost.danger:hover { background: var(--err-soft); }
label.btn { display: inline-flex; align-items: center; }
.hist-q { min-width: 230px; }
.grid tr.row-sel td { background: var(--navy-soft); }
#hist-detail .card:first-child { border-top: 3px solid var(--orange); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: none; background: #fff; padding: 6px 14px; cursor: pointer; color: var(--ink-2); border-right: 1px solid var(--line); }
.seg button:last-child { border-right: none; }
.seg button.active { background: var(--navy); color: #fff; }

/* 工具列與 KPI */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; }
.toolbar label { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-2); }
select, input[type=date], input[type=number], input:not([type]) {
  border: 1px solid #cfd3db; border-radius: 6px; padding: 6px 8px; background: #fff; color: var(--ink);
}
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 14px; }
.kpi { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; background: #fafbfc; }
.kpi .v { font-size: 26px; font-weight: 700; color: var(--navy); font-family: Roboto, sans-serif; line-height: 1.2; }
.kpi .l { font-size: 13px; color: var(--muted); }
.kpi.ok .v { color: var(--ok); } .kpi.warn .v { color: var(--warn); } .kpi.err .v { color: var(--err); }
.small-kpis .kpi .v { font-size: 22px; }

/* 表格 */
.table-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: 8px; margin-top: 10px; }
table.grid { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.grid th { position: sticky; top: 0; background: var(--navy); color: #fff; font-weight: 500; text-align: left; padding: 8px 8px; white-space: nowrap; z-index: 1; }
.grid td { padding: 7px 8px; border-bottom: 1px solid #eef0f3; vertical-align: top; }
.grid tr:hover td { background: #f7f9fd; }
.grid td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.grid td.nowrap { white-space: nowrap; }
.grid tr.mac-head td { background: var(--navy-soft); color: var(--navy); font-weight: 700; border-top: 2px solid #c9d3ec; }
.grid tr.row-error td { background: #fff6f6; }
.grid tr.row-warn td { background: #fffbf0; }
.grid tr.reason-row td { background: #fbfbfc; color: var(--ink-2); font-size: 13px; border-bottom: 1px solid var(--line); }
.grid tr.sched-row { cursor: pointer; }
.grid input[type=number] { width: 84px; padding: 3px 6px; }
.sched { font-size: 13px; }
.sched th, .sched td { padding: 6px 6px; }
.sched td.mat { min-width: 120px; max-width: 170px; }
.sched th.ck-h { text-align: center; width: 38px; }
.grid select { padding: 3px 4px; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; white-space: nowrap; font-weight: 500; }
.chip.error { background: var(--err-soft); color: var(--err); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.info { background: #eef1f5; color: #555; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.fc { background: #eef1f8; color: var(--navy); }
.ck { font-weight: 700; text-align: center; }
.ck.ok { color: var(--ok); } .ck.warn { color: var(--warn); } .ck.error { color: var(--err); }
.red { color: var(--err); }

/* 甘特圖 */
.gantt { margin-top: 10px; overflow-x: auto; }
.g-grid { min-width: 860px; }
.g-head, .g-row { display: grid; grid-template-columns: 74px 1fr; }
.g-head .g-days { display: grid; border-bottom: 1px solid var(--line); }
.g-head .g-days div { font-size: 12.5px; color: var(--ink-2); padding: 4px 6px; border-left: 1px solid var(--line); text-align: center; }
.g-head .g-days div.we { background: #f5f5f5; color: #999; }
.g-row { border-bottom: 1px solid #f0f1f4; min-height: 34px; }
.g-mac { font-size: 13px; font-weight: 700; color: var(--navy); padding: 6px 4px; display: flex; align-items: center; gap: 4px; }
.g-mac small { font-weight: 400; color: var(--muted); font-size: 11px; }
.g-track { position: relative; background-image: linear-gradient(to right, #eef0f3 1px, transparent 1px); }
.g-idle { position: absolute; inset: 0; display: flex; align-items: center; padding-left: 8px; font-size: 12px; color: #aab; }
.bar {
  position: absolute; top: 5px; height: 24px; border-radius: 4px; background: var(--navy); color: #fff; font-size: 12px;
  padding: 3px 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; cursor: pointer; border: 1px solid rgba(0,0,0,.08);
}
.bar.forecast { background: repeating-linear-gradient(45deg, #6b7fb5, #6b7fb5 6px, #7c8fc3 6px, #7c8fc3 12px); }
.bar.error { background: var(--err); }
.bar.warn { box-shadow: inset 0 -4px 0 #f0a400; }
.bar.cont-l { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.bar.cont-r { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.legend { font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.lg { display: inline-block; width: 16px; height: 11px; border-radius: 2px; margin-left: 8px; }
.lg.order { background: var(--navy); }
.lg.forecast { background: repeating-linear-gradient(45deg, #6b7fb5, #6b7fb5 3px, #7c8fc3 3px, #7c8fc3 6px); }
.lg.bad { background: var(--err); }

/* 設定 */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px 18px; margin-top: 10px; }
.form-grid label, .field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--ink-2); }
.wd { display: flex; gap: 4px; flex-wrap: wrap; }
.wd label { flex-direction: row; align-items: center; gap: 3px; border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; cursor: pointer; }
.mac-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin-top: 12px; }
.mac { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 13px; display: flex; flex-direction: column; gap: 8px; min-width: 0; overflow: hidden; }
.mac.off { background: #f3f3f3; }
.mac.off .mrow, .mac.off .mcol { opacity: .5; }
.mac .t { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 700; color: var(--navy); font-size: 14px; padding-bottom: 6px; border-bottom: 1px solid #eef0f3; }
.mac .t .en { display: inline-flex; align-items: center; gap: 4px; font-weight: 400; color: var(--ink-2); font-size: 13px; cursor: pointer; white-space: nowrap; }
.mac .mrow { display: flex; justify-content: space-between; align-items: center; gap: 6px; color: var(--ink-2); }
.mac .mrow .hr { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.mac .mcol { display: flex; flex-direction: column; gap: 4px; color: var(--ink-2); min-width: 0; }
.mac .mcol small { color: var(--muted); font-size: 11px; }
.mac select { padding: 3px 4px; }
.mac input[type=date] { width: 100%; min-width: 0; max-width: 100%; padding: 4px 6px; font-size: 13px; box-sizing: border-box; }

dialog { border: none; border-radius: 12px; padding: 22px 24px; width: min(420px, 92vw); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(16, 24, 48, .45); }
dialog form { display: grid; gap: 10px; }
dialog label { display: grid; gap: 4px; font-size: 14px; color: var(--ink-2); }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #111; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 14px; z-index: 50; box-shadow: 0 4px 20px rgba(0,0,0,.25); }

#print-area { display: none; }

@media (max-width: 720px) {
  .topbar { flex-direction: column; }
  .topbar-side { clip-path: none; padding: 8px 16px; }
  .brand { padding: 10px 16px; }
  .logo { height: 34px; }
  main, .steps { padding-left: 12px; padding-right: 12px; }
}

/* 列印：A4 橫式，只印排程表 */
@page { size: A4 landscape; margin: 9mm; }
@media print {
  body { background: #fff; font-size: 10px; }
  .topbar, .steps, main, dialog, .toast { display: none !important; }
  #print-area { display: block; }
  .p-head { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 2px solid var(--navy); padding-bottom: 4px; margin-bottom: 6px; }
  .p-head img { height: 30px; }
  .p-head h1 { font-size: 17px; margin: 0; color: var(--navy); }
  .p-meta { font-size: 10px; color: #333; text-align: right; }
  .p-table { width: 100%; border-collapse: collapse; font-size: 9px; }
  .p-table th { background: var(--navy) !important; color: #fff !important; padding: 3px 3px; border: 1px solid #999; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .p-table td { border: 1px solid #bbb; padding: 2px 3px; vertical-align: top; }
  .p-table td.num { text-align: right; }
  .p-table th:nth-child(16) { width: 20%; }
  .p-table th:last-child { width: 9%; }
  .p-table tr.mac-head td { background: #e8ecf6 !important; font-weight: 700; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .p-table tr.row-error td { background: #fde8e8 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .p-table tr { page-break-inside: avoid; }
  .p-table thead { display: table-header-group; }
  .p-foot { margin-top: 6px; font-size: 9px; color: #444; display: flex; justify-content: space-between; }
  .p-sign { margin-top: 10px; display: flex; gap: 40px; font-size: 10px; }
}
