:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary: #7c3aed;
  --bg: #f8fafc;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --row-hover: #f1f5f9;
  --paid-bg: #dcfce7;
  --paid-border: #86efac;
  --unpaid-bg: #fef3c7;
  --unpaid-border: #fcd34d;
  --amend-bg: #ddd6fe;
  --amend-border: #c4b5fd;
  --danger: #dc2626;
  --shadow: 0 4px 12px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
}

header {
  background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 14px 28px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white; display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700;
  box-shadow: 0 4px 12px rgba(37,99,235,0.25);
}
.title { font-size: 17px; font-weight: 600; }
.version-tag {
  font-size: 11px; font-weight: 500;
  color: var(--primary); background: #eff6ff;
  border: 1px solid #bfdbfe; padding: 1px 8px; border-radius: 10px;
  margin-left: 6px; vertical-align: middle;
}
.subtitle { font-size: 12px; color: var(--muted); }

nav { display: flex; gap: 4px; }
.nav-btn {
  background: transparent; border: none; padding: 8px 16px;
  font-size: 14px; cursor: pointer; border-radius: 8px; color: var(--muted);
  font-family: inherit;
}
.nav-btn:hover { background: var(--row-hover); color: var(--text); }
.nav-btn.active { background: var(--primary); color: white; }

.user-info { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.user-info #user-name { font-weight: 500; color: var(--text); }
.btn-logout {
  background: white; border: 1px solid var(--border); color: var(--text);
  padding: 6px 12px; border-radius: 7px; font-size: 13px; cursor: pointer;
  font-family: inherit;
}
.btn-logout:hover { background: var(--row-hover); color: var(--danger); border-color: var(--danger); }

main { max-width: 1400px; margin: 0 auto; padding: 24px 28px; }
.tab { display: none; }
.tab.active { display: block; }

/* ── 工具列、篩選 ─────────────────────────────────────── */
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; }
.filters { display: flex; gap: 8px; flex: 1; }
.filters input {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 7px;
  font-family: inherit; font-size: 14px; min-width: 280px;
}
.filters input:focus { outline: none; border-color: var(--primary); }
.muted { color: var(--muted); }

/* 標籤式快速篩選 */
.filter-tags-wrap {
  background: white; border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 16px; margin-bottom: 16px;
}
.filter-tag-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 6px 0; border-bottom: 1px dashed #f1f5f9;
}
.filter-tag-row:last-child { border-bottom: none; }
.filter-label {
  font-size: 13px; font-weight: 500; color: var(--muted);
  min-width: 80px; padding-top: 4px;
}
.filter-tags { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; }
.filter-tag {
  background: white; border: 1px solid var(--border); color: var(--text);
  padding: 4px 12px; border-radius: 14px; font-size: 13px;
  cursor: pointer; font-family: inherit; transition: all 0.15s;
}
.filter-tag:hover { border-color: var(--primary); color: var(--primary); }
.filter-tag.active { background: var(--primary); color: white; border-color: var(--primary); }

