* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #0d1117;
  color: #c9d1d9;
  font-size: 14px;
}
header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; border-bottom: 1px solid #30363d; background: #161b22;
}
header h1 { font-size: 18px; margin: 0; }
header h1 small { color: #7d8590; font-weight: normal; font-size: 12px; margin-left: 8px; }

.ws-conn { color: #3fb950; }
.ws-disc { color: #f85149; }
.ws-busy { color: #d29922; }

#status-bar { display: flex; gap: 12px; align-items: center; }
#auth-state { cursor: pointer; user-select: none; font-size: 12px; padding: 2px 8px; border-radius: 4px; border: 1px solid transparent; }
#auth-state.auth-out { color: #d29922; border-color: #4d3a14; background: #1a1410; }
#auth-state.auth-in  { color: #3fb950; border-color: #143a1a; background: #0e1a10; }
#auth-state:hover { filter: brightness(1.15); }

/* Auth modal */
.modal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(2px);
}
.modal.hidden { display: none; }
.modal-box {
  background: #161b22; border: 1px solid #30363d; border-radius: 8px;
  padding: 18px 22px; min-width: 320px; max-width: 90vw;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}
.modal-box h3 { margin: 0 0 8px; font-size: 16px; }
.modal-hint { color: #8b949e; font-size: 12.5px; margin: 0 0 14px; line-height: 1.5; }
.modal-box input[type="password"] {
  width: 100%; padding: 8px 10px; font-size: 14px;
  background: #0d1117; border: 1px solid #30363d; color: #c9d1d9;
  border-radius: 4px; box-sizing: border-box;
}
.modal-box input[type="password"]:focus { outline: none; border-color: #58a6ff; }
.modal-error {
  color: #f85149; font-size: 12px; min-height: 16px; margin: 6px 2px 0;
}
.modal-actions {
  display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px;
}
.modal-actions button { padding: 6px 14px; }
#auth-submit { border-color: #2f81f7; background: #1f6feb; color: #fff; }
#auth-submit:hover:not(:disabled) { background: #2f81f7; }

section { padding: 12px 16px; }

#modems { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.modem {
  background: #161b22; border: 1px solid #30363d; border-radius: 6px; padding: 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.modem.connected { border-left: 4px solid #3fb950; }
.modem.registered { border-left: 4px solid #d29922; }
.modem.failed, .modem.no-sim { border-left: 4px solid #f85149; opacity: 0.75; }
.modem .head { display: flex; justify-content: space-between; align-items: baseline; }
.modem .head .id { font-weight: 600; font-size: 16px; }
.modem .head .state { font-size: 11px; padding: 2px 6px; border-radius: 3px; background: #21262d; }
.modem .row { display: flex; justify-content: space-between; font-size: 12px; color: #8b949e; }
.modem .row b { color: #c9d1d9; font-weight: normal; }
.modem .signal-bar { height: 4px; background: #21262d; border-radius: 2px; overflow: hidden; margin-top: 6px; }
.modem .signal-bar > div { height: 100%; background: #3fb950; }

#controls .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
#controls .row.quick { padding-top: 8px; border-top: 1px dashed #30363d; }
#controls label { color: #8b949e; }

input, select, button {
  background: #0d1117; border: 1px solid #30363d; color: #c9d1d9; padding: 5px 10px;
  font: inherit; border-radius: 4px;
}
input[type="text"] { flex: 1 1 220px; min-width: 180px; }
input[type="number"] {
  width: 60px; min-width: 0; max-width: 80px; padding: 3px 6px;
}
input[type="checkbox"] {
  flex: 0 0 auto; min-width: 0; width: auto; padding: 0;
  margin: 0 2px 0 0; accent-color: #2f81f7;
}
input:focus, select:focus { outline: none; border-color: #58a6ff; }
button { cursor: pointer; transition: background 0.1s; flex: 0 0 auto; }
button:hover:not(:disabled) { background: #21262d; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { border-color: #2f81f7; background: #1f6feb; color: #fff; }
button.primary:hover:not(:disabled) { background: #2f81f7; }

#run { border-color: #2f81f7; background: #1f6feb; color: #fff; }
#stop { border-color: #da3633; background: #21262d; color: #f85149; }

.sources { display: flex; gap: 6px; flex-wrap: wrap; }
.src-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; background: #21262d; border: 1px solid #30363d; border-radius: 14px;
  cursor: pointer; user-select: none;
}
.src-chip input { display: none; }
.src-chip.checked { background: #1f6feb; border-color: #58a6ff; color: #fff; }
.src-chip .ip { font-size: 11px; opacity: 0.8; }

.quick-btn { font-size: 12px; }

.opts {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 4px 14px; font-size: 12px; color: #8b949e;
  flex: 1 1 100%;
}
.opts:empty { display: none; }
.opts label {
  display: inline-flex; align-items: center; gap: 4px;
  white-space: nowrap;
}
.opts label[data-tip] { cursor: help; border-bottom: 1px dotted #484f58; padding-bottom: 1px; }
.opts label.disabled { opacity: 0.45; cursor: not-allowed; }
.opts label.disabled input { cursor: not-allowed; }
.opts input[type="text"] { flex: 0 0 auto; min-width: 100px; max-width: 160px; padding: 2px 6px; }
.opts input:disabled { background: #161b22; color: #6e7681; border-color: #21262d; }
.opts-row { padding-top: 0 !important; margin-top: -2px; }
#controls .opts-row.row:has(.opts:empty) { display: none; }

/* tool description (under Tool/Target row) */
.tool-help {
  flex: 1 1 100%;
  font-size: 12px; color: #8b949e; line-height: 1.4;
  padding-left: 80px;
}
.tool-help:empty { display: none; }
.tool-help-row { padding-top: 0 !important; margin-top: -4px; }
#controls .tool-help-row.row:has(.tool-help:empty) { display: none; }
@media (max-width: 700px) { .tool-help { padding-left: 0; } }

/* generic data-tip tooltip — 500ms delay, dark theme */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  background: #1c2128;
  color: #e6edf3;
  border: 1px solid #444c56;
  border-radius: 5px;
  padding: 7px 10px;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 12px;
  font-weight: normal;
  line-height: 1.45;
  white-space: normal;
  width: max-content;
  max-width: 320px;
  opacity: 0; transform: translateY(2px);
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease;
  z-index: 100;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
}
[data-tip]:hover::after,
[data-tip]:focus-visible::after {
  opacity: 1; transform: translateY(0);
  transition-delay: 500ms;
}
/* tip bubble may overflow viewport on the right — let the browser pin it. */
[data-tip] { isolation: isolate; }

/* ---------- Subnet scan UI ---------- */
.scan-pane .pane-body { display: none; }
.scan-pane .pane-body > div { white-space: normal; word-break: normal; overflow-wrap: normal; }
.scan-meta {
  padding: 6px 10px; font-size: 11.5px; color: #8b949e;
  font-family: ui-monospace, monospace;
}
.scan-meta.err { color: #f85149; }
.scan-progress {
  position: relative; height: 18px; background: #21262d;
  margin: 4px 10px 4px; border-radius: 9px; overflow: hidden;
}
.scan-progress + .scan-progress { margin-top: 0; }
.scan-progress:last-of-type { margin-bottom: 8px; }
.scan-progress .bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #1f6feb, #58a6ff);
  transition: width 80ms linear;
}
.scan-progress[data-phase="icmp"] .bar {
  background: linear-gradient(90deg, #2ea043, #56d364);
}
.scan-progress .pct {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: #e6edf3; font-family: ui-monospace, monospace;
  text-shadow: 0 0 3px rgba(0,0,0,0.7);
}
.scan-progress .scan-phase-label {
  position: absolute; left: 8px; top: 0; bottom: 0;
  display: flex; align-items: center;
  font-size: 10px; font-weight: 700; letter-spacing: 0.5px;
  color: #e6edf3; font-family: ui-monospace, monospace;
  text-shadow: 0 0 3px rgba(0,0,0,0.7);
  z-index: 1;
}
.scan-summary { padding: 6px 10px 4px; }
.scan-summary .sum-row {
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
  font-size: 12px; margin-bottom: 4px;
}
.scan-summary .sum-pill {
  padding: 2px 8px; border-radius: 12px; background: #21262d; font-weight: 600;
}
.scan-summary .sum-pill.ok { background: #0e3a1c; color: #3fb950; }
.scan-summary .sum-pill.err { background: #3a0e0e; color: #f85149; }
.scan-summary .sum-detail {
  display: block; color: #8b949e;
  word-break: normal; overflow-wrap: normal;
}
.scan-summary .sum-detail b { color: #c9d1d9; font-weight: 600; }
.scan-summary .sum-actions {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 4px;
  font-size: 11.5px; color: #8b949e;
}
.scan-summary .sum-actions label { white-space: nowrap; }
.scan-summary .sum-actions button {
  padding: 3px 9px; font-size: 11.5px;
}
.scan-table-wrap { max-height: 50vh; overflow-y: auto; padding: 0 10px 10px; }
.scan-table {
  width: 100%; border-collapse: collapse;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
}
.scan-table thead th {
  position: sticky; top: 0; background: #161b22;
  text-align: left; padding: 4px 6px; border-bottom: 1px solid #30363d;
  font-size: 11px; color: #8b949e; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.5px;
}
.scan-table td, .scan-table th {
  white-space: nowrap; word-break: normal; overflow-wrap: normal;
}
.scan-table td { padding: 2px 6px; border-bottom: 1px solid #21262d; }
.scan-table-wrap { overflow-x: hidden; }
.scan-table tr.cert-details td { white-space: normal; word-break: break-all; }
.scan-table tr.alive { color: #c9d1d9; }
.scan-table tr.alive td:first-child { color: #79c0ff; }
.scan-table tr:not(.alive) { color: #6e7681; }
.scan-table .ok { color: #3fb950; }
.scan-table .dim { color: #484f58; }
.scan-table tbody.hide-dead tr.dead-hidden { display: none; }

.scan-table tr.has-cert { cursor: pointer; }
.scan-table tr.has-cert:hover { background: #1c2128; }
.scan-table .cert-cell {
  max-width: 0; width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.scan-table .cert-summary { color: #d2a8ff; }

.scan-table tr.cert-details { background: #0d1117; cursor: default; }
.scan-table tr.cert-details td {
  padding: 8px 12px; border-bottom: 1px solid #30363d;
}
.cert-detail {
  font-family: ui-monospace, monospace;
  font-size: 11.5px; color: #c9d1d9; line-height: 1.5;
}
.cert-detail b { color: #8b949e; font-weight: normal; min-width: 90px; display: inline-block; }
.scan-table.no-cert td:nth-child(5),
.scan-table.no-cert th:nth-child(5) { display: none; }

#terminal-wrap {
  margin: 12px 16px 16px; background: #010409; border: 1px solid #30363d; border-radius: 6px; overflow: hidden;
}
#terminal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 12px; background: #161b22; border-bottom: 1px solid #30363d;
  font-size: 12px;
}
#term-title { font-weight: 600; }
#term-meta { color: #8b949e; font-family: ui-monospace, monospace; }
#terminal {
  margin: 0; padding: 12px; min-height: 300px; max-height: 60vh; overflow-y: auto;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.45; color: #c9d1d9;
  white-space: pre-wrap; word-break: break-all;
}
#terminal .tline { white-space: pre-wrap; word-break: break-all; }

.run-group {
  display: grid; gap: 8px; margin: 8px 0;
}
.run-pane {
  background: #161b22; border: 1px solid #30363d;
  border-top: 3px solid #58a6ff;
  border-radius: 4px; overflow: hidden; min-width: 0;
}
.pane-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 10px; background: #0d1117; border-bottom: 1px solid #21262d;
  font-size: 11px; font-family: ui-sans-serif, system-ui, sans-serif;
}
.pane-tag { font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.pane-status { font-family: ui-monospace, monospace; }
.pane-status.ok { color: #3fb950; }
.pane-status.err { color: #f85149; }
.pane-status.info { color: #d29922; }
.pane-body {
  padding: 6px 10px; max-height: 50vh; overflow-y: auto;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.5;
}
.pane-body > div { white-space: pre-wrap; word-break: break-all; }

.modem .row.ext { font-size: 11.5px; }
.modem .row.ext .ext-age { font-size: 11px; color: #6e7681; }
.modem .row.ext .ext-refresh {
  color: #58a6ff; text-decoration: none; margin-left: 4px;
  font-size: 11px; cursor: pointer;
}
.modem .row.ext .ext-refresh:hover { color: #79c0ff; }
.modem .row b.dim { color: #8b949e; font-style: italic; }
#terminal .cmd { color: #58a6ff; font-weight: 600; }
#terminal .ok { color: #3fb950; }
#terminal .err { color: #f85149; }
#terminal .hint { color: #8b949e; }
#terminal .info { color: #d29922; }
.term-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.autoclear { display: inline-flex; align-items: center; gap: 4px; color: #8b949e; font-size: 11px; cursor: pointer; user-select: none; }
.autoclear input { margin: 0; cursor: pointer; }

.bs-yes { color: #d29922; font-weight: 600; }
.bs-no  { color: #7ee787; font-weight: 600; }
.bs-unknown { color: #8b949e; font-weight: 600; }
.bs-detail { display: flex; flex-wrap: wrap; gap: 4px; padding: 2px 0 4px; }
.bs-svc { font-size: 10px; padding: 1px 5px; border-radius: 3px; font-family: ui-monospace, monospace; border: 1px solid; }
.bs-svc-ok   { color: #7ee787; border-color: #2d6638; background: #0d1c12; }
.bs-svc-fail { color: #ff7b72; border-color: #6e2c2c; background: #1c0d0d; }
.bs-svc-na   { color: #6e7681; border-color: #30363d; background: #161b22; }

/* ---------- DPI-zombie probe UI ---------- */
.zombie-pane .pane-body { display: none; }
.zombie-meta {
  padding: 6px 10px; font-size: 11.5px; color: #8b949e;
  font-family: ui-monospace, monospace;
}
.zombie-steps {
  padding: 4px 10px 8px;
  display: flex; flex-direction: column; gap: 4px;
}
.zombie-step {
  display: flex; align-items: center; gap: 10px;
  font-family: ui-monospace, monospace; font-size: 12.5px;
  background: #161b22; border: 1px solid #30363d; border-radius: 6px;
  padding: 6px 10px;
}
.zombie-step .zs-label {
  flex: 0 0 auto; min-width: 64px;
  font-weight: 700; color: #c9d1d9; letter-spacing: 0.5px;
}
.zombie-step .zs-result { flex: 1 1 auto; color: #c9d1d9; }
.zombie-step .zs-result.ok  { color: #7ee787; }
.zombie-step .zs-result.err { color: #ff7b72; }
.zombie-step .zs-result .zs-ok  { color: #3fb950; font-weight: 700; margin-right: 4px; }
.zombie-step .zs-result .zs-fail { color: #f85149; font-weight: 700; margin-right: 4px; }
.zombie-step .zs-result .hint { color: #8b949e; }

.zombie-verdict {
  margin: 4px 10px 10px;
  padding: 10px 12px;
  border-radius: 8px;
  display: flex; align-items: center; gap: 10px;
  font-family: ui-monospace, monospace;
  background: #161b22; border: 1px solid #30363d;
  min-height: 18px;
}
.zombie-verdict:empty { display: none; }
.zombie-verdict .zv-icon { font-size: 18px; line-height: 1; }
.zombie-verdict .zv-label { font-weight: 800; letter-spacing: 1px; font-size: 13px; }
.zombie-verdict .zv-summary { color: #8b949e; font-size: 12px; }
.zombie-verdict.zv-clean       { background: #0d1c12; border-color: #2d6638; color: #7ee787; }
.zombie-verdict.zv-zombie      { background: #2a0d0d; border-color: #8c2424; color: #ff7b72; }
.zombie-verdict.zv-honest      { background: #2a1c0d; border-color: #6e5520; color: #d29922; }
.zombie-verdict.zv-unreachable { background: #161b22; border-color: #30363d; color: #8b949e; }

/* ---------- User card in status bar (TG-auth) ---------- */
.user-card {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; padding: 2px 8px;
  border-radius: 4px; border: 1px solid #30363d;
  background: #161b22; color: #c9d1d9;
}
.user-card.hidden { display: none; }
.user-card .uc-avatar {
  width: 18px; height: 18px; border-radius: 50%; object-fit: cover;
}
.user-card .uc-name { font-weight: 600; }
.user-card .uc-role { font-size: 10px; color: #d29922; }
.user-card .uc-balance {
  font-family: ui-monospace, monospace; color: #79c0ff;
  border-left: 1px solid #30363d; padding-left: 6px; margin-left: 4px;
}

/* ---------- TG widget block inside auth modal ---------- */
.tg-widget {
  display: flex; justify-content: center; align-items: center;
  min-height: 48px; margin: 4px 0 10px;
}
.tg-widget .hint { color: #8b949e; font-size: 12px; }

.admin-fallback {
  margin-top: 4px; padding: 6px 0;
  border-top: 1px solid #30363d;
}
.admin-fallback summary {
  cursor: pointer; color: #8b949e; font-size: 12px;
  padding: 4px 0; user-select: none;
}
.admin-fallback summary:hover { color: #c9d1d9; }
.admin-fallback[open] summary { color: #d29922; }
.admin-fallback input[type="password"] {
  width: 100%; box-sizing: border-box;
  margin-top: 6px; padding: 6px 8px;
  background: #0d1117; border: 1px solid #30363d; border-radius: 4px;
  color: #e6edf3;
}

.modal-actions .hidden { display: none; }

/* ---------- QR auth block ---------- */
.auth-box { max-width: 360px; }
.qr-block {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 8px 0 14px;
}
.qr-block canvas {
  border-radius: 8px; background: #fff; padding: 6px;
}
.qr-status {
  color: #8b949e; font-size: 12px; text-align: center;
  min-height: 14px;
}
.qr-deeplink {
  color: #58a6ff; font-size: 12.5px; text-decoration: none;
  border: 1px solid #1f6feb; padding: 5px 14px; border-radius: 6px;
  background: #0d1117; transition: background 80ms;
}
.qr-deeplink:hover { background: #161b22; }

.widget-fallback, .admin-fallback {
  border-top: 1px solid #30363d; padding-top: 6px; margin-top: 4px;
}
.widget-fallback summary {
  cursor: pointer; color: #8b949e; font-size: 12px; padding: 4px 0;
  user-select: none;
}
.widget-fallback summary:hover { color: #c9d1d9; }
.widget-fallback[open] summary { color: #58a6ff; }

/* ---------- DPI-zombie ASN/hosting row ---------- */
.zombie-verdict .zv-main {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.zombie-verdict .zv-asn {
  margin-top: 6px;
  font-size: 11.5px; color: #8b949e;
  font-family: ui-monospace, monospace;
  padding-top: 6px;
  border-top: 1px dashed rgba(139, 148, 158, 0.25);
}
.zombie-verdict .zv-hosting {
  display: inline-block; margin-left: 6px;
  font-weight: 600; color: #d29922;
  padding: 1px 6px; border-radius: 3px;
  background: rgba(210, 153, 34, 0.12);
  border: 1px solid rgba(210, 153, 34, 0.4);
}

/* ---------- Scan-table ASN column ---------- */
.scan-table th.asn-col, .scan-table td.asn-cell {
  font-size: 11.5px; color: #c9d1d9; max-width: 220px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.scan-table .asn-num {
  color: #79c0ff; font-family: ui-monospace, monospace;
  font-weight: 600; margin-right: 4px;
}
.scan-table .asn-host {
  display: inline-block; margin-left: 6px;
  font-size: 10px; font-weight: 700; color: #d29922;
  padding: 0 5px; border-radius: 3px;
  background: rgba(210, 153, 34, 0.12);
  border: 1px solid rgba(210, 153, 34, 0.4);
}

/* ---------- Scan-summary ASN aggregation ---------- */
.scan-summary .asn-summary-row {
  display: flex; flex-direction: column; gap: 4px;
  align-items: flex-start;
}
.scan-summary .asn-summary-label { color: #8b949e; font-weight: 600; }
.scan-summary .asn-summary-list {
  display: flex; flex-direction: column; gap: 3px;
  font-family: ui-monospace, monospace; font-size: 11.5px;
}
.scan-summary .asn-item {
  display: flex; align-items: center; gap: 6px; color: #c9d1d9;
}
.scan-summary .asn-num { color: #79c0ff; font-weight: 600; }
.scan-summary .asn-count {
  margin-left: auto; color: #8b949e; font-weight: 600;
  background: #161b22; padding: 1px 6px; border-radius: 3px;
  border: 1px solid #30363d;
}

/* ---------- BS row: services on left, status on right ---------- */
.bs-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 4px 0;
}
.bs-row .bs-detail { padding: 0; flex-wrap: wrap; flex: 0 1 auto; }
.bs-row .bs-status {
  font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 3px; white-space: nowrap;
  border: 1px solid;
}
.bs-row .bs-status.bs-yes     { color: #d29922; border-color: #6e5520; background: rgba(210,153,34,0.10); }
.bs-row .bs-status.bs-no      { color: #7ee787; border-color: #2d6638; background: rgba(126,231,135,0.10); }
.bs-row .bs-status.bs-unknown { color: #8b949e; border-color: #30363d; background: #161b22; }

/* Wider number inputs for 4+ digit values (port, timeout) */
input.wide-num { width: 80px; }
