:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: var(--font); font-size: 13px; color: var(--text); background: var(--bg); }
.hidden { display: none !important; }
.muted { color: var(--text-muted); font-size: 12px; }
.eyebrow { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--primary); font-weight: 600; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row-gap { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Buttons & Inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 7px; cursor: pointer;
  font-size: 13px; font-weight: 500; padding: 7px 13px; background: var(--surface); color: var(--text);
  transition: background 0.12s, border-color 0.12s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; padding: 10px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-outline { border-color: var(--border); background: var(--surface); }
.btn-outline:hover:not(:disabled) { background: var(--surface-muted); border-color: #cbd5e1; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-muted); color: var(--text); }

input, select, textarea {
  font-family: inherit; font-size: 13px; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 9px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(37, 99, 235, 0.2); border-color: var(--primary); }
.select-compact { padding: 5px 8px; font-size: 12px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; font-weight: 500; color: #334155; }
.form-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; border-radius: 6px; padding: 8px 10px; font-size: 12px; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; border-radius: 6px; padding: 8px 10px; font-size: 12px; }

/* Auth Shell */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: 0 12px 32px rgba(15, 23, 42, 0.06); }
.auth-card h1 { margin: 8px 0 6px; font-size: 20px; }

/* Topbar */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 18px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.brand-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--primary); display: inline-block; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sync-group { display: inline-flex; gap: 4px; padding: 2px; background: var(--surface-muted); border-radius: 8px; }
.user-menu { display: inline-flex; align-items: center; gap: 4px; margin-left: 4px; padding-left: 8px; border-left: 1px solid var(--border); }
.user-pill { font-size: 12px; font-weight: 500; padding: 3px 8px; background: #eef2ff; color: #3730a3; border-radius: 99px; }

.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--primary); color: #fff; }
.badge-warn { background: #fef3c7; color: #92400e; }

/* Metrics Strip */
.metrics-strip {
  display: grid; grid-template-columns: 1.2fr 1.1fr 1fr; gap: 12px;
  padding: 12px 18px 4px;
}
@media (max-width: 1080px) { .metrics-strip { grid-template-columns: 1fr; } }
.metric-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 11px 14px; display: flex; flex-direction: column; gap: 6px; }
.metric-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; }
.metric-value { font-weight: 700; font-size: 15px; }
.progress-track { height: 8px; background: #e2e8f0; border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 99px; transition: width 0.25s ease; background: var(--ok); }
.progress-fill.warn { background: var(--warn); }
.progress-fill.danger { background: var(--danger); }
.metric-sub { font-size: 11.5px; color: var(--text-muted); }
.chip-list { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  font-size: 11px; padding: 2px 7px; border-radius: 99px; border: 1px solid var(--border);
  background: var(--surface-muted); color: #334155; cursor: pointer;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip-warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }

/* Toolbar */
.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 10px 18px;
}
.toolbar-filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: 8px; }
.search-input { width: 250px; }
.checkbox-inline { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; cursor: pointer; user-select: none; }

/* Table */
.table-wrap { padding: 0 18px 36px; overflow-x: auto; }
.req-table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.req-table thead th {
  position: sticky; top: 0; background: #f8fafc; text-align: left;
  padding: 9px 10px; font-size: 12px; font-weight: 600; color: #475569;
  border-bottom: 1px solid var(--border);
}
.req-table tbody td {
  padding: 7px 10px; border-bottom: 1px solid #f1f5f9; vertical-align: middle;
}
.req-table tbody tr:hover { background: #f8fafc; }
.req-table tr.group-row td {
  background: #f1f5f9; font-weight: 600; font-size: 12.5px; color: #1e293b;
  padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--border);
}
.req-table tr.group-row:hover td { background: #e2e8f0; }

.title-btn {
  background: none; border: none; padding: 0; margin: 0; text-align: left; cursor: pointer;
  color: var(--text); font-weight: 500; font-size: 13px; line-height: 1.35;
}
.title-btn:hover { color: var(--primary); text-decoration: underline; }
.title-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 2px; font-size: 11.5px; color: var(--text-muted); }
.l2-tag { background: #f1f5f9; padding: 1px 6px; border-radius: 4px; color: #475569; }
.dirty-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); display: inline-block; title: "待同步"; }

.link-pill {
  display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px;
  text-decoration: none; border: 1px solid var(--border); color: #1d4ed8; background: #eff6ff;
}
.link-pill:hover { background: #dbeafe; }
.link-pill.notion { color: #334155; background: #f8fafc; }

.cell-input, .cell-select {
  width: 100%; padding: 4px 6px; font-size: 12px; border: 1px solid transparent; background: transparent; border-radius: 5px;
}
.cell-input:hover, .cell-select:hover { border-color: var(--border); background: #fff; }
.cell-input:focus, .cell-select:focus { border-color: var(--primary); background: #fff; }
.cell-num { text-align: right; font-variant-numeric: tabular-nums; }
.prio-Highest { color: #b91c1c; font-weight: 600; }
.prio-High { color: #c2410c; font-weight: 600; }
.prio-Medium { color: #1d4ed8; }
.dec-纳入7\.1 { color: #15803d; font-weight: 600; }
.dec-分阶段 { color: #b45309; font-weight: 600; }
.dec-裁掉 { color: #94a3b8; }

.empty-state { text-align: center; padding: 42px; color: var(--text-muted); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-top: 10px; }

/* Drawer & Modal */
.backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.35); z-index: 50; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(580px, 95vw);
  background: var(--surface); z-index: 60; box-shadow: -8px 0 28px rgba(15, 23, 42, 0.14);
  display: flex; flex-direction: column;
}
.drawer-header {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.drawer-header h2 { margin: 4px 0 0; font-size: 17px; }
.drawer-header-actions { display: flex; gap: 6px; align-items: center; }
.drawer-body { padding: 16px 20px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid .full { grid-column: 1 / -1; }

.modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(820px, 94vw); max-height: 88vh;
  background: var(--surface); z-index: 70; border-radius: 12px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.22); display: flex; flex-direction: column;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px 18px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 14px; }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.tab-btn { background: none; border: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-weight: 500; color: var(--text-muted); }
.tab-btn.active { background: #eff6ff; color: var(--primary); }

.sub-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.sub-table th, .sub-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.sub-table th { background: #f8fafc; font-weight: 600; color: #475569; }
.diff-old { color: #b91c1c; text-decoration: line-through; margin-right: 6px; }
.diff-new { color: #15803d; font-weight: 600; }

/* Toast */
.toast-container { position: fixed; bottom: 18px; right: 18px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #0f172a; color: #fff; padding: 9px 14px; border-radius: 8px; font-size: 12.5px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2); }
.toast.error { background: var(--danger); }
.toast.ok { background: #15803d; }
