/* ==========================================================================
   Design tokens
   ========================================================================== */
:root {
  --bg: #0F1720;
  --surface: #16212C;
  --surface-2: #1D2A37;
  --border: #263442;
  --text: #E6EDF3;
  --text-muted: #8B99A7;
  --accent: #35D399;      /* ok / connected */
  --accent-dim: #1F5C46;
  --warning: #F2B84B;
  --danger: #EF5F5F;
  --font-body: "Inter", -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  --radius: 10px;
}

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { font-family: var(--font-mono); font-weight: 600; letter-spacing: -0.01em; margin: 0 0 4px; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.06em; }

p { margin: 0 0 12px; color: var(--text-muted); }

/* ==========================================================================
   Layout
   ========================================================================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 15px;
}

.brand-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.topbar-right { display: flex; align-items: center; gap: 16px; font-size: 14px; color: var(--text-muted); }

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 28px 64px;
}

.container-wide {
  max-width: none;
  width: 100%;
}

.container-narrow {
  max-width: 460px;
  margin: 64px auto;
  padding: 0 20px;
}

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

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

/* ==========================================================================
   Forms
   ========================================================================== */
label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }

input[type="text"], input[type="password"], input[type="number"], input[type="date"], textarea, select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  margin-bottom: 14px;
  transition: border-color .15s ease;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

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

.field-hint { font-size: 12px; color: var(--text-muted); margin-top: -10px; margin-bottom: 14px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #06231A;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: opacity .15s ease;
}
.btn:hover { opacity: 0.88; }
.btn:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #2A0A0A; }
.btn-warning { background: var(--warning); color: #2A1B00; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ==========================================================================
   Badges & status
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  white-space: nowrap;
}
.badge-ok { background: rgba(53,211,153,0.12); color: var(--accent); }
.badge-warning { background: rgba(242,184,75,0.14); color: var(--warning); }
.badge-danger { background: rgba(239,95,95,0.14); color: var(--danger); }
.badge-neutral { background: rgba(139,153,167,0.12); color: var(--text-muted); }

/* Сплошные варианты — для отметок, которые должны быть заметны сразу */
.badge-solid-danger { background: var(--danger); color: #2A0A0A; }
.badge-solid-warning { background: var(--warning); color: #2A1B00; }
.badge-solid-neutral { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }

.dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.dot-ok { background: var(--accent); }
.dot-warning { background: var(--warning); }
.dot-danger { background: var(--danger); animation: pulse 1.6s infinite; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(239,95,95,0.55); }
  70% { box-shadow: 0 0 0 6px rgba(239,95,95,0); }
  100% { box-shadow: 0 0 0 0 rgba(239,95,95,0); }
}
@media (prefers-reduced-motion: reduce) {
  .dot-danger { animation: none; }
}

/* ==========================================================================
   Alerts / flash messages
   ========================================================================== */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.flash-success { background: rgba(53,211,153,0.1); border: 1px solid var(--accent-dim); color: var(--accent); }
.flash-error { background: rgba(239,95,95,0.1); border: 1px solid rgba(239,95,95,0.4); color: var(--danger); }

.banner {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
}
.banner-danger { background: rgba(239,95,95,0.08); border: 1px solid rgba(239,95,95,0.35); }
.banner-warning { background: rgba(242,184,75,0.08); border: 1px solid rgba(242,184,75,0.35); }
.banner-icon { font-family: var(--font-mono); font-size: 18px; line-height: 1; margin-top: 1px; }

/* ==========================================================================
   Table
   ========================================================================== */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding: 10px 8px;
  white-space: nowrap;
}
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:hover td { background: rgba(255,255,255,0.015); }
.table-wrap { overflow-x: auto; }

.mono { font-family: var(--font-mono); }
.text-muted { color: var(--text-muted); }
.small { font-size: 12.5px; }

