/* --- Reset & Base Styles --- */
        * { box-sizing: border-box; }
        body {
            margin: 0;
            padding: 0;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
            display: flex;
            height: 100vh;
            background-color: #f3f4f6;
            color: #1e293b;
            font-size: 14px;
            overflow: hidden;
        }

        /* --- Custom A.I.E Logo Styles --- */
        .aie-logo-wrapper {
            display: flex; flex-direction: column; align-items: center;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            line-height: 1; user-select: none;
        }
        .aie-stack { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; margin-bottom: 6px; }
        .aie-row { display: flex; align-items: center; gap: 8px; }
        .aie-letter { font-weight: 900; font-size: 24px; width: 22px; text-align: center; }
        .aie-a { color: #111; }
        .aie-i { height: 22px; width: 8px; margin-left: 7px; background: linear-gradient(to bottom, #0284c7, #1e3a8a); }
        .aie-e { 
            color: transparent; 
            background: linear-gradient(to bottom, #0284c7, #1e3a8a); 
            -webkit-background-clip: text; background-clip: text; 
            font-family: Impact, sans-serif; 
        }
        .aie-word { font-size: 14px; font-weight: 600; color: #333; letter-spacing: 0.5px; }
        .aie-consulting { 
            font-weight: 800; font-size: 16px; letter-spacing: 3px; color: #111; 
            border-top: 1px solid #cbd5e1; padding-top: 6px; width: 100%; text-align: center;
        }
        .aie-sub { font-size: 9px; color: #64748b; white-space: nowrap; margin-top: 4px; }

        /* Dark Mode Logo Overrides (for Sidebar) */
        .dark-mode .aie-a { color: #fff; }
        .dark-mode .aie-word { color: #f8fafc; }
        .dark-mode .aie-consulting { color: #fff; border-color: #475569; }
        .dark-mode .aie-sub { color: #94a3b8; }

        /* Client Logo Placeholder */
        .client-logo-placeholder {
            width: 100%; height: 100%; min-height: 70px;
            display: flex; align-items: center; justify-content: center; text-align: center;
            border: 2px dashed #cbd5e1; border-radius: 8px;
            color: #64748b; font-weight: bold; text-transform: uppercase;
            letter-spacing: 1px; cursor: pointer; background: #f8fafc;
            transition: all 0.2s; font-size: 14px; padding: 10px;
        }
        .client-logo-placeholder:hover { background: #f1f5f9; border-color: #94a3b8; color: #334155; }

        /* --- Layout Structure --- */
        .sidebar {
            width: 270px;
            background-color: #1e293b;
            color: #fff;
            display: flex;
            flex-direction: column;
            box-shadow: 4px 0 10px rgba(0,0,0,0.1);
            z-index: 20;
            transition: margin-left 0.3s ease;
        }
        .sidebar.pc-closed {
            margin-left: -270px;
        }
        .sidebar-header { padding: 24px 16px; border-bottom: 1px solid #334155; display: flex; justify-content: center; }
        .sidebar-padd { padding: 16px; }
        
        .btn-primary {
            width: 100%;
            background-color: #2563eb;
            color: #fff;
            border: none;
            padding: 10px;
            border-radius: 4px;
            cursor: pointer;
            font-weight: bold;
            transition: background 0.2s;
        }
        .btn-primary:hover { background-color: #1d4ed8; }

        .btn-secondary {
            background-color: #475569;
            color: #fff;
            border: none;
            padding: 8px 12px;
            border-radius: 4px;
            cursor: pointer;
            font-weight: bold;
            font-size: 12px;
            transition: background 0.2s;
            white-space: nowrap;
        }
        .btn-secondary:hover { background-color: #334155; }
        
        .sop-list { flex: 1; overflow-y: auto; padding: 0 8px; }
        .sop-item {
            padding: 12px; margin-bottom: 8px; border-radius: 4px; cursor: pointer;
            background-color: #334155; color: #e2e8f0; transition: all 0.2s;
        }
        .sop-item:hover { background-color: #475569; }
        .sop-item.active { background-color: #2563eb; color: #fff; }
        .sop-item-docno { font-size: 11px; font-family: monospace; color: #cbd5e1; margin-bottom: 4px; }
        .sop-item-name { 
            font-size: 14px; font-weight: 600; 
            display: flex; justify-content: space-between; align-items: center; 
        }
        .sop-item-name span {
            white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
        }
        
        .delete-sop-btn {
            background-color: transparent;
            color: #ef4444;
            border: none;
            padding: 6px;
            cursor: pointer;
            border-radius: 4px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.2s ease;
        }
        .delete-sop-btn:hover {
            background-color: #ef4444;
            color: #fff;
        }

        .main-wrapper { flex: 1; display: flex; flex-direction: column; min-width: 0; }
        
        /* --- Header & Form Fields --- */
        .header { background: #fff; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1); z-index: 10; border-bottom: 4px solid #60a5fa; display: flex; flex-direction: column; }
        
        .toolbox {
            display: flex; align-items: center; padding: 12px 16px;
            background-color: #f8fafc; border-bottom: 1px solid #e2e8f0; gap: 24px; overflow-x: auto;
        }
        .toolbox-label { font-weight: bold; color: #64748b; text-transform: uppercase; font-size: 12px; }
        .toolbox-hint { margin-left: auto; font-size: 12px; color: #94a3b8; line-height: 1.5; display: flex; align-items: center; gap: 12px;}
        .hint-text-group { display: flex; flex-direction: column; gap: 2px; }
        .hint-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
        .hint-dot.red { background-color: #ef4444; }
        .hint-dot.blue { background-color: #3b82f6; }

        .toolbar-group { display: flex; gap: 8px; border-left: 2px solid #cbd5e1; padding-left: 16px;}

        .header-data { display: flex; align-items: stretch; border-top: 1px solid #e2e8f0; }
        .header-data.details-collapsed .logo-container,
        .header-data.details-collapsed .form-grid {
            display: none;
        }
        
        .logo-container {
            width: 250px; display: flex; flex-direction: column; justify-content: center; align-items: center;
            border-right: 1px solid #e2e8f0; padding: 12px 8px; background: #fff;
        }
        
        .form-container { flex: 1; padding: 12px; display: flex; flex-direction: column; }
        
        .process-title-display { 
            text-align: center; font-weight: bold; font-size: 18px; margin-bottom: 8px; color: #1e293b;
            padding: 4px 8px; border-radius: 4px; outline: none; cursor: text; transition: all 0.2s;
        }
        .process-title-display:hover, .process-title-display:focus {
            background: #f1f5f9; box-shadow: inset 0 0 0 1px #cbd5e1;
        }
        
        .form-grid {
            display: grid; grid-template-columns: repeat(6, 1fr); gap: 1px;
            background-color: #cbd5e1; border: 1px solid #cbd5e1;
        }
        .form-cell-label { background-color: #1e293b; color: #fff; font-size: 11px; font-weight: bold; padding: 8px; display: flex; align-items: center; }
        .form-cell-input { background-color: #fff; border: none; padding: 8px; font-size: 13px; outline: none; width: 100%; color: #334155; font-family: inherit; margin: 0; }
        .col-span-3 { grid-column: span 3; }
        .bg-light { background-color: #f8fafc; font-family: monospace; }
        .font-semibold { font-weight: 600; }

        /* --- Workspace Areas --- */
        .workspace-content {
            flex: 1;
            position: relative;
            overflow: hidden; 
            background-color: #e2e8f0;
        }

        /* --- Canvas & Grid --- */
        .canvas-container {
            position: absolute; top: 0; left: 0; width: 100%; height: 100%;
            overflow: hidden; 
        }
        
        #canvas { 
            width: 4000px; height: 3000px; position: absolute; 
            background-color: #ffffff;
            background-image: 
                linear-gradient(to right, #e5e7eb 1px, transparent 1px),
                linear-gradient(to bottom, #e5e7eb 1px, transparent 1px);
            background-size: 20px 20px;
            transform-origin: 0 0; 
            box-shadow: 0 0 20px rgba(0,0,0,0.1);
        }

        /* --- Documentation Tab --- */
        .documentation-container {
            position: absolute; top: 0; left: 0; width: 100%; height: 100%;
            overflow: auto;
            background-color: #ffffff;
            padding: 24px;
            display: none; 
        }
        
        .docs-header-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 16px;
        }

        .doc-filter-banner {
            background-color: #e0f2fe; border: 1px solid #7dd3fc; color: #0369a1;
            padding: 12px 16px; border-radius: 6px; margin-bottom: 16px;
            display: flex; justify-content: space-between; align-items: center; font-weight: 600;
        }

        .docs-table {
            width: 100%;
            border-collapse: collapse;
            border: 1px solid #94a3b8;
        }
        
        .docs-table th {
            background-color: #2b579a;
            color: white;
            border: 1px solid #94a3b8;
            padding: 10px;
            font-size: 13px;
            font-weight: 600;
            text-align: center;
        }
        
        .docs-table td {
            border: 1px solid #cbd5e1;
            padding: 0;
            vertical-align: top;
        }
        
        .docs-table .text-center { text-align: center; vertical-align: middle; }
        
        .doc-input {
            width: 100%;
            height: 100%;
            min-height: 40px;
            border: none;
            padding: 8px;
            font-family: inherit;
            font-size: 13px;
            background: transparent;
            resize: vertical;
            outline: none;
        }
        
        .doc-input:focus {
            background: #f8fafc;
            box-shadow: inset 0 0 0 2px #3b82f6;
        }

        .btn-delete-row {
            background: #ef4444; color: white; border: none; border-radius: 4px;
            padding: 4px 8px; cursor: pointer; font-weight: bold; margin: 4px;
        }
        .btn-delete-row:hover { background: #dc2626; }

        /* --- Tab Bar (Bottom) --- */
        .tab-bar {
            background-color: #000;
            display: flex;
            align-items: flex-end;
            padding: 0 16px;
            height: 40px;
            z-index: 30;
        }
        .tab-btn {
            background-color: #333;
            color: #ccc;
            padding: 8px 24px;
            margin-right: 4px;
            border-radius: 6px 6px 0 0;
            font-size: 13px;
            font-weight: 600;
            cursor: pointer;
            border: 1px solid #444;
            border-bottom: none;
            transition: all 0.2s;
        }
        .tab-btn:hover { background-color: #444; color: #fff; }
        .tab-btn.active {
            background-color: #fff;
            color: #000;
            border-top: 1px solid #ccc;
            border-left: 1px solid #ccc;
            border-right: 1px solid #ccc;
            border-bottom: 3px solid #16a34a; 
        }

        /* --- SVG Line Layer --- */
        #svg-layer {
            position: absolute; top: 0; left: 0; width: 100%; height: 100%;
            pointer-events: none; z-index: 5;
        }
        path.connection {
            fill: none; stroke: #333; stroke-width: 2;
            pointer-events: stroke; cursor: pointer;
        }
        path.connection:hover { stroke: #ef4444; stroke-width: 3; }
        
        #temp-line { pointer-events: none !important; }

        /* --- Toolbar Shapes --- */
        .toolbar-shape {
            cursor: grab; display: flex; align-items: center; justify-content: center;
            font-size: 12px; font-weight: 600; color: white; text-align: center;
            box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
        }
        .shape-activity { background: #3b82f6; border-radius: 8px; width: 100px; height: 50px; }
        .shape-process { background: #06b6d4; border: 3px double white; width: 100px; height: 50px; }
        .shape-decision { background: #84cc16; width: 80px; height: 80px; clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); }
        .shape-database { background: #b91c1c; border-radius: 50% / 20%; width: 90px; height: 60px; position: relative; }
        .shape-database::before { content: ''; position: absolute; top: -5px; width: 100%; height: 20px; border-radius: 50%; background: #dc2626; border: 1px solid #7f1d1d;}
        .shape-form { background: #f97316; border-radius: 4px; width: 90px; height: 60px; clip-path: polygon(0 0, 70% 0, 100% 30%, 100% 100%, 0 100%); }

        /* --- Canvas Nodes & Graphical Layers --- */
        .canvas-node {
            position: absolute; z-index: 10; cursor: move; display: flex; align-items: center; justify-content: center;
            color: white; font-weight: bold; font-size: 12px; text-align: center; padding: 8px;
            user-select: none; transition: filter 0.2s;
            filter: drop-shadow(0 4px 3px rgba(0,0,0,0.3));
        }
        .canvas-node:hover { filter: drop-shadow(0 0 6px #facc15) drop-shadow(0 4px 3px rgba(0,0,0,0.3)); }

        .shape-bg {
            position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 0;
        }

        .canvas-node[data-shape="activity"] { width: 140px; min-height: 70px; height: auto; }
        .canvas-node[data-shape="process"] { width: 140px; min-height: 70px; height: auto; }
        .canvas-node[data-shape="decision"] { width: 120px; min-height: 120px; height: auto; padding: 24px; }
        .canvas-node[data-shape="database"] { width: 120px; min-height: 80px; height: auto; padding: 12px; }
        .canvas-node[data-shape="form"] { width: 140px; min-height: 70px; height: auto; }

        .canvas-node[data-shape="activity"] .shape-bg { background: #3b82f6; border-radius: 8px; }
        .canvas-node[data-shape="process"] .shape-bg { background: #06b6d4; border: 4px double white; }
        .canvas-node[data-shape="decision"] .shape-bg { background: #84cc16; clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); }
        .canvas-node[data-shape="database"] .shape-bg { background: #b91c1c; border-radius: 50% / 20%; }
        .canvas-node[data-shape="database"] .shape-bg::before { content: ''; position: absolute; top: -5px; left: 0; width: 100%; height: 20px; border-radius: 50%; background: #dc2626; border: 1px solid #7f1d1d; }
        .canvas-node[data-shape="form"] .shape-bg { background: #f97316; border-radius: 4px; clip-path: polygon(0 0, 80% 0, 100% 30%, 100% 100%, 0 100%); }

        .node-id-badge {
            position: absolute; top: -12px; left: 8px; background: #ea580c; color: white;
            font-size: 11px; padding: 2px 8px; border-radius: 12px; border: 2px solid white;
            z-index: 5; cursor: text; outline: none; min-width: 28px; text-align: center;
            user-select: text !important; -webkit-user-select: text !important;
        }
        
        .node-text { 
            width: 100%; outline: none; user-select: text !important; -webkit-user-select: text !important;
            cursor: text; position: relative; z-index: 2;
        }
        
        /* Node Hover Action Buttons */
        .node-actions {
            position: absolute; top: -12px; right: -12px;
            display: flex; gap: 4px; z-index: 30; opacity: 0; transition: all 0.2s ease;
        }
        .canvas-node:hover .node-actions { opacity: 1; }

        .btn-node-action {
            width: 24px; height: 24px;
            color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center;
            font-size: 12px; font-weight: bold; cursor: pointer;
            box-shadow: 0 2px 4px rgba(0,0,0,0.3); border: 2px solid white;
        }
        .btn-delete-node { background: #ef4444; }
        .btn-delete-node:hover { background: #dc2626; transform: scale(1.15); }
        
        .btn-notes-node { background: #f59e0b; }
        .btn-notes-node:hover { background: #d97706; transform: scale(1.15); }

        .btn-link-node { background: #8b5cf6; }
        .btn-link-node:hover { background: #7c3aed; transform: scale(1.15); }

        .btn-goto-node { background: #10b981; }
        .btn-goto-node:hover { background: #059669; transform: scale(1.15); }

        .btn-doc-node { background: #3b82f6; }
        .btn-doc-node:hover { background: #2563eb; transform: scale(1.15); }

        /* Linked Node Indicator */
        .node-linked-indicator {
            position: absolute; bottom: -8px; right: -8px;
            background: #8b5cf6; color: white; width: 20px; height: 20px;
            border-radius: 50%; display: flex; align-items: center; justify-content: center;
            font-size: 10px; z-index: 5; border: 2px solid white;
            box-shadow: 0 2px 4px rgba(0,0,0,0.3);
        }

        /* --- Connection Ports --- */
        .port {
            position: absolute; width: 14px; height: 14px; background: #fff;
            border: 2px solid #333; border-radius: 50%; cursor: crosshair;
            z-index: 20; opacity: 0; transition: opacity 0.2s;
        }
        .canvas-node:hover .port { opacity: 1; }
        .port.right { top: 50%; right: -7px; transform: translateY(-50%); }
        .port.bottom { bottom: -7px; left: 50%; transform: translateX(-50%); }
        .port.left { top: 50%; left: -7px; transform: translateY(-50%); }
        .port.top { top: -7px; left: 50%; transform: translateX(-50%); }

        /* --- Swimlanes --- */
        .swimlane-container { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
        .swimlane-row { border-bottom: 2px solid #94a3b8; position: relative; box-sizing: border-box; }
        .swimlane-label {
            position: absolute; left: 0; top: 0; width: 40px; height: 100%;
            background: #f1f5f9; border-right: 2px solid #94a3b8;
            display: flex; align-items: center; justify-content: center; pointer-events: auto;
        }
        .swimlane-label span { 
            transform: rotate(-90deg); white-space: nowrap; font-weight: 700; color: #334155; 
            letter-spacing: 1px; font-size: 12px; cursor: text; padding: 4px 8px; border-radius: 4px;
            transition: background 0.2s; outline: none;
        }
        .swimlane-label span:hover, .swimlane-label span:focus { background: rgba(0,0,0,0.05); }

        .add-lane-btn {
            position: absolute; left: 0; width: 40px; height: 40px;
            background: #f1f5f9; border-right: 2px solid #94a3b8; border-bottom: 2px solid #94a3b8;
            display: flex; align-items: center; justify-content: center;
            cursor: pointer; font-size: 20px; font-weight: bold; color: #3b82f6;
            transition: background 0.2s; pointer-events: auto; z-index: 10;
        }
        .add-lane-btn:hover { background: #e2e8f0; color: #2563eb; }
        
        /* --- Utilities --- */
        body.is-dragging, body.is-dragging * { user-select: none !important; -webkit-user-select: none !important; }
        body.is-panning { cursor: grabbing !important; }
        
        .drag-ghost {
            position: fixed; pointer-events: none; opacity: 0.8; z-index: 9999;
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3); transform: scale(1.05);
        }

        body.is-drawing .canvas-node { filter: drop-shadow(0 0 6px rgba(59, 130, 246, 0.8)) !important; }
        body.is-drawing .canvas-node.dragging-source { filter: drop-shadow(0 4px 3px rgba(0,0,0,0.3)) !important; opacity: 0.7; }

        /* --- Modals --- */
        .modal-overlay {
            position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
            background: rgba(15, 23, 42, 0.6); backdrop-filter: blur(4px);
            z-index: 1000; display: flex; align-items: center; justify-content: center;
        }
        .modal-content {
            background: #fff; width: 600px; max-width: 90vw; border-radius: 8px;
            box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
            display: flex; flex-direction: column; overflow: hidden;
            animation: modalPopIn 0.2s ease-out;
        }
        @keyframes modalPopIn {
            0% { opacity: 0; transform: scale(0.95); }
            100% { opacity: 1; transform: scale(1); }
        }
        .modal-header {
            padding: 16px 24px; border-bottom: 1px solid #e2e8f0;
            display: flex; justify-content: space-between; align-items: center;
            background: #f8fafc;
        }
        .modal-header h3 { margin: 0; font-size: 18px; color: #1e293b; }
        .btn-close-modal {
            background: transparent; border: none; font-size: 24px; color: #94a3b8;
            cursor: pointer; line-height: 1; padding: 0 4px; border-radius: 4px;
        }
        .btn-close-modal:hover { color: #ef4444; background: #fee2e2; }
        .modal-body { padding: 24px; flex: 1; display: flex; flex-direction: column; }
        #notes-textarea {
            width: 100%; min-height: 300px; padding: 12px; border: 1px solid #cbd5e1;
            border-radius: 6px; font-family: inherit; font-size: 14px; color: #334155;
            resize: vertical; outline: none; transition: border-color 0.2s;
        }
        #notes-textarea:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1); }
        .modal-footer {
            padding: 16px 24px; border-top: 1px solid #e2e8f0; background: #f8fafc;
            display: flex; justify-content: flex-end; gap: 12px;
        }

        /* --- Mobile Responsiveness --- */
        .btn-mobile-sidebar {
            background: transparent;
            border: none;
            color: #1e293b;
            cursor: pointer;
            padding: 4px;
            margin-right: 12px;
        }

        /* Dark overlay when sidebar is open on mobile */
        .sidebar-overlay {
            display: none;
            position: fixed;
            top: 0; left: 0; right: 0; bottom: 0;
            background: rgba(15, 23, 42, 0.5);
            backdrop-filter: blur(2px);
            z-index: 15;
            opacity: 0; transition: opacity 0.3s;
        }

        @media (max-width: 1000px) {
            .btn-mobile-sidebar { display: block; }
            
            .sidebar {
                position: fixed;
                left: -280px; /* Hide completely offscreen */
                top: 0;
                height: 100vh;
                transition: left 0.3s ease;
                box-shadow: 10px 0 20px rgba(0,0,0,0.2);
            }
            
            .sidebar.mobile-open {
                left: 0;
            }
            
            body.sidebar-open .sidebar-overlay {
                display: block; opacity: 1;
            }

            .main-wrapper {
                width: 100vw;
            }
        }