﻿:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #637083;
  --line: #d9e1e8;
  --soft: #edf2f6;
  --green: #138a55;
  --red: #bd3d35;
  --blue: #2563eb;
  --blue-dark: #1747ad;
  --amber: #b7791f;
  --shadow: 0 10px 28px rgba(23, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.25;
  letter-spacing: 0;
}

p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.top-actions,
.button-row,
.bulk-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 18px;
  margin-top: 18px;
}

.control-panel,
.results-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-panel {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-self: start;
}

.field-stack {
  display: grid;
  gap: 8px;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.source-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: end;
}

label,
.number-field span,
.toggle-field span {
  color: #263241;
  font-size: 13px;
  font-weight: 700;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--blue);
  min-height: 28px;
  padding: 0 2px;
  font-size: 13px;
  font-weight: 800;
}

.source-list {
  display: grid;
  gap: 8px;
  max-height: min(42vh, 420px);
  min-height: 220px;
  overflow: auto;
  padding-right: 2px;
}

.source-option,
.source-loading {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdff;
  padding: 10px;
}

.source-option {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 9px;
  align-items: start;
  transition:
    border-color 0.16s ease,
    box-shadow 0.16s ease,
    background 0.16s ease;
}

.source-option:has(input:checked) {
  border-color: rgba(37, 99, 235, 0.5);
  background: #f2f7ff;
  box-shadow: inset 3px 0 0 var(--blue);
}

.source-option input {
  margin-top: 2px;
}

.source-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-wrap: wrap;
}

.source-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.source-tag {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #e7f7ef;
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
}

.source-tag.format {
  background: #eef2ff;
  color: var(--blue-dark);
}

.source-tag.protocol {
  background: #fff7df;
  color: var(--amber);
}

.source-url,
.source-desc,
.source-loading {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.source-url,
.source-desc {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

textarea,
input[type="number"],
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdff;
  color: var(--ink);
  outline: none;
}

textarea {
  min-height: 132px;
  resize: vertical;
  padding: 11px 12px;
  line-height: 1.5;
}

input[type="number"],
select {
  height: 38px;
  padding: 0 10px;
}

textarea:focus,
input[type="number"]:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.number-field {
  display: grid;
  gap: 7px;
}

.toggle-field {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdff;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--blue);
}

.primary-button,
.ghost-button,
.danger-button,
.mini-button {
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 700;
  white-space: nowrap;
}

.primary-button {
  background: var(--blue);
  color: #fff;
}

.primary-button:hover:not(:disabled) {
  background: var(--blue-dark);
}

.ghost-button,
.mini-button {
  background: #fff;
  color: #253248;
  border-color: var(--line);
}

.ghost-button:hover:not(:disabled),
.mini-button:hover:not(:disabled) {
  border-color: #a7b6c5;
  background: var(--soft);
}

.danger-button {
  background: #fff;
  color: var(--red);
  border-color: #e4b6b1;
}

.full {
  flex: 1;
}

.results-panel {
  min-width: 0;
  overflow: hidden;
}

.stats-bar {
  display: grid;
  grid-template-columns: repeat(5, minmax(82px, 110px)) minmax(310px, 1fr);
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  align-items: center;
}

.stat {
  min-height: 54px;
  padding: 8px 10px;
  background: #f9fbfd;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat strong {
  display: block;
  margin-top: 3px;
  font-size: 22px;
  line-height: 1;
}

.stat.good strong {
  color: var(--green);
}

.stat.bad strong {
  color: var(--red);
}

.stat.fast strong {
  color: var(--blue-dark);
  font-size: 18px;
  line-height: 1.2;
}

.bulk-actions {
  justify-content: end;
  flex-wrap: wrap;
}

.export-select {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  color: #263241;
  font-size: 13px;
  font-weight: 800;
}

.export-select select {
  width: 92px;
}

.run-strip {
  display: grid;
  grid-template-columns: minmax(220px, 340px) minmax(0, 1fr);
  gap: 14px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfdff;
  align-items: center;
}

.run-strip strong {
  display: block;
  font-size: 13px;
}

.run-strip span {
  color: var(--muted);
  font-size: 12px;
}

.progress-track {
  position: relative;
  height: 10px;
  border-radius: 999px;
  background: #e8eef5;
  overflow: hidden;
}

.progress-track span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: linear-gradient(90deg, var(--blue), var(--green));
  transition: width 0.18s ease;
}

.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  flex-wrap: wrap;
}

.filter-bar > strong {
  color: #344054;
  font-size: 13px;
  margin-right: 2px;
}

