:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-soft: #f7f9fb;
  --text: #202833;
  --muted: #657181;
  --line: #d9e0e8;
  --line-strong: #bdc7d3;
  --blue: #225aa6;
  --green: #16794c;
  --amber: #a35f00;
  --red: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 1120px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

.hidden {
  display: none !important;
}

button {
  font: inherit;
}

.login-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: #eef1f5;
  padding: 24px;
}

.login-page,
.admin-page {
  min-height: 100vh;
  background: #eef1f5;
}

.login-page {
  display: grid;
  place-items: center;
  padding: 28px;
}

.login-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 28px;
  width: min(860px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 28px;
  box-shadow: 0 18px 42px rgb(32 40 51 / 12%);
}

.login-copy {
  display: grid;
  align-content: center;
  gap: 18px;
  border-right: 1px solid var(--line);
  padding-right: 28px;
}

.login-copy h1 {
  font-size: 28px;
}

.login-copy p {
  max-width: 420px;
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.login-copy .login-nowrap {
  max-width: none;
  white-space: nowrap;
}

.standalone-login {
  align-content: center;
}

.login-admin-link {
  color: var(--blue);
  font-size: 13px;
  text-align: center;
  text-decoration: none;
}

.admin-page {
  padding: 26px;
}

.admin-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  max-width: 1240px;
  margin: 0 auto 16px;
}

.admin-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-actions span {
  color: var(--muted);
  font-size: 13px;
}

.admin-page .panel {
  max-width: none;
  margin: 0;
}

.admin-layout {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 16px;
  max-width: 1240px;
  margin: 0 auto;
  align-items: start;
}

.admin-menu {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.admin-menu-item {
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: #334155;
  cursor: pointer;
  padding: 10px 12px;
  text-align: left;
  font: inherit;
  white-space: nowrap;
}

.admin-menu-item.active,
.admin-menu-item:hover {
  border-color: #b7c7dc;
  background: #f7f9fb;
  color: var(--blue);
  font-weight: 700;
}

.admin-main {
  display: grid;
  gap: 16px;
}

.admin-view {
  display: none;
}

.admin-view.active-admin-view {
  display: block;
}

.admin-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto minmax(120px, 0.5fr);
  gap: 12px;
  align-items: end;
}

.company-form {
  grid-template-columns: minmax(160px, 0.8fr) minmax(260px, 1.4fr) auto minmax(140px, 0.6fr);
  margin-bottom: 14px;
}

.user-form {
  grid-template-columns: repeat(4, minmax(150px, 1fr)) auto minmax(120px, 0.5fr);
  margin-bottom: 14px;
}

.reset-form {
  grid-template-columns: minmax(260px, 0.6fr) auto minmax(320px, 1fr);
}

.password-form {
  grid-template-columns: minmax(260px, 0.8fr) minmax(220px, 0.8fr) auto minmax(180px, 1fr);
}

.admin-reset-panel {
  border-color: #f0c6c1;
}

.admin-table {
  margin-top: 6px;
}

.nowrap-table {
  table-layout: auto;
}

.nowrap-table th,
.nowrap-table td {
  white-space: nowrap;
  vertical-align: middle;
}

.admin-form label {
  display: grid;
  gap: 6px;
}

.admin-form span {
  color: var(--muted);
  font-size: 13px;
}

.admin-form input,
.admin-form select {
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--text);
  font: inherit;
}

.login-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 24px;
  box-shadow: 0 18px 40px rgb(15 23 42 / 10%);
}

.login-brand {
  margin-bottom: 20px;
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-form label {
  display: grid;
  gap: 6px;
}

.login-form label span {
  color: var(--muted);
  font-size: 13px;
}

.login-form input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 10px 11px;
  color: var(--text);
  font: inherit;
}

.login-error {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
}

.demo-accounts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 14px;
}

.demo-accounts button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  color: #334155;
  cursor: pointer;
  padding: 8px;
  font-size: 12px;
}

.app-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #ffffff;
  padding: 16px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid #b8c4d4;
  border-radius: 6px;
  background: #fff;
  color: var(--blue);
  font-weight: 800;
}

.brand-name {
  font-size: 16px;
  font-weight: 750;
}

.brand-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.month-card {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  padding: 11px;
  margin-bottom: 14px;
}

.month-card span,
.month-card em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.month-card strong {
  font-size: 20px;
}

.nav-list {
  display: grid;
  gap: 4px;
}

.nav-item {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: #334155;
  cursor: pointer;
  padding: 9px 11px;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  border-color: #b7c7dc;
  background: #fff;
  color: var(--blue);
  font-weight: 700;
}

.main {
  min-width: 0;
  overflow: hidden;
  padding: 16px 20px 28px;
}

.topbar,
.panel-header,
.two-col,
.settlement-grid,
.summary-grid,
.month-flow,
.check-grid {
  display: grid;
  gap: 14px;
}

.topbar {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  margin-bottom: 14px;
}

