:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --surface: #fffdf8;
  --line: #d8d2c6;
  --text: #1e2722;
  --muted: #637069;
  --accent: #236b55;
  --accent-2: #b96d2b;
  --accent-soft: #e6f0ec;
  --danger: #a33b3b;
  --shadow: 0 14px 34px rgba(29, 40, 33, 0.1);
  font-family: Inter, "Segoe UI", Arial, "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

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

button {
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  min-height: 40px;
  padding: 0 14px;
  font-weight: 700;
}

button:hover {
  filter: brightness(0.96);
}

button.secondary {
  background: #26372f;
}

button.danger {
  background: var(--danger);
}

button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 22px;
  background: rgba(255, 253, 248, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(20px, 2vw, 30px);
  letter-spacing: 0;
}

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

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
}

.top-actions span {
  color: var(--muted);
  font-weight: 700;
}

.language-picker {
  display: flex;
  align-items: center;
  gap: 8px;
}

.language-picker span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.language-picker select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
}

.view-tabs {
  position: sticky;
  top: 73px;
  z-index: 9;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 18px;
  background: rgba(246, 244, 239, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.view-tabs button {
  flex: 0 0 auto;
  min-height: 38px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
}

.view-tabs button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.view-tabs span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  min-height: 22px;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
}

.app-view {
  display: none;
}

.app-view.active {
  display: grid;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 18px;
  padding: 18px;
}

.catalog {
  min-width: 0;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 250px 160px;
  gap: 12px;
  margin-bottom: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  padding: 9px 11px;
  outline: none;
}

.field textarea {
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(35, 107, 85, 0.12);
}

.section-tabs,
.category-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 0 12px;
}

.section-tabs {
  padding-bottom: 10px;
}

.section-tabs button,
.category-tabs button {
  flex: 0 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  min-height: 36px;
  font-weight: 700;
}

.section-tabs button.active,
.category-tabs button.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.product-card {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  gap: 12px;
  min-height: 236px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 0 rgba(29, 40, 33, 0.03);
}

.product-image {
  width: 108px;
  height: 108px;
  border: 1px solid var(--line);
  border-radius: 6px;
  object-fit: contain;
  background: #fff;
}

.image-empty {
  display: grid;
  place-items: center;
  width: 108px;
  height: 108px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: #faf8f2;
  font-size: 12px;
  text-align: center;
}

.product-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.product-code {
  color: var(--accent);
  font-weight: 800;
  font-size: 13px;
}

.product-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.product-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}

.product-badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
}

.product-badge.hot {
  background: #f0e3d4;
  color: #724013;
}

.product-badge.sale {
  background: #f3dfdc;
  color: var(--danger);
}

.product-name {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
  word-break: break-word;
}

.product-meta {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.price-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 7px;
  border-radius: 6px;
  background: #f0e3d4;
  color: #724013;
  font-size: 12px;
  font-weight: 800;
}

.tag.green {
  background: var(--accent-soft);
  color: var(--accent);
}

.tag.sale {
  background: #f3dfdc;
  color: var(--danger);
}

.tag.muted-tag {
  background: #ede8df;
  color: var(--muted);
}

.muted {
  color: var(--muted);
}

.add-row {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 8px;
  margin-top: auto;
}

.qty-input {
  min-width: 0;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 8px;
}

.order-panel {
  position: sticky;
  top: 86px;
  align-self: start;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 104px);
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  margin: 0;
  font-size: 22px;
}

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

.total {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 7px;
  background: #26372f;
  color: #fff;
  font-weight: 800;
  white-space: nowrap;
}

.customer-fields {
  display: grid;
  gap: 10px;
  padding: 12px 0;
}

.currency-field {
  padding-top: 12px;
}

.discount-notice {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  padding: 10px;
  border: 1px solid #b9d8c9;
  border-radius: 8px;
  background: #f1faf5;
}

