/* ── VPN Gateway Manager — styles ────────────────────── */

:root {
  --bg: #0f1117;
  --surface: #1a1d2e;
  --surface-alt: #212537;
  --surface-hover: #272b3d;
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #e2e8f0;
  --muted: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #10b981;
  --success-dim: rgba(16, 185, 129, 0.15);
  --danger: #ef4444;
  --danger-dim: rgba(239, 68, 68, 0.15);
  --warning: #f59e0b;
  --warning-dim: rgba(245, 158, 11, 0.15);
  --purple: #a78bfa;
  --purple-dim: rgba(139, 92, 246, 0.12);
  --radius: 14px;
  --radius-sm: 8px;
  --font: "Inter", -apple-system, system-ui, sans-serif;
  --mono: "JetBrains Mono", "Fira Code", monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  min-height: 100vh;
}

.container {
  max-width: 1800px;
  margin: 0 auto;
  padding: 24px;
}

/* ── Header ──────────────────────────────────────────── */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text) 0%, var(--accent) 100%);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-host {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
}

.host-ip {
  color: var(--accent);
  font-weight: 600;
}

.host-dns {
  color: var(--text-muted);
}

.host-sep {
  color: var(--text-muted);
  opacity: 0.4;
}

/* ── Traffic chart ────────────────────────────────────── */

.chart-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px 6px;
  margin-bottom: 20px;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 12px;
  flex-wrap: wrap;
}

.chart-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.chart-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.chart-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
}

.chart-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chart-legend-name {
  font-weight: 500;
  color: var(--text);
}

.chart-legend-val {
  font-family: var(--mono);
  font-size: 11px;
}

#traffic-chart {
  width: 100%;
  display: block;
}

/* ── Workers grid ────────────────────────────────────── */

.workers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(480px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.worker-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.2s;
}

.worker-card.connected {
  border-color: rgba(16, 185, 129, 0.3);
}

.worker-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.worker-header > div:first-child {
  flex: 1;
  min-width: 0;
}

.worker-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-reset {
  width: 28px;
  height: 28px;
  padding: 4px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color .15s, background .15s;
}
.btn-reset:hover {
  color: var(--text);
  background: rgba(255,255,255,.08);
}
.btn-reset svg {
  width: 18px;
  height: 18px;
}

.worker-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.worker-name {
  font-size: 16px;
  font-weight: 600;
}

/* ── VPN status indicator ────────────────────────────── */

.vpn-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.vpn-country {
  flex: 1;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}

.vpn-ext-ip {
  font-size: 12px;
  font-family: var(--mono);
  color: var(--muted);
  opacity: 0.7;
  white-space: nowrap;
}

.indicator-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-on      { background: var(--success); box-shadow: 0 0 8px var(--success); }
.dot-off     { background: var(--danger); }
.dot-idle    { background: var(--muted); }
.dot-starting { background: var(--warning); animation: pulse 1.5s infinite; }

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

/* ── Toggle switch ───────────────────────────────────── */

.toggle {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-track {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #374151;
  border-radius: 13px;
  transition: background 0.3s;
}

.toggle input:checked + .toggle-track { background: var(--success); }

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.3s;
  pointer-events: none;
}

.toggle input:checked ~ .toggle-thumb { transform: translateX(22px); }
.toggle.disabled { opacity: 0.35; pointer-events: none; }

/* ── Metrics grid ────────────────────────────────────── */

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}


.metrics-grid.metrics-muted {
  opacity: 0.4;
  pointer-events: none;
}
.metric {
  padding: 8px 10px;
  background: var(--surface-alt);
  border-radius: 6px;
}

.metric-label {
  display: block;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 2px;
}

.metric-value {
  font: 600 13px/1.3 var(--mono);
}

.metric-speed {
  background: rgba(59, 130, 246, 0.06);
  border: 1px solid rgba(59, 130, 246, 0.12);
}

.speed-value {
  color: #3b82f6;
}

.worker-chart {
  margin: 0 -14px;
  padding: 0 14px;
  margin-bottom: 10px;
}

.worker-chart canvas {
  width: 100%;
  display: block;
  border-radius: 4px;
  background: rgba(255,255,255,0.02);
}

/* ── Log panel ───────────────────────────────────────── */

.blocked-panel {
  margin-bottom: 12px;
  padding: 10px 12px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: var(--radius-sm);
}

.blocked-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--danger);
}

.blocked-header svg { flex-shrink: 0; }

.blocked-detail {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.blocked-ip {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--danger);
}

.blocked-desc {
  margin-left: 4px;
}

.blocked-failover {
  margin-top: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
}

.blocked-failover.rotating {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.25);
  color: #f59e0b;
}

