:root {
  --ink: #23272f;
  --muted: #667085;
  --line: #d7dde6;
  --page: #f4f7f9;
  --panel: #fff;
  --nav: #20313f;
  --nav-2: #2d4957;
  --green: #0f8b6b;
  --red: #ba3b46;
  --blue: #2864a6;
  --shadow: 0 16px 40px rgba(24, 39, 54, 0.1);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--page); color: var(--ink); font-family: "Microsoft JhengHei", "Noto Sans TC", Arial, sans-serif; }
button, input, select, textarea { font: inherit; }
.hidden { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(420px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 28px; display: grid; gap: 14px; }
.login-card h1 { margin: 0; font-size: 26px; }
.login-card p, .login-card small { color: var(--muted); margin: 0; }
.app-shell { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--nav); color: #fff; padding: 26px 22px; display: flex; flex-direction: column; gap: 28px; }
.brand { display: flex; gap: 14px; align-items: center; }
.brand-text { flex: 1; min-width: 0; }
.brand-mark { width: 48px; height: 48px; flex-shrink: 0; display: grid; place-items: center; background: #e7b85b; color: #162734; font-weight: 800; border-radius: 8px; }
.brand h1, .toolbar h2 { margin: 0; letter-spacing: 0; }
.brand h1 { font-size: 20px; }
.brand p { margin: 5px 0 0; color: #bfd0dc; font-size: 14px; }
.logout-btn { min-height: 38px; padding: 8px 12px; font-size: 14px; flex-shrink: 0; }
.nav-tabs { display: grid; gap: 8px; }
.nav-tab { border: 0; border-radius: 8px; padding: 13px 14px; text-align: left; color: #dbe8ef; background: transparent; cursor: pointer; font-weight: 800; }
.nav-tab.active { background: var(--nav-2); color: #fff; }
@media (hover: hover) {
  .nav-tab:hover { background: var(--nav-2); color: #fff; }
}
.sidebar-panel { margin-top: auto; display: grid; gap: 12px; }
.eyebrow { display: block; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0; }
.sidebar .eyebrow { color: #abc0cc; }
.cycle-card { border: 1px solid rgba(255,255,255,.14); border-radius: 8px; padding: 14px; display: grid; gap: 6px; background: rgba(255,255,255,.06); }
.cycle-card span { color: #c5d5df; font-size: 13px; }
.content { padding: 28px; min-width: 0; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.view { display: none; }
.view.active { display: block; }
.filter-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.list-header { padding: 16px; border-bottom: 1px solid var(--line); }
.compact-filter { display: flex; align-items: center; gap: 8px; color: #52616e; }
.compact-filter input { min-height: 42px; width: 160px; }
.two-column { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(320px, .8fr); gap: 18px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.form-panel, .info-panel { padding: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
label { display: grid; gap: 7px; color: #344054; font-size: 14px; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid #cdd5df; border-radius: 7px; padding: 11px 12px; color: var(--ink); background: #fff; min-height: 44px; font-size: 16px; }
textarea { resize: vertical; }
input[readonly] { background: #eef3f7; color: #152936; font-weight: 800; }
.wide { grid-column: 1 / -1; }
.form-actions { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 16px; display: flex; gap: 10px; flex-wrap: wrap; }
button, .button { border: 1px solid transparent; border-radius: 8px; padding: 10px 14px; cursor: pointer; min-height: 44px; font-weight: 800; text-decoration: none; display: inline-grid; place-items: center; }
button:disabled { opacity: .55; cursor: not-allowed; }
.primary { background: var(--green); color: #fff; }
.ghost { background: #fff; border-color: #c9d2dc; color: #273644; }
.ghost.dark { background: transparent; border-color: rgba(255,255,255,.2); color: #fff; }
.file-field { display: grid; gap: 10px; }
.file-field-label { color: #344054; font-size: 14px; font-weight: 700; }
.file-buttons { display: flex; gap: 10px; flex-wrap: wrap; }
.file-btn { flex: 1; min-width: 150px; min-height: 48px; }
.file-previews { display: grid; gap: 8px; }
.file-preview { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #f9fbfc; }
.file-preview img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; flex-shrink: 0; background: #e8edf2; }
.file-preview-icon { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 6px; background: #e8edf2; color: #52616e; font-weight: 900; font-size: 13px; flex-shrink: 0; }
.file-preview-meta { flex: 1; min-width: 0; display: grid; gap: 2px; }
.file-preview-name { font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-remove { min-height: 38px; padding: 6px 12px; flex-shrink: 0; }
.upload-progress { position: relative; height: 30px; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: #eef3f7; }
.upload-progress-bar { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--green); transition: width .2s ease; }
.upload-progress-text { position: relative; display: grid; place-items: center; height: 100%; font-size: 13px; font-weight: 800; color: #152936; }
.invoice-link { display: inline-flex; align-items: center; gap: 4px; color: var(--blue); font-weight: 800; text-decoration: none; padding: 4px 8px; margin: 2px 4px 2px 0; border: 1px solid #c4d9ec; border-radius: 999px; background: #f0f7fc; font-size: 13px; white-space: nowrap; }
.vendor-details { display: grid; gap: 10px; margin: 12px 0 0; }
.vendor-details div { display: grid; grid-template-columns: 86px minmax(0,1fr); gap: 12px; padding-bottom: 10px; border-bottom: 1px solid #edf1f5; }
.vendor-details dt { color: var(--muted); }
.vendor-details dd { margin: 0; font-weight: 800; word-break: break-word; }
.panel-title { display: grid; gap: 4px; }
.panel-title strong { font-size: 22px; }
.request-project-details { display: grid; gap: 12px; }
.stats-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 14px; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--line); border-left: 5px solid var(--blue); border-radius: 8px; padding: 14px; display: grid; gap: 6px; }
.stat span { color: var(--muted); font-size: 13px; font-weight: 700; }
.stat strong { font-size: 24px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1100px; }
th, td { padding: 13px 14px; border-bottom: 1px solid #edf1f5; text-align: left; vertical-align: top; font-size: 14px; }
th { color: #52616e; background: #f6f8fa; }
.sort-header { appearance: none; border: 0; background: transparent; color: inherit; font: inherit; font-weight: 900; padding: 6px 8px; margin: -6px -8px; min-height: 0; cursor: pointer; }
.sort-header.active { color: var(--blue); }
.amount { font-weight: 900; }
.muted { color: var(--muted); font-size: 12px; }
.status-select { min-width: 108px; min-height: 44px; padding: 8px; }
.vendor-list { display: grid; max-height: 650px; overflow: auto; }
.vendor-item { border-bottom: 1px solid #edf1f5; padding: 14px 16px; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 12px; align-items: center; }
.vendor-item strong { display: block; margin-bottom: 4px; }
.project-folder { border-bottom: 1px solid #dfe7ee; }
.project-folder:last-child { border-bottom: 0; }
.project-folder-title { position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; gap: 12px; padding: 12px 16px; background: #f6f8fa; border-bottom: 1px solid #edf1f5; color: #263744; font-weight: 900; }
.project-folder-title span { color: var(--muted); font-size: 12px; }
.empty-folder { padding: 14px 16px; }
.project-item { border-bottom: 1px solid #edf1f5; padding: 16px; display: grid; gap: 12px; }
.project-head, .project-summary, .project-line { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.project-head strong { display: block; margin-bottom: 4px; }
.project-summary { justify-content: flex-start; }
.compact-summary { margin-bottom: 4px; }
.project-summary span { background: #f0f4f6; border: 1px solid #dbe3ea; border-radius: 7px; padding: 8px 10px; font-size: 13px; font-weight: 800; }
.project-lines { display: grid; gap: 8px; }
.project-line { justify-content: flex-start; border-top: 1px solid #edf1f5; padding-top: 8px; font-size: 13px; }
.project-line.selected { border: 1px solid #b8d8ea; border-radius: 7px; padding: 8px 10px; background: #edf8fd; }
.request-project-lines .project-line { justify-content: space-between; }
.quote-builder { display: grid; gap: 12px; padding: 12px; border: 1px solid #dbe3ea; border-radius: 8px; background: #f9fbfc; }
.quote-builder-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; font-weight: 900; }
.quote-builder-head strong { color: var(--blue); }
.quote-rows { display: grid; gap: 10px; }
.quote-row { display: grid; grid-template-columns: minmax(120px,.9fr) minmax(120px,1fr) minmax(140px,1fr) auto; gap: 8px; align-items: center; }
.quote-row .quote-custom.hidden { display: none !important; }
.quote-row .quote-custom.hidden + .quote-amount { grid-column: span 2; }
.quote-row .icon-button { min-height: 44px; padding: 8px 10px; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 9px; background: #e7f4ef; color: #087458; font-size: 12px; font-weight: 800; }
.badge.warn { background: #fff2d8; color: #9a640d; }
.toast { position: fixed; right: 22px; bottom: calc(22px + env(safe-area-inset-bottom, 0px)); max-width: min(420px, calc(100vw - 44px)); background: #162734; color: #fff; padding: 12px 14px; border-radius: 8px; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); transition: .2s ease; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 30; flex-direction: row; align-items: center; gap: 12px; padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top, 0px)); box-shadow: 0 2px 10px rgba(10, 20, 30, .25); }
  .brand { flex: 1; gap: 10px; }
  .brand-mark { width: 36px; height: 36px; font-size: 15px; border-radius: 7px; }
  .brand h1 { font-size: 16px; }
  .brand p { margin-top: 2px; font-size: 12px; }
  .sidebar-panel { display: none; }
  .nav-tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; gap: 4px; background: var(--nav); padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px)); box-shadow: 0 -2px 10px rgba(10, 20, 30, .25); }
  .nav-tab { flex: 1; text-align: center; padding: 11px 4px; font-size: 13px; white-space: nowrap; }
  .content { padding: 18px 14px calc(86px + env(safe-area-inset-bottom, 0px)); }
  .two-column, .vendors-layout { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toast { left: 50%; right: auto; transform: translate(-50%, 12px); bottom: calc(84px + env(safe-area-inset-bottom, 0px)); width: max-content; }
  .toast.show { transform: translate(-50%, 0); }
}

@media (max-width: 680px) {
  .toolbar { align-items: flex-start; flex-direction: column; gap: 10px; margin-bottom: 16px; }
  .form-grid, .quote-row { grid-template-columns: 1fr; }
  .quote-row .quote-custom.hidden + .quote-amount { grid-column: auto; }
  .form-panel, .info-panel { padding: 16px; }
  .compact-filter input { width: 140px; }

  /* 請款清單改為卡片式，取代橫向捲動表格 */
  .table-wrap { overflow-x: visible; }
  table { min-width: 0; }
  thead { display: none; }
  table, tbody, tr, td { display: block; }
  tr { border: 1px solid var(--line); border-radius: 10px; margin: 10px 12px; background: #fff; overflow: hidden; }
  td { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 10px; align-items: start; border-bottom: 1px solid #f0f3f6; padding: 9px 14px; }
  td:last-child { border-bottom: 0; }
  td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 800; padding-top: 2px; }
  td[colspan] { grid-template-columns: 1fr; text-align: center; padding: 16px; }
  td[colspan]::before { display: none; }
}
