:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --surface: #ffffff;
  --surface-muted: #eef2f5;
  --ink: #1f2933;
  --muted: #667085;
  --line: #d9e0e7;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --danger: #b42318;
  --danger-bg: #fff1f0;
  --warn: #a15c07;
  --warn-bg: #fff7e6;
  --info: #175cd3;
  --info-bg: #eff6ff;
  --ok-bg: #ecfdf3;
  --shadow: 0 18px 48px rgba(28, 45, 59, 0.12);
  --radius: 8px;
  font-family:
    "Microsoft YaHei UI",
    "Microsoft YaHei",
    "Segoe UI",
    system-ui,
    sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(230, 235, 239, 0.78), rgba(245, 247, 249, 0) 320px),
    var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -48px;
  z-index: 20;
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  border-radius: 6px;
}

.skip-link:focus {
  top: 12px;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  padding: 20px 16px;
  background: #16212a;
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

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

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

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

.brand span {
  margin-top: 2px;
  color: #b8c4ce;
  font-size: 12px;
}

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

.nav-item {
  color: #cbd5df;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 6px;
  transition: background 180ms ease, color 180ms ease, transform 180ms ease;
}

.nav-item:hover,
.nav-item:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  outline: none;
}

.nav-item:active {
  transform: translateY(1px);
}

.nav-item.active {
  background: #213440;
  color: #fff;
}

.sidebar-note {
  margin-top: auto;
  padding: 14px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
}

.sidebar-note span,
.sidebar-note p,
.sync-panel span,
.sync-panel small,
.eyebrow,
.panel-head p,
.metric span,
.metric small {
  color: var(--muted);
}

.sidebar-note span {
  color: #b8c4ce;
  font-size: 12px;
}

.sidebar-note strong {
  display: block;
  margin: 4px 0 8px;
  font-size: 20px;
}

.sidebar-note p {
  margin: 0;
  color: #d4dde5;
  line-height: 1.6;
  font-size: 13px;
}

.main {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(28px, 3vw, 42px);
  line-height: 1.1;
}

h2 {
  margin-bottom: 6px;
  font-size: 18px;
}

.header-copy {
  max-width: 620px;
  color: var(--muted);
  line-height: 1.7;
}

.sync-panel {
  min-width: 260px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 10px 30px rgba(28, 45, 59, 0.08);
}

.sync-panel span,
.sync-panel strong,
.sync-panel small,
.sync-panel em {
  display: block;
}

.sync-panel strong {
  margin: 6px 0 4px;
  font-variant-numeric: tabular-nums;
}

.sync-panel em {
  width: fit-content;
  margin: 10px 0 5px;
  padding: 4px 8px;
  border-radius: 5px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 12px;
  font-style: normal;
  font-weight: 700;
}

.sync-panel em[data-status="completed"] {
  background: var(--ok-bg);
  color: var(--accent-dark);
}

.sync-panel em[data-status="blocked"],
.sync-panel em[data-status="failed"] {
  background: var(--danger-bg);
  color: var(--danger);
}

.filter-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.combo {
  position: relative;
}

.combo-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 4px;
}

.combo-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 2px 4px 2px 8px;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.1);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

.combo-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.combo-chip button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.combo-chip button:hover {
  background: var(--accent);
  color: #fff;
}

.combo-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 30;
  max-height: 220px;
  overflow-y: auto;
  margin: 2px 0 0;
  padding: 4px;
  list-style: none;
  background: #fff;
  border: 1px solid #cbd5df;
  border-radius: 6px;
  box-shadow: 0 8px 20px rgba(15, 35, 55, 0.12);
}

.combo-list li {
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.combo-list li:hover {
  background: #f0f4f8;
}

.combo-list li.combo-empty {
  color: #98a2b3;
  cursor: default;
}

.combo-list li.combo-empty:hover {
  background: transparent;
}

.overview-filter {
  grid-template-columns: 160px minmax(220px, 1fr) 220px;
}

.error-banner {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid #f3b4ae;
  border-left: 4px solid var(--danger);
  border-radius: var(--radius);
  background: var(--danger-bg);
  color: #7a271a;
}

.error-banner strong {
  white-space: nowrap;
}

label {
  display: grid;
  gap: 6px;
  color: #475467;
  font-size: 12px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  height: 38px;
  border: 1px solid #cbd5df;
  border-radius: 6px;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.18);
  border-color: var(--accent);
}

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

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

.metric {
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
}

button.metric {
  width: 100%;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

button.metric:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(28, 45, 59, 0.08);
}

button.metric[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.25);
  transform: translateY(-1px);
}

