:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #101828;
  --muted: #667085;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --soft: #f8fafc;
  --dark: #101828;
  --green: #0f766e;
  --blue: #2563eb;
  --orange: #c2410c;
  --red: #b42318;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

h1,
h2,
h3,
p,
pre {
  margin: 0;
}

.hidden {
  display: none !important;
}

.login-view {
  min-height: 100vh;
  padding: 24px 14px;
  background: var(--bg);
}

.login-shell {
  max-width: 420px;
  margin: 0 auto;
  padding-top: 72px;
}

.login-hero {
  margin-bottom: 22px;
}

.login-hero p,
.topbar p,
.metric span,
.toolbar label,
.card-head p,
.table-head,
.order-row span,
.rank-row span,
.config-card span,
.log-item span,
.detail-list span,
.product-item span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.login-hero h1,
.topbar h1 {
  margin-top: 5px;
  font-size: 30px;
  line-height: 1.12;
  letter-spacing: 0;
}

.login-card,
.card,
.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.04);
}

.login-card {
  display: grid;
  gap: 12px;
  padding: 18px;
}

label,
.field {
  display: grid;
  gap: 6px;
  color: #344054;
  font-size: 13px;
  font-weight: 900;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0 10px;
  outline: 0;
  background: #fff;
  color: var(--ink);
}

input:focus,
select:focus {
  border-color: var(--dark);
}

.login-card button,
.btn {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  background: var(--dark);
  color: #fff;
  font-weight: 900;
}

.btn.light {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.app-view {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  background: var(--dark);
  color: #fff;
}

.brand {
  display: grid;
  gap: 4px;
  padding: 4px 4px 24px;
}

.brand strong {
  font-size: 24px;
}

.brand span,
.nav small,
.userbox span {
  color: rgba(255, 255, 255, 0.62);
  font-size: 12px;
  font-weight: 800;
}

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

.nav button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.74);
  font-weight: 900;
  text-align: left;
}

.nav button.active {
  background: #fff;
  color: var(--dark);
}

.userbox {
  position: absolute;
  right: 18px;
  bottom: 18px;
  left: 18px;
  display: grid;
  gap: 7px;
  padding: 13px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
}

.logout-link {
  width: fit-content;
  padding: 0;
  background: transparent;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.main {
  min-width: 0;
  padding: 22px;
}

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

.top-actions {
  display: flex;
  gap: 10px;
  white-space: nowrap;
}

.password-panel {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.password-panel form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
}

.mini-field {
  min-width: 128px;
}

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

.metrics {
  display: grid;
  grid-template-columns: 1.4fr repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric {
  display: grid;
  gap: 8px;
  min-height: 112px;
  padding: 15px;
}

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

.metric.primary span,
.metric.primary em {
  color: rgba(255, 255, 255, 0.68);
}

.metric strong {
  font-size: 26px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.metric.primary strong {
  font-size: 34px;
}

.metric em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.toolbar {
  display: grid;
  grid-template-columns: 1.3fr repeat(6, minmax(120px, 0.7fr)) auto auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.overview-toolbar {
  grid-template-columns: 1fr;
  align-items: stretch;
}

.range-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(116px, 1fr));
  gap: 10px;
}

.range-buttons button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
}

.range-buttons button.active {
  border-color: var(--dark);
  background: var(--dark);
  color: #fff;
}

.sync-state {
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.sync-state.syncing {
  border-color: #bfdbfe;
  background: #eff6ff;
  color: var(--blue);
}

.sync-state.done {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: var(--green);
}

.sync-state.error {
  border-color: #fecaca;
  background: #fef2f2;
  color: var(--red);
}

.custom-range {
  display: grid;
  grid-template-columns: minmax(150px, 220px) minmax(150px, 220px) auto;
  gap: 10px;
  align-items: end;
  padding-top: 10px;
}

.layout,
.product-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 14px;
  align-items: start;
}

.card {
  min-width: 0;
  overflow: hidden;
}

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

.card-head h2 {
  font-size: 18px;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(58px, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.segmented button {
  min-height: 30px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.segmented button.active {
  background: var(--dark);
  color: #fff;
}

.scope-segmented {
  width: 100%;
  grid-template-columns: repeat(2, minmax(82px, 1fr));
}

.order-table-grid {
  display: grid;
  grid-template-columns: 1.35fr 0.9fr 0.72fr 0.72fr 0.75fr 94px;
  gap: 12px;
  align-items: center;
}

.table-head {
  min-height: 42px;
  padding: 0 16px;
  background: var(--soft);
}

.order-row {
  min-height: 68px;
  padding: 0 16px;
  border-top: 1px solid var(--line);
  cursor: pointer;
}

.order-row:first-of-type {
  border-top: 0;
}

.order-row strong,
.rank-row strong,
.product-item strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.money {
  color: var(--orange);
  font-weight: 1000;
  font-variant-numeric: tabular-nums;
}

.pill {
  display: inline-grid;
  place-items: center;
  width: fit-content;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: #ecfdf5;
  color: var(--green);
  font-size: 12px;
  font-style: normal;
  font-weight: 900;
}

.pill.wait {
  background: #fff7ed;
  color: var(--orange);
}

.pill.cancel {
  background: #fef2f2;
  color: var(--red);
}

.op,
.product-item button,
.action-grid button {
  min-height: 32px;
  border-radius: 8px;
  background: #f2f4f7;
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
}

.side-stack {
  display: grid;
  gap: 14px;
}

.rank-list,
.status-list,
.products,
.logs,
.detail-panel {
  display: grid;
  gap: 8px;
  padding: 14px 16px 16px;
}

.logs.compact {
  max-height: 360px;
  overflow: auto;
}

.rank-row {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) 86px;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  border-top: 1px solid var(--line);
}

.rank-row:first-child {
  border-top: 0;
}

.rank-row i {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 900;
}

.rank-row b {
  text-align: right;
}

.status-item {
  display: grid;
  gap: 7px;
}

.status-item div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 900;
}

.track {
  height: 8px;
  border-radius: 999px;
  background: #eef2f6;
  overflow: hidden;
}

.track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--dark);
}

