:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1c2430;
  --muted: #667085;
  --line: #d7dce3;
  --accent: #0f766e;
  --accent-soft: #d9f2ee;
  --warn: #b45309;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px 1fr;
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

aside {
  background: #17202b;
  color: #fff;
  padding: 22px 14px;
}

h1 {
  margin: 0 8px 26px;
  font-size: 20px;
  letter-spacing: 0;
}

nav {
  display: grid;
  gap: 8px;
}

button {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
}

nav button {
  border: 0;
  color: #d9e2ec;
  background: transparent;
  text-align: left;
  padding: 0 12px;
}

nav button.active,
nav button:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

main {
  min-width: 0;
  padding: 24px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.current-user {
  color: var(--muted);
  font-size: 13px;
}

.user-form {
  padding: 14px;
  grid-template-columns: repeat(4, minmax(140px, 1fr)) auto;
  align-items: end;
}

.login-page {
  display: grid;
  grid-template-columns: 1fr;
  place-items: center;
  padding: 24px;
  background: #edf1f5;
}

.login-shell {
  width: min(100%, 380px);
  padding: 0;
}

.login-panel {
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 12px 30px rgba(28, 36, 48, 0.12);
}

.login-panel h1 {
  margin: 0 0 6px;
}

.login-panel p {
  margin: 0 0 24px;
  color: var(--muted);
}

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

.login-panel label {
  display: grid;
  gap: 6px;
  font-size: 13px;
}

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

h2 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.stat {
  padding: 16px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.stat strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.panel {
  overflow: hidden;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-scroll table {
  min-width: max-content;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
}

.panel-title h3 {
  margin: 0;
  font-size: 16px;
}

.legend {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid var(--line);
}

.legend-dot.unreceived {
  background: #fff7d6;
  border-color: #d97706;
}

.legend-dot.partial {
  background: #eef5ff;
  border-color: #2563eb;
}

.legend-dot.return-pending {
  background: #fee2e2;
  border-color: #dc2626;
}

.table-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.table-tools label {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.table-tools input {
  width: 260px;
  max-width: min(260px, 58vw);
  height: 32px;
  font-size: 13px;
}

.table-tools select {
  width: 104px;
  height: 32px;
  padding: 0 8px;
  font-size: 13px;
}

.maintenance-grid {
  display: grid;
  gap: 0;
}

.maintenance-grid > div {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.maintenance-grid > div:last-child {
  border-bottom: 0;
}

.maintenance-grid p {
  margin: 5px 0 10px;
  font-size: 13px;
}

.button-link {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--panel);
  text-decoration: none;
  font-size: 13px;
}

.compact-link {
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

table {
  width: auto;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  padding: 6px 6px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

td input,
td select {
  height: 32px;
  min-width: 0;
  font-size: 12px;
}

td input[data-order-field="orderNo"],
td input[data-receipt-field="receiptNo"] {
  width: 120px;
}

td input[data-order-field="orderDate"],
td input[data-receipt-field="date"] {
  width: 96px;
}

td input[data-item-field="quantity"],
td input[data-item-field="unit"],
td input[data-item-field="unitPrice"],
td input[data-receipt-item-field="quantity"],
td input[data-receipt-item-field="unitPrice"] {
  width: 78px;
}

td input[data-receipt-field="handler"],
td input[data-receipt-field="location"] {
  width: 76px;
}

td input[data-item-field="remark"] {
  width: 120px;
}

td select[data-order-field="supplierId"],
td select[data-item-field="materialId"] {
  width: 150px;
}

th {
  position: relative;
  color: var(--muted);
  font-weight: 600;
  background: #fafbfc;
}

table[data-table-key] {
  table-layout: fixed;
}

table[data-table-key] td input,
table[data-table-key] td select {
  width: 100%;
  max-width: 100%;
}

table[data-table-key="receipts"] th,
table[data-table-key="receipts"] td {
  padding-top: 4px;
  padding-bottom: 4px;
}

table[data-table-key="receipts"] td input,
table[data-table-key="receipts"] td select {
  height: 28px;
  padding: 0 8px;
}

.resize-handle {
  position: absolute;
  top: 0;
  right: -3px;
  z-index: 1;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
}

.resize-handle::after {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 3px;
  width: 1px;
  background: transparent;
}

th:hover .resize-handle::after,
.resize-handle:hover::after {
  background: var(--accent);
}

.pagination {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.pagination label {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 6px;
}

.pagination select {
  width: 72px;
  height: 30px;
  padding: 0 6px;
  font-size: 12px;
}

.pagination button {
  width: 64px;
  height: 30px;
}

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

.order-unreceived td {
  background: #fff7d6;
}

.order-unreceived td:first-child {
  box-shadow: inset 4px 0 0 #d97706;
}

.order-unreceived input,
.order-unreceived select {
  border-color: #e7bd69;
  background: #fffbeb;
}

.order-partial td {
  background: #eef5ff;
}

.order-partial td:first-child {
  box-shadow: inset 4px 0 0 #2563eb;
}

.order-partial input,
.order-partial select {
  border-color: #9fc3ff;
  background: #f8fbff;
}

.order-return-pending td {
  background: #fee2e2;
}

.order-return-pending td:first-child {
  box-shadow: inset 4px 0 0 #dc2626;
}

.order-return-pending input,
.order-return-pending select {
  border-color: #fca5a5;
  background: #fff5f5;
}

.status {
  display: inline-flex;
  align-items: center;
  min-width: 56px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
}

.status.pending {
  background: #fff1d6;
  color: var(--warn);
}

.status.partial {
  background: #e6efff;
  color: #1d4ed8;
}

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.field-actions {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) repeat(3, 52px);
  gap: 6px;
  align-items: center;
}

.field-actions button {
  height: 36px;
  padding: 0;
  font-size: 12px;
}

dialog {
  width: min(720px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  background: var(--panel);
  color: var(--ink);
}

dialog::backdrop {
  background: rgba(23, 32, 43, 0.28);
}

.dialog-form {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.dialog-form h3 {
  margin: 0;
  font-size: 18px;
}

input,
select {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 10px;
  font: inherit;
}

input[name="date"],
input[name="orderDate"],
input[data-order-field="orderDate"],
input[data-receipt-field="date"] {
  width: 96px;
  min-width: 96px;
  max-width: 96px;
  padding: 0 8px;
}

input.new-order-date {
  width: 126px;
  min-width: 126px;
  max-width: 126px;
}

option.option-add {
  background: #dcfce7;
  color: #166534;
}

option.option-edit {
  background: #dbeafe;
  color: #1d4ed8;
}

option.option-delete {
  background: #fee2e2;
  color: #b91c1c;
}

textarea {
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  resize: vertical;
  font: inherit;
}

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

.quick-manage {
  border-bottom: 0;
}

.quick-box {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.quick-box h4 {
  margin: 0;
  font-size: 15px;
}

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

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

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

label input,
label select,
label textarea {
  width: 100%;
  color: var(--ink);
  background: #fff;
  font-size: 14px;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  color: var(--ink);
  font-size: 14px;
}

.checkline input {
  width: 16px;
  height: 16px;
}

.print-area {
  padding: 18px;
  background: #eef1f4;
}

.print-sheet {
  max-width: 960px;
  min-height: 540px;
  margin: 0 auto;
  padding: 28px;
  border: 1px solid var(--line);
  background: #fff;
}

.print-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 10px;
}

.print-company {
  margin-bottom: 4px;
  font-size: 15px;
}

.print-head h3 {
  margin: 0;
  font-size: 24px;
}

.print-head strong {
  font-size: 18px;
}

.print-meta,
.print-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 28px;
  margin-bottom: 14px;
  font-size: 14px;
}

.print-summary {
  justify-content: flex-start;
  padding-left: min(62%, 560px);
  margin-top: 14px;
  margin-bottom: 0;
  font-weight: 600;
}

.print-note {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.contract-picker {
  display: grid;
  gap: 8px;
}

.contract-picker-head {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

.contract-search {
  width: 220px;
}

.contract-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  max-height: 110px;
  overflow: auto;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.contract-check {
  min-height: 24px;
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.small {
  width: 64px;
  height: 30px;
  font-size: 12px;
}

.small.quick {
  width: 78px;
}

.row-actions {
  flex-wrap: nowrap;
  gap: 6px;
}

.receipt-actions {
  flex-wrap: nowrap;
  gap: 4px;
}

.receipt-actions .small {
  width: 44px;
  height: 26px;
  padding: 0;
}

.danger {
  border-color: #b91c1c;
  color: #b91c1c;
}

.return {
  border-color: #2563eb;
  color: #2563eb;
}

.void-row {
  color: var(--muted);
  background: #f6f7f9;
}

.void-row input,
.void-row select {
  background: #eef0f3;
  color: var(--muted);
}

.message {
  min-height: 20px;
  color: var(--accent);
  font-size: 13px;
}

.message.error {
  color: #b91c1c;
}

.price-hint {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-height: 28px;
  font-size: 12px;
}

.price-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 8px;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
}

.price-chip-remove {
  width: 16px;
  height: 16px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #dbeafe;
  color: #1d4ed8;
  line-height: 16px;
  font-size: 13px;
}

.price-chip-remove:hover {
  background: #bfdbfe;
}

.muted {
  color: var(--muted);
}

@media (max-width: 900px) {
  body {
    grid-template-columns: 1fr;
  }

  aside {
    position: sticky;
    top: 0;
    z-index: 2;
  }

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

  nav button {
    text-align: center;
    padding: 0 4px;
  }

  main {
    padding: 16px;
  }

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

  .grid,
  .grid.two {
    grid-template-columns: 1fr;
  }

  .field-actions {
    grid-template-columns: 1fr;
  }

  .user-form {
    grid-template-columns: 1fr;
  }

  .panel {
    overflow: hidden;
  }
}

@media print {
  body {
    display: block;
    min-height: 0;
    background: #fff;
  }

  aside,
  header,
  .print-controls,
  .panel-title {
    display: none !important;
  }

  main,
  .print-area,
  .print-sheet {
    margin: 0;
    padding: 0;
    border: 0;
    max-width: none;
    min-height: 0;
    background: #fff;
  }

  .panel,
  .table-scroll {
    border: 0;
    overflow: visible;
  }

  .table-scroll table {
    min-width: 0;
  }

  th,
  td {
    white-space: normal;
  }
}
