:root {
  --bg: #e9edf2;
  --panel: #ffffff;
  --side: #f7f8fa;
  --text: #17202a;
  --muted: #667085;
  --line: #e3e7ed;
  --line-strong: #d1d7e0;
  --head: #e9e9e9;
  --primary: #ff7900;
  --primary-strong: #e76800;
  --blue: #2f8cff;
  --blue-soft: #e3f4ff;
  --danger: #d92d20;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}

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

button {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  min-height: 30px;
  padding: 0 13px;
  border-radius: 3px;
  cursor: pointer;
  font-weight: 600;
}

button:hover { border-color: var(--primary-strong); background: var(--primary-strong); }
button.secondary { background: #fff; color: #1f2937; border-color: var(--line-strong); }
button.secondary:hover { background: #f8fafc; color: var(--primary); border-color: var(--primary); }
button.danger { background: var(--danger); border-color: var(--danger); }
button:disabled { opacity: .45; cursor: not-allowed; }

button.link-btn {
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
}

button.link-btn:hover {
  background: transparent;
  color: var(--blue);
}

.sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.sort-btn span {
  color: var(--primary);
  font-weight: 700;
}

input, select, textarea {
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  min-height: 30px;
  padding: 5px 9px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(47, 140, 255, .12);
}

textarea { min-height: 72px; resize: vertical; }

.wide-text {
  width: 100%;
  min-height: 160px;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: #fff;
}

th, td {
  border: 1px solid #edf0f3;
  padding: 9px 8px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  color: #111827;
  background: var(--head);
  font-weight: 700;
}

td input, td select { min-height: 28px; }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-box {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 28px;
  box-shadow: 0 18px 45px rgba(18, 38, 63, .08);
}

.login-box h1 { margin: 0 0 6px; font-size: 22px; }
.login-box p { margin: 0 0 20px; color: var(--muted); }
.field { display: grid; gap: 6px; margin-bottom: 12px; }

.shell {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  width: 100%;
  min-height: 100vh;
  margin: 0;
  background: #fff;
  box-shadow: none;
}

.side {
  background: var(--side);
  color: #344054;
  border-right: 1px solid var(--line);
}

.brand {
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  background: #fff;
  color: #1f2937;
  font-size: 16px;
  font-weight: 700;
}

.brand::first-letter { color: var(--primary); }

.nav { display: grid; padding-top: 2px; }

.nav button {
  width: 100%;
  min-height: 36px;
  padding: 0 15px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #344054;
  text-align: left;
  font-weight: 500;
}

.nav button:hover { background: #eef7ff; color: var(--blue); }

.nav button.active {
  background: var(--blue-soft);
  color: var(--blue);
  border-right: 3px solid var(--blue);
  font-weight: 700;
}

.nav button.nav-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  color: #101828;
  font-weight: 700;
}

.nav button.nav-group.active {
  background: #eef7ff;
  border-right: 0;
}

.nav-children {
  display: grid;
}

.nav-children.collapsed {
  display: none;
}

.nav-children button {
  padding-left: 30px;
  min-height: 34px;
  font-weight: 500;
}

.content {
  min-width: 0;
  background: #f2f4f7;
  overflow: auto;
}

.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0;
  padding: 0 20px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.topbar h1 { margin: 0; font-size: 18px; font-weight: 700; }

.topbar-user {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
  position: relative;
}

.user-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 160px;
  height: 32px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: var(--blue);
  font: inherit;
  cursor: pointer;
}

.user-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-icon {
  width: 13px;
  height: 13px;
  position: relative;
  flex: 0 0 13px;
}

.user-icon::before,
.user-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  background: var(--blue);
}

.user-icon::before {
  top: 1px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

.user-icon::after {
  bottom: 1px;
  width: 10px;
  height: 6px;
  border-radius: 6px 6px 2px 2px;
}

.user-arrow {
  width: 7px;
  height: 7px;
  border-right: 1px solid var(--blue);
  border-bottom: 1px solid var(--blue);
  transform: translateY(-2px) rotate(45deg);
  flex: 0 0 7px;
}

.user-menu {
  display: none;
  position: absolute;
  top: 38px;
  right: 0;
  min-width: 92px;
  padding: 6px 0;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 8px 20px rgba(16, 24, 40, 0.14);
  z-index: 20;
}

.user-menu.open { display: grid; }

.user-menu button {
  height: 32px;
  padding: 0 14px;
  border: 0;
  border-radius: 0;
  background: #fff;
  color: #344054;
  text-align: left;
  font-weight: 400;
  white-space: nowrap;
}

.user-menu button:hover {
  background: #eef7ff;
  color: var(--blue);
}

.user-menu button:last-child {
  margin-top: 6px;
  border-top: 1px solid var(--line);
}

#view { padding: 14px; }

.panel {
  background: var(--panel);
  border: 0;
  border-radius: 0;
  padding: 22px 28px;
  margin-bottom: 14px;
}

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

.toolbar-divider {
  width: 1px;
  height: 24px;
  margin: 0 2px;
  background: var(--line);
  flex: 0 0 auto;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 14px;
}

.section-title {
  padding: 0 28px 10px;
  color: #111827;
  font-weight: 700;
}

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

.import-card {
  display: grid;
  gap: 12px;
  align-content: start;
  min-height: 180px;
  padding: 16px;
  border: 1px solid var(--line);
  background: #fff;
}

.import-card p {
  min-height: 38px;
  margin: 6px 0 0;
}

.import-card input { width: 100%; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 10px;
}

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

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

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

.form-field {
  display: grid;
  gap: 6px;
}

.merchant-form,
.product-form {
  max-width: none;
}

.code-field {
  grid-template-columns: minmax(0, 1fr) 96px;
}

.switch-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
  font-weight: 600;
}

.switch-field input {
  appearance: none;
  width: 42px;
  height: 22px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #e5e7eb;
  position: relative;
  cursor: pointer;
}

.switch-field input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.24);
  transition: transform 0.15s ease;
}

