:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #667085;
  --line: #d9dee7;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success-bg: #e9f8ef;
  --error-bg: #fdecec;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: Arial, "Microsoft YaHei", sans-serif;
}

.topbar {
  align-items: center;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 20px;
  justify-content: space-between;
  min-height: 64px;
  padding: 0 24px;
}

.brand {
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  text-decoration: none;
}

.nav {
  align-items: center;
  display: flex;
  gap: 12px;
}

.nav a {
  color: var(--text);
  text-decoration: none;
}

.nav form {
  margin: 0;
}

.container {
  margin: 0 auto;
  max-width: 1180px;
  padding: 24px;
}

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

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

.page-head p,
.hint,
.muted,
.note {
  color: var(--muted);
}

.search {
  display: flex;
  gap: 8px;
}

input,
textarea,
select {
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  padding: 10px 12px;
  width: 100%;
}

button,
.button,
.ghost,
.danger {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  justify-content: center;
  line-height: 1;
  padding: 11px 14px;
  text-decoration: none;
  white-space: nowrap;
}

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

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

.ghost {
  background: #eef2f7;
  color: var(--text);
}

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

.small {
  font-size: 14px;
  padding: 8px 10px;
}

.messages {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.message {
  border-radius: 6px;
  padding: 10px 12px;
}

.message.success {
  background: var(--success-bg);
}

.message.error {
  background: var(--error-bg);
}

.login-panel,
.form-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 48px auto;
  max-width: 460px;
  padding: 24px;
}

.form-panel.wide {
  margin: 0 0 20px;
  max-width: none;
}

.form {
  display: grid;
  gap: 14px;
}

.form label {
  display: grid;
  gap: 6px;
  font-weight: 600;
}

.actions {
  display: flex;
  gap: 10px;
}

.readonly-field {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  gap: 6px;
  padding: 10px 12px;
}

.readonly-field span,
.readonly-field a {
  color: var(--muted);
}

.readonly-field strong {
  font-size: 18px;
}

.user-create {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(140px, 1fr) minmax(160px, 1fr) 120px auto;
}

.inline-form,
.user-actions {
  align-items: center;
  display: flex;
  gap: 8px;
}

.inline-form {
  margin: 0;
}

.inline-form input {
  min-width: 150px;
}

.inline-form select {
  min-width: 96px;
}

.item-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
}

.market-section {
  margin-bottom: 26px;
}

.section-head {
  align-items: baseline;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-head h2 {
  font-size: 18px;
  margin-bottom: 0;
}

.section-head span {
  color: var(--muted);
}

.item-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.image-box {
  align-items: center;
  aspect-ratio: 4 / 3;
  background: #e9edf3;
  color: var(--muted);
  display: flex;
  justify-content: center;
}

.image-box img {
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.thumb-box {
  align-items: center;
  background: #eef2f7;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  display: flex;
  height: 52px;
  justify-content: center;
  overflow: hidden;
  width: 52px;
}

.thumb-box img {
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.item-body {
  padding: 16px;
}

.item-title {
  align-items: baseline;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

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

.item-title strong {
  color: var(--primary);
  font-size: 28px;
}

.name {
  font-weight: 700;
}

.meta-line {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 13px;
  gap: 6px;
  margin-bottom: 10px;
}

.meta-line span {
  background: #f1f5f9;
  border-radius: 5px;
  padding: 4px 6px;
}

.stock-form {
  display: grid;
  gap: 8px;
  grid-template-columns: 90px minmax(0, 1fr) auto;
  margin-top: 12px;
}

.row-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.row-actions form {
  margin: 0;
}

.empty {
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 32px;
  text-align: center;
}

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
}

th {
  background: #f8fafc;
}

.inventory-table {
  min-width: 1050px;
}

.movement-table {
  min-width: 980px;
}

.inventory-table th,
.inventory-table td {
  vertical-align: middle;
}

.sku-cell {
  min-width: 180px;
}

.sku-cell strong,
.sku-cell span {
  display: block;
}

.sku-cell span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.quantity-cell {
  color: var(--primary);
  font-size: 18px;
  font-weight: 700;
  text-align: right;
}

.stock-row-form {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 80px 150px auto;
  min-width: 330px;
}

.row-actions.compact {
  margin-top: 0;
}

.movement-summary {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 18px;
}

.movement-summary div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.movement-summary span {
  color: var(--muted);
  display: block;
  margin-bottom: 6px;
}

.movement-summary strong {
  font-size: 20px;
}

.movement-panels {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  margin-bottom: 24px;
}

.movement-panel {
  margin: 0;
  max-width: none;
}

.status-active,
.status-canceled {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  padding: 3px 8px;
}

.status-active {
  background: #e9f8ef;
  color: #166534;
}

.status-canceled {
  background: #fee2e2;
  color: #991b1b;
}

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

.cancel-form {
  align-items: center;
  display: flex;
  gap: 6px;
}

.cancel-form input {
  min-width: 120px;
}

@media (max-width: 760px) {
  .topbar,
  .page-head,
  .nav,
  .search,
  .stock-form,
  .inline-form,
  .user-actions {
    align-items: stretch;
    flex-direction: column;
  }

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

  .stock-form {
    display: grid;
    grid-template-columns: 1fr;
  }

  .stock-row-form {
    grid-template-columns: 1fr;
    min-width: 220px;
  }

  .user-create {
    grid-template-columns: 1fr;
  }
}
