:root {
  --ink: #182027;
  --muted: #65717a;
  --paper: #f7f6f1;
  --surface: #fffefa;
  --line: #d8d8d2;
  --blue: #173b55;
  --blue-soft: #dfe9ee;
  --green: #2d735c;
  --red: #b7443e;
  --gray-cell: #e2e2de;
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--paper); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-screen { min-height: 100svh; display: grid; grid-template-columns: 1fr minmax(340px, 520px); background: var(--blue); color: white; }
.login-brand { padding: 42px 52px; display: flex; gap: 15px; align-items: flex-start; font-size: 20px; }
.login-brand span, .brand > span { display: grid; place-items: center; width: 42px; height: 42px; background: white; color: var(--blue); font-weight: 800; letter-spacing: -.08em; }
.login-panel { background: var(--surface); color: var(--ink); padding: clamp(44px, 9vw, 110px) clamp(30px, 6vw, 72px); display: flex; flex-direction: column; justify-content: center; }
.eyebrow { color: #6f8796; font-size: 11px; letter-spacing: .19em; font-weight: 800; margin: 0 0 14px; }
.login-panel h1 { font-size: clamp(34px, 5vw, 58px); letter-spacing: -.05em; margin: 0 0 16px; }
.login-panel > p:not(.eyebrow):not(.error) { color: var(--muted); margin: 0 0 42px; }
label { display: grid; gap: 8px; color: #47535b; font-size: 13px; font-weight: 700; }
input, select, textarea { width: 100%; border: 0; border-bottom: 1px solid #b9bcb9; background: transparent; color: var(--ink); padding: 10px 2px; outline: none; transition: border-color .18s, background .18s; }
textarea { resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); background: #f4f7f8; }
button { border: 0; background: var(--blue); color: white; min-height: 46px; padding: 0 20px; font-weight: 800; transition: transform .16s, opacity .16s, background .16s; }
button:hover:not(:disabled) { transform: translateY(-1px); background: #204d6c; }
button:disabled { opacity: .42; cursor: not-allowed; }
.login-panel button { margin-top: 24px; display: flex; justify-content: space-between; align-items: center; }
.error { color: var(--red); font-size: 13px; }

.topbar { height: 72px; display: flex; align-items: center; padding: 0 34px; border-bottom: 1px solid var(--line); background: rgba(255,254,250,.92); position: sticky; top: 0; z-index: 10; backdrop-filter: blur(12px); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand > span { background: var(--blue); color: white; width: 36px; height: 36px; }
.brand div { display: grid; }
.brand small { color: var(--muted); }
.topbar-status { margin-left: auto; color: var(--green); font-size: 12px; display: flex; align-items: center; gap: 8px; }
.topbar-status i { width: 7px; height: 7px; background: var(--green); border-radius: 50%; box-shadow: 0 0 0 5px #dfeee8; }
.text-button { background: none; color: var(--muted); padding: 0 0 0 26px; min-height: auto; font-weight: 600; }
.text-button:hover:not(:disabled) { transform: none; background: none; color: var(--ink); }

main { max-width: 1500px; margin: 0 auto; padding: 44px 34px 130px; }
.selector-band { display: grid; grid-template-columns: minmax(300px, 1fr) minmax(360px, .9fr); gap: 70px; align-items: end; padding: 22px 0 42px; }
.selector-band h1 { font-size: clamp(28px, 4vw, 50px); max-width: 720px; letter-spacing: -.045em; line-height: 1.08; margin: 0; }
.quote-select select { font-size: 15px; padding: 13px 2px; }
.loading-line { border-top: 1px solid var(--line); padding: 18px 0; color: var(--muted); display: flex; align-items: center; gap: 10px; }
.loading-line span { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.control-strip { display: grid; grid-template-columns: repeat(4, minmax(130px, 1fr)) minmax(220px, 1.3fr); gap: 22px; border-block: 1px solid var(--line); padding: 22px 0; }
.document-state { display: grid; grid-template-columns: 12px 1fr; column-gap: 10px; align-content: center; border-left: 1px solid var(--line); padding-left: 22px; }
.document-state span { width: 9px; height: 9px; border-radius: 50%; background: #9b9b95; grid-row: span 2; margin-top: 5px; }
.document-state span[data-state="ready"] { background: var(--green); box-shadow: 0 0 0 5px #dfeee8; }
.document-state span[data-state="error"] { background: var(--red); box-shadow: 0 0 0 5px #f3e3e1; }
.document-state small { color: var(--muted); margin-top: 3px; }

.form-section { padding: 52px 0; border-bottom: 1px solid var(--line); }
.section-title { display: grid; grid-template-columns: 55px 1fr; margin-bottom: 32px; }
.section-title > span { color: #89939a; font-size: 12px; font-weight: 800; padding-top: 5px; }
.section-title h2 { font-size: 24px; letter-spacing: -.025em; margin: 0 0 5px; }
.section-title p { color: var(--muted); margin: 0; }
.field-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 26px 28px; margin-left: 55px; }
.field-grid .wide { grid-column: span 2; }
.field-grid.compact { margin: 28px 0 0; }
details { margin: 34px 0 0 55px; border-top: 1px dashed var(--line); padding-top: 20px; }
summary { cursor: pointer; color: var(--blue); font-weight: 800; }

.table-wrap { overflow-x: auto; border-block: 1px solid #aeb3b5; }
.items-table { border-collapse: collapse; width: 100%; min-width: 1150px; table-layout: fixed; }
.items-table th, .items-table td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 8px; vertical-align: middle; }
.items-table th { background: #f1f1ed; font-size: 12px; letter-spacing: .04em; text-align: center; }
.items-table th:nth-child(1) { width: 60px; }
.items-table th:nth-child(2) { width: 300px; }
.items-table th:nth-child(3) { width: 65px; }
.items-table th:nth-child(4) { width: 75px; }
.items-table th:nth-child(n+5):nth-child(-n+8) { width: 105px; }
.items-table th:nth-child(9) { width: 140px; }
.items-table input, .items-table textarea { border: 0; padding: 6px; text-align: inherit; }
.items-table td:first-child, .items-table td:nth-child(3), .items-table td:nth-child(4), .items-table td:nth-child(n+5):nth-child(-n+8) { text-align: center; }
.items-table .calculated { background: var(--gray-cell); }
.items-table input[readonly] { color: #4b5155; }
.quoted-unit { font-variant-numeric: tabular-nums; }
.items-table tfoot th { text-align: right; background: var(--surface); }
.items-table tfoot td { font-weight: 800; text-align: right !important; font-variant-numeric: tabular-nums; }

.download-bar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 8; display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; padding: 16px max(34px, calc((100vw - 1432px) / 2)); background: rgba(24,32,39,.96); color: white; box-shadow: 0 -12px 40px rgba(20,30,36,.12); }
.download-bar div { display: grid; }
.download-bar small { color: #aebac1; margin-top: 2px; }
.download-bar button { min-width: 145px; }
.download-bar .secondary { background: transparent; border: 1px solid #71808a; }
.message { position: fixed; right: 26px; bottom: 92px; z-index: 12; max-width: 420px; padding: 15px 18px; background: var(--surface); border-left: 4px solid var(--green); box-shadow: 0 14px 40px rgba(20,30,36,.18); }
.message-error { border-left-color: var(--red); }
.reveal { opacity: 0; transform: translateY(10px); transition: opacity .38s ease, transform .38s ease; }
.reveal.visible, .selector-band { opacity: 1; transform: none; }

@media (max-width: 900px) {
  .login-screen { grid-template-columns: 1fr; }
  .login-brand { min-height: 28vh; }
  .selector-band { grid-template-columns: 1fr; gap: 32px; }
  .control-strip { grid-template-columns: repeat(2, 1fr); }
  .document-state { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); padding: 18px 0 0; }
  .field-grid { grid-template-columns: 1fr 1fr; margin-left: 0; }
  .section-title { grid-template-columns: 42px 1fr; }
  details { margin-left: 0; }
}

@media (max-width: 580px) {
  main { padding: 26px 18px 155px; }
  .topbar { padding: 0 18px; }
  .topbar-status { display: none; }
  .control-strip, .field-grid { grid-template-columns: 1fr; }
  .field-grid .wide { grid-column: auto; }
  .download-bar { grid-template-columns: 1fr 1fr; padding: 14px 18px; }
  .download-bar div { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
