:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #171a1f;
  --muted: #667085;
  --border: #e4e7ec;
  --accent: #0f766e;
  --accent-soft: #d7f3ef;
  --danger: #d92d20;
  --warn: #b54708;
  --ok: #067647;
  --blue: #175cd3;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 16px rgba(16, 24, 40, 0.04);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 20px; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; gap: 18px; min-height: 58px; }
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--text); font-weight: 700; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, #14b8a6, #0f766e);
  color: #fff; font-size: 15px; font-weight: 800;
}
.brand-name { font-size: 15px; }

.nav { display: flex; gap: 2px; margin-left: 8px; }
.nav a {
  padding: 7px 12px; border-radius: 8px; color: var(--muted);
  font-weight: 600; font-size: 13.5px;
}
.nav a:hover { background: #f2f4f7; text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }

.userbox { margin-left: auto; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.userbox .name { color: var(--text); font-weight: 600; }

/* ---------- 通用 ---------- */
.main { padding-top: 22px; padding-bottom: 60px; min-height: 60vh; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 21px; letter-spacing: -0.3px; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 9px; border: 1px solid transparent;
  background: var(--card); color: var(--text); font: inherit; font-weight: 600; font-size: 13.5px;
  cursor: pointer; white-space: nowrap; transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #f2f4f7; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #115e59; }
.btn-ghost { border-color: var(--border); }
.btn-danger { color: var(--danger); border-color: #fecdca; background: #fff; }
.btn-danger:hover { background: #fee4e2; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }

.money { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.money.pos { color: var(--ok); }
.money.neg { color: var(--danger); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- 统计卡 ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat-label { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 6px; letter-spacing: -0.5px; }
.stat-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- 表格 ---------- */
.table-wrap { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 12px;
  padding: 11px 14px; border-bottom: 1px solid var(--border); background: #fafbfc; white-space: nowrap;
}
table.data td { padding: 11px 14px; border-bottom: 1px solid #f0f2f5; vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: #fafbfc; }
table.data .num { text-align: right; }
table.data .clickable { cursor: pointer; }
.title-cell { display: flex; flex-direction: column; gap: 2px; min-width: 180px; }
.title-cell .name { font-weight: 600; }
.title-cell .sub { color: var(--muted); font-size: 12px; }
.snippet { color: var(--muted); font-size: 12px; line-height: 1.5; display: block; }
.snippet mark { background: #fef0c7; color: inherit; padding: 0 2px; border-radius: 3px; }

/* ---------- 状态 ---------- */
.pill { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.pending { background: #f2f4f7; color: #475467; }
.pill.doing { background: #eff4ff; color: var(--blue); }
.pill.pcb { background: #f4f3ff; color: #6941c6; }
.pill.parts { background: #ecfdff; color: #0e7090; }
.pill.review { background: #fffaeb; color: var(--warn); }
.pill.done { background: #ecfdf3; color: var(--ok); }
.pill.half { background: #fff4ed; color: #c4320a; }
.pill.settled { background: #d1fadf; color: #05603a; }
.pill.canceled { background: #f2f4f7; color: #98a2b3; text-decoration: line-through; }

.due { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.due.overdue { color: var(--danger); font-weight: 600; }
.due.soon { color: var(--warn); font-weight: 600; }

/* ---------- 工具条 ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type="search"],
.toolbar input[type="month"],
.toolbar select {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--card); font: inherit; font-size: 13.5px; color: inherit; outline: none;
}
.toolbar input:focus, .toolbar select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.1); }
.toolbar .grow { flex: 1 1 220px; }
.toolbar .grow input { width: 100%; }

/* ---------- 表单 ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; color: #344054; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px;
  background: #fff; color: var(--text); font: inherit; font-size: 14px; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field textarea { resize: vertical; min-height: 90px; line-height: 1.6; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.1);
}
.hint { color: var(--muted); font-size: 12px; }
.form-error { color: var(--danger); font-size: 13px; }
.form-actions { display: flex; gap: 10px; margin-top: 4px; }

/* ---------- 详情 ---------- */
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.detail-head h1 { margin: 0; font-size: 22px; letter-spacing: -0.3px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.kv-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px 20px; margin: 18px 0; }
.kv-item .k { color: var(--muted); font-size: 12px; }
.kv-item .v { font-weight: 600; margin-top: 2px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 22px 0 10px; }
.section-title h2 { margin: 0; font-size: 15px; }

.back { display: inline-block; margin-bottom: 12px; font-size: 13.5px; }

.note-box { white-space: pre-wrap; word-break: break-word; color: #344054; }

.mono { font-family: "Cascadia Code", Consolas, "Courier New", monospace; letter-spacing: 0.2px; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.code-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.code-prefix {
  display: inline-flex; align-items: center;
  padding: 9px 12px; border-radius: 9px;
  background: #f2f4f7; border: 1px solid var(--border); color: var(--text);
}
.group-row td { background: #f7f9fb; font-weight: 600; color: var(--muted); font-size: 12.5px; padding: 8px 14px; }

.file-card { margin-top: 14px; }
.upload-btn { cursor: pointer; }
.file-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.file-thumb {
  position: relative; width: 120px; height: 120px; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--border); background: #0f172a;
}
.file-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-del {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%;
  border: none; background: rgba(0, 0, 0, 0.65); color: #fff; font-size: 14px; line-height: 1; cursor: pointer;
}
.file-del:hover { background: var(--danger); }
.file-list { display: flex; flex-direction: column; gap: 6px; }
.file-row {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 9px; background: #fafbfc;
}
.file-row a { flex: 1; word-break: break-all; }

/* ---------- 登录 ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 30px 28px 26px; box-shadow: var(--shadow); }
.login-card .brand { margin-bottom: 18px; }
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card .sub { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.login-alt { text-align: center; margin-top: 14px; font-size: 13px; color: var(--muted); }

/* ---------- 其他 ---------- */
.empty { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty .big { display: block; font-size: 26px; margin-bottom: 8px; }
.loading { text-align: center; padding: 60px 0; color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #101828; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 13.5px;
  box-shadow: 0 8px 30px rgba(16, 24, 40, 0.25); z-index: 50; opacity: 0; pointer-events: none;
  transition: opacity 0.2s; max-width: calc(100vw - 40px);
}
.toast.show { opacity: 1; }
.toast.error { background: #b42318; }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

@media (max-width: 760px) {
  .wrap { padding: 0 14px; }
  .brand-name { display: none; }
  .nav { margin-left: 0; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .kv-grid { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .topbar-inner { gap: 10px; }
  .userbox .name { display: none; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --card: #171b21;
    --text: #e8eaed;
    --muted: #98a2b3;
    --border: #262c35;
    --accent: #2dd4bf;
    --accent-soft: #123c37;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
  .topbar { background: rgba(15, 18, 22, 0.9); }
  .nav a:hover { background: #1d232b; }
  .btn { background: var(--card); }
  .btn:hover { background: #1d232b; }
  .btn-primary { background: var(--accent); color: #06201d; }
  .field input, .field select, .field textarea, .toolbar input, .toolbar select { background: #10141a; }
  table.data th { background: #141920; }
  table.data td { border-bottom-color: #20262e; }
  table.data tbody tr:hover { background: #141920; }
  .pill.pending { background: #1d232b; color: #cfd4dc; }
  .pill.doing { background: #10203a; color: #84adff; }
  .pill.pcb { background: #241b3d; color: #c3b5fd; }
  .pill.parts { background: #0d2a33; color: #67e3f9; }
  .pill.review { background: #2a1f0b; color: #fdb022; }
  .pill.done { background: #0d2818; color: #75e0a7; }
  .pill.half { background: #33160a; color: #ff9c66; }
  .pill.settled { background: #0b2e1a; color: #6ce9a6; }
  .note-box { color: #cfd4dc; }
  .group-row td { background: #141920; }
  .file-row { background: #141920; }
  .code-prefix { background: #1d232b; }
  .snippet mark { background: #4a3a12; color: #fdb022; }
}