.discount-notice-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.discount-notice-head span,
.discount-line {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.discount-notice-head strong,
.discount-payable {
  color: var(--accent);
  font-weight: 800;
}

.discount-payable {
  padding-top: 4px;
  border-top: 1px solid #d7eadf;
}

.detail-currency {
  padding: 0 0 12px;
}

.cart-items {
  overflow: auto;
  display: grid;
  gap: 8px;
  padding-right: 2px;
}

.cart-empty {
  display: grid;
  place-items: center;
  min-height: 120px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.cart-item {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 70px 32px;
  gap: 8px;
  align-items: center;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf6;
}

.cart-item strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.cart-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.cart-item em {
  display: block;
  color: var(--accent-2);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
  margin-top: 2px;
}

.cart-thumb,
.cart-thumb-empty {
  width: 56px;
  height: 56px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.cart-thumb {
  object-fit: contain;
}

.cart-thumb-empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 10px;
  text-align: center;
}

.cart-item input {
  width: 70px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 7px;
}

.remove-btn {
  width: 32px;
  min-height: 32px;
  padding: 0;
  background: #f3dfdc;
  color: var(--danger);
}

.order-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding-top: 12px;
}

.order-actions button:first-child {
  grid-column: 1 / -1;
}

.notify-sales-btn {
  grid-column: 1 / -1;
  background: #1f6f55;
}

.notify-sales-btn:hover {
  background: #185944;
}

.page-view {
  gap: 14px;
  padding: 18px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.page-header h2 {
  margin: 0;
  font-size: 26px;
}

.page-header p,
.hint {
  margin: 5px 0 0;
  color: var(--muted);
}

.page-actions,
.import-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.order-detail-grid,
.import-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.detail-section {
  min-width: 0;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.detail-section h3 {
  margin: 0 0 12px;
  font-size: 18px;
}

.customer-preview,
.order-stats {
  display: grid;
  gap: 8px;
}

.preview-row,
.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid #ebe5dc;
}

.preview-row:last-child,
.stat-row:last-child {
  border-bottom: 0;
}

.preview-row span,
.stat-row span {
  color: var(--muted);
}

.preview-row strong,
.stat-row strong {
  text-align: right;
}

.order-detail-table {
  overflow-x: auto;
}

.order-detail-table table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

.order-detail-table th,
.order-detail-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

.order-detail-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #26372f;
  color: #fff;
}

.order-detail-table img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.order-detail-table input {
  width: 72px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 7px;
}

.order-detail-table .remove-btn {
  width: auto;
  min-height: 34px;
  padding: 0 10px;
}

#bulkImportText {
  width: 100%;
  margin: 10px 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  resize: vertical;
}

.import-result {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.5;
  white-space: pre-wrap;
}

.import-result.error-text {
  color: var(--danger);
  font-weight: 800;
}

.hidden {
  display: none !important;
}

.admin-lock {
  max-width: 780px;
}

.admin-login-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.admin-panel.locked {
  display: none;
}

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

.admin-shell {
  display: grid;
}

.admin-tab-panel {
  display: none;
}

.admin-tab-panel.active {
  display: grid;
  gap: 14px;
}

.admin-filter-grid {
  grid-template-columns: minmax(220px, 1fr) 180px 180px 180px;
}

.admin-actions {
  margin-top: 14px;
}

.admin-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  max-height: 360px;
  overflow: auto;
}

.admin-order-card {
  display: grid;
  gap: 7px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf6;
}

.admin-order-card strong,
.admin-order-card span {
  display: block;
}

.my-order-items {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

button.is-loading {
  opacity: 0.72;
  cursor: wait;
}

.admin-order-card span,
.admin-order-meta span {
  color: var(--muted);
  font-size: 12px;
}

.admin-order-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.product-editor-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.editor-wide {
  grid-column: 1 / -1;
}

.checkbox-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
}

.checkbox-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-weight: 700;
}

#categoryManageText {
  width: 100%;
  margin: 10px 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  resize: vertical;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  transform: translateY(80px);
  opacity: 0;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #26372f;
  color: #fff;
  box-shadow: var(--shadow);
  transition: 160ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .order-panel {
    position: static;
    max-height: none;
  }

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

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

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

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

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

  .page-header {
    flex-direction: column;
  }

  .admin-login-row {
    grid-template-columns: 1fr;
  }

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