.metric strong {
  display: block;
  margin: 8px 0;
  font-size: 34px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.compact-summary .metric strong {
  font-size: 26px;
}

.metric-restock {
  border-left: 4px solid var(--info);
}

.metric-slow {
  border-left: 4px solid var(--warn);
}

.metric-zero {
  border-left: 4px solid var(--danger);
}

.metric-stock {
  border-left: 4px solid var(--accent);
}

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

.top-panel {
  min-width: 0;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.top-list {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.top-list li {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--ink);
}

.top-list li:hover {
  background: #f0f4f8;
}

.top-title {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.top-title strong {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-title small {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-metric {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.top-list li.top-empty {
  grid-template-columns: 1fr;
  color: var(--muted);
}

.top-list li.top-empty:hover {
  background: transparent;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.table-panel,
.detail-panel,
.rules-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(28, 45, 59, 0.06);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head.compact {
  align-items: flex-start;
}

.panel-head p {
  margin: 0;
  line-height: 1.5;
}

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

.table-wrap {
  overflow-x: visible;
}

.export-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: #fff;
  color: var(--accent-dark);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background 180ms ease, color 180ms ease, border-color 180ms ease;
}

.export-button:hover,
.export-button:focus-visible {
  background: #ecfdf3;
  border-color: var(--accent-dark);
}

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

.col-product {
  width: 18%;
}

.col-sku {
  width: 7%;
}

.col-store {
  width: 12%;
}

.col-scope {
  width: 5%;
}

.col-number {
  width: 5%;
}

.col-number.wide {
  width: 7%;
}

.col-ratio {
  width: 7%;
}

.col-money {
  width: 8%;
}

.col-alert {
  width: 6%;
}

.col-action {
  width: 13%;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid #e8edf2;
  text-align: center;
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: break-word;
}

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

th[data-key] {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th[data-key]::after {
  content: "↕";
  margin-left: 4px;
  color: #b3c0cc;
  font-weight: 400;
}

th[data-key][aria-sort="ascending"]::after {
  content: "↑";
  color: var(--accent);
}

th[data-key][aria-sort="descending"]::after {
  content: "↓";
  color: var(--accent);
}

th[data-key]:hover {
  color: var(--accent);
}

td {
  line-height: 1.45;
  font-size: 12px;
}

td.num {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

th:nth-child(4),
th:nth-child(5),
th:nth-child(6),
th:nth-child(7),
th:nth-child(8),
th:nth-child(9),
th:nth-child(10) {
  text-align: center;
}

tr {
  cursor: pointer;
  transition: background 160ms ease;
}

tbody tr:hover,
tbody tr.selected {
  background: #f0fdfa;
}

.product-name {
  display: block;
  font-weight: 700;
}

.product-spec {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.sku-cell {
  display: inline-block;
  color: #344054;
  font-variant-numeric: tabular-nums;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 5px;
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
}

.badge-restock {
  color: var(--info);
  background: var(--info-bg);
}

.badge-slow {
  color: var(--warn);
  background: var(--warn-bg);
}

.badge-zero {
  color: var(--danger);
  background: var(--danger-bg);
}

.badge-normal {
  color: var(--accent-dark);
  background: var(--ok-bg);
}

.muted-cell {
  color: var(--muted);
  font-size: 11px;
}

.detail-panel {
  position: static;
}

.detail-list {
  margin: 0;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.detail-list div {
  padding-bottom: 14px;
  border-bottom: 1px solid #edf1f5;
}

.detail-list div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

dt {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

dd {
  margin: 0;
  line-height: 1.6;
}

.rules-panel {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 20px;
  margin-top: 16px;
  padding: 18px;
}

.standalone-rules {
  margin-top: 0;
}

.rules-panel p {
  color: var(--muted);
  line-height: 1.6;
}

.rule-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.rule-list li {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 7px;
  background: #f8fafc;
}

.rule-list span {
  color: #475467;
}

.empty-state {
  padding: 32px;
  text-align: center;
  color: var(--muted);
}

.empty-state strong,
.empty-state span {
  display: block;
}

.empty-state strong {
  margin-bottom: 8px;
  color: var(--ink);
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
  }

  .nav-list {
    grid-auto-flow: column;
    overflow-x: auto;
  }

  .sidebar-note {
    display: none;
  }

  .filter-bar,
  .summary-grid,
  .top-grid,
  .rules-panel {
    grid-template-columns: 1fr 1fr;
  }

  .content-grid,
  .detail-list {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    position: static;
  }
}

@media (max-width: 720px) {
  .main {
    padding: 14px;
  }

  .page-header,
  .panel-head,
  .sidebar,
  .error-banner {
    flex-direction: column;
    align-items: stretch;
  }

  .sync-panel {
    min-width: 0;
  }

  .filter-bar,
  .summary-grid,
  .top-grid,
  .content-grid,
  .detail-list,
  .rules-panel {
    grid-template-columns: 1fr;
  }

  th,
  td {
    padding: 8px 5px;
    font-size: 11px;
  }

  .table-wrap table,
  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap td {
    display: block;
    width: 100%;
  }

  .table-wrap thead,
  .table-wrap colgroup {
    display: none;
  }

  .table-wrap tbody {
    display: grid;
    gap: 10px;
    padding: 10px;
  }

  .table-wrap tr {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    overflow: hidden;
  }

  .table-wrap td {
    display: grid;
    grid-template-columns: 86px minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    min-height: 34px;
    border-bottom: 1px solid #edf1f5;
    text-align: left;
  }

  .table-wrap td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
  }

  .table-wrap td.num {
    text-align: left;
  }

  .table-wrap td:last-child {
    border-bottom: 0;
  }

  .product-spec,
  .badge {
    font-size: 10px;
  }

  .rule-list li {
    grid-template-columns: 1fr;
  }
}
