:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --text: #1f2420;
  --muted: #6a7169;
  --line: #dfe4dc;
  --primary: #1f8f68;
  --primary-dark: #126247;
  --amber: #b7791f;
  --red: #b42318;
  --cyan: #147d8c;
  --shadow: 0 12px 30px rgba(31, 36, 32, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 20;
  min-width: 240px;
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -12px);
  transition: 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(31, 36, 32, 0.42);
}

.modal {
  width: min(560px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.modal-sm {
  width: min(440px, 100%);
}

.modal-lg {
  width: min(760px, 100%);
}

.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
}

.modal-header {
  border-bottom: 1px solid var(--line);
}

.modal-header h3 {
  margin: 0;
}

.modal-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 16px;
}

.modal-body.one-col {
  grid-template-columns: 1fr;
}

.modal-message {
  padding: 18px 16px;
  color: var(--muted);
  line-height: 1.7;
}

.modal-body .full {
  grid-column: 1 / -1;
}

.modal-footer {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
}

.login-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 520px) minmax(320px, 440px);
  align-items: center;
  justify-content: center;
  gap: 56px;
  padding: 32px;
}

.login-brand h1 {
  margin: 18px 0 12px;
  font-size: 42px;
  line-height: 1.15;
}

.login-brand p {
  margin: 0;
  max-width: 420px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.7;
}

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

.brand-mark.small {
  width: 38px;
  height: 38px;
  font-size: 14px;
}

.login-panel {
  display: grid;
  gap: 16px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  outline: none;
}

textarea {
  min-height: 150px;
  resize: vertical;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 143, 104, 0.14);
}

.primary-btn,
.ghost-btn,
.text-btn,
.danger-btn {
  min-height: 40px;
  padding: 9px 13px;
  border-radius: 8px;
  border: 1px solid transparent;
  white-space: nowrap;
}

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

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

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

.text-btn {
  color: var(--primary-dark);
  background: #e8f4ef;
}

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

.app {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 238px 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: #fbfcfa;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}

.brand-row strong {
  display: block;
}

.brand-row small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
}

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

.nav button,
.mobile-nav button {
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--muted);
  background: transparent;
  text-align: left;
}

.nav button.active,
.mobile-nav button.active {
  color: var(--primary-dark);
  background: #e8f4ef;
  font-weight: 700;
}

.workspace {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  min-height: 78px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 244, 0.94);
  backdrop-filter: blur(12px);
}

.topbar h2,
.topbar p {
  margin: 0;
}

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

.topbar p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

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

.mobile-nav {
  display: none;
}

.content {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 28px 42px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

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

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

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

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.panel {
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.role-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.permission-list {
  display: grid;
  gap: 8px;
}

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

.panel-header h3,
.panel-header p {
  margin: 0;
}

.panel-header p {
  color: var(--muted);
  font-size: 13px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

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

.form-grid .wide {
  grid-column: span 2;
}

.check-row {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

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

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

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #eef0ec;
}

.badge.green {
  color: var(--primary-dark);
  background: #e8f4ef;
}

.badge.amber {
  color: #7a4b10;
  background: #fff3d8;
}

.badge.red {
  color: var(--red);
  background: #fde7e4;
}

.amount-negative {
  color: var(--red);
}

.amount-positive {
  color: var(--primary-dark);
}

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

.catalog-grid {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}

.sku-card {
  display: flex;
  min-height: 208px;
  flex-direction: column;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: left;
}

.product-tile {
  position: relative;
  overflow: hidden;
  min-height: 0;
  padding: 10px;
  cursor: pointer;
  content-visibility: auto;
  contain-intrinsic-size: 260px 210px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.product-tile:hover,
.product-tile:focus {
  border-color: rgba(31, 143, 104, 0.42);
  box-shadow: 0 10px 26px rgba(31, 36, 32, 0.1);
  transform: translateY(-1px);
  outline: none;
}

.product-tile-body {
  display: grid;
  gap: 2px;
}

.product-tile h4 {
  font-size: 14px;
  line-height: 1.35;
}

.product-tile p {
  font-size: 12px;
  line-height: 1.45;
}

.product-tile .sku-image {
  margin-bottom: 9px;
}

.product-tile .sku-desc {
  min-height: 34px;
  -webkit-line-clamp: 2;
}

.product-tile .card-actions {
  padding-top: 8px;
}

.product-tile .card-actions button {
  min-height: 34px;
  padding: 6px 9px;
  font-size: 13px;
}

.product-tile.is-sold-out {
  border-color: #d6dbd3;
}

.product-tile.is-sold-out:hover,
.product-tile.is-sold-out:focus {
  transform: none;
  box-shadow: none;
}

.sold-out-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  color: #fff;
  background: rgba(86, 91, 86, 0.58);
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0;
  pointer-events: none;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.24);
}

.sku-image,
.detail-image {
  display: block;
  width: 100%;
  border-radius: 8px;
  background: #f2f4f1;
}

.sku-image {
  aspect-ratio: 1 / 1;
  height: auto;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  object-fit: contain;
}

.sku-image-placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.upload-preview {
  display: block;
  width: 100%;
  max-height: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: contain;
  background: #f2f4f1;
}

.table-thumb {
  display: block;
  width: 56px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  object-fit: cover;
  background: #f2f4f1;
}

.detail-image {
  max-height: 320px;
  border: 1px solid var(--line);
  object-fit: contain;
}

.sku-card h4 {
  margin: 0 0 8px;
  font-size: 16px;
}

.sku-card p {
  margin: 4px 0;
  color: var(--muted);
}

.sku-desc {
  display: -webkit-box;
  min-height: 44px;
  overflow: hidden;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
  padding-top: 12px;
}

.card-actions button {
  flex: 1;
}

.detail-text {
  padding: 14px;
  border-radius: 8px;
  color: var(--text);
  background: #f2f4f1;
  line-height: 1.8;
  white-space: pre-wrap;
}

.client-detail-panel {
  min-height: 240px;
}

.client-detail-layout {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr;
  gap: 18px;
  align-items: start;
}

.client-detail-layout.no-image {
  grid-template-columns: 1fr;
}

.client-detail-image {
  width: 100%;
  max-height: 280px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: contain;
  background: #f2f4f1;
}

.client-detail-content {
  min-width: 0;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--muted);
}

.detail-meta span {
  padding: 5px 9px;
  border-radius: 999px;
  background: #eef0ec;
}

.detail-empty {
  min-height: 180px;
  display: grid;
  place-items: center;
}

.product-detail-page {
  min-height: calc(100vh - 150px);
}

.product-detail-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(320px, 1.05fr);
  gap: 24px;
  align-items: start;
}

