: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; }
.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); }

/* 500 家族標準右上連結(↩ 回HRM | 🗂 系統列表)— 標準導航 form B */
.sys-links { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; padding-left: 14px; border-left: 1px solid var(--line); white-space: nowrap; }
.sys-links a { text-decoration: none; color: #666; }
.sys-links a:hover { text-decoration: underline; }
.sys-links a.apps { color: #0a66c2; font-weight: 600; }
.sys-links .sep { color: #ccc; }

/* 範本區 */
.tpl-block { border: 1px solid #cfe0ff; background: #f5f9ff; border-radius: 8px; padding: 10px 14px; }
.tpl-head { font-weight: 700; margin-bottom: 8px; }
.tpl-head .hint { font-weight: 400; }
.tpl-table { background: transparent; }
.tpl-table th { color: #666; font-weight: 600; text-align: left; }

#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; }

.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; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 20px; background: #eef1f5; color: var(--muted); }
.tag.draft { background: #fff5e0; color: var(--warn); }
.tag.sent { background: #e4f6ec; color: var(--ok); }
.empty { text-align: center; color: var(--muted); padding: 40px; }

/* 表單 */
.grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(220px,1fr)); gap: 12px 16px; }
.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); }

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

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

/* 單價建議下拉 */
.sug-wrap { position: relative; }
.sug { position: absolute; z-index: 50; top: 100%; left: 0; min-width: 360px; max-width: 520px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 300px; overflow-y: auto; }
.sug-item { padding: 7px 10px; cursor: pointer; border-bottom: 1px solid #f0f2f5; font-size: 13px; }
.sug-item:hover, .sug-item.active { background: #eef4ff; }
.sug-item .s-name { font-weight: 500; }
.sug-item .s-meta { color: var(--muted); font-size: 12px; margin-top: 2px; display: flex; gap: 10px; }
.sug-item .s-price { color: var(--brand); font-weight: 700; }

/* 合計區 */
.totals { margin-left: auto; width: 320px; }
.totals .row { display: flex; justify-content: space-between; padding: 6px 4px; font-variant-numeric: tabular-nums; }
.totals .row.grand { font-size: 20px; font-weight: 800; border-top: 2px solid var(--ink); margin-top: 4px; padding-top: 10px; }
.totals .label { color: var(--muted); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.hint { font-size: 12px; color: var(--muted); }

/* 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); }

/* 自動填價 */
.autofill-bar { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 4px 10px; background: #f0f6ff; border: 1px solid #cfe0ff; border-radius: 8px; }
.autofill-bar .af-opt { font-size: 13px; color: var(--ink); display: inline-flex; align-items: center; gap: 3px; }
.autofill-bar input[type=number] { font: inherit; border: 1px solid var(--line); border-radius: 5px; padding: 3px 5px; }
.af-report { background: #f3faf5; border: 1px solid #c8e8d3; border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px; }
.af-rules { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.af-tag { font-size: 12px; background: #fff; border: 1px solid #c8e8d3; color: var(--ok); padding: 2px 9px; border-radius: 20px; }
.rate-box { font-size: 13px; }
.rate-box table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.rate-box th, .rate-box td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.rate-box td.num { text-align: right; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 80; }
.modal { background: #fff; border-radius: 12px; padding: 22px; max-width: 760px; width: 92%; max-height: 86vh; overflow-y: auto; box-shadow: var(--shadow); }
