:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --line: #e5e7eb;
  --line-strong: #d4d8de;
  --text: #1f2329;
  --text-2: #5b6472;
  --text-3: #9aa1ad;
  --accent: #e8830c;
  --accent-2: #f59e0b;
  --accent-soft: rgba(232, 131, 12, 0.1);
  --blue: #2f7cf6;
  --green: #0f9d58;
  --red: #e5484d;
  --purple: #7c5cf0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.06);
  --mono: 'SF Mono', 'Cascadia Code', Consolas, 'Noto Sans Mono CJK SC', 'WenQuanYi Micro Hei Mono', 'Courier New', monospace;
  --sans: -apple-system, BlinkMacSystemFont, 'Noto Sans CJK SC', 'Source Han Sans SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', 'Segoe UI', Arial, sans-serif;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ---------------- app bar ---------------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}

.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, #2b303c, #14161b);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 13px;
  box-shadow: 0 4px 12px rgba(15, 17, 21, 0.26);
  flex-shrink: 0;
}
.brand-text { font-size: 14px; font-weight: 600; letter-spacing: 0.2px; white-space: nowrap; }
.brand-sub { color: var(--text-3); font-size: 12px; white-space: nowrap; }

@media (max-width: 1240px) { .brand-sub { display: none; } }
@media (max-width: 860px) {
  .appbar { gap: 8px; padding: 0 12px; }
  .nav-link { padding: 6px 6px; font-size: 12px; }
  .user-switch > div:nth-child(2) { display: none; }
}

.spacer { flex: 1; }

.nav-link {
  color: var(--text-2); font-size: 12.5px; padding: 6px 10px; border-radius: 6px;
  white-space: nowrap; flex-shrink: 0;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.is-active { color: var(--accent); font-weight: 600; background: var(--accent-soft); }

/* ---------------- controls ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: 7px;
  background: #fff; color: var(--text);
  font-size: 12.5px; cursor: pointer; white-space: nowrap;
  transition: all 0.15s ease;
}
.btn:hover { border-color: #bcc3cd; background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600;
}
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { height: 27px; padding: 0 9px; font-size: 12px; border-radius: 6px; }
.btn-danger { color: var(--red); border-color: #f3c2c4; }
.btn-danger:hover { background: #fff5f5; border-color: #e5484d; }

.field {
  display: flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 10px;
  background: #fff; border: 1px solid var(--line-strong); border-radius: 7px;
}
.field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input, .field select { border: 0; outline: 0; background: transparent; font-size: 12.5px; color: var(--text); width: 100%; }
.field svg { width: 14px; height: 14px; color: var(--text-3); flex-shrink: 0; }

select.field { padding-right: 6px; cursor: pointer; }

.user-switch {
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 1; min-width: 0;
}
.user-switch select { max-width: 130px; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; color: #fff;
  font-size: 12px; font-weight: 600; flex-shrink: 0;
}
.role-chip {
  font-size: 11px; padding: 1px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); border: 1px solid rgba(232,131,12,0.2);
}

/* ---------------- layout ---------------- */
.wrap { max-width: 1480px; margin: 0 auto; padding: 20px 22px 56px; }
.section { margin-bottom: 16px; }
.section-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.section-title { font-size: 13px; font-weight: 650; letter-spacing: 0.2px; }
.section-hint { color: var(--text-3); font-size: 12px; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 318px; gap: 16px; align-items: start; }
@media (max-width: 1180px) { .layout { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 1px 2px rgba(16,24,40,0.03);
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
}
.card-title { font-size: 13px; font-weight: 650; }
.card-body { padding: 14px 16px; }

/* ---------------- kpi ---------------- */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1180px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 720px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.kpi {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 15px 12px;
}
.kpi::after {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--k-color, var(--line-strong));
}
.kpi-label { font-size: 11.5px; color: var(--text-2); display: flex; align-items: center; gap: 5px; }
.kpi-value { font-size: 24px; font-weight: 700; letter-spacing: -0.4px; margin-top: 2px; line-height: 1.2; }
.kpi-value small { font-size: 11px; font-weight: 500; color: var(--text-3); margin-left: 4px; }
.kpi-foot { font-size: 11.5px; color: var(--text-3); margin-top: 3px; }
.kpi-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--k-color); }