.top-actions {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.user-chip {
  display: grid;
  align-content: center;
  min-width: 74px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  padding: 6px 10px;
}

.user-chip span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.user-chip {
  min-width: 74px;
  justify-items: center;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 16px;
}

.period-switcher {
  display: grid;
  grid-template-columns: 34px 92px 34px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  overflow: hidden;
}

.period-switcher button {
  height: 34px;
  border: 0;
  background: var(--surface-soft);
  cursor: pointer;
}

.period-switcher strong {
  text-align: center;
  font-size: 14px;
}

.view {
  display: none;
}

.active-view {
  display: grid;
  gap: 16px;
}

#checks.active-view {
  gap: 10px;
}

.summary-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.summary-item,
.panel {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.summary-item {
  display: grid;
  gap: 4px;
  padding: 12px;
}

.summary-item span,
.summary-item small {
  color: var(--muted);
}

.summary-item strong {
  font-size: 22px;
}

.panel {
  min-width: 0;
  overflow: hidden;
  padding: 14px;
}

.deduction-overview {
  padding: 12px 16px;
}

.panel-header {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  margin-bottom: 14px;
}

#checks .panel {
  padding: 10px 12px;
}

#checks .panel-header {
  margin-bottom: 8px;
}

#checks .eyebrow {
  margin-bottom: 2px;
  font-size: 12px;
  line-height: 1.35;
}

.deduction-overview .panel-header {
  margin-bottom: 10px;
}

.primary-action,
.secondary-action {
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  cursor: pointer;
  min-height: 34px;
  padding: 7px 12px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.action-group {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-action.disabled,
.secondary-action.disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.primary-action {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
  font-weight: 700;
}

.danger-action {
  border: 1px solid var(--red);
  border-radius: 6px;
  min-height: 34px;
  padding: 7px 12px;
  background: var(--red);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.secondary-action {
  background: #fff;
  color: var(--text);
}

.text-action {
  border: 0;
  background: transparent;
  color: var(--blue);
  cursor: pointer;
  padding: 0 8px 0 0;
  font-weight: 700;
  white-space: nowrap;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgb(15 23 42 / 28%);
  padding: 24px;
}

.modal-card {
  display: grid;
  gap: 12px;
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 18px;
  box-shadow: 0 18px 42px rgb(32 40 51 / 18%);
}

.modal-card label {
  display: grid;
  gap: 6px;
}

.modal-card label span {
  color: var(--muted);
  font-size: 13px;
}

.modal-card input {
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 10px 11px;
  color: var(--text);
  font: inherit;
}

.modal-actions {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.panel-note {
  color: var(--muted);
  margin: -4px 0 14px;
}

.source-code {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-right: 8px;
}

.import-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  padding: 12px;
  margin-bottom: 14px;
}

#package .panel {
  padding: 12px 14px;
}

#package .panel-header {
  margin-bottom: 10px;
}

#package .import-strip {
  padding: 10px 12px;
  margin-bottom: 10px;
}

.import-strip div {
  display: grid;
  gap: 4px;
}

.import-strip span {
  color: var(--muted);
  font-size: 13px;
}

.file-action {
  position: relative;
  overflow: hidden;
}

