:root {
  color-scheme: light;
  --page: #edf4f0;
  --page-deep: #dceae3;
  --panel: #fbfdfb;
  --panel-soft: #f2f8f4;
  --ink: #24352f;
  --muted: #5b6b65;
  --line: #d5e2da;
  --line-strong: #b8cfc3;
  --green: #37ad58;
  --green-dark: #238643;
  --green-soft: #e2f5e8;
  --red: #e65c54;
  --red-dark: #bd3e39;
  --blue-soft: #eef6fb;
  --shadow: 0 10px 26px rgba(33, 75, 61, 0.10);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--page);
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(218, 235, 226, 0.96) 0%, rgba(239, 246, 241, 0.98) 42%, rgba(229, 238, 234, 0.98) 100%),
    repeating-linear-gradient(90deg, rgba(35, 134, 67, 0.04) 0 1px, transparent 1px 34px);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
  background:
    linear-gradient(135deg, oklch(25% 0.04 165), oklch(16% 0.035 190));
}

.login-panel {
  width: min(520px, 100%);
  color: oklch(97% 0.01 165);
  padding: 30px;
  text-align: center;
  background: rgba(18, 44, 39, 0.78);
  border: 1px solid rgba(228, 244, 235, 0.18);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.22);
}

.login-panel h1 {
  color: oklch(76% 0.18 145);
  font-size: 24px;
  margin: 0 0 18px;
}

.login-panel pre {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.8;
  color: oklch(90% 0.018 165);
}

.login-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  width: min(340px, 100%);
  margin: 24px auto 0;
}

.login-row input,
.login-row button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
}

.login-row button {
  background: var(--green);
  color: oklch(99% 0.004 145);
  font-weight: 700;
}

.login-error {
  display: block;
  margin-top: 16px;
  color: oklch(89% 0.08 25);
}

.workbench {
  width: min(1180px, calc(100% - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 12px 0 34px;
  text-align: center;
}

.top-actions,
.selector-row,
.table-title,
.table-actions,
.repo-row,
.profit-row,
.percent-row,
.add-row,
.settle-head,
.upstream-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.top-actions {
  width: min(930px, 100%);
  margin: 0 auto 7px;
}

.headline {
  width: min(930px, 100%);
  margin: 0 auto 10px;
  padding: 12px 18px 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.headline h1 {
  margin: 0 0 4px;
  color: var(--green-dark);
  font-size: 26px;
  line-height: 1.15;
}

.headline p {
  min-height: 22px;
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
}

.headline span {
  color: var(--green-dark);
  font-weight: 700;
}

.btn {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  padding: 8px 13px;
  color: oklch(99% 0.004 145);
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 4px 10px rgba(30, 120, 67, 0.14);
}

.btn:disabled,
button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  box-shadow: none;
}

.btn.success {
  background: var(--green);
}

.btn.success:hover,
.btn.success:active {
  background: var(--green-dark);
}

.btn.active {
  background: var(--green-dark);
}

.btn.danger {
  background: var(--red);
  box-shadow: 0 4px 10px rgba(150, 48, 48, 0.14);
}

.btn.danger:hover,
.btn.danger:active {
  background: var(--red-dark);
}

.btn.mini {
  min-width: 78px;
  width: auto;
  min-height: 30px;
  padding: 6px 8px;
  font-size: 12px;
}

.btn.micro {
  min-height: 26px;
  padding: 5px 8px;
  font-size: 12px;
  white-space: nowrap;
}

.btn.block {
  display: block;
  width: 100%;
  margin-top: 7px;
  padding: 8px;
}

.plain {
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 20px;
  box-shadow: none;
}

.link {
  color: oklch(47% 0.16 235);
  font-size: 12px;
  font-weight: 700;
}

.icon-delete {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--red-dark);
  box-shadow: none;
}

.icon-delete::before {
  content: "×";
  font-size: 16px;
  font-weight: 800;
}

.icon-delete:hover {
  background: oklch(96% 0.025 25);
}

.select-current {
  width: 92px;
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  color: oklch(99% 0.004 145);
  background: var(--green);
  padding: 0 10px;
  appearance: none;
  text-align: center;
  font-weight: 700;
}

.select-menu {
  position: relative;
  width: 92px;
  flex: 0 0 auto;
}

.select-current {
  display: block;
  width: 100%;
}

.select-options {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  z-index: 15;
  width: 120px;
  max-height: 210px;
  overflow: auto;
  padding: 5px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--panel);
  box-shadow: 0 12px 28px rgba(33, 75, 61, 0.16);
}

