:root {
  --bg: #f8fafc; --fg: #1e293b; --muted: #64748b; --border: #e2e8f0;
  --primary: #1e293b; --primary-fg: #ffffff;
  --blue: #2563eb; --blue-bg: #eff6ff; --blue-border: #bfdbfe;
  --green: #16a34a; --green-bg: #f0fdf4; --green-border: #bbf7d0;
  --amber: #d97706; --amber-bg: #fffbeb; --amber-border: #fde68a;
  --red: #dc2626; --red-bg: #fef2f2; --red-border: #fecaca;
  --slate-50: #f8fafc; --slate-100: #f1f5f9; --slate-200: #e2e8f0;
  --slate-300: #cbd5e1; --slate-400: #94a3b8; --slate-500: #64748b;
  --slate-600: #475569; --slate-700: #334155; --slate-800: #1e293b; --slate-900: #0f172a;
  --radius: 6px; --radius-lg: 8px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, -apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif; -webkit-font-smoothing: antialiased; background: var(--bg); color: var(--fg); }
button { cursor: pointer; font-family: inherit; }
input, select { font-family: inherit; }
a { color: inherit; text-decoration: none; }

/* Login */
.login-bg { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0f172a, #1e293b, #0f172a); }
.login-card { width: 100%; max-width: 400px; padding: 0 16px; }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .icon { display: inline-flex; align-items: center; justify-content: center; width: 60px; height: 60px; border-radius: 14px; background: var(--blue); color: #fff; font-size: 24px; font-weight: 700; margin-bottom: 16px; }
.login-logo h1 { color: #fff; font-size: 22px; font-weight: 600; }
.login-logo p { color: var(--slate-400); font-size: 14px; margin-top: 4px; }
.login-form { background: #fff; border-radius: 12px; padding: 32px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.login-hint { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--slate-100); font-size: 12px; color: var(--slate-400); }

/* Layout */
.app { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 220px; background: var(--slate-900); color: var(--slate-300); display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-header { display: flex; align-items: center; gap: 10px; padding: 0 16px; height: 56px; border-bottom: 1px solid #1e293b; }
.sidebar-header .icon { width: 32px; height: 32px; border-radius: 6px; background: var(--blue); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 13px; }
.sidebar-header .title { color: #fff; font-size: 13px; font-weight: 600; }
.sidebar-header .subtitle { font-size: 11px; color: var(--slate-400); }
.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: var(--radius); font-size: 13px; color: var(--slate-300); margin-bottom: 2px; transition: all 0.15s; }
.nav-item:hover { background: #1e293b; color: #fff; }
.nav-item.active { background: var(--blue); color: #fff; }
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid #1e293b; font-size: 11px; color: var(--slate-500); }
.sidebar-collapsed { width: 56px; }
.sidebar-collapsed .sidebar-header { padding: 0; justify-content: center; }
.sidebar-collapsed .sidebar-nav { padding: 12px 4px; }
.sidebar-collapsed .nav-item { justify-content: center; padding: 8px 0; }
.sidebar-collapsed .sidebar-footer { padding: 8px 0; text-align: center; }

/* 二级菜单分组 */
.nav-group { margin-bottom: 2px; }
.nav-group-header { display: flex; align-items: center; gap: 6px; width: 100%; border: none; background: transparent; color: var(--slate-400); font-size: 12px; font-weight: 600; letter-spacing: .3px; padding: 8px 12px 4px; cursor: pointer; text-align: left; }
.nav-group-header span { flex: 1; }
.nav-chevron { transition: transform 0.15s; }
.nav-chevron.open { transform: rotate(90deg); }
.nav-sub { padding-left: 8px; border-left: 1px solid #1e293b; margin-left: 16px; margin-bottom: 4px; }
.nav-sub .nav-item { font-size: 13px; padding: 7px 12px; }
.sidebar-collapsed .nav-group-header { justify-content: center; padding: 8px 0; }
.sidebar-collapsed .nav-group-header span { display: none; }
.sidebar-collapsed .nav-sub { border-left: none; margin-left: 0; padding-left: 0; }

/* 空模块占位 */
.empty-module { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 80px 20px; color: var(--slate-400); }
.empty-icon { opacity: .5; }
.empty-text { font-size: 14px; }

/* 权限设置矩阵 */
.perm-hint { font-size: 13px; color: var(--slate-500); padding: 12px 16px; background: #f8fafc; border-radius: var(--radius); margin-bottom: 14px; }
.perm-hint .hl { color: var(--blue); font-weight: 600; }
.perm-scroll { overflow-x: auto; }
.perm-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 720px; }
.perm-table th, .perm-table td { border: 1px solid var(--border); padding: 8px 10px; text-align: center; }
.perm-table thead th { background: #f8fafc; position: sticky; top: 0; z-index: 1; }
.perm-table .perm-mod { text-align: left; min-width: 190px; background: #fff; }
.perm-table .perm-bl { background: #eff6ff; }
.perm-table .perm-cell input { width: 16px; height: 16px; cursor: pointer; }
.perm-table .perm-group { color: var(--slate-400); font-size: 12px; }
.perm-empty-tag { display: inline-block; background: #f1f5f9; color: var(--slate-500); border-radius: 4px; font-size: 11px; padding: 1px 5px; margin-right: 6px; }
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.header { height: 56px; background: #fff; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; flex-shrink: 0; }
.content { flex: 1; overflow: auto; padding: 20px; }

/* User menu */
.user-btn { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: var(--radius); border: none; background: transparent; }
.user-btn:hover { background: var(--slate-100); }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--blue); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; }
.user-name { font-size: 13px; font-weight: 500; color: var(--slate-800); }
.user-role { font-size: 11px; color: var(--slate-500); }
.user-dropdown { position: absolute; right: 0; top: 100%; margin-top: 4px; width: 200px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: 0 4px 12px rgba(0,0,0,0.1); z-index: 50; overflow: hidden; }
.user-dropdown-header { padding: 12px 16px; border-bottom: 1px solid var(--slate-100); }
.user-dropdown-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px 16px; border: none; background: transparent; font-size: 13px; color: var(--slate-700); text-align: left; }
.user-dropdown-item:hover { background: var(--slate-50); }

/* Page */
.page-title { font-size: 18px; font-weight: 600; color: var(--slate-900); margin-bottom: 16px; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }

/* Card */
.card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg); }
.card-body { padding: 16px; }
.card-header { padding: 8px 16px; border-bottom: 1px solid var(--slate-100); font-size: 13px; color: var(--slate-500); }

/* Toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }

/* Form */
.form-group { margin-bottom: 12px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--slate-700); margin-bottom: 4px; }
.form-input, .form-select { width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--slate-300); border-radius: var(--radius); font-size: 13px; background: #fff; color: var(--slate-800); }
.form-input:focus, .form-select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 2px rgba(37,99,235,0.15); }
.form-input::placeholder { color: var(--slate-400); }
.input-icon { position: relative; }
.input-icon svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--slate-400); }
.input-icon .form-input { padding-left: 34px; }

/* Button */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--radius); font-size: 13px; font-weight: 500; border: none; transition: all 0.15s; white-space: nowrap; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--slate-900); color: #fff; }
.btn-primary:hover { background: var(--slate-800); }
.btn-outline { background: #fff; border: 1px solid var(--slate-300); color: var(--slate-700); }
.btn-outline:hover { background: var(--slate-50); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; }
.btn-block { width: 100%; }

/* Table */
.table-wrap { overflow: auto; max-height: calc(100vh - 200px); scrollbar-width: thin; }
.table-wrap::-webkit-scrollbar { height: 8px; width: 8px; }
.table-wrap::-webkit-scrollbar-track { background: var(--slate-100); border-radius: 4px; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--slate-300); border-radius: 4px; }
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--slate-400); }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
/* 项目拟排16列宽表：设最小宽度防压缩换行 */
table.plans-table { min-width: 1440px; }
table.plans-table td { white-space: nowrap; }
table.plans-table td.wrap-cell { white-space: normal; word-break: break-word; }
table.plans-table td.truncate { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
thead tr { border-bottom: 1px solid var(--slate-200); background: var(--slate-50); }
thead th { position: sticky; top: 0; z-index: 10; background: var(--slate-50); box-shadow: inset 0 -1px 0 var(--slate-200); }
th { padding: 6px 8px; text-align: left; font-weight: 600; font-size: 11px; color: var(--slate-600); white-space: nowrap; }
td { padding: 5px 8px; color: var(--slate-700); border-bottom: 1px solid var(--slate-100); }
td.truncate { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tbody tr:hover { background: var(--slate-50); }
tbody tr.row-danger { background: var(--red-bg); }
/* Sticky first column for horizontal scroll */
.sticky-col { position: sticky; left: 0; z-index: 5; background: white; box-shadow: inset -1px 0 0 var(--slate-200); }
thead th.sticky-col { z-index: 11; background: var(--slate-50); }
tbody tr:hover .sticky-col { background: var(--slate-50); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-nowrap { white-space: nowrap; }
.font-medium { font-weight: 500; }
.text-xs { font-size: 11px; }
.text-muted { color: var(--slate-400); }
.text-red { color: var(--red); }
.text-green { color: var(--green); }
.text-blue { color: var(--blue); }
.cpa-expire-red { color: var(--red); font-weight: 700; }
.truncate { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Badge */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 500; }
.badge-default { background: var(--slate-100); color: var(--slate-700); }
.badge-success { background: var(--green-bg); color: var(--green); }
.badge-warning { background: var(--amber-bg); color: var(--amber); }
.badge-danger { background: var(--red-bg); color: var(--red); }
.badge-info { background: var(--blue-bg); color: var(--blue); }

/* Dialog */
.dialog-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 100; display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; padding: 60px 16px; }
.dialog { background: #fff; border-radius: var(--radius-lg); box-shadow: 0 20px 60px rgba(0,0,0,0.2); width: 100%; margin-bottom: 40px; }
.dialog-sm { max-width: 480px; }
.dialog-md { max-width: 640px; }
.dialog-lg { max-width: 900px; }
.dialog-xl { max-width: 1100px; }
.dialog-2xl { max-width: 1650px; }
.dialog-2xl .dialog-body { max-height: 78vh; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--slate-200); }
.dialog-header h2 { font-size: 15px; font-weight: 600; color: var(--slate-900); }
.dialog-close { border: none; background: transparent; padding: 4px; border-radius: 4px; color: var(--slate-400); }
.dialog-close:hover { background: var(--slate-100); }
.dialog-body { padding: 20px; max-height: 65vh; overflow-y: auto; }
.dialog-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--slate-100); }
.dialog-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.dialog-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Summary cards */
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.summary-card { border-radius: var(--radius-lg); padding: 16px; display: flex; align-items: center; gap: 12px; border: 1px solid; }
.summary-card .icon { width: 40px; height: 40px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.summary-card .value { font-size: 24px; font-weight: 700; }
.summary-card .label { font-size: 12px; }
.sc-blue { background: var(--blue-bg); color: var(--blue); border-color: var(--blue-border); }
.sc-green { background: var(--green-bg); color: var(--green); border-color: var(--green-border); }
.sc-amber { background: var(--amber-bg); color: var(--amber); border-color: var(--amber-border); }
.sc-red { background: var(--red-bg); color: var(--red); border-color: var(--red-border); }
.sc-violet { background: #ede9fe; color: #6d28d9; border-color: #ddd6fe; }

/* Backbone chips */
.chip-container { border: 1px solid var(--slate-200); border-radius: var(--radius); padding: 8px; max-height: 160px; overflow-y: auto; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 4px 8px; border-radius: 4px; font-size: 12px; border: none; transition: all 0.15s; }
.chip-inactive { background: var(--slate-100); color: var(--slate-600); }
.chip-inactive:hover { background: var(--slate-200); }
.chip-active { background: var(--blue); color: #fff; }
.chip .level { opacity: 0.7; margin-left: 4px; font-size: 10px; }

/* Info box */
.info-box { border-radius: var(--radius-lg); padding: 12px; margin-bottom: 12px; border: 1px solid; }
.info-blue { background: var(--blue-bg); border-color: var(--blue-border); }
.info-slate { background: var(--slate-50); border-color: var(--slate-200); }
.info-box-title { font-size: 12px; font-weight: 600; margin-bottom: 8px; }

/* Loading */
.loading { text-align: center; padding: 32px; color: var(--slate-400); }

/* Tab */
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tab { padding: 6px 14px; border-radius: var(--radius); font-size: 13px; font-weight: 500; border: none; }
.tab-active { background: var(--slate-900); color: #fff; }
.tab-inactive { background: var(--slate-100); color: var(--slate-600); }

/* Sign-off years hint */
.sign-hint { font-size: 11px; color: var(--slate-500); margin-top: 3px; }
.sign-hint.danger { color: var(--red); font-weight: 700; }

/* Personnel picker */
.picker-filters { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
.picker-filter-group { flex: 1; min-width: 200px; }
.picker-filter-label { font-size: 11px; font-weight: 600; color: var(--slate-600); margin-bottom: 4px; }
.picker-checkbox-group { display: flex; flex-wrap: wrap; gap: 4px; max-height: 80px; overflow-y: auto; border: 1px solid var(--slate-200); border-radius: 4px; padding: 6px; }
.picker-checkbox { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; padding: 2px 6px; border-radius: 3px; cursor: pointer; background: var(--slate-100); color: var(--slate-600); }
.picker-checkbox.checked { background: var(--blue); color: #fff; }
.picker-list { max-height: 300px; overflow-y: auto; border: 1px solid var(--slate-200); border-radius: 4px; }
.picker-item { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-bottom: 1px solid var(--slate-100); cursor: pointer; font-size: 13px; }
.picker-item:hover { background: var(--slate-50); }
.picker-item.selected { background: var(--blue-bg); }
.picker-item .checkbox { width: 16px; height: 16px; border: 1.5px solid var(--slate-300); border-radius: 3px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.picker-item.selected .checkbox { background: var(--blue); border-color: var(--blue); color: #fff; }
.picker-selected-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.picker-tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 12px; font-size: 11px; background: var(--blue-bg); color: var(--blue); border: 1px solid var(--blue-border); }
.picker-tag .remove { cursor: pointer; font-weight: 700; }
.picker-field { display: flex; align-items: center; gap: 6px; }
.picker-field-btn { flex-shrink: 0; height: 36px; padding: 0 10px; border: 1px solid var(--slate-300); border-radius: var(--radius); background: var(--slate-50); font-size: 12px; color: var(--slate-600); cursor: pointer; white-space: nowrap; }
.picker-field-btn:hover { background: var(--slate-100); }

/* Combobox (client search) */
.combobox { position: relative; }
.combobox-input { width: 100%; }
.combobox-dropdown { position: absolute; top: 100%; left: 0; right: 0; max-height: 240px; overflow-y: auto; background: #fff; border: 1px solid var(--slate-300); border-radius: 0 0 var(--radius) var(--radius); z-index: 60; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.combobox-item { padding: 6px 12px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--slate-100); }
.combobox-item:hover { background: var(--blue-bg); }
.combobox-item .short { font-weight: 500; }
.combobox-item .full { color: var(--slate-500); font-size: 11px; margin-left: 6px; }
.combobox-empty { padding: 12px; text-align: center; color: var(--slate-400); font-size: 13px; }

/* Multi-select dropdown */
.ms-dropdown { position: relative; }
.ms-trigger { display: flex; align-items: center; justify-content: space-between; height: 36px; padding: 0 10px; border: 1px solid var(--slate-300); border-radius: var(--radius); background: #fff; font-size: 13px; cursor: pointer; min-width: 160px; }
.ms-trigger:hover { border-color: var(--slate-400); }
.ms-trigger .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.ms-trigger .arrow { margin-left: 6px; color: var(--slate-400); flex-shrink: 0; }
.ms-panel { position: absolute; top: 100%; left: 0; min-width: 100%; max-width: 380px; max-height: 200px; overflow-y: auto; background: #fff; border: 1px solid var(--slate-300); border-radius: var(--radius); z-index: 60; box-shadow: 0 4px 12px rgba(0,0,0,0.1); padding: 4px; }
.ms-option { display: flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 4px; font-size: 12px; cursor: pointer; white-space: nowrap; }
.ms-option:hover { background: var(--slate-50); }
.ms-option .cb { width: 14px; height: 14px; border: 1.5px solid var(--slate-300); border-radius: 3px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ms-option.checked .cb { background: var(--blue); border-color: var(--blue); color: #fff; }

/* Excel式表头排序/筛选控件（紧凑，不增大列宽） */
.sf-arrow { display: inline-block; width: 5px; font-size: 7px; line-height: 1; color: var(--blue); }
.sf-funnel { display: inline-flex; align-items: center; justify-content: center; width: 12px; height: 12px; border-radius: 2px; color: var(--slate-400); }
.sf-funnel:hover { background: var(--slate-200); color: var(--slate-700); }
.sf-funnel.active { color: var(--blue); }
th .sf-reset { font-weight: 400; font-size: 11px; color: var(--blue); cursor: pointer; margin-left: 8px; }
th .sf-reset:hover { text-decoration: underline; }

/* Mobile */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .dialog-grid, .dialog-grid-2 { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: 1fr; }
}
