:root {
  --bg: #f4f6f9; --card: #fff; --text: #1f2933; --muted: #6b7785; --line: #e1e5eb;
  --primary: #2459c7; --primary-hover: #1c48a3; --danger: #c43d3d; --warn-bg: #fff6e0; --warn: #8a5a00;
  --ok: #1e7f4f; --radius: 8px;
  font-family: "Segoe UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1em; margin: 6px 0; }
.neg { color: var(--danger); }
.nowrap { white-space: nowrap; }
h2 { margin: 0; font-size: 20px; }
h3 { margin: 0 0 12px; font-size: 16px; }
h4 { margin: 16px 0 6px; font-size: 14px; color: var(--muted); }

/* 登入 */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--card); padding: 32px; border-radius: 12px; width: 100%; max-width: 360px; box-shadow: 0 4px 24px rgba(0,0,0,.08); display: grid; gap: 12px; }
.login-card h1 { margin: 0 0 8px; font-size: 22px; text-align: center; }

/* 頂部 */
.topbar { display: flex; align-items: center; gap: 24px; background: #1d2a3a; color: #fff; padding: 0 20px; height: 54px; position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
#nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
#nav a { color: #c9d3df; text-decoration: none; padding: 6px 12px; border-radius: 6px; white-space: nowrap; }
#nav a:hover { color: #fff; background: rgba(255,255,255,.08); }
#nav a.active { color: #fff; background: rgba(255,255,255,.16); }
.me { display: flex; gap: 10px; align-items: center; white-space: nowrap; font-size: 13px; }
.me .link { color: #c9d3df; }
.badge { background: var(--danger); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; margin-left: 2px; }

main { max-width: 1280px; margin: 0 auto; padding: 20px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-head h3 { margin: 0; }
.cols { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; }
.cols .card { margin-bottom: 16px; }

/* 表單元素 */
label { display: grid; gap: 4px; font-weight: 500; }
input, select, textarea { font: inherit; padding: 7px 10px; border: 1px solid #c8cfd8; border-radius: 6px; background: #fff; color: var(--text); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(36,89,199,.25); border-color: var(--primary); }
textarea { resize: vertical; }
.check { display: flex; align-items: center; gap: 6px; font-weight: normal; white-space: nowrap; }
.check input { width: auto; }
.inline { display: flex; gap: 8px; align-items: center; }
.form h3 { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }
.form h3:first-of-type { margin-top: 18px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; }
.span2 { grid-column: span 2; }
.profit { margin-top: 12px; font-size: 15px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; align-items: center; }
.form .actions { margin-top: 12px; }

.btn { font: inherit; display: inline-block; padding: 7px 16px; border-radius: 6px; border: 1px solid #c8cfd8; background: #fff; color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: #f0f2f5; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: #fdeeee; }
.link { background: none; border: none; color: var(--primary); cursor: pointer; padding: 0; font: inherit; white-space: nowrap; }
.link.danger { color: var(--danger); }

.filters { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filters select { width: auto; }
.filters input[name=q] { max-width: 300px; }

/* 表格 */
.table-wrap { overflow-x: auto; }
.card.table-wrap { padding: 0; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { background: #f7f9fb; font-weight: 600; color: var(--muted); font-size: 13px; white-space: nowrap; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table tfoot td { font-weight: 700; background: #f7f9fb; border-bottom: none; }
.table.clickable tbody tr { cursor: pointer; }
.table.clickable tbody tr:hover { background: #f2f6fd; }
.table tr.current { background: #eef3fc; }
.empty { padding: 24px; text-align: center; margin: 0; }

.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; vertical-align: middle; }
.st-draft { background: #eceff3; color: #56606b; }
.st-pending { background: #fff1d6; color: #8a5a00; }
.st-approved { background: #dff3e8; color: var(--ok); }
.st-rejected { background: #fde3e3; color: var(--danger); }
.st-cancelled { background: #eceff3; color: #9aa3ad; text-decoration: line-through; }

.notice { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); border: 1px solid #f2d79b; }

/* 明細 */
.info { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; margin: 0; }
.info dt { color: var(--muted); }
.info dd { margin: 0; }
.info dd.big { font-size: 17px; font-weight: 600; }
.desc { white-space: pre-wrap; background: #f7f9fb; padding: 10px 12px; border-radius: 6px; }
.progress { height: 8px; background: #eceff3; border-radius: 4px; overflow: hidden; margin-bottom: 6px; }
.progress div { height: 100%; background: var(--ok); }
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 14px 14px; }
.timeline li::before { content: ""; position: absolute; left: -21px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: #b7c0cb; }
.timeline .tl-approve::before { background: var(--ok); }
.timeline .tl-reject::before, .timeline .tl-cancel::before { background: var(--danger); }
.timeline .tl-submit::before { background: #e3a008; }
.timeline .tl-invoice::before { background: var(--primary); }
.tl-time { color: var(--muted); font-size: 12px; margin-right: 8px; }
.tl-comment { background: #f7f9fb; padding: 6px 10px; border-radius: 6px; margin-top: 4px; white-space: pre-wrap; }

/* 附件 */
.files { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 6px; }
.files:empty { display: none; }
.files li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px; background: #fafbfc; }
.files.pending li { border-style: dashed; background: #f5f8fe; }
.f-icon { font-size: 18px; line-height: 1; }
.f-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
a.f-name { color: var(--primary); text-decoration: none; }
a.f-name:hover { text-decoration: underline; }
.f-meta { font-size: 12px; white-space: nowrap; }
.dropzone { border: 2px dashed #c8cfd8; border-radius: var(--radius); padding: 18px; text-align: center; cursor: pointer; background: #fbfcfd; color: var(--text); }
.dropzone b { color: var(--primary); }
.dropzone:hover, .dropzone:focus, .dropzone.over { border-color: var(--primary); background: #f2f6fd; outline: none; }
.dropzone .muted { font-size: 12px; margin-top: 4px; }
.btn.disabled, .link.disabled { pointer-events: none; opacity: .55; }

/* 報表 */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 2px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat b { font-size: 22px; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); }
.stat.accent { border-color: var(--primary); box-shadow: inset 3px 0 0 var(--primary); }
input[type=month] { width: auto; }

/* 對話框 */
dialog { border: none; border-radius: 12px; padding: 0; width: min(440px, calc(100vw - 32px)); box-shadow: 0 10px 40px rgba(0,0,0,.2); }
dialog::backdrop { background: rgba(20,30,45,.45); }
#dialog-form { padding: 20px; display: grid; gap: 12px; }
#dialog-form h3 { margin: 0; }
.dlg-body { display: grid; gap: 12px; }
.dlg-body p { margin: 0; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1d2a3a; color: #fff; padding: 10px 20px; border-radius: 8px; z-index: 100; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
.toast.error { background: var(--danger); }

@media (max-width: 900px) {
  .cols { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 16px; gap: 8px; }
  #nav { order: 3; flex-basis: 100%; }
  main { padding: 16px; }
  .grid { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .stats { grid-template-columns: 1fr; }
  .filters input[name=q] { max-width: none; }
  .files li { flex-wrap: wrap; }
  .f-meta { flex-basis: 100%; padding-left: 28px; }
}
