:root {
  --bg: #f4f6f9; --card: #fff; --line: #e2e6ec; --ink: #1f2933; --muted: #6b7682;
  --brand: #1f6feb; --brand-d: #1755c0;
  --ok: #1a9c5b; --warn: #d98e00; --danger: #d64545;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 14px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI","Microsoft JhengHei",system-ui,sans-serif; background: var(--bg); color: var(--ink); }
.loading { padding: 60px; text-align: center; color: var(--muted); }

.topbar { display: flex; align-items: center; gap: 24px; background: #fff; border-bottom: 1px solid var(--line); padding: 0 20px; height: 56px; position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; font-size: 18px; cursor: pointer; }
.brand small { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 4px; }
#topnav { margin-left: auto; display: flex; gap: 10px; align-items: center; }
#topnav a { color: var(--ink); text-decoration: none; padding: 6px 10px; border-radius: 6px; font-size: 14px; }
#topnav a:hover { background: #eef1f5; }
#topnav a.active { color: var(--brand); background: #e8f0ff; font-weight: 600; }
.nav-user { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); margin-left: 6px; padding-left: 12px; border-left: 1px solid var(--line); }

#app { max-width: 1180px; margin: 22px auto; padding: 0 18px 60px; }

/* 登入 */
.login-wrap { min-height: 70vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 360px; text-align: center; padding: 32px 28px; }
.login-card h1 { font-size: 22px; margin: 6px 0 2px; }
.login-card .login-logo { font-size: 44px; }
.login-card form { margin-top: 18px; text-align: left; }
.login-card .field { margin-bottom: 12px; }
.login-card code { background: #eef1f5; padding: 1px 6px; border-radius: 4px; }
.login-ver { color: var(--muted); font-size: 12px; margin-top: 20px; }

.btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 14px; border-radius: 7px; cursor: pointer; transition: .12s; }
.btn:hover { border-color: #c3ccd6; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-d); }
.btn.danger { color: var(--danger); border-color: #f0c4c4; }
.btn.danger:hover { background: #fdf0f0; }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-head .spacer { margin-left: auto; }

table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
table.list th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.list tr:hover td { background: #f8fafc; }
table.list tr { cursor: pointer; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 40px; }

.tag { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 20px; background: #eef1f5; color: var(--muted); }
.tag.stage-inquiry   { background: #eef1f5; color: var(--muted); }
.tag.stage-evaluated { background: #e8f0ff; color: var(--brand); }
.tag.stage-quoted    { background: #fff5e0; color: var(--warn); }
.tag.stage-awarded   { background: #e4f6ec; color: var(--ok); }
.tag.stage-closed    { background: #f0f0f0; color: #555; }
.tag.stage-rejected  { background: #fbeaea; color: var(--danger); }

.tag.decision-accept      { background: #e4f6ec; color: var(--ok); font-weight: 600; }
.tag.decision-conditional { background: #fff5e0; color: var(--warn); font-weight: 600; }
.tag.decision-reject      { background: #fbeaea; color: var(--danger); font-weight: 600; }

.tag.risk-low  { background: #e4f6ec; color: var(--ok); }
.tag.risk-mid  { background: #fff5e0; color: var(--warn); }
.tag.risk-high { background: #fbeaea; color: var(--danger); }

/* 表單 */
.grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(220px,1fr)); gap: 12px 16px; }
.grid.tight { gap: 8px 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea { width: 100%; font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.field input:focus, .field textarea:focus, .field select:focus { outline: 2px solid #cfe0ff; border-color: var(--brand); }
.field textarea { min-height: 60px; resize: vertical; }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* section */
.section-h { font-weight: 700; font-size: 15px; margin: 6px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); color: var(--brand); display: flex; align-items: center; gap: 8px; }

/* 評估表 */
.risk-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.risk-table th, .risk-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.risk-table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; background: #fafbfc; }
.risk-table td.desc { min-width: 150px; }
.risk-table td.opts label { display: inline-flex; align-items: center; gap: 4px; margin-right: 14px; font-size: 13px; cursor: pointer; }
.risk-table td.opts input[type=radio] { accent-color: var(--brand); }
.risk-table td.score { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; width: 60px; }

/* 決策卡 */
.decision-card { padding: 22px; border-radius: 12px; text-align: center; margin-top: 10px; border: 2px solid; }
.decision-card.accept { background: #ecfaf1; border-color: var(--ok); }
.decision-card.conditional { background: #fff8e6; border-color: var(--warn); }
.decision-card.reject { background: #fdecec; border-color: var(--danger); }
.decision-card .badge { font-size: 34px; font-weight: 800; letter-spacing: 2px; }
.decision-card.accept .badge { color: var(--ok); }
.decision-card.conditional .badge { color: var(--warn); }
.decision-card.reject .badge { color: var(--danger); }
.decision-card .reasons { margin-top: 8px; color: var(--ink); font-size: 14px; line-height: 1.6; }

/* KPI */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit,minmax(140px,1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: #fafbfc; border: 1px solid var(--line); padding: 10px 14px; border-radius: 8px; }
.kpi .k { font-size: 12px; color: var(--muted); }
.kpi .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .v.ok { color: var(--ok); }
.kpi .v.warn { color: var(--warn); }
.kpi .v.danger { color: var(--danger); }

/* Toast */
#toast { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #2b3440; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); font-size: 14px; animation: slidein .2s; }
.toast.ok { background: var(--ok); } .toast.err { background: var(--danger); }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } }

.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }
.right { text-align: right; }

/* Stage 進度條 (案件工作台頂端) */
.stepper { display: flex; gap: 4px; margin: 4px 0 20px; }
.stepper .step { flex: 1; padding: 8px 6px; text-align: center; background: #eef1f5; color: var(--muted); font-size: 13px; border-radius: 6px; position: relative; }
.stepper .step.active { background: var(--brand); color: #fff; font-weight: 600; }
.stepper .step.done { background: #e4f6ec; color: var(--ok); }
.stepper .step .n { display: inline-block; width: 20px; height: 20px; line-height: 20px; background: rgba(255,255,255,.4); border-radius: 50%; margin-right: 6px; font-size: 12px; font-weight: 600; }
.stepper .step.done .n { background: var(--ok); color: #fff; }
.stepper .step:not(.active):not(.done) .n { background: #d5dae0; color: #fff; }

/* Sub-tab 導覽 */
.subnav { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.subnav a { padding: 10px 16px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; font-size: 14px; }
.subnav a:hover { color: var(--ink); }
.subnav a.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* 報價 BOM */
.bom-sec { border: 1px solid var(--line); border-radius: 9px; margin-bottom: 14px; overflow: hidden; }
.bom-sec-head { display: flex; align-items: center; gap: 10px; background: #f0f4fa; padding: 8px 12px; }
.bom-sec-head .code { font-weight: 700; color: var(--brand); padding: 2px 8px; background: #fff; border-radius: 4px; }
.bom-sec-head .sec-title { font-weight: 600; border: 1px solid transparent; background: transparent; padding: 4px 6px; border-radius: 5px; min-width: 200px; font: inherit; }
.bom-sec-head .sec-title:hover { border-color: var(--line); background: #fff; }
.bom-sec-head .sec-sub { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }

table.bom { width: 100%; border-collapse: collapse; }
table.bom th { font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; background: #fafbfc; }
table.bom td { padding: 3px 5px; border-bottom: 1px solid #eef1f4; vertical-align: middle; }
table.bom input { width: 100%; font: inherit; border: 1px solid transparent; padding: 5px 6px; border-radius: 5px; background: transparent; }
table.bom input:hover { border-color: var(--line); }
table.bom input:focus { outline: none; border-color: var(--brand); background: #fff; box-shadow: 0 0 0 2px #cfe0ff; }
table.bom td.num, table.bom td.num input { text-align: right; }
table.bom td.total { font-variant-numeric: tabular-nums; text-align: right; padding-right: 8px; white-space: nowrap; }
.col-name  { width: 26%; }
.col-spec  { width: 18%; }
.col-unit  { width: 60px; }
.col-qty   { width: 72px; }
.col-price { width: 96px; }
.col-total { width: 110px; }
.col-act   { width: 34px; }
.row-del { color: var(--danger); cursor: pointer; border: none; background: none; font-size: 16px; line-height: 1; }

/* Checklist */
.check-list { display: flex; flex-direction: column; gap: 4px; }
.check-item { display: flex; align-items: flex-start; gap: 10px; padding: 8px 10px; border-bottom: 1px solid #f0f2f5; font-size: 14px; }
.check-item input[type=checkbox] { margin-top: 3px; transform: scale(1.2); accent-color: var(--brand); }
.check-item.done { background: #f7fbf8; }
.check-item.done .txt { color: var(--muted); text-decoration: line-through; }
.check-item .id-tag { font-size: 11px; color: var(--muted); font-weight: 600; min-width: 40px; padding-top: 3px; }

.sign-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 12px; }
.sign-box { border: 1px dashed var(--line); border-radius: 8px; padding: 12px; }
.sign-box .role { font-size: 12px; color: var(--muted); }
.sign-box .name { font-weight: 700; font-size: 16px; margin: 4px 0; }
.sign-box .at { font-size: 12px; color: var(--muted); }
.sign-box.signed { border-style: solid; border-color: var(--ok); background: #f7fbf8; }

/* 警報 */
.alert-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; }
.alert-normal { background: #d5dae0; }
.alert-yellow { background: #ffd54f; }
.alert-orange { background: #ff9800; }
.alert-red    { background: #f44336; }

/* 里程碑 */
.ms-list { display: flex; flex-direction: column; gap: 8px; }
.ms-item { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; display: grid; grid-template-columns: 90px 1fr 130px 120px 120px 100px; gap: 10px; align-items: center; }
.ms-item .ms-code { font-weight: 700; color: var(--brand); font-size: 12px; }
.ms-item .ms-title { font-weight: 500; }
.ms-item.done { background: #f7fbf8; border-color: var(--ok); }
.ms-status { font-size: 12px; padding: 2px 8px; border-radius: 10px; text-align: center; }
.ms-status.pending  { background: #eef1f5; color: var(--muted); }
.ms-status.billed   { background: #fff5e0; color: var(--warn); }
.ms-status.received { background: #e4f6ec; color: var(--ok); }
.ms-status.overdue  { background: #fbeaea; color: var(--danger); }

/* 用於報表/列印 */
@media print {
  .topbar, .btn, .no-print { display: none !important; }
  #app { max-width: none; margin: 0; padding: 10mm; }
  .card { border: 1px solid #333; box-shadow: none; break-inside: avoid; }
}