.switch-field input:checked {
  border-color: var(--blue);
  background: var(--blue);
}

.switch-field input:checked::after {
  transform: translateX(20px);
}

.form-field span {
  color: #374151;
  font-size: 12px;
  font-weight: 600;
}

.inline-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  align-items: center;
}

.actions button {
  min-height: 26px;
  padding: 0 9px;
}

.actions input, .actions select { min-width: 120px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

.status {
  min-height: 22px;
  margin-top: 8px;
  color: var(--muted);
}

.status.error { color: var(--danger); }
.status.ok { color: #0f766e; }

.table-wrap {
  overflow: auto;
  background: #fff;
  padding: 28px 28px 0;
}

.wide-table {
  overflow-x: auto;
  overflow-y: visible;
}

.wide-table table {
  table-layout: auto;
}

.wide-transactionDisplay table,
.wide-transactions table {
  min-width: 1500px;
}

.wide-sales table {
  min-width: 2200px;
}

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

.pager {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 14px;
  min-height: 76px;
  padding: 18px 24px;
  background: #fff;
  color: #344054;
}

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

.pager select {
  min-width: 88px;
  height: 32px;
  color: #344054;
}

.page-btn {
  min-width: 28px;
  height: 30px;
  min-height: 30px;
  padding: 0 7px;
  border: 0;
  background: transparent;
  color: #1f2937;
  font-weight: 600;
}

.page-btn:hover {
  background: #f3f8ff;
  color: var(--blue);
}

.page-btn.active {
  color: var(--blue);
  background: transparent;
}

.page-btn.arrow {
  color: #98a2b3;
  font-size: 20px;
  line-height: 1;
}

.page-ellipsis {
  min-width: 24px;
  text-align: center;
  color: #1f2937;
  font-weight: 700;
}

.pager input {
  width: 48px;
  height: 32px;
  min-height: 32px;
  padding: 4px 6px;
  text-align: center;
}

.pill {
  display: inline-block;
  border-radius: 3px;
  padding: 2px 7px;
  background: #eef2f7;
  color: #374151;
}

.pill.bad { background: #fee2e2; color: var(--danger); }
.pill.good { background: #d1fae5; color: #047857; }

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}

.rank-cards {
  grid-template-columns: repeat(2, minmax(320px, 1fr));
  margin-top: 14px;
}

.dashboard-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 14px;
}

.metric-card {
  min-height: 112px;
  display: grid;
  align-content: center;
  gap: 12px;
  padding: 22px 24px;
  background: #fff;
  border: 1px solid var(--line);
}

.metric-card span {
  color: #101828;
  font-weight: 600;
}

.metric-card b {
  color: var(--primary);
  font-size: 28px;
  line-height: 1;
}

.dashboard-panel {
  margin-top: 14px;
  padding: 22px 24px;
  background: #fff;
  border: 1px solid var(--line);
}

.dashboard-ranks {
  display: grid;
  grid-template-columns: repeat(2, minmax(360px, 1fr));
  gap: 14px;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-title span {
  color: var(--muted);
  font-weight: 600;
}

.dashboard-table {
  min-width: 0;
  table-layout: fixed;
}

.dashboard-table th,
.dashboard-table td {
  white-space: normal;
}

.empty.compact {
  height: 96px;
}

.metric {
  background: #fff;
  border: 0;
  border-radius: 0;
  padding: 18px;
}

.metric b { display: block; font-size: 24px; margin-top: 6px; color: var(--primary); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, .38);
}

.modal {
  width: min(860px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .22);
}

.modal.merchant-modal,
.modal.product-modal,
.modal.base-modal {
  width: min(568px, 100%);
}

.modal .form-grid {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
}

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

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

.modal .form-grid .wide {
  grid-column: 1 / -1;
}

.modal .inline-field {
  grid-template-columns: minmax(0, 1fr) 116px;
}

.modal .code-field {
  grid-template-columns: minmax(0, 1fr) 96px;
}

.modal .form-grid.compact {
  grid-template-columns: repeat(3, minmax(170px, 1fr));
}

.modal .form-grid.compact .wide {
  grid-column: 1 / -1;
}

.modal .form-grid.two-col {
  grid-template-columns: repeat(2, minmax(240px, 1fr));
}

.modal .form-grid.two-col .wide {
  grid-column: 1 / -1;
}

.image-manager {
  display: grid;
  gap: 8px;
}

.image-list,
.image-viewer {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.image-viewer {
  max-height: 70vh;
  overflow: auto;
}

.image-thumb {
  position: relative;
  width: 96px;
  height: 96px;
  border: 1px solid var(--line);
  background: #f8fafc;
}

.image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-thumb button {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  min-height: 22px;
  padding: 0;
  border-color: rgba(0, 0, 0, .25);
  background: rgba(17, 24, 39, .78);
  color: #fff;
  line-height: 20px;
}

.image-viewer .image-thumb {
  width: 180px;
  height: 180px;
}

.match-summary {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.match-rows {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.match-row {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 96px 72px;
  gap: 8px;
  align-items: center;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-head b { font-size: 16px; }
.modal-body { padding: 16px; }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

.icon-btn {
  width: 30px;
  padding: 0;
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}

.suffix-field { position: relative; }
.suffix-field input { width: 100%; padding-right: 34px; }

.suffix-field span {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 12px 0;
}

.checks label, .check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
}

.error-detail {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  color: var(--danger);
}

.checks input, .check input { min-height: auto; }

.perm-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.perm-grid fieldset {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px;
}

.perm-grid legend { color: var(--muted); padding: 0 4px; }
.perm-grid label { display: block; margin: 6px 0; }
.perm-grid input { min-height: auto; }

.settings-grid {
  display: grid;
  gap: 10px;
}

.setting-row {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(260px, 420px);
  gap: 16px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.setting-row p {
  margin: 6px 0 0;
}

.setting-check {
  min-height: 36px;
}

.settings-actions {
  justify-content: flex-end;
  margin-top: 16px;
}

.profile-card {
  max-width: 860px;
}

.profile-form {
  max-width: 560px;
}

.profile-actions {
  justify-content: center;
  max-width: 560px;
  margin-top: 14px;
}

.profile-actions button {
  min-width: 96px;
}

.profile-permissions b {
  display: block;
  margin-bottom: 10px;
}

.permission-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.permission-tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #f8fafc;
  color: #475467;
  font-size: 12px;
}

@media (max-width: 760px) {
  .modal .form-grid,
  .modal .form-grid.compact,
  .modal .form-grid.two-col {
    grid-template-columns: 1fr;
  }

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

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

@media (max-width: 900px) {
  .shell {
    width: 100%;
    min-height: 100vh;
    margin: 0;
    grid-template-columns: 1fr;
  }

  .side { border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { height: 52px; }
  .nav { grid-template-columns: repeat(3, 1fr); }
  .nav button { text-align: center; }
  .content { overflow: visible; }
  #view { padding: 10px; }
  .panel { padding: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .cards { grid-template-columns: 1fr 1fr; }
  .rank-cards { grid-template-columns: 1fr; }
  .dashboard-metrics { grid-template-columns: 1fr; }
  .dashboard-ranks { grid-template-columns: 1fr; }
  .import-grid { grid-template-columns: 1fr; }
  .perm-grid { grid-template-columns: 1fr; }
  .table-wrap { padding: 12px 12px 0; }
  .pager { justify-content: flex-start; padding: 14px 12px; flex-wrap: wrap; }
}
