*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --sidebar-bg: #F9FAFB;
  --sidebar-col2-bg: #f9fafb;
  --border: #e5e7eb;
  --active-bg: #dbeafe;
  --active-text: #1d4ed8;
  --hover-bg: #f3f4f6;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --radius: 8px;
}
html, body { height: 100%; font-family: -apple-system, "Microsoft YaHei", "PingFang SC", sans-serif; background: #fff; color: var(--text); font-size: 13px; overflow: hidden; }

/* Header */
.header {
  height: 52px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; border-bottom: 1px solid var(--border); background: #fff;
  flex-shrink: 0; z-index: 10;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-collapse {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  border: none; background: none; cursor: pointer; border-radius: 6px; color: var(--text-secondary);
}
.header-collapse:hover { background: var(--hover-bg); }
.header-logo {
  background: linear-gradient(90deg, #ef4444, #f97316, #eab308, #22c55e, #06b6d4, #3b82f6, #a855f7);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  font-weight: 700; font-size: 15px;
}
.header-right { display: flex; align-items: center; gap: 12px; }
.header-mask-toggle {
  height: 32px; display: inline-flex; align-items: center; gap: 6px;
  padding: 0 10px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; color: var(--text-secondary); cursor: pointer;
  font-size: 12px; font-weight: 500; white-space: nowrap;
}
.header-mask-toggle:hover { background: var(--hover-bg); color: var(--primary); border-color: #bfdbfe; }
.header-mask-toggle.active {
  background: #111827; border-color: #111827; color: #fff;
}
.header-mask-toggle svg { flex-shrink: 0; }
.header-user {
  display: flex; align-items: center; gap: 6px; cursor: pointer;
  padding: 4px 8px; border-radius: 6px; position: relative;
}
.header-user:hover { background: var(--hover-bg); }
.header-user-avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--primary);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}
.header-user-menu {
  display: none; position: absolute; top: 40px; right: 0; min-width: 140px;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12); z-index: 100; padding: 4px;
}
.header-user-menu.show { display: block; }
.header-user-menu button {
  width: 100%; display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border: none; background: none; cursor: pointer;
  border-radius: 4px; font-size: 13px; color: var(--text);
}
.header-user-menu button:hover { background: var(--hover-bg); }

/* Main layout */
.main { display: flex; height: calc(100vh - 52px); overflow: hidden; }

/* Sidebar */
.sidebar { display: flex; border-right: 1px solid var(--border); flex-shrink: 0; transition: width 0.2s; }
.sidebar.collapsed { width: 0 !important; overflow: hidden; border-right: 0; }

/* Column 1 - Years & Sections */
.sidebar-col1 {
  width: 12.5vw; background: var(--sidebar-bg); display: flex; flex-direction: column;
  border-right: 1px solid var(--border); overflow: hidden;
}
.sidebar-col1-inner { flex: 1; overflow-y: auto; padding: 4px 0; }

/* Year item */
.year-item { margin: 2px 8px; }
.year-header {
  display: flex; align-items: center; padding: 7px 12px; border-radius: var(--radius);
  cursor: pointer; border: 1px solid var(--border); background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04); transition: all 0.15s;
}
.year-header:hover { background: var(--hover-bg); }
.year-chevron { width: 16px; height: 16px; margin-right: 6px; color: var(--text-secondary); flex-shrink: 0; transition: transform 0.15s; }
.year-chevron.open { transform: rotate(90deg); }
.year-title { font-weight: 600; flex: 1; font-size: 14px; }
.year-badge { font-size: 11px; color: var(--text-secondary); margin-left: auto; }

/* Section item (under year) */
.section-items { overflow: hidden; transition: max-height 0.2s; }
.section-items.collapsed { max-height: 0; }
.section-item {
  display: flex; align-items: center; padding: 6px 12px 6px 36px; cursor: pointer;
  transition: all 0.1s; color: var(--text);
}
.section-item:hover { background: var(--hover-bg); }
.section-item.active { background: var(--active-bg); color: var(--active-text); font-weight: 500; }
.section-icon { width: 16px; height: 16px; margin-right: 8px; flex-shrink: 0; }
.section-name { flex: 1; }
.section-count { font-size: 11px; color: var(--text-secondary); }