/* ── 表格 ───────────────────────────────────────────── */
.table-wrap {
  background: white; border: 1px solid var(--border); border-radius: 12px;
  overflow: auto;
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
th { background: #f8fafc; font-weight: 500; color: var(--muted); font-size: 13px; }
tbody tr:hover { background: var(--row-hover); }
tbody tr:last-child td { border-bottom: none; }
td.amount { font-variant-numeric: tabular-nums; font-weight: 500; }
.proj-name { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.empty-row { color: var(--muted); text-align: center; padding: 30px; }

/* 進度條 */
.progress { background: #e2e8f0; height: 6px; border-radius: 3px; overflow: hidden; margin-top: 4px; }
.progress-bar { background: var(--primary); height: 100%; transition: width 0.3s; }

/* ── 標籤 ───────────────────────────────────────────── */
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 500;
}
.tag-paid { background: var(--paid-bg); color: #065f46; border: 1px solid var(--paid-border); }
.tag-unpaid { background: var(--unpaid-bg); color: #92400e; border: 1px solid var(--unpaid-border); }
.tag-amend { background: var(--amend-bg); color: #5b21b6; border: 1px solid var(--amend-border); }

/* ── 按鈕 ───────────────────────────────────────────── */
.btn-primary {
  background: var(--primary); color: white; border: none;
  padding: 9px 16px; border-radius: 7px; cursor: pointer;
  font-size: 14px; font-family: inherit;
}
.btn-primary:hover { filter: brightness(0.92); }
.btn-primary.btn-sm, .btn-ghost.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-ghost {
  background: white; border: 1px solid var(--border); color: var(--text);
  padding: 9px 16px; border-radius: 7px; cursor: pointer;
  font-size: 14px; font-family: inherit;
}
.btn-ghost:hover { background: var(--row-hover); }
.btn-mini {
  background: white; border: 1px solid var(--border); color: var(--text);
  padding: 4px 10px; border-radius: 6px; cursor: pointer;
  font-size: 12px; font-family: inherit; margin-right: 4px;
}
.btn-mini:hover { background: var(--primary); color: white; border-color: var(--primary); }
.btn-mini.btn-danger:hover { background: var(--danger); border-color: var(--danger); }
.btn-close {
  background: transparent; border: none; font-size: 22px; cursor: pointer;
  color: var(--muted); padding: 0; width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
}
.btn-close:hover { color: var(--text); }

/* ── ⭐ 名字風格 A：藍紫漸層（無頭像） ───────────────── */
.person-avatar {
  /* 風格 A：頭像不顯示 */
  display: none;
}
.person-tag {
  display: inline-flex; align-items: center; gap: 6px;
  background: #f1f5f9; padding: 2px 12px; border-radius: 14px;
  font-size: 13px;
}

/* ── 個人總覽 ──────────────────────────────────────── */
.person-card {
  background: white; border: 1px solid var(--border);
  border-radius: 12px; margin-bottom: 14px; overflow: hidden;
}
.person-card-head {
  padding: 14px 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid transparent;
  transition: background 0.15s;
}
.person-card-head:hover { background: var(--row-hover); }
.person-card.expanded .person-card-head { border-bottom-color: var(--border); }
.person-card-name {
  display: flex; align-items: center; gap: 10px;
  font-size: 18px; font-weight: 700;
}
.person-card-name .name-text {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.5px;
}
.person-card-stats { display: flex; gap: 20px; align-items: center; }
.stat-item { font-size: 13px; }
.stat-item .stat-label { color: var(--muted); margin-right: 4px; }
.stat-item .stat-value { font-weight: 500; font-variant-numeric: tabular-nums; }
.stat-item.unpaid .stat-value { color: #92400e; }
.stat-item.paid .stat-value { color: #065f46; }
.stat-item.total .stat-value { color: var(--primary); font-size: 15px; font-weight: 600; }
.expand-icon { font-size: 12px; color: var(--muted); transition: transform 0.2s; }
.person-card.expanded .expand-icon { transform: rotate(180deg); }
.person-card-body { display: none; padding: 0; }
.person-card.expanded .person-card-body { display: block; }
.person-share-link { color: var(--primary); cursor: pointer; }
.person-share-link:hover { text-decoration: underline; }

/* ── 個人標案明細 modal ──────────────────────────────── */
.ps-meta {
  background: #f8fafc; border-radius: 8px; padding: 14px 16px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.ps-meta-item { font-size: 13px; }
.ps-meta-item .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.ps-meta-item .value { font-weight: 500; margin-top: 2px; }
.ps-meta-item.highlight .value { color: var(--primary); font-size: 16px; font-weight: 600; }

/* ── 設定中心 ──────────────────────────────────────── */
.settings-tabs {
  display: flex; gap: 4px; border-bottom: 2px solid var(--border);
  margin-bottom: 18px;
}
.settings-tab {
  background: transparent; border: none; padding: 10px 20px;
  font-size: 14px; cursor: pointer; color: var(--muted); font-family: inherit;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.settings-tab:hover { color: var(--text); }
.settings-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }
.settings-panel { display: none; }
.settings-panel.active { display: block; }

/* ── Modal ─────────────────────────────────────────── */
.modal[hidden] { display: none !important; }
.modal {
  position: fixed; inset: 0; background: rgba(15,23,42,.55);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  padding: 20px;
}
.modal-card {
  background: white; border-radius: 14px; box-shadow: var(--shadow);
  max-height: 92vh; display: flex; flex-direction: column;
  width: 480px; overflow: hidden;
}
.modal-card.large { width: 880px; max-width: 100%; }
.modal-head {
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-body label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--text); }
.modal-body label input[type=text],
.modal-body label input[type=number],
.modal-body label input[type=password],
.modal-body label select {
  display: block; width: 100%; padding: 9px 12px; margin-top: 4px;
  border: 1px solid var(--border); border-radius: 7px;
  font-size: 14px; font-family: inherit; box-sizing: border-box;
}
.modal-foot {
  padding: 14px 22px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sec-title { font-size: 14px; font-weight: 500; margin: 16px 0 8px; color: var(--muted); }

/* phase / share rows */
.phase-row, .share-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: #f8fafc; border-radius: 7px; margin-bottom: 6px;
}
.phase-row .phase-no { min-width: 60px; font-weight: 500; }
.phase-row input { width: 90px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 5px; font-family: inherit; }
.share-row label { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 12px; }
.share-row input { width: 80px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 5px; font-family: inherit; }
.add-share-row { display: flex; gap: 8px; margin-top: 8px; }
.add-share-row select { flex: 1; padding: 8px 12px; border: 1px solid var(--border); border-radius: 7px; font-family: inherit; }
.preview {
  margin-top: 18px; padding: 14px; background: #eff6ff;
  border: 1px solid #bfdbfe; border-radius: 9px;
}
.preview table th, .preview table td { border-bottom: 1px solid #cbd5e1; padding: 6px 8px; }

/* 登入錯誤 */
.login-error {
  background: #fef2f2; border: 1px solid #fecaca; color: #991b1b;
  padding: 8px 12px; border-radius: 7px; font-size: 13px;
  display: none;
}
.login-error.show { display: block; }

/* ── Toast ────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: white; padding: 10px 18px;
  border-radius: 8px; font-size: 13px; z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

/* ── v2.4.0:多選總計 sticky bar ──────────────────── */
.select-sum-bar {
  position: sticky; bottom: 0;
  background: white;
  border: 1px solid #e2e8f0;
  border-top: 2px solid #7c3aed;
  border-radius: 0 0 12px 12px;
  padding: 12px 18px;
  display: flex; align-items: center; gap: 10px;
  font-size: 14px;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.06);
  z-index: 10;
  margin-top: -1px;
}
.select-sum-bar[hidden] { display: none !important; }

.proj-row-cb, .sum-row-cb {
  cursor: pointer;
  width: 16px; height: 16px;
}
#proj-select-all { cursor: pointer; width: 16px; height: 16px; }