.blocked-failover.exhausted {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: var(--danger);
}

.log-panel {
  margin-bottom: 12px;
  padding: 10px 12px;
  background: rgba(239, 68, 68, 0.06);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-sm);
}

.log-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.log-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--danger);
}

.log-dismiss {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.log-dismiss:hover {
  opacity: 1;
  color: var(--text);
}

.log-content {
  font: 12px/1.6 var(--mono);
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
  max-height: 150px;
  overflow-y: auto;
}

/* ── Profile slots ────────────────────────────────────── */

.profile-slots {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
  flex: 1;
}

.profile-slot {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 8px 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-width: 0;
  height: 72px;
  box-sizing: border-box;
  overflow: hidden;
}

.profile-slot.active {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.06);
}

.profile-slot.slot-connected {
  border-color: var(--success);
  background: rgba(16, 185, 129, 0.08);
}

.profile-slot.slot-trying {
  animation: slotBlink 1s ease-in-out infinite;
}

.profile-slot.slot-failed {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.06);
}

@keyframes slotBlink {
  0%, 100% { background: rgba(245, 158, 11, 0.06); border-color: rgba(245, 158, 11, 0.3); }
  50% { background: rgba(245, 158, 11, 0.18); border-color: rgba(245, 158, 11, 0.7); }
}

/* Autorotation toggle row */
.autorotation-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px 6px;
}

.autorotation-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.toggle.toggle-sm {
  width: 36px;
  height: 20px;
}

.toggle.toggle-sm .toggle-track {
  border-radius: 10px;
}

.toggle.toggle-sm .toggle-thumb {
  width: 14px;
  height: 14px;
  top: 3px;
  left: 3px;
}

.toggle.toggle-sm input:checked ~ .toggle-thumb {
  transform: translateX(16px);
}

.profile-slot.empty {
  border-style: dashed;
  border-color: var(--border-strong);
  background: transparent;
  margin-top: auto;
}

.profile-slot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  min-height: 22px;
}

.profile-slot-num {
  font: 600 10px var(--mono);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.profile-slot-num::before {
  content: "Слот ";
}

.profile-slot-active {
  font-size: 10px;
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.profile-slot-body {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  min-height: 24px;
}

.profile-slot-body .profile-hint {
  font-size: 12px;
  color: var(--muted);
  flex: 1;
}

.profile-slot-body .profile-filename {
  flex: 1;
  min-width: 0;
  font-size: 11px;
}

.profile-slot-body .profile-btns {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.profile-slot-body .btn-icon {
  width: 24px;
  height: 24px;
}

.profile-slot-body .btn-icon svg {
  width: 12px;
  height: 12px;
}

.btn-xs {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--muted);
  transition: all 0.15s;
}

.btn-xs:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-color: var(--accent);
}

.btn-xs.btn-outline {
  border-color: var(--border-strong);
}

.profile-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--accent);
}

.profile-icon svg {
  width: 14px;
  height: 14px;
}

