/* ProxyFinder UI. Tokens first; dark values are their own steps, not an inversion. */
:root {
  color-scheme: light;
  --bg: #f3f2ee;
  --surface: #fcfcfb;
  --surface-2: #f0efea;
  --line: #e1dfd8;
  --line-strong: #c9c6bc;
  --text: #121211;
  --text-2: #52514e;
  --text-3: #7d7b74;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-soft: #e3eefc;
  --s-http: #2a78d6;
  --s-socks4: #eb6834;
  --s-socks5: #1baf7a;
  --good: #0a8a0a;
  --good-soft: #e2f4e2;
  --warn: #a86e00;
  --warn-soft: #fbf0d6;
  --bad: #c43333;
  --bad-soft: #fbe5e5;
  --grid: #e8e6e0;
  --mono: ui-monospace, "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(20, 20, 18, .05), 0 4px 16px rgba(20, 20, 18, .04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --line: #2e2e2b;
    --line-strong: #44433f;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #8e8c84;
    --accent: #5598e7;
    --accent-ink: #86b6ef;
    --accent-soft: #1b2a3d;
    --s-http: #3987e5;
    --s-socks4: #d95926;
    --s-socks5: #199e70;
    --good: #3fbf3f;
    --good-soft: #17301a;
    --warn: #e0a322;
    --warn-soft: #33290f;
    --bad: #e66767;
    --bad-soft: #3a1c1c;
    --grid: #2a2a27;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #232321;
  --line: #2e2e2b;
  --line-strong: #44433f;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --text-3: #8e8c84;
  --accent: #5598e7;
  --accent-ink: #86b6ef;
  --accent-soft: #1b2a3d;
  --s-http: #3987e5;
  --s-socks4: #d95926;
  --s-socks5: #199e70;
  --good: #3fbf3f;
  --good-soft: #17301a;
  --warn: #e0a322;
  --warn-soft: #33290f;
  --bad: #e66767;
  --bad-soft: #3a1c1c;
  --grid: #2a2a27;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.boot { padding: 40px; color: var(--text-3); }

/* ------------------------------------------------ shell */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px;
  padding: 0 20px; height: 52px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand i { width: 14px; height: 14px; border-radius: 50%; border: 3px solid var(--accent); position: relative; }
.brand i::after { content: ""; position: absolute; inset: 2px; border-radius: 50%; background: var(--s-socks5); }
nav.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs a {
  padding: 7px 11px; border-radius: 6px; color: var(--text-2); white-space: nowrap; font-weight: 500;
}
nav.tabs a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
nav.tabs a.on { background: var(--accent-soft); color: var(--accent-ink); }
.top-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.live-dot { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); white-space: nowrap; }
.live-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.live-dot.run::before { background: var(--accent); animation: pulse 1.2s infinite; }
.live-dot.ok::before { background: var(--good); }
.live-dot.off::before { background: var(--bad); }
@keyframes pulse { 50% { opacity: .3; } }