.select-options button {
  display: block;
  width: 100%;
  min-height: 30px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  font-weight: 700;
}

.select-options button:hover {
  background: var(--green-soft);
  color: var(--green-dark);
}

.selector-row {
  width: min(740px, 100%);
  margin: 0 auto 7px;
  padding: 6px 10px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  background: rgba(250, 253, 250, 0.74);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.selector-row b {
  font-size: 18px;
}

.with-line {
  margin-top: 0;
}

.compact {
  width: 100%;
  margin: 6px 0;
  border: 0;
  border-radius: 6px;
  background: var(--panel-soft);
}

.upstream-row {
  margin: 7px 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
}

.recognizer {
  width: min(930px, 100%);
  margin: 0 auto 10px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

textarea {
  width: 100%;
  min-height: 118px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
  background: oklch(99% 0.004 165);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
}

textarea:focus,
input:focus,
.select-current:focus {
  outline: 2px solid rgba(69, 179, 83, 0.24);
  outline-offset: 1px;
}

.error-list {
  width: 100%;
  margin: 7px 0;
  min-height: 0;
  border-radius: 6px;
  background: oklch(96% 0.025 25);
}

.error-list:empty {
  display: none;
}

.error-list p {
  margin: 0;
  padding: 4px 8px;
  color: var(--red-dark);
  text-align: left;
  font-size: 12px;
}

.tables {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.78fr);
  align-items: start;
  gap: 12px;
  width: 100%;
}

.table-card {
  min-width: 0;
  overflow: hidden;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.table-title {
  min-height: 32px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.table-title b {
  font-size: 18px;
}

.total-line,
.hint-line {
  margin: 7px 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.hint-line {
  padding: 5px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.table-actions {
  margin: 7px 0;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  font-size: 14px;
}

.table-scroll {
  max-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
}

.table-scroll table {
  border: 0;
  border-radius: 0;
}

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

th,
td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 5px 5px;
  line-height: 1.3;
  text-align: center;
}

th:last-child,
td:last-child {
  border-right: 0;
}

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

th {
  background: var(--panel-soft);
  color: var(--muted);
  font-weight: 700;
}

tr:nth-child(even) td {
  background: oklch(98% 0.008 165);
}

tbody tr:only-child td[colspan="2"] {
  height: 48px;
  color: var(--muted);
  background: var(--panel-soft);
}

tbody tr td:first-child {
  font-weight: 700;
  color: #2b5744;
}

.repo-row {
  padding-bottom: 4px;
}

.repo-row input,
.add-row input,
.percent-row input,
.settle-head input,
.modal input {
  min-width: 0;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
  background: oklch(99% 0.004 165);
  color: var(--ink);
}

.repo-row input {
  width: 118px;
}

.profit-row {
  padding: 7px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.profit-row b {
  color: var(--muted);
  font-size: 11px;
}

.add-row {
  display: grid;
  grid-template-columns: 1fr auto 68px auto;
  margin-top: 8px;
}

.add-row input:first-child {
  width: 100%;
}

.add-row input:nth-child(3),
.percent-row input {
  width: 68px;
}

.percent-row {
  justify-content: center;
  margin-top: 8px;
}

.copy-box pre {
  margin: 0;
  white-space: pre-wrap;
  font-size: 12px;
  line-height: 1.65;
}

.copy-box {
  width: min(930px, 100%);
  margin: 10px auto 0;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: left;
  box-shadow: var(--shadow);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: start center;
  overflow: auto;
  padding: 22px 12px;
  background: rgba(17, 38, 35, 0.42);
}

.modal {
  width: min(860px, 100%);
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(13, 40, 34, 0.28);
}

.modal header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.modal textarea {
  width: 100%;
  min-height: 360px;
}

.replace-panel textarea {
  min-height: 180px;
}

.dialog-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}

.submit-btn {
  min-width: 120px;
}

.update-toolbar {
  display: grid;
  grid-template-columns: auto auto minmax(180px, 1fr);
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.update-toolbar .active {
  background: var(--green-dark);
}

.order-editor {
  min-height: 390px;
  max-height: min(58vh, 560px);
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  text-align: left;
  line-height: 1.65;
}

.order-editor:focus {
  outline: 2px solid rgba(55, 173, 88, 0.22);
  outline-offset: 1px;
}

.order-group {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
}

.order-group:last-child {
  border-bottom: 0;
}

.order-group h3 {
  margin: 0 0 6px;
  color: var(--red-dark);
  font-size: 14px;
}

.order-group p {
  margin: 2px 0;
  color: var(--ink);
  font-size: 14px;
}

.order-editor mark {
  border-radius: 3px;
  padding: 0 2px;
  background: #ffe679;
  color: #3b2d00;
}

.order-hidden {
  display: none;
}

.edit-list label {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.appraise-panel {
  display: grid;
  gap: 10px;
}

.appraise-top {
  margin-top: 0;
}

.appraise-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.appraise-controls input,
.appraise-controls select {
  min-width: 120px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
  background: #fff;
  color: var(--ink);
}

.risk-table td:nth-child(3) {
  color: var(--red-dark);
  font-weight: 700;
}

.legacy-hidden {
  display: none;
}

.setting-table {
  width: 100%;
  margin-bottom: 10px;
  font-size: 13px;
}

.setting-table input,
.setting-table select,
.check-toolbar select {
  width: 100%;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
  background: #fff;
  color: var(--ink);
}

.setting-table input:disabled,
.setting-table select:disabled {
  color: var(--muted);
  background: var(--panel-soft);
}

.user-setting-table th:first-child,
.user-setting-table td:first-child {
  width: 52px;
}

.check-toolbar {
  display: grid;
  grid-template-columns: 120px auto auto 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.check-toolbar input {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.chip {
  border: 1px solid var(--green);
  border-radius: 6px;
  padding: 6px 10px;
  background: var(--green-soft);
  color: var(--green-dark);
  font-weight: 700;
}

.customer-grid {
  display: grid;
  grid-template-columns: 86px 1fr 78px;
  gap: 8px;
}

.settle-table {
  font-size: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 30;
  transform: translateX(-50%);
  border-radius: 6px;
  padding: 9px 14px;
  background: rgba(18, 44, 39, 0.9);
  color: oklch(99% 0.004 145);
  font-size: 13px;
}

@media (max-width: 780px) {
  .workbench {
    width: min(100%, calc(100% - 12px));
    padding-top: 8px;
  }

  .headline,
  .recognizer,
  .selector-row,
  .contact-footer,
  .copy-box {
    width: 100%;
  }

  .tables {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .table-card {
    padding: 5px;
  }

  .headline h1 {
    font-size: 22px;
  }

  th,
  td {
    padding: 4px 2px;
    font-size: 12px;
  }

  .btn.micro {
    padding: 4px 5px;
    font-size: 10px;
  }

  .repo-row input {
    width: 100%;
  }

  .add-row {
    grid-template-columns: 1fr auto 48px auto;
  }

  .update-toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .update-toolbar input {
    grid-column: 1 / -1;
  }
}

@media (max-width: 520px) {
  .workbench {
    width: 100%;
    padding-left: 4px;
    padding-right: 4px;
  }

  .top-actions {
    padding: 0 2px;
  }

  .headline,
  .recognizer,
  .table-card,
  .contact-footer,
  .copy-box,
  .selector-row {
    border-radius: 6px;
  }

  .selector-row b,
  .table-title b {
    font-size: 15px;
  }

  .select-menu,
  .select-current {
    width: 72px;
  }

  .selector-row {
    grid-template-columns: auto 1fr auto;
  }

  .selector-row b {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .repo-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
  }

  .table-scroll {
    max-height: 460px;
  }
}