.profile-filename {
  font: 500 12px var(--mono);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.profile-btns {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* ── Icon buttons ────────────────────────────────────── */

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-icon svg {
  width: 16px;
  height: 16px;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.btn-icon-danger:hover {
  background: var(--danger-dim);
  color: var(--danger);
}

/* ── Card footer links ───────────────────────────────── */

.card-footer-links {
  display: flex;
  gap: 16px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.card-link {
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
  transition: color 0.15s;
}

.card-link:hover { color: var(--text); }

.auth-fields {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.auth-fields.visible { display: grid; }

/* ── Buttons ─────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font: 600 13px/1 var(--font);
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

.btn svg { width: 14px; height: 14px; }
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
}
.btn-outline:hover { background: var(--surface-hover); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #dc2626; }
.btn-success { background: var(--success); }
.btn-success:hover { background: #059669; }

/* ── Badges ──────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-sm { padding: 2px 8px; font-size: 10px; }

.badge-success { background: var(--success-dim); color: var(--success); }
.badge-danger  { background: var(--danger-dim);  color: var(--danger); }
.badge-warning { background: var(--warning-dim); color: var(--warning); }
.badge-muted   { background: rgba(100, 116, 139, 0.15); color: var(--muted); }

/* ── Section ─────────────────────────────────────────── */

.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title { font-size: 17px; font-weight: 600; }

/* ── Policy bar ──────────────────────────────────────── */

.policy-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.policy-label {
  font-size: 13px;
  color: var(--muted);
}

select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 6px 10px;
  font: 13px var(--font);
  cursor: pointer;
}

select:focus { outline: 1px solid var(--accent); }

/* ── Rules list ──────────────────────────────────────── */

.rules-list {
  display: grid;
  gap: 8px;
}

.rule-card {
  padding: 12px 16px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  transition: border-color 0.15s;
}

.rule-card:hover {
  border-color: var(--border-strong);
}

.rule-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.rule-name {
  font-weight: 600;
  font-size: 14px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rule-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.rule-worker-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(59, 130, 246, 0.12);
  color: var(--accent);
  white-space: nowrap;
}

.rule-worker-badge.auto {
  background: rgba(100, 116, 139, 0.15);
  color: var(--muted);
}

.rule-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.rule-tag {
  display: inline-block;
  padding: 3px 10px;
  font: 12px var(--mono);
  border-radius: 4px;
}

.rule-tag.domain {
  background: rgba(59, 130, 246, 0.10);
  color: var(--accent);
}

.rule-tag.cidr {
  background: var(--purple-dim);
  color: var(--purple);
}

.rule-tag.client {
  background: rgba(139, 92, 246, 0.12);
  color: #a78bfa;
  border-color: rgba(139, 92, 246, 0.25);
}

.rule-tag.empty {
  background: transparent;
  color: var(--muted);
  font-family: var(--font);
  font-style: italic;
}

/* ── Add rule form ───────────────────────────────────── */

.add-form {
  display: none;
  gap: 14px;
  padding: 20px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  margin-bottom: 16px;
}

.add-form.visible { display: grid; }

.form-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 2px;
}

input, textarea {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 10px 12px;
  font: 13px var(--font);
  resize: vertical;
  width: 100%;
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

input::placeholder, textarea::placeholder { color: var(--muted); }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }

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

.form-inline-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: end;
}

.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 4px;
}

/* ── Clients panel ───────────────────────────────────── */

.clients-panel {
  display: none;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.clients-panel.visible { display: block; }

/* ── Settings panel ──────────────────────────────────── */

.settings-panel {
  display: none;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.settings-panel.visible { display: block; }

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-toggle-row {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  gap: 0 10px;
  align-items: center;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
  transition: background 0.15s;
}

.settings-toggle-row:hover {
  background: rgba(255, 255, 255, 0.04);
}

.settings-toggle-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  grid-row: 1 / 3;
  cursor: pointer;
}

.settings-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.settings-hint {
  grid-column: 2;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.3;
}

.settings-directives {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 8px;
}

.settings-label-sm {
  font-size: 12px;
  color: var(--text);
  font-weight: 500;
}

.settings-hint-inline {
  font-weight: 400;
  color: var(--muted);
}

.settings-directives textarea {
  font: 12px var(--mono);
  padding: 8px 10px;
  resize: vertical;
  min-height: 50px;
}

.settings-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 2px 8px 0;
}

.settings-note {
  font-size: 11px;
  color: var(--muted);
}

.clients-loading {
  font-size: 13px;
  color: var(--muted);
  padding: 8px 0;
}

.client-group { margin-bottom: 10px; }

.client-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.client-ip { font: 600 13px/1 var(--mono); }
.client-hostname { font-size: 12px; color: var(--muted); }

.dest-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding-left: 4px;
}

.dest-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font: 12px var(--mono);
  border-radius: 4px;
  background: rgba(59, 130, 246, 0.10);
  color: var(--accent);
}

.dest-tag .port { color: var(--muted); font-size: 11px; }

.clients-empty {
  font-size: 13px;
  color: var(--muted);
  padding: 8px 0;
}

.clients-count {
  font: 600 11px/1 var(--mono);
  color: var(--muted);
  margin-bottom: 8px;
}

/* ── Routing section ─────────────────────────────────── */

.routing-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 24px;
}

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

.rt-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.rt-title {
  font-size: 15px;
  font-weight: 600;
}

.rt-policy-label {
  font-size: 12px;
  color: var(--muted);
}

.rt-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rt-policy-select {
  padding: 4px 8px;
  font-size: 12px;
}

.rt-table {
  display: grid;
  gap: 8px;
}

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

/* ── Rules modal extras ──────────────────────────────── */

.rm-rules-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.rm-add-form {
  display: none;
  margin-bottom: 12px;
}

.rm-add-form.visible { display: block; }

.rm-form-inner {
  display: grid;
  gap: 12px;
  padding: 16px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
}

/* ── Empty state ─────────────────────────────────────── */

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

/* ── Upload overlay ──────────────────────────────────── */

.upload-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(15, 17, 23, 0.85);
  backdrop-filter: blur(4px);
  border-radius: var(--radius);
}

.upload-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.upload-label {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}


/* ── Upload progress ring ──────────────────────────── */

.upload-progress-ring {
  position: relative;
  width: 48px;
  height: 48px;
}

