:root {
            --bg-dark: #f8fafc; /* Changed to lighter for Chat like EmLaw */
            --bg-panel: #ffffff;
            --border-color: #e2e8f0;
            --text-main: #334155;
            --text-muted: #64748b;
            --accent: #4f46e5;
            --accent-hover: #4338ca;
        }
        
        * { box-sizing: border-box; margin: 0; padding: 0; }
        body {
            font-family: 'Inter', sans-serif;
            background-color: var(--bg-dark);
            color: var(--text-main);
            height: 100vh;
            display: flex;
            overflow: hidden;
        }

        /* ── TWO PANE LAYOUT ── */
        .layout-container {
            display: flex;
            width: 100%;
            height: 100%;
        }

        /* ── LEFT PANE: CHAT ── */
        .left-pane {
            width: 400px;
            background: var(--bg-panel);
            border-right: 1px solid var(--border-color);
            display: flex;
            flex-direction: column;
            position: relative;
            flex-shrink: 0;
            box-shadow: 4px 0 15px rgba(0,0,0,0.02);
            z-index: 10;
        }

        .chat-header {
            padding: 16px;
            border-bottom: 1px solid var(--border-color);
            display: flex;
            justify-content: space-between;
            align-items: center;
            background: #f8fafc;
        }
        
        .chat-header h2 { font-size: 16px; font-weight: 600; color: #0f172a; }

        .btn-icon {
            background: none; border: none; cursor: pointer;
            color: var(--text-muted); font-size: 16px;
            padding: 8px; border-radius: 6px;
            transition: all 0.2s;
        }
        .btn-icon:hover { background: #e2e8f0; color: #0f172a; }

        .chat-messages {
            flex: 1;
            overflow-y: auto;
            padding: 24px 16px;
            display: flex;
            flex-direction: column;
            gap: 20px;
            scroll-behavior: smooth;
        }

        .chat-msg {
            max-width: 90%;
            padding: 12px 16px;
            border-radius: 12px;
            font-size: 14px;
            line-height: 1.5;
            animation: fadeIn 0.3s ease;
        }
        @keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

        .user-msg {
            align-self: flex-end;
            background: var(--accent);
            color: white;
            border-bottom-right-radius: 4px;
        }

        .ai-msg {
            align-self: flex-start;
            background: #f1f5f9;
            color: var(--text-main);
            border-bottom-left-radius: 4px;
            width: 100%;
        }

        .agent-process {
            border-radius: 12px;
            margin-bottom: 10px;
            overflow: hidden;
            border: 1px solid #e2e8f0;
            background: #fafbfd;
        }
        .agent-process-header {
            display: flex; align-items: center; gap: 8px;
            padding: 10px 14px;
            cursor: pointer;
            user-select: none;
            background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
            border-bottom: 1px solid #e2e8f0;
            transition: background 0.2s;
        }
        .agent-process-header:hover { background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%); }
        .agent-process-header .process-icon {
            width: 24px; height: 24px; border-radius: 50%;
            background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
            display: flex; align-items: center; justify-content: center;
            color: white; font-size: 11px; flex-shrink: 0;
        }
        .agent-process-header .process-icon.done {
            background: linear-gradient(135deg, #10b981 0%, #059669 100%);
        }
        .agent-process-header .process-label {
            font-size: 13px; font-weight: 600; color: #334155; flex: 1;
        }
        .agent-process-header .process-toggle {
            font-size: 10px; color: #94a3b8;
            transition: transform 0.3s;
        }
        .agent-process.collapsed .process-toggle { transform: rotate(-90deg); }
        .agent-process-body {
            padding: 12px 14px;
            max-height: 350px;
            overflow-y: auto;
            transition: max-height 0.3s ease, padding 0.3s ease;
        }
        .agent-process.collapsed .agent-process-body {
            max-height: 0; padding: 0 14px; overflow: hidden;
        }

        /* Thinking stream */
        .thinking-stream {
            color: #64748b; font-size: 13px; font-style: italic;
            line-height: 1.6; white-space: pre-wrap;
            border-left: 2px solid #a78bfa;
            padding-left: 12px; margin-bottom: 8px;
        }
        @keyframes shimmer {
            0% { background-position: -200% 0; }
            100% { background-position: 200% 0; }
        }
        .thinking-stream.streaming {
            border-image: linear-gradient(180deg, #a78bfa, #6366f1, #a78bfa) 1;
        }

        /* Process steps */
        .process-step {
            display: flex; align-items: flex-start; gap: 8px;
            padding: 6px 0; font-size: 12px; color: #475569;
        }
        .process-step .step-icon {
            width: 18px; height: 18px; border-radius: 50%;
            display: flex; align-items: center; justify-content: center;
            font-size: 9px; flex-shrink: 0; margin-top: 1px;
        }
        .process-step .step-icon.query { background: #ede9fe; color: #7c3aed; }
        .process-step .step-icon.success { background: #d1fae5; color: #059669; }
        .process-step .step-icon.error { background: #fee2e2; color: #dc2626; }
        .process-step .step-icon.reflect { background: #fef3c7; color: #d97706; }
        .process-step .step-text { flex: 1; line-height: 1.4; }
        .process-step .step-text .step-label { font-weight: 600; color: #334155; }
        .process-step .step-text .step-detail {
            display: block; font-size: 11px; color: #94a3b8; margin-top: 2px;
            font-family: 'JetBrains Mono', 'Fira Code', monospace;
        }

        /* Tool chips */
        .tool-chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
        .tool-chip {
            display: inline-flex; align-items: center; gap: 4px;
            padding: 3px 8px; border-radius: 6px; font-size: 11px; font-weight: 500;
            background: #f1f5f9; border: 1px solid #e2e8f0; color: #475569;
        }
        .tool-chip.pending { border-color: #c7d2fe; background: #eef2ff; color: #4f46e5; }
        .tool-chip.success { border-color: #a7f3d0; background: #ecfdf5; color: #059669; }
        .tool-chip.error { border-color: #fecaca; background: #fef2f2; color: #dc2626; }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        .chat-input-area {
            padding: 16px;
            border-top: 1px solid var(--border-color);
            background: white;
        }
        
        .chat-input-wrapper {
            position: relative;
            display: flex;
            align-items: flex-end;
            background: #f8fafc;
            border: 1px solid #cbd5e1;
            border-radius: 16px;
            padding: 4px;
            transition: border-color 0.2s;
        }
        .chat-input-wrapper:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(79,70,229,0.1); }

        .chat-input-wrapper textarea {
            flex: 1;
            border: none;
            background: transparent;
            padding: 12px;
            max-height: 120px;
            min-height: 44px;
            resize: none;
            outline: none;
            font-family: inherit;
            font-size: 14px;
            color: var(--text-main);
        }

        .btn-send {
            width: 36px;
            height: 36px;
            border-radius: 12px;
            border: none;
            background: var(--accent);
            color: white;
            display: flex; align-items: center; justify-content: center;
            cursor: pointer;
            margin: 4px;
            transition: all 0.2s;
        }
        .btn-send:hover { background: var(--accent-hover); transform: scale(1.05); }
        .btn-send:disabled { background: #cbd5e1; cursor: not-allowed; transform: none; }

        /* ── HISTORY SIDEBAR (Slide-over) ── */
        .history-sidebar {
            position: absolute;
            top: 0; left: 0; bottom: 0;
            width: 100%;
            background: white;
            z-index: 20;
            transform: translateX(-100%);
            transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            display: flex; flex-direction: column;
        }
        .history-sidebar.open { transform: translateX(0); }
        
        .history-header {
            padding: 16px; border-bottom: 1px solid var(--border-color);
            display: flex; justify-content: space-between; align-items: center;
        }
        .conv-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
        .conv-item {
            padding: 12px; border-radius: 8px; cursor: pointer;
            border: 1px solid transparent; transition: all 0.2s;
        }
        .conv-item:hover { background: #f1f5f9; }
        .conv-item.active { background: #eef2ff; border-color: #c7d2fe; }
        .conv-title { font-size: 13px; font-weight: 600; line-height: 1.4; margin-bottom: 4px; }
        .conv-meta { font-size: 11px; color: var(--text-muted); }

        /* ── RIGHT PANE: DOCUMENT ── */
        .right-pane {
            flex: 1;
            display: flex;
            flex-direction: column;
            background: #f1f5f9; /* Outer background */
            position: relative;
        }

        .doc-header {
            height: 60px;
            padding: 0 24px;
            background: white;
            border-bottom: 1px solid var(--border-color);
            display: flex; align-items: center; justify-content: space-between;
        }

        .doc-versions {
            display: flex; align-items: center; gap: 12px;
            background: #f8fafc; padding: 4px; border-radius: 8px; border: 1px solid #e2e8f0;
        }
        .version-btn {
            background: white; border: 1px solid #cbd5e1; border-radius: 4px;
            padding: 4px 10px; cursor: pointer; font-size: 12px; font-weight: 600; color: var(--text-main);
            transition: all 0.2s;
        }
        .version-btn:hover:not(:disabled) { background: #e2e8f0; }
        .version-btn:disabled { opacity: 0.5; cursor: not-allowed; }
        .version-label { font-size: 13px; font-weight: 700; min-width: 40px; text-align: center; color: var(--accent); }

        .doc-actions { display: flex; gap: 8px; }
        .btn-action {
            padding: 8px 16px; border-radius: 8px; font-size: 13px; font-weight: 600;
            cursor: pointer; border: 1px solid var(--border-color); background: white;
            display: flex; align-items: center; gap: 6px; transition: all 0.2s;
        }
        .btn-action:hover { background: #f8fafc; border-color: #cbd5e1; }

        .doc-scroll {
            flex: 1; overflow-y: auto; padding: 40px;
            display: flex; justify-content: center;
        }

        .doc-paper {
            width: 100%; max-width: 900px;
            background: white;
            border-radius: 8px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.05);
            min-height: 1000px; /* A4 aspect ratio approximation */
            padding: 60px;
            position: relative;
        }

        /* INLINE EDIT POPUP (Same as before) */
        #inlineEditPopup {
            position: absolute; display: none; z-index: 1000;
            background: white; border: 1px solid #e2e8f0; border-radius: 12px;
            box-shadow: 0 10px 25px rgba(0,0,0,0.1); padding: 8px; width: 280px;
        }
        .inline-edit-btn {
            display: block; width: 100%; text-align: left; padding: 10px 12px;
            border: none; background: none; cursor: pointer; font-size: 13px; color: #334155;
            border-radius: 6px; transition: background 0.2s;
        }
        .inline-edit-btn:hover { background: #f1f5f9; color: #4f46e5; }
        .inline-edit-btn i { width: 20px; color: #64748b; }

        /* LOADING SPINNER */
        .chat-typing { display: flex; gap: 4px; padding: 10px; align-items: center; }
        .dot { width: 6px; height: 6px; background: #94a3b8; border-radius: 50%; animation: bounce 1.4s infinite ease-in-out both; }
        .dot:nth-child(1) { animation-delay: -0.32s; }
        .dot:nth-child(2) { animation-delay: -0.16s; }
        @keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }
        
        /* HIDE PRINT BUTTON FROM LLM OUTPUT */
        .print-btn, .no-print { display: none !important; }

        .empty-doc-state {
            height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
            color: #94a3b8; text-align: center;
        }
        .empty-icon { font-size: 64px; margin-bottom: 24px; opacity: 0.5; }
@media print {
    .left-pane, .doc-header { display: none !important; }
    .layout-container { display: block; }
    .right-pane { background: white; }
    .doc-scroll { overflow: visible; padding: 0; }
    .doc-paper { box-shadow: none; padding: 0; border: none; min-height: 0; }
    body { background: white; }
}