/* Proxy Checker — тёмная тема для операционного дашборда */

:root {
  --bg: #0b1120;
  --surface: #111a2e;
  --surface-2: #16223b;
  --surface-3: #1c2a48;
  --border: #24324f;
  --border-strong: #33456b;
  --text: #e6edf7;
  --text-muted: #9aa8bf;
  --primary: #3b82f6;
  --primary-strong: #2563eb;
  --primary-soft: rgba(59, 130, 246, 0.14);
  --accent: #f59e0b;
  --ok: #22c55e;
  --ok-text: #4ade80;
  --ok-soft: rgba(34, 197, 94, 0.13);
  --warn: #f59e0b;
  --warn-text: #fbbf24;
  --warn-soft: rgba(245, 158, 11, 0.14);
  --err: #ef4444;
  --err-text: #f87171;
  --err-soft: rgba(239, 68, 68, 0.13);
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
p { margin: 0; }
[hidden] { display: none !important; }
.sprite { display: none; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; }
.spacer { flex: 1 1 auto; }
.center { display: flex; justify-content: center; margin-top: 16px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 100;
  background: var(--primary); color: #fff; padding: 8px 12px; border-radius: var(--radius-sm);
}
.skip-link:focus { top: 12px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.icon {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.icon-xl { width: 40px; height: 40px; color: var(--text-muted); }

/* ─── Кнопки ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 500; white-space: nowrap; cursor: pointer;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease), color 150ms var(--ease);
  touch-action: manipulation;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary-strong); border-color: var(--primary-strong); color: #fff; }
.btn-primary:hover { background: var(--primary); }
.btn-danger { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.btn-danger:hover { background: var(--err); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger-text { color: var(--err-text); }
.btn-icon { width: 40px; padding: 0; }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn .spin, .spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Шапка ──────────────────────────────────────────────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 24px;
  background: rgba(11, 17, 32, 0.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; font-size: 17px; }
.brand:hover { text-decoration: none; }
.brand-lg { font-size: 22px; }
.nav { display: flex; gap: 4px; }
.nav a {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 0 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--text); }
.topbar-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }

main { max-width: 1440px; margin: 0 auto; padding: 20px 24px 64px; outline: none; }

.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar-sub { margin: 28px 0 12px; }
.view-title { font-size: 22px; font-weight: 650; }
.section-title { font-size: 16px; font-weight: 600; }

/* ─── Карточки машин ─────────────────────────────────────────────────────── */

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(380px, 100%), 1fr)); gap: 16px; align-items: start; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 14px; min-width: 0;
}
.card-head { display: flex; align-items: flex-start; gap: 8px 12px; flex-wrap: wrap; }
.card-title { flex: 1 1 160px; min-width: 0; }
.card-title h2 { font-size: 17px; font-weight: 650; overflow-wrap: anywhere; }
.card-title .sub { color: var(--text-muted); font-size: 13px; overflow-wrap: anywhere; }
.card-actions { display: flex; gap: 2px; flex: none; }
.card-actions .btn-icon { width: 36px; min-height: 36px; }
.card-note { font-size: 13px; color: var(--text-muted); }

