:root {
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-strong: #f0f4f2;
  --text: #1f2933;
  --muted: #667085;
  --border: #d8dfdc;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --danger: #b42318;
  --warn: #b45309;
  --shadow: 0 10px 24px rgba(31, 41, 51, 0.08);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

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

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

button {
  min-height: 38px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  padding: 0 14px;
  white-space: nowrap;
}

button:hover {
  background: var(--accent-dark);
}

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

button.secondary:hover {
  background: var(--surface-strong);
}

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

textarea {
  resize: vertical;
}

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

.sidebar {
  background: #17211f;
  color: #fff;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #e0f2f1;
  color: #0f4f49;
  font-weight: 700;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.brand p {
  margin: 4px 0 0;
  color: #b6c2bd;
  font-size: 13px;
}

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

.nav button {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  border-color: transparent;
  background: transparent;
  color: #d7e0dc;
}

.nav button.active,
.nav button:hover {
  background: #23433f;
  color: #fff;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

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

.eyebrow {
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
}

.topbar h2 {
  margin: 4px 0 0;
  font-size: 26px;
}

.api-state {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
}

.api-state.ok {
  color: var(--accent-dark);
  border-color: #93c5bd;
}

.api-state.error {
  color: var(--danger);
  border-color: #f4aaa3;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  font-size: 25px;
  margin-top: 6px;
}

.panel {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.panel.active {
  display: block;
}

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

.section-head h3 {
  margin: 0;
  font-size: 19px;
}

.section-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.inline-form input,
.inline-form select {
  width: 180px;
}

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

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

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 11px 12px;
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

th {
  background: var(--surface-strong);
  color: #475467;
  font-weight: 700;
}

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

.asset-cell {
  display: grid;
  gap: 3px;
}

.asset-cell strong {
  font-size: 14px;
}

.asset-cell span,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.thumb {
  width: 52px;
  height: 52px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--surface-strong);
}

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

.thumb-button {
  width: 58px;
  min-height: 58px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  position: relative;
}

.thumb-button:hover {
  background: transparent;
}

.image-count {
  position: absolute;
  right: -4px;
  bottom: -4px;
  min-width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #17211f;
  color: #fff;
  font-size: 12px;
  border: 2px solid #fff;
}

.note-text {
  display: -webkit-box;
  max-width: 320px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.qty {
  font-weight: 700;
}

.qty.warn {
  color: var(--warn);
}

.qty.danger {
  color: var(--danger);
}

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

label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-size: 14px;
  font-weight: 700;
}

label span {
  min-height: 18px;
}

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

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.category-form {
  justify-content: flex-start;
  margin-bottom: 14px;
}

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

.dingtalk-tools {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.tool-block {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.tool-block > div {
  display: grid;
  gap: 4px;
}

.tool-block span {
  color: var(--muted);
  font-size: 13px;
}

.tool-block label {
  flex: 1;
}

.instance-preview {
  max-height: 260px;
  overflow: auto;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #17211f;
  color: #e8f3f0;
  padding: 12px;
  font-size: 12px;
  line-height: 1.55;
}

.instance-preview:empty {
  display: none;
}

.category-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
}

.category-row strong {
  display: block;
}

.category-row span {
  color: var(--muted);
  font-size: 13px;
}

.danger-button {
  border-color: #f1b7b2;
  background: #fff;
  color: var(--danger);
}

.danger-button:hover {
  background: #fff4f2;
}

.hidden {
  display: none;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(440px, calc(100vw - 44px));
  background: #17211f;
  color: #fff;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  z-index: 10;
}

.toast.error {
  background: var(--danger);
}

.image-dialog {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
}

.image-dialog[hidden] {
  display: none;
}

.image-dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 33, 31, 0.66);
}

.image-dialog-body {
  position: relative;
  width: min(920px, calc(100vw - 40px));
  max-height: calc(100vh - 40px);
  display: grid;
  gap: 12px;
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
}

.image-dialog-body img {
  width: 100%;
  max-height: calc(100vh - 170px);
  object-fit: contain;
  background: var(--surface-strong);
  border-radius: 6px;
}

.image-dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border-color: rgba(255, 255, 255, 0.8);
  background: rgba(23, 33, 31, 0.82);
}

.image-dialog-meta {
  display: grid;
  gap: 4px;
}

.image-dialog-meta span {
  color: var(--muted);
  font-size: 13px;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 14px;
  }

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

  .nav button {
    text-align: center;
    justify-content: center;
    padding: 0 8px;
  }

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

  .section-head {
    display: grid;
  }

  .inline-form {
    justify-content: flex-start;
  }

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

@media (max-width: 620px) {
  .workspace {
    padding: 14px;
  }

  .topbar {
    display: grid;
  }

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

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

  .inline-form input,
  .inline-form select,
  .inline-form button {
    width: 100%;
  }
}
