:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-2: #eef3f5;
  --ink: #1f2933;
  --muted: #657282;
  --line: #d8e0e6;
  --brand: #176b87;
  --brand-2: #0f8c6f;
  --danger: #b3282d;
  --warn: #9a5b00;
  --ok: #0f7a53;
  --shadow: 0 12px 30px rgba(31, 41, 51, .08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 76px;
  display: flex;
  align-items: center;
  padding: 14px 28px;
  color: #fff;
  background: #17232d;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

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

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

.brand h1,
.brand p,
.section-head h2,
.subsection-head h3,
.subsection-head p {
  margin: 0;
}

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

.brand p,
.subsection-head p,
.muted-line {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.topbar .brand p {
  color: #aab6c2;
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.field input,
.field select,
.field textarea,
.batch-card textarea {
  width: 100%;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.field textarea,
.batch-card textarea {
  resize: vertical;
  min-height: 42px;
  line-height: 1.45;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.batch-card textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(23, 107, 135, .14);
}

.compact {
  grid-template-columns: auto minmax(130px, 190px);
  align-items: center;
}

.check-field {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  color: var(--muted);
  font-size: 13px;
  user-select: none;
}

.check-field input,
.select-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--brand);
}

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

.sidebar {
  padding: 18px 12px;
  background: #fff;
  border-right: 1px solid var(--line);
}

.nav-item {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  color: #42505e;
  background: transparent;
  text-align: left;
}

.nav-item svg,
.btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.nav-item:hover,
.nav-item.active {
  color: #0d4c60;
  background: #e8f5f4;
}

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

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: grid;
  gap: 18px;
}

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

.section-head h2 {
  font-size: 22px;
  line-height: 1.25;
}

.subsection-head {
  padding-top: 6px;
}

.subsection-head h3 {
  font-size: 18px;
  line-height: 1.25;
}

.status-pill,
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
  color: #0f5138;
  background: #d9f4e8;
}

.status-pill.muted,
.badge.muted {
  color: #526171;
  background: #e6ebf0;
}

.status-pill.warn,
.badge.warn {
  color: #744200;
  background: #ffe9bd;
}

.status-pill.danger,
.badge.danger {
  color: #7d1418;
  background: #ffdadd;
}

.status-pill.info,
.badge.info {
  color: #0d4c60;
  background: #d9eef4;
}

.summary-grid {
  display: grid;
  gap: 12px;
}

