:root {
  --paper: #f3f0e7;
  --paper-deep: #e8e2d2;
  --ink: #17211b;
  --ink-soft: #4f5c53;
  --line: rgba(23, 33, 27, 0.17);
  --panel: rgba(250, 248, 241, 0.94);
  --moss: #315b43;
  --moss-dark: #20402f;
  --signal: #e96f36;
  --signal-dark: #c94f1c;
  --ok: #1f7548;
  --warn: #a95d18;
  --danger: #a7352a;
  --shadow: 0 22px 70px rgba(30, 39, 32, 0.14);
  --display: "Noto Serif SC", "Songti SC", "STSong", serif;
  --body: "Noto Sans CJK SC", "Microsoft YaHei", "PingFang SC", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--paper);
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  background:
    linear-gradient(rgba(23, 33, 27, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 33, 27, 0.035) 1px, transparent 1px),
    radial-gradient(circle at 12% 8%, rgba(233, 111, 54, 0.13), transparent 28rem),
    radial-gradient(circle at 88% 82%, rgba(49, 91, 67, 0.14), transparent 32rem),
    var(--paper);
  background-size: 34px 34px, 34px 34px, auto, auto, auto;
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
}

body::before {
  position: fixed;
  inset: 0;
  content: "";
  pointer-events: none;
  opacity: 0.2;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.13'/%3E%3C/svg%3E");
}

button,
input,
select {
  font: inherit;
}

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

