:root{
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #fafbff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e6e8ef;
  --line-2: #eef0f5;

  --brand: #4f46e5;
  --brand-2: #7c3aed;
  --brand-soft: #eef2ff;

  --trigger: #0ea5e9;
  --trigger-soft: #e0f2fe;
  --action: #10b981;
  --action-soft: #d1fae5;
  --keyboard: #f59e0b;
  --keyboard-soft: #fef3c7;
  --logic: #8b5cf6;
  --logic-soft: #ede9fe;
  --data: #ec4899;
  --data-soft: #fce7f3;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --shadow-md: 0 4px 12px rgba(16,24,40,.06), 0 2px 4px rgba(16,24,40,.04);
  --shadow-lg: 0 20px 40px -12px rgba(16,24,40,.15), 0 8px 16px -8px rgba(16,24,40,.08);
}

*{box-sizing:border-box}
html,body{margin:0;padding:0;height:100%}
body{
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  overflow: hidden;
}

/* Topbar */
.topbar{
  height: 64px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display:flex;align-items:center;justify-content:space-between;
  padding: 0 24px;
  position: relative;
  z-index: 10;
}
.brand{display:flex;align-items:center;gap:12px}
.logo{
  width: 36px;height:36px;border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color:#fff;display:grid;place-items:center;
  box-shadow: 0 6px 14px -4px rgba(79,70,229,.45);
}
.logo svg{width:20px;height:20px}
.brand-title{font-weight:700;font-size:15px;letter-spacing:-.01em}
.brand-sub{font-size:12px;color:var(--muted);margin-top:-1px}