.product-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px 150px;
  gap: 10px;
  padding: 14px 16px 0;
}

.bulk-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px 0;
}

.bulk-bar label {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.bulk-bar input,
.product-check {
  width: 16px;
  min-height: 16px;
  padding: 0;
}

.bulk-bar div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.product-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) 72px;
  align-items: center;
  gap: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.product-item div {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.product-item em {
  display: inline-block;
  margin-left: 8px;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-style: normal;
  vertical-align: middle;
}

.product-item em.on {
  background: #ecfdf5;
  color: var(--green);
}

.product-item em.off {
  background: #fef2f2;
  color: var(--red);
}

.query-card form {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.detail-list {
  display: grid;
  gap: 10px;
}

.detail-list div {
  display: grid;
  gap: 4px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.detail-list strong {
  overflow-wrap: anywhere;
  font-size: 14px;
}

.detail-items {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.detail-items h3 {
  font-size: 15px;
}

.detail-items article {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.action-grid {
  display: grid;
  gap: 8px;
  padding: 16px;
}

.action-grid button {
  display: grid;
  gap: 4px;
  align-content: center;
  min-height: 58px;
  padding: 10px;
  text-align: left;
}

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

.config-card {
  display: grid;
  gap: 12px;
}

.config-card > div:not(.card-head) {
  display: grid;
  gap: 4px;
  padding: 0 16px;
}

.config-card > div:last-child {
  padding-bottom: 16px;
}

.config-card strong {
  overflow-wrap: anywhere;
  font-size: 14px;
}

pre {
  max-height: 310px;
  overflow: auto;
  margin: 16px;
  border-radius: 8px;
  padding: 12px;
  background: var(--dark);
  color: #d1fae5;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.log-item {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.log-item strong {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.log-item em {
  color: var(--orange);
  font-style: normal;
}

.empty {
  padding: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.mobile-nav {
  display: none;
}

.site-footer {
  display: grid;
  gap: 4px;
  padding: 18px 18px 22px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.55;
  text-align: center;
}

.site-footer a {
  color: var(--muted);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--ink);
  text-decoration: underline;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 30;
  transform: translateX(-50%) translateY(20px);
  max-width: 420px;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--dark);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  opacity: 0;
  transition: 0.2s ease;
}

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

@media (max-width: 1120px) {
  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric.primary {
    grid-column: span 2;
  }

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

@media (max-width: 980px) {
  .app-view {
    display: block;
  }

  .sidebar {
    display: none;
  }

  .main {
    padding: 16px 14px 86px;
  }

  .site-footer {
    padding-bottom: 78px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar h1 {
    font-size: 28px;
  }

  .toolbar,
  .product-tools,
  .password-panel form {
    grid-template-columns: 1fr;
  }

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

  .overview-toolbar,
  .range-buttons,
  .custom-range {
    grid-template-columns: 1fr;
  }

  .bulk-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .card-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .card-actions {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }

  .segmented {
    width: 100%;
  }

  .table-head {
    display: none;
  }

  .order-table-grid.order-row {
    grid-template-columns: 1fr auto;
    gap: 7px 12px;
    padding: 14px 16px;
  }

  .order-row > * {
    min-width: 0;
  }

  .order-row span:nth-child(2),
  .order-row span:nth-child(3) {
    grid-column: 1 / -1;
  }

  .order-row .pill {
    grid-column: 1;
  }

  .order-row .money {
    grid-column: 2;
    grid-row: 1;
    align-self: start;
    text-align: right;
  }

  .order-row .op {
    grid-column: 2;
  }

  .mobile-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(18px);
  }

  .mobile-nav button {
    min-height: 58px;
    background: transparent;
    color: var(--muted);
    font-weight: 900;
  }

  .mobile-nav button.active {
    color: var(--ink);
  }
}

@media (max-width: 560px) {
  .top-actions {
    display: grid;
    gap: 8px;
  }

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

  .metric {
    min-height: 96px;
    padding: 12px;
  }

  .metric.primary {
    grid-column: span 3;
  }

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

  .metric.primary strong {
    font-size: 32px;
  }
}
