:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #d8dee6;
  --text: #1f2933;
  --muted: #6b7280;
  --blue: #1f7ae0;
  --green: #168a5a;
  --red: #cf3c3c;
  --amber: #a86412;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", Arial, sans-serif;
  font-size: 14px;
}

button,
input,
select,
textarea {
  font: inherit;
  max-width: 100%;
}

button {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #fff;
  border-radius: 4px;
  padding: 8px 14px;
  cursor: pointer;
}

button.secondary {
  background: #fff;
  color: var(--blue);
}

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

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

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
  min-width: 0;
  max-width: 100%;
}

input[type="date"] {
  display: block;
  width: 100%;
  min-width: 0;
  min-inline-size: 0;
  max-width: 100%;
  max-inline-size: 100%;
  -webkit-appearance: none;
  appearance: none;
}

textarea {
  min-height: 180px;
  resize: vertical;
  width: 100%;
  line-height: 1.5;
}

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

.layout > section {
  min-width: 0;
}

.sidebar,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.sidebar {
  align-self: start;
  position: sticky;
  top: 16px;
  padding: 16px;
}

.panel {
  padding: 16px;
  margin-bottom: 16px;
  min-width: 0;
}

.query-panel {
  overflow: hidden;
}

.delete-panel {
  overflow: hidden;
}

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

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

.brand-copy {
  min-width: 0;
}

.brand-logos {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.brand-logos img {
  display: block;
  width: auto;
  height: 92px;
  max-width: 160px;
  object-fit: contain;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 17px;
}

h3 {
  font-size: 16px;
}

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

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  min-width: 0;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field label {
  color: var(--muted);
  font-size: 13px;
}

.field input,
.field select {
  min-width: 170px;
  max-width: 100%;
  height: 36px;
  width: 100%;
}

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

.metric {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #fbfcfd;
}

.metric .label {
  color: var(--muted);
  font-size: 12px;
}

.metric .value {
  margin-top: 6px;
  font-size: 20px;
  font-weight: 700;
}

.settlement-note {
  margin-top: 12px;
  color: var(--red);
  font-weight: 600;
  line-height: 1.5;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  max-width: 100%;
  width: 100%;
}

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

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

th {
  background: #eef2f6;
  font-weight: 600;
  white-space: nowrap;
}

td {
  color: #374151;
}

tr:hover td {
  background: #f8fafc;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 10px 0 14px;
}

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

.tab.active {
  border-color: var(--blue);
  color: #fff;
  background: var(--blue);
}

.ranking-item {
  border-top: 1px solid var(--line);
  padding: 10px 0;
}

.ranking-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin-right: 8px;
  border-radius: 4px;
  background: #edf2f7;
  font-weight: 700;
}

.ranking-rank.top {
  background: #f06445;
  color: #fff;
}

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

.status.ok {
  color: var(--green);
}

.status.err {
  color: var(--red);
}

.admin-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

.login-box {
  width: min(420px, calc(100vw - 32px));
  margin: 80px auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 22px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.delete-date-field {
  flex: 1 1 220px;
}

.hidden {
  display: none !important;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 4px;
  background: rgba(31, 41, 51, 0.94);
  color: #fff;
  line-height: 1.5;
  text-align: center;
  box-shadow: 0 8px 24px rgba(31, 41, 51, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

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

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

  .sidebar {
    position: static;
  }

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

  .field,
  .field input,
  .field select {
    min-width: 0;
    min-inline-size: 0;
    width: 100%;
    max-width: 100%;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 13px;
    overflow-x: hidden;
  }

  .layout,
  .admin-shell {
    padding: 8px;
  }

  .layout {
    gap: 10px;
  }

  .sidebar,
  .panel,
  .login-box {
    border-radius: 4px;
    padding: 12px;
  }

  .login-box {
    margin: 40px auto;
  }

  .panel {
    margin-bottom: 10px;
  }

  .panel-title {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .brand-head {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .brand-logos {
    justify-content: center;
    gap: 8px;
  }

  .brand-logos img {
    height: 72px;
    max-width: calc(50vw - 22px);
  }

  h1 {
    font-size: 18px;
  }

  h2,
  h3 {
    font-size: 16px;
  }

  .toolbar,
  .action-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
    gap: 10px;
    min-width: 0;
    width: 100%;
  }

  .delete-date-field {
    width: 100%;
  }

  .field input,
  .field select {
    min-width: 0;
    min-inline-size: 0;
    width: 100%;
    max-width: 100%;
  }

  input[type="date"] {
    inline-size: 100%;
    max-inline-size: 100%;
    overflow: hidden;
  }

  .toolbar button,
  .action-row button,
  .action-row input,
  .action-row a,
  .pagination button,
  .pagination select {
    width: 100%;
  }

  .tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .tab {
    padding: 8px 6px;
    white-space: nowrap;
  }

  .metrics {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .metric {
    padding: 10px;
  }

  .metric .value {
    font-size: 18px;
    overflow-wrap: anywhere;
  }

  .table-wrap {
    border: none;
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  td {
    display: block;
  }

  table {
    min-width: 0;
    width: 100%;
    background: transparent;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 10px;
  }

  tr {
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    overflow: hidden;
  }

  tr:hover td {
    background: transparent;
  }

  td {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    min-height: 36px;
    padding: 8px 10px;
    border-bottom: 1px solid #edf1f5;
    overflow-wrap: anywhere;
  }

  td:last-child {
    border-bottom: none;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
  }

  .pagination {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .pagination .muted,
  .pagination select {
    grid-column: 1 / -1;
    text-align: center;
  }

  .toast {
    bottom: 14px;
  }
}
