:root {
  --ink: #14213d;
  --ink-soft: #4a5578;
  --paper: #f7f7f5;
  --panel: #ffffff;
  --line: #e4e4e0;
  --accent: #1f6f5c;
  --accent-soft: #e4f2ee;
  --danger: #b3432b;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--paper);
  color: var(--ink);
}

/* login */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 32px; width: 320px; }
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card .hint { color: var(--ink-soft); font-size: 13px; margin-bottom: 20px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; }

/* shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
nav { background: var(--ink); color: #fff; padding: 24px 16px; }
nav h1 { font-size: 17px; margin: 0 0 28px; letter-spacing: 0.02em; }
nav .tab { display: block; padding: 10px 12px; border-radius: 8px; color: #cdd3e4; text-decoration: none; font-size: 14px; margin-bottom: 4px; cursor: pointer; }
nav .tab.active, nav .tab:hover { background: rgba(255,255,255,0.08); color: #fff; }
main { padding: 32px 40px; max-width: 1100px; }
.panel { display: none; }
.panel.active { display: block; }
h2 { font-size: 20px; margin-top: 0; }
h3 { font-size: 15px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
button { background: var(--accent); color: #fff; border: none; padding: 9px 16px; border-radius: 7px; font-size: 14px; cursor: pointer; margin-right: 8px; }
button.secondary { background: var(--accent-soft); color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
input, textarea, select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px;
  font-size: 14px; font-family: inherit; margin-bottom: 10px;
}
label { font-size: 12px; color: var(--ink-soft); display:block; margin-bottom:4px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
th { color: var(--ink-soft); font-weight: 600; }
.pill { display:inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; }
.pill.connected, .pill.sent, .pill.active { background:#e4f2ee; color:#1f6f5c; }
.pill.failed, .pill.error { background:#fbe6e0; color:#b3432b; }
.pill.inactive, .pill.connecting, .pill.received { background:#eef0f8; color:#4a5578; }
.row { display:flex; gap:10px; align-items:flex-end; }
.row > div { flex: 1; }
small.hint { color: var(--ink-soft); }
#qrImg { width: 220px; height: 220px; border: 8px solid #fff; box-shadow: 0 0 0 1px var(--line); border-radius: 8px; }
.channel-add-row button { margin-bottom: 0; }

/* flow builder */
.flow-editor { display: grid; grid-template-columns: 180px 1fr 260px; gap: 16px; height: 520px; padding: 12px; }
.flow-palette button { display:block; width:100%; margin-bottom:6px; text-align:left; }
.flow-canvas-wrap { position: relative; border: 1px dashed var(--line); border-radius: 8px; overflow: auto; background: #fbfbfa; }
#flowEdges { position: absolute; top: 0; left: 0; width: 1200px; height: 900px; pointer-events: none; }
#flowCanvas { position: relative; width: 1200px; height: 900px; }
.flow-node {
  position: absolute; width: 160px; background: #fff; border: 1.5px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; cursor: grab; user-select: none;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.flow-node.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.flow-node.connecting-source { border-color: #2f9e5c; box-shadow: 0 0 0 3px rgba(47,158,92,0.25); }
.flow-node .node-type { font-weight: 600; color: var(--accent); text-transform: uppercase; font-size: 10px; margin-bottom: 4px; }
.flow-node .node-summary { color: var(--ink-soft); word-break: break-word; }
.flow-dot { position: absolute; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; cursor: crosshair; box-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.flow-dot:hover { transform: scale(1.15); }
.flow-dot.out { right: -9px; top: 50%; margin-top: -9px; }
.flow-dot.out-true { right: -9px; top: 30%; margin-top: -9px; background:#2f9e5c; }
.flow-dot.out-false { right: -9px; top: 70%; margin-top: -9px; background:#b3432b; }
.flow-dot.in { left: -9px; top: 50%; margin-top: -9px; background: #94a3b8; }
.connect-banner { display:none; background: #eef7f1; border: 1px solid #b7ddc4; color: #1f6f5c; padding: 8px 14px; border-radius: 8px; margin-bottom: 10px; font-size: 13px; }
.flow-inspector { border-left: 1px solid var(--line); padding-left: 16px; overflow-y: auto; }

/* inbox */
.inbox-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; height: 560px; }
.inbox-list { padding: 8px; overflow-y: auto; }
.conv-row { padding: 10px 12px; border-radius: 8px; cursor: pointer; margin-bottom: 4px; }
.conv-row:hover { background: var(--paper); }
.conv-row.active { background: var(--accent-soft); }
.conv-name { font-size: 13px; font-weight: 600; }
.conv-preview { font-size: 12px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-thread { display: flex; flex-direction: column; padding: 12px; }
.thread-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 4px; }
.msg-bubble { max-width: 70%; padding: 8px 12px; border-radius: 10px; font-size: 13px; }
.msg-bubble.in { align-self: flex-start; background: #eef0f8; }
.msg-bubble.out { align-self: flex-end; background: var(--accent-soft); }
.msg-time { font-size: 10px; color: var(--ink-soft); margin-top: 3px; }
.thread-reply { display: flex; gap: 8px; margin-top: 10px; }
.thread-reply input { margin-bottom: 0; }
.thread-reply button { margin: 0; }
.msg-media-img { max-width: 220px; border-radius: 8px; display: block; cursor: pointer; }
.msg-media-video { max-width: 240px; border-radius: 8px; display: block; }
.msg-caption { margin-top: 6px; font-size: 13px; }
.msg-doc-link { color: var(--accent); text-decoration: underline; font-size: 13px; }
