/* 隐藏number输入框的spinner按钮 */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type=number] {
  -moz-appearance: textfield;
}
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  background: #f3f4f6;
  color: #374151;
  line-height: 1.5;
}
.container {
  max-width: none;
  margin: 0 auto;
  padding: 1rem;
}
.card {
  background: white;
  border-radius: 0.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  margin-bottom: 1rem;
}
.card-header {
  padding: 0.75rem;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-body {
  padding: 0.75rem;
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
select, input[type="number"], input[type="file"] {
  border: 1px solid #e5e7eb;
  border-radius: 0.25rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  outline: none;
}
select:focus, input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}
.btn {
  cursor: pointer;
  border: none;
  font-size: 0.875rem;
  border-radius: 0.25rem;
  padding: 0.5rem 1rem;
  color: white;
  white-space: nowrap;
  flex-shrink: 0;
  word-break: keep-all;
}
.btn-primary { background: #3b82f6; }
.btn-primary:hover { background: #2563eb; }
.btn-success { background: #22c55e; }
.btn-success:hover { background: #16a34a; }
.btn-warning { background: #f59e0b; color: #fff; }
.btn-warning:hover { background: #d97706; }
.btn-purple { background: #9333ea; }
.btn-purple:hover { background: #7e22ce; }
.btn-orange { background: #f97316; }
.btn-orange:hover { background: #ea580c; }
.btn-link {
  background: none;
  color: #3b82f6;
  padding: 0.25rem 0.5rem;
}
.btn-link:hover { text-decoration: underline; }
.btn-link-success { color: #22c55e; }
.btn-link-orange { color: #f97316; }
.btn-link-gray { color: #6b7280; }
.btn-company-inactive { background: #e5e7eb; color: #6b7280; }
.btn-company-inactive:hover { background: #d1d5db; }

/* 表格容器：纵向滚动 */
.table-container {
  max-height: 720px;
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
/* 展开行卡片样式 */
.expand-row td {
  padding: 0 !important;
  border: none !important;
  background: transparent !important;
}
.expand-card {
  display: flex;
  flex-direction: column;
  padding: 0;
  background: #f9fafb;
  border-top: 1px solid #e5e7eb;
  border-bottom: 1px solid #e5e7eb;
  font-size: 0.8125rem;
  line-height: 1.6;
}
.expand-card .ec-row-data {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.6rem;
  padding: 0.35rem 0.75rem;
  align-items: center;
}
.ec-actions-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem 0.5rem;
  margin-left: auto;
  flex-wrap: wrap;
}
.ec-edit-field {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}
.ec-edit-field label {
  font-size: 0.75rem;
  color: #6b7280;
  white-space: nowrap;
}
.ec-edit-field .input-sm {
  width: 4.5rem;
  border: 1px solid #d1d5db;
  border-radius: 0.25rem;
}
.ec-edit-field .input-sm:focus {
  border-color: #3b82f6;
  outline: none;
}
.expand-card .ec-item {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
}
.expand-card .ec-label {
  color: #6b7280;
  font-size: 0.75rem;
}
.expand-card .ec-val {
  font-weight: 500;
}
/* 备注行 */
.ec-row-remark {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  padding: 0.25rem 0.75rem 0.35rem;
  border-top: 1px dashed #e5e7eb;
}
.ec-row-remark .ec-label {
  font-size: 0.75rem;
  color: #6b7280;
  white-space: nowrap;
  line-height: 1.8;
}
.ec-remark-input {
  flex: 1;
  border: 1px solid #e5e7eb;
  border-radius: 0.25rem;
  padding: 0.2rem 0.5rem;
  font-size: 0.8125rem;
  resize: vertical;
  min-height: 1.6em;
  line-height: 1.5;
  background: #fff;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s;
}
.ec-remark-input:focus {
  border-color: #3b82f6;
}
.ec-remark-status {
  font-size: 0.7rem;
  color: #9ca3af;
  white-space: nowrap;
  line-height: 1.8;
}
/* 更多按钮 */
.btn-expand {
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  font-size: 0.625rem;
  padding: 0.15rem 0.35rem;
  transition: transform 0.2s, color 0.2s;
}
.btn-expand.open {
  transform: rotate(90deg);
  color: #3b82f6;
}
.btn-expand.has-remark {
  color: #f59e0b;
}
.btn-expand.has-remark.open {
  color: #3b82f6;
}
.btn-expand:hover {
  color: #2563eb;
}
table {
  border-collapse: collapse;
  font-size: 1rem;
}
th, td {
  padding: 0.35rem 0.35rem;
  text-align: left;
}
thead {
  background: #f9fafb;
}
tbody tr:hover {
  background: #f9fafb;
}
tbody tr.editing {
  background: #fef9c3;
}
.divide-y > tr + tr {
  border-top: 1px solid #e5e7eb;
}

/* 工资表 */
.salary-table {
  table-layout: auto;
  width: 100%;
  min-width: 100%;
  max-width: none;
  font-size: 1rem;
}
.salary-table th,
.salary-table td {
  padding: 0.3rem 0.4rem;
}
/* 固定表头 */
.salary-table thead th {
  position: sticky;
  top: 0;
  background-color: #f9fafb;
  z-index: 20;
  box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1);
}
/* 固定姓名列 */
.salary-table th:first-child,
.salary-table td:first-child {
  position: sticky;
  left: 0;
  background-color: white;
  z-index: 10;
  box-shadow: 2px 0 2px -1px rgba(0, 0, 0, 0.1);
  min-width: 4rem;
  max-width: 7rem;
  text-align: center;
}
.salary-table thead th:first-child {
  z-index: 30;
  background-color: #f9fafb;
}
/* 汇总行 */
.summary-row td {
  background: #f3f4f6 !important;
  font-weight: bold;
}
/* 公司汇总表：公司名列勿过窄 */
.company-summary-table {
  max-width: none;
  table-layout: auto;
}
.company-summary-table th,
.company-summary-table td {
  padding: 0.2rem 0.35rem;
}
.company-summary-table th:nth-child(1),
.company-summary-table td:nth-child(1) { min-width: 5.5rem; max-width: 12rem; white-space: normal; word-break: break-all; }
.company-summary-table th:nth-child(2),
.company-summary-table td:nth-child(2) { width: 44px; min-width: 44px; }
.company-summary-table th:nth-child(3),
.company-summary-table td:nth-child(3) { width: 82px; min-width: 82px; }
.company-summary-table th:nth-child(4),
.company-summary-table td:nth-child(4) { width: 82px; min-width: 82px; }
.company-summary-table th:nth-child(5),
.company-summary-table td:nth-child(5) { width: 64px; min-width: 64px; }
.company-summary-table th:nth-child(6),
.company-summary-table td:nth-child(6) { width: 90px; min-width: 90px; }
.company-summary-table th:nth-child(7),
.company-summary-table td:nth-child(7) { width: 90px; min-width: 90px; }
.company-summary-table tfoot td {
  background: #f3f4f6 !important;
  font-weight: bold;
  border-top: 2px solid #d1d5db;
}
tbody tr:hover td:first-child {
  background: #f9fafb;
}
tbody tr.editing td:first-child {
  background: #fef9c3;
}

/* 颜色 */
.text-red { color: #dc2626; }
.text-green { color: #16a34a; }
.text-blue { color: #2563eb; }
.text-purple { color: #9333ea; }
.text-orange { color: #ea580c; }
.text-pink { color: #db2777; }
.text-gray { color: #6b7280; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-medium { font-weight: 500; }
.font-bold { font-weight: 700; }
.whitespace-nowrap { white-space: nowrap; }

/* 弹窗 */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  justify-content: center;
  align-items: center;
  padding: 1rem;
}
.modal-overlay.show {
  display: flex;
}
.modal {
  background: white;
  border-radius: 0.5rem;
  width: 100%;
  max-width: 72rem;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
}
.modal-header {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-body {
  padding: 0.75rem;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 0.5rem 0.75rem;
  border-top: 1px solid #e5e7eb;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}
.close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #6b7280;
}

/* 小输入框 */
.input-sm {
  width: 4rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.8125rem;
  text-align: right;
}
.input-sort-order {
  width: 2.2rem;
  padding: 0.15rem 0.25rem;
  font-size: 0.75rem;
  text-align: center;
  border: 1px solid #e5e7eb;
  border-radius: 0.2rem;
  background: transparent;
}
.input-sort-order:focus {
  border-color: #3b82f6;
  background: #fff;
  outline: none;
}
.input-match {
  width: 6rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.8125rem;
  text-align: right;
}

/* 匹配弹窗表格 */
.match-table {
  font-size: 0.875rem;
  width: 100%;
}
.match-table thead {
  position: sticky;
  top: 0;
  background: #f9fafb;
  z-index: 10;
}
.match-table th, .match-table td {
  padding: 0.35rem;
}
.match-row-matched {
  background: #f0fdf4;
  border-left: 4px solid #22c55e;
}
.match-row-selected {
  background: #fef9c3;
}

/* 信息区 */
.info-box {
  background: #f9fafb;
  padding: 0.5rem;
  border-radius: 0.25rem;
  margin-bottom: 0.5rem;
}
.info-box strong {
  color: #1f2937;
}
.flex { display: flex; }
.gap-4 { gap: 1rem; }
.mt-2 { margin-top: 0.5rem; }
.ml-2 { margin-left: 0.5rem; }

/* 版本号 */
.version {
  color: #9ca3af;
  font-size: 0.8125rem;
}

/* 隐藏文件输入 */
.file-input {
  display: none;
}
.file-label {
  cursor: pointer;
}

/* ===== 公司标签页布局样式 ===== */
.company-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.company-tab-separator {
  color: #d1d5db;
  font-size: 0.875rem;
  margin: 0 0.25rem;
  flex-shrink: 0;
}

.company-tab-group-label {
  font-size: 0.75rem;
  color: #6b7280;
  font-weight: 500;
  flex-shrink: 0;
  margin-right: 0.125rem;
}

.company-tab {
  flex-shrink: 0;
  background: white;
  border-radius: 0.375rem;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.company-tab:hover {
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  transform: translateY(-1px);
}

.company-tab.active {
  background: #2563eb;
  color: white;
}

.company-tab-name {
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
}

.company-tab.active .company-tab-name {
  color: white;
}

.company-tab-stats {
  display: flex;
  gap: 0.5rem;
  font-size: 0.875rem;
}

.company-tab.active .company-tab-stats {
  color: rgba(255, 255, 255, 0.9);
}

/* 公司详情页面 */
.company-detail {
  display: none;
  background: white;
  border-radius: 0.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.company-detail.active {
  display: block;
}

.company-detail-header {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.company-detail-header > div {
  flex-shrink: 0;
}

.company-detail-body {
  padding: 0;
}

/* Month tabs */
.month-tabs {
  display: flex;
  gap: 0;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
  padding: 0 1rem;
  overflow-x: auto;
}
.month-tab {
  padding: 0.5rem 1rem;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.9375rem;
  color: #6b7280;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
}
.month-tab:hover {
  color: #2563eb;
}
.month-tab.active {
  color: #2563eb;
  border-bottom-color: #2563eb;
  font-weight: 500;
}

/* Month content */
.month-content {
  padding: 0.75rem;
}

.month-summary-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: #f9fafb;
  border-radius: 0.375rem;
  font-size: 0.9375rem;
  margin-bottom: 0.5rem;
}

.month-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.accordion-loading {
  padding: 2rem;
  text-align: center;
  color: #9ca3af;
}

/* 员工姓名链接 */
.employee-link {
  color: #2563eb;
  text-decoration: none;
  cursor: pointer;
}
.employee-link:hover {
  text-decoration: underline;
}

/* 总成本链接 */
.cost-link {
  color: #9333ea;
  text-decoration: none;
  cursor: pointer;
}
.cost-link:hover {
  text-decoration: underline;
}

/* 可拖拽调整列宽 */
.resizable-table th {
  position: relative;
}
.resizable-table th .col-resizer {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  cursor: col-resize;
  user-select: none;
}
.resizable-table th .col-resizer:hover,
.resizable-table th .col-resizer.resizing {
  background: #3b82f6;
}

/* 列设置 */
.col-settings-btn {
  background: #f3f4f6; border: 1px solid #e5e7eb; border-radius: 0.25rem;
  padding: 0.3rem 0.5rem; cursor: pointer; font-size: 0.875rem; color: #6b7280; line-height: 1;
}
.col-settings-btn:hover { background: #e5e7eb; }
.col-settings-dropdown {
  position: absolute; top: 100%; right: 0; z-index: 50; margin-top: 4px;
  background: #fff; border: 1px solid #e5e7eb; border-radius: 0.5rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1); padding: 0.5rem; min-width: 140px;
  max-height: 320px; overflow-y: auto;
}
.col-settings-dropdown label {
  display: block; padding: 0.2rem 0.25rem; font-size: 0.8125rem; cursor: pointer;
  white-space: nowrap; border-radius: 0.25rem;
}
.col-settings-dropdown label:hover { background: #f3f4f6; }
.col-settings-dropdown label.mandatory { color: #9ca3af; cursor: default; }
.col-settings-dropdown input { margin-right: 0.4rem; vertical-align: middle; }
/* 列设置操作按钮区 */
.col-settings-actions {
  border-top: 1px solid #e5e7eb;
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  display: flex;
  gap: 0.4rem;
  position: sticky;
  bottom: -0.5rem;
  background: #fff;
  padding-bottom: 0.25rem;
  z-index: 1;
}
.col-settings-save-btn {
  flex: 1;
  background: #3b82f6;
  color: #fff;
  border: none;
  border-radius: 0.25rem;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  font-size: 0.75rem;
  white-space: nowrap;
}
.col-settings-save-btn:hover { background: #2563eb; }
.col-settings-cancel-btn {
  flex: 1;
  background: #e5e7eb;
  color: #374151;
  border: none;
  border-radius: 0.25rem;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  font-size: 0.75rem;
  white-space: nowrap;
}
.col-settings-cancel-btn:hover { background: #d1d5db; }
/* 有未保存修改时按钮高亮 */
.col-settings-btn.col-settings-dirty {
  background: #fef3c7;
  border-color: #f59e0b;
  color: #92400e;
}

/* ==================== 移动端适配 (≤767px) ==================== */
@media (max-width: 767px) {
  body { font-size: 0.8125rem; }
  .container { padding: 0.5rem; }

  /* 顶部卡片头：标题+工具栏紧凑 */
  .card-header {
    padding: 0.5rem;
    flex-wrap: wrap;
    gap: 0.4rem;
  }
  .card-header h1 {
    font-size: 1rem !important;
  }
  /* 顶部按钮紧凑 */
  .toolbar { gap: 0.3rem !important; }
  .toolbar .btn,
  .month-actions .btn,
  .company-detail-header .btn,
  .cd-actions .btn,
  .cd-actions button,
  button.btn {
    padding: 0.3rem 0.5rem !important;
    font-size: 0.7rem !important;
    line-height: 1.3 !important;
    word-break: keep-all !important;
    white-space: nowrap !important;
    min-width: max-content !important;
    flex-shrink: 0 !important;
    width: auto !important;
    height: auto !important;
    writing-mode: horizontal-tb !important;
  }
  /* 公司详情头内层按钮组：允许换行避免按钮被挤压 */
  .company-detail-header > div,
  .cd-actions { flex-wrap: wrap !important; }
  .cd-actions select { flex-shrink: 1; min-width: 0; max-width: 100%; }
  /* 顶部右上角"进入主站"区域 */
  .card-header > div:last-child .btn {
    padding: 0.3rem 0.5rem !important;
    font-size: 0.7rem !important;
  }
  .version { font-size: 0.7rem !important; }

  /* 顶部导入个税 select 缩小 */
  #importTaxCompanyId { width: 80px !important; font-size: 0.75rem; padding: 0.3rem 0.4rem; }

  /* 公司标签：紧凑 */
  .company-tabs { gap: 0.3rem; padding-bottom: 0.3rem; }
  .company-tab { padding: 0.25rem 0.45rem; }
  .company-tab-name { font-size: 0.75rem; }
  .company-tab-stats { font-size: 0.7rem; gap: 0.3rem; }
  .company-tab-group-label { font-size: 0.7rem; }

  /* 公司详情头：紧凑 */
  .company-detail-header {
    padding: 0.5rem;
    gap: 0.35rem;
  }
  .company-detail-header h2 {
    font-size: 0.875rem !important;
  }
  .company-detail-header > div { gap: 0.3rem !important; }
  .company-detail-header select {
    padding: 0.3rem 0.4rem !important;
    font-size: 0.75rem !important;
  }

  /* 月份 tabs */
  .month-tabs { padding: 0 0.4rem; }
  .month-tab { padding: 0.4rem 0.6rem; font-size: 0.8125rem; }

  /* 月度内容区紧凑 */
  .month-content { padding: 0.4rem; }
  .month-summary-strip {
    padding: 0.4rem 0.5rem;
    font-size: 0.75rem;
    gap: 0.3rem 0.5rem;
  }

  /* 工资表：表格自适应+横向滚动 */
  .salary-table {
    font-size: 0.7rem;
    table-layout: auto !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
  }
  .salary-table th,
  .salary-table td {
    padding: 0.25rem 0.2rem;
    white-space: nowrap !important;
    min-width: max-content !important;
    word-break: keep-all !important;
  }
  /* 移动端取消首列 sticky 与固定宽度，避免布局错位 */
  .salary-table th:first-child,
  .salary-table td:first-child {
    position: static !important;
    width: auto !important;
    min-width: max-content !important;
    max-width: none !important;
    box-shadow: none !important;
  }
  /* 重置 colgroup 中的固定 col 宽度（让浏览器自适应） */
  .salary-table colgroup col { width: auto !important; min-width: 0 !important; }
  /* 重置 JS 设置的 inline 列宽（来自 localStorage） */
  .salary-table thead th { width: auto !important; min-width: max-content !important; max-width: none !important; }
  /* 表头允许折行（防止单字竖排） */
  .salary-table th {
    white-space: normal !important;
    word-break: keep-all !important;
    line-height: 1.2;
    font-size: 0.7rem;
  }
  /* 姓名列 sticky 保留，宽度紧凑 */
  .salary-table th:nth-child(2),
  .salary-table td:nth-child(2) {
    min-width: 3.5rem !important;
    max-width: 7rem !important;
  }
  /* 表格容器：开启横向滚动 */
  .table-container {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* 备注/输入框 */
  .ec-remark-input { font-size: 0.75rem; }
  .input-sm { font-size: 0.75rem; width: 3.5rem; }

  /* 公司汇总表（首页/全员）字号缩小 */
  .company-summary-table { font-size: 0.7rem; }
  .company-summary-table th,
  .company-summary-table td { padding: 0.2rem 0.25rem; }

  /* 弹窗：占满屏 */
  .modal-overlay { padding: 0.4rem; }
  .modal { max-height: calc(100vh - 60px); }
  .modal-header { padding: 0.4rem 0.5rem; }
  .modal-body { padding: 0.5rem; }
  .modal-footer { padding: 0.4rem 0.5rem; gap: 0.35rem; }
  .modal-footer .btn {
    padding: 0.35rem 0.55rem !important;
    font-size: 0.75rem !important;
  }
  .match-table { font-size: 0.7rem; }
  .match-table th, .match-table td { padding: 0.25rem; }

  /* 列设置按钮 */
  .col-settings-btn { font-size: 0.75rem; padding: 0.25rem 0.4rem; }
}
