:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --border: #e4e8f0;
  --border-soft: #eef1f6;
  --text: #1a2233;
  --text-2: #5a6478;
  --text-3: #8d97ab;
  --primary: #2f6bff;
  --primary-soft: #eaf1ff;
  --success: #12a150;
  --warn: #f0a020;
  --danger: #e5484d;
  --purple: #7c5cff;
  --teal: #0fa3a3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .05);
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary); text-decoration: none; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 216px; flex: 0 0 216px;
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex: 0 0 34px;
  background: linear-gradient(135deg, #2f6bff, #7c5cff);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; letter-spacing: -.5px;
}
.brand-text b { display: block; font-size: 14px; line-height: 1.3; }
.brand-text span { display: block; font-size: 11px; color: var(--text-3); }

.nav-group { margin-top: 14px; }
.nav-label { font-size: 11px; color: var(--text-3); padding: 0 10px 6px; letter-spacing: .5px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 9px;
  color: var(--text-2); font-size: 13.5px;
  border: none; background: none; width: 100%; text-align: left;
  transition: background .15s;
}
.nav-item:hover { background: #f3f5f9; color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item .ico { width: 18px; text-align: center; opacity: .85; font-size: 14px; }
.nav-item .badge {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: 10.5px; padding: 1px 6px; border-radius: 9px; font-weight: 600;
}

.main { flex: 1; min-width: 0; padding: 22px 28px 60px; }

.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar h1 { margin: 0; font-size: 21px; font-weight: 650; letter-spacing: -.3px; }
.topbar p { margin: 3px 0 0; color: var(--text-3); font-size: 12.5px; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.sync-status {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; padding: 4px 9px; border-radius: 999px;
  border: 1px solid transparent; white-space: nowrap; max-width: 220px;
  overflow: hidden; text-overflow: ellipsis;
}
.sync-status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.sync-status.ok { color: #1a7f4b; background: #e9f7ef; border-color: #bfe6cf; }
.sync-status.local { color: #8a6d1a; background: #fff7e0; border-color: #f0e0a8; }
.sync-status.offline { color: #8a4b1a; background: #fdf0e6; border-color: #f0d6bf; }
.sync-status.loading { color: #1a4b7f; background: #e6f0fb; border-color: #b8d4ef; }
.sync-status.loading::before { animation: sync-pulse 0.9s linear infinite; }
@keyframes sync-pulse { 0% { opacity: 0.3; } 50% { opacity: 1; } 100% { opacity: 0.3; } }
.sync-status:empty { display: none; }

.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text-2);
  padding: 7px 13px; border-radius: 8px; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all .15s;
}
.btn:hover { border-color: #c9d2e3; color: var(--text); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #2559df; }
.btn.danger { color: var(--danger); border-color: #f3c9ca; }
.btn.danger:hover { background: #fdf1f1; }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #f1f3f8; }

/* ---------- Cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head {
  padding: 14px 18px; border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.card-head h3 { margin: 0; font-size: 14.5px; font-weight: 650; }
.card-head .sub { font-size: 12px; color: var(--text-3); }
.card-body { padding: 16px 18px; }
.card-body.tight { padding: 8px 18px 14px; }

.grid { display: grid; gap: 14px; }
.grid.kpi { grid-template-columns: repeat(5, 1fr); }
.grid.g2 { grid-template-columns: 1.35fr 1fr; }
.grid.g2e { grid-template-columns: 1fr 1fr; }
.grid.g3 { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 1280px) {
  .grid.kpi { grid-template-columns: repeat(3, 1fr); }
  .grid.g2, .grid.g2e, .grid.g3 { grid-template-columns: 1fr; }
}

/* ---------- KPI ---------- */
.kpi-card { padding: 15px 16px; }
.kpi-label { font-size: 12.5px; color: var(--text-3); display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 25px; font-weight: 680; letter-spacing: -.6px; margin-top: 6px; line-height: 1.15; }
.kpi-value .unit { font-size: 13px; font-weight: 500; color: var(--text-3); margin-left: 2px; }
.kpi-foot { font-size: 11.5px; color: var(--text-3); margin-top: 5px; }
.kpi-foot .up { color: var(--success); }
.kpi-foot .down { color: var(--danger); }
.kpi-icon {
  width: 28px; height: 28px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
  font-size: 14px; margin-left: auto;
}

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left; font-weight: 600; color: var(--text-3); font-size: 12px;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  background: #fafbfd; white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
table.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
table.tbl tbody tr:hover { background: #fafbfe; }
table.tbl tbody tr { cursor: pointer; }
.row-name { font-weight: 600; }
.row-sub { font-size: 11.5px; color: var(--text-3); }
.row-actions { white-space: nowrap; display: flex; gap: 6px; }
.actions-col { width: 1%; white-space: nowrap; text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--danger); }
.pos { color: var(--success); }

/* ---------- Tags ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 500;
  background: #f0f2f7; color: var(--text-2); white-space: nowrap;
}
.tag.blue { background: #eaf1ff; color: #2f6bff; }
.tag.green { background: #e6f7ee; color: #0d8a45; }
.tag.orange { background: #fff4e2; color: #b57308; }
.tag.red { background: #fdecec; color: #cf3035; }
.tag.purple { background: #f0ebff; color: #6b46e5; }
.tag.teal { background: #e3f7f7; color: #0a8484; }
.tag.gray { background: #f1f3f7; color: #6b7280; }

.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }

/* ---------- Progress / pipeline ---------- */
.stage-track { display: flex; gap: 3px; margin-top: 6px; }
.stage-seg { height: 5px; flex: 1; border-radius: 3px; background: #eaedf3; }
.stage-seg.on { background: var(--primary); }

.pipeline { display: flex; align-items: stretch; gap: 0; padding: 4px 0; }
.pipe-step { flex: 1; text-align: center; position: relative; padding: 0 4px; min-width: 0; }
.pipe-bar { height: 30px; border-radius: 6px; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; font-size: 13px; }
.pipe-name { font-size: 12px; color: var(--text-2); margin-top: 6px; }
.pipe-arrow { display: flex; align-items: center; color: #cfd6e4; font-size: 15px; padding: 0 2px; }

/* ---------- bars ---------- */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 12.5px; }
.bar-row .lbl { width: 96px; flex: 0 0 96px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; height: 20px; background: #f2f4f9; border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; }
.bar-row .val { width: 66px; text-align: right; color: var(--text-2); font-variant-numeric: tabular-nums; flex: 0 0 66px; }

/* stacked cost bar */
.stack-row { margin-bottom: 12px; }
.stack-head { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 5px; }
.stack-head .nm { font-weight: 600; }
.stack-bar { display: flex; height: 20px; border-radius: 5px; overflow: hidden; background: #f2f4f9; }
.stack-seg { height: 100%; }
.stack-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; font-size: 12px; color: var(--text-2); }
.stack-legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; margin-right: 5px; }

/* ---------- Risk ---------- */
.stars { letter-spacing: 1px; font-size: 12px; }
.stars.s3 { color: var(--danger); }
.stars.s2 { color: var(--warn); }
.stars.s1 { color: var(--text-3); }
.stars.s0 { color: #c8cfdb; }

.risk-card { border: 1px solid var(--border); border-radius: 10px; padding: 13px 14px; background: #fff; }
.risk-card h4 { margin: 0 0 10px; font-size: 13.5px; display: flex; align-items: center; gap: 8px; }
.risk-line { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px dashed var(--border-soft); font-size: 12.5px; }
.risk-line:first-of-type { border-top: none; }
.risk-line .who { font-weight: 600; width: 110px; flex: 0 0 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Timeline ---------- */
.tl { position: relative; padding-left: 20px; }
.tl::before { content: ''; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding-bottom: 14px; }
.tl-item::before {
  content: ''; position: absolute; left: -19px; top: 5px;
  width: 8px; height: 8px; border-radius: 50%; background: #fff; border: 2px solid var(--primary);
}
.tl-item.head::before { background: var(--primary); }
.tl-date { font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.tl-text { font-size: 13px; white-space: pre-wrap; word-break: break-word; }

/* ---------- Milestone steps ---------- */
.ms-steps { display: flex; gap: 8px; flex-wrap: wrap; }
.ms-step {
  flex: 1; min-width: 96px; border: 1px solid var(--border); border-radius: 10px; padding: 10px 11px;
  background: #fcfdff;
}
.ms-step.done { border-color: #bfe5cf; background: #f4fcf7; }
.ms-step .t { font-size: 11.5px; color: var(--text-3); }
.ms-step .v { font-size: 12.5px; font-weight: 600; margin-top: 2px; word-break: break-all; }
.ms-step.done .v { color: #0d8a45; }

/* ---------- Filters ---------- */
.filters {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  padding: 12px 18px; border-bottom: 1px solid var(--border-soft); background: #fcfdff;
}
.filters select, .filters input {
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px;
  background: #fff; font-size: 12.5px; outline: none;
}
.filters select:focus, .filters input:focus { border-color: var(--primary); }
.filters .spacer { flex: 1; }
.f-count { font-size: 12px; color: var(--text-3); }

/* ---------- Drawer ---------- */
.drawer-mask {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .38);
  opacity: 0; pointer-events: none; transition: opacity .22s; z-index: 60;
}
.drawer-mask.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 620px; max-width: 94vw;
  background: #fff; z-index: 61; box-shadow: -8px 0 32px rgba(16, 24, 40, .12);
  transform: translateX(100%); transition: transform .26s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; gap: 12px;
}
.drawer-head h2 { margin: 0; font-size: 17px; font-weight: 650; }
.drawer-head .meta { font-size: 12px; color: var(--text-3); margin-top: 3px; }
.drawer-close { margin-left: auto; border: none; background: #f2f4f9; width: 28px; height: 28px; border-radius: 8px; color: var(--text-2); flex: 0 0 28px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px 40px; }
.drawer-foot { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; background: #fcfdff; }

.sec { margin-bottom: 22px; }
.sec > h4 {
  margin: 0 0 10px; font-size: 12px; color: var(--text-3); font-weight: 600;
  letter-spacing: .6px; text-transform: uppercase;
}
.kv { display: grid; grid-template-columns: 92px 1fr; gap: 7px 12px; font-size: 13px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; word-break: break-word; }

.fin-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.fin-cell { border: 1px solid var(--border-soft); border-radius: 9px; padding: 9px 11px; background: #fcfdff; }
.fin-cell .k { font-size: 11.5px; color: var(--text-3); }
.fin-cell .v { font-size: 15px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.fin-cell.hl { background: var(--primary-soft); border-color: #d3e2ff; }
.fin-cell.hl .v { color: var(--primary); }
.fin-cell.warn { background: #fff7ea; border-color: #fae2b8; }
.fin-cell.warn .v { color: #b57308; }

/* ---------- Modal ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .42); z-index: 70;
  display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
}
.modal-mask.open { display: flex; }
.modal { background: #fff; border-radius: 14px; width: 780px; max-width: 100%; box-shadow: 0 20px 60px rgba(16,24,40,.2); }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: #fcfdff; border-radius: 0 0 14px 14px; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--text-3); }
.field input, .field select, .field textarea {
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; outline: none; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,107,255,.09); }
.field textarea { resize: vertical; min-height: 62px; }
.form-sec-title { grid-column: 1/-1; font-size: 12px; font-weight: 650; color: var(--text-2); margin-top: 8px; padding-top: 10px; border-top: 1px dashed var(--border); }
.form-sec-title:first-child { border-top: none; margin-top: 0; padding-top: 0; }

/* ---------- Misc ---------- */
.empty { text-align: center; padding: 46px 16px; color: var(--text-3); font-size: 13px; }
.view { display: none; }
.view.active { display: block; }
.muted { color: var(--text-3); }
.tiny { font-size: 12px; }
.nowrap { white-space: nowrap; }
.scroll-y { max-height: 420px; overflow-y: auto; }
.log-line { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--border-soft); font-size: 12.5px; }
.log-line .d { flex: 0 0 78px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.log-line .w { flex: 0 0 88px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-line .t { flex: 1; color: var(--text-2); white-space: pre-wrap; }
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1a2233; color: #fff; padding: 9px 18px; border-radius: 8px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: all .22s; z-index: 90;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.legend-inline { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin-top: 10px; }
.legend-inline i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; margin-right: 5px; }

/* ---------- Login ---------- */
.login-mask {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(135deg, #eef3ff 0%, #f4f6fa 60%, #f0ebff 100%);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.login-mask.open { display: flex; }
.login-card {
  width: 340px; max-width: 100%; background: #fff; border: 1px solid var(--border);
  border-radius: 16px; box-shadow: 0 20px 60px rgba(16,24,40,.14); padding: 26px 24px 22px; text-align: center;
}
.login-input {
  width: 100%; border: 1px solid var(--border); border-radius: 9px; padding: 11px 13px;
  font-size: 14px; outline: none; margin-bottom: 12px; text-align: center; letter-spacing: .5px;
}
.login-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47,107,255,.1); }
.btn.block { width: 100%; justify-content: center; padding: 10px; font-size: 14px; }
.login-err { color: var(--danger); font-size: 12.5px; margin-top: 10px; }
.login-sync {
  display: flex; align-items: center; gap: 7px; justify-content: center;
  font-size: 12px; margin: 12px 0 2px; padding: 6px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: #f6f8fb; color: var(--text-3);
}
.login-sync .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.login-sync.ok { color: #1a7f4b; background: #e9f7ef; border-color: #bfe6cf; }
.login-sync.local { color: #8a6d1a; background: #fff7e0; border-color: #f0e0a8; }
.login-sync.offline { color: #8a4b1a; background: #fdf0e6; border-color: #f0d6bf; }
