:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef3f8;
  --line: #d8e1eb;
  --text: #17202a;
  --muted: #667789;
  --primary: #1267d6;
  --primary-strong: #0a4aa3;
  --good: #16845b;
  --warn: #b46a00;
  --bad: #c8333a;
  --shadow: 0 12px 28px rgba(31, 49, 72, 0.09);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

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

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

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

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #9fb2c6;
  font-size: 12px;
  margin-top: 2px;
}

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

.nav-link {
  color: #c4d2e0;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
}

.nav-link:hover,
.nav-link.active {
  color: #fff;
  background: #1d2a38;
  border-color: #2e4053;
}

.token-panel {
  margin-top: auto;
  padding: 14px;
  background: #172231;
  border: 1px solid #2e4053;
  border-radius: 8px;
}

.token-panel label {
  display: block;
  font-size: 12px;
  color: #b3c3d3;
  margin-bottom: 8px;
}

.token-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.token-row input {
  min-width: 0;
}

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

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

h1,
h2,
p {
  margin: 0;
}

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

h2 {
  font-size: 16px;
  line-height: 1.25;
}

.topbar p {
  color: var(--muted);
  margin-top: 6px;
}

.top-actions,
.form-actions,
.panel-header,
.targets-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.mode-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.mode-pill.aliyun,
.status-pill.good {
  color: var(--good);
  background: #e6f6ef;
}

.status-pill.bad {
  color: var(--bad);
  background: #fdecef;
}

.status-pill.warn,
.mode-pill.simulation {
  color: var(--warn);
  background: #fff4dc;
}

.primary,
.ghost,
.danger {
  min-height: 36px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 650;
}

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

.primary:hover {
  background: var(--primary-strong);
}

.ghost {
  background: #e7edf5;
  color: #233447;
}

.danger {
  background: #fdecef;
  color: var(--bad);
}

.compact {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

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

.metric {
  padding: 18px;
}

.metric span {
  color: var(--muted);
  display: block;
  margin-bottom: 8px;
}

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

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(320px, 0.8fr);
  gap: 16px;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(340px, 0.85fr) minmax(0, 1.4fr);
  gap: 16px;
  align-items: start;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel-header {
  justify-content: space-between;
  margin-bottom: 14px;
}

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

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

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

.event-list,
.record-list,
.agent-list,
.targets-editor {
  display: grid;
  gap: 12px;
}

.event {
  border-left: 3px solid var(--line);
  padding: 8px 0 8px 12px;
}

.event.warn {
  border-color: var(--warn);
}

.event.error,
.event.bad {
  border-color: var(--bad);
}

.event.info {
  border-color: var(--primary);
}

.event strong {
  display: block;
  font-size: 13px;
}

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

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

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

label {
  display: grid;
  gap: 7px;
  font-size: 13px;
  color: #30445a;
  font-weight: 650;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-check input {
  width: auto;
  min-height: auto;
}

.setting-check {
  align-self: end;
  min-height: 38px;
  padding: 8px 0;
}

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

input:focus,
select:focus {
  outline: 2px solid rgba(18, 103, 214, 0.2);
  border-color: var(--primary);
}

.target-editor {
  border: 1px solid var(--line);
  background: #fbfdff;
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.target-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.target-title strong {
  font-size: 14px;
}

.record-card,
.agent-card {
  padding: 14px;
}

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

.record-main h3,
.agent-main h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.record-actions,
.agent-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.target-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.target-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.8fr) minmax(130px, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.code-box {
  margin-top: 12px;
  background: #101820;
  color: #e8f1fa;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 12px;
  line-height: 1.5;
}

.settings-panel {
  max-width: 860px;
}

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

.agent-option {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.agent-option input {
  width: auto;
  min-height: auto;
}

.agent-option span {
  display: grid;
  gap: 2px;
}

.agent-option small {
  color: var(--muted);
}

.form-hint {
  display: none;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #102030;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

  .sidebar {
    position: static;
  }

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

  .token-panel {
    margin-top: 0;
  }

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

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

  .topbar,
  .record-main,
  .agent-main {
    display: grid;
  }

  .top-actions,
  .record-actions,
  .agent-actions {
    justify-content: start;
  }

  nav,
  .metrics-grid,
  .field-row,
  .target-row,
  .agent-picker {
    grid-template-columns: 1fr;
  }
}
