:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #162033;
  --muted: #62708a;
  --border: #dbe2ee;
  --primary: #1769e0;
  --primary-dark: #0d53b8;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --good: #087443;
  --warning: #9a5b00;
  --shadow: 0 18px 44px rgba(22, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  min-height: 40px;
  padding: 0 16px;
  cursor: pointer;
}

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

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.workspace {
  width: min(1440px, 100%);
  margin: 0 auto;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
  font-weight: 750;
}

h2 {
  font-size: 18px;
  line-height: 1.3;
}

.topbar p,
.table-head p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

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

.primary:hover {
  background: var(--primary-dark);
}

.secondary {
  color: var(--text);
  background: #e8eef7;
}

.secondary:hover {
  background: #dce5f2;
}

.query-panel,
.summary-grid,
.compare-shell,
.table-shell {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.query-panel {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 150px 128px;
  gap: 14px;
  align-items: end;
  padding: 16px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

textarea,
input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
}

textarea {
  min-height: 92px;
  resize: vertical;
  padding: 12px;
  line-height: 1.5;
}

input {
  height: 40px;
  padding: 0 11px;
}

textarea:focus,
input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 105, 224, 0.13);
}

.query-button {
  height: 40px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-top: 14px;
  background: var(--border);
}

.metric {
  min-height: 86px;
  padding: 16px;
  background: var(--panel);
}

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

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

.metric.alert strong {
  color: var(--danger);
}

.table-shell {
  margin-top: 14px;
  overflow: hidden;
}

.compare-shell {
  margin-top: 14px;
  overflow: hidden;
}

.compare-head {
  border-bottom: 1px solid var(--border);
}

.compare-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  background: var(--border);
}

.compare-grid .metric small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.metric.accent strong {
  color: var(--primary);
}

.compare-table-scroll {
  overflow: auto;
  max-height: 380px;
}

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

.inline-field {
  width: min(320px, 100%);
}

.table-scroll {
  overflow: auto;
  max-height: calc(100vh - 360px);
  min-height: 320px;
}

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

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 11px 12px;
  text-align: left;
  font-size: 14px;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

td {
  background: #fff;
}

tr.low-stock td {
  background: var(--danger-soft);
}

tr.outbound td {
  background: #eef6ff;
}

.number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.sku {
  font-weight: 700;
}

.name-cell {
  max-width: 420px;
  min-width: 260px;
}

.empty-row td {
  height: 180px;
  color: var(--muted);
  text-align: center;
  vertical-align: middle;
}

.error-text {
  color: var(--danger);
}

.good-text {
  color: var(--good);
}

.warning-text {
  color: var(--warning);
}

@media (max-width: 820px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .table-head {
    display: grid;
  }

  .toolbar {
    justify-content: start;
  }

  .query-panel {
    grid-template-columns: 1fr;
  }

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

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

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