.top-actions{display:flex;gap:8px}
.btn{
  display:inline-flex;align-items:center;gap:6px;
  height:36px;padding:0 14px;border-radius:10px;
  font-size:13px;font-weight:600;cursor:pointer;
  border:1px solid transparent;transition: all .15s ease;
  font-family:inherit;
}
.btn.primary{
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color:#fff;box-shadow: 0 4px 12px -2px rgba(79,70,229,.4);
}
.btn.primary:hover{transform:translateY(-1px);box-shadow: 0 6px 16px -2px rgba(79,70,229,.5)}
.btn.ghost{background:transparent;color:var(--ink-2);border-color:var(--line)}
.btn.ghost:hover{background:var(--surface-2);border-color:#d8dce5}

/* Layout */
.layout{
  display:grid;
  grid-template-columns: 280px 1fr 320px;
  height: calc(100vh - 64px);
}

/* Panels */
.panel{
  background:var(--surface);
  display:flex;flex-direction:column;
  overflow: hidden;
}
.panel.left{border-right:1px solid var(--line)}
.panel.right{border-left:1px solid var(--line)}

.panel-head{
  padding: 20px 20px 4px;
  display:flex;align-items:center;justify-content:space-between;
}
.panel-head h3{margin:0;font-size:13px;font-weight:700;letter-spacing:.02em;text-transform:uppercase;color:var(--ink-2)}
.panel-sub{padding:0 20px 16px;font-size:12px;color:var(--muted)}
.panel-foot{padding:12px 20px;border-top:1px solid var(--line-2);background:var(--surface-2)}
.hint{font-size:11.5px;color:var(--muted);display:flex;align-items:center;gap:6px}

.chip{
  background:var(--brand-soft);color:var(--brand);
  font-size:11px;font-weight:700;padding:3px 8px;border-radius:999px;
}

/* Tree */
.tree{flex:1;overflow-y:auto;padding: 4px 12px 20px}
.tree-node{
  display:flex;align-items:center;gap:8px;
  padding:8px 10px;border-radius:8px;cursor:pointer;
  font-size:13px;color:var(--ink-2);
  transition:background .12s ease;
}
.tree-node:hover{background:var(--surface-2)}
.tree-node.active{background:var(--brand-soft);color:var(--brand);font-weight:600}
.tree-node .dot{width:8px;height:8px;border-radius:50%;flex-shrink:0}
.tree-node .tlabel{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.tree-children{margin-left:14px;border-left:1.5px dashed var(--line);padding-left:4px}

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

/* Workspace */
.workspace{
  background:
    radial-gradient(circle at 1px 1px, #d9dde6 1px, transparent 0),
    linear-gradient(180deg, #f8f9fc 0%, #f1f3f9 100%);
  background-size: 20px 20px, auto;
  display:flex;flex-direction:column;
  overflow:hidden;
}
.ws-head{
  display:flex;justify-content:space-between;align-items:flex-end;
  padding: 20px 28px 16px;
  background: linear-gradient(180deg, rgba(255,255,255,.9), rgba(255,255,255,0));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(230,232,239,.6);
}
.ws-title{font-size:16px;font-weight:700;letter-spacing:-.01em}
.ws-sub{font-size:12.5px;color:var(--muted);margin-top:2px}
.ws-tabs{display:flex;gap:4px;background:var(--surface);padding:4px;border-radius:10px;border:1px solid var(--line)}
.tab{
  border:none;background:transparent;padding:6px 14px;border-radius:7px;
  font-size:12.5px;font-weight:600;color:var(--muted);cursor:pointer;font-family:inherit;
}
.tab.active{background:var(--brand-soft);color:var(--brand)}

.canvas{
  flex:1; overflow: hidden;
  position: relative;
  cursor: default;
}
.canvas.panning{cursor: grab}
.canvas.panning.active, .canvas.space-pan{cursor: grabbing}
.canvas-inner{
  position: absolute; top: 0; left: 0; width: 100%;
  padding: 40px 40px 120px;
  display: flex; flex-direction: column; align-items: center;
  transform-origin: 0 0;
  will-change: transform;
}
.zoom-ctrl{
  position: absolute; bottom: 16px; right: 16px; z-index: 5;
  display: flex; align-items: center; gap: 2px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  box-shadow: var(--shadow-md);
}
.zoom-ctrl button{
  border: none; background: transparent;
  width: 28px; height: 28px; border-radius: 7px;
  cursor: pointer; color: var(--ink-2);
  font-size: 16px; font-weight: 600; font-family: inherit;
  display: grid; place-items: center;
  transition: background .1s;
}
.zoom-ctrl button:hover{background: var(--surface-2); color: var(--ink)}
.zoom-level{
  min-width: 46px; text-align: center;
  font-size: 11.5px; font-weight: 600; color: var(--ink-2);
  padding: 0 4px;
}
.zoom-sep{width:1px; height:18px; background:var(--line); margin: 0 2px}
.pan-hint{
  position: absolute; bottom: 16px; left: 16px; z-index: 5;
  font-size: 11px; color: var(--muted);
  background: var(--surface);
  padding: 6px 10px; border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  opacity: .85;
  pointer-events: none;
}

/* Blocks */
.block{
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow:visible;
  transition: box-shadow .18s ease, transform .18s ease, border-color .18s ease;
  position:relative;
}
/* Clip inner content to rounded corners without clipping external ports */
.block > .block-head,
.block > .block-body,
.block > .slot{ border-radius: inherit }
.block > .block-head{ border-bottom-left-radius:0; border-bottom-right-radius:0 }
.block > .block-body,
.block > .slot{ border-top-left-radius:0; border-top-right-radius:0 }
.block:hover{box-shadow: var(--shadow-md);border-color:#d8dce5}
.block.selected{
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(79,70,229,.12), var(--shadow-md);
}
.block-head{
  display:flex;align-items:center;gap:10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-2);
  cursor:pointer;
  user-select:none;
}
.block-head .bdot{width:10px;height:10px;border-radius:3px;flex-shrink:0}
.block-icon{
  width:32px;height:32px;border-radius:8px;
  display:grid;place-items:center;flex-shrink:0;
}
.block-icon svg{width:18px;height:18px}
.block-meta{flex:1;min-width:0}
.block-kind{
  font-size:10.5px;font-weight:700;letter-spacing:.08em;text-transform:uppercase;
  color:var(--muted);
}
.block-title{font-size:14px;font-weight:600;color:var(--ink);margin-top:1px}
.block-actions{display:flex;gap:4px}
.icon-btn{
  border:none;background:transparent;width:28px;height:28px;border-radius:7px;
  display:grid;place-items:center;color:var(--muted);cursor:pointer;transition:all .12s;
}
.icon-btn:hover{background:var(--surface-2);color:var(--ink)}
.icon-btn.danger:hover{background:#fef2f2;color:#dc2626}

.block-body{
  padding: 12px 16px 14px;
  font-size:13px;color:var(--ink-2);
}
.block-param{
  display:flex;gap:8px;font-size:12.5px;
  padding: 3px 0;
}
.block-param .k{color:var(--muted);min-width:80px}
.block-param .v{color:var(--ink);font-weight:500;word-break:break-word}
.block-param .v.empty{color:#cbd5e1;font-style:italic;font-weight:400}

/* Slot (container for children) */
.slot{
  padding: 8px 16px 16px;
  background: var(--surface-2);
  border-top: 1px dashed var(--line);
}
.slot-label{
  font-size:10.5px;font-weight:700;letter-spacing:.08em;text-transform:uppercase;
  color:var(--muted);margin-bottom:10px;
}
.slot-children{display:flex;flex-direction:column;gap:10px}
.slot-children .block{max-width: 100%}

.block{position:relative}
.tree-slot-label{font-size:10.5px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;color:var(--muted);padding:6px 0 2px}

.slot-label{display:flex;align-items:center;justify-content:space-between;gap:8px}

.tree-wrap{position:relative;z-index:1;display:flex;flex-direction:column;align-items:center;width:100%}

.block-floating{
  position:absolute !important;
  width:320px !important;
  max-width:320px !important;
  margin:0 !important;
  z-index:2;
  cursor:grab;
  box-shadow: 0 6px 20px rgba(0,0,0,.10);
}
.block-floating:active{cursor:grabbing}

/* -- Condition branches (then/else stacked vertically) ----------- */
.slot[data-slot-key="then"]{
  background:#f0fdf4;
  border-top:1px solid #bbf7d0;
}
.slot[data-slot-key="else"]{
  background:#fff7ed;
  border-top:1px solid #fed7aa;
}
.slot[data-slot-key="then"] .slot-label{ color:#15803d }
.slot[data-slot-key="else"] .slot-label{ color:#c2410c }

.slot-empty{
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  padding: 16px;
  text-align:center;font-size:12px;color:var(--muted);
  background: var(--surface);
}

/* Connector line between stacked blocks */
.connector{
  width:2px;height:20px;background:var(--line);
  margin: 0 auto;
  position:relative;
}
.connector::before,.connector::after{
  content:"";position:absolute;left:50%;transform:translateX(-50%);
  width:8px;height:8px;border-radius:50%;background:var(--line);
}
.connector::before{top:-3px}.connector::after{bottom:-3px}

/* Block colors by category */
.block[data-cat="trigger"] .block-icon{background:var(--trigger-soft);color:var(--trigger)}
.block[data-cat="trigger"] .bdot{background:var(--trigger)}
.block[data-cat="action"] .block-icon{background:var(--action-soft);color:var(--action)}
.block[data-cat="action"] .bdot{background:var(--action)}
.block[data-cat="keyboard"] .block-icon{background:var(--keyboard-soft);color:#d97706}
.block[data-cat="keyboard"] .bdot{background:var(--keyboard)}
.block[data-cat="logic"] .block-icon{background:var(--logic-soft);color:var(--logic)}
.block[data-cat="logic"] .bdot{background:var(--logic)}
.block[data-cat="data"] .block-icon{background:var(--data-soft);color:var(--data)}
.block[data-cat="data"] .bdot{background:var(--data)}

/* Drag & drop */
.block[draggable="true"]{cursor: grab}
.block[draggable="true"]:active{cursor: grabbing}
.block.drag-snapshot{transform: rotate(3deg) scale(1.02); box-shadow: 0 12px 28px rgba(0,0,0,.18)}
.block.dragging{opacity:.4}
.block.block-settle{animation: blockSettle .28s cubic-bezier(.2,.8,.3,1)}
@keyframes blockSettle{
  from { transform: rotate(3deg) scale(1.02); }
  to   { transform: rotate(0deg) scale(1); }
}
.slot-children > .block{
  transition: transform .22s cubic-bezier(.2,.8,.3,1);
}
.slot-children > .block.shift-down{transform: translateY(var(--shift,72px))}
.drop-indicator{
  height: 3px; background: var(--brand); border-radius: 2px;
  margin: 2px 0; opacity: 0;
  box-shadow: 0 0 0 3px rgba(79,70,229,.18);
  pointer-events: none;
}
.drop-indicator.show{opacity:1}
.slot-children.drag-over > .slot-empty{
  border-color: var(--brand); background: var(--brand-soft); color: var(--brand);
  transition: all .2s ease;
}
.palette-item{user-select:none}
.palette-item[draggable="true"]:active{cursor: grabbing}

/* Start block emphasis */
.block.start{
  background: linear-gradient(135deg, #eff6ff, #eef2ff);
  border-color: #c7d2fe;
}
.block.start .block-icon{background:#dbeafe;color:#2563eb}

/* Palette */
.palette{flex:1;overflow-y:auto;padding: 0 16px 20px}
.palette-cat{margin-top:12px}
.palette-cat-head{
  display:flex;align-items:center;gap:8px;
  padding:8px 6px;font-size:11px;font-weight:700;
  letter-spacing:.08em;text-transform:uppercase;color:var(--muted);
}
.palette-cat-head .pdot{width:8px;height:8px;border-radius:2px}
.palette-items{display:flex;flex-direction:column;gap:6px}
.palette-item{
  display:flex;align-items:center;gap:10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: all .14s ease;
}
.palette-item:hover{
  border-color: var(--brand);
  background: var(--brand-soft);
  transform: translateX(-2px);
  box-shadow: var(--shadow-sm);
}
.palette-item .pi-icon{
  width:28px;height:28px;border-radius:7px;display:grid;place-items:center;flex-shrink:0;
}
.palette-item .pi-icon svg{width:14px;height:14px}
.palette-item .pi-label{font-size:13px;font-weight:500;color:var(--ink)}
.palette-item .pi-desc{font-size:11px;color:var(--muted);margin-top:1px}
.palette-item .pi-text{flex:1;min-width:0}

.palette-item[data-cat="trigger"] .pi-icon{background:var(--trigger-soft);color:var(--trigger)}
.palette-item[data-cat="action"] .pi-icon{background:var(--action-soft);color:var(--action)}
.palette-item[data-cat="keyboard"] .pi-icon{background:var(--keyboard-soft);color:#d97706}
.palette-item[data-cat="logic"] .pi-icon{background:var(--logic-soft);color:var(--logic)}
.palette-item[data-cat="data"] .pi-icon{background:var(--data-soft);color:var(--data)}

.palette-cat[data-cat="trigger"] .pdot{background:var(--trigger)}
.palette-cat[data-cat="action"] .pdot{background:var(--action)}
.palette-cat[data-cat="keyboard"] .pdot{background:var(--keyboard)}
.palette-cat[data-cat="logic"] .pdot{background:var(--logic)}
.palette-cat[data-cat="data"] .pdot{background:var(--data)}

/* Modal */
.modal[hidden]{display:none !important}
.modal{
  position:fixed;inset:0;z-index:50;
  background:rgba(15,23,42,.45);
  backdrop-filter: blur(6px);
  display:grid;place-items:center;
  padding: 20px;
  animation: fadeIn .18s ease;
}
@keyframes fadeIn{from{opacity:0}to{opacity:1}}
.modal-card{
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 100%;max-width: 480px;
  display:flex;flex-direction:column;
  max-height: 90vh;
  animation: popIn .22s cubic-bezier(.2,.8,.3,1.1);
  position: relative;
}
.modal-card.dragged{animation:none;transition:none}
.modal-head{cursor: move;user-select:none}
.modal-head button, .modal-head .icon-btn{cursor:pointer}
.modal-card.wide{max-width: 820px}
@keyframes popIn{from{opacity:0;transform:scale(.96) translateY(8px)}to{opacity:1;transform:none}}
.modal-head{
  display:flex;justify-content:space-between;align-items:flex-start;
  padding: 20px 22px 16px;border-bottom:1px solid var(--line-2);
}
.modal-title{font-size:16px;font-weight:700}
.modal-sub{font-size:12.5px;color:var(--muted);margin-top:2px}
.modal-body{padding: 18px 22px;overflow-y:auto;flex:1}

/* New-bot wizard */
.wiz-steps{
  display:flex;gap:8px;padding:10px 22px 0;
  border-bottom:1px solid var(--line-2);
}
.wiz-step{
  display:flex;align-items:center;gap:8px;padding:10px 4px;
  font-size:12.5px;color:var(--muted);font-weight:500;
  border-bottom:2px solid transparent;margin-bottom:-1px;
}
.wiz-step .wiz-dot{
  width:20px;height:20px;border-radius:50%;display:inline-grid;place-items:center;
  background:var(--surface-2);border:1px solid var(--line);font-size:11px;font-weight:700;
}
.wiz-step.active{color:var(--ink);border-bottom-color:var(--brand)}
.wiz-step.active .wiz-dot{background:var(--brand);color:#fff;border-color:var(--brand)}
.wiz-step.done .wiz-dot{background:#10b981;color:#fff;border-color:#10b981}
.wiz-guide{font-size:13.5px;color:var(--ink-2);line-height:1.55}
.wiz-guide p{margin:0 0 10px}
.wiz-list{margin:0 0 10px;padding-left:20px;display:flex;flex-direction:column;gap:6px}
.wiz-list code{background:var(--surface-2);padding:1px 6px;border-radius:5px;font-size:12.5px}
.wiz-hint{font-size:12.5px;color:var(--muted)}
.wiz-verify{margin-top:12px;min-height:20px}
.wiz-verify-loading{font-size:13px;color:var(--muted)}
.wiz-verify-err{
  font-size:13px;color:#b91c1c;background:#fef2f2;
  border:1px solid #fecaca;padding:10px 12px;border-radius:9px;
}
.wiz-verify-ok{
  font-size:12.5px;color:#047857;background:#ecfdf5;
  border:1px solid #a7f3d0;padding:4px 8px;border-radius:999px;
  align-self:flex-start;white-space:nowrap;
}
.wiz-bot-card{
  display:flex;align-items:center;gap:12px;
  padding:12px;border:1px solid var(--line);border-radius:12px;
  background:var(--surface-2);
}
.wiz-bot-img{width:52px;height:52px;border-radius:50%;object-fit:cover;background:var(--surface)}
.wiz-bot-img.placeholder{display:grid;place-items:center;font-size:26px}
.wiz-bot-info{flex:1;min-width:0}
.wiz-bot-name{font-weight:700;font-size:14px}
.wiz-bot-user{font-size:12.5px;color:var(--muted)}
.wiz-bot-desc{font-size:12.5px;color:var(--ink-2);margin-top:4px}
.modal-foot{
  padding: 14px 22px;border-top:1px solid var(--line-2);
  display:flex;justify-content:flex-end;gap:8px;
  background: var(--surface-2);border-radius: 0 0 16px 16px;
}

/* Form fields */
.field{margin-bottom:14px}
.field label{
  display:block;font-size:12px;font-weight:600;color:var(--ink-2);
  margin-bottom:6px;
}
.field .help{font-size:11.5px;color:var(--muted);margin-top:4px}
.input, .textarea, .select{
  width:100%;padding:10px 12px;border:1px solid var(--line);
  border-radius:9px;font-size:13px;font-family:inherit;color:var(--ink);
  background:var(--surface);transition:border-color .12s, box-shadow .12s;
}
.input:focus,.textarea:focus,.select:focus{
  outline:none;border-color:var(--brand);
  box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
.textarea{resize:vertical;min-height:80px;font-family:inherit}

.hl-wrap{position:relative;width:100%}
.hl-wrap .hl-target{
  position:relative;background:transparent;
  color:transparent;-webkit-text-fill-color:transparent;
  caret-color:var(--ink);
  line-height:1.5;
}
.hl-wrap .hl-target::selection{background:rgba(79,70,229,.25);-webkit-text-fill-color:var(--ink)}
.hl-overlay{
  position:absolute;inset:0;
  padding:10px 12px;border:1px solid transparent;border-radius:9px;
  font-family:inherit;font-size:13px;line-height:1.5;
  white-space:pre-wrap;word-wrap:break-word;overflow:hidden;
  pointer-events:none;color:var(--ink);
  margin:0;
}
.hl-overlay .hl-var{
  background:var(--brand-soft);color:var(--brand);
  border-radius:3px;
  /* no padding / font-weight — must keep identical metrics to textarea text
     so caret position and word-wrap stay aligned */
}
.kb-rows{display:flex;flex-direction:column;gap:8px}
.kb-row{display:flex;gap:6px;align-items:center}
.kb-row .input{flex:1}

.kb-row-2d{
  display:flex;flex-wrap:wrap;gap:6px;align-items:center;
  padding:8px;border:1px dashed var(--line);border-radius:10px;
  background:var(--surface);transition:background .12s,border-color .12s;
}
.kb-row-2d.drag-over{background:var(--brand-soft);border-color:var(--brand)}
.kb-row-mark{
  width:3px;align-self:stretch;background:var(--line);
  border-radius:2px;flex-shrink:0;
}
.kb-row-2d:hover .kb-row-mark{background:var(--brand)}
.kb-chip{
  display:inline-flex;align-items:center;gap:4px;
  background:var(--panel,#fff);border:1px solid var(--line);
  border-radius:8px;padding:2px 2px 2px 4px;cursor:grab;
  transition:box-shadow .12s,border-color .12s,opacity .12s;
}
.kb-chip:hover{border-color:var(--brand)}
.kb-chip.dragging{opacity:.35;cursor:grabbing}
.kb-chip.drag-target{box-shadow:-2px 0 0 var(--brand)}
.kb-chip-handle{color:var(--muted);font-size:10px;line-height:1;user-select:none;padding:0 2px}
.kb-chip-input{
  width:110px;border:none;background:transparent;font-size:13px;
  font-family:inherit;color:var(--ink);padding:4px 2px;outline:none;
}
.kb-chip-rm{
  background:transparent;border:none;color:var(--muted);
  padding:2px;border-radius:4px;cursor:pointer;display:inline-flex;
}
.kb-chip-rm:hover{color:#e11d48;background:rgba(225,29,72,.08)}
.kb-chip-rm svg{width:14px;height:14px}
.kb-add-chip{
  background:transparent;border:1px dashed var(--line);color:var(--muted);
  padding:4px 10px;border-radius:8px;font-size:12px;cursor:pointer;font-family:inherit;
}
.kb-add-chip:hover{border-color:var(--brand);color:var(--brand);background:var(--brand-soft)}

.tg-kb-row{display:flex;gap:4px;margin-bottom:4px}
.tg-kb-row:last-child{margin-bottom:0}
.tg-kb-row .tg-kb-btn{flex:1}
.btn-add{
  border:1.5px dashed var(--line);background:transparent;
  padding:8px;border-radius:8px;color:var(--muted);cursor:pointer;
  font-size:12px;font-weight:500;width:100%;margin-top:6px;font-family:inherit;
  transition:all .12s;
}
.btn-add:hover{border-color:var(--brand);color:var(--brand);background:var(--brand-soft)}

.code{
  background:#0f172a;color:#e2e8f0;padding:16px;border-radius:10px;
  font-family:'JetBrains Mono',monospace;font-size:12px;
  overflow:auto;max-height:50vh;line-height:1.55;
  margin:0;
}

/* iPhone simulator */
.sim{
  position: fixed; right: 24px; bottom: 24px; z-index: 40;
  width: 320px;
  background: transparent;
  animation: popIn .22s cubic-bezier(.2,.8,.3,1.1);
  user-select: none;
  filter: drop-shadow(0 25px 40px rgba(0,0,0,.35)) drop-shadow(0 8px 14px rgba(0,0,0,.2));
}
.sim[hidden]{display:none !important}
.sim-head{
  display:flex; justify-content:space-between; align-items:center;
  padding: 6px 10px 8px;
  cursor: move;
  background: rgba(255,255,255,.72);
  backdrop-filter: blur(10px);
  border-radius: 10px;
  border: 1px solid var(--line);
  margin-bottom: 6px;
}
.sim-title{font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted)}
.sim-head-actions{display:flex;gap:2px}

/* iPhone 15 Pro-like frame */
.iphone{
  position: relative;
  padding: 12px;
  background: linear-gradient(145deg, #2a2a2d 0%, #151517 40%, #1f1f22 100%);
  border-radius: 54px;
  box-shadow:
    inset 0 0 0 2px #3f3f45,
    inset 0 0 0 4px #0b0b0d,
    inset 0 0 0 6px #2a2a2d;
}
.iphone::before{
  /* subtle titanium edge */
  content:""; position:absolute; inset: 2px; border-radius: 52px;
  box-shadow: inset 0 1px 1px rgba(255,255,255,.06), inset 0 -1px 1px rgba(0,0,0,.5);
  pointer-events: none;
}
.iphone-side-btn{
  position: absolute; background: #2a2a2d;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.05), inset 0 -1px 0 rgba(0,0,0,.4);
  border-radius: 2px;
}
.iphone .side-silent{left: -2px; top: 90px; width: 3px; height: 28px}
.iphone .side-volup{left: -2px; top: 132px; width: 3px; height: 48px}
.iphone .side-voldn{left: -2px; top: 188px; width: 3px; height: 48px}
.iphone .side-power{right: -2px; top: 140px; width: 3px; height: 72px}

.iphone-screen{
  background: #000;
  border-radius: 42px;
  overflow: hidden;
  height: 580px;
  display: flex; flex-direction: column;
  position: relative;
}

/* Dynamic Island */
.iphone-island{
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  width: 100px; height: 30px;
  background: #000;
  border-radius: 20px;
  z-index: 10;
  box-shadow: 0 0 0 .5px rgba(255,255,255,.04);
}

/* Status bar */
.status-bar{
  position: relative;
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 24px 6px;
  height: 46px;
  color: #000;
  background: #f7f7f9;
  z-index: 2;
}
.sb-time{
  font-weight: 600; font-size: 15px;
  font-family: -apple-system, 'SF Pro Display', 'Inter', sans-serif;
  letter-spacing: -.01em;
  padding-left: 6px;
  line-height: 1;
}
.sb-right{
  display: flex; align-items: center; gap: 6px;
  padding-right: 0;
}
.sb-signal{width: 17px; height: 10px; color: #000}
.sb-wifi{width: 15px; height: 11px; color: #000}
.sb-battery{
  position: relative;
  display: flex; align-items: center;
  width: 26px; height: 12px;
}
.sb-battery-body{
  width: 24px; height: 12px;
  border: 1px solid rgba(0,0,0,.35);
  border-radius: 3.5px;
  padding: 1px;
  box-sizing: border-box;
  overflow: hidden;
}
.sb-battery-cap{
  position: absolute; right: 0; top: 3px;
  width: 2px; height: 6px;
  background: rgba(0,0,0,.35);
  border-radius: 0 1.5px 1.5px 0;
}
.sb-battery-fill{
  height: 100%; width: 78%;
  background: #000;
  border-radius: 1.5px;
}

.tg-topbar{
  background: #f7f7f9;
  padding: 6px 10px 8px;
  display: flex; align-items: center; gap: 6px;
  border-bottom: .5px solid #c7c9cd;
  position: relative;
  z-index: 2;
}
.tg-back{
  display: flex; align-items: center; gap: 3px;
  color: #2481cc; padding: 4px 2px; cursor: default;
}
.tg-back-label{font-size: 14px; font-weight: 400}
.tg-peer{
  display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0;
}
.tg-avatar{
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #5dade2, #2874a6);
  color: #fff; display: grid; place-items: center;
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(0,0,0,.1);
}
.tg-title-wrap{flex:1; min-width: 0}
.tg-title{
  font-size: 14px; font-weight: 600; color: #000;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tg-status{font-size: 11.5px; color: #8a8e94; margin-top: 1px}
.tg-actions{color: #2481cc; padding: 4px}

/* Chat area with Telegram-like pattern */
.tg-chat-wrap{
  flex: 1; position: relative; overflow: hidden;
  background: #b4cbd6;
}
.tg-chat-bg{
  position: absolute; inset: 0;
  background-image:
    radial-gradient(circle at 20% 20%, rgba(255,255,255,.35) 0, transparent 35%),
    radial-gradient(circle at 80% 60%, rgba(180,220,200,.4) 0, transparent 40%),
    radial-gradient(circle at 50% 90%, rgba(255,200,180,.3) 0, transparent 45%),
    linear-gradient(135deg, #d6c3a8 0%, #b9a9c9 35%, #90c0d4 75%, #b7d4c4 100%);
  opacity: .85;
}
.tg-chat-bg::after{
  content: "";
  position: absolute; inset: 0;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(0,0,0,.04) 1px, transparent 0);
  background-size: 14px 14px;
  opacity: .8;
}
.tg-chat{
  position: relative; z-index: 1;
  height: 100%; overflow-y: auto;
  padding: 10px 8px 12px;
  display: flex; flex-direction: column;
}
.tg-msg{
  max-width: 80%;
  padding: 6px 9px 6px 10px;
  font-size: 13px;
  line-height: 1.32;
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: msgIn .2s ease;
  position: relative;
  box-shadow: 0 1px 1.5px rgba(0,0,0,.12);
  margin-top: 2px;
}
/* Larger gap when sender changes (group break) */
.tg-msg.group-start{margin-top: 8px}
.tg-msg:first-child{margin-top: 0}

@keyframes msgIn{from{opacity:0;transform:translateY(6px) scale(.97)}to{opacity:1;transform:none}}

.tg-msg.bot{
  align-self: flex-start;
  background: #fff;
  color: #000;
  margin-left: 6px;
  border-radius: 14px 14px 14px 14px;
}
.tg-msg.user{
  align-self: flex-end;
  background: #e4fdd1;
  color: #000;
  margin-right: 6px;
  border-radius: 14px 14px 14px 14px;
}
/* Tail only on last message of a group */
.tg-msg.bot.group-end{border-bottom-left-radius: 4px}
.tg-msg.bot.group-end::before{
  content: ""; position: absolute; left: -5px; bottom: 0;
  width: 10px; height: 14px;
  background: #fff;
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
  border-bottom-right-radius: 6px;
}
.tg-msg.user.group-end{border-bottom-right-radius: 4px}
.tg-msg.user.group-end::before{
  content: ""; position: absolute; right: -5px; bottom: 0;
  width: 10px; height: 14px;
  background: #e4fdd1;
  clip-path: polygon(0 0, 100% 100%, 0 100%);
  border-bottom-left-radius: 6px;
}
.tg-msg .tg-time{
  font-size: 10px; color: #8fa0a8;
  display: inline-block; margin-left: 6px; vertical-align: bottom;
  font-weight: 400;
}
.tg-msg.user .tg-time{color: #4fae4e}
.tg-msg.tg-photo{padding: 3px 3px 5px; max-width: 82%}
.tg-photo-img{
  display:block; width: 100%; max-width: 240px;
  border-radius: 11px; object-fit: cover; max-height: 240px;
  background: #e6e8ec;
}
.tg-photo-fallback{
  width: 220px; height: 140px;
  display: grid; place-items: center;
  background: #e6e8ec; color: #8b95a3;
  border-radius: 11px; font-size: 12px;
}
.tg-photo-cap{
  font-size: 12.5px; color: #000;
  padding: 6px 8px 2px;
  white-space: pre-wrap; word-wrap: break-word;
}
.tg-photo .tg-time{margin: 2px 8px 0; display: inline-block}
.tg-typing{
  align-self: flex-start; background: #fff;
  padding: 10px 12px; border-radius: 14px;
  border-bottom-left-radius: 4px;
  display: flex; gap: 3px;
  box-shadow: 0 1px 1px rgba(0,0,0,.06);
}
.tg-typing span{
  width: 5px; height: 5px; background: #a0a6b0; border-radius: 50%;
  animation: dotBounce 1.2s infinite ease-in-out;
}
.tg-typing span:nth-child(2){animation-delay: .15s}
.tg-typing span:nth-child(3){animation-delay: .3s}
@keyframes dotBounce{0%,60%,100%{transform:translateY(0);opacity:.4}30%{transform:translateY(-4px);opacity:1}}

.tg-kb{
  align-self: stretch;
  display: flex; flex-direction: column; gap: 4px;
  margin-top: 6px;
  padding: 0 2px;
}
.tg-kb-btn{
  flex: 1 1 calc(33.333% - 3px);
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(6px);
  color: #000;
  padding: 9px 8px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: background .1s;
  box-shadow: 0 1px 1.5px rgba(0,0,0,.08);
  min-width: 0;
}
.tg-kb-btn:hover{background: #fff}
.tg-kb-btn.contact{
  flex: 1 1 100%;
  background: rgba(36,129,204,.95); color: #fff;
}
.tg-kb-btn.contact:hover{background:#2481cc}

.tg-input{
  background: #f7f7f9;
  padding: 6px 6px 30px;
  display: flex; gap: 6px; align-items: center;
  border-top: .5px solid #c7c9cd;
  position: relative;
  z-index: 2;
}
.tg-input-icon{
  color: #8a8e94;
  padding: 6px;
  display: grid; place-items: center;
}
.tg-input-box{
  flex: 1;
  background: #fff;
  border-radius: 18px;
  padding: 7px 12px;
  font-size: 13px;
  color: #b8bcc2;
  border: .5px solid #d7dae0;
  display: flex; justify-content: space-between; align-items: center;
  min-height: 22px;
}
.tg-input-emoji{color: #8a8e94}
.iphone-home{
  position: absolute; bottom: 9px; left: 50%; transform: translateX(-50%);
  width: 134px; height: 5px;
  background: #000;
  border-radius: 3px;
  z-index: 3;
}

/* Onboarding tour */
.tour[hidden]{display:none !important}
.tour{position:fixed;inset:0;z-index:100;pointer-events:none}
.tour-backdrop{
  position:absolute;inset:0;
  background: transparent;
  pointer-events: auto;
}
.tour-spot{
  position:absolute;
  border-radius: 12px;
  background: transparent;
  box-shadow:
    0 0 0 4px rgba(79,70,229,.85),
    0 0 0 9999px rgba(15,23,42,.62);
  transition: all .35s cubic-bezier(.2,.8,.3,1);
  pointer-events: none;
  z-index: 2;
}
.tour-card{
  position: absolute;
  width: 320px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 18px 18px 14px;
  pointer-events: auto;
  transition: all .35s cubic-bezier(.2,.8,.3,1);
  z-index: 3;
  animation: popIn .25s cubic-bezier(.2,.8,.3,1.1);
}
.tour-step{
  font-size: 11px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--brand);
  margin-bottom: 8px;
}
.tour-title{font-size: 16px; font-weight: 700; letter-spacing: -.01em}
.tour-body{
  font-size: 13px; line-height: 1.5; color: var(--ink-2);
  margin-top: 6px;
}
.tour-foot{
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 16px;
}
.tour-nav{display: flex; gap: 6px}
.tour-foot .btn{height: 32px; padding: 0 12px; font-size: 12.5px}
.tour-card::before{
  content: ""; position: absolute;
  width: 12px; height: 12px;
  background: var(--surface);
  transform: rotate(45deg);
}
.tour-card.arrow-top::before{top: -6px; left: 50%; margin-left: -6px; box-shadow: -1px -1px 3px rgba(0,0,0,.04)}
.tour-card.arrow-bottom::before{bottom: -6px; left: 50%; margin-left: -6px; box-shadow: 1px 1px 3px rgba(0,0,0,.04)}
.tour-card.arrow-left::before{left: -6px; top: 50%; margin-top: -6px; box-shadow: -1px 1px 3px rgba(0,0,0,.04)}
.tour-card.arrow-right::before{right: -6px; top: 50%; margin-top: -6px; box-shadow: 1px -1px 3px rgba(0,0,0,.04)}

/* Scrollbars */
::-webkit-scrollbar{width:10px;height:10px}
::-webkit-scrollbar-track{background:transparent}
::-webkit-scrollbar-thumb{background:#d8dce5;border-radius:10px;border:2px solid transparent;background-clip:padding-box}
::-webkit-scrollbar-thumb:hover{background:#b8bdc8;background-clip:padding-box;border:2px solid transparent}

/* Responsive */
@media (max-width: 1100px){
  .layout{grid-template-columns: 240px 1fr 280px}
}
@media (max-width: 900px){
  .layout{grid-template-columns: 1fr;grid-template-rows: auto 1fr auto}
  .panel.left,.panel.right{display:none}
}

/* -- Dashboard ------------------------------------------------- */
.dash-body{overflow:auto}
.brand-link{text-decoration:none;color:inherit;cursor:pointer;padding:4px 8px;margin:-4px -8px;border-radius:10px;transition:background .15s}
.brand-link:hover{background:var(--surface-2)}
.brand-link .logo{background:linear-gradient(135deg,#64748b,#334155);box-shadow:0 6px 14px -4px rgba(51,65,85,.35)}

.dash-main{max-width:1200px;margin:0 auto;padding:32px 24px 60px}
.dash-head{display:flex;align-items:flex-end;justify-content:space-between;gap:24px;margin-bottom:28px;flex-wrap:wrap}
.dash-title{margin:0 0 6px;font-size:26px;font-weight:700;letter-spacing:-.02em}
.dash-sub{color:var(--muted);font-size:14px}
.dash-stats{display:flex;gap:12px}
.stat{background:var(--surface);border:1px solid var(--line);border-radius:var(--radius);padding:12px 18px;display:flex;flex-direction:column;gap:2px;min-width:110px;box-shadow:var(--shadow-sm)}
.stat-val{font-size:22px;font-weight:700;color:var(--ink)}
.stat-val.stat-running{color:var(--action)}
.stat-lbl{font-size:12px;color:var(--muted)}

.bot-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(300px,1fr));gap:16px}
.bot-card{
  background:var(--surface);border:1px solid var(--line);border-radius:var(--radius);
  padding:18px;box-shadow:var(--shadow-sm);cursor:pointer;
  transition:transform .15s,box-shadow .15s,border-color .15s;
  display:flex;flex-direction:column;gap:16px;
}
.bot-card:hover{transform:translateY(-2px);box-shadow:var(--shadow-md);border-color:#d4d7e0}
.bot-card-head{display:flex;align-items:flex-start;gap:12px}
.bot-avatar{
  width:40px;height:40px;border-radius:12px;flex:0 0 40px;
  background:linear-gradient(135deg,var(--brand),var(--brand-2));color:#fff;
  display:grid;place-items:center;box-shadow:0 6px 14px -4px rgba(79,70,229,.35);
}
.bot-info{flex:1;min-width:0}
.bot-name{font-weight:600;font-size:15px;color:var(--ink);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.bot-meta{font-size:12px;color:var(--muted);margin-top:2px}
.bot-status{
  display:inline-flex;align-items:center;gap:6px;
  padding:4px 10px;border-radius:999px;font-size:11px;font-weight:600;
  background:var(--line-2);color:var(--muted);white-space:nowrap;
}
.bot-status .dot{width:6px;height:6px;border-radius:50%;background:currentColor}
.bot-status.on{background:var(--action-soft);color:#047857}
.bot-status.on .dot{background:var(--action);box-shadow:0 0 0 3px rgba(16,185,129,.18);animation:pulse 1.6s infinite}
.bot-status.off{background:#fef2f2;color:#b91c1c}
@keyframes pulse{0%,100%{opacity:1}50%{opacity:.5}}

.bot-card-foot{display:flex;gap:8px;align-items:center;padding-top:14px;border-top:1px solid var(--line-2)}
.bot-card-foot .btn{padding:7px 12px;font-size:12px}
.bot-card-foot .btn.sm{height:30px}
.bot-card-foot [data-act="open"]{margin-left:auto}

.dash-empty{
  text-align:center;padding:80px 24px;background:var(--surface);border:1px dashed var(--line);
  border-radius:var(--radius);display:flex;flex-direction:column;align-items:center;gap:12px;
  margin-top:24px;
}
.dash-empty[hidden]{display:none}
.empty-illus{color:var(--muted);opacity:.5}
.empty-title{font-size:18px;font-weight:600}
.empty-sub{color:var(--muted);max-width:380px;margin-bottom:8px}

.field{display:block;margin-bottom:14px}
.field-label{font-size:12px;color:var(--muted);font-weight:500;margin-bottom:6px}
.input{
  width:100%;padding:10px 12px;border:1px solid var(--line);border-radius:10px;
  font-family:inherit;font-size:14px;background:var(--surface-2);color:var(--ink);
  transition:border-color .15s,background .15s;
}
.input:focus{outline:none;border-color:var(--brand);background:var(--surface)}

.btn.sm{height:30px;padding:6px 12px;font-size:12px}