/* ---------------- table ---------------- */
.table-wrap { overflow-x: auto; }
table.task-table { width: 100%; border-collapse: collapse; }
.task-table th {
  text-align: left; font-weight: 550; color: var(--text-2); font-size: 11.5px;
  padding: 9px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.task-table td { padding: 11px 14px; border-bottom: 1px solid #f0f1f3; vertical-align: middle; }
.task-table tr:last-child td { border-bottom: 0; }
.task-table tbody tr { transition: background 0.12s; }
.task-table tbody tr:hover { background: #fcfcfd; }
.task-table tbody tr.is-clickable { cursor: pointer; }

.task-code { font-family: var(--mono); font-size: 11.5px; color: var(--text-3); letter-spacing: 0.3px; }
.task-title { font-weight: 600; font-size: 13px; display: block; margin-top: 1px; }
.task-meta { color: var(--text-3); font-size: 11.5px; margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }

.status {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; padding: 2px 8px; border-radius: 999px; white-space: nowrap;
  border: 1px solid transparent;
}
.status i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.status-pending { color: #8b6b00; background: #fff8e1; border-color: #ffe9a8; }
.status-working { color: #1d6fd8; background: #eef6ff; border-color: #cfe4ff; }
.status-review { color: #7a4bd8; background: #f4efff; border-color: #e0d4ff; }
.status-rejected { color: #c53030; background: #fff2f2; border-color: #ffd3d3; }
.status-approved { color: #0f7a46; background: #ebfaf1; border-color: #cfefdd; }

.prio { font-size: 11.5px; display: inline-flex; align-items: center; gap: 5px; color: var(--text-2); }
.prio i { width: 6px; height: 6px; border-radius: 2px; }
.prio-high i { background: #e5484d; }
.prio-medium i { background: #f59e0b; }
.prio-low i { background: #9aa1ad; }

.assignee { display: flex; align-items: center; gap: 7px; }
.assignee .avatar { width: 22px; height: 22px; font-size: 11px; }
.assignee-empty { color: var(--text-3); font-size: 12px; }

.due { font-size: 12px; color: var(--text-2); white-space: nowrap; }
.due.is-late { color: var(--red); }

/* ---------------- filters ---------------- */
.filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.chip-group { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; gap: 2px; }
.chip {
  border: 0; background: transparent; color: var(--text-2);
  font-size: 12px; padding: 4px 10px; border-radius: 6px; cursor: pointer;
}
.chip:hover { color: var(--text); }
.chip.is-on { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(16,24,40,0.08); }
.chip .n { color: var(--text-3); font-size: 11px; margin-left: 3px; }

/* ---------------- sidebar ---------------- */
.side-card + .side-card { margin-top: 12px; }

.person-row { display: flex; align-items: center; gap: 9px; padding: 8px 0; border-bottom: 1px dashed #eef0f2; }
.person-row:last-child { border-bottom: 0; }
.person-name { font-size: 12.5px; font-weight: 550; }
.person-sub { font-size: 11px; color: var(--text-3); }
.bar { height: 5px; border-radius: 3px; background: #f0f1f3; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

.flow-step { display: flex; gap: 10px; padding: 7px 0; align-items: flex-start; }
.flow-num {
  width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0;
  background: var(--surface-2); border: 1px solid var(--line-strong);
  display: grid; place-items: center; font-size: 10.5px; color: var(--text-2);
}
.flow-text { font-size: 12px; color: var(--text-2); }
.flow-text b { color: var(--text); font-weight: 600; }

/* ---------------- drawer ---------------- */
.overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.32);
  opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 60;
}
.overlay.is-open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 94vw);
  background: #fff; z-index: 70; box-shadow: -8px 0 32px rgba(16, 24, 40, 0.14);
  transform: translateX(102%); transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex; flex-direction: column;
}
.drawer.is-open { transform: none; }
.drawer-head { padding: 16px 20px 12px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 20px 24px; }
.drawer-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; background: var(--surface-2); }

.kv { display: grid; grid-template-columns: 88px 1fr; gap: 8px 12px; font-size: 12.5px; }
.kv dt { color: var(--text-3); }
.kv dd { color: var(--text); }

.sub-block {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; font-family: var(--sans); font-size: 12.5px;
  white-space: pre-wrap; word-break: break-word; max-height: 200px; overflow-y: auto;
}

.timeline { position: relative; padding-left: 16px; }
.timeline::before { content: ''; position: absolute; left: 5px; top: 4px; bottom: 4px; width: 1px; background: var(--line); }
.tl-item { position: relative; padding: 0 0 14px 12px; }
.tl-item::before {
  content: ''; position: absolute; left: -16px; top: 4px;
  width: 7px; height: 7px; border-radius: 50%; background: #fff; border: 1.5px solid var(--line-strong);
}
.tl-item.is-latest::before { border-color: var(--accent); background: var(--accent); }
.tl-title { font-size: 12.5px; font-weight: 600; }
.tl-meta { font-size: 11.5px; color: var(--text-3); }
.tl-note { font-size: 12px; color: var(--text-2); margin-top: 2px; }

/* ---------------- modal ---------------- */
.modal {
  position: fixed; z-index: 80; left: 50%; top: 50%; transform: translate(-50%, -48%) scale(0.98);
  width: min(600px, 94vw); max-height: 88vh; background: #fff; border-radius: 12px;
  box-shadow: 0 24px 64px rgba(16, 24, 40, 0.24); opacity: 0; pointer-events: none;
  transition: all 0.2s ease; display: flex; flex-direction: column;
}
.modal.is-open { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }

.form-row { margin-bottom: 13px; }
.form-label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 5px; }
.form-label b { color: var(--red); font-weight: 400; margin-left: 2px; }
.input, .textarea {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 7px;
  padding: 8px 10px; font-size: 12.5px; font-family: inherit; color: var(--text);
  background: #fff; outline: none;
}
.input:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea { resize: vertical; min-height: 72px; line-height: 1.6; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.dropzone {
  border: 1px dashed var(--line-strong); border-radius: 8px; padding: 14px;
  text-align: center; color: var(--text-3); font-size: 12px; cursor: pointer;
  transition: all 0.15s; background: var(--surface-2);
}
.dropzone:hover, .dropzone.is-drag { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* ---------------- toast ---------------- */
.toast-host { position: fixed; right: 20px; bottom: 20px; z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #1f2329; color: #fff; font-size: 12.5px;
  padding: 9px 13px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  animation: toastIn 0.22s ease; max-width: 360px;
}
.toast.is-error { background: #b42318; }
.toast.is-success { background: #0f7a46; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.empty {
  padding: 42px 16px; text-align: center; color: var(--text-3); font-size: 12.5px;
}
.empty svg { width: 34px; height: 34px; opacity: 0.35; display: block; margin: 0 auto 8px; }

.muted { color: var(--text-3); }
.mono { font-family: var(--mono); }