.status-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--text-muted); }
.status-dot.ok { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
.status-dot.err { background: var(--err); box-shadow: 0 0 0 4px var(--err-soft); }
.status-dot.loading { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px 14px; }
.kv-item { min-width: 0; }
.kv-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kv-value { font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.meter { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 10px; font-size: 13px; }
.meter-track { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.meter-fill { height: 100%; background: var(--primary); border-radius: 3px; transition: width 300ms var(--ease); }
.meter-fill.warn { background: var(--warn); }
.meter-fill.err { background: var(--err); }
.meters { display: grid; gap: 6px; }

.line { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; }
.line .muted { margin-right: 4px; }

.events { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 14px; font-size: 13px; }
.events div { display: flex; justify-content: space-between; gap: 8px; }

.ports { display: flex; flex-wrap: wrap; gap: 6px; }
.port-chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 0 10px;
  border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 13px; cursor: pointer;
  transition: border-color 150ms var(--ease), background-color 150ms var(--ease);
}
.port-chip:hover { border-color: var(--primary); background: var(--primary-soft); }
.port-chip .port { font-family: var(--mono); font-weight: 600; }
.port-chip .icon { width: 12px; height: 12px; color: var(--primary); }
.port-chip[disabled] { cursor: default; opacity: 0.6; }
.port-chip[disabled]:hover { border-color: var(--border-strong); background: var(--surface-2); }

.mode { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; padding: 1px 6px; border-radius: 4px; }
.mode-hybrid { background: var(--primary-soft); color: #93c5fd; }
.mode-socks { background: rgba(168, 85, 247, 0.15); color: #d8b4fe; }
.mode-http { background: rgba(20, 184, 166, 0.15); color: #5eead4; }
.mode-mitm { background: var(--warn-soft); color: var(--warn-text); }

.card-error {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--err-soft); color: var(--text); font-size: 13px;
}
.card-error .icon { color: var(--err-text); margin-top: 1px; }
.card-error b { color: var(--err-text); }

.last-test {
  border-top: 1px solid var(--border); padding-top: 12px; margin-top: auto;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; font-size: 13px;
}
.last-test a { color: var(--text-muted); }

.section-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }

/* ─── Бейджи и метки ─────────────────────────────────────────────────────── */

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-3); color: var(--text-muted); white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok-text); }
.badge-warn { background: var(--warn-soft); color: var(--warn-text); }
.badge-err { background: var(--err-soft); color: var(--err-text); }
.badge-info { background: var(--primary-soft); color: #93c5fd; }
.badge .icon { width: 12px; height: 12px; }

.ratio { font-variant-numeric: tabular-nums; font-weight: 600; }
.ratio.ok { color: var(--ok-text); }
.ratio.warn { color: var(--warn-text); }
.ratio.err { color: var(--err-text); }

/* ─── Пустые состояния, тосты, алерты ────────────────────────────────────── */

.empty {
  display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center;
  padding: 56px 24px; border: 1px dashed var(--border-strong); border-radius: var(--radius);
}
.empty h2 { font-size: 18px; }

.alert { display: flex; align-items: flex-start; gap: 8px; padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; }
.alert-error { background: var(--err-soft); color: var(--err-text); }
.alert-warn { background: var(--warn-soft); color: var(--warn-text); }

.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 1000; display: grid; gap: 8px; }
.toast {
  min-width: 240px; max-width: 420px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--surface-3); border: 1px solid var(--border-strong); box-shadow: var(--shadow);
  font-size: 14px; animation: toast-in 200ms var(--ease);
}
.toast-ok { border-color: rgba(34, 197, 94, 0.5); }
.toast-err { border-color: rgba(239, 68, 68, 0.6); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ─── Формы и диалоги ────────────────────────────────────────────────────── */

.dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 32px);
  padding: 0; border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.dialog-wide { width: min(860px, calc(100vw - 24px)); }
.dialog-narrow { width: min(420px, calc(100vw - 24px)); }
.dialog-xl { width: min(1100px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(2, 6, 16, 0.6); }
.dialog[open] { animation: dialog-in 200ms var(--ease); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.dialog form { display: flex; flex-direction: column; max-height: calc(100dvh - 34px); }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.dialog-header h2 { font-size: 18px; }
.dialog-body { padding: 16px 20px; overflow-y: auto; display: grid; gap: 16px; }
.dialog-footer { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 14px 20px; border-top: 1px solid var(--border); }

.field { display: grid; gap: 6px; min-width: 0; }
.field-label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text); }
.field-label .icon { width: 14px; height: 14px; color: var(--text-muted); }
.field-help { font-size: 12px; color: var(--text-muted); }
.field-help.tight { margin-top: -10px; }
.req { color: var(--err-text); }

input[type="text"], input[type="password"], input[type="number"], input[type="url"], select {
  width: 100%; min-height: 40px; padding: 8px 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); font: inherit;
  transition: border-color 150ms var(--ease);
}
input:hover, select:hover { border-color: #46598a; }
input:focus, select:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }
input[aria-invalid="true"] { border-color: var(--err); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); margin: 0; cursor: pointer; flex: none; }

.input-with-action { display: flex; gap: 6px; }
.input-with-action input { flex: 1 1 auto; }

