:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #dce3ee;
  --line-soft: #eef2f7;
  --text: #172033;
  --muted: #667085;
  --muted-2: #8a95a8;
  --primary: #1f5eff;
  --primary-soft: #eaf1ff;
  --green: #087443;
  --green-soft: #e4f7ef;
  --orange: #a45b00;
  --orange-soft: #fff2d8;
  --red: #b42318;
  --red-soft: #ffe8e4;
  --shadow: 0 12px 32px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

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

button {
  cursor: pointer;
}

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

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 4px 24px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  color: #fff;
  background: var(--primary);
  font-weight: 800;
}

.brand-title {
  font-size: 17px;
  font-weight: 800;
}

.brand-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

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

.nav-item {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  text-align: left;
  font-weight: 700;
}

.nav-item:hover,
.nav-item.active {
  color: var(--primary);
  background: var(--primary-soft);
}

.token-card {
  display: grid;
  gap: 8px;
  margin-top: 28px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.token-row {
  display: flex;
  gap: 8px;
}

.field-label.second {
  margin-top: 8px;
}

.hint {
  color: var(--muted-2);
  font-size: 12px;
  line-height: 1.45;
}

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

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

h1 {
  font-size: 28px;
  line-height: 1.2;
}

.topbar p,
.panel-head p,
.modal-head p {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.45;
}

.top-actions,
.toolbar,
.modal-actions,
.inline-actions,
.row-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn,
.text-btn,
.icon-btn {
  border: 0;
  border-radius: 8px;
  font-weight: 700;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  height: 38px;
  padding: 0 16px;
}

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

.btn.secondary {
  color: var(--primary);
  background: var(--primary-soft);
}

.btn.quiet,
.btn.plain {
  color: var(--text);
  background: #eef2f7;
}

.btn.danger {
  color: var(--red);
  background: var(--red-soft);
}

.btn.success {
  color: var(--green);
  background: var(--green-soft);
}

.btn:disabled {
  color: var(--muted-2);
  background: #eef2f7;
  cursor: not-allowed;
}

.text-btn {
  color: var(--primary);
  background: transparent;
}

.icon-btn {
  height: 34px;
  padding: 0 12px;
  color: var(--muted);
  background: #eef2f7;
}

.input,
.select,
.textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  outline: none;
}

.input,
.select {
  height: 38px;
  padding: 0 12px;
}

.input.compact {
  height: 34px;
}

.textarea {
  min-height: 90px;
  padding: 10px 12px;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 94, 255, 0.12);
}

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

.field-label {
  display: block;
  color: #445064;
  font-size: 12px;
  font-weight: 800;
}

.alert {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #334155;
  background: #fff;
}

.alert.error {
  border-color: #ffc4ba;
  color: var(--red);
  background: var(--red-soft);
}

.alert.success {
  border-color: #b8ead5;
  color: var(--green);
  background: var(--green-soft);
}

.hidden {
  display: none;
}

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

.metric-card,
.panel,
.stat-card {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  min-height: 112px;
  padding: 18px;
}

.metric-card span {
  color: var(--muted);
  font-weight: 700;
}

.metric-card strong {
  display: block;
  margin-top: 16px;
  font-size: 34px;
  line-height: 1;
}

.metric-card.warn strong {
  color: var(--orange);
}

.metric-card.green strong {
  color: var(--green);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  overflow: hidden;
}

.panel + .panel {
  margin-top: 16px;
}

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

.panel-body {
  padding: 18px;
}

.stack-list {
  display: grid;
}

.stack-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
}

.stack-item:last-child {
  border-bottom: 0;
}

.stack-title {
  font-weight: 800;
}

.stack-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.toolbar {
  justify-content: space-between;
  margin-bottom: 16px;
}

.toolbar-left {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  width: min(760px, 100%);
}

.search-input {
  max-width: 320px;
}

.card-list {
  display: grid;
  gap: 14px;
}

.entity-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

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

