:root {
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bg: #eef1f6;
  --surface: #ffffff;
  --text: #1a1d26;
  --muted: #5c6370;
  --border: #e2e6ef;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 12px rgba(15, 23, 42, 0.06);
  --radius: 12px;
  --radius-lg: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

/* ----- Login ----- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 1.5rem;
}

.login-card .muted {
  margin-bottom: 20px;
}

/* ----- App shell ----- */
.app-wrap {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 20px 32px;
}

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

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

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 20px;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

.brand-name {
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

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

.header-freshness {
  font-size: 12px;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 640px) {
  .header-freshness {
    order: 3;
    width: 100%;
    max-width: none;
  }
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: #f8fafc;
  color: var(--text);
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  background: #f8fafc;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-primary-lg {
  padding: 10px 20px;
  border-radius: 10px;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
}

.btn-ghost {
  background: transparent;
}

.btn-danger-ghost {
  color: var(--bad);
  border-color: #fecaca;
  background: #fff;
}

.btn-danger-ghost:hover {
  background: #fef2f2;
}

/* Row actions: outline icons (как в RemnaWave) */
.actions-cell {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

/*
 * flex на <td> даёт браузерам неверную минимальную ширину колонки — кнопки переносятся 2×2.
 * Ячейка остаётся table-cell; один ряд — у внутреннего inline-flex.
 */
.clients-table td.actions-cell--table {
  display: table-cell;
  white-space: nowrap;
  vertical-align: middle;
  min-width: 11.75rem;
}

.clients-table thead th:last-child {
  min-width: 11.75rem;
}

.clients-table td.actions-cell--table .actions-cell-row {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
}

.btn-action {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #374151;
  background: var(--surface);
  box-shadow: none;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.btn-action:hover:not(:disabled) {
  background: #f9fafb;
  border-color: #9ca3af;
  color: #111827;
}

.btn-action:active:not(:disabled) {
  background: #f3f4f6;
}

.btn-action:disabled {
  opacity: 0.32;
  cursor: not-allowed;
  color: #9ca3af;
}

.btn-action-svg {
  display: block;
  flex-shrink: 0;
}

.btn-action-edit {
  width: 34px;
  min-width: 34px;
  padding: 0;
  gap: 0;
}

.btn-action-edit .btn-action-edit-label {
  display: none;
}

.btn-action-del {
  color: #b91c1c;
  border-color: #fecaca;
}

.btn-action-del:hover:not(:disabled) {
  color: #991b1b;
  border-color: #fca5a5;
  background: #fef2f2;
}

/* Stats */
.stats-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

@media (max-width: 1200px) {
  .stats-row {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 640px) {
  .stats-row {
    grid-template-columns: 1fr 1fr;
  }
}

.stat-card {
  --stat-accent: var(--primary);
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 118px;
  padding: 14px 16px 16px;
  border-radius: 14px;
  border: 1px solid rgba(226, 230, 239, 0.95);
  background: linear-gradient(165deg, #ffffff 0%, #f8fafc 55%, #f1f5f9 100%);
  box-shadow:
    0 1px 2px rgba(15, 23, 42, 0.04),
    0 6px 20px rgba(15, 23, 42, 0.06);
  overflow: hidden;
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--stat-accent);
  opacity: 0.88;
}

.stat-card__head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}

.stat-card__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1;
  flex-shrink: 0;
}

.stat-card--clients .stat-card__icon {
  color: #2563eb;
  background: rgba(37, 99, 235, 0.12);
}

.stat-card--online .stat-card__icon {
  font-size: 9px;
  color: var(--good);
  background: rgba(22, 163, 74, 0.14);
}

.stat-card--in .stat-card__icon {
  color: #4f46e5;
  background: rgba(79, 70, 229, 0.12);
}

.stat-card--out .stat-card__icon {
  color: #7c3aed;
  background: rgba(124, 58, 237, 0.12);
}

.stat-card--nodes .stat-card__icon {
  color: #d97706;
  background: rgba(217, 119, 6, 0.14);
}

.stat-card--sum .stat-card__icon {
  font-size: 12px;
  font-weight: 700;
  color: #0d9488;
  background: rgba(13, 148, 136, 0.12);
}

.stat-card__label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  line-height: 1.3;
}

.stat-card__grow {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 0;
  padding-top: 6px;
}

.stat-card__value {
  font-size: 1.625rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: #0f172a;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.stat-card__value--good {
  color: var(--good);
}

.stat-card__sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  margin-top: 6px;
  min-height: 1.35em;
  line-height: 1.35;
  letter-spacing: 0.01em;
}

.chart-block {
  margin-bottom: 16px;
}

.chart-block__hint {
  margin: -2px 0 12px;
  max-width: 72ch;
  line-height: 1.4;
}

.nodes-plates-title {
  margin: 20px 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.nodes-plates {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.node-plate {
  padding: 14px 16px;
  background: #f8fafc;
  border-radius: 12px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.node-plate-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.node-plate-flag {
  font-size: 1.35rem;
  line-height: 1;
  flex-shrink: 0;
}

.node-plate-name {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.3;
}

.node-plate-rows {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.node-plate-rows strong {
  color: var(--text);
  font-weight: 600;
}

.node-plate-load-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
}

.node-load {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.node-load--ok {
  color: #15803d;
}

.node-load--warn {
  color: #b45309;
}

.node-load--bad {
  color: #b91c1c;
}

.node-load--na {
  font-weight: 500;
}

.node-plate--load-warn {
  border-color: #fbbf24;
  box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.22);
}

.node-plate--load-bad {
  border-color: #fca5a5;
  background: #fffafa;
  box-shadow: 0 0 0 1px rgba(220, 38, 38, 0.18);
}

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

.panel-card h3 {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 600;
}

.chart-wrap {
  position: relative;
  height: 260px;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
}

.tab {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.tab:hover:not(:disabled) {
  background: #f1f5f9;
  color: var(--text);
}

.tab.active {
  background: #eff6ff;
  color: var(--primary);
  border-color: #bfdbfe;
}

.tab:disabled,
.tab.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.nodes-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.node-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: #f8fafc;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.node-row .name {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.node-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

/* Clients section */
.clients-section {
  padding: 0;
  overflow: hidden;
}

.clients-toolbar {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}

.clients-toolbar-inner {
  display: flex;
  align-items: center;
  gap: 20px;
  width: 100%;
  min-width: 0;
}

.clients-toolbar-rows {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  min-width: 0;
}

.filter-row--tags {
  min-width: 0;
}

.filter-toolbar-divider {
  width: 1px;
  height: 28px;
  background: var(--border);
  flex-shrink: 0;
}

.filter-chip-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.filter-chip-group--scroll {
  flex-wrap: nowrap;
  overflow-x: auto;
  min-width: 0;
  padding-bottom: 4px;
  margin-bottom: -4px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

/* Верхняя строка: гео забирает оставшееся место, скролл только при нехватке */
.filter-chip-group--geo {
  flex: 1 1 160px;
  max-width: 100%;
}

/* Теги — вся ширина блока слева, длинные названия не сжимаем */
.filter-chip-group--tags {
  width: 100%;
  max-width: 100%;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.25;
  flex-shrink: 0;
  transition: background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease, color 0.12s ease;
}

.filter-chip:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.filter-chip:focus-visible {
  outline: none;
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.filter-chip.is-active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 10px rgba(37, 99, 235, 0.35);
}

.filter-chip.is-active:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.filter-chip--icon-only {
  padding: 8px 12px;
  font-size: 1.15rem;
  line-height: 1;
}

.filter-chip-emoji {
  font-size: 1em;
  line-height: 1;
}

.filter-chip-tagdot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--tag-dot, #6c757d);
  flex-shrink: 0;
}

.filter-chip--tag.is-active .filter-chip-tagdot {
  background: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.45);
}

.clients-toolbar-search {
  flex-shrink: 0;
  width: min(280px, 34vw);
  min-width: 180px;
  align-self: center;
}

.clients-toolbar-search input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  background: var(--surface);
}

.clients-toolbar-search input:focus {
  outline: none;
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

@media (max-width: 720px) {
  .clients-toolbar-inner {
    flex-direction: column;
    align-items: stretch;
  }

  .clients-toolbar-search {
    width: 100%;
    max-width: none;
    align-self: stretch;
  }
}

.clients-table-wrap {
  overflow-x: auto;
}

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

.clients-table th {
  text-align: left;
  padding: 12px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.th-sort {
  background: none;
  border: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  padding: 0;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-transform: inherit;
  letter-spacing: inherit;
  max-width: 100%;
}

.th-sort:hover {
  color: var(--text);
}

.th-sort.is-active {
  color: var(--primary);
}

.th-sort .sort-ind {
  font-size: 9px;
  opacity: 0.55;
  line-height: 1;
}

.th-sort.is-active .sort-ind {
  opacity: 1;
}

.tag-chip {
  display: inline-block;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

.clients-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.clients-table tbody tr:hover {
  background: #fafbfc;
}

.clients-cards {
  display: none;
  flex-direction: column;
  gap: 12px;
  padding: 14px 18px 20px;
}

.client-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

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

.client-card-panel-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
  color: #111827;
}

.client-card-login {
  font-weight: 500;
  font-size: 15px;
  letter-spacing: -0.02em;
  color: #111827;
  margin-top: 3px;
  line-height: 1.35;
}

.client-card-dbname {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}

.client-card-meta {
  font-size: 11px;
  color: var(--muted);
  font-family: ui-monospace, monospace;
  margin-top: 4px;
}

.client-card-dl {
  margin: 0 0 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13px;
}

.client-card-dl dt {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 2px;
}

.client-card-dl dd {
  margin: 0;
  color: var(--text);
}

.client-card-actions {
  padding-top: 12px;
  border-top: 1px solid var(--border);
  margin: 0 -4px;
}

@media (max-width: 768px) {
  .clients-section .clients-table-wrap {
    display: none;
  }

  .clients-cards {
    display: flex;
  }
}

.client-cell-panel-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
  color: #111827;
}

/* Логин: тот же кегль и цвет, что у бывшей основной строки, без «жирного» заголовка */
.client-cell-login {
  font-weight: 500;
  font-size: 15px;
  letter-spacing: -0.02em;
  color: #111827;
  margin-top: 3px;
  line-height: 1.35;
}

.client-cell-dbname {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  font-weight: 500;
}

.client-cell-sub {
  font-size: 12px;
  color: #6b7280;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  margin-top: 3px;
}

.client-cell-traffic {
  font-size: 14px;
  font-weight: 700;
  color: #111827;
  letter-spacing: -0.01em;
}

.client-cell-term {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.client-cell-term--days {
  font-weight: 600;
  color: #15803d;
}

.server-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  padding: 3px 10px 3px 8px;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  background: #fafafa;
  color: #374151;
}

.server-badge.muted {
  color: var(--muted);
}

.server-last-hint {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-right: 2px;
}

.server-ico {
  font-size: 14px;
  opacity: 0.85;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.status-pill--online {
  color: #15803d;
}

.status-pill--offline {
  color: #b91c1c;
  font-weight: 600;
}

.status-pill--new {
  color: #0369a1;
  font-weight: 600;
}

/* Онлайн: ядро + расходящееся кольцо */
.status-dot {
  position: relative;
  width: 12px;
  height: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.status-dot__ping {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--good);
  opacity: 0.55;
  animation: status-ping 2s cubic-bezier(0.22, 1, 0.36, 1) infinite;
}

.status-pill--online .dot.good {
  position: relative;
  z-index: 1;
  width: 10px;
  height: 10px;
  background: #16a34a;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.95), 0 1px 4px rgba(22, 163, 74, 0.45);
}

@keyframes status-ping {
  0% {
    transform: scale(1);
    opacity: 0.55;
  }
  70% {
    transform: scale(2.35);
    opacity: 0;
  }
  100% {
    transform: scale(2.35);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .status-dot__ping {
    animation: none;
    opacity: 0;
  }

  .status-pill--online .dot.good {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.95);
  }
}

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

.dot.good {
  background: var(--good);
}

.dot.bad {
  background: var(--bad);
}

.dot.warn {
  background: var(--warn);
}

.dot.gray {
  background: #94a3b8;
}

.status-pill--offline .dot.gray,
.status-pill--new .dot.gray {
  width: 10px;
  height: 10px;
}

.status-pill--offline .dot.gray {
  background: #ef4444;
  box-shadow: 0 0 0 2px #b91c1c, 0 1px 3px rgba(185, 28, 28, 0.35);
}

.status-pill--new .dot.gray {
  background: #38bdf8;
  box-shadow: 0 0 0 2px #0284c7, 0 1px 3px rgba(2, 132, 199, 0.3);
}

.tag-pill {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  background: #eff6ff;
  color: var(--primary);
  margin-top: 4px;
}

.expire-field-block {
  min-width: 0;
}

.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}

.checkbox-inline input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.expire-hint {
  font-size: 12px;
  margin: 6px 0 8px;
  line-height: 1.45;
}

.expire-quick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.expire-quick-row .btn {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
}

/* Modal */
dialog.modal {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  max-width: 520px;
  width: calc(100% - 32px);
  box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.25);
  background: var(--surface);
  color: var(--text);
}

dialog.modal::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

dialog.modal.modal--raw {
  max-width: min(920px, calc(100vw - 24px));
  width: 100%;
}

dialog.modal.modal--wide {
  max-width: min(960px, calc(100vw - 24px));
  width: 100%;
}

.bot-settings-section .bot-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.bot-modal-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  align-items: center;
}

.bot-bc-list {
  font-size: 12px;
  line-height: 1.5;
  max-height: 220px;
  overflow: auto;
  padding: 8px 0;
}

.modal-raw-subtitle {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
}

.modal-raw-pre {
  margin: 0;
  padding: 14px 16px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.5;
  max-height: min(58vh, 520px);
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
  word-break: break-word;
  color: #1e293b;
}

.btn-action-raw {
  color: #4b5563;
}

.btn-action-raw:hover:not(:disabled) {
  color: #111827;
}

.modal-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-body {
  padding: 20px 22px 24px;
}

.modal-close {
  width: 36px;
  height: 36px;
  border: none;
  background: #f1f5f9;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
}

.modal-close:hover {
  background: #e2e8f0;
  color: var(--text);
}

label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin: 10px 0 4px;
}

input,
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
}

textarea {
  min-height: 72px;
  resize: vertical;
}

.formrow {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 520px) {
  .formrow {
    grid-template-columns: 1fr;
  }
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.alert {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 12px;
}

.alert.ok {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

.alert.err {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

code {
  font-size: 0.88em;
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
}

/* ----- Remnawave loading overlay ----- */
.rw-global-loader {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.rw-global-loader__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  pointer-events: auto;
}

.rw-global-loader__panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 28px 36px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.25);
  pointer-events: auto;
  max-width: 90vw;
}

.rw-global-loader__panel p {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.rw-global-loader__spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: rw-spin 0.75s linear infinite;
}

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