:root {
  --primary: #1f6bff;
  --primary-600: #1557d6;
  --primary-50: #eef4ff;
  --ink: #1b2330;
  --ink-2: #4a5568;
  --muted: #8a94a6;
  --line: #e6e9ef;
  --bg: #f4f6f9;
  --card: #ffffff;
  --green: #12b76a;
  --green-50: #e8f8f0;
  --amber: #f79009;
  --amber-50: #fff6e5;
  --red: #f04438;
  --red-50: #fdecea;
  --purple: #7a5af8;
  --purple-50: #f1edff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
  --sidebar: 232px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink); background: var(--bg);
  font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.hidden { display: none !important; }

/* ---- shell ---- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar); background: var(--card); border-right: 1px solid var(--line); position: fixed;
  inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; font-weight: 750; font-size: 17px; }
.brand .logo { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, #1f6bff, #7a5af8);
  display: grid; place-items: center; color: #fff; }
.account { margin: 0 12px 10px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; display: flex;
  align-items: center; gap: 9px; font-size: 13px; }
.account .av { width: 26px; height: 26px; border-radius: 50%; background: var(--purple-50); color: var(--purple);
  display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.account .logout-btn { margin-left: auto; padding: 5px 10px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 12px; font-weight: 600; color: var(--ink-2); flex: none; }
.account .logout-btn:hover { background: var(--bg); color: var(--ink); }
.nav { padding: 4px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; min-height: 0; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 9px; color: var(--ink-2);
  font-weight: 520; }
.nav a:hover { background: var(--bg); color: var(--ink); }
.nav a.active { background: var(--primary-50); color: var(--primary); }
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav .sep { height: 1px; background: var(--line); margin: 8px 6px; }
.nav .badge { margin-left: auto; }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.main { margin-left: var(--sidebar); flex: 1; min-width: 0; }
.topbar { height: 60px; display: flex; align-items: center; gap: 12px; padding: 0 28px; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar .spacer { flex: 1; }
.content { padding: 24px 28px 48px; max-width: 1280px; }

/* ---- components ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px;
  border-bottom: 1px solid var(--line); }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, 1fr); } .g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g-wide { grid-template-columns: 2fr 1fr; }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, 1fr); } .g3 { grid-template-columns: 1fr 1fr; } }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.between { justify-content: space-between; }

.btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); border-radius: 9px; padding: 8px 14px; font: inherit; font-weight: 560; cursor: pointer;
  white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.danger { color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--bg); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.icon { padding: 6px; }
.btn svg { width: 16px; height: 16px; }
.btn:disabled { opacity: .5; cursor: default; }

input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 11px; background: #fff; width: 100%; outline: none; transition: border-color .12s, box-shadow .12s; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31, 107, 255, .14); }
textarea { resize: vertical; min-height: 70px; }
label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); display: block; margin-bottom: 5px; }
.field { margin-bottom: 12px; }
input[type=checkbox] { width: auto; }
.switch { position: relative; width: 36px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cfd5df; border-radius: 99px; cursor: pointer; transition: .15s; }
.switch span::after { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: #fff;
  border-radius: 50%; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(16px); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 11.5px;
  font-weight: 600; background: var(--bg); color: var(--ink-2); }
.badge.blue { background: var(--primary-50); color: var(--primary); }
.badge.green { background: var(--green-50); color: var(--green); }
.badge.amber { background: var(--amber-50); color: var(--amber); }
.badge.red { background: var(--red-50); color: var(--red); }
.badge.purple { background: var(--purple-50); color: var(--purple); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.green { background: var(--green); } .dot.amber { background: var(--amber); } .dot.red { background: var(--red); }

table.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 16px;
  border-bottom: 1px solid var(--line); background: #fafbfc; }
.table td { padding: 11px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.click:hover td { background: #fafbfd; cursor: pointer; }

.stat { padding: 16px 18px; }
.stat .k { color: var(--muted); font-size: 12.5px; font-weight: 550; display: flex; align-items: center; gap: 6px; }
.stat .v { font-size: 26px; font-weight: 720; margin-top: 4px; letter-spacing: -.02em; }
.stat .ic { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; }
.stat .ic svg { width: 16px; height: 16px; }

.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700;
  font-size: 13px; color: #fff; flex: none; position: relative; }
.avatar .ch { position: absolute; right: -3px; bottom: -3px; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid #fff; display: grid; place-items: center; }
.avatar .ch svg { width: 9px; height: 9px; color: #fff; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; color: #c3cad6; margin-bottom: 10px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: inherit; font-weight: 580; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--primary); border-color: var(--primary); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 99px; background: var(--bg);
  border: 1px solid var(--line); font-size: 12px; font-weight: 550; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0; font-size: 14px; line-height: 1; }

/* ---- modal / drawer / toast ---- */
.overlay { position: fixed; inset: 0; background: rgba(16, 24, 40, .4); display: grid; place-items: center; z-index: 100;
  animation: fade .12s; }
