:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #f0f3f6;
  --line: #d8dee6;
  --line-strong: #b7c0cc;
  --text: #1f2933;
  --muted: #697586;
  --brand: #16665c;
  --brand-strong: #0f4d45;
  --warning: #b7791f;
  --danger: #b42318;
  --ok: #13795b;
  --focus: #1c7ed6;
  --shadow: 0 12px 28px rgba(31, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

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

[hidden] {
  display: none !important;
}

body.auth-pending {
  min-width: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  display: grid;
  width: min(380px, 100%);
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 22px;
}

.brand.compact {
  margin-bottom: 8px;
  color: var(--text);
}

.brand.compact div span {
  color: var(--muted);
}

input,
select {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 10px;
  outline: none;
}

input:focus,
select:focus,
button:focus-visible {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(28, 126, 214, 0.15);
  outline: none;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #17212b;
  color: #eef3f6;
  padding: 20px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  margin-bottom: 26px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: #e4f4ef;
  color: var(--brand-strong);
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 16px;
}

.brand div span {
  margin-top: 3px;
  color: #aebbc7;
  font-size: 12px;
}

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

.nav-item {
  height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #d7dee6;
  text-align: left;
  padding: 0 12px;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.login-panel,
.user-panel {
  display: grid;
  gap: 10px;
  margin-top: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding-top: 18px;
}

.login-panel label {
  color: #c8d2dc;
  font-size: 13px;
}

.login-panel input {
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.user-panel .muted-text {
  color: #c8d2dc;
}

.full-button {
  width: 100%;
}

.main-view {
  display: grid;
  grid-template-rows: auto auto 1fr;
  min-width: 0;
  padding: 22px 24px 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar h1,
.panel h2 {
  margin: 0;
  font-weight: 700;
}

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

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

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

.metric {
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
  line-height: 1;
}

.workspace-section {
  display: none;
  min-height: 0;
}

.workspace-section.active {
  display: block;
}

.toolbar,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.search-row {
  display: grid;
  grid-template-columns: minmax(280px, 420px) 150px 84px;
  gap: 10px;
}

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  color: var(--muted);
}

.primary-button,
.ghost-button,
.danger-button {
  min-width: 76px;
  height: 36px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 0 14px;
}

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

.inline-input {
  height: 30px;
  min-width: 86px;
  padding: 0 8px;
}

.action-cell {
  display: flex;
  align-items: center;
  gap: 6px;
}

.primary-button {
  background: var(--brand);
  color: #fff;
}

.primary-button:hover {
  background: var(--brand-strong);
}

.ghost-button {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.ghost-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.danger-button {
  background: var(--danger);
  color: #fff;
}

.table-frame {
  overflow: auto;
  max-height: calc(100vh - 252px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.table-frame.compact {
  max-height: calc(100vh - 342px);
  margin-top: 12px;
  box-shadow: none;
}

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

th,
td {
  height: 42px;
  border-bottom: 1px solid var(--line);
  padding: 0 12px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef2f5;
  color: #45515f;
  font-size: 12px;
  font-weight: 700;
}

tbody tr {
  background: #fff;
}

tbody tr:hover {
  background: #f2f8f6;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: #e9eef3;
  color: #495766;
  font-size: 12px;
  font-weight: 700;
}

.status-pill.verified,
.status-pill.ok {
  background: #e0f2eb;
  color: var(--ok);
}

.status-pill.pending,
.status-pill.warning {
  background: #fff1d6;
  color: var(--warning);
}

.status-pill.error {
  background: #fee4e2;
  color: var(--danger);
}

.status-pill.disabled {
  background: #eceff3;
  color: #6b7280;
}

.status-pill.ready {
  background: #dff3ff;
  color: #0969a8;
}

.status-pill.uploading {
  background: #e7edff;
  color: #3956a4;
}

.status-pill.done {
  background: #e0f2eb;
  color: var(--ok);
}

.status-pill.failed,
.status-pill.conflict {
  background: #fee4e2;
  color: var(--danger);
}

.status-pill.unmatched {
  background: #fff1d6;
  color: var(--warning);
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 14px;
}

.image-workspace {
  display: grid;
  grid-template-columns: minmax(260px, 330px) minmax(260px, 1fr) minmax(280px, 360px);
  gap: 14px;
  margin-bottom: 14px;
}

.panel {
  min-width: 0;
  padding: 16px;
}

.panel h2 {
  margin-bottom: 16px;
  font-size: 16px;
}

.panel form,
.panel label,
.panel input {
  min-width: 0;
}

.panel label {
  display: block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 13px;
}

.panel .primary-button,
.panel .danger-button {
  width: 100%;
  margin-top: 12px;
}

.muted-text {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.import-progress {
  margin-top: 12px;
}

.import-progress[hidden] {
  display: none;
}

.import-progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #45515f;
  font-size: 13px;
  font-weight: 700;
}

.import-progress-track {
  height: 8px;
  overflow: hidden;
  margin-top: 8px;
  border-radius: 999px;
  background: #e4e9ee;
}

.import-progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #1f8a70, #2f80ed);
  transition: width 180ms ease;
}

.import-progress-fill.processing {
  background-image: linear-gradient(90deg, #1f8a70 0%, #2f80ed 50%, #1f8a70 100%);
  background-size: 180% 100%;
  animation: import-progress-pulse 1.2s linear infinite;
}

@keyframes import-progress-pulse {
  from {
    background-position: 0% 0;
  }
  to {
    background-position: 180% 0;
  }
}

.preview-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(84px, 1fr));
  gap: 8px;
}

.image-summary {
  grid-template-columns: repeat(4, minmax(84px, 1fr));
  min-width: 420px;
}

.preview-summary span {
  display: flex;
  align-items: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  padding: 0 10px;
  color: #45515f;
  font-weight: 700;
}

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

.panel-heading-row h2 {
  margin-bottom: 0;
}

.batch-preview-panel {
  padding: 14px;
}

.image-preview-table {
  max-height: calc(100vh - 420px);
  margin-top: 0;
}

.product-detail dl {
  display: grid;
  gap: 10px;
  margin: 0;
}

.product-detail div {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 10px;
}

.product-detail dt {
  color: var(--muted);
}

.product-detail dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.image-preview {
  display: block;
  width: min(360px, 100%);
  max-height: 320px;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: contain;
  background: #fff;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  min-width: 220px;
  max-width: 420px;
  border-radius: 8px;
  background: #17212b;
  color: #fff;
  padding: 12px 14px;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  box-shadow: 0 16px 36px rgba(23, 33, 43, 0.22);
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

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

  .app-shell {
    grid-template-columns: 220px minmax(740px, 1fr);
  }

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

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

  .image-workspace {
    grid-template-columns: 1fr;
  }

  .panel-heading-row {
    align-items: stretch;
    flex-direction: column;
  }

  .image-summary {
    min-width: 0;
  }
}
