:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #617080;
  --border: #d7dde4;
  --blue: #1f6feb;
  --blue-strong: #164ea6;
  --green: #147d45;
  --red: #c62828;
  --amber: #a15c00;
  --shadow: 0 1px 2px rgba(23, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  font-size: 15px;
}

.hidden {
  display: none !important;
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(244, 246, 248, 0.96);
}

.login-card {
  display: grid;
  gap: 12px;
  width: min(420px, 100%);
  padding: 22px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(23, 32, 42, 0.18);
}

.login-card button {
  width: 100%;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.user-bar button {
  min-width: 64px;
  height: 34px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 12px 18px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  font-weight: 700;
}

h2 {
  font-size: 17px;
  font-weight: 700;
}

#serverStatus {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px;
}

.tabs,
.button-row,
.import-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.user-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

button,
.button,
input,
select {
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 82px;
  padding: 0 12px;
  background: #ffffff;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

button:hover,
.button:hover {
  border-color: #9aa8b6;
}

button:disabled {
  color: #99a2ad;
  cursor: not-allowed;
  background: #eef1f4;
}

.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
}

.primary:hover {
  border-color: var(--blue-strong);
  background: var(--blue-strong);
}

.tab-button {
  min-width: 92px;
  background: #f6f8fa;
}

.tab-button.active {
  border-color: var(--blue);
  color: #ffffff;
  background: var(--blue);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.work-grid,
.settings-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(340px, 1fr);
  gap: 14px;
  align-items: start;
}

.panel {
  margin-bottom: 14px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

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

.work-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.work-actions button {
  min-width: 190px;
}

#nextPalletHint {
  color: var(--muted);
  font-size: 13px;
}

label,
.full-label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  padding: 0 10px;
  background: #ffffff;
  color: var(--text);
}

.combo {
  position: relative;
}

.input-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.input-action button {
  min-width: 76px;
}

input[readonly] {
  background: #f7f9fb;
  color: #3d4b59;
}

.scan-mode {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.scan-mode button {
  min-width: 82px;
  height: 34px;
}

.scan-mode button.active {
  border-color: var(--blue);
  background: #eaf2ff;
  color: #0b4f9c;
  font-weight: 700;
}

#scanModeText {
  color: var(--muted);
  font-size: 13px;
}

.combo-options {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 30;
  display: none;
  max-height: 236px;
  overflow: auto;
  padding: 4px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(23, 32, 42, 0.18);
}

.combo-options.open {
  display: grid;
  gap: 2px;
}

.combo-option {
  justify-content: space-between;
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 0 8px;
  border: 0;
  background: #ffffff;
  color: var(--text);
  text-align: left;
}

.combo-option:hover,
.combo-option.active {
  background: #eaf2ff;
  color: #0b4f9c;
}

.combo-option-count {
  color: var(--muted);
  font-size: 13px;
}

.combo-empty {
  padding: 8px;
  color: var(--muted);
  font-size: 13px;
}

input:focus,
select:focus,
button:focus,
.button:focus {
  outline: 2px solid rgba(31, 111, 235, 0.25);
  outline-offset: 1px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eaf2ff;
  color: #0b4f9c;
  font-size: 13px;
  white-space: nowrap;
}

.badge.muted {
  background: #edf0f2;
  color: #596572;
}

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

.badge.ng {
  background: #fdeaea;
  color: var(--red);
}

.notice {
  margin-bottom: 10px;
  padding: 9px 10px;
  border: 1px solid #e2c77b;
  border-radius: 6px;
  background: #fff8e5;
  color: var(--amber);
  font-size: 13px;
}

.camera-box {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #111820;
  border-radius: 8px;
  border: 1px solid #0f141a;
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-state {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 6px 10px;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.62);
  border-radius: 6px;
  font-size: 14px;
}

.manual-scan {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
  margin-top: 10px;
}

.result-box {
  margin-top: 12px;
  min-height: 56px;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  line-height: 1.45;
  font-weight: 700;
  display: grid;
  gap: 4px;
}

.result-box.neutral {
  background: #f7f9fb;
  color: var(--muted);
}

.result-box.ok {
  border-color: #7cc99a;
  background: #e9f8ef;
  color: var(--green);
}

.result-box.ng {
  border-color: #ef9a9a;
  background: #ffebee;
  color: var(--red);
}

.result-title {
  font-size: 38px;
  line-height: 1;
  letter-spacing: 0;
}

.result-message {
  font-size: 15px;
  overflow-wrap: anywhere;
}

.pallet-counter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f7f9fb;
}

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

.pallet-counter strong {
  font-size: 22px;
  color: var(--blue-strong);
  white-space: nowrap;
}

.progress-summary {
  display: flex;
  align-items: center;
  gap: 8px;
}

.progress-bar {
  height: 10px;
  overflow: hidden;
  background: #e8ecef;
  border-radius: 999px;
  margin-bottom: 10px;
}

#progressBar {
  width: 0;
  height: 100%;
  background: var(--green);
  transition: width 140ms ease;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7f9fb;
  color: #3d4b59;
  font-size: 13px;
}

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

.status-ok {
  color: var(--green);
  font-weight: 700;
}

.status-ng {
  color: var(--red);
  font-weight: 700;
}

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

.stats-row > div {
  display: grid;
  gap: 2px;
  padding: 10px;
  background: #f7f9fb;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.stats-row strong {
  font-size: 22px;
}

.stats-row span,
.helper,
.small-status {
  color: var(--muted);
  font-size: 13px;
}

.helper {
  margin-bottom: 10px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
}

.inline-check input {
  width: 18px;
  height: 18px;
}

td input,
td select {
  min-width: 120px;
}

.records-table {
  max-height: 540px;
}

.small-status {
  margin-top: 8px;
}

@media (max-width: 860px) {
  .app-header {
    position: static;
    align-items: stretch;
    flex-direction: column;
  }

  main {
    padding: 10px;
  }

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

  .manual-scan {
    grid-template-columns: 1fr;
  }

  .button-row,
  .tabs {
    width: 100%;
  }

  .tab-button,
  button,
  .button {
    flex: 1 1 auto;
  }

  table {
    min-width: 680px;
  }
}