.entity-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
  font-weight: 800;
}

.entity-meta {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.5;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.chip {
  padding: 6px 8px;
  border-radius: 8px;
  color: #334155;
  background: #f1f5f9;
  font-size: 12px;
}

.detail-grid,
.check-grid,
.person-list,
.mini-table {
  display: grid;
  gap: 12px;
}

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

.detail-card {
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #f8fafc;
}

.stat-card.warn strong {
  color: var(--orange);
}

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

.check-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 4px 8px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #f8fafc;
}

.check-card span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.check-card small {
  grid-column: 2;
  color: var(--muted);
}

.person-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #f8fafc;
}

.person-head,
.mini-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.mini-row {
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 12px;
}

.mini-row strong {
  color: var(--text);
  white-space: nowrap;
}

.return-allocation-list {
  display: grid;
  gap: 8px;
  min-width: 240px;
}

.allocation-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px 76px;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #f8fafc;
}

.allocation-row span {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.allocation-row small {
  color: var(--muted);
  font-size: 12px;
}

.compact-field {
  display: grid;
  gap: 4px;
}

.compact-field small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.entity-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 104px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 8px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 12px;
  font-weight: 800;
}

.badge.done,
.badge.green {
  color: var(--green);
  background: var(--green-soft);
}

.badge.warn {
  color: var(--orange);
  background: var(--orange-soft);
}

.badge.danger {
  color: var(--red);
  background: var(--red-soft);
}

.badge.muted {
  color: #64748b;
  background: #eef2f7;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  background: #f8fafc;
  font-size: 12px;
  font-weight: 800;
}

tbody tr:hover {
  background: #fbfcff;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.right {
  text-align: right;
}

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

.amount-out {
  color: var(--red);
  font-weight: 800;
}

.amount-in {
  color: var(--green);
  font-weight: 800;
}

.thumb {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  background: #eef2f7;
}

.thumb.placeholder {
  display: inline-grid;
  place-items: center;
  color: var(--primary);
  font-weight: 800;
}

.item-image-section {
  display: grid;
  gap: 12px;
}

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

.image-tile {
  display: grid;
  gap: 8px;
  align-content: start;
  min-width: 0;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #f8fafc;
}

.image-tile img,
.image-tile .thumb {
  width: 100%;
  aspect-ratio: 1;
  height: auto;
  border-radius: 8px;
  object-fit: cover;
}

.image-tile figcaption {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-empty {
  padding: 14px;
  text-align: left;
}

.bar-row {
  display: grid;
  grid-template-columns: 170px 1fr 80px;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
}

.bar-track {
  height: 10px;
  border-radius: 5px;
  overflow: hidden;
  background: #eef2f7;
}

.bar-fill {
  height: 100%;
  background: var(--primary);
}

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

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

.form-section {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line-soft);
}

.line-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.line-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 120px 48px;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.order-line {
  grid-template-columns: 28px minmax(220px, 1fr) 120px;
  align-items: center;
}

.check {
  width: 18px;
  height: 18px;
}

.modal {
  width: min(980px, calc(100vw - 40px));
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 40px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.48);
}

.modal-card {
  display: grid;
  gap: 18px;
  width: 100%;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 22px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.modal-actions {
  justify-content: flex-end;
  padding-top: 6px;
}

.empty-state {
  padding: 28px 18px;
  color: var(--muted);
  text-align: center;
}

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

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .token-card {
    margin-top: 16px;
  }

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

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

  .entity-card {
    grid-template-columns: 1fr;
  }

  .entity-actions {
    flex-direction: row;
    flex-wrap: wrap;
  }
}

@media (max-width: 680px) {
  .main,
  .sidebar {
    padding: 16px;
  }

  .topbar,
  .toolbar,
  .top-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .metrics-grid,
  .dashboard-grid,
  .detail-grid,
  .check-grid,
  .form-grid,
  .form-grid.three,
  .line-row,
  .order-line {
    grid-template-columns: 1fr;
  }

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