:root {
  --bg: #0f1318;
  --panel: #171d24;
  --ink: #e6edf3;
  --muted: #9ba8b7;
  --line: #2a3440;
  --accent: #1f9d6b;
  --danger: #f87171;
  --mono: "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --sans: "IBM Plex Sans", "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 0%, #1a2532, transparent 40%),
    radial-gradient(circle at 80% 100%, #12242f, transparent 40%),
    var(--bg);
}
.layout {
  max-width: 1120px;
  margin: 24px auto;
  padding: 0 16px 24px;
  display: grid;
  gap: 16px;
}
.hero, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.quick-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.hero h1 { margin: 0; font-size: 28px; }
.hero p { margin: 8px 0 0; color: var(--muted); }
.auth-row {
  margin-top: 12px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.auth-token-label {
  min-width: 260px;
  flex: 1 1 320px;
}
.auth-token-label input {
  width: 100%;
}
#api-token-status {
  min-height: 18px;
  margin: 8px 0 0;
}
#api-token-status.ok {
  color: #86efac;
}
#api-token-status.error {
  color: #fca5a5;
}
.hero-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
}
button {
  border: 1px solid var(--line);
  background: #222b36;
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}
button:disabled {
  cursor: wait;
}
button.is-loading {
  position: relative;
  color: transparent;
}
button.is-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  margin-top: -6px;
  border-radius: 50%;
  border: 2px solid #5e6f83;
  border-top-color: #dce7f3;
  animation: spin 0.8s linear infinite;
}
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { background: #3a1f25; color: #fecaca; border-color: #6b2b38; }
.form-grid {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}
.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  grid-column: 1 / -1;
  margin-top: 2px;
}
label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}
label.checkbox {
  flex-direction: row;
  align-items: center;
  margin-top: 22px;
  gap: 8px;
}
input:not([type="checkbox"]), select {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font-size: 14px;
  color: var(--ink);
  background: #111820;
}
select {
  padding-right: 28px;
  background-image:
    linear-gradient(45deg, transparent 50%, #7f93a8 50%),
    linear-gradient(135deg, #7f93a8 50%, transparent 50%);
  background-position:
    calc(100% - 16px) 52%,
    calc(100% - 11px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
input:not([type="checkbox"]):focus, select:focus {
  outline: none;
  border-color: #3f8fda;
  box-shadow: 0 0 0 3px rgba(63, 143, 218, 0.18);
}
.form-status {
  margin: 8px 0 4px;
  min-height: 18px;
}
.form-status.ok {
  color: #86efac;
}
.form-status.error {
  color: #fca5a5;
}
.output {
  background: #0b1016;
  color: #c9f4db;
  font-family: var(--mono);
  border-radius: 8px;
  padding: 10px;
  min-height: 44px;
  overflow: auto;
  white-space: pre-wrap;
}
#targets {
  position: relative;
  min-height: 30px;
}
#targets.is-loading {
  opacity: 0.72;
  pointer-events: none;
}
#targets.is-loading::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #36506a;
  border-top-color: #9ad0ff;
  animation: spin 0.8s linear infinite;
}
.target-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #121920;
  margin-bottom: 10px;
}
.target-header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.target-meta {
  margin: 8px 0;
  color: var(--muted);
  font-size: 13px;
}
.target-selection {
  margin: 8px 0 10px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 8px;
}
.target-selection > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f161d;
  padding: 8px;
  display: grid;
  gap: 2px;
}
.target-selection .key {
  color: var(--muted);
  font-size: 12px;
}
.target-selection .value {
  color: var(--ink);
  font-size: 14px;
  font-family: var(--mono);
}
.error-text {
  color: #fca5a5;
}
.target-candidates {
  margin: 8px 0 10px;
}
.candidates {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f161d;
  padding: 8px;
}
.ip-metrics {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f161d;
  padding: 8px;
}
.ip-metrics-title {
  margin: 0 0 6px;
  font-size: 13px;
}
.ip-table-wrap {
  overflow-x: auto;
  border: 1px solid #24303d;
  border-radius: 8px;
}
.ip-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.ip-table th,
.ip-table td {
  padding: 7px 8px;
  border-bottom: 1px solid #24303d;
  text-align: left;
  vertical-align: top;
}
.ip-table th {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}
.ip-table tr:last-child td {
  border-bottom: none;
}
.ip-table tr.selected td {
  background: rgba(31, 157, 107, 0.12);
  box-shadow: inset 0 1px 0 #1f9d6b, inset 0 -1px 0 #1f9d6b;
}
.mono {
  font-family: var(--mono);
}
.ip-flag {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11px;
  border: 1px solid;
  margin-right: 4px;
  margin-bottom: 2px;
}
.ip-flag.good {
  color: #86efac;
  border-color: #2f6f48;
  background: #153223;
}
.ip-flag.warn {
  color: #fcd34d;
  border-color: #7a6120;
  background: #2f250e;
}
.ip-flag.bad {
  color: #fca5a5;
  border-color: #7d2b35;
  background: #34151b;
}
.ip-flag.selected {
  color: #6ee7b7;
  border-color: #2f6f48;
  background: #153223;
}
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal.is-hidden {
  display: none;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 10, 16, 0.72);
  backdrop-filter: blur(2px);
}
.modal-card {
  position: relative;
  width: min(1040px, 100%);
  max-height: calc(100vh - 32px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #131c25;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 {
  margin: 0;
  font-size: 16px;
}
.modal-actions {
  display: flex;
  gap: 8px;
}
.modal-body {
  padding: 12px 14px 14px;
  max-height: calc(100vh - 120px);
  overflow: auto;
}
.candidates-title {
  margin: 0 0 6px;
  font-size: 13px;
}
.candidate-list {
  display: grid;
  gap: 6px;
}
.candidate-row {
  border: 1px solid #24303d;
  border-radius: 8px;
  padding: 7px 8px;
  display: grid;
  grid-template-columns: minmax(140px, 1.4fr) minmax(80px, 0.7fr) minmax(52px, 0.5fr) minmax(100px, 1fr);
  gap: 8px;
  align-items: center;
  font-size: 12px;
}
.candidate-row.selected {
  border-color: #1f9d6b;
  box-shadow: inset 0 0 0 1px #1f9d6b;
}
.candidate-ip,
.candidate-latency {
  font-family: var(--mono);
}
.candidate-status {
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.candidate-status.good {
  color: #86efac;
}
.candidate-status.bad {
  color: #fca5a5;
}
.candidate-note {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.target-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.small {
  font-size: 12px;
  color: var(--muted);
}
@media (max-width: 768px) {
  .hero h1 { font-size: 22px; }
  .layout { margin-top: 12px; }
  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .form-actions .primary {
    width: 100%;
  }
  .candidate-row {
    grid-template-columns: 1fr 1fr;
  }
  .modal {
    padding: 8px;
  }
  .modal-card {
    max-height: calc(100vh - 16px);
  }
  .modal-head {
    flex-direction: column;
    align-items: flex-start;
  }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
