/* 设计语言：Linear（awesome-design-md / linear.app）。
   暗色单主题 —— Linear 不提供浅色版；层次靠 canvas → surface 阶梯 + 1px hairline，不用阴影。
   薰衣草蓝 #5e6ad2 只出现在主按钮、焦点环、链接强调三处。 */
:root {
  color-scheme: dark;

  --canvas: #010102;
  --surface-1: #0f1011;
  --surface-2: #141516;
  --surface-3: #18191a;
  --hairline: #23252a;
  --hairline-strong: #34343a;

  --ink: #f7f8f8;
  --ink-muted: #d0d6e0;
  --ink-subtle: #8a8f98;
  --ink-tertiary: #62666d;

  --primary: #5e6ad2;
  --primary-hover: #828fff;
  --primary-focus: rgb(94 105 210 / 50%);
  --on-primary: #ffffff;

  --success: #27a644;
  --danger: #f0616d;
  --warn: #d9a441;

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 9999px;

  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, "Segoe UI", Roboto,
    "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.app-shell {
  width: min(100% - 32px, 1760px);
  margin: 0 auto;
  padding: 24px 0;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 24px;
  margin-bottom: 16px;
}

h1 {
  margin: 0 0 4px;
  color: var(--ink);
  font-size: 28px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.6px;
}

p {
  margin: 0;
  color: var(--ink-subtle);
  font-size: 14px;
  line-height: 1.5;
}

.summary {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.summary span {
  padding: 6px 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--surface-1);
  color: var(--ink-muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(330px, 430px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.input-panel,
.result-panel {
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  background: var(--surface-1);
}

.input-panel {
  position: sticky;
  top: 16px;
  padding: 24px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--ink-subtle);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.4px;
}

textarea,
select,
input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--ink);
  letter-spacing: normal;
}

textarea::placeholder,
input::placeholder {
  color: var(--ink-tertiary);
}

textarea:hover,
select:hover,
input:hover {
  border-color: var(--hairline-strong);
}

textarea:focus,
select:focus,
input:focus,
button:focus-visible {
  outline: 2px solid var(--primary-focus);
  outline-offset: 2px;
  border-color: var(--hairline-strong);
}

textarea {
  min-height: clamp(220px, 34vh, 460px);
  resize: vertical;
  padding: 12px;
  line-height: 1.5;
  font-family: var(--font-mono);
  font-size: 13px;
  overflow-wrap: anywhere;
}

select,
input {
  min-height: 38px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 400;
}

.controls {
  display: grid;
  grid-template-columns: minmax(118px, 1fr) minmax(104px, 0.9fr) minmax(76px, 0.7fr) minmax(102px, 0.9fr);
  gap: 12px;
  margin-top: 16px;
}

.upstream-label {
  margin-top: 16px;
}

.saved-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  gap: 8px;
}

.saved-input button {
  min-height: 38px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  color: var(--ink-muted);
  letter-spacing: normal;
}

.checkbox-label input {
  width: 16px;
  min-height: 16px;
  flex: 0 0 16px;
  accent-color: var(--primary);
}

.progress-panel {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  padding: 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink-subtle);
  font-size: 13px;
}

.progress-row strong {
  color: var(--ink);
  font-family: var(--font-mono);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.actions {
  display: grid;
  grid-template-columns: 1fr;
  margin-top: 24px;
}

button {
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

button:hover {
  background: var(--surface-3);
  border-color: var(--hairline-strong);
}

button[type="submit"] {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--on-primary);
}

button[type="submit"]:hover {
  border-color: var(--primary-hover);
  background: var(--primary-hover);
}

button:disabled {
  cursor: not-allowed;
  color: var(--ink-tertiary);
  opacity: 0.6;
}

button:disabled:hover {
  background: var(--surface-2);
  border-color: var(--hairline);
}

.message {
  min-height: 22px;
  margin-top: 16px;
  color: var(--ink-subtle);
  font-size: 13px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

/* 不能 overflow:hidden —— 白名单弹层要能溢出面板；圆角交给 .table-wrap 自己收 */
.result-panel {
  min-width: 0;
}

.result-toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--hairline);
  background: var(--surface-2);
}

