:root {
  color-scheme: light;
  --bg: #f4f7f2;
  --surface: #ffffff;
  --surface-soft: #f9faf7;
  --ink: #1d2829;
  --muted: #64706d;
  --border: #dce3da;
  --border-strong: #c6d2ca;
  --teal: #16776f;
  --teal-dark: #0f5752;
  --coral: #dd6b4a;
  --amber: #c38a28;
  --blue: #2f6f9e;
  --red: #c7473d;
  --shadow: 0 22px 60px rgba(29, 40, 41, 0.11);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
  background:
    linear-gradient(rgba(255, 255, 255, 0.54) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.54) 1px, transparent 1px),
    radial-gradient(circle at 12% 8%, rgba(221, 107, 74, 0.14), transparent 28%),
    radial-gradient(circle at 88% 16%, rgba(22, 119, 111, 0.14), transparent 30%),
    var(--bg);
  background-size: 36px 36px, 36px 36px, auto, auto, auto;
}

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

button {
  cursor: pointer;
}

svg {
  width: 1.1em;
  height: 1.1em;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--teal), #21484b 64%, var(--coral));
  border-radius: var(--radius);
  box-shadow: 0 14px 30px rgba(22, 119, 111, 0.25);
}

.brand-mark svg {
  width: 28px;
  height: 28px;
}

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

.brand strong {
  font-size: 1.08rem;
  letter-spacing: 0;
}

.brand small {
  color: var(--muted);
  font-size: 0.78rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.system-pill,
.ghost-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  font-size: 0.9rem;
  text-decoration: none;
  white-space: nowrap;
}

.ghost-link {
  color: var(--teal-dark);
}

.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 999px;
  background: var(--teal);
  box-shadow: 0 0 0 0 rgba(22, 119, 111, 0.34);
  animation: pulse 1.9s infinite;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 0.9fr) minmax(520px, 1.25fr);
  gap: 18px;
  align-items: start;
  margin-top: 24px;
}

.control-column {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 18px;
}

.panel {
  min-width: 0;
  border: 1px solid rgba(198, 210, 202, 0.88);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--coral);
  font-size: 0.78rem;
  font-weight: 750;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.7rem, 3.2vw, 2.55rem);
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 12px;
  font-size: 1.02rem;
  letter-spacing: 0;
}

.icon-button,
.icon-text-button,
.primary-button,
.secondary-button {
  border: 0;
  border-radius: var(--radius);
}

.icon-button {
  display: inline-grid;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  place-items: center;
  color: var(--teal-dark);
  background: #eaf3ef;
}

.icon-button:hover {
  background: #dcece7;
}

.field-group {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.field-group legend,
.field > span,
.proxy-editor > span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.87rem;
  font-weight: 700;
}

.protocol-picker {
  display: grid;
  gap: 8px;
}

.protocol-auto,
.protocol-options {
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

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

.protocol-picker label {
  min-width: 0;
}

.protocol-picker input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.protocol-picker span {
  display: grid;
  min-width: 0;
  min-height: 38px;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.protocol-auto span {
  grid-template-columns: auto auto;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
}

.protocol-auto small {
  padding: 2px 7px;
  border-radius: 999px;
  color: var(--teal-dark);
  background: #dff4ed;
  font-size: 0.72rem;
  font-weight: 900;
}

.protocol-picker input:checked + span {
  color: #fff;
  background: var(--teal);
  box-shadow: 0 8px 20px rgba(22, 119, 111, 0.22);
}

.protocol-picker input:checked + span small {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.2);
}

.input-grid {
  display: grid;
  grid-template-columns: 1.3fr 0.85fr 0.85fr;
  gap: 12px;
  align-items: end;
}

.field {
  min-width: 0;
}

.field select {
  width: 100%;
  min-height: 42px;
  padding: 0 36px 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink);
  background: #fff;
}

.field output {
  display: inline-block;
  margin: 0 0 7px;
  color: var(--teal-dark);
  font-size: 0.88rem;
  font-weight: 800;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--teal);
}

.proxy-editor textarea {
  display: block;
  width: 100%;
  min-height: 264px;
  resize: vertical;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(22, 119, 111, 0.05), transparent 26%),
    #fff;
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, ui-monospace, monospace;
  font-size: 0.92rem;
  line-height: 1.65;
}

.proxy-editor textarea:focus,
.field select:focus,
input[type="range"]:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(22, 119, 111, 0.22);
  outline-offset: 2px;
}

.form-note {
  min-height: 44px;
  margin: -4px 0 0;
  padding: 11px 12px;
  border: 1px solid #eadcc7;
  border-radius: var(--radius);
  color: #76511d;
  background: #fff8ea;
  font-size: 0.9rem;
}

.form-note.is-error {
  border-color: #efc1bd;
  color: var(--red);
  background: #fff1ef;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 0;
}

.primary-button,
.secondary-button,
.icon-text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  font-weight: 800;
}

.primary-button {
  color: #fff;
  background: var(--teal);
  box-shadow: 0 16px 30px rgba(22, 119, 111, 0.25);
}

.primary-button:hover {
  background: var(--teal-dark);
}

.primary-button.is-running {
  background: var(--coral);
  box-shadow: 0 16px 30px rgba(221, 107, 74, 0.22);
}

.secondary-button,
.icon-text-button {
  color: var(--teal-dark);
  background: #edf4f0;
}

.secondary-button:hover,
.icon-text-button:hover {
  background: #dfeee8;
}

.results-panel {
  display: flex;
  align-self: stretch;
  flex-direction: column;
  overflow: hidden;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.stats-grid div {
  min-width: 0;
  padding: 16px;
  border-right: 1px solid var(--border);
}

.stats-grid div:last-child {
  border-right: 0;
}

.stats-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.stats-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 1.35rem;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.progress-track {
  height: 5px;
  background: #edf2ec;
}

.progress-track span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--amber), var(--coral));
  transition: width 180ms ease;
}

