@import url("https://fonts.googleapis.com/css2?family=DM+Sans:ital,wght@0,400;0,500;0,700;1,400&family=JetBrains+Mono:wght@400;500&display=swap");

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

body {
  font-family: "DM Sans", system-ui, sans-serif;
  background: #f9fafb;
  color: #1f2937;
  min-height: 100vh;
  padding: 24px;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 720px;
  margin: 0 auto;
}

/* ── Header ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  padding-bottom: 16px;
  border-bottom: 1px solid #e5e7eb;
}

.page-header h1 {
  font-family: "JetBrains Mono", monospace;
  font-size: 18px;
  font-weight: 600;
  color: #111827;
  letter-spacing: -0.4px;
}

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

.status-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
}

.status-indicator.error {
  background: #ef4444;
}

.status-label {
  font-size: 12px;
  color: #9ca3af;
}

.badge {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  font-weight: 500;
  color: #6b7280;
  background: #f3f4f6;
  padding: 3px 8px;
  border-radius: 6px;
}

.badge:empty {
  display: none;
}

/* ── Cards ── */
.card {
  background: #ffffff;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  margin-bottom: 12px;
  overflow: hidden;
}

.card-header {
  padding: 16px 20px 0;
}

.card-header h2 {
  font-family: "JetBrains Mono", monospace;
  font-size: 14px;
  font-weight: 600;
  color: #111827;
}

.card-body {
  padding: 16px 20px;
}

.card-compact .card-body {
  padding: 14px 20px;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.hint {
  font-size: 13px;
  color: #9ca3af;
  margin-bottom: 14px;
}

/* ── Bot Bar ── */
.bot-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 12px;
}

.bot-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bot-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #ffffff;
  font-family: "JetBrains Mono", monospace;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.bot-name {
  font-size: 14px;
  font-weight: 600;
  color: #111827;
  line-height: 1.2;
}

.bot-mode {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  color: #9ca3af;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-top: 2px;
}

.bot-actions {
  display: flex;
  gap: 4px;
}

/* ── Inputs ── */
.input-row {
  display: flex;
  gap: 8px;
}

.input-row input[type="text"] {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  color: #111827;
  outline: none;
  transition: border-color 0.2s ease;
}

.input-row input[type="text"]:focus {
  border-color: #3b82f6;
}

/* ── Buttons ── */
.btn-primary {
  padding: 8px 14px;
  background: #ffffff;
  color: #374151;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-family: "DM Sans", sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-primary:hover {
  border-color: #3b82f6;
  color: #111827;
  background: rgba(59, 130, 246, 0.06);
}

.btn-primary:active {
  transform: scale(0.97);
}

.btn-primary:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.btn-ghost {
  padding: 6px 10px;
  background: transparent;
  color: #6b7280;
  border: none;
  border-radius: 6px;
  font-family: "DM Sans", sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-ghost:hover {
  background: #f3f4f6;
  color: #111827;
}

.btn-ghost-danger:hover {
  background: rgba(239, 68, 68, 0.08);
  color: #ef4444;
}

/* ── Toggle Switch ── */
.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

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

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #d1d5db;
  border-radius: 11px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  bottom: 3px;
  background: #ffffff;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.toggle input:checked + .toggle-slider {
  background: #22c55e;
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(18px);
}

/* ── Settings Row ── */
.setting-label {
  font-size: 13px;
  font-weight: 500;
  color: #374151;
}

.setting-desc {
  font-size: 12px;
  color: #9ca3af;
  margin-top: 2px;
}

/* ── Help Blocks ── */
.help-block {
  margin-bottom: 12px;
}

.help-block summary {
  padding: 10px 0;
  font-size: 12px;
  font-weight: 500;
  color: #9ca3af;
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color 0.15s ease;
}

.help-block summary::before {
  content: "?";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid #d1d5db;
  font-size: 10px;
  color: #9ca3af;
  flex-shrink: 0;
}

.help-block[open] summary::before {
  content: "-";
}

.help-block summary::-webkit-details-marker {
  display: none;
}

.help-block summary:hover {
  color: #6b7280;
}

.help-block ol {
  padding: 4px 0 8px 28px;
  font-size: 13px;
  color: #6b7280;
  line-height: 1.8;
}

.help-block ol li strong {
  color: #374151;
  font-weight: 500;
}

/* ── Table ── */
.table-wrap {
  background: #ffffff;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  word-break: break-word;
}

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

thead th {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #9ca3af;
  background: #fafafa;
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
  user-select: none;
}

tbody tr {
  transition: background 0.15s ease;
  animation: rowIn 0.2s ease both;
}

tbody tr:hover {
  background: #fafafa;
}

tbody td {
  padding: 10px 16px;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

.col-id {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  color: #9ca3af;
  width: 120px;
}

.col-name {
  color: #111827;
  font-weight: 500;
}

/* ── Bitrix24 field ── */
.bx-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 180px;
}

.user-field {
  display: none;
}

.bx-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px dashed #d1d5db;
  background: transparent;
  color: #6b7280;
  font-family: "DM Sans", sans-serif;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
  min-width: 120px;
}

.bx-trigger:hover {
  border-color: #3b82f6;
  color: #111827;
  background: rgba(59, 130, 246, 0.04);
}

.bx-trigger.linked {
  border-style: solid;
  border-color: #22c55e;
  color: #16a34a;
  background: rgba(34, 197, 94, 0.06);
}

.bx-trigger .icon {
  font-size: 13px;
  line-height: 1;
}

.btn-unlink {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #d1d5db;
  cursor: pointer;
  font-size: 11px;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.btn-unlink:hover {
  background: rgba(239, 68, 68, 0.08);
  color: #ef4444;
}

.th-actions {
  text-align: right;
  width: 40px;
}

.btn-refresh {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #ffffff;
  color: #6b7280;
  cursor: pointer;
  font-family: "DM Sans", sans-serif;
  font-size: 11px;
  font-weight: 500;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-refresh:hover {
  border-color: #3b82f6;
  color: #3b82f6;
  background: rgba(59, 130, 246, 0.04);
}

.btn-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #d1d5db;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s ease;
}

.btn-delete:hover {
  background: rgba(239, 68, 68, 0.08);
  color: #ef4444;
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: #9ca3af;
  font-size: 13px;
}

/* ── Loading ── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: #9ca3af;
  font-size: 13px;
  gap: 8px;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #e5e7eb;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 13px;
  color: #111827;
  box-shadow: 0 5px 22px rgba(0, 0, 0, 0.08);
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 100;
}

.toast.visible {
  transform: translateY(0);
  opacity: 1;
}

.toast.error {
  border-color: #fca5a5;
  color: #b91c1c;
}

/* ── Row entrance ── */
@keyframes rowIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