.app {
  position: relative;
  width: min(1240px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 34px 0;
}

.login-panel,
.workbench {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(23, 33, 27, 0.24);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.login-panel::after,
.workbench::after {
  position: absolute;
  top: 0;
  right: 0;
  width: 160px;
  height: 9px;
  content: "";
  background: var(--signal);
}

.login-panel {
  width: min(520px, 100%);
  margin: 7vh auto 0;
  padding: 42px;
  animation: panel-in 520ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.eyebrow,
.summary-kicker {
  color: var(--signal-dark);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand {
  display: flex;
  gap: 18px;
  align-items: center;
  margin: 24px 0 34px;
}

.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 68px;
  height: 68px;
  color: #fffaf0;
  background: var(--ink);
  box-shadow: 7px 7px 0 var(--signal);
  font-family: var(--display);
  font-size: 30px;
  font-weight: 900;
  transform: rotate(-3deg);
}

h1,
p {
  margin: 0;
}

h1 {
  font-family: var(--display);
  font-size: 46px;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1.05;
}

p {
  margin-top: 8px;
  color: var(--ink-soft);
  line-height: 1.7;
}

.stack,
.toolbar {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

input,
select {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 0 13px;
  color: var(--ink);
  background: rgba(255, 254, 249, 0.9);
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

input:hover,
select:hover {
  background: #fffef9;
}

input:focus,
select:focus {
  border-color: var(--moss);
  background: #fffef9;
  box-shadow: 0 0 0 3px rgba(49, 91, 67, 0.14);
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 0;
  padding: 0 17px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 150ms ease, background 150ms ease, color 150ms ease, box-shadow 150ms ease;
}

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

button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(233, 111, 54, 0.45);
  outline-offset: 3px;
}

.primary {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  color: #fffaf0;
  background: var(--ink);
  box-shadow: 5px 5px 0 var(--signal);
}

.primary b {
  color: #ffc09f;
  font-size: 19px;
}

.primary:hover:not(:disabled) {
  color: #fff;
  background: var(--moss-dark);
  box-shadow: 7px 7px 0 var(--signal);
  transform: translate(-2px, -2px);
}

.ghost {
  color: var(--ink);
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--line);
}

.ghost:hover:not(:disabled) {
  color: #fff;
  background: var(--ink);
}

.privacy-note {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.workbench {
  min-height: calc(100vh - 68px);
  animation: panel-in 420ms ease both;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 28px 30px;
  border-bottom: 1px solid var(--line);
  background: rgba(232, 226, 210, 0.5);
}

.topbar h1 {
  margin-top: 7px;
  font-size: 40px;
}

.topbar p {
  margin-top: 5px;
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.favorite-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.favorite-toggle[aria-pressed="true"] {
  color: #fffaf0;
  background: var(--moss);
  box-shadow: inset 0 0 0 1px var(--moss);
}

.favorite-toggle-icon {
  color: var(--signal);
  font-size: 17px;
  line-height: 1;
}

.favorite-toggle[aria-pressed="true"] .favorite-toggle-icon {
  color: #ffc09f;
}

.favorite-count {
  display: inline-grid;
  place-items: center;
  min-width: 21px;
  height: 21px;
  padding: 0 5px;
  color: #fffaf0;
  background: var(--signal-dark);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.toolbar {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: end;
  padding: 26px 30px 24px;
}

.search-box,
.block-keywords {
  grid-column: span 2;
}

.search-actions {
  display: grid;
  grid-column: span 2;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.favorites-toolbar {
  display: flex;
  min-height: 98px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 24px 30px;
  border-bottom: 1px solid var(--line);
  background: rgba(232, 226, 210, 0.5);
}

.favorites-view-title {
  font-family: var(--display);
  font-size: 20px;
  font-weight: 900;
}

.refresh-favorites {
  display: inline-flex;
  min-width: 126px;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.refresh-icon {
  color: var(--signal-dark);
  font-size: 19px;
  line-height: 1;
}

.search-submit,
.live-search {
  min-height: 46px;
}

.live-search {
  color: #fffaf0;
  background: var(--signal-dark);
  box-shadow: 4px 4px 0 var(--ink);
}

.live-search:hover:not(:disabled) {
  background: var(--signal);
  box-shadow: 6px 6px 0 var(--ink);
  transform: translate(-2px, -2px);
}

.range-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.range-inputs input {
  min-width: 0;
}

.summary {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  padding: 18px 30px;
  color: var(--ink-soft);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 254, 249, 0.5);
}

.summary > div:first-child {
  display: grid;
  gap: 6px;
}

#summaryText {
  font-size: 13px;
  font-weight: 700;
}

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pager button {
  min-height: 34px;
  height: 34px;
}

.page-size-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-size-control span,
#pageText {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 800;
}

.page-size-control select {
  width: 94px;
  height: 34px;
}

.progress-panel {
  padding: 15px 30px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--ink);
}

.progress-line {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 11px;
  color: #bac5bd;
  font-size: 13px;
}

.progress-line span:first-child {
  color: #fffaf0;
  font-weight: 800;
}

.progress-track {
  width: 100%;
  height: 5px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.15);
}

.progress-bar {
  width: 0;
  height: 100%;
  background: var(--signal);
  transition: width 180ms ease;
}

.table-wrap {
  overflow-x: auto;
  background: rgba(255, 254, 249, 0.68);
}

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

th,
td {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--ink-soft);
  background: #e8e2d2;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
}

tbody tr {
  transition: background 140ms ease;
}

tbody tr:hover {
  background: rgba(233, 111, 54, 0.07);
}

tbody tr.lowest-row {
  background: rgba(31, 117, 72, 0.07);
}

th:nth-child(1),
td:nth-child(1) {
  min-width: 330px;
}

th:nth-child(2),
td:nth-child(2) {
  min-width: 96px;
}

th:nth-child(3),
td:nth-child(3),
th:nth-child(4),
td:nth-child(4) {
  min-width: 100px;
}

th:nth-child(5),
td:nth-child(5) {
  min-width: 125px;
}

th:nth-child(6),
td:nth-child(6) {
  min-width: 88px;
}

th:nth-child(7),
td:nth-child(7) {
  min-width: 88px;
}

.goods-name {
  font-family: var(--display);
  font-size: 16px;
  font-weight: 900;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.goods-name a,
.key-link {
  color: var(--ink);
  text-decoration-color: rgba(233, 111, 54, 0.55);
  text-underline-offset: 4px;
}

.goods-name a:hover,
.key-link:hover {
  color: var(--signal-dark);
}

.key-link {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
}

.detail-link {
  display: inline-grid;
  place-items: center;
  height: 34px;
  min-width: 62px;
  color: #fffaf0;
  background: var(--moss);
  font-size: 12px;
  font-weight: 900;
  text-decoration: none;
  transition: transform 150ms ease, background 150ms ease;
}

.detail-link:hover {
  background: var(--signal-dark);
  transform: translateY(-2px);
}

.favorite-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 72px;
  height: 34px;
  min-height: 34px;
  padding: 0 10px;
  color: var(--ink-soft);
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 12px;
}

.favorite-action:hover:not(:disabled) {
  color: #fffaf0;
  background: var(--ink);
}

.favorite-action[aria-pressed="true"] {
  color: #fffaf0;
  background: var(--signal-dark);
  box-shadow: inset 0 0 0 1px var(--signal-dark);
}

.favorite-action-icon {
  color: var(--signal);
  font-size: 15px;
  line-height: 1;
}

.favorite-action[aria-pressed="true"] .favorite-action-icon {
  color: #ffc09f;
}

.goods-meta {
  margin-top: 5px;
  color: var(--ink-soft);
  font-size: 12px;
}

.badge,
.lowest-tag {
  display: inline-flex;
  align-items: center;
  min-width: 58px;
  height: 27px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 900;
}

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

.badge.empty-stock {
  color: #fff;
  background: var(--warn);
}

.badge.offline {
  color: var(--ink-soft);
  background: var(--paper-deep);
}

.badge.muted {
  color: #fff;
  background: #765286;
}

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

.price {
  color: var(--signal-dark);
  font-family: var(--display);
  font-size: 17px;
  font-weight: 900;
}

.lowest-tag {
  min-width: 0;
  height: 22px;
  margin-left: 7px;
  padding: 0 7px;
  color: #fff;
  background: var(--ok);
  font-family: var(--body);
  font-size: 10px;
  vertical-align: 2px;
}

.empty {
  height: 250px;
  color: var(--ink-soft);
  text-align: center;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: min(440px, calc(100vw - 48px));
  padding: 14px 17px;
  color: #fffaf0;
  border-left: 5px solid var(--signal);
  background: var(--ink);
  box-shadow: var(--shadow);
  animation: toast-in 220ms ease both;
}

.toast.error {
  background: var(--danger);
}

.hidden {
  display: none !important;
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 980px) {
  .toolbar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .app {
    width: min(100vw - 20px, 1240px);
    padding: 10px 0;
  }

  .login-panel {
    margin-top: 3vh;
    padding: 28px 22px;
  }

  h1 {
    font-size: 38px;
  }

  .brand {
    align-items: flex-start;
  }

  .brand-mark {
    width: 58px;
    height: 58px;
    font-size: 25px;
  }

  .topbar,
  .summary {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: space-between;
  }

  .topbar-actions > button {
    flex: 1;
  }

  .topbar,
  .toolbar,
  .favorites-toolbar,
  .summary {
    padding-right: 18px;
    padding-left: 18px;
  }

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

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

  .search-box,
  .block-keywords,
  .search-actions {
    grid-column: span 1;
  }

  .pager {
    justify-content: space-between;
  }

  .page-size-control {
    width: 100%;
  }

  .page-size-control select {
    flex: 1;
  }

  .progress-line {
    flex-direction: column;
    gap: 5px;
  }

  table {
    min-width: 890px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