.result-filter {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.result-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}

.copy-limit-label {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--ink-subtle);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.4px;
}

.copy-limit-label input {
  min-height: 28px;
  width: 64px;
  padding: 4px 8px;
  font-size: 12px;
}

.asn-toggle {
  gap: 6px;
  cursor: pointer;
}

.asn-toggle input {
  width: 16px;
  min-height: 16px;
  flex: 0 0 16px;
  margin: 0;
  accent-color: var(--primary);
}

.asn-editor {
  position: relative;
}

.asn-editor summary {
  padding: 4px 8px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--surface-1);
  color: var(--ink-subtle);
  font-size: 12px;
  letter-spacing: 0.4px;
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.asn-editor summary::-webkit-details-marker {
  display: none;
}

.asn-editor summary:hover {
  border-color: var(--hairline-strong);
  color: var(--ink);
}

.asn-editor[open] summary {
  border-color: var(--hairline-strong);
  color: var(--ink);
}

.asn-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 5;
  display: grid;
  gap: 8px;
  justify-items: end;
  width: min(440px, 80vw);
  padding: 12px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
}

.asn-popover textarea {
  min-height: 170px;
  padding: 10px;
  background: var(--surface-1);
  font-size: 12px;
  line-height: 1.7;
}

.result-filter-label {
  color: var(--ink-subtle);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.4px;
}

.result-filter-count {
  min-height: 22px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 181px);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  scrollbar-color: var(--hairline-strong) transparent;
}

.result-toolbar {
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

table {
  width: 100%;
  /* 只兜住列被挤成细条的下限；再高就是白白强制横向滚动 */
  min-width: 880px;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--hairline);
  text-align: left;
  vertical-align: top;
}

/* 首尾列贴着表格边缘会显脏，单独把外侧留回来 */
th:first-child,
td:first-child {
  padding-left: 16px;
}

th:last-child,
td:last-child {
  padding-right: 16px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--ink-subtle);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

td {
  color: var(--ink-muted);
  overflow-wrap: anywhere;
}

