* { box-sizing: border-box; }
:root {
  --bg: #0f1115; --panel: #181b22; --panel2: #1f232c; --line: #2a2f3a;
  --txt: #e6e8ec; --mut: #8b93a3; --acc: #4f7cff; --danger: #e5484d; --ok: #3fb950;
}
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--txt); font: 14px/1.5 system-ui, -apple-system, sans-serif; }
.hidden { display: none !important; }
code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* login */
.login { display: flex; align-items: center; justify-content: center; height: 100%; }
.login-box { background: var(--panel); padding: 36px; border-radius: 14px; width: 320px; border: 1px solid var(--line); text-align: center; }
.login-box h1 { margin: 0 0 4px; }
.login-box p { color: var(--mut); margin: 0 0 20px; }
.login-box input, .login-box button { width: 100%; padding: 11px 14px; border-radius: 8px; margin-top: 10px; font-size: 14px; }
.login-box input { background: var(--panel2); border: 1px solid var(--line); color: var(--txt); }
.login-box button { background: var(--acc); border: 0; color: #fff; cursor: pointer; font-weight: 600; }
.err { color: var(--danger); margin-top: 10px; min-height: 18px; }

/* layout */
.app { display: flex; height: 100vh; }
.sidebar { width: 260px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 16px; overflow: hidden; transition: width .2s ease, padding .2s ease; }
.sb-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.sb-toggle { padding: 6px 10px; }
.app.sb-collapsed .sidebar { width: 52px; padding: 12px 8px; }
.app.sb-collapsed .sidebar .brand { display: none; }
.app.sb-collapsed .sidebar #newBtn { display: none; }
.app.sb-collapsed .sidebar #list { display: none; }
.app.sb-collapsed .sidebar #logout { display: none; }
.app.sb-collapsed .sb-head { margin-bottom: 0; justify-content: center; }
.brand { font-weight: 700; font-size: 18px; margin-bottom: 0; }
.list { list-style: none; padding: 0; margin: 12px 0; flex: 1; overflow: auto; }
.list li { padding: 10px 12px; border-radius: 8px; cursor: pointer; display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.list li:hover { background: var(--panel2); }
.list li.active { background: var(--acc); }
.list li .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mut); flex: none; }
.list li.on .dot { background: var(--ok); }
.list li .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; overflow: auto; overflow-x: hidden; }
.empty { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--mut); }
.editor { padding: 20px 28px; max-width: 1400px; }
.editor-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.name-input { background: var(--panel2); border: 1px solid var(--line); color: var(--txt); padding: 9px 12px; border-radius: 8px; font-size: 15px; min-width: 220px; }
.spacer { flex: 1; }
.switch { display: flex; align-items: center; gap: 6px; color: var(--mut); }