/* Column 1 footer */
.sidebar-col1-footer { padding: 8px; border-top: 1px solid var(--border); flex-shrink: 0; }
.sidebar-col1-footer button {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 4px;
  padding: 6px; border: 1px dashed var(--border); border-radius: var(--radius);
  background: none; cursor: pointer; font-size: 12px; color: var(--text-secondary);
}
.sidebar-col1-footer button:hover { background: var(--hover-bg); border-color: var(--primary); color: var(--primary); }

/* Column 2 - Pages */
.sidebar-col2 {
  width: 12.5vw; background: var(--sidebar-col2-bg); display: flex; flex-direction: column;
  overflow: hidden;
}
.sidebar-col2-header {
  padding: 10px 12px; font-size: 12px; color: var(--text-secondary);
  border-bottom: 1px solid var(--border); flex-shrink: 0; font-weight: 600;
}
.sidebar-col2-inner { flex: 1; overflow-y: auto; padding: 4px 0; }

.page-item {
  display: flex; align-items: center; padding: 6px 12px 6px 20px; cursor: pointer;
  transition: all 0.1s; color: var(--text);
}
.page-item:hover { background: var(--hover-bg); }
.page-item.active { background: var(--active-bg); color: var(--active-text); font-weight: 500; }
.page-icon { width: 14px; height: 14px; margin-right: 8px; flex-shrink: 0; opacity: 0.6; }
.page-title { flex: 1; font-size: 13px; }

.sidebar-col2-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; color: var(--text-secondary); font-size: 13px;
}
.sidebar-col2-empty p { margin-bottom: 8px; }

