:root {
  --bg: #0f1220; --panel: #171a2b; --panel2: #1d2136; --line: #262b45;
  --text: #e8eaf5; --muted: #8a90a8; --accent: #6c8cff; --accent2: #29e0c8;
  --danger: #e0466b;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "Segoe UI", Roboto, Inter, sans-serif; color: var(--text);
  background: radial-gradient(1100px 600px at 15% -10%, #1b2140 0%, transparent 55%), var(--bg); min-height: 100vh; }
.editor, .sidebar, .leads-wrap { box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Логин */
.login-body { display: grid; place-items: center; min-height: 100vh;
  background: radial-gradient(900px 600px at 50% -10%, #1b2140, var(--bg)); }
.login-card { width: min(360px, 92vw); background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 32px 28px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.45); }
.login-logo { font-size: 40px; }
.login-card h1 { margin: 8px 0 2px; font-size: 22px; }
.login-form { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; }

.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.topbar .account { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 13px; }
.balance { background: linear-gradient(135deg, #1c8f81, #29e0c8); color: #06231f; font-weight: 700;
  padding: 6px 12px; border-radius: 20px; }
.balance.low { background: linear-gradient(135deg, #7a2f42, #e0466b); color: #fff; }
.brand { font-weight: 700; }
.brand span { color: var(--muted); font-weight: 400; font-size: 13px; }
.tabs { display: flex; gap: 6px; }
.tab { background: transparent; border: 0; color: var(--muted); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.tab.active { background: var(--panel2); color: var(--text); }
.topbar .status { margin-left: auto; font-size: 12px; color: var(--muted); }

.layout { display: grid; grid-template-columns: 280px 1fr; gap: 20px; padding: 20px; align-items: start; }
.sidebar { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.agent-list { list-style: none; margin: 14px 0 0; padding: 0; }
.agent-list li {
  padding: 10px 12px; border-radius: 9px; cursor: pointer; margin-bottom: 4px;
  border: 1px solid transparent;
}
.agent-list li:hover { background: var(--panel2); }
.agent-list li.active { background: var(--panel2); border-color: var(--accent); }
.agent-list li small { display: block; color: var(--muted); font-size: 11px; }

.editor { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; min-height: 60vh; }
.editor-head { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.agent-name { flex: 1; font-size: 20px; font-weight: 700; background: transparent; border: 0; border-bottom: 1px solid var(--line); color: var(--text); padding: 6px 2px; }
.agent-name:focus { outline: none; border-color: var(--accent); }
.editor-actions { display: flex; gap: 8px; }
.save-hint { min-height: 18px; font-size: 13px; color: var(--accent2); margin-bottom: 10px; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin: 0; }
fieldset.wide { grid-column: 1 / -1; }
legend { color: var(--muted); font-size: 12px; padding: 0 6px; text-transform: uppercase; letter-spacing: .04em; }
label { display: block; font-size: 13px; margin: 10px 0; color: var(--text); }
input, select, textarea {
  width: 100%; margin-top: 5px; background: var(--panel2); border: 1px solid var(--line);
  color: var(--text); border-radius: 9px; padding: 9px 11px; font-size: 14px; font-family: inherit;
}
input[type="range"] { padding: 0; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; }
textarea.embed { font-family: ui-monospace, monospace; font-size: 12px; color: var(--accent2); }

label.check { display: flex; align-items: center; gap: 8px; }
label.check input { width: auto; margin: 0; }
.avatar-row { display: flex; gap: 18px; align-items: flex-start; }
.avatar-preview { width: 96px; height: 96px; border-radius: 50%; background: var(--panel2);
  border: 1px solid var(--line); background-size: cover; background-position: center;
  display: grid; place-items: center; color: var(--muted); font-size: 11px; flex-shrink: 0; }
.avatar-controls { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.avatar-hint { font-size: 12px; color: var(--accent2); min-height: 16px; }
.avatar-row .row { display: flex; gap: 8px; }
.avatar-row .row input:not([type=file]) { flex: 1; }

.tools label { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.tools input { width: auto; margin: 0; }
.tools .tname { font-weight: 600; }
.tools .tdesc { color: var(--muted); font-size: 12px; }

.btn { background: var(--panel2); border: 1px solid var(--line); color: var(--text); padding: 9px 14px; border-radius: 9px; cursor: pointer; font-size: 14px; text-decoration: none; display: inline-block; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }

/* База знаний */
.kb { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 8px; }
.kb .row { display: flex; gap: 8px; align-items: center; }
.kb .row input[type="file"] { flex: 1; }
.kb-hint { min-height: 18px; font-size: 12px; color: var(--accent2); margin-top: 8px; }
.kb-paste { margin-top: 12px; }
.kb-paste summary { cursor: pointer; }
.kb-list { list-style: none; margin: 8px 0 0; padding: 0; }
.kb-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; background: var(--panel2); border-radius: 9px; margin-bottom: 6px; font-size: 13px; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.row-actions { display: flex; gap: 6px; }

.leads-wrap { grid-column: 1 / -1; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; }
.leads-table { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 14px; }
.leads-table th, .leads-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.leads-table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.badge { padding: 2px 8px; border-radius: 20px; font-size: 11px; }
.badge.lead { background: #23314f; color: #9bb3ff; }
.badge.callback { background: #2a2440; color: #c9a7ff; }

/* Конструктор виджета */
.wbuilder { display: grid; grid-template-columns: 1fr 320px; gap: 18px; align-items: start; }
.wbuilder-form { display: flex; flex-direction: column; gap: 14px; }
.wbuilder-form .row { display: flex; gap: 8px; }
.wbuilder-form .row input:not([type=file]) { flex: 1; }
.wpreview-wrap { position: sticky; top: 78px; display: flex; flex-direction: column; gap: 8px; }
.wpreview { background: radial-gradient(400px 300px at 50% 0%, #26306a, #0b0e1a); border: 1px solid var(--line);
  border-radius: 16px; padding: 20px; display: flex; place-items: center; min-height: 340px; }
/* Превью виджета — как на сайте: прозрачно, без рамки. */
.wprev-card { background: none; border: 0; padding: 0; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 8px; transition: all .12s; }
.wprev-title { font-size: 15px; font-weight: 700; margin-bottom: 2px; }
.wprev-sub { font-size: 11px; color: var(--muted); margin-bottom: 12px; }
.wprev-orb { width: 74px; height: 74px; border-radius: 50%; margin: 6px auto 14px;
  background: radial-gradient(circle at 32% 28%, var(--accent), #34407f); background-size: cover; background-position: center;
  box-shadow: 0 8px 24px rgba(108,140,255,.4); display: grid; place-items: center; flex-shrink: 0; }
.wprev-card.bubble .wprev-orb { margin: 0; }
.wprev-orb span { font-size: 12px; font-weight: 700; color: #fff; text-shadow: 0 1px 4px rgba(0,0,0,.6); padding: 0 6px; }
.wprev-btn { padding: 9px 14px; border-radius: 11px; color: #fff; font-size: 13px; font-weight: 700; margin-top: 4px;
  background: linear-gradient(135deg, var(--accent), #8a6cff); }
.wprev-status { font-size: 10.5px; color: var(--muted); margin-top: 8px; }

/* Клиенты (супер-админ) */
.new-client { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; align-items: center; }
.new-client input { width: auto; flex: 1; min-width: 120px; margin: 0; }
.nc-hint { min-height: 18px; font-size: 13px; color: var(--accent2); margin-bottom: 8px; }

/* Статистика */
.stats { display: flex; gap: 12px; flex-wrap: wrap; margin: 14px 0; }
.tile { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; min-width: 110px; }
.tile b { display: block; font-size: 24px; }
.tile span { color: var(--muted); font-size: 12px; }

/* Модалка / Playground */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 100; }
.modal-box { width: min(560px, 94vw); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.pg-chat { height: 360px; overflow-y: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 10px 0; display: flex; flex-direction: column; gap: 8px; }
.pg-msg { padding: 8px 12px; border-radius: 10px; max-width: 85%; font-size: 14px; line-height: 1.4; white-space: pre-wrap; }
.pg-msg.user { background: var(--accent); color: #fff; align-self: flex-end; }
.pg-msg.assistant { background: var(--panel2); align-self: flex-start; }
.pg-tool { font-size: 12px; color: var(--muted); background: #2a2440; border-radius: 8px; padding: 6px 10px; align-self: center; max-width: 95%; }
.pg-input { display: flex; gap: 8px; }
.pg-input input { flex: 1; margin: 0; }

/* Значок «?» с пояснением к настройке (подсказка по наведению). */
.help {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; margin-left: 6px; vertical-align: middle;
  border-radius: 50%; background: #2a3550; color: #9fb0d0;
  font-size: 11px; font-weight: 700; cursor: help; user-select: none;
}
.help:hover { background: #3a4a70; color: #fff; }

/* Карточка туннеля виджета ElevenLabs */
.tunnel-card {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; margin-bottom: 12px;
}
.tunnel-card .editor-head { margin-bottom: 10px; align-items: baseline; }
.tunnel-card textarea {
  width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 12px;
  line-height: 1.5; resize: vertical; margin-bottom: 10px;
}
.tunnel-card .editor-actions { display: flex; gap: 8px; }