.modal { background: #fff; border-radius: 14px; width: min(560px, 94vw); max-height: 90vh; overflow: auto;
  box-shadow: var(--shadow-lg); }
.modal.wide { width: min(860px, 94vw); }
.modal-head { padding: 18px 22px 0; display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 16px 22px; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 96vw); background: #fff; z-index: 90;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slide .16s; }
.drawer-body { flex: 1; overflow: auto; padding: 18px 22px; }
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex;
  flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow-lg);
  font-weight: 550; animation: fade .15s; }
.toast.err { background: var(--red); }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }

/* ---- template gallery ---- */
.tpl { padding: 16px; cursor: pointer; transition: border-color .12s, transform .12s; }
.tpl:hover { border-color: var(--primary); transform: translateY(-1px); }
.tpl .ti { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; margin-bottom: 10px; }
.tpl .ti svg { width: 18px; height: 18px; }

/* ---- chat (inbox + simulator) ---- */
.inbox { display: grid; grid-template-columns: 320px 1fr 290px; height: calc(100vh - 60px); }
.inbox > div { min-height: 0; }
.conv-list { border-right: 1px solid var(--line); background: #fff; display: flex; flex-direction: column; }
.conv-list .items { overflow: auto; flex: 1; }
.conv { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv:hover { background: #fafbfd; } .conv.on { background: var(--primary-50); }
.conv .meta { min-width: 0; flex: 1; }
.conv .name { font-weight: 620; display: flex; justify-content: space-between; gap: 6px; }
.conv .last { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat { display: flex; flex-direction: column; background: var(--bg); }
.chat-head { background: #fff; border-bottom: 1px solid var(--line); padding: 12px 18px; display: flex; align-items: center;
  gap: 10px; }
.msgs { flex: 1; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 6px; }
.bubble-row { display: flex; flex-direction: column; max-width: 72%; }
.bubble-row.in { align-self: flex-start; } .bubble-row.out { align-self: flex-end; align-items: flex-end; }
.bubble-row.system { align-self: center; max-width: 90%; }
.bubble { padding: 9px 13px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; }
.in .bubble { background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.out .bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 5px; }
.out.human .bubble { background: var(--purple); }
.system .bubble { background: transparent; color: var(--muted); font-size: 12px; padding: 2px; text-align: center; }
.bubble img { max-width: 220px; border-radius: 10px; display: block; margin-bottom: 6px; }
.cards-row { display: flex; gap: 8px; overflow-x: auto; margin-top: 6px; }
.mcard { flex: 0 0 170px; background: var(--card, #fff); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.mcard img { width: 100%; max-width: none; height: 96px; object-fit: cover; margin: 0; }
.post-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.post-card { display: flex; flex-direction: column; }
.post-card .thumb { aspect-ratio: 4/5; background: var(--bg) center/cover no-repeat; border-radius: 12px 12px 0 0; display: grid; place-items: center; color: var(--muted); position: relative; }
.post-card .thumb video { width: 100%; height: 100%; object-fit: cover; border-radius: 12px 12px 0 0; }
.post-card .thumb .n { position: absolute; top: 8px; right: 8px; }
.post-card .cap { padding: 10px 12px; font-size: 13px; white-space: pre-wrap; max-height: 74px; overflow: hidden; }
.media-list { display: flex; gap: 8px; flex-wrap: wrap; }
.media-list .m { width: 72px; height: 72px; border-radius: 10px; background: var(--bg) center/cover; position: relative; border: 1px solid var(--line); display: grid; place-items: center; font-size: 11px; }
.media-list .m button { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: var(--ink); color: #fff; cursor: pointer; line-height: 1; }
.int-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; align-items: start; }
.int-logo { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 15px; flex: none; }
.note { background: #fff8e6; border: 1px solid #fde7b0; border-radius: 10px; padding: 8px 10px; font-size: 13px; margin-bottom: 6px; }
pre.code { background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 10px; font-size: 12px; overflow: auto; max-height: 260px; white-space: pre; }
.bubble-btns { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; min-width: 180px; }
.bubble-btns button, .bubble-btns a { border: 1px solid var(--primary); color: var(--primary); background: #fff;
  border-radius: 10px; padding: 7px 10px; font: inherit; font-weight: 600; cursor: pointer; text-align: center; }
.bubble-btns button:hover { background: var(--primary-50); }
.bubble-time { font-size: 10.5px; color: var(--muted); margin: 2px 4px 6px; }
.composer { background: #fff; border-top: 1px solid var(--line); padding: 12px 14px; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 42px; max-height: 140px; }
.side-panel { border-left: 1px solid var(--line); background: #fff; overflow: auto; padding: 18px; }
.paused-bar { background: var(--amber-50); color: #9a5b00; padding: 8px 18px; font-size: 13px; display: flex;
  align-items: center; gap: 10px; border-bottom: 1px solid #fde2b4; }

/* ---- builder ---- */
.builder { display: grid; grid-template-columns: 1fr 360px; height: calc(100vh - 60px); }
.canvas-wrap { position: relative; overflow: hidden; background-color: #f2f4f8;
  background-image: radial-gradient(#d3d9e3 1px, transparent 1px); background-size: 22px 22px; cursor: grab; }
.canvas-wrap.panning { cursor: grabbing; }
.canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.canvas svg.edges { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.edges path { fill: none; stroke: #9aa7bd; stroke-width: 2; pointer-events: stroke; cursor: pointer; }
.edges path:hover { stroke: var(--red); stroke-width: 3; }
.edges path.temp { stroke: var(--primary); stroke-dasharray: 5 4; pointer-events: none; }
.node { position: absolute; width: 250px; background: #fff; border: 1.5px solid var(--line); border-radius: 14px;
  box-shadow: 0 2px 6px rgba(16, 24, 40, .06); cursor: default; user-select: none; }
.node.sel { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31, 107, 255, .15); }
.node-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line);
  cursor: move; font-weight: 640; font-size: 13px; }
.node-head .ni { width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; flex: none; }
.node-head .ni svg { width: 14px; height: 14px; }
.node-head .count { margin-left: auto; }
.node-body { padding: 10px 12px; font-size: 12.5px; color: var(--ink-2); }
.node-body .txt { background: var(--bg); border-radius: 10px; padding: 8px 10px; white-space: pre-wrap; max-height: 110px;
  overflow: hidden; }
.node-port-row { position: relative; display: flex; align-items: center; justify-content: space-between; padding: 6px 12px;
  border-top: 1px dashed var(--line); font-size: 12px; font-weight: 580; }
.port { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 2.5px solid #9aa7bd; position: absolute;
  cursor: crosshair; z-index: 2; }
.port:hover { border-color: var(--primary); transform: scale(1.2); }
.port.out { right: -8px; top: 50%; margin-top: -7px; }
.port.in { left: -8px; top: 17px; }
.port.connected { background: #9aa7bd; }
.node.t-start { width: 200px; border-color: #b9d0ff; }
.palette { position: absolute; left: 16px; top: 16px; display: flex; flex-direction: column; gap: 6px; z-index: 5; }
.palette button { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; padding: 7px 12px 7px 8px; font: inherit; font-weight: 580; cursor: pointer;
  box-shadow: var(--shadow); font-size: 13px; }
.palette button:hover { border-color: var(--primary); }
.palette .pi { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; }
.pi svg { width: 14px; height: 14px; }
.palette .pi svg { width: 13px; height: 13px; }
.zoombar { position: absolute; right: 16px; bottom: 16px; display: flex; gap: 4px; z-index: 5; background: #fff;
  border: 1px solid var(--line); border-radius: 10px; padding: 4px; box-shadow: var(--shadow); }
.inspector { background: #fff; border-left: 1px solid var(--line); overflow: auto; display: flex; flex-direction: column; }
.inspector .sec { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.inspector h3 { margin-bottom: 10px; }
.list-item { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.list-item input, .list-item select { padding: 6px 9px; }
.sim-float { position: fixed; right: 380px; bottom: 20px; width: 340px; height: 520px; background: #fff; border-radius: 16px;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden; z-index: 60; border: 1px solid var(--line); }
.sim-float .chat-head { padding: 10px 14px; }

.t-message .ni, .pi.t-message { background: var(--primary-50); color: var(--primary); }
.t-question .ni, .pi.t-question { background: #e6f7fb; color: #0e93b5; }
.t-condition .ni, .pi.t-condition { background: var(--amber-50); color: var(--amber); }
.t-action .ni, .pi.t-action { background: var(--green-50); color: var(--green); }
.t-delay .ni, .pi.t-delay { background: #f2f4f7; color: #475467; }
.t-randomizer .ni, .pi.t-randomizer { background: #fdf0f7; color: #d6408f; }
.t-ai .ni, .pi.t-ai { background: var(--purple-50); color: var(--purple); }
.t-goto .ni, .pi.t-goto { background: #eef1f6; color: #3d4b63; }
.t-request .ni, .pi.t-request { background: #e6f6fb; color: #0e93b5; }
.t-end .ni, .pi.t-end { background: var(--red-50); color: var(--red); }
.t-start .ni { background: var(--primary); color: #fff; }

.bar { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 10px; }
.bar > div { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bar .b { width: 100%; max-width: 34px; background: var(--primary); border-radius: 6px 6px 2px 2px; min-height: 2px; }
.bar .b2 { background: #b7cdff; }
.bar .l { font-size: 11px; color: var(--muted); }
.kpi-hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.trig-pill { display: inline-flex; gap: 6px; align-items: center; padding: 4px 9px; border-radius: 8px; background: var(--bg);
  font-size: 12px; font-weight: 560; margin: 2px 4px 2px 0; }
.trig-pill svg { width: 13px; height: 13px; }
code.k { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; font-size: 12px; }
.copy { cursor: pointer; }

/* ---- login + phone access page ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); padding: 32px 26px; text-align: center; }
.login-card h1 { margin-top: 12px; }
.login-error { background: var(--red-50); color: var(--red); border-radius: 9px; padding: 10px 12px; margin-bottom: 12px; font-size: 13px; }
.qr-block { display: flex; gap: 16px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.qr-block:first-child { border-top: 0; padding-top: 0; }
.qr-block .qr { flex: none; background: #fff; padding: 6px; border: 1px solid var(--line); border-radius: 10px; }

/* ---- phone layout ---- */
.menu-btn, .tabbar, .menu-scrim, .mobile-only { display: none; }
.canvas-wrap { touch-action: none; }
@media (pointer: coarse) {
  .port { width: 22px; height: 22px; }
  .port.out { right: -12px; margin-top: -11px; }
  .port.in { left: -12px; top: 13px; }
}
@media (max-width: 760px) {
  body { font-size: 15px; }
  input, select, textarea { font-size: 16px; } /* stops iPhone zooming into fields */
  .menu-btn, .mobile-only { display: inline-flex; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; width: min(290px, 85vw); box-shadow: var(--shadow-lg); }
  body.menu-open .sidebar { transform: none; }
  body.menu-open .menu-scrim { display: block; position: fixed; inset: 0; background: rgba(16, 24, 40, .35); z-index: 19; }
  .main { margin-left: 0; padding-bottom: calc(62px + env(safe-area-inset-bottom)); }
  .topbar { height: auto; min-height: 56px; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); flex-wrap: wrap; gap: 8px; }
  .topbar h2 { font-size: 16px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar .spacer { display: none; }
  .content { padding: 16px 16px 32px; }
  .g2, .g3, .g4, .g-wide { grid-template-columns: 1fr; }
  .card-head { padding: 14px 16px; flex-wrap: wrap; gap: 8px; }
  .card-pad { padding: 16px; }
  .table { display: block; overflow-x: auto; white-space: nowrap; }
  .modal-foot { flex-wrap: wrap; }
  .qr-block { flex-direction: column; align-items: flex-start; }

  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 18; background: var(--card);
    border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 7px;
    font-size: 11px; font-weight: 560; color: var(--muted); position: relative; }
  .tabbar a.active { color: var(--primary); }
  .tabbar svg { width: 22px; height: 22px; }
  .tabbar .badge { position: absolute; top: 3px; left: 54%; font-size: 10px; padding: 0 5px; }

  /* inbox: list first, conversation full screen after tapping one */
  .inbox { grid-template-columns: 1fr; height: calc(100dvh - 56px - 62px - env(safe-area-inset-bottom)); }
  .inbox .chat, .inbox .side-panel { display: none; }
  .inbox.open .conv-list { display: none; }
  .inbox.open .chat { display: flex; min-height: 0; }
  .chat-head { flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
  .chat-head select { flex: 1 1 100%; order: 5; }
  .composer { flex-wrap: wrap; }
  .composer select { flex: 1 1 100%; }
  .composer textarea { flex: 1; min-width: 0; }

  /* flow editor: canvas on top, step settings underneath */
  .builder { grid-template-columns: 1fr; grid-template-rows: 55dvh auto; height: auto; }
  .inspector { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  #flow-name { width: 100% !important; min-width: 0; }
  .topbar h2:has(#flow-name) { flex: 1 1 calc(100% - 52px); overflow: visible; }
  .topbar h2:has(#flow-name) .row { min-width: 0; }
  #save-state { display: none; }
  .topbar .btn { padding: 7px 11px; }
  /* step buttons become one scrollable strip along the top of the canvas */
  .palette { left: 0; right: 0; top: 0; flex-direction: row; overflow-x: auto; padding: 8px; gap: 6px;
    background: linear-gradient(#f2f4f8 70%, transparent); scrollbar-width: none; }
  .palette button { padding: 6px 10px; font-size: 13px; flex: none; }
  .zoombar { right: 8px; bottom: 8px; }
  .sim-float { inset: 0; right: 0; bottom: 0; width: auto; height: auto; border-radius: 0; z-index: 60; }
}