.sidebar-col2-footer { padding: 8px; border-top: 1px solid var(--border); flex-shrink: 0; }
.sidebar-col2-footer button {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 4px;
  padding: 10px; border: 1px solid #e9d5ff; border-radius: var(--radius);
  background: #faf5ff; cursor: pointer; font-size: 13px; color: #7c3aed;
}
.sidebar-col2-footer button:hover { background: #f3e8ff; }

/* Editor panel */
.editor {
  flex: 1; display: flex; flex-direction: column; background: #fff; overflow: hidden;
  min-width: 0;
}
.editor-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.editor-title { font-size: 16px; font-weight: 600; }
.editor-meta { font-size: 11px; color: var(--text-secondary); }
.editor-meta-chip {
  display: inline-flex; align-items: center; margin-left: 6px; padding: 2px 7px;
  border-radius: 10px; background: #f3f4f6; color: var(--text-secondary);
  font-size: 11px; line-height: 1.4; white-space: nowrap;
}
.editor-meta-chip.ok { background: #dcfce7; color: #15803d; }
.editor-meta-chip.warn { background: #fef3c7; color: #b45309; }
.editor-meta-chip.bad { background: #fee2e2; color: #b91c1c; }
.editor-actions { display: flex; gap: 6px; }
.btn {
  display: inline-flex; align-items: center; gap: 5px; padding: 6px 14px;
  border: none; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 500;
  transition: all 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn-outline:hover { background: #eff6ff; }
.btn-success { background: #16a34a; color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-warning { background: #f59e0b; color: #fff; }
.btn-warning:hover { background: #d97706; }
.btn-sm { padding: 4px 10px; font-size: 11px; }

/* Editor tabs */
.editor-tabs {
  display: flex; gap: 0; padding: 0 16px; border-bottom: 1px solid var(--border);
  background: #fafbfc; flex-shrink: 0;
}
.editor-tab {
  padding: 8px 18px; border: none; background: none; cursor: pointer;
  font-size: 12px; color: var(--text-secondary); font-weight: 500;
  border-bottom: 2px solid transparent; transition: all 0.15s;
}
.editor-tab:hover { color: var(--primary); background: #f0f4ff; }
.editor-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Audit log */
.audit-log { padding: 16px 24px; }
.audit-log-title { font-weight: 600; font-size: 14px; margin-bottom: 12px; }
.audit-timeline { list-style: none; padding: 0; }
.audit-timeline li {
  padding: 8px 0; border-bottom: 1px solid #f3f4f6; font-size: 12px;
  display: flex; align-items: flex-start; gap: 10px;
}
.audit-timeline li .tl-icon {
  width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 10px;
}
.tl-import { background: #dbeafe; color: var(--primary); }
.tl-edit { background: #fed7aa; color: #c2410c; }
.tl-calc { background: #d1fae5; color: #059669; }
.audit-note {
  margin-top: 16px; padding: 14px; background: #f9fafb; border-radius: 8px;
  border: 1px solid var(--border); white-space: pre-wrap; font-size: 12px;
  line-height: 1.7; font-family: inherit; color: var(--text);
}

/* Analysis panel */
.analysis-panel { padding: 16px 24px; font-size: 12px; }
.analysis-section { margin-bottom: 18px; }
.analysis-section h4 { font-size: 13px; font-weight: 600; margin-bottom: 8px; color: var(--primary); }
.anomaly-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 600; }
.anomaly-high { background: #fee2e2; color: #dc2626; }
.anomaly-low { background: #fef3c7; color: #d97706; }
.analysis-chips { display: flex; gap: 4px; flex-wrap: wrap; }
.analysis-chip {
  padding: 3px 10px; border-radius: 12px; background: #f3f4f6;
  font-size: 11px; color: var(--text-secondary);
}
.ds-result {
  padding: 12px 16px; background: linear-gradient(135deg, #eff6ff, #f5f3ff);
  border-radius: 8px; border: 1px solid #c7d2fe; line-height: 1.7;
  font-size: 13px; margin-top: 12px;
}
.ds-result::before {
  content: 'AI 分析'; display: block; font-size: 10px; font-weight: 700;
  color: #6366f1; margin-bottom: 6px; text-transform: uppercase;
}

/* Files panel */
.files-panel { padding: 16px 24px; }
.file-item {
  display: flex; align-items: center; padding: 8px 12px; border-radius: 6px;
  margin-bottom: 4px; gap: 10px; font-size: 12px;
}
.file-item:hover { background: var(--hover-bg); }
.file-icon { font-size: 18px; }
.file-name { font-weight: 500; flex: 1; }
.file-date { color: var(--text-secondary); font-size: 11px; }

.editor-body { flex: 1; overflow: auto; padding: 0; position: relative; }
.data-masked-text {
  letter-spacing: 0;
  text-align: center;
}
.editor-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; color: var(--text-secondary); gap: 12px;
}
.editor-empty-icon { font-size: 48px; opacity: 0.3; }
.editor-empty p { font-size: 14px; }

/* Salary table */
.salary-table-wrap { padding: 0; height: 100%; overflow: auto; }
.salary-table { width: auto; min-width: 100%; border-collapse: collapse; font-size: 13px; table-layout: auto; }
.salary-table th {
  position: sticky; top: 0; z-index: 2; background: #f8f9fb; padding: 10px 8px;
  text-align: center; font-weight: 600; color: var(--text-secondary);
  border-bottom: 2px solid var(--border); white-space: nowrap;
  font-size: 12px; border-right: 1px solid var(--border); line-height: 1.4;
}
.salary-table td {
  padding: 5px 8px; text-align: center; border-bottom: 1px solid #f3f4f6;
  border-right: 1px solid #f3f4f6; cursor: default; white-space: nowrap;
  line-height: 1.2; min-height: 28px;
}
.salary-table th {
  position: sticky; top: 0; z-index: 2; background: #f8f9fb; padding: 8px 8px;
  text-align: center; font-weight: 600; color: var(--text-secondary);
  border-bottom: 2px solid var(--border); white-space: nowrap;
  font-size: 12px; border-right: 1px solid var(--border); line-height: 1.2;
}
.salary-table td:nth-child(1) { position: sticky; left: 0; z-index: 1; background: #fff; text-align: left; padding-left: 10px; }
.salary-table td:nth-child(2) { position: sticky; left: 36px; z-index: 1; background: #fff; text-align: left; font-weight: 500; }
.salary-table th:nth-child(1) { position: sticky; left: 0; z-index: 3; }
.salary-table th:nth-child(2) { position: sticky; left: 36px; z-index: 3; }
.salary-table tr:hover td { background: #f0f7ff; }
.salary-table tr:hover td:nth-child(1),
.salary-table tr:hover td:nth-child(2) { background: #e8f2ff; }
.salary-table td.editable { cursor: cell; }
.salary-table td.editable:hover { background: #fff3cd !important; outline: 1px solid var(--primary); outline-offset: -1px; }
.salary-table td.editable.editing { background: #fff !important; outline: 2px solid var(--primary); outline-offset: -2px; padding: 0; }
.salary-table td.editable input {
  width: 100%; border: none; outline: none; padding: 5px 6px; font-size: 12px; text-align: center;
  font-family: inherit; background: #fff;
}
.salary-table tr.total td {
  font-weight: 700; background: #fffbeb !important; border-top: 2px solid #f59e0b;
  position: sticky; bottom: 0; z-index: 2;
}
.th-filter {
  font-size: 9px; color: #bbb; cursor: pointer; margin-left: 3px; padding: 1px 3px;
  border-radius: 3px; vertical-align: middle;
}
.th-filter:hover { color: var(--primary); background: #e8f0fe; }
.filter-dropdown {
  position: fixed; z-index: 2000; background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  min-width: 140px; max-width: 220px;
}
.filter-opt {
  padding: 6px 12px; cursor: pointer; font-size: 12px; border-bottom: 1px solid #f3f4f6;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.filter-opt:hover { background: var(--hover-bg); color: var(--primary); }
.salary-col-idx { min-width: 36px; }
.salary-col-name { min-width: 60px; }
.salary-col-dept { min-width: 80px; }
.salary-col-num { min-width: 70px; }

/* Toast */
.toast {
  position: fixed; top: 16px; right: 16px; padding: 10px 20px; border-radius: 8px;
  color: #fff; font-size: 13px; z-index: 9999; animation: toast-in 0.3s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.toast-success { background: #16a34a; }
.toast-error { background: #dc2626; }
@keyframes toast-in { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Login page */
.login-page {
  display: flex; justify-content: center; align-items: center;
  min-height: 100vh; background: linear-gradient(135deg, #2563eb, #1e3a5f);
}
.login-card {
  background: #fff; border-radius: 16px; padding: 40px; width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-card h1 { font-size: 22px; text-align: center; color: var(--primary); margin-bottom: 6px; }
.login-card .subtitle { text-align: center; color: var(--text-secondary); font-size: 13px; margin-bottom: 28px; }
.login-form-group { margin-bottom: 16px; }
.login-form-group label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; }
.login-form-group input {
  width: 100%; padding: 10px 14px; border: 2px solid var(--border);
  border-radius: 8px; font-size: 14px; transition: border-color 0.2s; outline: none;
}
.login-form-group input:focus { border-color: var(--primary); }
.login-btn {
  width: 100%; padding: 12px; background: var(--primary); color: #fff;
  border: none; border-radius: 8px; font-size: 15px; font-weight: 600;
  cursor: pointer; margin-top: 8px; transition: background 0.2s;
}
.login-btn:hover { background: var(--primary-hover); }
.login-error { color: #dc2626; font-size: 12px; text-align: center; margin-top: 10px; display: none; }

/* Modal */
.modal-overlay {
  display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4); z-index: 1000; justify-content: center; align-items: center;
}
.modal-overlay.show { display: flex; }
.modal {
  background: #fff; border-radius: 12px; padding: 24px; max-width: 460px; width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal h2 { font-size: 16px; margin-bottom: 16px; }
.modal .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.modal select, .modal input {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px;
}
.modal .btn-group { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* Responsive scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

@media (max-width: 900px) {
  .sidebar-col1 { width: 15vw !important; }
  .sidebar-col2 { width: 15vw !important; }
}
