:root {
  --bg: #f4f6fa; --card: #fff; --ink: #1f2937; --muted: #6b7280;
  --line: #e5e7eb; --brand: #2563eb; --brand-d: #1d4ed8;
  --ok: #16a34a; --ok-bg: #d7f0d7; --warn: #d97706; --danger: #dc2626;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px; }
.loading { padding: 80px; text-align: center; color: var(--muted); }
a { color: var(--brand); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* Layout — 500 系列標準可縮放側欄 */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.shell.side-hidden { grid-template-columns: 0 1fr; }
.shell.side-hidden .side { transform: translateX(-100%); }
.side { background: #0f2540; color: #cfd8dc; overflow: hidden; transition: transform .2s; position: relative; display: flex; flex-direction: column; }
.side .brand { padding: 16px 16px 14px 60px; border-bottom: 1px solid #1c3557; }
.side .brand h1 { font-size: 16px; color: #fff; margin: 0; }
.side .brand .v { font-size: 11px; color: #8a9db4; margin-top: 2px; font-family: ui-monospace, Menlo, monospace; }
.side .backhrm { position: absolute; top: 16px; right: 12px; font-size: 12px; color: #4da3ff; text-decoration: none; }
.side nav { padding: 8px 0; flex: 1; overflow-y: auto; }
.side nav .grp { padding: 12px 20px 4px; font-size: 11px; color: #6f86a3; letter-spacing: 1px; }
.side nav a { display: block; padding: 8px 20px; color: #cfd8dc; font-size: 14px; border-left: 3px solid transparent; border-radius: 0; }
.side nav a:hover { background: #173458; color: #fff; }
.side nav a.active { background: #173458; color: #fff; border-left-color: #4da3ff; }
.side .who { padding: 12px 20px; border-top: 1px solid #1c3557; font-size: 12px; color: #8a9db4; }
.side .who button { margin-top: 8px; width: 100%; background: #173458; color: #cfd8dc; border: none; padding: 8px; border-radius: 8px; cursor: pointer; }
.main { padding: 22px 28px; overflow: auto; }
.shell.side-hidden .main { padding-left: 60px; }

/* ☰ 縮放 toggle + 遮罩 */
.side-toggle { position: fixed; top: 14px; left: 14px; z-index: 100; width: 36px; height: 36px; background: #0a66c2; color: #fff; border: none; border-radius: 6px; font-size: 18px; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.2); display: flex; align-items: center; justify-content: center; opacity: .85; }
.side-toggle:hover { background: #084d95; opacity: 1; }
.side-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 98; display: none; }
.shell.side-open .side-backdrop { display: block; }

/* 🗂 系統列表 + ↩回HRM 固定右上(每頁皆可見,本頁跳轉) */
.apps-link { position: fixed; top: 14px; right: 16px; z-index: 100; display: flex; gap: 8px; align-items: center; font-size: 12px; background: rgba(255,255,255,.92); padding: 6px 12px; border-radius: 6px; box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.apps-link a { text-decoration: none; }
.apps-link .sep { color: #ccc; }

h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 22px 0 10px; }

/* 手機:側欄改抽屜 */
@media (max-width: 768px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; top: 0; left: -240px; bottom: 0; width: 230px; z-index: 99; box-shadow: 2px 0 12px rgba(0,0,0,.3); transform: none; }
  .shell.side-open .side { left: 0; }
  .main, .shell.side-hidden .main { padding: 16px 16px 24px; }
  .side-toggle { width: 44px; height: 44px; font-size: 22px; }
  .apps-link { top: 16px; }
}

/* Cards / tables */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #f0f4fb; font-weight: 600; white-space: nowrap; }
tr:hover td { background: #fafbff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.lowest { background: var(--ok-bg) !important; font-weight: 600; }

/* Forms */
input, select, textarea { font-family: inherit; font-size: 14px; padding: 7px 9px; border: 1px solid var(--line);
  border-radius: 7px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); }
input.cell { padding: 5px 6px; border-radius: 5px; }
label { display: block; font-size: 12px; color: var(--muted); margin: 0 0 4px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 140px; }

/* Buttons */
.btn { background: var(--brand); color: #fff; border: none; padding: 8px 16px; border-radius: 8px; font-size: 14px; }
.btn:hover { background: var(--brand-d); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: #f3f4f6; }
.btn.danger { background: var(--danger); }
.btn.ok { background: var(--ok); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.b-draft { background: #e5e7eb; color: #374151; }
.b-open { background: #dbeafe; color: #1d4ed8; }
.b-closed { background: #fef3c7; color: #b45309; }
.b-done { background: #d7f0d7; color: #166534; }
.tag-urgent { background: #fee2e2; color: #b91c1c; }
.muted { color: var(--muted); }
.right { text-align: right; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; }
.spacer { flex: 1; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg,#1e3a8a,#2563eb); }
.login-box { background: #fff; padding: 34px; border-radius: 14px; width: 340px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-box h1 { text-align: center; font-size: 18px; }
.login-box .sub { text-align: center; color: var(--muted); margin-bottom: 20px; font-size: 13px; }

/* Toast */
#toast { position: fixed; top: 18px; right: 18px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #111827; color: #fff; padding: 11px 16px; border-radius: 9px; box-shadow: 0 6px 18px rgba(0,0,0,.2); animation: slide .2s; }
.toast.ok { background: var(--ok); } .toast.err { background: var(--danger); }
@keyframes slide { from { transform: translateX(20px); opacity: 0; } }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 500; }
.modal { background: #fff; border-radius: 12px; padding: 22px; width: 560px; max-width: 92vw; max-height: 88vh; overflow: auto; }
.modal h2 { margin-top: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.empty { text-align: center; color: var(--muted); padding: 40px; }
.chk-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; max-height: 320px; overflow: auto; }
.chk-list label { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; margin: 0; color: var(--ink); font-size: 13px; }
.chk-list input { width: auto; }

/* ERP 單據:產品挑選下拉 / 合計表 / 列印 */
.pick-box { position: fixed; z-index: 900; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.18); max-height: 300px; overflow: auto; }
.pick-item { padding: 7px 10px; cursor: pointer; border-bottom: 1px solid #f1f3f7; font-size: 13px; }
.pick-item:hover { background: #eef4ff; }
table.totals { width: auto; background: none; }
table.totals td { border: none; padding: 3px 0 3px 18px; }
/* 總覽卡片 */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 8px; }
.kpi { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; color: var(--ink); }
a.kpi:hover { border-color: var(--brand); }
.kpi .n { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi.warn .n { color: var(--danger); }
.kpi .t { font-size: 12px; color: var(--muted); }
.help h2 { margin-top: 0; } .help li { margin: 4px 0; line-height: 1.7; } .help code { background: #eef2f7; padding: 1px 6px; border-radius: 4px; }
.print-head { display: none; }
@media print {
  .print-head { display: block; font-size: 16px; font-weight: 700; padding-bottom: 8px; margin-bottom: 8px; border-bottom: 2px solid #000; }
  .side, .side-toggle, .side-backdrop, .apps-link, .toolbar, #toast, .main > .btn-row { display: none !important; }
  .shell { display: block; } .main { padding: 0; overflow: visible; } body { background: #fff; }
  .card { border: none; padding: 6px 0; } a { color: inherit; }
}