.tabs { display: flex; gap: 6px; margin-bottom: 20px; flex-wrap: wrap; }
.tab {
  font-family: var(--font-mono);
  font-size: 12.5px;
  padding: 7px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--surface-2);
}
.tab.active { background: var(--accent); color: #06231A; border-color: var(--accent); font-weight: 600; }

.stat-row { display: flex; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  min-width: 120px;
}
.stat .num { font-family: var(--font-mono); font-size: 24px; font-weight: 600; }
.stat .label { font-size: 12px; color: var(--text-muted); }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.link-muted { color: var(--text-muted); font-size: 13px; }
.top-link { margin-bottom: 18px; display: inline-block; }

/* ==========================================================================
   Tag editor (списки конфигов / тегов)
   ========================================================================== */
.tag-editor { margin-bottom: 14px; }

.tag-editor-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 32px;
  padding: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  border-bottom: none;
}

.tag-editor-empty { font-size: 12.5px; color: var(--text-muted); padding: 4px 2px; }

.tag-editor-input { border-radius: 0 0 8px 8px; margin-bottom: 0; }

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 6px 4px 12px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text);
}

.tag-pill-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0 6px;
}
.tag-pill-remove:hover { color: var(--danger); }

/* Статичные (не редактируемые) пилюли — для просмотра конфигов/тегов */
.pill-list { display: flex; flex-wrap: wrap; gap: 6px; }

.pill-static {
  display: inline-flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  transition: outline-color .15s ease;
  outline: 2px solid transparent;
  outline-offset: 1px;
}
.pill-static.pill-copyable { cursor: pointer; }
.pill-static.pill-copied { outline-color: var(--accent); }

.pill-tag { background: rgba(53,211,153,0.10); border-color: var(--accent-dim); color: var(--accent); }

/* ==========================================================================
   Chat widget
   ========================================================================== */
.chat-widget { display: flex; flex-direction: column; }

.chat-log {
  max-height: 320px;
  min-height: 120px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 4px 14px;
  margin-bottom: 12px;
}

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

.chat-msg {
  max-width: 78%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.4;
  word-break: break-word;
}
.chat-msg-body { white-space: pre-wrap; }
.chat-msg-time { font-size: 10.5px; color: var(--text-muted); margin-top: 4px; text-align: right; }

.chat-msg-other {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
}
.chat-msg-self {
  align-self: flex-end;
  background: rgba(53,211,153,0.14);
  border: 1px solid var(--accent-dim);
  border-bottom-right-radius: 2px;
}

.chat-form { display: flex; gap: 8px; }
.chat-form .chat-input { flex: 1; margin-bottom: 0; }

/* ==========================================================================
   Файловые пилюли-ссылки
   ========================================================================== */
.pill-file {
  text-decoration: none;
  cursor: pointer;
  color: var(--text);
}
.pill-file:hover { text-decoration: none; border-color: var(--accent-dim); color: var(--accent); }

input[type="file"] {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 13px;
}

/* ==========================================================================
   Toast-уведомление (новое сообщение в чате)
   ========================================================================== */
.toast {
  position: fixed;
  top: 16px;
  right: 16px;
  max-width: 320px;
  background: var(--surface);
  border: 1px solid var(--accent-dim);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 1000;
}
.toast-visible { opacity: 1; transform: translateY(0); }

/* ==========================================================================
   Вложения в чате
   ========================================================================== */
.chat-file-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  transition: border-color .15s ease;
}
.chat-file-label:hover { border-color: var(--accent-dim); }

.chat-file-name {
  font-size: 12px;
  color: var(--text-muted);
  margin: -4px 0 8px;
  min-height: 14px;
}

.chat-attachment-image-link { display: inline-block; margin-top: 4px; }
.chat-attachment-image {
  max-width: 220px;
  max-height: 220px;
  border-radius: 8px;
  display: block;
  border: 1px solid var(--border);
}

.chat-attachment-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding: 6px 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text);
  text-decoration: none;
}
.chat-attachment-file:hover { border-color: var(--accent-dim); text-decoration: none; }
.chat-attachment-size { color: var(--text-muted); font-size: 11px; }
