:root {
  --bg: #f4f6f9; --card: #fff; --ink: #1f2937; --muted: #6b7280; --line: #e5e7eb;
  --brand: #1d4ed8; --brand-dark: #1e40af; --ok: #059669; --warn: #d97706; --risk: #dc2626;
  --forecast: #059669; --upside: #2563eb; --pipeline: #6b7280;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.55; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Nav */
.nav { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; background: #fff;
  border-bottom: 1px solid var(--line); padding: 10px 18px; position: sticky; top: 0; z-index: 20; }
.nav a { color: #374151; font-weight: 500; }
.nav .brand { font-weight: 700; color: var(--brand); font-size: 16px; }
.nav .spacer { flex: 1; }
.nav .user-info { color: var(--muted); font-size: 13px; }
.nav .notif { position: relative; }
.badge { background: var(--risk); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 6px; margin-left: 3px; }
.link-btn { background: none; border: none; color: var(--brand); cursor: pointer; font-size: 15px; padding: 0; }
.inline { display: inline; }

.container { max-width: 1200px; margin: 0 auto; padding: 20px 18px 60px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 22px 0 10px; }
.subtitle { color: var(--muted); margin: 0 0 16px; }

/* Cards / KPI */
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.kpi .value.sm { font-size: 19px; }
.kpi.ok .value { color: var(--ok); } .kpi.warn .value { color: var(--warn); } .kpi.risk .value { color: var(--risk); }

/* Tables */
table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.table-wrap { overflow-x: auto; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; white-space: nowrap; }
th { background: #f9fafb; color: #374151; font-weight: 600; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Badges */
.tag { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.tag.FORECAST { background: #d1fae5; color: #065f46; }
.tag.UPSIDE { background: #dbeafe; color: #1e40af; }
.tag.PIPELINE { background: #f3f4f6; color: #374151; }
.tag.NONE { background: #f3f4f6; color: #9ca3af; }
.tag.st-COOKING { background: #fef3c7; color: #92400e; }
.tag.st-SIGNED_PENDING_PROJECT { background: #dbeafe; color: #1e40af; }
.tag.st-PROJECT_CREATED { background: #d1fae5; color: #065f46; }
.tag.st-DORMANT { background: #f3f4f6; color: #6b7280; }
.tag.st-LOST { background: #fee2e2; color: #991b1b; }
.tag.st-VOID { background: #f3f4f6; color: #9ca3af; }
.risk-row { background: #fef2f2; }

/* Forms */
form.stack { display: grid; gap: 12px; max-width: 640px; }
label { font-size: 13px; color: #374151; display: block; margin-bottom: 3px; font-weight: 500; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 7px; font-size: 14px; font-family: inherit; }
textarea { min-height: 70px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.btn { background: var(--brand); color: #fff; border: none; padding: 9px 16px; border-radius: 7px; font-size: 14px; cursor: pointer; font-weight: 600; }
.btn:hover { background: var(--brand-dark); }
.btn.ghost { background: #fff; color: var(--brand); border: 1px solid var(--brand); }
.btn.warn { background: var(--warn); } .btn.risk { background: var(--risk); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.hint { color: var(--muted); font-size: 12px; }
.error { background: #fee2e2; color: #991b1b; padding: 10px 12px; border-radius: 7px; margin-bottom: 12px; }
.ok-box { background: #d1fae5; color: #065f46; padding: 10px 12px; border-radius: 7px; margin-bottom: 12px; }

/* Login */
.login-wrap { max-width: 340px; margin: 8vh auto; }
.login-wrap .card { padding: 26px; }
.login-wrap h1 { text-align: center; margin-bottom: 18px; }

/* Detail */
.detail-header { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.detail-header .code { color: var(--muted); font-family: monospace; }
.section { margin-top: 18px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.reasons { list-style: none; padding: 0; margin: 6px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.reasons li { background: #eef2ff; color: #3730a3; padding: 2px 9px; border-radius: 20px; font-size: 12px; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { border-left: 2px solid var(--line); padding: 0 0 14px 14px; position: relative; }
.timeline li::before { content: ''; position: absolute; left: -5px; top: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }
.timeline .meta { color: var(--muted); font-size: 12px; }
details.panel { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; background: #fff; margin-top: 10px; }
details.panel > summary { cursor: pointer; font-weight: 600; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.pill-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.pill-row a { background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 5px 12px; color: #374151; font-size: 13px; }
.pill-row a.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* Mobile: 表格轉卡片 */
@media (max-width: 720px) {
  .nav { gap: 10px; }
  .card-list table, .card-list thead { display: none; }
  .card-list tbody, .card-list tr, .card-list td { display: block; width: 100%; }
  .card-list tr { background: #fff; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; padding: 8px; }
  .card-list td { border: none; white-space: normal; padding: 4px 6px; }
  .card-list td::before { content: attr(data-label) "："; color: var(--muted); font-weight: 600; }
  .row2, .row3 { grid-template-columns: 1fr; }
}