.upload-progress-ring svg {
  width: 48px;
  height: 48px;
  transform: rotate(-90deg);
}

.upload-progress-ring .progress-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.1);
  stroke-width: 3;
}

.upload-progress-ring .progress-fg {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.15s ease;
}

.upload-progress-ring .progress-pct {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
}

/* ── Drag-and-drop ─────────────────────────────────── */

.drag-handle {
  display: inline-flex;
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  cursor: grab;
  opacity: 0.5;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.drag-handle:hover {
  opacity: 1;
  color: var(--text);
}

.profile-slot.dragging {
  opacity: 0.4;
}

.profile-slot.drag-over {
  background: rgba(59, 130, 246, 0.08);
}

/* ── Modal ───────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.15s;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 460px;
  max-width: 92vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.2s;
}

.modal.modal-wide {
  width: 640px;
}

.modal.modal-fullscreen {
  width: 96vw;
  max-width: 1400px;
  height: 90vh;
  max-height: 90vh;
}

.modal.modal-fullscreen .modal-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.modal.modal-rule {
  width: 94vw;
  max-width: 700px;
  height: 90vh;
  max-height: 90vh;
}

.modal.modal-rule .modal-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.modal.modal-rule .rm-form-inner {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 24px;
  flex: 1;
}

.modal.modal-rule .form-group label {
  font-size: 13px;
  margin-bottom: 2px;
}

.modal.modal-rule input[type="text"],
.modal.modal-rule select {
  height: 42px;
  font-size: 14px;
  padding: 8px 14px;
}

.modal.modal-rule .form-group.fg-expand {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.modal.modal-rule .form-group.fg-expand textarea {
  flex: 1;
}

.modal.modal-rule textarea {
  font-size: 14px;
  padding: 10px 14px;
  min-height: 80px;
  resize: vertical;
}

.modal.modal-rule .form-row {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal.modal-rule .modal-footer {
  padding: 16px 24px;
  gap: 12px;
}

.modal.modal-rule .modal-footer .btn {
  padding: 8px 24px;
  font-size: 14px;
}

@keyframes slideUp {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title {
  font-size: 15px;
  font-weight: 600;
}

.modal-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  border-radius: 6px;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-section {
  margin-bottom: 20px;
}

.modal-section:last-child { margin-bottom: 0; }

.modal-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 10px;
}

.modal-hint {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
  line-height: 1.4;
}

.auth-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.modal-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* ── Clients modal ───────────────────────────────────── */

.clients-modal-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 40px 0;
  color: var(--muted);
  font-size: 13px;
}

.clients-modal-empty {
  text-align: center;
  padding: 40px 0;
  color: var(--muted);
  font-size: 13px;
}

.cm-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.cm-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
}

.cm-stat-val {
  font: 600 18px/1 var(--mono);
  color: var(--accent);
}

.cm-stat-lbl {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.cm-filter-row {
  margin-bottom: 12px;
}

.cm-search {
  width: 100%;
}

.cm-table-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
}

.cm-table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
  font-size: 12px;
}

.cm-table th {
  position: sticky;
  top: 0;
  background: var(--surface);
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  z-index: 1;
}

.cm-table td {
  padding: 5px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  font-family: var(--mono);
  color: var(--text);
  vertical-align: middle;
  white-space: nowrap;
}

.cm-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.04);
}

.cm-col-host {
  font-family: var(--font);
  font-size: 11px;
  color: var(--text);
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cm-empty {
  color: rgba(255, 255, 255, 0.15);
}

.cm-proto {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  padding: 1px 5px;
  border-radius: 3px;
}

/* ── Responsive ──────────────────────────────────────── */

@media (max-width: 768px) {
  .workers-grid { grid-template-columns: 1fr; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
  .form-inline-row { grid-template-columns: 1fr; }
  .header { flex-direction: column; gap: 12px; align-items: flex-start; }
  .auth-fields.visible { grid-template-columns: 1fr; }
  .modal.modal-rule { width: 98vw; height: 95vh; max-height: 95vh; }
  .modal.modal-rule .rm-form-inner { padding: 16px; gap: 12px; }
  .profile-slots { flex-direction: column; }
}

/* ── Disabled rule ───────────────────────── */
.rule-card.rule-disabled {
  opacity: 0.45;
}
.rule-card.rule-disabled .rule-name {
  text-decoration: line-through;
  text-decoration-color: var(--muted);
}

/* ── Toggle button ───────────────────────── */
.btn-toggle {
  transition: color 0.15s;
}
.btn-toggle.toggle-on {
  color: #10b981;
}
.btn-toggle.toggle-off {
  color: var(--muted);
}
.btn-toggle:hover {
  color: #f59e0b;
}
