:root {
  color-scheme: light;
  --page: #eef0f2;
  --surface: #ffffff;
  --surface-soft: #f7f8f9;
  --surface-muted: #f1f3f4;
  --text: #111827;
  --muted: #68737d;
  --border: #d4d9dd;
  --border-strong: #bfc6cc;
  --brand: #b42318;
  --brand-dark: #901c14;
  --brand-soft: #fae9e7;
  --success: #267a55;
  --success-soft: #e9f5ef;
  --warning: #b65300;
  --warning-soft: #fff2df;
  --danger: #c3221a;
  --danger-soft: #fdecea;
  --neutral: #727b84;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}

button,
select,
input {
  font: inherit;
}

button,
label,
select {
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
p {
  margin: 0;
}

.app-shell {
  width: min(1680px, calc(100% - 24px));
  min-height: calc(100vh - 24px);
  margin: 12px auto;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgb(17 24 39 / 5%);
}

.topbar {
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  display: block;
  border-radius: 11px;
}

.brand-copy {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.brand-title-row {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

h1 {
  font-size: 24px;
  line-height: 1.25;
  font-weight: 700;
  white-space: nowrap;
}

h2 {
  font-size: 16px;
  line-height: 1.35;
  font-weight: 700;
}

.brand-separator {
  width: 1px;
  height: 18px;
  flex: 0 0 1px;
  background: var(--border-strong);
}

#libraryStatus,
.brand-subtitle,
.panel-head p,
.control-head p {
  color: var(--muted);
  font-size: 13px;
}

.brand-subtitle {
  display: none;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

button {
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

button:hover:not(:disabled) {
  border-color: #9ea6ad;
  background: var(--surface-soft);
}

button.button-strong {
  border-color: var(--brand);
  background: var(--brand);
  color: #ffffff;
}

button.button-strong:hover:not(:disabled) {
  border-color: var(--brand-dark);
  background: var(--brand-dark);
}

button.button-soft {
  border-color: #e2b2ad;
  background: var(--brand-soft);
  color: #8e2119;
}

button.button-soft:hover:not(:disabled) {
  border-color: #d68d86;
  background: #f7dbd8;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

.reset-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 13px;
}

.button-symbol {
  font-family: "Segoe UI Symbol", sans-serif;
  font-size: 21px;
  line-height: 1;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.stat-card {
  min-width: 0;
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 24px;
  border: 0;
  border-left: 4px solid var(--neutral);
  border-radius: 0;
  background: var(--surface);
  text-align: left;
}

.stat-card + .stat-card {
  margin-left: 12px;
}

.stat-card[data-filter="ok"] {
  border-left-color: var(--success);
}

.stat-card[data-filter="review"] {
  border-left-color: var(--warning);
}

.stat-card[data-filter="miss"] {
  border-left-color: var(--danger);
}

.stat-card:hover,
.stat-card[aria-pressed="true"] {
  background: var(--surface-muted);
}

.stat-card:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
}

.stat-card span {
  min-width: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
}

.stat-card strong {
  color: var(--text);
  font-size: 30px;
  line-height: 1;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.workbench {
  min-height: 610px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
}

.result-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.panel-head,
.control-head {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.panel-head > div,
.control-head > div {
  min-width: 0;
  display: grid;
  gap: 4px;
}

#runStatus {
  max-width: 50%;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
  overflow-wrap: anywhere;
}

.table-wrap {
  min-width: 0;
  flex: 1;
  overflow: auto;
  max-height: calc(100vh - 286px);
}

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

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid #e1e5e8;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
  line-height: 1.45;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-muted);
  color: #34404a;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: inset 0 -1px 0 var(--border-strong);
}

tbody tr:hover td {
  background: #fafbfb;
}

td {
  max-width: 250px;
  overflow-wrap: anywhere;
}

.reason-cell {
  max-width: 330px;
  color: #46515a;
}

.status {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status.ok {
  border-color: #b9dec9;
  background: var(--success-soft);
  color: var(--success);
}

.status.review {
  border-color: #f0c990;
  background: var(--warning-soft);
  color: var(--warning);
}

.status.miss {
  border-color: #efb6b1;
  background: var(--danger-soft);
  color: var(--danger);
}

.empty {
  height: 300px;
  padding: 60px 16px;
  color: var(--muted);
  text-align: center;
  vertical-align: middle;
}

.control-rail {
  min-width: 0;
  border-left: 1px solid var(--border);
  background: #fafbfc;
}

.control-panel,
.timing-panel {
  background: var(--surface);
}

.offline-badge {
  flex: 0 0 auto;
  padding: 4px 8px;
  border: 1px solid #bfd7c9;
  border-radius: 999px;
  background: var(--success-soft);
  color: var(--success);
  font-size: 11px;
  font-weight: 700;
}

.upload-grid {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.upload-card {
  min-width: 0;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  min-height: 76px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 140ms ease, background-color 140ms ease;
}

.upload-card:hover,
.upload-card:focus-within {
  border-color: #cf7a72;
  background: #fffafa;
}

.upload-index {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 13px;
  font-weight: 700;
}

.upload-copy {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.upload-copy strong {
  overflow: hidden;
  color: #202932;
  font-size: 13px;
  line-height: 1.35;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-name {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-action {
  padding-left: 10px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.settings {
  display: grid;
  gap: 12px;
  padding: 4px 16px 16px;
}

.field {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.field label {
  color: var(--muted);
  font-size: 12px;
}

select {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}

select:focus {
  border-color: var(--brand);
  outline: 2px solid rgb(180 35 24 / 12%);
}

select:disabled {
  background: var(--surface-muted);
  color: #8a939b;
}

.progress-panel {
  display: grid;
  gap: 9px;
  padding: 14px 16px 16px;
  border-top: 1px solid var(--border);
}

.progress-panel[hidden],
.timing-panel[hidden] {
  display: none;
}

.progress-copy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
}

.progress-copy span {
  color: var(--muted);
}

.progress-copy strong {
  color: #3a444d;
  font-weight: 700;
}

.progress-track,
.timing-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e6e9eb;
}

.progress-bar,
.timing-bar {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
  transition: width 160ms ease;
}

.timing-panel {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.timing-summary {
  display: grid;
  gap: 5px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.timing-summary span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.timing-list {
  display: grid;
  gap: 10px;
  padding: 14px 16px 16px;
}

.timing-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 10px;
  font-size: 11px;
}

.timing-name {
  color: #46515a;
}

.timing-track {
  grid-column: 1 / -1;
  grid-row: 2;
}

.timing-value {
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 1100px) {
  .app-shell {
    width: min(100% - 16px, 1680px);
    min-height: calc(100vh - 16px);
    margin: 8px auto;
  }

  .workbench {
    grid-template-columns: 1fr;
  }

  .control-rail {
    grid-row: 1;
    border-left: 0;
    border-bottom: 1px solid var(--border);
  }

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

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

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

  .table-wrap {
    max-height: 620px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: 100%;
    min-height: 100vh;
    margin: 0;
    border-width: 0;
    border-radius: 0;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 14px;
    padding: 14px;
  }

  .brand-mark {
    width: 46px;
    height: 46px;
    flex-basis: 46px;
  }

  .brand-title-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }

  .brand-separator {
    display: none;
  }

  h1 {
    font-size: 20px;
    white-space: normal;
  }

  #libraryStatus {
    font-size: 11px;
  }

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

  .actions button {
    min-width: 0;
    min-height: 40px;
    padding: 0 8px;
    font-size: 12px;
  }

  .button-symbol {
    display: none;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1px;
    padding: 0;
    background: var(--border);
  }

  .stat-card,
  .stat-card + .stat-card {
    min-height: 66px;
    margin: 0;
    padding: 9px 14px;
    background: var(--surface);
  }

  .stat-card strong {
    font-size: 24px;
  }

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

  .upload-card {
    grid-template-columns: 30px minmax(0, 1fr);
  }

  .upload-action {
    grid-column: 2;
    padding-left: 0;
  }

  .panel-head,
  .control-head {
    min-height: 64px;
    padding: 12px 14px;
  }

  #runStatus {
    max-width: 46%;
    font-size: 11px;
  }

  .table-wrap {
    max-height: none;
  }

  table {
    min-width: 1360px;
  }
}

/* Unified desktop scale: matches the production instruction converter. */
@media (min-width: 761px) {
  body {
    font-size: 14px;
  }

  .app-shell {
    display: grid;
    grid-template-rows: 86px 104px minmax(0, 1fr);
    width: calc(100% - 24px);
    height: calc(100vh - 24px);
    min-height: calc(100vh - 24px);
    margin: 12px auto;
    border-radius: 8px;
  }

  .topbar {
    min-height: 86px;
    gap: 24px;
    padding: 16px 28px;
  }

  .brand {
    gap: 14px;
  }

  .brand-mark {
    width: 52px;
    height: 52px;
    flex-basis: 52px;
    border-radius: 8px;
  }

  .brand-copy {
    gap: 5px;
  }

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

  h2 {
    font-size: 16px;
    font-weight: 750;
  }

  #libraryStatus,
  .brand-subtitle,
  .panel-head p,
  .control-head p {
    font-size: 13px;
  }

  .actions {
    gap: 10px;
  }

  button {
    min-height: 40px;
    min-width: 96px;
    padding: 0 16px;
    border-radius: 8px;
    font-weight: 700;
  }

  .reset-button {
    padding-inline: 16px;
  }

  .stats {
    min-height: 104px;
    padding: 12px 28px;
  }

  .stat-card {
    min-height: 76px;
    gap: 10px;
    padding: 10px 18px;
    border-left-width: 3px;
  }

  .stat-card span {
    font-size: 14px;
  }

  .stat-card strong {
    font-size: 30px;
  }

  .workbench {
    min-height: 0;
    grid-template-columns: minmax(0, 2.15fr) minmax(340px, 0.85fr);
  }

  .result-panel,
  .control-rail {
    min-height: 0;
  }

  .table-wrap {
    min-height: 0;
    max-height: none;
  }

  .control-rail {
    overflow: auto;
  }

  .panel-head,
  .control-head {
    min-height: 58px;
    gap: 16px;
    padding: 8px 20px;
  }

  .panel-head > div,
  .control-head > div {
    gap: 2px;
  }

  .upload-grid {
    gap: 12px;
    padding: 0 20px 16px;
  }

  .upload-card {
    min-height: 64px;
    padding: 10px 12px;
    border-radius: 8px;
  }

  .sheet-grid {
    padding: 0 20px 16px;
  }
}
