/* funnel-bots management UI — deliberately framework-free. */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1d2430;
  --muted: #6b7280;
  --border: #e3e6ea;
  --accent: #2563eb;
  --ok: #16a34a;
  --err: #dc2626;
  --warn: #b45309;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #eef1f4; border-radius: 4px; padding: 1px 5px; font-size: 12px; }
h1 { font-size: 22px; margin: 18px 0 8px; }
h2 { font-size: 16px; margin: 0 0 10px; }

.topbar {
  display: flex; align-items: center; gap: 18px;
  background: #101827; color: #e5e7eb; padding: 10px 20px;
}
.topbar .brand { color: #fff; font-weight: 700; font-size: 15px; }
.topbar nav { display: flex; gap: 14px; flex: 1; }
.topbar nav a { color: #cbd5e1; }
.topbar nav a.accent { color: #93c5fd; font-weight: 600; }
.logout-form { margin: 0; }

.botnav {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: #1f2937; color: #d1d5db; padding: 8px 20px; font-size: 13px;
}
.botnav a { color: #d1d5db; }
.botnav-name { margin-right: 8px; }

.container { max-width: 1180px; margin: 0 auto; padding: 12px 20px 48px; }

.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 16px; margin: 16px 0;
}
.panel-switch { display: flex; justify-content: space-between; align-items: center; gap: 16px; }

.cards { display: flex; gap: 12px; flex-wrap: wrap; margin: 16px 0; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 16px; min-width: 120px; text-align: center; color: var(--muted); font-size: 12px;
}
.card a { color: inherit; }
.card-num { display: block; font-size: 20px; font-weight: 700; color: var(--text); }

.table { width: 100%; border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { background: #f0f2f5; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-compact th, .table-compact td { padding: 4px 10px; }
.cell-html { max-width: 420px; overflow-wrap: anywhere; color: var(--muted); }
.actions { white-space: nowrap; }
.actions form { display: inline-block; margin: 0 0 0 6px; }

.badge {
  display: inline-block; border-radius: 10px; padding: 1px 9px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
}
.badge-on, .badge-active { background: #dcfce7; color: var(--ok); }
.badge-off, .badge-disabled { background: #e5e7eb; color: var(--muted); }
.badge-error { background: #fee2e2; color: var(--err); }
.status-detail { color: var(--err); font-size: 12px; max-width: 320px; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.tg-username { font-size: 13px; font-weight: 400; color: var(--muted); text-decoration: none; }
.tg-username:hover { text-decoration: underline; }
.hint { color: var(--muted); font-size: 13px; }

.flash { border-radius: 6px; padding: 9px 14px; margin: 12px 0; font-size: 13px; }
.flash-ok { background: #dcfce7; color: #14532d; }
.flash-err { background: #fee2e2; color: #7f1d1d; }
.flash-warn { background: #fef3c7; color: var(--warn); }

.form-grid { display: grid; gap: 12px; max-width: 640px; }
.form-grid label { display: grid; gap: 4px; font-weight: 600; font-size: 13px; }
.form-grid small { font-weight: 400; color: var(--muted); }
.form-grid input, .form-grid select, .form-grid textarea, .form-inline input, .form-inline select {
  font: inherit; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff;
}
.form-grid textarea { resize: vertical; font-family: ui-monospace, monospace; font-size: 13px; }
.form-inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.checkbox { flex-direction: row; display: flex !important; align-items: center; gap: 8px; }
.req { color: var(--err); }
.input-slim { font: inherit; padding: 3px 6px; border: 1px solid var(--border); border-radius: 4px; max-width: 130px; }
.input-slim.num { max-width: 64px; }

.btn {
  display: inline-block; font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); border-radius: 6px; background: #fff;
  color: var(--text); padding: 7px 14px;
}
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-go { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-go:hover { background: #15803d; }
.btn-danger { background: #fff; border-color: var(--err); color: var(--err); }
.btn-danger:hover { background: #fee2e2; }
.btn-small { padding: 3px 9px; font-size: 12px; }
.btn-big { padding: 12px 22px; font-size: 15px; }
.btn-ghost { background: transparent; border-color: transparent; color: inherit; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions-row { display: flex; gap: 10px; }

.kv { display: grid; gap: 4px; margin-bottom: 14px; font-size: 13px; }

.pagination { display: flex; gap: 12px; align-items: center; margin: 14px 0; }

.preview-pane {
  border: 1px dashed var(--border); border-radius: 8px; background: #fff;
  padding: 14px; min-height: 60px; white-space: pre-wrap; overflow-wrap: anywhere;
}

.login-body { display: grid; place-items: center; min-height: 100vh; background: #101827; }
.login-box {
  background: var(--panel); border-radius: 10px; padding: 28px 32px; width: 340px;
  display: grid; gap: 12px;
}
.login-box h1 { margin: 0; font-size: 18px; }
.login-box form { display: grid; gap: 10px; }
.login-box input { font: inherit; padding: 9px 12px; border: 1px solid var(--border); border-radius: 6px; }
.login-box label { font-size: 13px; font-weight: 600; }

/* --- markdown editor with live telegram preview (editor.js) --- */
.tg-editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 900px) { .tg-editor { grid-template-columns: 1fr; } }
.tg-editor-main { display: grid; gap: 6px; }
.tg-toolbar { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.tg-toolbar button {
  font: inherit; font-size: 12px; font-weight: 700; padding: 3px 9px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 6px; background: #fff; min-width: 30px;
}
.tg-toolbar button:hover { background: #eef2ff; }
.tg-toolbar .tg-mode { margin-left: auto; font-family: ui-monospace, monospace; }
.tg-toolbar .tg-mode-err { border-color: var(--err); color: var(--err); }
.tg-toolbar .tg-count { margin-left: 6px; }

.tg-preview { background: #8daabe; border-radius: 10px; padding: 18px 14px; display: grid; gap: 8px; justify-items: start; }
.tg-bubble {
  background: #fff; border-radius: 12px; border-bottom-left-radius: 4px; max-width: 420px;
  overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,.2); font-size: 14px; line-height: 1.35;
}
.tg-photo { display: block; width: 100%; max-height: 260px; object-fit: cover; }
.tg-media-note { padding: 8px 12px 0; font-size: 12px; color: var(--muted); }
.tg-text { padding: 8px 12px 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.tg-text blockquote { margin: 4px 0; padding: 2px 8px; border-left: 3px solid #3b82f6; background: #eff6ff; border-radius: 4px; }
.tg-text pre { background: #f3f4f6; border-radius: 6px; padding: 6px 8px; overflow-x: auto; }
.tg-text code { background: #f3f4f6; border-radius: 4px; padding: 0 3px; font-size: 13px; }
.tg-text tg-spoiler { background: #d1d5db; color: transparent; border-radius: 3px; }
.tg-text tg-spoiler:hover { color: inherit; background: #e5e7eb; }
.tg-inline-btn {
  background: rgba(255,255,255,.85); border-radius: 8px; padding: 7px 0; max-width: 420px; width: 100%;
  text-align: center; font-size: 13px; font-weight: 600; color: #2563eb; cursor: default;
}

/* --- feature cards (карточка бота → Фичи) --- */
.feature { border: 1px solid var(--border); border-radius: 8px; background: var(--panel); margin: 10px 0; }
.feature > summary { cursor: pointer; padding: 10px 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.feature > summary::-webkit-details-marker { display: none; }
.feature-body { padding: 4px 14px 14px; border-top: 1px solid var(--border); display: grid; gap: 10px; }
.feature-body p { margin: 6px 0 0; }
.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.checklist a { margin-left: 6px; }
.check-ok { color: var(--ok); }
.check-fail { color: var(--err); }
.check-opt { color: var(--muted); }
.feature-actions { margin-top: 4px; }
.items-editor { border: 1px dashed var(--border); border-radius: 6px; padding: 10px; display: grid; gap: 6px; }
.items-editor legend { font-weight: 600; font-size: 13px; padding: 0 4px; }
.items-row { display: flex; gap: 8px; }
.items-row select { max-width: 260px; }
.items-row input { flex: 1; }

/* --- контент: «Где используется» --- */
.cell-usage { max-width: 260px; }
.usage-tag { display: inline-block; background: #eef2ff; color: #3730a3; border-radius: 4px;
  padding: 1px 6px; margin: 1px 2px 1px 0; font-size: 12px; }
a.usage-tag { text-decoration: none; border: 1px solid transparent; }
a.usage-tag:hover { border-color: #3730a3; text-decoration: underline; }

/* --- пуши: таймлайн --- */
.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--border); }
.timeline-item { position: relative; padding: 8px 0 8px 14px; display: grid; gap: 2px; }
.timeline-item::before { content: ''; position: absolute; left: -23px; top: 16px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--accent); }
.timeline-broken::before { background: var(--err); }
.timeline-when { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.timeline-preview { color: var(--muted); font-size: 13px; max-width: 720px; overflow-wrap: anywhere; }

/* --- кнопки: превью клавиатуры --- */
.kb-preview { margin-bottom: 12px; }
.tg-reply-kb { background: rgba(255,255,255,.5); border-radius: 8px; padding: 6px; display: grid; gap: 4px;
  max-width: 420px; width: 100%; }
.tg-reply-btn { background: #fff; border-radius: 6px; padding: 7px 0; text-align: center; font-size: 13px;
  color: #111; box-shadow: 0 1px 1px rgba(0,0,0,.15); cursor: default; }

/* --- карточка бота: схема воронки --- */
.flow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0 10px; }
.flow-node { background: #eef2ff; color: #3730a3; border-radius: 6px; padding: 4px 10px; font-size: 13px; }
a.flow-node { text-decoration: none; }
a.flow-node:hover { text-decoration: underline; }
.flow-arrow { color: var(--muted); }
