﻿:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef3ef;
  --ink: #17201a;
  --muted: #667168;
  --line: #dce3dd;
  --brand: #146c5c;
  --brand-2: #0f8b72;
  --amber: #b97312;
  --red: #ba2d2d;
  --blue: #256f9c;
  --violet: #6554a8;
  --radius: 8px;
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); }
button, input, select { font: inherit; }

.app-shell { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; display: flex; flex-direction: column; gap: 16px; height: 100vh; min-height: 0; padding: 20px; background: #18231d; color: #f8fbf8; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 8px; background: #e6a63b; color: #18231d; font-weight: 800; }
.brand h1, .topbar h2, .panel h3, .plan-card h3 { margin: 0; letter-spacing: 0; }
.brand h1 { font-size: 18px; }
.brand p, .sidebar-panel small, .eyebrow, .task-table small, .progress-title span, .progress-facts, .kpi-card small, .plan-card p { color: var(--muted); }
.brand p { margin: 4px 0 0; color: #b9c7bd; font-size: 13px; }

.project-list { display: grid; gap: 5px; min-height: 0; overflow-y: auto; padding-right: 4px; scrollbar-color: #607266 #202d25; scrollbar-width: thin; }
.project-list::-webkit-scrollbar { width: 8px; }
.project-list::-webkit-scrollbar-track { background: #202d25; border-radius: 999px; }
.project-list::-webkit-scrollbar-thumb { background: #607266; border-radius: 999px; }
.project-list button, .risk-item { width: 100%; border: 1px solid transparent; border-radius: var(--radius); cursor: pointer; text-align: left; }
.project-list button { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; min-height: 38px; padding: 8px 9px; background: transparent; color: #f8fbf8; }
.project-list button:hover, .project-list button.active { background: #243229; border-color: #405145; }
.project-list span { overflow: hidden; font-size: 13px; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.project-list strong { color: #b8e1d6; font-size: 11px; white-space: nowrap; }
.sidebar-panel { flex: 0 0 auto; padding: 12px; border: 1px solid #35463b; border-radius: var(--radius); background: #202d25; }
.sidebar-panel strong, .sidebar-panel small, .panel-label { display: block; }
.sidebar-panel strong { margin: 8px 0; font-size: 13px; line-height: 1.5; word-break: break-all; }
.panel-label, .eyebrow { color: #7e8a81; font-size: 12px; font-weight: 700; text-transform: uppercase; }

.workspace { min-width: 0; padding: 26px; }
.topbar, .panel-header, .table-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.topbar { margin-bottom: 22px; }
.topbar h2 { margin-top: 4px; font-size: 28px; }
.toolbar, .filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.view-tabs { display: inline-flex; padding: 4px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.view-tabs button { min-height: 32px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; }
.view-tabs button.active { background: #18231d; color: #fff; }
.search-box { display: flex; align-items: center; gap: 8px; min-width: 300px; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--muted); }
.search-box input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); }
.icon-button, select { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); }
.icon-button { width: 42px; height: 42px; cursor: pointer; font-size: 20px; }
select { min-height: 38px; padding: 0 34px 0 12px; }

.hidden-view { display: none !important; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi-card, .panel, .plan-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.kpi-card { padding: 16px; }
.kpi-card span { color: var(--muted); font-size: 13px; }
.kpi-card strong { display: block; margin: 8px 0 4px; font-size: 26px; }
.sync-status { display: grid; gap: 10px; margin-bottom: 16px; }
.sync-card-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.sync-card { min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: #fbfcfb; }
.sync-card span { color: var(--muted); font-size: 12px; }
.sync-card strong { display: block; overflow: hidden; margin: 6px 0 3px; color: var(--ink); font-size: 18px; text-overflow: ellipsis; white-space: nowrap; }
.sync-card small { display: block; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.sync-warning { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 12px; border: 1px solid #e4c993; border-radius: var(--radius); background: #fff8ea; color: #73500a; font-size: 13px; }
.sync-warning.danger { border-color: #e5adad; background: #fff1f1; color: var(--red); }
.sync-warning strong { margin-right: 4px; }
.sync-warning span { padding: 3px 8px; border-radius: 999px; background: rgba(255,255,255,.75); }
.sync-command { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px; border: 1px solid #cbd8d0; border-radius: var(--radius); background: #f3f7f4; color: var(--ink); font-size: 13px; }
.sync-command span { color: var(--muted); font-weight: 700; }
.sync-command code { padding: 4px 8px; border-radius: 6px; background: #18231d; color: #f8fbf8; font-size: 12px; }
.sync-command small { color: var(--muted); }
.sync-action-button { min-height: 34px; padding: 0 14px; border: 0; border-radius: 6px; background: var(--brand); color: #fff; cursor: pointer; font-weight: 700; }
.sync-action-button:hover { background: #21382b; }
.sync-action-button:disabled { cursor: progress; opacity: .7; }
.sync-live-status { padding: 4px 8px; border-radius: 6px; background: #eef4ef; color: var(--brand); }
.sync-live-status.done { background: #dcefe8; color: var(--brand); }
.sync-live-status.danger { background: #fff1f1; color: var(--red); }
.sync-log { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: #fbfcfb; }
.sync-log summary { cursor: pointer; padding: 9px 12px; color: var(--muted); font-size: 13px; font-weight: 700; }
.sync-log pre { max-height: 180px; margin: 0; padding: 10px 12px; overflow: auto; border-top: 1px solid var(--line); background: #18231d; color: #f8fbf8; font-size: 12px; line-height: 1.6; white-space: pre-wrap; }
.sync-history { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.sync-history summary { cursor: pointer; padding: 9px 12px; color: var(--muted); font-size: 13px; font-weight: 700; }
.sync-history table { width: 100%; border-collapse: collapse; border-top: 1px solid var(--line); font-size: 12px; }
.sync-history th, .sync-history td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.sync-history th { color: var(--muted); font-weight: 700; }
.sync-history-status { display: inline-flex; align-items: center; min-height: 22px; padding: 0 8px; border-radius: 999px; font-weight: 700; }
.sync-history-status.done { background: #dcefe8; color: var(--brand); }
.sync-history-status.danger { background: #fff1f1; color: var(--red); }
.mapping-panel { margin-bottom: 16px; }
.mapping-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.mapping-card { display: grid; gap: 12px; min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: #fbfcfb; }
.mapping-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.mapping-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mapping-title span, .mapping-card dt, .mapping-stats span { color: var(--muted); font-size: 12px; }
.mapping-card dl { display: grid; gap: 8px; margin: 0; }
.mapping-card dl div { display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 8px; }
.mapping-card dt, .mapping-card dd { margin: 0; }
.mapping-card dd { overflow: hidden; color: var(--ink); text-overflow: ellipsis; white-space: nowrap; }
.mapping-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.mapping-stats span { padding: 8px; border-radius: var(--radius); background: var(--surface-2); }
.mapping-stats strong { display: block; margin-top: 2px; color: var(--ink); font-size: 18px; }
.mapping-quality { min-height: 24px; }
.settlement-panel { margin-bottom: 16px; }
.settlement-period { padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); color: var(--ink); font-weight: 700; }
.settlement-kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); margin: 14px 0; }
.settlement-kpis .kpi-card { padding: 12px; }
.settlement-kpis .kpi-card strong { font-size: 22px; }
.settlement-table-wrap { max-height: 340px; }
.settlement-table { min-width: 1060px; }
.alert-panel { margin-bottom: 16px; }
.alert-kpis { grid-template-columns: repeat(7, minmax(0, 1fr)); margin: 14px 0; }
.alert-kpis .kpi-card { padding: 12px; }
.alert-kpis .kpi-card strong { font-size: 22px; }
.alert-table-wrap { max-height: 360px; }
.alert-table { min-width: 1060px; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; margin-bottom: 16px; }
.panel { padding: 18px; }

.project-progress { display: grid; gap: 18px; margin-top: 18px; }
.progress-title, .progress-facts { display: flex; justify-content: space-between; gap: 12px; }
.progress-facts { margin-top: 7px; font-size: 12px; }
.bar { overflow: hidden; height: 10px; margin-top: 8px; border-radius: 999px; background: var(--surface-2); }
.bar span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--brand), #d79936); }

.risk-list { display: grid; gap: 8px; margin-top: 12px; }
.risk-item { display: grid; grid-template-columns: 88px minmax(180px, 1fr) minmax(260px, .8fr); align-items: center; gap: 12px; min-height: 54px; padding: 9px 12px; background: #fafbf9; color: var(--ink); }
.risk-item:hover { border-color: #b7c9bd; }
.risk-item strong { overflow: hidden; font-size: 16px; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.risk-item small { overflow: hidden; color: var(--muted); font-size: 13px; line-height: 1.35; text-align: right; text-overflow: ellipsis; white-space: nowrap; }
.risk-badge, .status-pill { display: inline-flex; align-items: center; width: fit-content; min-height: 24px; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.risk-badge.danger, .date.danger { color: var(--red); }
.risk-badge.warning, .date.warning { color: var(--amber); }
.risk-badge.neutral { color: var(--blue); }
.status-pill.done { background: #dcefe8; color: var(--brand); }
.status-pill.pending, .status-pill.waiting { background: #f7ead5; color: var(--amber); }
.status-pill.review, .status-pill.active { background: #dfeaf2; color: var(--blue); }
.status-pill.outsourced { background: #ebe6f6; color: var(--violet); }
.status-pill.paused, .status-pill.unknown, .status-pill.other { background: #ecefed; color: #59635c; }

.plan-hero { display: grid; gap: 12px; margin-bottom: 16px; }
.plan-card { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(280px, .8fr); gap: 16px; padding: 18px; }
.plan-card h3 { margin-top: 4px; font-size: 24px; }
.plan-card p { margin: 8px 0 0; }
.plan-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; align-content: start; }
.plan-metrics span { padding: 10px; border-radius: var(--radius); background: #f3f6f3; color: var(--muted); }
.plan-metrics strong { display: block; color: var(--ink); font-size: 20px; }
.plan-card .bar { grid-column: 1 / -1; }

.project-detail-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.project-detail-top select { min-width: 220px; }
.project-detail-hero { margin-bottom: 16px; }
.project-detail-card { margin-bottom: 0; }
.project-detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.project-detail-table-wrap { max-height: 44vh; }
.project-detail-table { min-width: 940px; }
.project-detail-task-wrap { max-height: 62vh; }
.project-detail-task-table { min-width: 1240px; }
.project-detail-table a, .project-detail-task-table a { color: var(--brand); font-weight: 700; text-decoration: none; }
.project-detail-table a:hover, .project-detail-task-table a:hover { text-decoration: underline; }

.batch-top-filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.batch-top-filters select { min-width: 180px; }
.batch-summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.summary-panel { min-width: 0; }
.summary-list { display: grid; gap: 8px; margin-top: 14px; }
.summary-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: #fbfcfb; color: var(--ink); cursor: pointer; text-align: left; }
.summary-row:hover { border-color: #b7c9bd; background: #f3f6f3; }
.summary-row span { color: var(--muted); font-size: 13px; text-align: right; }
.settlement-quality-panel { margin-bottom: 16px; }
.quality-count { color: var(--muted); font-size: 13px; font-weight: 700; }
.quality-issue-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 12px 0; }
.quality-issue-tabs button { min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: #fbfcfb; color: var(--ink); cursor: pointer; text-align: left; }
.quality-issue-tabs button:hover, .quality-issue-tabs button.active { border-color: #9fb7a8; background: #eef4ef; }
.quality-issue-tabs span, .quality-issue-tabs small { display: block; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.quality-issue-tabs strong { display: block; margin: 5px 0 2px; color: var(--ink); font-size: 20px; }
.quality-table-wrap { max-height: 48vh; }
.quality-table { min-width: 1180px; }
.quality-table a { color: var(--brand); font-weight: 700; text-decoration: none; }
.quality-table a:hover { text-decoration: underline; }
.billing-top-filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.billing-top-filters select { min-width: 180px; }
.billing-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); gap: 16px; margin-bottom: 16px; }
.billing-table-wrap { max-height: 42vh; }
.billing-table { min-width: 880px; }
.billing-project-wrap { max-height: 58vh; }
.billing-project-table { min-width: 1320px; }

.table-header { align-items: flex-start; }
.table-meta { margin: 12px 0; color: var(--muted); font-size: 13px; }
.task-table-wrap { overflow: auto; max-height: 58vh; border: 1px solid var(--line); border-radius: var(--radius); }
.batch-table-wrap { max-height: 64vh; }
.task-table { width: 100%; min-width: 1080px; border-collapse: collapse; font-size: 14px; }
.batch-table { min-width: 1160px; }
.task-table th, .task-table td { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.task-table th { position: sticky; top: 0; z-index: 1; background: #edf2ee; color: #435047; font-size: 12px; text-transform: uppercase; }
.task-table td:first-child { max-width: 360px; }
.task-table strong, .task-table small { display: block; }
.task-table small { margin-top: 4px; line-height: 1.4; }
.sub-row td:first-child { padding-left: 28px; }
.sub-row td:first-child strong::before { content: "↳ "; color: var(--muted); }

.stage-rail { display: flex; gap: 6px; flex-wrap: wrap; min-width: 260px; }
.stage-dot { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 999px; background: #ecefed; color: #68736b; font-size: 12px; font-weight: 700; }
.stage-dot.done { background: #dcefe8; color: var(--brand); }
.mini-tag { display: inline-flex; align-items: center; min-height: 22px; margin: 0 4px 4px 0; padding: 2px 7px; border-radius: 999px; background: #f7ead5; color: var(--amber); font-size: 12px; font-weight: 700; }
.mini-tag.danger { background: #fff1f1; color: var(--red); }
.muted, .empty-state, .empty-row { color: var(--muted); }
.empty-row, .empty-state { padding: 18px; text-align: center; }
.error-screen { max-width: 640px; margin: 80px auto; padding: 24px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .kpi-grid, .dashboard-grid, .plan-card, .project-detail-grid, .batch-summary-grid, .billing-grid, .mapping-grid, .sync-card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settlement-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .alert-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .workspace { padding: 16px; }
  .topbar, .panel-header, .table-header { align-items: stretch; flex-direction: column; }
  .search-box { min-width: 0; width: 100%; }
  .kpi-grid, .dashboard-grid, .plan-card, .plan-metrics, .project-detail-grid, .batch-summary-grid, .billing-grid, .mapping-grid, .sync-card-grid { grid-template-columns: 1fr; }
  .settlement-kpis { grid-template-columns: 1fr; }
  .alert-kpis { grid-template-columns: 1fr; }
  .risk-item { grid-template-columns: 1fr; align-items: flex-start; gap: 6px; }
  .risk-item small { text-align: left; white-space: normal; }
  .summary-row { align-items: flex-start; flex-direction: column; }
  .summary-row span { text-align: left; }
}

.portfolio-table-wrap {
  max-height: 68vh;
}

.portfolio-table {
  min-width: 1220px;
}

.unconfigured-row {
  background: #fbfcfb;
}

.unconfigured-row td {
  color: #6f7b72;
}