main { max-width: 1320px; margin: 0 auto; padding: 20px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { color: var(--text-3); font-size: 13px; margin-top: 2px; }

/* ------------------------------------------------ blocks */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; min-width: 0;
}
.card > h3:first-child, .card > .card-head:first-child { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt { margin-top: 14px; }
@media (max-width: 960px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: 1fr; } }
@media (max-width: 720px) {
  main { padding: 14px 12px; }
  .top { padding: 6px 12px 4px; gap: 4px 10px; height: auto; flex-wrap: wrap; }
  .brand { flex: 1; }
  nav.tabs { order: 3; flex-basis: 100%; margin: 0 -6px; }
  nav.tabs a { padding: 6px 8px; }
  .g2 { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat .v { font-size: 22px; }
  .card { padding: 12px; }
  .span2 { grid-column: auto; }
  .filters .field input { width: 96px; }
}

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .v { font-size: 28px; font-weight: 680; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat .l { color: var(--text-2); font-size: 12.5px; }
.stat .d { color: var(--text-3); font-size: 12px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* horizontal bars (HTML, not a chart lib) */
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar { display: grid; grid-template-columns: 74px 1fr 52px; align-items: center; gap: 8px; font-size: 12.5px; }
.bar .track { height: 10px; background: var(--surface-2); border-radius: 0 4px 4px 0; overflow: hidden; }
.bar .fill { height: 100%; border-radius: 0 4px 4px 0; background: var(--accent); min-width: 2px; }
.bar .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }
.seg { display: flex; height: 12px; border-radius: 4px; overflow: hidden; gap: 2px; background: var(--surface); }
.seg > div { height: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ------------------------------------------------ controls */
button, .btn {
  font: inherit; font-weight: 550; font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  white-space: nowrap;
}
button:hover:not(:disabled), .btn:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--accent-ink); }
:root[data-theme="dark"] button.primary:hover:not(:disabled) { background: #3987e5; }
button.danger { color: var(--bad); }
button.ghost { border-color: transparent; background: transparent; }
button.sm, .btn.sm { height: 26px; padding: 0 8px; font-size: 12px; }
input, select, textarea {
  font: inherit; font-size: 13px; color: var(--text);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 6px;
  height: 32px; padding: 0 9px; min-width: 0;
}
textarea { height: auto; padding: 8px 9px; resize: vertical; font-family: var(--mono); font-size: 12.5px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type="checkbox"] { height: auto; width: 15px; height: 15px; accent-color: var(--accent); }
label.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; color: var(--text-3); }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters .field input { width: 110px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  height: 28px; padding: 0 10px; border-radius: 14px; font-size: 12.5px; font-weight: 500;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text-2);
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.chip b { font-weight: 600; color: var(--text-3); margin-left: 4px; }
.seg-ctl { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.seg-ctl button { border: 0; border-radius: 0; height: 30px; border-right: 1px solid var(--line); }
.seg-ctl button:last-child { border-right: 0; }
.seg-ctl button.on { background: var(--accent-soft); color: var(--accent-ink); }

/* ------------------------------------------------ table */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
th.sort { cursor: pointer; user-select: none; }
th.sort:hover { color: var(--text); }
th.sort.on { color: var(--accent-ink); }
tbody tr:hover { background: var(--surface-2); }
tbody tr.click { cursor: pointer; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.url { max-width: 520px; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 28px; text-align: center; color: var(--text-3); }

/* ------------------------------------------------ badges */
.b {
  display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px; border-radius: 10px;
  font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.b.good { background: var(--good-soft); color: var(--good); }
.b.warn { background: var(--warn-soft); color: var(--warn); }
.b.bad { background: var(--bad-soft); color: var(--bad); }
.b.info { background: var(--accent-soft); color: var(--accent-ink); }
.proto { display: inline-flex; align-items: center; gap: 5px; font-family: var(--mono); font-size: 12px; }
.proto i { width: 8px; height: 8px; border-radius: 2px; }
.proto.http i { background: var(--s-http); }
.proto.socks4 i { background: var(--s-socks4); }
.proto.socks5 i { background: var(--s-socks5); }

/* ------------------------------------------------ progress */
.progress { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .5s; }
.stages { display: flex; gap: 4px; flex-wrap: wrap; }
.stages span { font-size: 12px; padding: 3px 8px; border-radius: 5px; background: var(--surface-2); color: var(--text-3); }
.stages span.done { color: var(--text-2); }
.stages span.now { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }

/* ------------------------------------------------ misc */
.log {
  font-family: var(--mono); font-size: 12px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--surface-2); border-radius: 6px; padding: 10px 12px; max-height: 480px; overflow: auto; margin: 0;
}
.events { display: flex; flex-direction: column; }
.ev { display: grid; grid-template-columns: 92px 1fr; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.ev:last-child { border-bottom: 0; }
.ev time { color: var(--text-3); font-size: 12px; white-space: nowrap; }
.md { font-size: 14px; line-height: 1.6; }
.md h1 { font-size: 19px; margin: 0 0 10px; }
.md h2 { font-size: 16px; margin: 22px 0 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.md h3 { font-size: 14px; text-transform: none; letter-spacing: 0; color: var(--text); margin: 14px 0 6px; }
.md ul { padding-left: 20px; }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.md pre { background: var(--surface-2); padding: 10px; border-radius: 6px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.steps { display: flex; flex-direction: column; gap: 6px; }
.step { font-size: 13px; padding: 6px 10px; border-left: 3px solid var(--line-strong); }
.step.tool { font-family: var(--mono); font-size: 12px; color: var(--text-2); border-left-color: var(--accent); }
.step.result { border-left-color: var(--good); background: var(--surface-2); white-space: pre-wrap; }
.step.text { white-space: pre-wrap; }
.toast {
  position: fixed; right: 16px; bottom: 16px; z-index: 50; max-width: min(420px, calc(100vw - 32px));
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; font-size: 13px;
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.toast.err { background: var(--bad); color: #fff; }
.modal-bg { position: fixed; inset: 0; background: rgba(10,10,9,.45); z-index: 40; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 12px; overflow-y: auto; }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; width: min(720px, 100%); padding: 18px; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.modal .row.end { justify-content: flex-end; margin-top: 16px; }
.login { max-width: 360px; margin: 12vh auto; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.err-text { color: var(--bad); font-size: 13px; }
.chart { width: 100%; min-height: 180px; }
.chart .u-legend { font-size: 12px; color: var(--text-2); }
.chart .u-legend th { background: none; position: static; text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--text-2); }
.chart .u-legend td, .chart .u-legend th { border: 0; padding: 2px 6px; }
.u-select { background: color-mix(in srgb, var(--accent) 15%, transparent); }
.strip { display: flex; gap: 2px; flex-wrap: wrap; }
.strip i { width: 10px; height: 18px; border-radius: 2px; background: var(--surface-2); }
.strip i.ok { background: var(--good); }
.strip i.fail { background: var(--bad); opacity: .75; }
.tabs2 { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs2 a { padding: 8px 12px; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.tabs2 a.on { color: var(--accent-ink); border-bottom-color: var(--accent); }
.tabs2 a:hover { text-decoration: none; color: var(--text); }
.copybox { display: flex; gap: 6px; }
.copybox input { flex: 1; font-family: var(--mono); font-size: 12px; }