.result-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 8px;
}

.result-tools h2 {
  margin: 0;
}

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

.run-state-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border: 1px solid #c9e2d8;
  border-radius: 999px;
  color: var(--teal-dark);
  background: #edf7f2;
  font-size: 0.78rem;
  font-weight: 850;
  white-space: nowrap;
}

.icon-text-button {
  min-height: 38px;
  padding-inline: 12px;
  font-size: 0.88rem;
}

.table-wrap {
  flex: 0 1 auto;
  max-height: calc(30px + 8px + (58px + 8px) * 4 + 18px);
  overflow: auto;
  padding: 0 18px 18px;
}

.table-wrap.is-empty {
  max-height: calc(30px + 174px + 18px);
}

table {
  width: 100%;
  min-width: 900px;
  border-collapse: separate;
  border-spacing: 0 8px;
  table-layout: fixed;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  height: 30px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.96);
  font-size: 0.78rem;
  text-align: left;
  white-space: nowrap;
}

td {
  height: 58px;
  overflow: hidden;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: #fff;
  font-size: 0.88rem;
  text-overflow: ellipsis;
  vertical-align: middle;
  white-space: nowrap;
}

th:nth-child(1),
td:nth-child(1) {
  width: 44px;
}

th:nth-child(2),
td:nth-child(2) {
  width: 250px;
}

th:nth-child(3),
td:nth-child(3),
th:nth-child(4),
td:nth-child(4) {
  width: 78px;
}

th:nth-child(5),
td:nth-child(5) {
  width: 92px;
}

th:nth-child(6),
td:nth-child(6) {
  width: 180px;
}

th:nth-child(7),
td:nth-child(7) {
  width: 178px;
}

td:first-child {
  border-left: 1px solid var(--border);
  border-radius: var(--radius) 0 0 var(--radius);
}

td:last-child {
  border-right: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.proxy-cell {
  max-width: 260px;
  overflow: hidden;
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, ui-monospace, monospace;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  color: #42504d;
  background: #eef2ee;
  font-size: 0.78rem;
  font-weight: 850;
  white-space: nowrap;
}

.status-badge.ok {
  color: #0f675b;
  background: #dff4ed;
}

.status-badge.fail {
  color: #a43b34;
  background: #ffe6e3;
}

.status-badge.testing {
  color: #8a5b11;
  background: #fff1d1;
}

.status-badge.stopped {
  color: #5d6765;
  background: #edf0ef;
}

.empty-row td {
  height: 174px;
  color: var(--muted);
  text-align: center;
}

.log-panel {
  display: flex;
  flex: 1 1 220px;
  min-height: 220px;
  flex-direction: column;
  margin: 0 18px 18px;
  overflow: hidden;
  border: 1px solid #263135;
  border-radius: var(--radius);
  background: #1f2528;
}

.log-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid #303b3f;
  color: #d7ffdc;
  background: #20282b;
}

.log-heading h2 {
  margin: 0;
  color: #d7ffdc;
}

.log-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.log-actions span {
  color: #82d98d;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.log-copy-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid #3a5f45;
  border-radius: 6px;
  color: #d7ffdc;
  background: #26362b;
  font-size: 0.82rem;
  font-weight: 850;
}

.log-copy-button:hover {
  color: #ffffff;
  background: #2e4a35;
}

.log-copy-button svg {
  width: 15px;
  height: 15px;
}

.log-panel pre {
  flex: 1;
  max-height: none;
  min-height: 170px;
  margin: 0;
  overflow: auto;
  padding: 16px;
  color: #20ff3d;
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, ui-monospace, monospace;
  font-size: 0.86rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

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

.info-block {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.78);
}

.format-panel {
  flex: 0 0 auto;
  min-height: 220px;
}

.info-block p,
.info-block li {
  color: var(--muted);
  font-size: 0.94rem;
}

.info-block p {
  margin-bottom: 0;
}

.info-block ul {
  margin: 0;
  padding-left: 18px;
}

.format-list {
  display: grid;
  gap: 8px;
}

.format-list code {
  display: block;
  width: 100%;
  padding: 9px 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: #2b3a3a;
  background: var(--surface-soft);
  font-size: 0.84rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid rgba(198, 210, 202, 0.9);
  border-radius: var(--radius);
  color: #fff;
  background: rgba(29, 40, 41, 0.92);
  box-shadow: 0 18px 48px rgba(29, 40, 41, 0.24);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@keyframes pulse {
  70% {
    box-shadow: 0 0 0 10px rgba(22, 119, 111, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(22, 119, 111, 0);
  }
}

@media (max-width: 1040px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 12px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar-actions {
    flex-direction: column;
    align-items: flex-end;
  }

  .system-pill,
  .ghost-link {
    min-height: 32px;
    padding-inline: 10px;
    font-size: 0.8rem;
  }

  .control-panel {
    padding: 18px;
  }

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

  .stats-grid,
  .support-section {
    grid-template-columns: 1fr;
  }

  .stats-grid div {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .stats-grid div:last-child {
    border-bottom: 0;
  }

  .result-tools {
    align-items: flex-start;
    flex-direction: column;
  }

  .log-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .log-actions {
    width: 100%;
    justify-content: space-between;
  }
}

@media (max-width: 480px) {
  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .brand small {
    display: none;
  }

  .topbar-actions {
    gap: 6px;
  }

  .ghost-link {
    display: none;
  }

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

  .action-row > button {
    width: 100%;
  }

  .proxy-editor textarea {
    min-height: 220px;
  }

}
