:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --sidebar: #1e293b;
  --sidebar-hover: #334155;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --blue: #2563eb;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

button { font-family: inherit; }

/* ---------- 角色選擇頁 ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  padding: 24px;
}
.login-brand { color: #fff; text-align: center; margin-bottom: 32px; }
.login-brand h1 { font-size: 28px; letter-spacing: 2px; }
.login-brand p { color: #94a3b8; margin-top: 8px; }
.login-cards { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; max-width: 980px; }
.login-card {
  background: var(--card);
  border-radius: 12px;
  padding: 24px 20px;
  width: 175px;
  text-align: center;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform .15s, border-color .15s;
}
.login-card:hover { transform: translateY(-4px); border-color: var(--primary); }
.login-card .avatar {
  width: 56px; height: 56px; border-radius: 50%;
  background: #e0e7ff; color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700; margin: 0 auto 12px;
}
.login-card h3 { font-size: 16px; margin-bottom: 6px; }
.login-card .desc { color: var(--muted); font-size: 12px; line-height: 1.5; margin-top: 8px; }
.login-foot { margin-top: 36px; color: #94a3b8; font-size: 12px; text-align: center; }
.login-foot button {
  margin-top: 10px; background: none; border: 1px solid #475569;
  color: #94a3b8; padding: 6px 14px; border-radius: 6px; cursor: pointer;
}
.login-foot button:hover { color: #fff; border-color: #94a3b8; }

/* ---------- 主版面 ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 210px; min-width: 210px;
  background: var(--sidebar); color: #cbd5e1;
  display: flex; flex-direction: column;
}
.sidebar .brand { padding: 20px 18px; color: #fff; font-size: 18px; font-weight: 700; letter-spacing: 1px; }
.sidebar .brand small { display: block; font-size: 11px; color: #94a3b8; font-weight: 400; margin-top: 4px; }
.sidebar nav { flex: 1; padding: 8px 0; }
.sidebar nav a {
  display: block; padding: 11px 18px; color: #cbd5e1;
  text-decoration: none; font-size: 14px; border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar nav a.active { background: var(--sidebar-hover); color: #fff; border-left-color: var(--primary); }
.sidebar .side-foot { padding: 14px 18px; font-size: 11px; color: #64748b; border-top: 1px solid #334155; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: 0 24px; height: 56px;
  display: flex; align-items: center; justify-content: space-between;
}
.topbar h2 { font-size: 17px; }
.topbar .user-box { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.topbar .user-box a { color: var(--primary); text-decoration: none; }

.page { padding: 24px; max-width: 1280px; width: 100%; }

/* ---------- 卡片與統計 ---------- */
.cards { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 18px; flex: 1; min-width: 150px;
}
.stat-card .label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.stat-card .value { font-size: 20px; font-weight: 700; }
.stat-card .value.green { color: var(--green); }
.stat-card .value.red { color: var(--red); }
.stat-card .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 18px; margin-bottom: 20px;
}
.card h3 { font-size: 15px; margin-bottom: 12px; }
.card h3 .hint { font-weight: 400; font-size: 12px; color: var(--muted); margin-left: 8px; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-head h3 { font-size: 15px; }

/* ---------- 表格 ---------- */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left; font-size: 12px; color: var(--muted); font-weight: 600;
  padding: 8px 10px; border-bottom: 2px solid var(--border); white-space: nowrap;
}
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl td:first-child { min-width: 130px; }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.clickable:hover { background: #f8fafc; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl .empty { color: var(--muted); text-align: center; padding: 20px; }
.tbl tr.detail-row > td { background: #f8fafc; padding: 14px 16px 16px 32px; }
.tbl .sub-tbl td { background: transparent; }

/* ---------- 狀態標籤 ---------- */
.chip {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; white-space: nowrap;
}
.chip-gray  { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }
.chip-blue  { background: #dbeafe; color: #1d4ed8; }
.chip-amber { background: #fef3c7; color: #b45309; }
.chip-green { background: #dcfce7; color: #15803d; }
.chip-red   { background: #fee2e2; color: #b91c1c; }

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-block; padding: 7px 14px; border-radius: 7px;
  border: 1px solid transparent; cursor: pointer; font-size: 13px;
  text-decoration: none; background: #e2e8f0; color: var(--text);
}
.btn:hover { filter: brightness(.96); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.green { background: var(--green); color: #fff; }
.btn.amber { background: var(--amber); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { background: none; border: none; font-size: 15px; cursor: pointer; color: var(--muted); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 進度條 ---------- */
.bar-wrap { display: flex; align-items: center; gap: 8px; min-width: 110px; }
.bar { flex: 1; height: 8px; background: #e2e8f0; border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 4px; }
.bar-num { font-size: 12px; color: var(--muted); min-width: 32px; text-align: right; }

/* ---------- FAQ 卡片 ---------- */
.faq-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; margin-bottom: 20px; }
.faq-card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.faq-card h4 { font-size: 14px; margin-bottom: 4px; }
.faq-card .q { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.faq-card ul { list-style: none; }
.faq-card li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 0; border-bottom: 1px dashed var(--border); font-size: 13px;
}
.faq-card li:last-child { border-bottom: none; }
.faq-card li .who { flex: 1; min-width: 0; }
.faq-card li .who small { display: block; color: var(--muted); }
.faq-card li .amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.faq-card .none { color: var(--muted); font-size: 13px; padding: 6px 0; }

/* ---------- 指引 ---------- */
details.guide {
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 10px;
  padding: 12px 16px; margin-bottom: 20px;
}
details.guide summary { cursor: pointer; font-weight: 600; color: var(--primary-dark); font-size: 14px; }
details.guide ol { margin: 10px 0 4px 22px; line-height: 1.9; font-size: 13px; }

/* ---------- 表單與彈窗 ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal {
  background: var(--card); border-radius: 12px; width: 460px; max-width: 100%;
  max-height: 90vh; overflow-y: auto; padding: 20px 22px;
}
.modal.modal-wide { width: 680px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { font-size: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px;
  font-size: 14px; font-family: inherit; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary);
}
.field .note { font-size: 12px; color: var(--muted); margin-top: 4px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.checkbox-field { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-size: 13px; }
.checkbox-field input { width: auto; }

.cmp-box {
  background: #f8fafc; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; margin-bottom: 12px; font-size: 13px;
}
.cmp-box h4 { font-size: 13px; margin-bottom: 8px; }
.cmp-box table { width: 100%; border-collapse: collapse; font-size: 12px; }
.cmp-box th { text-align: left; color: var(--muted); padding: 4px 6px; border-bottom: 1px solid var(--border); }
.cmp-box td { padding: 4px 6px; border-bottom: 1px dashed var(--border); }

/* ---------- 其他 ---------- */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mb0 { margin-bottom: 0; }
.profit-pos { color: var(--green); font-weight: 600; }
.profit-neg { color: var(--red); font-weight: 600; }
.breadcrumb { font-size: 13px; margin-bottom: 14px; }
.breadcrumb a { color: var(--primary); text-decoration: none; }
.proj-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.proj-head h2 { font-size: 20px; margin-bottom: 6px; }
.proj-head .meta { color: var(--muted); font-size: 13px; line-height: 1.7; }
.lock { color: var(--muted); font-size: 12px; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; min-width: 0; }
  .sidebar nav { display: flex; flex-wrap: wrap; }
  .sidebar nav a { border-left: none; }
}