.filter-field {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.filter-field select {
  width: 122px;
  height: 34px;
  background: #fbfdff;
}

.filter-reset {
  min-height: 34px;
  padding: 0 11px;
  font-size: 12px;
}

.filter-summary {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  max-height: calc(100vh - 280px);
}

table {
  width: 100%;
  min-width: 830px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: #445166;
  font-size: 12px;
  text-transform: uppercase;
}

.select-col {
  width: 44px;
  text-align: center;
}

.mono {
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

.source-cell {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.actions-cell {
  width: 128px;
}

.mini-button {
  min-height: 30px;
  padding: 0 9px;
  margin-right: 6px;
  font-size: 12px;
}

.status-pill,
.protocol-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: #eef2f7;
  color: #4d5b6f;
  font-weight: 800;
  font-size: 12px;
}

.protocol-pill {
  min-width: 58px;
  background: #eef2ff;
  color: var(--blue-dark);
  text-transform: uppercase;
}

.status-pill.checking {
  background: #fff7df;
  color: var(--amber);
}

.status-pill.alive {
  background: #e7f7ef;
  color: var(--green);
}

.status-pill.dead {
  background: #fdecea;
  color: var(--red);
}

.empty-row td {
  height: 180px;
  text-align: center;
  color: var(--muted);
}

.log-panel {
  min-height: 96px;
  max-height: 170px;
  overflow: auto;
  padding: 12px 14px;
  background: #101820;
  color: #d7e0ea;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
}

.log-panel div {
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(360px, calc(100vw - 44px));
  padding: 11px 13px;
  border-radius: 6px;
  background: #17202a;
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 13px;
  z-index: 10;
}

@media (max-width: 980px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .workspace {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions button,
  .button-row button {
    flex: 1;
  }

  .workspace {
    display: grid;
  }

  .stats-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .bulk-actions {
    grid-column: 1 / -1;
    justify-content: stretch;
  }

  .export-select {
    flex: 1 1 100%;
    justify-content: space-between;
  }

  .export-select select {
    width: 130px;
  }

  .run-strip {
    grid-template-columns: 1fr;
  }

  .filter-summary {
    width: 100%;
    margin-left: 0;
  }

  .bulk-actions button {
    flex: 1;
  }
}

@media (max-width: 560px) {
  h1 {
    font-size: 20px;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .button-row,
  .top-actions,
  .bulk-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-bar {
    align-items: stretch;
  }

  .filter-bar > strong,
  .filter-summary {
    width: 100%;
  }

  .filter-field {
    flex: 1 1 100%;
    justify-content: space-between;
  }

  .filter-field select {
    width: min(180px, 62vw);
  }
}

/* ===== Login overlay ===== */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at top, rgba(37, 99, 235, 0.22), transparent 42%),
    linear-gradient(160deg, #0f172a 0%, #1e293b 55%, #0b1220 100%);
  -webkit-overflow-scrolling: touch;
}

.login-box {
  width: min(400px, 100%);
  padding: clamp(24px, 5vw, 36px) clamp(18px, 4.5vw, 32px) clamp(22px, 4vw, 30px);
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 18px;
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.28),
    0 1px 0 rgba(255, 255, 255, 0.5) inset;
  text-align: center;
  backdrop-filter: blur(10px);
}

.login-brand {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: linear-gradient(180deg, #eff6ff, #dbeafe);
  border: 1px solid #bfdbfe;
  font-size: 26px;
  line-height: 1;
}

.login-box h1 {
  margin: 0;
  font-size: clamp(20px, 5vw, 24px);
  line-height: 1.3;
  letter-spacing: 0;
}

.login-desc {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.login-form {
  margin-top: 22px;
  text-align: left;
}

.login-label {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}

.login-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: stretch;
}

.password-shell {
  position: relative;
  min-width: 0;
  display: flex;
  align-items: center;
}

.password-shell input {
  width: 100%;
  min-height: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 46px 0 14px;
  font-size: 16px;
  line-height: 1.2;
  outline: none;
  background: #f8fafc;
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}

/* 隐藏 Edge/IE 原生显示密码与清除按钮，避免和自定义按钮重复 */
.password-shell input::-ms-reveal,
.password-shell input::-ms-clear {
  display: none;
  width: 0;
  height: 0;
}

.password-shell input::-webkit-credentials-auto-fill-button,
.password-shell input::-webkit-contacts-auto-fill-button,
.password-shell input::-webkit-caps-lock-indicator {
  visibility: hidden;
  display: none !important;
  pointer-events: none;
  position: absolute;
  right: 0;
}

.password-shell input::placeholder {
  color: #94a3b8;
}

.password-shell input:hover {
  border-color: #b6c3d1;
  background: #fff;
}

.password-shell input:focus {
  border-color: var(--blue);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.14);
}

.password-shell input.login-input-error {
  border-color: #f5a8a3;
  background: #fff7f7;
  box-shadow: 0 0 0 4px rgba(189, 61, 53, 0.12);
}

.password-toggle {
  z-index: 2;
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  padding: 0;
  line-height: 1;
  transition: background 0.15s ease, color 0.15s ease;
}

.password-toggle:hover,
.password-toggle:focus-visible {
  background: var(--soft);
  color: var(--ink);
  outline: none;
}

.password-toggle[aria-pressed="true"] {
  color: var(--blue);
  background: #eff6ff;
}

.password-toggle-icon {
  font-size: 16px;
  pointer-events: none;
}

.login-submit,
.login-field .primary-button {
  min-height: 48px;
  height: 48px;
  padding: 0 18px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}

.login-error {
  margin-top: 12px;
  min-height: 20px;
  color: var(--red);
  font-size: 13px;
  line-height: 1.4;
  text-align: left;
}

.login-box.is-error {
  animation: login-shake 0.42s ease;
}

@keyframes login-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@media (max-width: 560px) {
  .login-box {
    width: min(100%, 420px);
    border-radius: 16px;
  }

  .login-field {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .login-submit,
  .login-field .primary-button {
    width: 100%;
  }

  .password-shell input,
  .login-submit,
  .login-field .primary-button {
    min-height: 50px;
    height: 50px;
    font-size: 16px;
  }

  .password-toggle {
  z-index: 2;
    width: 40px;
    height: 40px;
  }
}

@media (max-width: 380px) {
  .login-brand {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    font-size: 22px;
  }

  .login-desc {
    font-size: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .login-box.is-error {
    animation: none;
  }
}

/* ===== Proxy source input ===== */
.proxy-source-row {
  display: flex;
  gap: 8px;
}

.proxy-source-row input {
  flex: 1;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  font-size: 13px;
  outline: none;
  background: #fbfdff;
  color: var(--ink);
}

.proxy-source-row input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.14);
}

.proxy-source-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 160px;
  overflow-y: auto;
}

.proxy-source-empty {
  color: var(--muted);
  font-size: 12px;
  padding: 8px 0;
  text-align: center;
}

.proxy-source-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdff;
  font-size: 12px;
}

