:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --border: #262b35;
  --text: #e6e8ec;
  --muted: #8a93a3;
  --accent: #4f8cff;
  --accent-hover: #3a78f0;
  --success: #2ecc71;
  --warn: #f5a623;
  --danger: #ff5c5c;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

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

.logo {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #4f8cff, #6c5cff);
  border-radius: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  font-size: 14px;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.2px;
}

.subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.layout {
  max-width: 880px;
  margin: 28px auto 80px;
  padding: 0 24px;
  display: grid;
  gap: 22px;
}

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

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

.card-head h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0.2px;
}

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

.small {
  font-size: 13px;
}

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

.stack {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.row {
  display: grid;
  gap: 6px;
}

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

.row-inline {
  display: flex;
  gap: 10px;
}

.row-inline input {
  flex: 1;
}

input[type="text"], input[type="tel"], input[type="password"], input[type="number"] {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.18);
}

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s;
}

.btn:hover {
  background: #262b35;
  border-color: #323845;
}

.btn:active {
  transform: translateY(1px);
}

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

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

.btn-danger {
  background: transparent;
  border-color: rgba(255, 92, 92, 0.4);
  color: var(--danger);
}

.btn-danger:hover {
  background: rgba(255, 92, 92, 0.1);
  border-color: var(--danger);
}

.pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
}

.pill-muted { color: var(--muted); }
.pill-success { color: #fff; background: rgba(46, 204, 113, 0.18); border-color: rgba(46, 204, 113, 0.4); }
.pill-warn { color: #fff; background: rgba(245, 166, 35, 0.18); border-color: rgba(245, 166, 35, 0.4); }
.pill-danger { color: #fff; background: rgba(255, 92, 92, 0.18); border-color: rgba(255, 92, 92, 0.4); }

.hidden { display: none !important; }

.toast {
  min-height: 22px;
  padding: 0 14px;
  border-radius: 8px;
  font-size: 13px;
  display: flex;
  align-items: center;
  opacity: 0;
  transition: opacity 0.2s ease;
  border: 1px solid transparent;
  max-width: 380px;
}

.toast.show { opacity: 1; }
.toast.success { background: rgba(46, 204, 113, 0.15); border-color: rgba(46, 204, 113, 0.4); }
.toast.error { background: rgba(255, 92, 92, 0.15); border-color: rgba(255, 92, 92, 0.4); }
.toast.info { background: rgba(79, 140, 255, 0.12); border-color: rgba(79, 140, 255, 0.35); }

.help-card ul {
  margin: 12px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.help-card li strong {
  color: var(--text);
}

code {
  background: var(--panel-2);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
}

/* ============================== System health ============================== */

.health-grid {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.health-section-title {
  margin: 8px 0 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  font-weight: 600;
}

.health-cells {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}

.health-cell {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.health-cell-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.health-cell-label {
  font-size: 13px;
  font-weight: 600;
}

.health-cell-detail {
  font-size: 11px;
  color: var(--muted);
  word-break: break-word;
  line-height: 1.4;
}

/* ============================== Dialogs table ============================== */

.dialogs-wrap {
  margin-top: 14px;
  overflow-x: auto;
}

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

.dialogs-table th,
.dialogs-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.dialogs-table th {
  font-weight: 600;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--panel-2);
}

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

.dialog-name {
  font-weight: 600;
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  white-space: nowrap;
}

.row-actions .btn {
  padding: 6px 10px;
  font-size: 12px;
}

.dialogs-table input[type="text"] {
  padding: 6px 10px;
  font-size: 13px;
  width: 100%;
  min-width: 160px;
}

/* ============================== Toggle switch ============================== */

.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.switch .slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  top: 2px;
  background: var(--muted);
  border-radius: 50%;
  transition: transform 0.15s ease, background 0.15s ease;
}

.switch input:checked + .slider {
  background: rgba(46, 204, 113, 0.25);
  border-color: rgba(46, 204, 113, 0.5);
}

.switch input:checked + .slider::before {
  transform: translateX(16px);
  background: var(--success);
}

.switch input:focus-visible + .slider {
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.18);
}

/* ============================== Recipients cell ============================== */

.recipients-cell {
  min-width: 180px;
}
.recipients-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.pill.pill-soft {
  background: rgba(79, 140, 255, 0.12);
  border-color: rgba(79, 140, 255, 0.35);
  color: #cfe0ff;
}

.btn-link {
  background: transparent;
  border: none;
  color: #7aa6ff;
  padding: 2px 0;
  font-size: 0.85em;
  cursor: pointer;
  text-decoration: underline;
}
.btn-link:hover { color: #aac6ff; }

/* ============================== Modal ============================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-backdrop.hidden { display: none; }

.modal-panel {
  background: var(--card-bg, #1d2230);
  color: inherit;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  width: min(520px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 18px 20px 16px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.modal-head h3 { margin: 0; font-size: 1.1rem; }

.modal-close {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 6px;
  opacity: 0.65;
}
.modal-close:hover { opacity: 1; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}