.inventory-summary {
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.stats-panel {
  display: grid;
  gap: 12px;
}

.stats-toggle {
  display: none;
  width: 100%;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  box-shadow: var(--shadow);
  text-align: left;
}

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

.stats-toggle strong {
  min-width: 0;
  color: var(--ink);
  font-size: 13px;
  overflow-wrap: anywhere;
  text-align: right;
}

.stats-toggle::after {
  content: "收起";
  flex: 0 0 auto;
  color: var(--brand);
  font-size: 12px;
  font-weight: 650;
}

.stats-panel.is-collapsed .stats-toggle::after {
  content: "展开";
}

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

.live-stock-title {
  display: grid;
  gap: 2px;
  flex: 0 0 auto;
}

.live-stock-title span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.live-stock-title time {
  color: var(--muted);
  font-size: 12px;
}

.live-stock-items {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.live-stock-item {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 9px;
  color: #0f5138;
  background: #d9f4e8;
  font-size: 12px;
  white-space: nowrap;
}

.live-stock-item.info {
  color: #0d4c60;
  background: #d9eef4;
}

.live-stock-item.stock {
  color: #0d4c60;
  background: #e8f5f4;
  border: 1px solid #cae7e2;
}

.live-stock-item.warn {
  color: #744200;
  background: #ffe9bd;
}

.live-stock-item.danger {
  color: #7d1418;
  background: #ffdadd;
}

.live-stock-item.muted {
  color: #526171;
  background: #e6ebf0;
}

.live-stock-item em {
  font-style: normal;
  color: inherit;
}

.live-stock-item strong {
  font-size: 14px;
}

.metric {
  min-height: 82px;
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

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

.tool-surface {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.inventory-query {
  grid-template-columns: minmax(170px, 220px) minmax(260px, 1fr) auto auto;
  align-items: end;
}

.inventory-actions {
  justify-content: flex-end;
  flex-wrap: nowrap;
}

.inline-summary {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 13px;
  white-space: nowrap;
}

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

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

.list-toolbar {
  justify-content: space-between;
}

.btn {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--brand);
  border-radius: 8px;
  padding: 9px 14px;
  color: #fff;
  background: var(--brand);
  font-weight: 650;
}

.btn:hover {
  filter: brightness(.96);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: .55;
}

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

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

.btn.small {
  min-height: 34px;
  padding: 7px 11px;
  font-size: 12px;
}

.record-list {
  display: grid;
  gap: 12px;
}

.record-card,
.tool-pane {
  display: grid;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.record-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.record-title,
.record-main strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.select-row {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.record-meta,
.inline-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}

.record-meta div,
.inline-meta div {
  min-width: 0;
}

.record-meta dt,
.inline-meta dt {
  color: var(--muted);
  font-size: 12px;
}

.record-meta dd,
.inline-meta dd {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.credential-info,
.secret-preview,
.secret-editor {
  padding: 10px 12px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.secret-editor summary {
  cursor: pointer;
  font-weight: 650;
}

.secret-editor textarea,
.secret-block {
  margin-top: 10px;
}

.secret-block {
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--ink);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
}

.mono {
  font-family: "Cascadia Mono", Consolas, monospace;
}

.empty {
  min-height: 72px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.progress div {
  width: 0;
  height: 100%;
  background: var(--brand-2);
  transition: width .2s ease;
}

.result-box {
  min-height: 96px;
  padding: 14px;
  color: #28323d;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: var(--shadow);
}

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

.toast-host {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  display: grid;
  gap: 10px;
  width: min(380px, calc(100vw - 36px));
}

.toast {
  padding: 12px 14px;
  color: #fff;
  background: #17232d;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 13px;
}

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

.toast.ok {
  background: var(--ok);
}

@media (max-width: 1180px) {
  .inventory-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .record-meta,
  .inline-meta,
  .inventory-query {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .inventory-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 900px) {
  .topbar {
    position: static;
    padding: 14px 16px;
  }

  .app-shell,
  .tool-surface,
  .split,
  .inventory-query {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .inventory-actions {
    flex-wrap: wrap;
  }

  .sidebar {
    display: grid;
    grid-template-columns: repeat(4, minmax(78px, 1fr));
    gap: 8px;
    padding: 10px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-item {
    justify-content: center;
    min-width: 78px;
    padding: 9px 8px;
    text-align: center;
  }

  .content {
    padding: 16px;
  }

  .section-head,
  .subsection-head {
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .brand h1 {
    font-size: 16px;
  }

  .section-head h2 {
    font-size: 19px;
  }

  .summary-grid,
  .record-meta,
  .inline-meta {
    grid-template-columns: 1fr;
  }

  .stats-toggle {
    display: flex;
  }

  .stats-panel.is-collapsed .summary-grid {
    display: none;
  }

  .stats-panel.is-collapsed {
    gap: 0;
  }

  .live-stock {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
  }

  .live-stock-title {
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .live-stock-items {
    display: grid;
    grid-template-columns: minmax(118px, 1.6fr) repeat(4, minmax(42px, .7fr));
    gap: 5px;
  }

  .live-stock-item {
    justify-content: center;
    min-width: 0;
    gap: 3px;
    padding: 6px 4px;
    font-size: 12px;
  }

  .live-stock-item strong {
    font-size: 13px;
  }

  .live-stock-item:not(.stock) em {
    display: none;
  }

  .record-main {
    flex-direction: column;
  }

  .actions,
  .list-toolbar,
  .record-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .btn,
  .compact,
  .compact select {
    width: 100%;
  }

  .nav-item {
    font-size: 12px;
  }
}