.check { display: inline-flex; align-items: center; gap: 8px; min-height: 32px; cursor: pointer; font-size: 14px; }
.check-row { display: flex; flex-wrap: wrap; gap: 4px 20px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid-3 { grid-template-columns: repeat(3, 1fr); }
.span-2 { grid-column: span 2; }

.fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px 16px; margin: 0; display: grid; gap: 14px; }
.fieldset legend { padding: 0 6px; font-weight: 600; font-size: 14px; }

.details summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--text-muted); min-height: 32px; display: flex; align-items: center; }
.details[open] summary { margin-bottom: 12px; }
.details .btn { margin-top: 12px; }

.form-error { color: var(--err-text); font-size: 14px; }
.probe { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 14px; background: var(--surface-2); }
.probe.ok { background: var(--ok-soft); }
.probe.err { background: var(--err-soft); }

.targets { display: grid; gap: 10px; max-height: 320px; overflow-y: auto; padding-right: 4px; }
.target { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; display: grid; gap: 8px; }
.target-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.target-head .check { font-weight: 600; }
.target-ports { display: flex; flex-wrap: wrap; gap: 6px; padding-left: 26px; }
.port-toggle {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 10px;
  border: 1px solid var(--border-strong); border-radius: 999px; font-size: 13px; cursor: pointer;
}
.port-toggle:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.port-toggle input { width: 14px; height: 14px; }
.port-toggle .port { font-family: var(--mono); font-weight: 600; }
.target-disabled { opacity: 0.55; }

/* ─── Быстрый тест ───────────────────────────────────────────────────────── */

.quick-row { display: grid; grid-template-columns: 1fr 96px auto; gap: 12px; align-items: end; }
.quick-row input#qf-url { font-family: var(--mono); font-size: 13px; }
.verdict {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-radius: var(--radius); font-size: 18px; font-weight: 650;
}
.verdict .icon { width: 26px; height: 26px; }
.verdict small { display: block; font-size: 13px; font-weight: 500; color: var(--text-muted); }
.verdict-ok { background: var(--ok-soft); color: var(--ok-text); }
.verdict-warn { background: var(--warn-soft); color: var(--warn-text); }
.verdict-err { background: var(--err-soft); color: var(--err-text); }
#qf-result { display: grid; gap: 14px; }
#qf-result .tiles { margin-bottom: 0; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
#qf-result .tile-value { font-size: 22px; }
#qf-result .cell-ok .ip { white-space: nowrap; overflow-wrap: normal; }

/* ─── Таблицы ────────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2);
}
.table td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; transition: background-color 150ms var(--ease); }
.table tbody tr.clickable:hover { background: var(--surface-2); }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions .btn-icon { width: 32px; min-height: 32px; }

.cell-ok { color: var(--ok-text); }
.cell-ok .ip { font-family: var(--mono); font-size: 13px; color: var(--text); overflow-wrap: anywhere; }
.cell-err { color: var(--err-text); font-size: 13px; max-width: 320px; overflow-wrap: anywhere; }
.cell-na { color: var(--text-muted); }
.ms { display: block; font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.table-results tr.row-new { animation: row-in 600ms var(--ease); }
@keyframes row-in { from { background: var(--primary-soft); } }
.only-errors tr[data-ok="1"] { display: none; }

/* ─── Прогон ─────────────────────────────────────────────────────────────── */

.progress { position: relative; height: 28px; margin: 12px 0 20px; border-radius: var(--radius-sm); background: var(--surface-2); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary-strong), var(--primary)); transition: width 400ms var(--ease); }
.progress-label { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.progress.done .progress-bar { background: var(--surface-3); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 4px; }
.tile-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.tile-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.tile-sub { font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ─── Вход ───────────────────────────────────────────────────────────────── */

.login-page { display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(380px, 100%); padding: 28px; display: grid; gap: 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.login-card form { display: grid; gap: 14px; }

/* ─── Адаптив ────────────────────────────────────────────────────────────── */

@media (max-width: 760px) {
  .topbar { padding: 10px 14px; gap: 10px; }
  .topbar-actions { width: 100%; margin-left: 0; }
  .topbar-actions .btn-primary { flex: 1; }
  main { padding: 16px 14px 48px; }
  .grid { grid-template-columns: 1fr; }
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .quick-row { grid-template-columns: 1fr 1fr; }
  .quick-row .field:first-child { grid-column: span 2; }
  .toasts { left: 14px; right: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
