/* ==========================================================================
   Панель управления прокси — оформление
   Вся палитра в переменных: тёмная тема в :root, светлая переопределяет тот
   же набор в :root[data-theme='light']. Ниже цветов в hex нет.
   ========================================================================== */

:root {
  /* Тёмная тема — значения по умолчанию */
  --bg: #0b1017;
  --bg-glow-1: rgba(91, 140, 255, 0.14);
  --bg-glow-2: rgba(52, 211, 153, 0.08);
  --surface: #131b28;
  --surface-2: #1a2434;
  --surface-3: #212d40;
  --input-bg: #0d141f;
  --border: #253145;
  --border-soft: #1c2637;
  --text: #e8edf7;
  --muted: #8a99b5;
  --accent: #5b8cff;
  --accent-hover: #4a7bf0;
  --accent-soft: rgba(91, 140, 255, 0.14);
  --on-accent: #ffffff;
  --ok: #34d399;
  --danger: #f87171;

  --btn-hover: #212d40;
  --row-border: #1b2534;
  --row-hover: rgba(255, 255, 255, 0.03);
  --ok-soft: rgba(52, 211, 153, 0.12);
  --ok-soft-border: rgba(52, 211, 153, 0.3);
  --danger-border: rgba(248, 113, 113, 0.28);
  --danger-soft: rgba(248, 113, 113, 0.12);
  --overlay: rgba(5, 9, 15, 0.7);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px -8px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.6);
  --focus-ring: rgba(91, 140, 255, 0.2);

  --radius: 16px;
  --radius-sm: 10px;
}

:root[data-theme='light'] {
  --bg: #f4f7fb;
  --bg-glow-1: rgba(47, 107, 255, 0.1);
  --bg-glow-2: rgba(13, 148, 92, 0.06);
  --surface: #ffffff;
  --surface-2: #f5f8fc;
  --surface-3: #eaeff7;
  --input-bg: #fbfcfe;
  --border: #dde5f0;
  --border-soft: #e8edf5;
  --text: #111a29;
  --muted: #64748b;
  --accent: #2f6bff;
  --accent-hover: #1f57e6;
  --accent-soft: rgba(47, 107, 255, 0.1);
  --on-accent: #ffffff;
  --ok: #0d8a4e;
  --danger: #d92d20;

  --btn-hover: #eaeff7;
  --row-border: #edf1f7;
  --row-hover: rgba(17, 26, 41, 0.025);
  --ok-soft: rgba(13, 148, 92, 0.1);
  --ok-soft-border: rgba(13, 148, 92, 0.28);
  --danger-border: rgba(217, 45, 32, 0.25);
  --danger-soft: rgba(217, 45, 32, 0.08);
  --overlay: rgba(15, 23, 42, 0.4);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px -10px rgba(15, 23, 42, 0.18);
  --shadow-lg: 0 24px 48px -16px rgba(15, 23, 42, 0.22);
  --focus-ring: rgba(47, 107, 255, 0.18);
}

* { box-sizing: border-box; }

/* Атрибут hidden должен побеждать display из классов ниже (.login-screen,
   .modal объявлены как display:flex, а авторские стили сильнее
   пользовательского агента — иначе «скрытые» экраны остаются видимыми). */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-feature-settings: 'tnum' 1;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(1100px 520px at 12% -10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(900px 480px at 92% 0%, var(--bg-glow-2), transparent 55%);
  background-attachment: fixed;
}

h1, h2 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 21px; }
h2 { font-size: 15px; }
p { margin: 0; }

.muted { color: var(--muted); }
.small-text, .small { font-size: 12px; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- элементы форм -------------------------------------------------------- */

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  min-width: 0;
}

input {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 12px;
  font: inherit;
  width: 100%;
  min-width: 0;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

input::placeholder { color: var(--muted); opacity: 0.75; }
input:hover:not(:focus) { background: var(--surface-2); }

input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.with-action { display: flex; gap: 8px; }
.with-action input { flex: 1; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* --- кнопки --------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.08s, box-shadow 0.15s;
}

.btn:hover:not(:disabled) { background: var(--btn-hover); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--on-accent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12), 0 8px 20px -10px var(--accent);
}

.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--btn-hover); }
.btn.danger { color: var(--danger); border-color: var(--danger-border); }
.btn.danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn.block { width: 100%; }
.btn.small { padding: 6px 11px; font-size: 12px; font-weight: 500; }
.btn.icon { width: 38px; height: 38px; padding: 0; font-size: 15px; line-height: 1; flex: none; }

.theme-toggle { transition: background 0.15s, transform 0.12s; }
.theme-toggle:active { transform: scale(0.93); }

