body { margin:0; font-family:var(--font-sans, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif); background:var(--background,#faf9f7); color:var(--foreground,#1c1917); }

.page-wrap { max-width:1400px; margin:0 auto; padding:16px 20px; }

/* Header — same as tag-search */
.page-header { margin-bottom:12px; display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap; gap:8px; }
.page-header h1 { font-size:20px; font-weight:700; margin:0; }
.page-header p { font-size:12px; color:var(--muted-fg,#78716c); margin:2px 0 0; }
.header-badges { display:flex; gap:6px; align-items:center; }
.header-badge { padding:3px 10px; font-size:11px; font-weight:600; border-radius:12px; background:#f0efec; color:#78716c; }
.session-badge { padding:3px 10px; font-size:10px; font-weight:500; border-radius:12px; background:#dbeafe; color:#3b82f6; font-family:'Consolas',monospace; }

/* ═══════ 2-Column Layout ═══════ */
.split-layout { display:grid; grid-template-columns:1fr 1fr; gap:12px; height:calc(100vh - 120px); min-height:450px; }

/* Left: Chat Panel */
.chat-panel { display:flex; flex-direction:column; background:var(--card,#fff); border:1px solid var(--border,#e7e5e2); border-radius:12px; overflow:hidden; }

.chat-messages { flex:1; overflow-y:auto; padding:16px; display:flex; flex-direction:column; gap:10px; }
.chat-messages::-webkit-scrollbar { width:3px; }
.chat-messages::-webkit-scrollbar-thumb { background:rgba(0,0,0,.08); border-radius:4px; }

.msg { max-width:88%; padding:9px 13px; border-radius:12px; font-size:13px; line-height:1.5; word-break:break-word; }
.msg.user { align-self:flex-end; background:var(--primary,#1c1917); color:#fff; border-bottom-right-radius:4px; }
.msg.ai { align-self:flex-start; background:var(--muted,#f0efec); color:var(--foreground); border-bottom-left-radius:4px; }
.msg.ai .meta { margin-top:5px; font-size:10px; color:var(--muted-fg,#78716c); display:flex; gap:6px; }
.msg.system { align-self:center; font-size:11px; color:var(--muted-fg); font-style:italic; background:none; padding:4px 0; }
.msg.error { align-self:center; font-size:11px; color:#dc2626; background:rgba(220,38,38,.05); padding:6px 12px; }

/* Markdown in AI messages */
.msg.ai a { color:var(--primary); text-decoration:underline; }
.msg.ai strong { font-weight:600; }
.msg.ai code { background:var(--muted); padding:1px 4px; border-radius:3px; font-size:11.5px; }
.msg.ai p { margin: 0 0 8px 0; }
.msg.ai p:last-child { margin: 0; }
.msg.ai ul, .msg.ai ol { margin: 0 0 8px 0; padding-left: 20px; }
.msg.ai li { margin-bottom: 2px; }

/* Quick actions */
.quick-actions { padding:6px 12px; display:flex; gap:5px; flex-wrap:wrap; border-top:1px solid var(--border); background:var(--card); }
.quick-btn { padding:4px 10px; font-size:11px; border:1px solid var(--border); border-radius:14px; background:var(--background); cursor:pointer; color:var(--foreground); transition:all .15s; }
.quick-btn:hover { background:var(--muted); border-color:var(--muted-fg); }

/* Input */
.chat-input { border-top:1px solid var(--border); padding:10px 12px; display:flex; gap:6px; background:var(--card); }
.chat-input textarea { flex:1; padding:9px 12px; border:1px solid var(--border); border-radius:8px; font-size:13px; outline:none; background:var(--background); transition:border-color .2s; resize:none; font-family:inherit; }
.chat-input textarea:focus { border-color:var(--primary); }
.chat-input button { padding:9px 16px; background:var(--primary,#1c1917); color:#fff; border:none; border-radius:8px; font-size:12px; font-weight:600; cursor:pointer; transition:opacity .2s; white-space:nowrap; }
.chat-input button:hover { opacity:.85; }
.chat-input button:disabled { opacity:.5; cursor:not-allowed; }
.btn-clear { background:#dc2626 !important; }
.btn-clear:hover { background:#b91c1c !important; }

/* Thinking animation */
.thinking { display:flex; gap:4px; padding:8px 13px; }
.thinking span { width:5px; height:5px; border-radius:50%; background:var(--muted-fg); animation:bounce 1.4s ease-in-out infinite; }
.thinking span:nth-child(2) { animation-delay:.2s; }
.thinking span:nth-child(3) { animation-delay:.4s; }
@keyframes bounce { 0%,80%,100%{transform:translateY(0)} 40%{transform:translateY(-7px)} }

/* Pipeline trace (inside chat) */
.pipeline-trace { display:flex; flex-direction:column; gap:0; }
.p-step { position:relative; padding:8px 10px 8px 24px; margin:0; }
.p-step:not(:last-child) { border-left:2px solid var(--border); margin-left:5px; padding-bottom:10px; }
.p-step:last-child { border-left:2px solid transparent; margin-left:5px; }

.p-step::before { content:''; position:absolute; left:-1px; top:11px; width:8px; height:8px; border-radius:50%; border:2px solid var(--border); background:var(--card); z-index:1; margin-left:-3px; }
.p-step.s-planner::before { background:#f59e0b; border-color:#f59e0b; }
.p-step.s-tool_result::before { background:#10b981; border-color:#10b981; }
.p-step.s-responder::before { background:#3b82f6; border-color:#3b82f6; }

.p-step .step-label { font-size:10px; font-weight:700; margin-bottom:2px; }
.p-step.s-planner .step-label { color:#f59e0b; }
.p-step.s-tool_result .step-label { color:#10b981; }
.p-step.s-responder .step-label { color:#3b82f6; }
.p-step .step-content { font-size:11px; line-height:1.4; color:var(--muted-fg); word-break:break-word; }

@keyframes slideIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }
.p-step { animation:slideIn .3s ease-out; }

/* ═══════ RIGHT: Diagram Panel ═══════ */
.diagram-panel { display:flex; flex-direction:column; background:var(--card,#fff); border:1px solid var(--border,#e7e5e2); border-radius:12px; overflow:hidden; }

.diagram-header { padding:10px 14px; border-bottom:1px solid var(--border); display:flex; align-items:center; justify-content:space-between; }
.diagram-header h3 { font-size:13px; font-weight:700; margin:0; }
.diagram-toolbar { display:flex; gap:4px; align-items:center; }
.toolbar-btn { padding:4px 10px; font-size:11px; border:1px solid var(--border); border-radius:8px; background:var(--background); cursor:pointer; color:var(--foreground); transition:all .15s; }
.toolbar-btn:hover { background:var(--muted); border-color:var(--muted-fg); }
.zoom-label { font-size:10px; font-weight:600; color:var(--muted-fg); min-width:38px; text-align:center; font-family:var(--font-mono); }

.diagram-canvas { flex:1; overflow:hidden; position:relative; background:var(--background); cursor:grab; user-select:none; }
.diagram-canvas.grabbing { cursor:grabbing; }
.diagram-canvas::-webkit-scrollbar { display:none; }

/* Grid background like draw.io */
.diagram-canvas::before { content:''; position:absolute; inset:0; background-image:radial-gradient(circle, var(--border) 0.5px, transparent 0.5px); background-size:20px 20px; opacity:.4; pointer-events:none; z-index:0; }

#diagramOutput { position:absolute; top:0; left:0; transform-origin:0 0; transition:none; will-change:transform; z-index:1; }
#diagramOutput svg { display:block; max-width:none; height:auto; }

/* Empty state */
.empty-state { text-align:center; color:var(--muted-fg); padding:40px; }
.empty-state .icon { font-size:56px; margin-bottom:12px; opacity:.5; }
.empty-state h3 { font-size:16px; font-weight:600; color:var(--secondary-fg); margin-bottom:6px; }
.empty-state p { font-size:12px; line-height:1.6; max-width:280px; margin:0 auto; }

/* Diagram info bar */
.diagram-info { padding:6px 14px; border-top:1px solid var(--border); display:flex; align-items:center; justify-content:space-between; font-size:10px; color:var(--muted-fg); background:var(--card); }

/* Mermaid code viewer */
.code-viewer { display:none; padding:12px 14px; border-top:1px solid var(--border); background:rgba(0,0,0,.02); max-height:180px; overflow:auto; }
.code-viewer.show { display:block; }
.code-viewer pre { font-family:var(--font-mono,'Consolas','Monaco',monospace); font-size:11px; color:var(--foreground); white-space:pre-wrap; line-height:1.5; margin:0; }

@media (max-width:900px) {
    .split-layout { grid-template-columns:1fr; }
    .split-layout > * { min-height:350px; }
}