/* buttons */
.btn { background: var(--panel2); border: 1px solid var(--line); color: var(--txt); padding: 9px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.btn:hover { border-color: var(--acc); }
.btn.primary { background: var(--acc); border-color: var(--acc); color: #fff; font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }

/* tabs */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tab { background: 0; border: 0; color: var(--mut); padding: 10px 16px; cursor: pointer; border-bottom: 2px solid transparent; font-size: 14px; }
.tab.active { color: var(--txt); border-bottom-color: var(--acc); }

/* fields */
.fld { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; color: var(--mut); font-size: 13px; }
.fld.checkbox { flex-direction: row; align-items: center; color: var(--txt); }
.fld input, .fld select, .fld textarea { background: var(--panel2); border: 1px solid var(--line); color: var(--txt); padding: 9px 12px; border-radius: 8px; font-size: 14px; }
.fld input[type=checkbox] { width: auto; }
textarea.code { font-family: ui-monospace, Menlo, monospace; min-height: 180px; resize: vertical; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.hint { color: var(--mut); font-size: 12px; }

/* rules */
.rules { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.rule { display: flex; gap: 8px; align-items: center; }
.rule select, .rule input { background: var(--panel2); border: 1px solid var(--line); color: var(--txt); padding: 8px 10px; border-radius: 8px; }
.rule .field { width: 150px; } .rule .op { width: 150px; } .rule .val { flex: 1; }
.rule .rm { background: 0; border: 0; color: var(--danger); cursor: pointer; font-size: 18px; }
.presets { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 14px 0; color: var(--mut); }
.chip { background: var(--panel2); border: 1px solid var(--line); color: var(--txt); padding: 5px 11px; border-radius: 20px; cursor: pointer; font-size: 12px; }
.chip:hover { border-color: var(--acc); }

.preview-frame { width: 100%; height: calc(100vh - 220px); min-height: 520px; border: 1px solid var(--line); border-radius: 10px; margin-top: 14px; background: #fff; }

/* ── визуальный конструктор ── */
.bld-toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 14px; }
.bld-tb-label { color: var(--mut); font-size: 13px; margin-right: 4px; }
.bld-add { background: var(--panel2); border: 1px solid var(--line); color: var(--txt); padding: 6px 11px; border-radius: 20px; cursor: pointer; font-size: 12px; }
.bld-add:hover { border-color: var(--acc); }
.bld-add.accent { background: var(--acc); border-color: var(--acc); color: #fff; font-weight: 600; }

/* ── шаблоны ── */
.tpl-modal { width: 860px; max-width: 94vw; max-height: 88vh; display: flex; flex-direction: column; }
.tpl-modal-head { display: flex; align-items: center; justify-content: space-between; }
.tpl-grid { overflow: auto; margin-top: 12px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.tpl-section { grid-column: 1 / -1; font-weight: 600; color: var(--mut); font-size: 13px; margin: 6px 0 0; padding-top: 8px; border-top: 1px solid var(--line); }
.tpl-card { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.tpl-thumb { height: 170px; background: #e9ebef; border-radius: 8px; overflow: hidden; display: flex; align-items: flex-start; justify-content: center; padding: 10px; }
.tpl-thumb-inner { transform: scale(.55); transform-origin: top center; pointer-events: none; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.tpl-thumb-inner * { pointer-events: none; }
.tpl-name { font-weight: 600; font-size: 13px; text-align: center; }
.tpl-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.tpl-actions .btn { flex: 1 1 45%; padding: 7px 8px; font-size: 12px; white-space: nowrap; }
.bld-main { display: grid; grid-template-columns: 1fr minmax(320px, 520px); gap: 18px; align-items: start; width: 100%; }
@media (max-width: 980px) {
  .bld-main { grid-template-columns: 1fr; }
  .bld-props { position: static; top: auto; }
}
.bld-stage { background: #e9ebef; border-radius: 12px; padding: 28px; min-height: 360px; display: flex; align-items: flex-start; justify-content: center; min-width: 0; }
.bld-canvas { width: 100%; }
.bld-card { box-shadow: 0 10px 40px rgba(0,0,0,.12); }
.bld-slot { position: relative; outline: 1px dashed transparent; border-radius: 6px; cursor: pointer; transition: outline-color .15s; }
.bld-slot:hover { outline-color: #9db2ff; }
.bld-slot.sel { outline: 2px solid var(--acc); }
.bld-slot-tools { position: absolute; top: -10px; right: -6px; display: none; gap: 2px; }
.bld-slot:hover .bld-slot-tools, .bld-slot.sel .bld-slot-tools { display: flex; }
.bld-slot-tools button { width: 22px; height: 22px; border: 0; border-radius: 5px; background: var(--acc); color: #fff; cursor: pointer; font-size: 12px; line-height: 1; }
.bld-empty { color: #aaa; font-size: 13px; padding: 8px; text-align: center; }

.bld-props { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; position: sticky; top: 10px; min-width: 0; }
.props-sec { margin-bottom: 16px; }
.props-h { font-weight: 600; font-size: 13px; margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.props-h.sec-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; cursor: pointer; user-select: none; }
.props-h.sec-h > span { min-width: 0; }
.props-toggle { background: var(--panel2); border: 1px solid var(--line); color: var(--mut); border-radius: 8px; padding: 2px 8px; cursor: pointer; }
.props-toggle:hover { border-color: var(--acc); color: var(--txt); }
.props-sec.collapsed > :not(.props-h.sec-h) { display: none; }
.props-sec.collapsed .props-toggle { transform: rotate(-90deg); }
.pf { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; font-size: 13px; color: var(--mut); }
.pf > span { flex: none; }
.pf input, .pf select, .pf textarea { flex: 1; min-width: 0; background: var(--panel2); border: 1px solid var(--line); color: var(--txt); padding: 6px 8px; border-radius: 6px; font-size: 13px; }
.pf input[type=color] { padding: 2px; height: 30px; max-width: 56px; cursor: pointer; }
.pf input[type=number] { max-width: 90px; }
.pf textarea { min-height: 54px; resize: vertical; }
.pf .color-combo { flex: 1; min-width: 0; display: flex; gap: 8px; align-items: center; }
.pf .color-combo input[type=color] { flex: none; }
.pf .color-combo input[type=text] { flex: 1; min-width: 0; }
.pf-check { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; }

@media (min-width: 1100px) {
  .bld-props .props-sec { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; align-items: start; }
  .bld-props .props-h, .bld-props .hint, .bld-props .mod-row, .bld-props .mod-add { grid-column: 1 / -1; }
  .bld-props .pf { margin-bottom: 0; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 6px; }
  .bld-props .pf > span { flex: none; }
  .bld-props .pf-check { margin-bottom: 0; }
}

/* ── телеграм ── */
.tg-status { margin: -8px 0 12px; font-size: 13px; padding: 8px 12px; border-radius: 6px; line-height: 1.4; }
.tg-status:empty { display: none; }
.tg-status.tg-ok   { background: rgba(63,185,80,0.12); border: 1px solid rgba(63,185,80,0.3); color: #c9f3d0; }
.tg-status.tg-warn { background: rgba(255,196,0,0.10); border: 1px solid rgba(255,196,0,0.3); color: #ffe69a; }

.tg-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.tg-result { margin-top: 12px; padding: 10px 14px; border-radius: 8px; font-size: 13px; line-height: 1.5; display: none; }
.tg-result.tg-ok   { display: block; background: rgba(63,185,80,0.12); border: 1px solid rgba(63,185,80,0.3); color: #c9f3d0; }
.tg-result.tg-err  { display: block; background: rgba(229,72,77,0.12); border: 1px solid rgba(229,72,77,0.3); color: #ffd2d4; }
.tg-result.tg-info { display: block; background: var(--panel2); border: 1px solid var(--line); color: var(--mut); }
.tg-chats { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.tg-chat { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; background: var(--panel2); border: 1px solid var(--line); color: var(--txt); padding: 10px 14px; border-radius: 8px; cursor: pointer; text-align: left; }
.tg-chat:hover { border-color: var(--acc); }
.tg-chat-title { font-weight: 600; font-size: 14px; }
.tg-chat-meta { color: var(--mut); font-size: 12px; }

/* ── интеграции / заявки ── */
.box-info { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px; margin-top: 16px; }
.st-group-title { font-weight: 700; font-size: 13px; color: var(--accent, #6c8bff); margin: 18px 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line); letter-spacing: .01em; }
.box-info ol { margin: 8px 0; padding-left: 20px; }
.box-info li { margin-bottom: 6px; }
#directTagsBox textarea { min-height: 64px; height: 64px; resize: none; margin: 10px 0; }
#directTagsBox .modal-actions { justify-content: flex-start; }
.leads-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.leads-search { flex: 1 1 260px; min-width: 180px; background: var(--panel2); border: 1px solid var(--line); color: var(--txt); padding: 9px 12px; border-radius: 8px; font-size: 14px; }
.leads-list { display: flex; flex-direction: column; gap: 10px; }
.lead { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; }
.lead-date { color: var(--mut); font-size: 12px; margin-bottom: 6px; }
.lead-row { font-size: 14px; }
.lead-row b { color: var(--mut); font-weight: 500; }

.leads-table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: auto; }
.leads-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.leads-table th, .leads-table td { padding: 8px 10px; border-bottom: 1px solid rgba(255,255,255,.06); vertical-align: top; }
.leads-table th { position: sticky; top: 0; background: rgba(18,22,35,.92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); text-align: left; font-weight: 600; color: var(--txt); border-bottom: 1px solid rgba(255,255,255,.12); }
.leads-table td { color: var(--txt); }
.leads-table tr:hover td { background: rgba(255,255,255,.04); }
.leads-table .col-date { white-space: nowrap; color: var(--mut); font-size: 12px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; width: 560px; max-width: 92vw; }
.modal-box h3 { margin: 0 0 8px; }
.modal-box p { color: var(--mut); }
.modal-box textarea { width: 100%; min-height: 90px; margin: 12px 0; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