/* --- вход ----------------------------------------------------------------- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
}

.login-screen .theme-toggle { position: absolute; top: 22px; right: 22px; }

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 34px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow-lg);
  animation: rise 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

.login-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  font-size: 22px;
  border-radius: 14px;
  background: var(--accent-soft);
  border: 1px solid var(--border);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.error { color: var(--danger); margin: 0; }

/* --- каркас --------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 11px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand strong { font-size: 15px; letter-spacing: -0.01em; }

.logo {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  box-shadow: 0 6px 16px -8px var(--accent);
}

.topbar-right { display: flex; align-items: center; gap: 10px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px 5px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12px;
  color: var(--muted);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px var(--ok-soft);
}

.dot.off { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

main {
  max-width: 1220px;
  margin: 0 auto;
  padding: 26px 28px 8px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

footer {
  max-width: 1220px;
  margin: 0 auto;
  padding: 8px 28px 34px;
}

/* --- карточки ------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

/* Карточки в ряду одной высоты: разная высота оставляла дыру под
   короткой карточкой. */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr);
  gap: 20px;
  align-items: stretch;
}

.grid > .card { display: flex; flex-direction: column; }
.grid > .card > .stack:last-child { margin-top: auto; }

/* Блок подключения */
.hero { padding: 24px; }

.hero-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.hero-text h2 { font-size: 16px; margin-bottom: 3px; }

.endpoint {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 14px;
  border-radius: 12px;
  background: var(--accent-soft);
  border: 1px solid var(--border);
}

.endpoint-value {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  background: none;
  border: none;
  padding: 0;
  color: var(--text);
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 28px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
  font-size: 12.5px;
}

.meta-item { display: inline-flex; gap: 7px; align-items: baseline; }
.meta-key { font-weight: 500; }

/* Статистика */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
}

.stat {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.stat::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--accent);
  opacity: 0.85;
}

.stat .value {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

.stat .label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.stat.live::before { background: var(--ok); }

/* Таблицы */
.table-wrap { overflow-x: auto; margin: 0 -6px; padding: 0 6px; }

/* Журнал бывает длинным — ограничиваем высоту, страница не растёт */
.table-wrap.scroll { max-height: 430px; overflow-y: auto; }
.table-wrap.scroll thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }

th {
  text-align: left;
  padding: 9px 10px;
  color: var(--muted);
  font-weight: 500;
  font-size: 11.5px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--row-border);
  vertical-align: middle;
}

th.num, td.num { text-align: right; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.12s; }
tbody tr:hover { background: var(--row-hover); }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 4px 9px;
  font-size: 12.5px;
}

.login-cell {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  border: 1px solid var(--border);
  color: var(--muted);
  background: var(--surface-2);
  white-space: nowrap;
}

.badge.online, .badge.ok {
  color: var(--ok);
  border-color: var(--ok-soft-border);
  background: var(--ok-soft);
}

.badge.online::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.badge.danger {
  color: var(--danger);
  border-color: var(--danger-border);
  background: var(--danger-soft);
}

.count-pill {
  min-width: 26px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.actions { display: flex; gap: 5px; justify-content: flex-end; flex-wrap: nowrap; }

/* Компактные кнопки-иконки в действиях клиента */
.icon-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 13px;
  line-height: 1;
  display: inline-grid;
  place-items: center;
}

.nowrap { white-space: nowrap; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 22px 0 6px;
  margin: 0;
  font-size: 13px;
}

.hint { font-size: 12px; color: var(--muted); line-height: 1.5; }

.select {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 7px 11px;
  font: inherit;
  font-size: 12.5px;
  max-width: 240px;
}

.select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }

/* --- модальное окно и уведомления ---------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  animation: rise 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.cred-row {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.cred-row code { overflow-x: auto; }
.modal-actions { display: flex; justify-content: flex-end; margin-top: 22px; }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 70;
  max-width: 340px;
  padding: 13px 17px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  animation: rise 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.toast.error { border-left-color: var(--danger); }

/* --- адаптив -------------------------------------------------------------- */

/* Колонка комментария уходит раньше остальных: таблица клиентов живёт
   в узкой части сетки, и текст комментария первым идёт за край. */
@media (max-width: 1280px) {
  .hide-md { display: none; }
}

@media (max-width: 1020px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 720px) {
  .hide-sm { display: none; }
  main { padding: 18px 16px 8px; }
  .topbar { padding: 12px 16px; }
  footer { padding: 8px 16px 28px; }
  .card, .hero { padding: 16px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pair { grid-template-columns: 1fr; }
  .hero-main { flex-direction: column; align-items: stretch; }
  .endpoint { justify-content: space-between; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}