tbody tr:hover td {
  background: var(--surface-2);
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* IP、ASN、耗时这类定长数据不能断行，否则 "AS5650" 会被拆成两行 */
td.mono {
  white-space: nowrap;
}

/* 代理串本来就被 compactProxy 截过，这里再压一道宽度上限；完整值在 title 和点击复制里 */
.proxy-cell {
  max-width: 170px;
  width: 170px;
}

/* 运营商名可以很长（"Universal Service Network Frontier - D - HRFR.CT"），截断，全名给 title */
.org-cell {
  max-width: 160px;
}

.org-cell span {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.copy-cell {
  width: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-family: var(--font-mono);
  text-align: left;
  cursor: copy;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.copy-cell:hover {
  background: transparent;
  border-color: transparent;
  color: var(--primary-hover);
}

/* 低风控代理是这张表最该被一眼看到的东西 —— 用绿色描边而不是实心块，避免和风控徽章抢注意力 */
.proxy-low-risk {
  display: inline-block;
  max-width: 100%;
  padding: 2px 8px;
  border: 1px solid rgb(39 166 68 / 40%);
  border-radius: var(--radius-xs);
  background: rgb(39 166 68 / 12%);
  color: #4ade80;
}

.proxy-low-risk:hover {
  border-color: rgb(39 166 68 / 70%);
  color: #86efac;
}

/* 风控徽章：暗底上不用高饱和实心色块，改成同色系描边 + 12% 底色 */
.risk-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.risk-extreme-clean {
  border-color: rgb(39 166 68 / 40%);
  background: rgb(39 166 68 / 14%);
  color: #4ade80;
}

.risk-clean {
  border-color: rgb(39 166 68 / 28%);
  background: rgb(39 166 68 / 10%);
  color: #86efac;
}

.risk-neutral {
  border-color: var(--hairline-strong);
  background: var(--surface-3);
  color: var(--ink-muted);
}

.risk-light {
  border-color: rgb(217 164 65 / 34%);
  background: rgb(217 164 65 / 12%);
  color: #e3b341;
}

.risk-high {
  border-color: rgb(232 131 58 / 38%);
  background: rgb(232 131 58 / 12%);
  color: #f0883e;
}

.risk-extreme {
  border-color: rgb(240 97 109 / 42%);
  background: rgb(240 97 109 / 14%);
  color: #ff7b72;
}

.ip-type-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  max-width: 100%;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--ink-muted);
  font-size: 12px;
  white-space: nowrap;
}

.speed-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.speed-fast {
  border-color: rgb(39 166 68 / 40%);
  background: rgb(39 166 68 / 14%);
  color: #4ade80;
}

.speed-medium {
  border-color: rgb(217 164 65 / 34%);
  background: rgb(217 164 65 / 12%);
  color: #e3b341;
}

.speed-slow {
  border-color: rgb(240 97 109 / 42%);
  background: rgb(240 97 109 / 14%);
  color: #ff7b72;
}

.mini-action {
  min-height: 28px;
  width: fit-content;
  padding: 4px 12px;
  border-radius: var(--radius-md);
  font-size: 12px;
  line-height: 1.2;
}

.empty-row td {
  text-align: center;
  color: var(--ink-tertiary);
  padding: 72px 16px;
}

.empty-row:hover td {
  background: transparent;
}

@media (min-width: 1600px) {
  .workspace {
    grid-template-columns: minmax(380px, 480px) minmax(0, 1fr);
  }

  table {
    min-width: 960px;
  }
}

@media (max-width: 1180px) {
  .app-shell {
    width: min(100% - 24px, 1040px);
    padding: 24px 0;
  }

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

  .input-panel {
    position: static;
  }

  textarea {
    min-height: 240px;
  }

  .table-wrap {
    max-height: none;
  }
}

@media (max-width: 820px) {
  .app-shell {
    width: 100%;
    padding: 0;
  }

  .topbar {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 16px 12px 12px;
    margin-bottom: 0;
  }

  h1 {
    font-size: 24px;
    letter-spacing: -0.4px;
  }

  .summary {
    justify-content: flex-start;
  }

  .workspace {
    gap: 12px;
  }

  .input-panel,
  .result-panel,
  .result-toolbar,
  .table-wrap {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

  .input-panel {
    padding: 16px 12px;
  }

  .controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .saved-input {
    grid-template-columns: minmax(0, 1fr) 64px;
  }

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

  textarea {
    min-height: 190px;
    max-height: 42vh;
  }

  table,
  thead,
  tbody,
  tr,
  td {
    display: block;
  }

  table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0;
  }

  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  tbody {
    display: grid;
    gap: 12px;
    padding: 12px;
    background: var(--canvas);
  }

  tr {
    border: 1px solid var(--hairline);
    border-radius: var(--radius-lg);
    background: var(--surface-1);
    overflow: hidden;
  }

  tbody tr:hover td {
    background: transparent;
  }

  td {
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr);
    gap: 12px;
    min-height: 42px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--hairline);
  }

  td:last-child {
    border-bottom: 0;
  }

  /* 卡片布局宽度有限，允许长值回到换行 */
  td.mono,
  .ip-type-badge {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  td::before {
    content: attr(data-label);
    color: var(--ink-tertiary);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.4px;
  }

  .empty-row td {
    display: block;
    padding: 56px 12px;
  }

  .empty-row td::before {
    content: "";
  }
}

@media (max-width: 460px) {
  .topbar {
    padding-inline: 12px;
  }

  .input-panel {
    padding: 12px;
  }

  .summary span {
    flex: 1 1 calc(33.333% - 8px);
    text-align: center;
    padding-inline: 8px;
  }

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

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

  .saved-input button {
    width: 100%;
  }

  td {
    grid-template-columns: 76px minmax(0, 1fr);
  }
}
