:root {
  --ink: #18323a;
  --ink-soft: #52666c;
  --paper: #f5f4ef;
  --surface: #ffffff;
  --line: #d8ddd9;
  --line-dark: #b8c2bf;
  --green-pale: #edf2e8;
  --blue-pale: #eaf1f2;
  --orange: #bd4e24;
  --orange-dark: #973b1d;
  --danger: #a33b32;
  --success: #236646;
  --shadow: 0 20px 60px rgba(24, 50, 58, 0.09);
  --radius: 14px;
}

* { box-sizing: border-box; }

html { color-scheme: light; scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid rgba(189, 78, 36, 0.28);
  outline-offset: 2px;
}

[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.audit-header {
  min-height: 78px;
  padding: 14px clamp(20px, 5vw, 72px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  color: white;
  background: var(--ink);
  border-bottom: 4px solid var(--orange);
}

.audit-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.audit-brand img { width: 34px; height: 34px; object-fit: contain; image-rendering: pixelated; }
.audit-brand small { display: block; margin-top: -2px; font-size: 11px; font-weight: 500; letter-spacing: 0.12em; color: #c9d7d9; }

.privacy-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 13px;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 999px;
  font-size: 13px;
  color: #e9f1f2;
}

.privacy-chip span { width: 8px; height: 8px; border-radius: 50%; background: #8bc99c; box-shadow: 0 0 0 4px rgba(139,201,156,.14); }

main { width: min(1460px, calc(100% - 40px)); margin: 0 auto; padding: 48px 0 80px; }

.auth-layout {
  min-height: calc(100vh - 220px);
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, .7fr);
  align-items: center;
  gap: clamp(42px, 7vw, 110px);
  max-width: 1120px;
  margin: 0 auto;
}

.auth-copy { max-width: 640px; }
.eyebrow { margin: 0 0 8px; color: var(--orange); font-size: 12px; font-weight: 800; letter-spacing: .16em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 16px; font-family: Georgia, "Noto Serif TC", serif; font-size: clamp(34px, 4.2vw, 60px); line-height: 1.08; letter-spacing: -.025em; }
h2 { margin-bottom: 8px; font-size: clamp(25px, 2.5vw, 34px); line-height: 1.2; }
h3 { margin-bottom: 9px; font-size: 20px; }
.auth-copy > p:not(.eyebrow) { color: var(--ink-soft); font-size: 18px; }
.plain-list { margin: 28px 0 0; padding: 0; list-style: none; border-top: 1px solid var(--line-dark); }
.plain-list li { padding: 13px 0 13px 26px; border-bottom: 1px solid var(--line); position: relative; }
.plain-list li::before { content: "✓"; position: absolute; left: 2px; color: var(--success); font-weight: 800; }

.auth-card {
  background: var(--surface);
  border: 1px solid var(--line-dark);
  border-top: 4px solid var(--orange);
  border-radius: var(--radius);
  padding: clamp(24px, 4vw, 38px);
  box-shadow: var(--shadow);
}

.form-heading { padding-bottom: 22px; margin-bottom: 22px; border-bottom: 1px solid var(--line); }
.form-heading span { color: var(--ink-soft); font-size: 13px; }
.form-heading h2 { margin: 3px 0 0; font-size: 27px; }
.spaced-label { margin-top: 18px; }

label { display: block; color: var(--ink); font-size: 14px; font-weight: 700; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line-dark);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  padding: 11px 12px;
}
label > input, label > select, label > textarea { margin-top: 7px; }
textarea { resize: vertical; }
input[readonly] { background: #f0f2ef; color: #3f555c; }

.key-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-top: 7px; }
.key-row input { margin: 0; }
.small-button, .secondary-button, .primary-button, .text-button, .file-button {
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 800;
  text-decoration: none;
}
.small-button { padding: 9px 14px; color: var(--ink); background: var(--blue-pale); border-color: var(--line-dark); }
.primary-button { min-height: 46px; padding: 11px 20px; color: white; background: var(--orange); border-color: var(--orange); }
.primary-button:hover { background: var(--orange-dark); }
.secondary-button { min-height: 42px; padding: 9px 16px; color: var(--ink); background: white; border-color: var(--line-dark); }
.secondary-button:hover, .small-button:hover { border-color: var(--ink); }
.secondary-button.danger { color: var(--danger); border-color: #d8aaa5; }
.text-button { padding: 8px 0; background: transparent; border: 0; color: var(--orange); }
.danger-text { color: var(--danger); }
.auth-card > .primary-button { width: 100%; margin-top: 6px; }

.field-note { margin: 6px 0 17px; color: var(--ink-soft); font-size: 12px; }
.check-row { display: flex; align-items: flex-start; gap: 10px; margin: 18px 0; font-weight: 500; }
.check-row input { width: 18px; height: 18px; margin: 3px 0 0; accent-color: var(--orange); }
.check-row.compact { margin: 13px 0 4px; }
.form-error { min-height: 24px; margin: 7px 0; color: var(--danger); font-weight: 700; font-size: 13px; }
.form-success { min-height: 24px; color: var(--success); font-weight: 700; }

.workspace-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.workspace-head h1 { margin: 0; font-size: clamp(34px, 4vw, 52px); }
.workspace-note { margin: 9px 0 0; color: var(--ink-soft); font-size: 13px; }
.head-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; justify-content: flex-end; }
.role-badge { padding: 8px 12px; border-radius: 999px; color: var(--success); background: #e5f0e9; border: 1px solid #c4d9cb; font-size: 12px; font-weight: 800; }
.role-badge.reviewer { color: #415f77; background: #e9f0f5; border-color: #c8d6e1; }

.session-notice { display: flex; gap: 16px; align-items: center; padding: 13px 16px; margin-bottom: 22px; color: #4c5e50; background: var(--green-pale); border-left: 4px solid #78925e; font-size: 13px; }
.session-notice strong { white-space: nowrap; }

.summary-grid { display: grid; grid-template-columns: 1fr 1fr 1.5fr; gap: 12px; margin-bottom: 28px; }
.summary-grid article { min-height: 126px; padding: 19px 21px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.summary-grid article > span { display: block; color: var(--ink-soft); font-size: 12px; font-weight: 800; letter-spacing: .05em; }
.summary-grid article > strong { display: block; margin: 7px 0 2px; font-family: Georgia, serif; font-size: 33px; line-height: 1.1; }
.summary-grid small { color: var(--ink-soft); }
.currency-totals { display: flex; flex-wrap: wrap; gap: 16px; margin: 8px 0 5px; }
.currency-totals strong { font-family: Georgia, serif; font-size: 25px; }

.workspace-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--line-dark); overflow-x: auto; }
.workspace-tabs button { padding: 13px 20px; border: 0; border-bottom: 3px solid transparent; color: var(--ink-soft); background: transparent; font-weight: 800; white-space: nowrap; }
.workspace-tabs button:hover { color: var(--ink); }
.workspace-tabs button.active { color: var(--orange); border-bottom-color: var(--orange); }
.tab-panel { display: none; padding: 28px 0 10px; }
.tab-panel.active { display: block; }

.panel-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 19px; }
.panel-heading h2 { margin: 0; }
.panel-heading .eyebrow { margin-bottom: 4px; }
.panel-intro { max-width: 820px; color: var(--ink-soft); }
.table-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.table-actions input { min-width: 270px; }
.table-actions select { width: auto; min-width: 140px; }

.table-wrap { position: relative; overflow-x: auto; background: var(--surface); border: 1px solid var(--line-dark); border-top: 3px solid var(--ink); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; white-space: nowrap; }
th { color: #41575d; background: #edf0ee; font-size: 11px; letter-spacing: .03em; }
tbody tr:hover { background: #f8f8f4; }
td strong { display: block; }
td small { color: var(--ink-soft); }
.row-action { padding: 5px 9px; border: 1px solid var(--line-dark); border-radius: 6px; color: var(--ink); background: white; font-weight: 700; }
.status { display: inline-flex; align-items: center; padding: 4px 8px; border-radius: 999px; font-size: 11px; font-weight: 800; background: #e8efeb; color: var(--success); }
.status[data-status="資料待補"], .status[data-status="待交付"] { color: #8c5a12; background: #f6ecd9; }
.status[data-status="已退款"], .status[data-status="已作廢"] { color: #82504b; background: #f1e4e2; }
.empty-state { padding: 74px 20px; text-align: center; color: var(--ink-soft); }
.empty-state strong { display: block; color: var(--ink); font-size: 18px; }
.empty-state p { margin: 6px 0 0; }

.record-form { display: grid; gap: 18px; }
fieldset { min-width: 0; margin: 0; padding: 22px; border: 1px solid var(--line); background: var(--surface); }
legend { padding: 0 9px; font-size: 16px; font-weight: 900; color: var(--ink); }
.form-grid { display: grid; gap: 16px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.calculation-line { margin: 9px 0 17px; padding: 10px 12px; color: #4f6553; background: var(--green-pale); border-left: 3px solid #78925e; font-weight: 700; }
.form-actions { display: flex; gap: 10px; }

.proof-upload { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 18px; }
.proof-upload .file-button { margin: 0; }
.proof-upload strong { display: block; overflow-wrap: anywhere; }
.proof-upload p { margin: 4px 0 0; color: var(--ink-soft); font-size: 13px; }

.rates-form { max-width: 900px; border: 1px solid var(--line-dark); background: var(--surface); }
.rate-table-head, .rate-row { display: grid; grid-template-columns: minmax(220px, 1.5fr) minmax(150px, .7fr) minmax(180px, 1fr); align-items: center; gap: 12px; padding: 13px 16px; }
.rate-table-head { color: var(--ink-soft); background: #edf0ee; font-size: 11px; font-weight: 800; }
.rate-row { border-top: 1px solid var(--line); }
.rates-form > p, .rates-form > button { margin-left: 16px; margin-right: 16px; }
.rates-form > button { margin-bottom: 16px; }

.reviewer-key-card { max-width: 900px; margin-top: 18px; padding: 22px; background: var(--surface); border: 1px solid var(--line-dark); border-left: 4px solid var(--orange); }
.reviewer-key-card p { color: var(--ink-soft); }
.key-result { display: flex; align-items: center; gap: 10px; margin-top: 16px; padding: 12px; background: var(--green-pale); border: 1px solid #ccd9c4; }
.key-result code { flex: 1; color: var(--ink); font-size: 17px; font-weight: 800; overflow-wrap: anywhere; }

.transfer-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 13px; }
.transfer-grid.two-column { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.transfer-grid article { min-height: 270px; padding: 24px; border: 1px solid var(--line-dark); background: var(--surface); display: flex; flex-direction: column; align-items: flex-start; }
.transfer-grid p { color: var(--ink-soft); }
.step-number { display: block; margin-bottom: 25px; color: var(--orange); font-family: Georgia, serif; font-size: 25px; }
.file-button { display: inline-flex; justify-content: center; align-items: center; padding: 10px 16px; color: white; background: var(--orange); cursor: pointer; }
.file-button input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.transfer-grid .secondary-button, .file-button { margin-top: auto; }
.transfer-feedback { margin: 10px 0 0 !important; font-size: 12px; font-weight: 700; }

.record-page { min-height: calc(100vh - 260px); }
.detail-page-head { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: start; gap: 24px; margin-bottom: 22px; padding-bottom: 22px; border-bottom: 1px solid var(--line-dark); }
.detail-page-head h1 { margin: 0; font-size: clamp(34px, 4vw, 52px); }
.detail-page-head .secondary-button { margin-top: 4px; white-space: nowrap; }
.record-detail { display: grid; grid-template-columns: 1fr 1fr; margin: 0; padding: 14px 28px 28px; background: var(--surface); border: 1px solid var(--line-dark); border-top: 3px solid var(--ink); }
.record-detail div { padding: 15px 0; border-bottom: 1px solid var(--line); }
.record-detail div:nth-child(odd) { padding-right: 28px; }
.record-detail dt { color: var(--ink-soft); font-size: 11px; font-weight: 800; }
.record-detail dd { margin: 4px 0 0; overflow-wrap: anywhere; font-weight: 700; }
.dialog-actions { display: flex; gap: 9px; justify-content: flex-end; margin-top: 18px; padding: 18px 22px; background: #f2f3ef; border: 1px solid var(--line); }
.proof-preview { margin-top: 22px; padding: 24px 28px 28px; background: var(--surface); border: 1px solid var(--line-dark); }
.proof-preview-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.proof-preview-head h3 { margin: 0; }
.proof-preview-head span { color: var(--ink-soft); font-size: 12px; }
.proof-gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.proof-gallery figure { min-width: 0; margin: 0; }
.proof-gallery a { display: block; border-radius: 8px; overflow: hidden; }
.proof-gallery img { display: block; width: 100%; height: 240px; object-fit: contain; background: #edf0ee; border: 1px solid var(--line); }
.proof-gallery figcaption { padding: 7px 2px 0; color: var(--ink-soft); font-size: 12px; }
.proof-load-error { display: grid; min-height: 120px; place-items: center; margin: 0; padding: 14px; color: var(--danger); background: #f8ecea; border: 1px dashed #d8aaa5; text-align: center; }
.proof-empty { margin: 22px 0 0; padding: 24px; color: var(--ink-soft); background: #f2f3ef; border: 1px dashed var(--line-dark); text-align: center; }

footer { display: flex; justify-content: space-between; gap: 20px; padding: 22px clamp(20px, 5vw, 72px); color: #c8d3d5; background: var(--ink); font-size: 13px; }
footer a { color: white; }

@media (max-width: 980px) {
  .auth-layout { grid-template-columns: 1fr; max-width: 680px; align-items: start; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .summary-grid .wide { grid-column: span 2; }
  .form-grid.three, .form-grid.four { grid-template-columns: 1fr 1fr; }
  .transfer-grid { grid-template-columns: 1fr; }
  .transfer-grid.two-column { grid-template-columns: 1fr; }
  .transfer-grid article { min-height: 220px; }
}

@media (max-width: 680px) {
  .audit-header { align-items: flex-start; flex-direction: column; }
  .privacy-chip { font-size: 11px; }
  main { width: min(100% - 24px, 1460px); padding-top: 30px; }
  .auth-layout { gap: 28px; }
  .workspace-head, .panel-heading { align-items: flex-start; flex-direction: column; }
  .head-actions, .table-actions { width: 100%; justify-content: flex-start; }
  .summary-grid { grid-template-columns: 1fr; }
  .summary-grid .wide { grid-column: auto; }
  .form-grid.three, .form-grid.four { grid-template-columns: 1fr; }
  fieldset { padding: 16px; }
  .rate-table-head { display: none; }
  .rate-row { grid-template-columns: 1fr; }
  .proof-upload { grid-template-columns: 1fr; }
  .proof-gallery { grid-template-columns: 1fr; }
  .key-result { align-items: stretch; flex-direction: column; }
  .table-actions input, .table-actions select { width: 100%; min-width: 0; }
  .detail-page-head { grid-template-columns: 1fr; gap: 14px; }
  .record-detail { grid-template-columns: 1fr; }
  .record-detail div:nth-child(odd) { padding-right: 0; }
  footer { flex-direction: column; }
}

@media print {
  body { background: white; font-size: 10pt; }
  .audit-header { min-height: auto; padding: 12px 0; color: var(--ink); background: white; border-bottom: 2px solid var(--ink); }
  .audit-brand small, .privacy-chip { color: var(--ink-soft); }
  main { width: 100%; padding: 20px 0; }
  .head-actions, .session-notice, .workspace-tabs, .table-actions, .action-column, .row-action, .detail-page-head button, .dialog-actions, footer { display: none !important; }
  .summary-grid { grid-template-columns: 1fr 1fr 1fr; break-inside: avoid; }
  #tab-records { display: block !important; padding-top: 10px; }
  .table-wrap { overflow: visible; border-top: 2px solid var(--ink); }
  table { font-size: 7.5pt; }
  th, td { padding: 6px; white-space: normal; }
  @page { size: landscape; margin: 12mm; }
}
