* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: #1f2937;
  background: #f6f7fb;
}
a { color: #2563eb; text-decoration: none; }
.app-shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: #111827; color: #e5e7eb; padding: 18px 14px; }
.brand { font-weight: 700; line-height: 1.3; margin-bottom: 20px; }
.nav a, .logout-button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  color: #d1d5db;
  text-align: left;
  padding: 9px 10px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}
.nav a:hover, .logout-button:hover { background: #1f2937; color: #fff; }
.main { padding: 24px; overflow-x: auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; }
h1 { font-size: 24px; margin: 0; }
h2 { font-size: 18px; margin: 22px 0 10px; }
.muted { color: #6b7280; font-size: 13px; }
.flash { padding: 10px 12px; border-radius: 6px; margin-bottom: 16px; }
.flash.success { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.flash.error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.panel { background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 16px; margin-bottom: 18px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 14px; }
.stat strong { display: block; font-size: 22px; margin-top: 4px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid #e5e7eb; }
th, td { padding: 9px 10px; border-bottom: 1px solid #e5e7eb; text-align: left; vertical-align: top; font-size: 14px; }
th { background: #f9fafb; color: #374151; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
form.inline { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.form-grid.compact { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); align-items: end; }
.product-form { grid-template-columns: repeat(auto-fit, minmax(140px, 160px)); align-items: end; }
.product-form label { width: 100%; }
.product-form textarea.compact-textarea { min-height: 38px; height: 38px; }
.section-tabs {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: -8px 0 16px;
}
.section-tabs a {
  padding: 7px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: #374151;
  font-size: 14px;
}
.section-tabs a.active {
  border-color: #2563eb;
  background: #eff6ff;
  color: #1d4ed8;
}
.inline-create-form {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}
.inline-create-form label { width: 220px; }
.inline-create-form label.narrow { width: 120px; }
.inline-create-form .submit-label { width: auto; }
.category-create-form .name-field { width: 220px; }
.category-create-form .sort-field { width: 90px; }
.category-create-form .status-field { width: 82px; }
.mapping-form label { width: 220px; }
.mapping-form label.status-field { width: 110px; }
.table-input { min-width: 180px; }
.table-input-small { min-width: 90px; }
.table-select { min-width: 150px; }
.table-select-wide { min-width: 260px; }
.compact-entity-form label,
.compact-plan-form label { width: 150px; }
.compact-entity-form .submit-label,
.compact-plan-form .submit-label { width: auto; }
.plan-item-form label:first-child { width: 180px; }
.plan-item-form label.narrow { width: 82px; }
.upload-card-form {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}
.upload-card-form .small-field { width: 180px; }
.upload-card-form .cards-field {
  width: min(720px, 100%);
  flex-basis: min(720px, 100%);
}
.upload-card-form textarea {
  min-height: 92px;
  height: 120px;
}
.upload-card-form-vertical {
  display: grid;
  grid-template-columns: minmax(160px, 220px);
  align-items: start;
}
.upload-card-form-vertical .small-field {
  width: 220px;
}
.upload-card-form-vertical .cards-field {
  width: min(520px, 100%);
  flex-basis: auto;
}
.upload-card-form-vertical textarea {
  min-height: 120px;
  height: 150px;
}
.password-form {
  display: grid;
  grid-template-columns: minmax(180px, 240px);
  gap: 10px;
  align-items: start;
}
.password-form label {
  width: 240px;
}
.upload-card-form select:disabled,
.delivery-form select:disabled {
  background: #f3f4f6;
  color: #9ca3af;
  cursor: not-allowed;
}
.operation-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  min-width: 720px;
}
.operation-row-small { min-width: 360px; }
.amount-input { width: 120px; }
.remark-input { width: 160px; }
.status-select { width: 96px; }
.button-fit { width: auto; white-space: nowrap; }
label { display: grid; gap: 5px; font-size: 13px; color: #374151; }
input, select, textarea {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 8px 9px;
  font: inherit;
  background: #fff;
}
textarea { min-height: 120px; resize: vertical; }
textarea.compact-textarea { min-height: 42px; height: 42px; resize: vertical; }
.product-thumb {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #f9fafb;
}
.product-thumb.large {
  width: 120px;
  height: 120px;
}
.product-card-image {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 10px;
  border: 1px solid #e5e7eb;
}
.customer-product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.customer-product-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px;
}
.customer-product-card h2 {
  font-size: 15px;
  margin: 6px 0 4px;
  line-height: 1.3;
}
.customer-product-card p {
  margin: 5px 0;
}
.customer-product-thumb {
  width: 76px;
  height: 76px;
  object-fit: cover;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #f9fafb;
}
.customer-product-desc {
  color: #4b5563;
  font-size: 13px;
  line-height: 1.35;
  min-height: 18px;
}
.customer-product-price {
  font-size: 13px;
}
.customer-buy-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
  white-space: nowrap;
}
.customer-buy-row input {
  width: 48px;
  padding: 6px;
}
.customer-buy-row button {
  padding: 6px 10px;
}
button, .button {
  border: 0;
  background: #2563eb;
  color: #fff;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
button.secondary { background: #4b5563; }
button.danger { background: #dc2626; }
.button.secondary { background: #4b5563; }
.button.danger { background: #dc2626; }
.badge { display: inline-block; padding: 2px 7px; border-radius: 999px; background: #e5e7eb; font-size: 12px; }
.code-block { white-space: pre-wrap; background: #111827; color: #f9fafb; padding: 12px; border-radius: 6px; }
.table-pre { white-space: pre-wrap; margin: 0; max-width: 260px; font: inherit; }
@media (max-width: 780px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .main { padding: 16px; }
}