.file-action input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.output-status {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.output-status div {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  padding: 12px;
}

.output-status span,
.output-status small {
  color: var(--muted);
  font-size: 12px;
}

.output-status strong {
  font-size: 18px;
}

.deduction-editor {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  padding: 14px;
  margin-bottom: 14px;
}

.deduction-strip {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  padding: 10px 12px;
}

.deduction-strip span,
.deduction-strip strong {
  font-size: 13px;
  line-height: 1.35;
}

.deduction-strip span {
  color: var(--muted);
}

.deduction-strip b {
  color: var(--text);
}

.deduction-summary,
.deduction-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.compact-table th,
.compact-table td {
  padding: 9px 10px;
}

.deduction-price,
.deduction-pool {
  width: 112px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 7px 8px;
  color: var(--text);
  font: inherit;
}

.deduction-footer {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.deduction-footer span {
  color: var(--muted);
  font-size: 13px;
}

.deduction-footer strong {
  font-size: 15px;
}

.negative {
  color: var(--red);
  font-weight: 750;
}

.month-flow {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.step {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 8px;
  min-height: 108px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  padding: 11px;
}

.step.pending {
  opacity: 0.82;
}

.step b {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #e7ecf3;
  color: #334155;
}

.step strong {
  font-size: 15px;
}

.step span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.step.active {
  border-color: #9bbcf0;
  background: #f3f7ff;
}

.step.active b {
  background: #dbeafe;
  color: var(--blue);
}

.step.done {
  border-color: #badbcc;
  background: #f3fbf6;
}

.step.done b {
  background: #d8f0e2;
  color: var(--green);
}

.step.warning {
  border-color: #eed3a6;
  background: #fff8ed;
}

.step.warning b {
  background: #f7e3bd;
  color: var(--amber);
}

.two-col {
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
}

.settlement-grid {
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, 0.9fr);
}

.excel-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.excel-panel {
  overflow: hidden;
}

.excel-panel table {
  table-layout: fixed;
}

.excel-panel th,
.excel-panel td {
  padding: 9px 8px;
  font-size: 12px;
  overflow-wrap: anywhere;
  white-space: normal;
}

table {
  width: 100%;
  border-collapse: collapse;
}

.package-table {
  table-layout: fixed;
}

.fixed-list-table {
  table-layout: fixed;
}

.fixed-list-table th,
.fixed-list-table td {
  height: 34px;
  padding: 7px 10px;
  white-space: nowrap;
  vertical-align: middle;
}

.fixed-list-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.package-table th:nth-child(1),
.package-table td:nth-child(1) {
  width: 190px;
}

.package-table th:nth-child(2),
.package-table td:nth-child(2) {
  width: auto;
}

.package-table th:nth-child(3),
.package-table td:nth-child(3) {
  width: 135px;
}

.package-table th:nth-child(4),
.package-table td:nth-child(4) {
  width: 92px;
}

.package-table th:nth-child(5),
.package-table td:nth-child(5) {
  width: 150px;
}

.package-table th,
.package-table td {
  white-space: nowrap;
}

.package-table td {
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

table.package-table th,
table.package-table td {
  height: 29px;
  padding: 5px 10px;
  white-space: nowrap;
}

table.package-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.check-items-table th:nth-child(1),
.check-items-table td:nth-child(1) {
  width: 200px;
}

.check-items-table th,
.check-items-table td {
  height: 36px;
  padding-top: 5px;
  padding-bottom: 5px;
}

.check-items-table th:nth-child(2),
.check-items-table td:nth-child(2) {
  width: auto;
}

.check-items-table th:nth-child(3),
.check-items-table td:nth-child(3) {
  width: 110px;
}

.check-items-table th:nth-child(4),
.check-items-table td:nth-child(4) {
  width: 360px;
}

.check-items-table td:nth-child(1),
.check-items-table td:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.check-items-table .check-reason-cell {
  height: 39px;
  padding-top: 4px;
  padding-bottom: 4px;
  overflow: hidden;
  white-space: normal;
}

.check-reason-main,
.check-reason-action {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.check-reason-main {
  color: var(--text);
  font-size: 12px;
  line-height: 1.25;
}

.check-reason-action {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  line-height: 1.45;
}

th {
  background: #f1f4f7;
  color: #475569;
  font-size: 13px;
  font-weight: 750;
}

td {
  font-size: 13px;
}

tr:last-child td {
  border-bottom: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 24px;
  border-radius: 999px;
  background: #eef2f7;
  color: #475569;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.ok {
  background: #e8f6ef;
  color: var(--green);
}

.badge.warning {
  background: #fff3da;
  color: var(--amber);
}

.badge.danger {
  background: #ffe9e6;
  color: var(--red);
}

.evidence-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.evidence-list div {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  padding: 11px;
  font-weight: 650;
}

.check-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.check-card {
  display: grid;
  gap: 4px;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  padding: 9px 10px;
  align-content: center;
}

#checks .check-card strong {
  font-size: 14px;
}

.check-card span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.check-card.ok {
  border-color: #badbcc;
  background: #f3fbf6;
}

.check-card.warning {
  border-color: #eed3a6;
  background: #fff8ed;
}

.check-card.danger {
  border-color: #f3b6af;
  background: #fff3f1;
}

.result-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 750;
  background: #eef2f7;
  color: #475569;
  white-space: nowrap;
}

.result-pill.ok {
  background: #e8f6ef;
  color: var(--green);
}

.result-pill.warning {
  background: #fff3da;
  color: var(--amber);
}

.result-pill.danger {
  background: #ffe9e6;
  color: var(--red);
}

.formula-box {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.formula-box div {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  padding: 12px;
}

.formula-box span {
  color: var(--muted);
  font-size: 13px;
}

.formula-box strong {
  font-size: 18px;
}

.action-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 20px;
  line-height: 1.55;
}

@media (max-width: 1180px) {
  body {
    min-width: 0;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 3;
  }

  .nav-list {
    grid-template-columns: repeat(5, minmax(130px, 1fr));
    overflow-x: auto;
  }

  .summary-grid,
  .month-flow,
  .two-col,
  .settlement-grid,
  .excel-grid,
  .check-grid,
  .output-status {
    grid-template-columns: 1fr;
  }

  .topbar,
  .top-actions {
    align-items: stretch;
  }

  .top-actions {
    flex-wrap: wrap;
  }

  .login-card,
  .admin-form {
    grid-template-columns: 1fr;
  }

  .admin-layout {
    grid-template-columns: 1fr;
  }

  .admin-menu {
    grid-template-columns: repeat(4, minmax(120px, 1fr));
    overflow-x: auto;
  }

  .login-copy {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding-right: 0;
    padding-bottom: 20px;
  }
}
