:root {
  color-scheme: light;
  --ink: #17201f;
  --muted: #62706d;
  --line: #d9dfdd;
  --soft: #f4f6f5;
  --paper: #ffffff;
  --green: #0b6b4f;
  --green-dark: #084c39;
  --amber: #a65a00;
  --red: #b5372f;
  --blue: #245d8f;
  --shadow: 0 10px 30px rgba(21, 31, 29, 0.08);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  letter-spacing: 0;
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(36, 93, 143, 0.22);
  outline-offset: 1px;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #eef2f0;
  border-top: 6px solid #d9972e;
}

.login-panel {
  width: min(420px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  box-shadow: var(--shadow);
}

.login-brand {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  margin-bottom: 22px;
  border-radius: 5px;
  background: var(--green);
  color: white;
  font-size: 15px;
  font-weight: 800;
}

.login-panel .eyebrow { color: var(--amber); }
.login-panel h1 { margin: 6px 0 26px; font-size: 27px; line-height: 1.2; }
.login-fields { display: grid; gap: 16px; }
.totp-input { font-size: 20px; font-variant-numeric: tabular-nums; letter-spacing: 0; }
.login-error { min-height: 20px; margin: 13px 0 8px; color: var(--red); font-size: 12px; }
.login-button { width: 100%; }

.topbar {
  min-height: 124px;
  padding: 28px max(24px, calc((100vw - 1400px) / 2));
  background: #182321;
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 5px solid #d9972e;
}

.topbar h1 { margin: 4px 0 0; font-size: 32px; line-height: 1.15; font-weight: 760; }
.eyebrow, .section-index { margin: 0; color: #b7c5c1; font-size: 11px; font-weight: 750; }
.bridge-actions, .toolbar, .endpoint-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

main { width: min(1400px, 100%); margin: 0 auto; }

.metrics-band {
  min-height: 82px;
  display: grid;
  grid-template-columns: repeat(6, minmax(90px, 1fr));
  border-bottom: 1px solid var(--line);
}

.metrics-band div {
  padding: 18px 24px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  border-right: 1px solid var(--line);
}

.metrics-band div:last-child { border-right: 0; }
.metrics-band span { color: var(--muted); font-size: 12px; }
.metrics-band strong { font-size: 27px; line-height: 1; font-variant-numeric: tabular-nums; }

.workspace-section { padding: 34px 24px 40px; border-bottom: 1px solid var(--line); }
.section-heading { display: flex; justify-content: space-between; gap: 20px; align-items: center; margin-bottom: 26px; }
.section-heading > div:first-child { display: flex; align-items: baseline; gap: 12px; }
.section-heading h2 { margin: 0; font-size: 20px; }
.section-index { color: var(--amber); }

.config-grid { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.config-column { padding: 24px; background: var(--paper); }
.dify-column { border-left: 1px solid var(--line); background: #fbfcff; }
.column-title { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.column-title h3, .test-tool h3 { margin: 0; font-size: 15px; }
.system-mark { width: 30px; height: 30px; display: grid; place-items: center; color: white; font-weight: 800; border-radius: 5px; }
.sentence-mark { background: var(--green); }
.dify-mark { background: var(--blue); }

.connection-state {
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--soft);
}
.connection-state strong { display: block; font-size: 13px; }
.connection-state p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.connection-dot { width: 10px; height: 10px; flex: 0 0 auto; border-radius: 50%; background: #98a39f; }
.connection-dot.connected { background: var(--green); box-shadow: 0 0 0 4px rgba(11, 107, 79, 0.12); }
.connection-dot.disconnected { background: var(--red); box-shadow: 0 0 0 4px rgba(181, 55, 47, 0.12); }

label { display: block; min-width: 0; }
label > span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 7px; }
.config-column > label, .config-column > .two-fields, .config-column > .account-picker { margin-top: 15px; }
.field-label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 7px; }
.account-picker select { margin-top: 8px; }
.target-picker { margin: 13px 0; }
.target-picker select { margin-top: 8px; }

input, select, textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid #bcc6c3;
  border-radius: 4px;
  background: white;
  color: var(--ink);
  padding: 9px 11px;
}

textarea { resize: vertical; line-height: 1.55; }
input[readonly] { background: var(--soft); color: #4e5b58; }
.two-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.input-action { display: grid; grid-template-columns: 1fr auto; gap: 8px; }

.bridge-options {
  padding: 18px 20px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-top: 0;
  display: grid;
  grid-template-columns: 1.2fr 0.75fr 0.9fr repeat(3, minmax(132px, auto));
  align-items: end;
  gap: 14px;
}

.toggle-row { min-height: 40px; display: flex; align-items: center; gap: 9px; padding: 0 10px; border: 1px solid var(--line); background: white; border-radius: 4px; }
.toggle-row input { width: 17px; min-height: 17px; height: 17px; accent-color: var(--green); }
.toggle-row span { margin: 0; color: var(--ink); line-height: 1.25; }
.warning-toggle { border-color: #dfb36f; background: #fff9ee; }

.button {
  min-height: 40px;
  padding: 9px 15px;
  border: 1px solid #aeb9b5;
  border-radius: 4px;
  background: white;
  color: var(--ink);
  font-weight: 680;
  cursor: pointer;
  white-space: nowrap;
}

.button:hover { background: #f0f3f2; }
.button:disabled { cursor: wait; opacity: 0.58; }
.button.primary { background: var(--green); border-color: var(--green); color: white; }
.button.primary:hover { background: var(--green-dark); }
.danger-action { border-color: var(--red); color: var(--red); }
.subtle-danger { color: var(--red); border-color: #d7aaa6; }

.status-badge {
  min-width: 86px;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.status-badge.running { color: #baf6d9; border-color: #57b98b; }
.status-badge.stopped { color: #d7dddb; }
.inline-status { color: var(--muted); font-size: 12px; }
.inline-status.success { color: var(--green); }
.inline-status.error { color: var(--red); }

.test-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.test-tool { border: 1px solid var(--line); border-radius: 6px; padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.test-tool h3 { margin-bottom: 16px; }
.test-tool label { margin-bottom: 13px; }
.compact { gap: 10px; }
.result-box { min-height: 88px; max-height: 180px; overflow: auto; margin: 14px 0 0; padding: 12px; border-radius: 4px; background: #182321; color: #dbe7e3; white-space: pre-wrap; word-break: break-word; font-size: 12px; line-height: 1.55; }
.selected-receipt { min-height: 118px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.receipt-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; color: var(--muted); font-size: 12px; }
.selected-receipt strong { display: block; font-size: 15px; line-height: 1.35; }
.selected-receipt p { min-height: 38px; margin: 7px 0 4px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.selected-receipt time { color: #7a8683; font-size: 11px; font-variant-numeric: tabular-nums; }
.receipt-status { display: inline-flex; align-items: center; gap: 6px; font-weight: 750; }
.receipt-status::before { content: ""; width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: #98a39f; }
.receipt-status.pending { color: var(--amber); }
.receipt-status.pending::before { background: var(--amber); }
.receipt-status.success { color: var(--green); }
.receipt-status.success::before { background: var(--green); }
.receipt-status.failed { color: var(--red); }
.receipt-status.failed::before { background: var(--red); }
.endpoints-tool { box-shadow: none; background: var(--soft); }
.endpoint-actions { margin-top: 18px; }

.log-section { padding-bottom: 60px; }
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th { text-align: left; background: var(--soft); color: var(--muted); font-size: 11px; padding: 11px 12px; border-bottom: 1px solid var(--line); }
td { padding: 12px; border-bottom: 1px solid #e7ebe9; vertical-align: top; font-size: 12px; line-height: 1.45; word-break: break-word; }
tr:last-child td { border-bottom: 0; }
th:nth-child(1), td:nth-child(1) { width: 155px; }
th:nth-child(2), td:nth-child(2) { width: 100px; }
th:nth-child(3), td:nth-child(3) { width: 80px; }
th:nth-child(5), td:nth-child(5) { width: 34%; }
.log-level { font-weight: 750; }
.log-level.error { color: var(--red); }
.log-level.info { color: var(--green); }
.empty-row { text-align: center; color: var(--muted); padding: 30px; }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(440px, calc(100vw - 44px));
  background: #182321;
  color: white;
  padding: 12px 16px;
  border-radius: 5px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { background: #7e2520; }

@media (max-width: 1080px) {
  .bridge-options { grid-template-columns: repeat(3, 1fr); }
  .test-grid { grid-template-columns: 1fr 1fr; }
  .endpoints-tool { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .topbar { min-height: 150px; padding: 24px 18px; align-items: flex-start; flex-direction: column; }
  .topbar h1 { font-size: 27px; }
  .metrics-band { grid-template-columns: repeat(3, 1fr); }
  .metrics-band div:nth-child(3) { border-right: 0; }
  .metrics-band div:nth-child(-n + 3) { border-bottom: 1px solid var(--line); }
  .workspace-section { padding: 28px 16px 34px; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .config-grid, .test-grid { grid-template-columns: 1fr; }
  .dify-column { border-left: 0; border-top: 1px solid var(--line); }
  .bridge-options { grid-template-columns: 1fr 1fr; }
  .endpoints-tool { grid-column: auto; }
}

@media (max-width: 500px) {
  .metrics-band div { padding: 15px 12px; }
  .metrics-band strong { font-size: 22px; }
  .config-column { padding: 18px; }
  .two-fields, .bridge-options { grid-template-columns: 1fr; }
  .input-action { grid-template-columns: 1fr; }
  .bridge-actions { width: 100%; }
  .bridge-actions .button { flex: 1; }
}