.product-gallery {
  position: sticky;
  top: 92px;
}

.product-detail-image {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: contain;
  background: #f2f4f1;
}

.product-detail-placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.product-buy-panel {
  display: grid;
  gap: 14px;
}

.product-title-block {
  display: grid;
  gap: 6px;
}

.product-title-block h3,
.product-title-block p {
  margin: 0;
}

.product-title-block h3 {
  font-size: 28px;
  line-height: 1.25;
}

.product-title-block p {
  color: var(--muted);
}

.product-title-block strong {
  font-size: 22px;
  color: var(--primary-dark);
}

.detail-order-form {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(160px, 1.2fr);
  gap: 12px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.detail-order-form button {
  grid-column: 1 / -1;
}

.detail-order-form .full {
  grid-column: 1 / -1;
}

.detail-order-form textarea {
  min-height: 78px;
}

.profit-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.profit-grid div {
  padding: 10px;
  border-radius: 8px;
  background: #f2f4f1;
}

.profit-grid span,
.profit-grid strong {
  display: block;
}

.profit-grid span {
  color: var(--muted);
  font-size: 12px;
}

.profit-grid strong {
  margin-top: 6px;
}

.order-remark {
  display: grid;
  gap: 6px;
  margin: 10px 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f2f4f1;
}

.order-remark strong {
  font-size: 12px;
  color: var(--muted);
}

.order-remark p {
  margin: 0;
  line-height: 1.6;
  white-space: pre-wrap;
}

.order-note-cell {
  max-width: 240px;
  margin-bottom: 8px;
  color: var(--muted);
  line-height: 1.5;
  white-space: pre-wrap;
}

.inventory-editor {
  min-height: 360px;
  font-family: Consolas, "Courier New", monospace;
}

.code-box {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.code-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  background: #f2f4f1;
  font-family: Consolas, "Courier New", monospace;
  word-break: break-all;
}

.code-line button {
  flex: 0 0 auto;
}

.trend {
  display: grid;
  gap: 8px;
}

.trend-row {
  display: grid;
  grid-template-columns: 54px 1fr 78px;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.trend-bar {
  height: 9px;
  border-radius: 999px;
  background: #e8ece6;
  overflow: hidden;
}

.trend-bar span {
  display: block;
  height: 100%;
  background: var(--cyan);
}

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

@media (max-width: 960px) {
  .login-layout {
    grid-template-columns: 1fr;
    gap: 28px;
    align-content: center;
  }

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

  .sidebar {
    display: none;
  }

  .topbar {
    padding: 14px 16px;
  }

  .mobile-nav {
    position: sticky;
    top: 78px;
    z-index: 9;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
    background: rgba(246, 247, 244, 0.96);
  }

  .mobile-nav button {
    flex: 0 0 auto;
    text-align: center;
  }

  .content {
    padding: 16px 14px 32px;
  }

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

  .grid-2,
  .sku-grid,
  .catalog-grid {
    grid-template-columns: 1fr;
  }

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

  .product-detail-grid {
    grid-template-columns: 1fr;
  }

  .product-gallery {
    position: static;
  }

  .product-title-block h3 {
    font-size: 22px;
  }

  .form-grid,
  .form-grid.three {
    grid-template-columns: 1fr;
  }

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

  .form-grid .wide {
    grid-column: auto;
  }
}

@media (max-width: 520px) {
  .login-layout {
    padding: 20px;
  }

  .login-brand h1 {
    font-size: 30px;
  }

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

  .metric strong {
    font-size: 23px;
  }

  .topbar h2 {
    font-size: 19px;
  }

  .modal-body {
    grid-template-columns: 1fr;
  }

  .detail-order-form {
    grid-template-columns: 1fr;
  }
}