.proxy-source-item .proxy-source-url {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
}

.proxy-source-item .proxy-source-remove {
  border: 0;
  background: transparent;
  color: var(--red);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 4px;
  opacity: 0.7;
  transition: opacity 0.12s;
}

.proxy-source-item .proxy-source-remove:hover {
  opacity: 1;
}

.source-group {
  margin-bottom: 16px;
}

.source-group-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding: 0 4px;
}

.source-group-head .source-group-toggle {
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
}

.source-group-head .source-group-title {
  font-weight: 600;
  color: var(--ink);
  font-size: 14px;
}

.source-group-head .source-group-tools {
  margin-left: auto;
}

.source-group-head button {
  font-size: 12px;
  padding: 2px 8px;
  height: 24px;
  line-height: 1;
}
.source-tag.cn {
  background: #ecfdf5;
  color: #047857;
  border-color: #a7f3d0;
}

.source-tag.global {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.source-group {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fbfcfe;
}

.source-group + .source-group {
  margin-top: 12px;
}

.source-group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--line);
}

.source-group-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

.source-group .source-option {
  margin-bottom: 6px;
}
.source-region-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin: 0 0 10px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #eef3f8;
}

.source-region-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  min-height: 38px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.source-region-tab:hover {
  color: var(--ink);
}

.source-region-tab.is-active {
  background: #fff;
  color: var(--blue-dark);
  box-shadow: 0 1px 3px rgba(23, 32, 42, 0.08);
}

.source-list {
  display: grid;
  gap: 8px;
  max-height: min(42vh, 420px);
  min-height: 220px;
  overflow: auto;
  padding-right: 2px;
}
.advanced-sources {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: #f8fafc;
}

.advanced-sources summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  user-select: none;
}

.advanced-sources[open] summary {
  margin-bottom: 8px;
  color: var(--ink);
}

.advanced-sources textarea {
  min-height: 88px;
}

.proxy-source-list {
  max-height: 96px;
}

.panel-block textarea {
  min-height: 96px;
}

.panel-block-primary .source-list {
  max-height: min(46vh, 460px);
}

@media (max-width: 980px) {
  .control-panel {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .results-panel {
    min-height: auto;
  }

  .topbar {
    position: static;
  }

  .panel-block-primary .source-list,
  .source-list {
    max-height: 320px;
    min-height: 160px;
  }
}